svn commit: samba r1949 - in branches/SAMBA_4_0/source: lib/cmdline utils/net

metze at samba.org metze at samba.org
Fri Aug 20 09:48:26 GMT 2004


Author: metze
Date: 2004-08-20 09:48:25 +0000 (Fri, 20 Aug 2004)
New Revision: 1949

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=1949&nolog=1

Log:
provide functions to access the username, userdomain and userpassword

now you're prompted when cmdline_get_userpassword() is called
and the password is not yet known

metze

Modified:
   branches/SAMBA_4_0/source/lib/cmdline/popt_common.c
   branches/SAMBA_4_0/source/utils/net/net.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/cmdline/popt_common.c
===================================================================
--- branches/SAMBA_4_0/source/lib/cmdline/popt_common.c	2004-08-20 09:21:58 UTC (rev 1948)
+++ branches/SAMBA_4_0/source/lib/cmdline/popt_common.c	2004-08-20 09:48:25 UTC (rev 1949)
@@ -33,7 +33,7 @@
  *		-i,--scope
  */
 
-struct cmdline_auth_info cmdline_auth_info;
+static struct cmdline_auth_info cmdline_auth_info;
 
 static void popt_common_callback(poptContext con, 
 			   enum poptCallbackReason reason,
@@ -396,3 +396,38 @@
 	{ "machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" },
 	POPT_TABLEEND
 };
+
+const char *cmdline_get_username(void)
+{
+	return cmdline_auth_info.username;
+}
+
+const char *cmdline_get_userdomain(void)
+{
+	if (cmdline_auth_info.domain[0]) {
+		return cmdline_auth_info.domain;
+	}
+
+	/* I think this should be lp_netbios_name() 
+	 * instead of lp_workgroup(), because if you're logged in 
+	 * as domain user the getenv("USER") contains the domain
+	 * and this code path isn't used
+	 * --metze
+	 */
+	return lp_netbios_name();
+}
+
+const char *cmdline_get_userpassword(void)
+{
+	pstring prompt;
+
+	if (cmdline_auth_info.got_pass) {
+		return cmdline_auth_info.password;
+	}
+
+	pstr_sprintf(prompt, "Password for [%s\\%s]:", 
+			cmdline_get_userdomain(),
+			cmdline_get_username());
+
+	return getpass(prompt);
+}

Modified: branches/SAMBA_4_0/source/utils/net/net.c
===================================================================
--- branches/SAMBA_4_0/source/utils/net/net.c	2004-08-20 09:21:58 UTC (rev 1948)
+++ branches/SAMBA_4_0/source/utils/net/net.c	2004-08-20 09:48:25 UTC (rev 1949)
@@ -156,7 +156,6 @@
 	const char **argv_new;
 	TALLOC_CTX *mem_ctx;
 	struct net_context *ctx;
-	const char *domain;
 	poptContext pc;
 	struct poptOption long_options[] = {
 		POPT_AUTOHELP
@@ -204,12 +203,6 @@
 		return 1;
 	}
 
-	if (cmdline_auth_info.domain[0]) {
-		domain = cmdline_auth_info.domain;
-	} else {
-		domain = lp_workgroup();
-	}
-
 	mem_ctx = talloc_init("net_context");
 	ctx = talloc_p(mem_ctx, struct net_context);
 	if (!ctx) {
@@ -219,9 +212,9 @@
 
 	ZERO_STRUCTP(ctx);
 	ctx->mem_ctx = mem_ctx;
-	ctx->user.account_name = talloc_strdup(ctx->mem_ctx, cmdline_auth_info.username);
-	ctx->user.domain_name = talloc_strdup(ctx->mem_ctx, domain);
-	ctx->user.password = talloc_strdup(ctx->mem_ctx, cmdline_auth_info.password);
+	ctx->user.account_name = talloc_strdup(ctx->mem_ctx, cmdline_get_username());
+	ctx->user.domain_name = talloc_strdup(ctx->mem_ctx, cmdline_get_userdomain());
+	ctx->user.password = talloc_strdup(ctx->mem_ctx, cmdline_get_userpassword());
 
 	rc = net_run_function(ctx, argc_new-1, argv_new+1, net_functable, net_usage);
 



More information about the samba-cvs mailing list