svn commit: samba r15420 - in branches/SAMBA_4_0/source: auth/credentials lib/cmdline

abartlet at samba.org abartlet at samba.org
Wed May 3 20:23:20 GMT 2006


Author: abartlet
Date: 2006-05-03 20:23:19 +0000 (Wed, 03 May 2006)
New Revision: 15420

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

Log:
Add a new function to print a the 'unparsed' string format for usernames.

This is used in the password prompt, and should be reversable by the
parse string function.

Also, don't look at the ccache, even for the guess code, if kerberos
is disabled.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/auth/credentials/credentials.c
   branches/SAMBA_4_0/source/lib/cmdline/credentials.c


Changeset:
Modified: branches/SAMBA_4_0/source/auth/credentials/credentials.c
===================================================================
--- branches/SAMBA_4_0/source/auth/credentials/credentials.c	2006-05-03 16:07:21 UTC (rev 15419)
+++ branches/SAMBA_4_0/source/auth/credentials/credentials.c	2006-05-03 20:23:19 UTC (rev 15420)
@@ -514,6 +514,38 @@
 }
 
 /**
+ * Given a string, typically obtained from a -U argument, parse it into domain, username, realm and password fields
+ *
+ * The format accepted is [domain\\]user[%password] or user[@realm][%password]
+ *
+ * @param credentials Credentials structure on which to set the password
+ * @param data the string containing the username, password etc
+ * @param obtained This enum describes how 'specified' this password is
+ */
+
+const char *cli_credentials_get_unparsed_name(struct cli_credentials *credentials, TALLOC_CTX *mem_ctx)
+{
+	const char *bind_dn = cli_credentials_get_bind_dn(credentials);
+	const char *domain;
+	const char *username;
+	const char *name;
+
+	if (bind_dn) {
+		name = talloc_reference(mem_ctx, bind_dn);
+	} else {
+		cli_credentials_get_ntlm_username_domain(credentials, mem_ctx, &username, &domain);
+		if (domain && domain[0]) {
+			name = talloc_asprintf(mem_ctx, "%s\\%s", 
+					       domain, username);
+		} else {
+			name = talloc_asprintf(mem_ctx, "%s", 
+					       username);
+		}
+	}
+	return name;
+}
+
+/**
  * Specifies default values for domain, workstation and realm
  * from the smb.conf configuration file
  *
@@ -565,8 +597,10 @@
 	if (getenv("PASSWD_FILE")) {
 		cli_credentials_parse_password_file(cred, getenv("PASSWD_FILE"), CRED_GUESS_FILE);
 	}
-
-	cli_credentials_set_ccache(cred, NULL, CRED_GUESS_FILE);
+	
+	if (cli_credentials_get_kerberos_state(cred) != CRED_DONT_USE_KERBEROS) {
+		cli_credentials_set_ccache(cred, NULL, CRED_GUESS_FILE);
+	}
 }
 
 /**
@@ -646,7 +680,7 @@
  * Mark the current password for a credentials struct as wrong. This will 
  * cause the password to be prompted again (if a callback is set).
  *
- * This will decremebt the number of times the password can be tried.
+ * This will decrement the number of times the password can be tried.
  *
  * @retval whether the credentials struct is finished
  */

Modified: branches/SAMBA_4_0/source/lib/cmdline/credentials.c
===================================================================
--- branches/SAMBA_4_0/source/lib/cmdline/credentials.c	2006-05-03 16:07:21 UTC (rev 15419)
+++ branches/SAMBA_4_0/source/lib/cmdline/credentials.c	2006-05-03 20:23:19 UTC (rev 15420)
@@ -24,28 +24,15 @@
 
 static const char *cmdline_get_userpassword(struct cli_credentials *credentials)
 {
-	char *prompt;
 	char *ret;
-	const char *domain;
-	const char *username;
 	TALLOC_CTX *mem_ctx = talloc_new(NULL);
 
-	const char *bind_dn = cli_credentials_get_bind_dn(credentials);
-	
-	if (bind_dn) {
-		prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", 
-					 bind_dn);
-	} else {
-		cli_credentials_get_ntlm_username_domain(credentials, mem_ctx, &username, &domain);
-		if (domain && domain[0]) {
-			prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", 
-						 domain, username);
-		} else {
-			prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", 
-						 username);
-		}
-	}
+	const char *prompt_name = cli_credentials_get_unparsed_name(credentials, mem_ctx);
+	const char *prompt;
 
+	prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", 
+				 prompt_name);
+
 	ret = getpass(prompt);
 
 	talloc_free(mem_ctx);



More information about the samba-cvs mailing list