From 31e8101ea2073fa65437d79c6f4bf722831d09c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Sep 2001 20:00:42 +0000 Subject: Fixed problems with arg parsing as root with smbpasswd. Jeremy. (This used to be commit 6399cf490dffbd162afa06f18cdd6e0364db567d) --- source3/utils/smbpasswd.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 74f4e8833a..da5f817c80 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -550,7 +550,7 @@ static int process_root(int argc, char *argv[]) { struct passwd *pwd; int result = 0, ch; - BOOL joining_domain = False, got_pass = False; + BOOL joining_domain = False, got_pass = False, got_username = False; int local_flags = 0; BOOL stdin_passwd_get = False; fstring user_name, user_password; @@ -559,12 +559,12 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - ZERO_STRUCT(user_name); - ZERO_STRUCT(user_password); + ZERO_STRUCT(user_name); + ZERO_STRUCT(user_password); user_name[0] = '\0'; - while ((ch = getopt(argc, argv, "ax:d:e:hmnj:r:sR:D:U:L")) != EOF) { + while ((ch = getopt(argc, argv, "axdehmnj:r:sR:D:U:L")) != EOF) { switch(ch) { case 'L': local_mode = True; @@ -574,17 +574,14 @@ static int process_root(int argc, char *argv[]) break; case 'x': local_flags |= LOCAL_DELETE_USER; - fstrcpy(user_name, optarg); new_passwd = xstrdup("XXXXXX"); break; case 'd': local_flags |= LOCAL_DISABLE_USER; - fstrcpy(user_name, optarg); new_passwd = xstrdup("XXXXXX"); break; case 'e': local_flags |= LOCAL_ENABLE_USER; - fstrcpy(user_name, optarg); break; case 'm': local_flags |= LOCAL_TRUST_ACCOUNT; @@ -616,6 +613,7 @@ static int process_root(int argc, char *argv[]) case 'U': { char *lp; + got_username = True; fstrcpy(user_name, optarg); if ((lp = strchr_m(user_name, '%'))) { @@ -691,12 +689,17 @@ static int process_root(int argc, char *argv[]) switch(argc) { case 0: - fstrcpy(user_name, ""); + if (!got_username) + fstrcpy(user_name, ""); break; case 1: + if (got_username) + usage(); fstrcpy(user_name, argv[0]); break; case 2: + if (got_username || got_pass) + usage(); fstrcpy(user_name, argv[0]); new_passwd = xstrdup(argv[1]); break; -- cgit