Merge from HEAD:
[bbaumbach/samba-autobuild/.git] / source3 / rpcclient / rpcclient.c
index c34f3b08ad90619d75a63e55ed8ae608e02c6e73..dc33a8ec2a98cb450f2b74047ec9846a6abbdd5a 100644 (file)
@@ -197,7 +197,7 @@ static void fetch_machine_sid(struct cli_state *cli)
 
        if (got_domain_sid) return;
 
-       if (!(mem_ctx=talloc_init()))
+       if (!(mem_ctx=talloc_init("fetch_machine_sid")))
        {
                DEBUG(0,("fetch_machine_sid: talloc_init returned NULL!\n"));
                goto error;
@@ -435,7 +435,8 @@ static void add_command_set(struct cmd_set *cmd_set)
 static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, 
                        char *cmd)
 {
-       char *p = cmd, **argv = NULL;
+       char **argv = NULL;
+       const char *p = cmd;
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        pstring buf;
        int argc = 0, i;
@@ -478,7 +479,7 @@ static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry,
 
                 /* Create mem_ctx */
 
-                if (!(mem_ctx = talloc_init())) {
+                if (!(mem_ctx = talloc_init("do_cmd"))) {
                         DEBUG(0, ("talloc_init() failed\n"));
                         goto done;
                 }
@@ -528,7 +529,7 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
        struct cmd_list *temp_list;
        BOOL found = False;
        pstring buf;
-       char *p = cmd;
+       const char *p = cmd;
        NTSTATUS result = NT_STATUS_OK;
        int len = 0;
 
@@ -578,7 +579,6 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
 
  int main(int argc, char *argv[])
 {
-       extern pstring          global_myname;
        static int              got_pass = 0;
        BOOL                    interactive = True;
        int                     opt;
@@ -591,7 +591,6 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
        static char             *opt_authfile=NULL,
                                *opt_username=NULL,
                                *opt_domain=NULL,
-                               *opt_configfile=NULL,
                                *opt_logfile=NULL,
                                *opt_ipaddr=NULL;
        pstring                 logfile;
@@ -604,15 +603,15 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
        poptContext pc;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               {"authfile",    'A', POPT_ARG_STRING,   &opt_authfile, 'A', "File containing user credentials"},
-               {"conf",        's', POPT_ARG_STRING,   &opt_configfile, 's', "Specify an alternative config file"},
+               {"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"},
-               {"workgroup",   'W', POPT_ARG_STRING,   &opt_domain, 'W', "Set the domain name for user account"},
-               {"command",     'c', POPT_ARG_STRING,   &cmdstr, 'c', "Execute semicolon separated cmds"},
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', "Logfile to use instead of stdout"},
-               {"dest-ip",     'I', POPT_ARG_STRING,   &opt_ipaddr, 'I', "Specify destination IP address"},
+               {"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 }
        };
 
@@ -644,18 +643,14 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
                        interactive = False;
                        break;
                        
-               case 's':
-                       pstrcpy(dyn_CONFIGFILE, opt_configfile);
-                       break;
-                       
                case 'U': {
                        char *lp;
 
-                       pstrcpy(username,opt_username);
+                       fstrcpy(username,opt_username);
 
                        if ((lp=strchr_m(username,'%'))) {
                                *lp = 0;
-                               pstrcpy(password,lp+1);
+                               fstrcpy(password,lp+1);
                                got_pass = 1;
                                memset(strchr_m(opt_username,'%') + 1, 'X',
                                       strlen(password));
@@ -669,7 +664,7 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
                                return 1;
                        }
                case 'W':
-                       pstrcpy(domain, opt_domain);
+                       fstrcpy(domain, opt_domain);
                        break;
                }
        }
@@ -699,8 +694,8 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
 
        load_interfaces();
 
-       get_myname((*global_myname)?NULL:global_myname);
-       strupper(global_myname);
+       if (!init_names())
+               return 1;
 
        /* Resolve the IP address */
 
@@ -724,11 +719,11 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
        if (!strlen(username) && !got_pass)
                get_username(username);
                
-       nt_status = cli_full_connection(&cli, global_myname, server, 
+       nt_status = cli_full_connection(&cli, global_myname(), server, 
                                        &server_ip, 0,
                                        "IPC$", "IPC",  
                                        username, domain,
-                                       password, 0);
+                                       password, 0, NULL);
        
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0,("Cannot connect to server.  Error was %s\n", nt_errstr(nt_status)));