Patch from metze to generalise POPT_COMMON_SAMBA, with some minor changes
authorJelmer Vernooij <jelmer@samba.org>
Mon, 24 Mar 2003 11:25:34 +0000 (11:25 +0000)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 24 Mar 2003 11:25:34 +0000 (11:25 +0000)
(This used to be commit 2ddfed298d7f0b6e690275725a39c3ef107077ae)

20 files changed:
source3/client/client.c
source3/include/popt_common.h
source3/lib/popt_common.c
source3/nmbd/nmbd.c
source3/nsswitch/wbinfo.c
source3/nsswitch/winbindd.c
source3/rpcclient/rpcclient.c
source3/smbd/server.c
source3/torture/samtest.c
source3/torture/vfstest.c
source3/utils/net.c
source3/utils/nmblookup.c
source3/utils/ntlm_auth.c
source3/utils/pdbedit.c
source3/utils/smbcacls.c
source3/utils/smbtree.c
source3/utils/status.c
source3/utils/testparm.c
source3/web/swat.c
source3/wrepld/server.c

index 9fb843cfbae6c6a095899c55c4e7f2d237fb6ec2..8d6730cdc66685a9e46d76d1e84cf782d4e9df01 100644 (file)
@@ -2589,15 +2589,7 @@ static void remember_query_host(const char *arg,
        int rc = 0;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               POPT_COMMON_SAMBA
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options }, 
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netbios_name },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_scope },
-               POPT_CREDENTIALS
+
                { "name-resolve", 'R', POPT_ARG_STRING, &new_name_resolve_order, 'R', "Use these name resolution services only", "NAME-RESOLVE-ORDER" },
                { "message", 'M', POPT_ARG_STRING, NULL, 'M', "Send message", "HOST" },
                { "ip-address", 'I', POPT_ARG_STRING, NULL, 'I', "Use this IP to connect to", "IP" },
