svn commit: samba r12819 - in branches/SAMBA_4_0: source/scripting/ejs swat

abartlet at samba.org abartlet at samba.org
Tue Jan 10 09:21:14 GMT 2006


Author: abartlet
Date: 2006-01-10 09:21:13 +0000 (Tue, 10 Jan 2006)
New Revision: 12819

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=12819

Log:
Fix swat authentication again.  We need to pass the socket_address
structure around, so the auth code knows where the request came from.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_auth.c
   branches/SAMBA_4_0/swat/login.esp


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_auth.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_auth.c	2006-01-10 09:18:48 UTC (rev 12818)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_auth.c	2006-01-10 09:21:13 UTC (rev 12819)
@@ -29,7 +29,7 @@
 static int ejs_doauth(MprVarHandle eid,
 		      TALLOC_CTX *tmp_ctx, struct MprVar *auth, const char *username, 
 		      const char *password, const char *domain, const char *workstation,
-		      const char *authtype)
+		      struct socket_address *remote_host, const char *authtype)
 {
 	struct auth_usersupplied_info *user_info = NULL;
 	struct auth_serversupplied_info *server_info = NULL;
@@ -63,7 +63,7 @@
 
 	user_info->workstation_name = workstation;
 
-	user_info->remote_host = NULL;
+	user_info->remote_host = remote_host;
 
 	user_info->password_state = AUTH_PASSWORD_PLAIN;
 	user_info->password.plaintext = talloc_strdup(user_info, password);
@@ -75,7 +75,9 @@
 
 	nt_status = auth_check_password(auth_context, tmp_ctx, user_info, &server_info);
 	if (!NT_STATUS_IS_OK(nt_status)) {
-		mprSetPropertyValue(auth, "report", mprString("Login Failed"));
+		mprSetPropertyValue(auth, "report", 
+				    mprString(talloc_asprintf(mprMemCtx(), "Login Failed: %s", 
+							      get_friendly_nt_error_msg(nt_status))));
 		mprSetPropertyValue(auth, "result", mprCreateBoolVar(False));
 		goto done;
 	}
@@ -111,8 +113,9 @@
 	const char *workstation;
 	struct MprVar auth;
 	struct cli_credentials *creds;
+	struct socket_address *remote_host;
 
-	if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {
+	if (argc != 2 || argv[0]->type != MPR_TYPE_OBJECT || argv[1]->type != MPR_TYPE_OBJECT) {
 		ejsSetErrorMsg(eid, "userAuth invalid arguments, this function requires an object.");
 		return -1;
 	}
@@ -120,10 +123,16 @@
 	/* get credential values from credentials object */
 	creds = mprGetPtr(argv[0], "creds");
 	if (creds == NULL) {
-		ejsSetErrorMsg(eid, "userAuth requires a 'creds' element");
+		ejsSetErrorMsg(eid, "userAuth requires a 'creds' first parameter");
 		return -1;
 	}
 
+	remote_host = mprGetPtr(argv[1], "socket_address");
+	if (remote_host == NULL) {
+		ejsSetErrorMsg(eid, "userAuth requires a socket address second parameter");
+		return -1;
+	}
+
  	tmp_ctx = talloc_new(mprMemCtx());	
 	
 	username    = cli_credentials_get_username(creds);
@@ -139,10 +148,10 @@
 
 	auth = mprObject("auth");
 
-	if (domain && (strcmp("System User", domain) == 0)) {
-		ejs_doauth(eid, tmp_ctx, &auth, username, password, domain, workstation, "unix");
+	if (domain && (strcmp("SYSTEM USER", domain) == 0)) {
+		ejs_doauth(eid, tmp_ctx, &auth, username, password, domain, workstation, remote_host, "unix");
 	} else {
-		ejs_doauth(eid, tmp_ctx, &auth, username, password, domain, workstation, "sam");
+		ejs_doauth(eid, tmp_ctx, &auth, username, password, domain, workstation, remote_host, "sam");
 	}
 
 	mpr_Return(eid, auth);

Modified: branches/SAMBA_4_0/swat/login.esp
===================================================================
--- branches/SAMBA_4_0/swat/login.esp	2006-01-10 09:18:48 UTC (rev 12818)
+++ branches/SAMBA_4_0/swat/login.esp	2006-01-10 09:21:13 UTC (rev 12819)
@@ -28,7 +28,7 @@
 		creds.set_domain(form.Domain);
 		creds.set_workstation(request['REMOTE_HOST']);
 
-		auth = userAuth(creds);
+		auth = userAuth(creds, request['REMOTE_SOCKET_ADDRESS']);
 		if (auth == undefined) {
 			write("<b>Invalid login - please try again<br /></b>\n");
 		} else if (auth.result) {
@@ -38,6 +38,7 @@
 			session.authinfo.username = auth.username;
 			session.authinfo.domain = auth.domain;
 			session.authinfo.credentials = creds;
+			session.authinfo.session_info = auth.session_info;
 			
 			/* if the user was asking for the login page, then now
 			   redirect them to the main page. Otherwise just
@@ -48,8 +49,10 @@
 			} else {
 			   redirect(session_uri(request.REQUEST_URI));
 			}
+		} else if (auth.report == undefined) {
+			write("<b>Login failed - please try again<br /></b>\n");
 		} else {
-			write("<b>Login failed - please try again<br /></b>\n");
+			write("<b>Login failed: " + auth.report + " - please try again<br /></b>\n");
 		}
 	}
 %>



More information about the samba-cvs mailing list