summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-12-06 18:49:39 -0800
committerJeremy Allison <jra@samba.org>2007-12-06 18:49:39 -0800
commit9fdf2d05867e5d6abd9099996b9e6c071bdbd0e7 (patch)
tree85fc8c753c9fc8a6e60a5f80b7c0c6d65c7f7fd2
parente67a6620a7e5e3edb4a6c285841224bc4173fc44 (diff)
downloadsamba-9fdf2d05867e5d6abd9099996b9e6c071bdbd0e7.tar.gz
samba-9fdf2d05867e5d6abd9099996b9e6c071bdbd0e7.tar.bz2
samba-9fdf2d05867e5d6abd9099996b9e6c071bdbd0e7.zip
Get closer to building with smbmount. Move parameter line changes
into lib/util.c Jeremy. (This used to be commit 6ac5d81655927ba8eabea35adaae5adfcbb821c9)
-rw-r--r--source3/Makefile.in9
-rw-r--r--source3/lib/popt_common.c102
-rw-r--r--source3/lib/util.c109
-rw-r--r--source3/utils/smbtree.c14
4 files changed, 143 insertions, 91 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 8ab2b9ec34..127a631513 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -687,7 +687,7 @@ TOOL_OBJ = client/smbctool.o client/clitar.o $(PARAM_OBJ) $(LIBSMB_OBJ) \
UTIL_REG_OBJ = lib/util_reg.o
UTIL_REG_API_OBJ = lib/util_reg_api.o
-UTIL_REG_SMBCONF_OBJ = lib/util_reg_smbconf.o
+UTIL_REG_SMBCONF_OBJ = lib/util_reg_smbconf.o
# objects to be used when not all of the registry code should be
# loaded but only the portion needed by reg_api, typically for
@@ -731,16 +731,15 @@ NET_OBJ = $(NET_OBJ1) $(PARAM_WITHOUT_REG_OBJ) $(SECRETS_OBJ) $(LIBSMB_OBJ) \
$(REG_API_OBJ) $(DISPLAY_DSDCINFO_OBJ) $(NETAPI_OBJ)
CUPS_OBJ = client/smbspool.o $(PARAM_OBJ) $(LIBSMB_OBJ) \
- $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(SECRETS_OBJ)
+ $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(SECRETS_OBJ) $(POPT_LIB_OBJ)
MOUNT_OBJ = client/smbmount.o \
- $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ) \
- $(POPT_LIB_OBJ)
+ $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ)
MNT_OBJ = client/smbmnt.o $(VERSION_OBJ) $(LIBREPLACE_OBJ) $(POPT_LIB_OBJ) $(SOCKET_WRAPPER_OBJ)
UMOUNT_OBJ = client/smbumount.o $(PARAM_OBJ) $(LIBSMB_OBJ) \
- $(KRBCLIENT_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ) $(POPT_LIB_OBJ)
+ $(KRBCLIENT_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ)
CIFS_MOUNT_OBJ = client/mount.cifs.o
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index d454a798ac..bd8410a958 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -36,58 +36,6 @@
extern bool AllowDebugChange;
extern bool override_logfile;
-static struct user_auth_info cmdline_auth_info;
-
-const char *get_cmdline_auth_info_username(void)
-{
- if (!cmdline_auth_info.username) {
- return "";
- }
- return cmdline_auth_info.username;
-}
-
-void set_cmdline_auth_info_username(const char *username)
-{
- SAFE_FREE(cmdline_auth_info.username);
- cmdline_auth_info.username = SMB_STRDUP(username);
- if (!cmdline_auth_info.username) {
- exit(ENOMEM);
- }
-}
-
-const char *get_cmdline_auth_info_password(void)
-{
- if (!cmdline_auth_info.password) {
- return "";
- }
- return cmdline_auth_info.password;
-}
-
-void set_cmdline_auth_info_password(const char *password)
-{
- SAFE_FREE(cmdline_auth_info.password);
- cmdline_auth_info.password = SMB_STRDUP(password);
- if (!cmdline_auth_info.password) {
- exit(ENOMEM);
- }
- cmdline_auth_info.got_pass = true;
-}
-
-int get_cmdline_auth_info_signing_state(void)
-{
- return cmdline_auth_info.signing_state;
-}
-
-bool get_cmdline_auth_info_use_kerberos(void)
-{
- return cmdline_auth_info.use_kerberos;
-}
-
-bool get_cmdline_auth_info_got_pass(void)
-{
- return cmdline_auth_info.got_pass;
-}
-
static void set_logfile(poptContext con, const char * arg)
{
@@ -471,9 +419,6 @@ static void popt_common_credentials_callback(poptContext con,
char *p;
if (reason == POPT_CALLBACK_REASON_PRE) {
- cmdline_auth_info.use_kerberos = False;
- cmdline_auth_info.got_pass = False;
- cmdline_auth_info.signing_state = Undefined;
set_cmdline_auth_info_username("GUEST");
if (getenv("LOGNAME")) {
@@ -488,9 +433,11 @@ static void popt_common_credentials_callback(poptContext con,
set_cmdline_auth_info_username(puser);
if ((p = strchr_m(puser,'%'))) {
+ size_t len;
*p = 0;
+ len = strlen(p+1);
set_cmdline_auth_info_password(p+1);
- memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password));
+ memset(strchr_m(getenv("USER"),'%')+1,'X',len);
}
SAFE_FREE(puser);
}
@@ -510,14 +457,19 @@ static void popt_common_credentials_callback(poptContext con,
case 'U':
{
char *lp;
+ char *puser = SMB_STRDUP(arg);
- pstrcpy(cmdline_auth_info.username,arg);
- if ((lp=strchr_m(cmdline_auth_info.username,'%'))) {
+ if ((lp=strchr_m(puser,'%'))) {
+ size_t len;
*lp = 0;
- pstrcpy(cmdline_auth_info.password,lp+1);
- cmdline_auth_info.got_pass = True;
- memset(strchr_m(arg,'%')+1,'X',strlen(cmdline_auth_info.password));
+ set_cmdline_auth_info_username(puser);
+ set_cmdline_auth_info_password(lp+1);
+ len = strlen(lp+1);
+ memset(strchr_m(arg,'%')+1,'X',len);
+ } else {
+ set_cmdline_auth_info_username(puser);
}
+ SAFE_FREE(puser);
}
break;
@@ -530,25 +482,14 @@ static void popt_common_credentials_callback(poptContext con,
d_printf("No kerberos support compiled in\n");
exit(1);
#else
- cmdline_auth_info.use_kerberos = true;
- cmdline_auth_info.got_pass = true;
+ set_cmdline_auth_info_use_krb5_ticket();
#endif
break;
case 'S':
- {
- cmdline_auth_info.signing_state = -1;
- if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) {
- cmdline_auth_info.signing_state = false;
- } else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") ||
- strequal(arg, "auto")) {
- cmdline_auth_info.signing_state = true;
- } else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) {
- cmdline_auth_info.signing_state = Required;
- } else {
- fprintf(stderr, "Unknown signing option %s\n", arg );
- exit(1);
- }
+ if (!set_cmdline_auth_info_signing_state(arg)) {
+ fprintf(stderr, "Unknown signing option %s\n", arg );
+ exit(1);
}
break;
case 'P':
@@ -579,17 +520,20 @@ static void popt_common_credentials_callback(poptContext con,
SAFE_FREE(opt_password);
/* machine accounts only work with kerberos */
- cmdline_auth_info.use_kerberos = true;
+ set_cmdline_auth_info_use_krb5_ticket();
}
break;
+ case 'N':
+ set_cmdline_auth_info_no_password();
+ break;
}
}
struct poptOption popt_common_credentials[] = {
{ NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback },
{ "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" },
- { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" },
- { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" },
+ { "no-pass", 'N', POPT_ARG_NONE, NULL, 0, "Don't ask for a password" },
+ { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use kerberos (active directory) authentication" },
{ "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" },
{ "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" },
{"machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" },
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 2d90d211dd..289d8a058f 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -187,7 +187,7 @@ void gfree_names(void)
void gfree_all( void )
{
- gfree_names();
+ gfree_names();
gfree_loadparm();
gfree_case_tables();
gfree_debugsyms();
@@ -280,6 +280,113 @@ bool init_names(void)
}
/**************************************************************************n
+ Code to cope with username/password auth options from the commandline.
+ Used mainly in client tools.
+****************************************************************************/
+
+static struct user_auth_info cmdline_auth_info = {
+ NULL, /* username */
+ NULL, /* password */
+ false, /* got_pass */
+ false, /* use_kerberos */
+ Undefined /* signing state */
+};
+
+const char *get_cmdline_auth_info_username(void)
+{
+ if (!cmdline_auth_info.username) {
+ return "";
+ }
+ return cmdline_auth_info.username;
+}
+
+void set_cmdline_auth_info_username(const char *username)
+{
+ SAFE_FREE(cmdline_auth_info.username);
+ cmdline_auth_info.username = SMB_STRDUP(username);
+ if (!cmdline_auth_info.username) {
+ exit(ENOMEM);
+ }
+}
+
+const char *get_cmdline_auth_info_password(void)
+{
+ if (!cmdline_auth_info.password) {
+ return "";
+ }
+ return cmdline_auth_info.password;
+}
+
+void set_cmdline_auth_info_password(const char *password)
+{
+ SAFE_FREE(cmdline_auth_info.password);
+ cmdline_auth_info.password = SMB_STRDUP(password);
+ if (!cmdline_auth_info.password) {
+ exit(ENOMEM);
+ }
+ cmdline_auth_info.got_pass = true;
+}
+
+bool set_cmdline_auth_info_signing_state(const char *arg)
+{
+ cmdline_auth_info.signing_state = -1;
+ if (strequal(arg, "off") || strequal(arg, "no") ||
+ strequal(arg, "false")) {
+ cmdline_auth_info.signing_state = false;
+ } else if (strequal(arg, "on") || strequal(arg, "yes") ||
+ strequal(arg, "true") || strequal(arg, "auto")) {
+ cmdline_auth_info.signing_state = true;
+ } else if (strequal(arg, "force") || strequal(arg, "required") ||
+ strequal(arg, "forced")) {
+ cmdline_auth_info.signing_state = Required;
+ } else {
+ return false;
+ }
+ return true;
+}
+
+int get_cmdline_auth_info_signing_state(void)
+{
+ return cmdline_auth_info.signing_state;
+}
+
+bool get_cmdline_auth_info_use_kerberos(void)
+{
+ return cmdline_auth_info.use_kerberos;
+}
+
+/* This should only be used by lib/popt_common.c JRA */
+void set_cmdline_auth_info_use_krb5_ticket(void)
+{
+ cmdline_auth_info.use_kerberos = true;
+ cmdline_auth_info.got_pass = true;
+}
+
+bool get_cmdline_auth_info_got_pass(void)
+{
+ return cmdline_auth_info.got_pass;
+}
+
+/* This should only be used by lib/popt_common.c JRA */
+void set_cmdline_auth_info_no_password(void)
+{
+ SAFE_FREE(cmdline_auth_info.password);
+ cmdline_auth_info.got_pass = false;
+}
+
+bool get_cmdline_auth_info_copy(struct user_auth_info *info)
+{
+ *info = cmdline_auth_info;
+ /* Now re-alloc the strings. */
+ info->username = SMB_STRDUP(get_cmdline_auth_info_username());
+ info->password = SMB_STRDUP(get_cmdline_auth_info_password());
+ if (!info->username || !info->password) {
+ return false;
+ }
+ return true;
+}
+
+/**************************************************************************n
Find a suitable temporary directory. The result should be copied immediately
as it may be overwritten by a subsequent call.
****************************************************************************/
diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index 23090013a3..91d3b1542b 100644
--- a/source3/utils/smbtree.c
+++ b/source3/utils/smbtree.c
@@ -265,6 +265,7 @@ static bool print_tree(struct user_auth_info *user_info)
int main(int argc,char *argv[])
{
TALLOC_CTX *frame = talloc_stackframe();
+ struct user_auth_info local_user_info;
struct poptOption long_options[] = {
POPT_AUTOHELP
{ "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" },
@@ -295,19 +296,20 @@ static bool print_tree(struct user_auth_info *user_info)
/* Parse command line args */
- if (!cmdline_auth_info.got_pass) {
+ if (!get_cmdline_auth_info_got_pass()) {
char *pass = getpass("Password: ");
if (pass) {
- strlcpy(cmdline_auth_info.password,
- pass,
- sizeof(cmdline_auth_info.password));
+ set_cmdline_auth_info_password(pass);
}
- cmdline_auth_info.got_pass = true;
}
/* Now do our stuff */
- if (!print_tree(&cmdline_auth_info)) {
+ if (!get_cmdline_auth_info_copy(&local_user_info)) {
+ return 1;
+ }
+
+ if (!print_tree(&local_auth_info)) {
TALLOC_FREE(frame);
return 1;
}