@@ -2610,7 +2602,9 @@ static void remember_query_host(const char *arg,
                { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" }, 
                { "send-buffer", 'b', POPT_ARG_INT, NULL, 'b', "Changes the transmit/send buffer", "BYTES" },
                { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to", "PORT" },
-               { 0, 0, 0, 0 }
+               POPT_COMMON_SAMBA
+               POPT_CREDENTIALS
+               POPT_TABLEEND
        };
        
 
@@ -2720,7 +2714,7 @@ static void remember_query_host(const char *arg,
 
        pstrcpy(username, cmdline_auth_info.username);
        pstrcpy(password, cmdline_auth_info.password);
-       pstrcpy(workgroup, cmdline_auth_info.workgroup);
+       pstrcpy(workgroup, lp_workgroup());
        use_kerberos = cmdline_auth_info.use_kerberos;
        got_pass = cmdline_auth_info.got_pass;
 
index 9354e8734d72df4ecd066a2896870513c6dc89e4..7cdbc9886232cfb2c2b5f2c0ea59f19809c8072f 100644 (file)
 #define _POPT_COMMON_H
 
 /* Common popt structures */
-extern struct poptOption popt_common_debug[];
-extern struct poptOption popt_common_configfile[];
-extern struct poptOption popt_common_socket_options[];
-extern struct poptOption popt_common_version[];
-extern struct poptOption popt_common_netbios_name[];
-extern struct poptOption popt_common_log_base[];
+extern struct poptOption popt_common_samba[];
 extern struct poptOption popt_common_credentials[];
-extern struct poptOption popt_common_scope[];
 
-#define POPT_COMMON_SAMBA { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version, 0, "Common samba options:", NULL },
+#define POPT_COMMON_SAMBA { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_samba, 0, "Common samba options:", NULL },
 #define POPT_CREDENTIALS { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials, 0, "Authentication options:", NULL },
 
 struct user_auth_info {
        pstring username;
        pstring password;
-       pstring workgroup;
        BOOL got_pass;
        BOOL use_kerberos;
 };
index 3c9a87b361cda8f966c9d4e6876e05fdb9e35d2f..06ba4fc898ec435322f35aee1197dcd3993a1b62 100644 (file)
@@ -29,6 +29,7 @@
  *             -V,--version
  *             -l,--log-base
  *             -n,--netbios-name
+ *             -W,--workgroup
  *             -i,--scope
  */
 
@@ -102,49 +103,29 @@ static void popt_common_callback(poptContext con,
                          set_global_scope(arg);
                }
                break;
+
+       case 'W':
+               if (arg) {
+                       set_global_myworkgroup(arg);
+               }
+               break;
        }
 }
 
-struct poptOption popt_common_debug[] = {
+struct poptOption popt_common_samba[] = {
        { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
        { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" },
-       { 0 }
-};
-
-struct poptOption popt_common_scope[] = {
-       { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, 
-    { "scope", 'i', POPT_ARG_STRING, NULL, 'i', "Use this Netbios scope", "SCOPE" },  
-       { 0 }
-};
-
-struct poptOption popt_common_configfile[] = {
-       { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
-       { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file" },
-       { 0 }
-};
-
-struct poptOption popt_common_socket_options[] = {
-       { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
-       {"socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use" },
-       { 0 }
-};
-
-struct poptOption popt_common_version[] = {
-       { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
-       {"version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
-       { 0 }
-};
-
-struct poptOption popt_common_netbios_name[] = {
-       { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
-       {"netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name"},
-       { 0 }
-};
-
-struct poptOption popt_common_log_base[] = {
-       { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback },
-       { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files"},
-       { 0 }
+       { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file",
+         "CONFIGFILE" },
+       { "socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use",
+         "SOCKETOPTIONS" },
+       { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
+       { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files",
+         "LOGFILEBASE" },
+       { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" },
+       { "workgroup", 'W', POPT_ARG_STRING, NULL, 'W', "Set the workgroup name", "WORKGROUP" },
+       { "scope", 'i', POPT_ARG_STRING, NULL, 'i', "Use this Netbios scope", "SCOPE" },
+       POPT_TABLEEND
 };
 
 /****************************************************************************
@@ -255,7 +236,7 @@ static void get_credentials_file(const char *file, struct user_auth_info *info)
                else if (strwicmp("username", param) == 0)
                        pstrcpy(info->username, val);
                else if (strwicmp("domain", param) == 0)
-                       pstrcpy(info->workgroup,val);
+                       set_global_myworkgroup(val);
                memset(buf, 0, sizeof(buf));
        }
        x_fclose(auth);
@@ -263,7 +244,6 @@ static void get_credentials_file(const char *file, struct user_auth_info *info)
 
 /* Handle command line options:
  *             -U,--user
- *             -W,--workgroup
  *             -A,--authentication-file
  *             -k,--use-kerberos
  *             -N,--no-pass
@@ -327,30 +307,25 @@ static void popt_common_credentials_callback(poptContext con,
                get_credentials_file(arg, &cmdline_auth_info);
                break;
 
-               case 'W':
-                       pstrcpy(cmdline_auth_info.workgroup,arg);
-                       break;
-
-               case 'k':
+       case 'k':
 #ifndef HAVE_KRB5
-                       d_printf("No kerberos support compiled in\n");
-                       exit(1);
+               d_printf("No kerberos support compiled in\n");
+               exit(1);
 #else
-                       cmdline_auth_info.got_pass = True;
+               cmdline_auth_info.use_kerberos = True;
+               cmdline_auth_info.got_pass = True;
 #endif
-
-                       break;
-               }
+               break;
        }
+}
 
 
 
-       struct poptOption popt_common_credentials[] = {
-               { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_credentials_callback },
-               { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" },
-               { "no-pass", 'N', POPT_ARG_VAL, &cmdline_auth_info.got_pass, True, "Don't ask for a password" },
-               { "kerberos", 'k', POPT_ARG_VAL, &cmdline_auth_info.use_kerberos, True, "Use kerberos (active directory) authentication" },
-               { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" },
-               { "workgroup", 'W', POPT_ARG_STRING, NULL, 'W', "Set the workgroup name", "WORKGROUP" },
-               { 0 }
-       };
+struct poptOption popt_common_credentials[] = {
+       { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, 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, True, "Don't ask for a password" },
+       { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, True, "Use kerberos (active directory) authentication" },
+       { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" },
+       POPT_TABLEEND
+};
index a34593557e5269ebdd48f9b41284ff0834ba44e4..d013b79d3e6b952c5d1c6e0b25fcc7dd77e6c8c4 100644 (file)
@@ -601,11 +601,6 @@ static BOOL open_sockets(BOOL isdaemon, int port)
        {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"},
        {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" },
        POPT_COMMON_SAMBA
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options },
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netbios_name },
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base },
        { NULL }
        };
        pstring logfile;
index 4f621e7008a2e0ce1be9baa15c34fc0519b1d069..fe11cd652851cddae969bd737c1a6ef0e154c40d 100644 (file)
@@ -711,8 +711,8 @@ int main(int argc, char **argv)
                { "set-auth-user", 'A', POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
                { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
                { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { 0, 0, 0, 0 }
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
 
        /* Samba client initialisation */
index c9d6808316838846d1fd7a9010b50fcf17092cf3..cd72a4f5721891595424de2bd781072d6587a6b8 100644 (file)
@@ -814,16 +814,13 @@ int main(int argc, char **argv)
        static BOOL log_stdout = False;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               POPT_COMMON_SAMBA
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
                { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
                { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" },
                { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" },
                { "dual-daemon", 'B', POPT_ARG_VAL, &opt_dual_daemon, True, "Dual daemon mode" },
                { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, False, "Disable caching" },
-               
-               { 0, 0, 0, 0 }
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
        poptContext pc;
        int opt;
index 2338d72f19273cf3941ff8dd8150cff0bb50196d..97a944dbf9ddf7522169b7c3e44034ad3243ea14 100644 (file)
@@ -97,70 +97,6 @@ static char **completion_fn(char *text, int start, int end)
        return matches;
 }
 
-/***********************************************************************
- * read in username/password credentials from a file
- */
-static void read_authfile (
-       char *filename, 
-       char* username, 
-       char* password, 
-       char* domain
-)
-{
-       FILE *auth;
-        fstring buf;
-        uint16 len = 0;
-       char *ptr, *val, *param;
-                               
-       if ((auth=sys_fopen(filename, "r")) == NULL)
-       {
-               printf ("ERROR: Unable to open credentials file!\n");
-               return;
-       }
-                                
-       while (!feof(auth))
-       {  
-               /* get a line from the file */
-               if (!fgets (buf, sizeof(buf), auth))
-                       continue;
-               
-               len = strlen(buf);
-               
-               /* skip empty lines */                  
-               if ((len) && (buf[len-1]=='\n'))
-               {
-                       buf[len-1] = '\0';
-                       len--;
-               }       
-               if (len == 0)
-                       continue;
-                                       
-               /* break up the line into parameter & value.
-                  will need to eat a little whitespace possibly */
-               param = buf;
-               if (!(ptr = strchr_m(buf, '=')))
-                       continue;
-               val = ptr+1;
-               *ptr = '\0';
-                                       
-               /* eat leading white space */
-               while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
-                       val++;
-                                       
-               if (strwicmp("password", param) == 0)
-                       fstrcpy (password, val);
-               else if (strwicmp("username", param) == 0)
-                       fstrcpy (username, val);
-               else if (strwicmp("domain", param) == 0)
-                       fstrcpy (domain, val);
-                                               
-               memset(buf, 0, sizeof(buf));
-       }
-       fclose(auth);
-       
-       return;
-}
-
 static char* next_command (char** cmdstr)
 {
        static pstring          command;
@@ -181,28 +117,6 @@ static char* next_command (char** cmdstr)
        return command;
 }
 
-
-/**
- * Find default username from environment variables.
- *
- * @param username fstring to receive username; not touched if none is
- * known.
- **/
-static void get_username (char *username)
-{
-        if (getenv("USER"))
-                fstrcpy(username,getenv("USER"));
-        if (*username == 0 && getenv("LOGNAME"))
-                fstrcpy(username,getenv("LOGNAME"));
-        if (*username == 0) {
-                fstrcpy(username,"GUEST");
-        }
-
-       return;
-}
-
 /* Fetch the SID for this computer */
 
 static void fetch_machine_sid(struct cli_state *cli)
@@ -575,21 +489,12 @@ out_free:
 
  int main(int argc, char *argv[])
 {
-       static int              got_pass = 0;
        BOOL                    interactive = True;
        int                     opt;
-       static char             *cmdstr = "";
+       static char             *cmdstr = NULL;
        const char *server;
        struct cli_state        *cli;
-       fstring                 password="",
-                               username="",
-               domain="";
-       static char             *opt_authfile=NULL,
-                               *opt_username=NULL,
-                               *opt_domain=NULL,
-                               *opt_logfile=NULL,
-                               *opt_ipaddr=NULL;
-       pstring                 logfile;
+       static char             *opt_ipaddr=NULL;
        struct cmd_set          **cmd_set;
        struct in_addr          server_ip;
        NTSTATUS                nt_status;
@@ -599,17 +504,11 @@ out_free:
        poptContext pc;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               {"authfile",    'A', POPT_ARG_STRING,   &opt_authfile, 'A', "File containing user credentials", "AUTHFILE"},
-               {"nopass",      'N', POPT_ARG_NONE,     &got_pass, 'N', "Don't ask for a password"},
-               {"user", 'U', POPT_ARG_STRING,  &opt_username, 'U', "Set the network username", "USER"},
-               {"workgroup", 'W', POPT_ARG_STRING,     &opt_domain, 'W', "Set the domain name for user account", "DOMAIN"},
                {"command",     'c', POPT_ARG_STRING,   &cmdstr, 'c', "Execute semicolon separated cmds", "COMMANDS"},
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', "Logfile to use instead of stdout", "LOGFILE" },
                {"dest-ip", 'I', POPT_ARG_STRING,   &opt_ipaddr, 'I', "Specify destination IP address", "IP"},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { NULL }
+               POPT_COMMON_SAMBA
+               POPT_CREDENTIALS
+               POPT_TABLEEND
        };
 
        ZERO_STRUCT(server_ip);
@@ -628,43 +527,13 @@ out_free:
        
        while((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
-               case 'A':
-                       /* only get the username, password, and domain from the file */
-                       read_authfile (opt_authfile, username, password, domain);
-                       if (strlen (password))
-                               got_pass = 1;
-                       break;
-                       
-               case 'l':
-                       slprintf(logfile, sizeof(logfile) - 1, "%s.client", 
-                                opt_logfile);
-                       lp_set_logfile(logfile);
-                       interactive = False;
-                       break;
-                       
-               case 'U': {
-                       char *lp;
 
-                       fstrcpy(username,opt_username);
-
-                       if ((lp=strchr_m(username,'%'))) {
-                               *lp = 0;
-                               fstrcpy(password,lp+1);
-                               got_pass = 1;
-                               memset(strchr_m(opt_username,'%') + 1, 'X',
-                                      strlen(password));
-                       }
-                       break;
-               }
                case 'I':
                        if ( (server_ip.s_addr=inet_addr(opt_ipaddr)) == INADDR_NONE ) {
                                fprintf(stderr, "%s not a valid IP address\n",
                                        opt_ipaddr);
                                return 1;
                        }
-               case 'W':
-                       fstrcpy(domain, opt_domain);
-                       break;
                }
        }
 
@@ -701,28 +570,25 @@ out_free:
         * from stdin if necessary
         */
 
-       if (!got_pass) {
+       if (!cmdline_auth_info.got_pass) {
                char *pass = getpass("Password:");
                if (pass) {
-                       fstrcpy(password, pass);
+                       pstrcpy(cmdline_auth_info.password, pass);
                }
        }
        
-       if (!strlen(username) && !got_pass)
-               get_username(username);
-               
        nt_status = cli_full_connection(&cli, global_myname(), server, 
                                        opt_ipaddr ? &server_ip : NULL, 0,
                                        "IPC$", "IPC",  
-                                       username, domain,
-                                       password, 0, NULL);
+                                       cmdline_auth_info.username, lp_workgroup(),
+                                       cmdline_auth_info.password, 0, NULL);
        
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0,("Cannot connect to server.  Error was %s\n", nt_errstr(nt_status)));
                return 1;
        }
 
-       memset(password,'X',sizeof(password));
+       memset(cmdline_auth_info.password,'X',sizeof(cmdline_auth_info.password));
 
        /* Load command lists */
 
@@ -737,7 +603,7 @@ out_free:
        fetch_machine_sid(cli);
  
        /* Do anything specified with -c */
-        if (cmdstr[0]) {
+        if (cmdstr && cmdstr[0]) {
                 char    *cmd;
                 char    *p = cmdstr;
  
index 627fad1572698c881421694f44aa50049a9700b2..715e9162631f06490e879d961464a3162478149d 100644 (file)
@@ -670,10 +670,6 @@ static BOOL init_structs(void )
        {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
        {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
        POPT_COMMON_SAMBA
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug},
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile},
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options},
-       {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base},
        { NULL }
        };
 
index 0de2e5d2889363022ac72f876efca8ad1cfd4812..fd5f75a664b6f2c98b5b395ca5ed00ae14e7e2bc 100644 (file)
@@ -353,10 +353,7 @@ int main(int argc, char *argv[])
 {
        BOOL                    interactive = True;
        int                     opt;
-       static char             *cmdstr = "";
-       static char *opt_logfile=NULL;
-       static char *config_file = dyn_CONFIGFILE;
-       pstring                 logfile;
+       static char             *cmdstr = NULL;
        struct cmd_set          **cmd_set;
        struct samtest_state st;
 
@@ -365,12 +362,9 @@ int main(int argc, char *argv[])
        poptContext pc;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
                {"command",     'e', POPT_ARG_STRING,   &cmdstr, 'e', "Execute semicolon seperated cmds"},
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', "Logfile to use instead of stdout"},
-               {"configfile", 'c', POPT_ARG_STRING, &config_file, 0,"use different configuration file",NULL},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { 0, 0, 0, 0}
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
 
        ZERO_STRUCT(st);
@@ -419,7 +413,7 @@ int main(int argc, char *argv[])
        }
 
        /* Do anything specified with -c */
-       if (cmdstr[0]) {
+       if (cmdstr && cmdstr[0]) {
                char    *cmd;
                char    *p = cmdstr;
  
index 04f31656d3d0a92ad1809b7d8034a08c4ae719a0..3b28a3c496b90a9515e97057ebb5caba02b5f0a4 100644 (file)
@@ -4,7 +4,7 @@
 
    Copyright (C) Simo Sorce 2002
    Copyright (C) Eric Lorimer 2002
-   Copyright (C) Jelmer Vernooij 2002
+   Copyright (C) Jelmer Vernooij 2002,2003
 
    Most of this code was ripped off of rpcclient.
    Copyright (C) Tim Potter 2000-2001
@@ -474,17 +474,11 @@ BOOL reload_services(BOOL test)
 
 int main(int argc, char *argv[])
 {
-       BOOL                    interactive = True;
-       int                     opt;
-       static char             *cmdstr = "";
-       static char             *opt_logfile=NULL;
-       static int              opt_debuglevel;
-       pstring                 logfile;
+       static char             *cmdstr = NULL;
        struct cmd_set          **cmd_set;
-       extern BOOL             AllowDebugChange;
        static struct vfs_state vfs;
        int i;
-       static const char       *filename = "";
+       static const char       *filename = NULL;
 
        /* make sure the vars that get altered (4th field) are in
           a fixed location or certain compilers complain */
@@ -493,35 +487,17 @@ int main(int argc, char *argv[])
                POPT_AUTOHELP
                {"file",        'f', POPT_ARG_STRING,   &filename, 0, },
                {"command",     'c', POPT_ARG_STRING,   &cmdstr, 0, "Execute specified list of commands" },
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', "Write output to specified logfile" },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { 0, 0, 0, 0}
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
 
 
        setlinebuf(stdout);
 
-       DEBUGLEVEL = 1;
-       AllowDebugChange = False;
-
        pc = poptGetContext("vfstest", argc, (const char **) argv,
                            long_options, 0);
        
-       while((opt = poptGetNextOpt(pc)) != -1) {
-               switch (opt) {
-               case 'l':
-                       slprintf(logfile, sizeof(logfile) - 1, "%s.client", 
-                                opt_logfile);
-                       lp_set_logfile(logfile);
-                       interactive = False;
-                       break;
-                       
-               case 'd':
-                       DEBUGLEVEL = opt_debuglevel;
-                       break;
-               }
-       }
+       while(poptGetNextOpt(pc) != -1);
 
 
        poptFreeContext(pc);
@@ -531,9 +507,7 @@ int main(int argc, char *argv[])
 
        /* the following functions are part of the Samba debugging
           facilities.  See lib/debug.c */
-       setup_logging("vfstest", interactive);
-       if (!interactive) 
-               reopen_logs();
+       setup_logging("vfstest", True);
        
        /* Load command lists */
 
@@ -556,13 +530,13 @@ int main(int argc, char *argv[])
        smbd_vfs_init(vfs.conn);
 
        /* Do we have a file input? */
-       if (filename[0]) {
+       if (filename && filename[0]) {
                process_file(&vfs, filename);
                return 0;
        }
 
        /* Do anything specified with -c */
-       if (cmdstr[0]) {
+       if (cmdstr && cmdstr[0]) {
                char    *cmd;
                char    *p = cmdstr;
  
index 33c125901b9fa92e3fdaa1267e42c49a53e7f3ea..d6945ceefbd28209275bdec9ae3a9be236d010ca 100644 (file)
@@ -515,7 +515,6 @@ static struct functable net_func[] = {
        struct poptOption long_options[] = {
                {"help",        'h', POPT_ARG_NONE,   0, 'h'},
                {"workgroup",   'w', POPT_ARG_STRING, &opt_target_workgroup},
-               {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup},
                {"user",        'U', POPT_ARG_STRING, &opt_user_name, 'U'},
                {"ipaddress",   'I', POPT_ARG_STRING, 0,'I'},
                {"port",        'p', POPT_ARG_INT,    &opt_port},
@@ -532,8 +531,6 @@ static struct functable net_func[] = {
                {"timeout",     't', POPT_ARG_INT,    &opt_timeout},
                {"machine-pass",'P', POPT_ARG_NONE,   &opt_machine_pass},
                POPT_COMMON_SAMBA
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
                { 0, 0, 0, 0}
        };
 
index 97cea3a7bbf77b5d2f5068c419caa7322b7f83f8..88038fb566a18c958fe7197124ce3dd3261811a0 100644 (file)
@@ -203,9 +203,6 @@ int main(int argc,char *argv[])
          { "root-port", 'r', POPT_ARG_VAL, &RootPort, True, "Use root port 137 (Win95 only replies to this)" },
          { "lookup-by-ip", 'A', POPT_ARG_VAL, &lookup_by_ip, True, "Do a node status on <name> as an IP Address" },
          POPT_COMMON_SAMBA
-         { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_scope },
-         { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-         { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
          { 0, 0, 0, 0 }
   };
        
index ac456769f22d0021430af1ecb377fd0d019ee64d..a28bbf936481ad86da7978732261bad51e3ee7db 100644 (file)
@@ -439,14 +439,13 @@ enum {
        OPT_NT_KEY
 };
 
-int main(int argc, const char **argv)
+ int main(int argc, const char **argv)
 {
        int opt;
 
        poptContext pc;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-
                { "helper-protocol", 0, POPT_ARG_STRING, &helper_protocol, OPT_DOMAIN, "operate as a stdio-based helper", "helper protocol to use"},
                { "username", 0, POPT_ARG_STRING, &username, OPT_USERNAME, "username"},
                { "domain", 0, POPT_ARG_STRING, &domain, OPT_DOMAIN, "domain name"},
@@ -457,10 +456,9 @@ int main(int argc, const char **argv)
                { "password", 0, POPT_ARG_STRING, &password, OPT_PASSWORD, "User's plaintext password"},                
                { "request-lm-key", 0, POPT_ARG_NONE, &request_lm_key, OPT_LM_KEY, "Retreive LM session key"},
                { "request-nt-key", 0, POPT_ARG_NONE, &request_nt_key, OPT_NT_KEY, "Retreive NT session key"},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { 0, 0, 0, 0 }
+               POPT_COMMON_SAMBA
+               POPT_CREDENTIALS
+               POPT_TABLEEND
        };
 
        /* Samba client initialisation */
index f373adcb0a970a4275bf1311f65ae34cbbb2ae47..03be2571e54d75537ef80846699382580bea63fe 100644 (file)
@@ -537,9 +537,7 @@ int main (int argc, char **argv)
                {"value",       'C', POPT_ARG_LONG, &account_policy_value, 'C',"set the account policy to this value", NULL},
                {"account-control",     'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL},
                POPT_COMMON_SAMBA
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               {0,0,0,0}
+               POPT_TABLEEND
        };
        
        setup_logging("pdbedit", True);
index af5bf09e48c63c062a432f0c3920ff0e29060a09..ac15cf1aa03d783eda71a1ec40db99b409122dc2 100644 (file)
 
 #include "includes.h"
 
-static fstring password;
-static pstring username;
 static pstring owner_username;
 static fstring server;
-static int got_pass;
 static int test_args = False;
 static TALLOC_CTX *ctx;
 
@@ -716,19 +713,19 @@ static struct cli_state *connect_one(const char *share)
        NTSTATUS nt_status;
        zero_ip(&ip);
        
-       if (!got_pass) {
+       if (!cmdline_auth_info.got_pass) {
                char *pass = getpass("Password: ");
                if (pass) {
-                       fstrcpy(password, pass);
-                       got_pass = True;
+                       pstrcpy(cmdline_auth_info.password, pass);
+                       cmdline_auth_info.got_pass = True;
                }
        }
 
        if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, global_myname(), server, 
                                                            &ip, 0,
                                                            share, "?????",  
-                                                           username, lp_workgroup(),
-                                                           password, 0, NULL))) {
+                                                           cmdline_auth_info.username, lp_workgroup(),
+                                                           cmdline_auth_info.password, 0, NULL))) {
                return c;
        } else {
                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
@@ -743,7 +740,6 @@ static struct cli_state *connect_one(const char *share)
 {
        char *share;
        int opt;
-       char *p;
        enum acl_mode mode = SMB_ACL_SET;
        static char *the_acl = NULL;
        enum chown_mode change_mode = REQUEST_NONE;
@@ -759,12 +755,10 @@ static struct cli_state *connect_one(const char *share)
                { "set", 'S', POPT_ARG_STRING, NULL, 'S', "Set acls", "ACLS" },
                { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" },
                { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" },
-               { "numeric", 'n', POPT_ARG_VAL, &numeric, True, "Don't resolve sids or masks to names" },
-               { "test-args", 't', POPT_ARG_VAL, &test_args, True, "Test arguments"},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               {"username", 'U', POPT_ARG_STRING, NULL, 'U', "User to authenticate as", "user%password" },
+               { "numeric", 0, POPT_ARG_NONE, &numeric, True, "Don't resolve sids or masks to names" },
+               { "test-args", 't', POPT_ARG_NONE, &test_args, True, "Test arguments"},
+               POPT_COMMON_SAMBA
+               POPT_CREDENTIALS
                { NULL }
        };
 
@@ -781,33 +775,12 @@ static struct cli_state *connect_one(const char *share)
        lp_load(dyn_CONFIGFILE,True,False,False);
        load_interfaces();
 
-       if (getenv("USER")) {
-               pstrcpy(username,getenv("USER"));
-
-               if ((p=strchr_m(username,'%'))) {
-                       *p = 0;
-                       fstrcpy(password,p+1);
-                       got_pass = True;
-                       memset(strchr_m(getenv("USER"), '%') + 1, 'X',
-                              strlen(password));
-               }
-       }
        pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
        
        poptSetOtherOptionHelp(pc, "//server1/share1 filename");
 
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
-               case 'U':
-                       pstrcpy(username,poptGetOptArg(pc));
-                       p = strchr_m(username,'%');
-                       if (p) {
-                               *p = 0;
-                               fstrcpy(password, p+1);
-                               got_pass = 1;
-                       }
-                       break;
-
                case 'S':
                        the_acl = smb_xstrdup(poptGetOptArg(pc));
                        mode = SMB_ACL_SET;
index a55dd4dd009a4644821f61632c8e79488b80f201..32506c41019f4d0c20c2d89abb953b44b7fa6efe 100644 (file)
@@ -247,14 +247,12 @@ static BOOL print_tree(struct user_auth_info *user_info)
 {
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
                { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" },
                { "domains", 'D', POPT_ARG_VAL, &level, LEV_WORKGROUP, "List only domains (workgroups) of tree" },
                { "servers", 'S', POPT_ARG_VAL, &level, LEV_SERVER, "List domains(workgroups) and servers of tree" },
-               { 0 }
+               POPT_COMMON_SAMBA
+               POPT_CREDENTIALS
+               POPT_TABLEEND
        };
        poptContext pc;
        
index 8014b133d9e9decb0f9ed5f76f7a1d45f4a4fc55..7e87701752a1e150af2f8af1d0a865a35b1412bd 100644 (file)
@@ -559,10 +559,8 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo
                {"profile",     'P', POPT_ARG_NONE,     &profile_only, 'P', "Do profiling" },
 #endif /* WITH_PROFILE */
                {"byterange",   'B', POPT_ARG_NONE,     &show_brl, 'B', "Include byte range locks"},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               { 0, 0, 0, 0}
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
 
        setup_logging(argv[0],True);
index 22964214be4c012792b2b12b382bf8f2933ac55f..c0e4f7606e0a1a7f6e9178138258c90bfef4348d 100644 (file)
@@ -186,7 +186,7 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
        return ret;
 }   
 
-int main(int argc, const char *argv[])
+ int main(int argc, const char *argv[])
 {
        const char *config_file = dyn_CONFIGFILE;
        int s;
@@ -206,7 +206,7 @@ int main(int argc, const char *argv[])
                {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"},
                {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
                {"encoding", 't', POPT_ARG_STRING, &term_code, 0, "Print parameters with encoding"},
-               {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
+               POPT_COMMON_SAMBA
                {0,0,0,0}
        };
 
index 92dece6ecd9e5771b2b6dd8ee4080582b3788234..9a133e1330d54f1dc2daec1d25bd819a3d0fd689 100644 (file)
@@ -1267,9 +1267,8 @@ static void printers_page(void)
        struct poptOption long_options[] = {
                POPT_AUTOHELP
                { "disable-authentication", 'a', POPT_ARG_VAL, &demo_mode, True, "Disable authentication (demo mode)" },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile},
-               { 0, 0, 0, 0 }
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
 
        fault_setup(NULL);
index 5203d337457daf1eb0d0b718a15651bf7dedd066..be9d86952d280c34230a1b13de0cf7b1f027bb47 100644 (file)
@@ -510,17 +510,13 @@ static void process(void)
        static BOOL log_stdout = False;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               POPT_COMMON_SAMBA
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base },
                { "daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
                { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc)" },
                { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
                { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Run interactive (not a daemon)" },
                { "port", 'p', POPT_ARG_INT, &wins_port, 'p', "Listen on the specified port" },
-               { 0, 0, 0, 0 }
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
        };
        int opt;
        poptContext pc;