From 53ca6d33ce46f29afdf3fa82ba0669ef88dd97e4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2001 01:15:17 +0000 Subject: added a -L option to smbpasswd to force it to run locally so we can test smbpasswd as non-root (This used to be commit ab635202655712a05b812ff40550d00d00552853) --- source3/utils/smbpasswd.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 00a7d3c1c1..b4576a603c 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -29,6 +29,9 @@ extern int DEBUGLEVEL; extern char *optarg; extern int optind; +/* forced running in root-mode */ +static BOOL local_mode; + /********************************************************* a strdup with exit **********************************************************/ @@ -59,7 +62,8 @@ static void usage(void) printf(" -U USER remote username\n"); printf(" -r MACHINE remote machine\n"); - if (getuid() == 0) { + if (getuid() == 0 || local_mode) { + printf(" -L local mode (must be first option)\n"); printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); printf(" -a add user\n"); @@ -261,8 +265,11 @@ static int process_root(int argc, char *argv[]) char *old_passwd = NULL; char *remote_machine = NULL; - while ((ch = getopt(argc, argv, "ax:d:e:mnj:r:sR:D:U:")) != EOF) { + while ((ch = getopt(argc, argv, "ax:d:e:mnj:r:sR:D:U:L")) != EOF) { switch(ch) { + case 'L': + local_mode = True; + break; case 'a': local_flags |= LOCAL_ADD_USER; break; @@ -609,7 +616,14 @@ int main(int argc, char **argv) exit(1); } - if (getuid() == 0) { + /* pre-check for local mode option as first option. We can't + do this via normal getopt as getopt can't be called + twice. */ + if (argc > 1 && strcmp(argv[1], "-L") == 0) { + local_mode = True; + } + + if (local_mode || getuid() == 0) { return process_root(argc, argv); } -- cgit