Merge from HEAD:
[bbaumbach/samba-autobuild/.git] / source3 / rpcclient / rpcclient.c
index 5f15c57577489c139c9e42b19de42a12c1fc41fd..dc33a8ec2a98cb450f2b74047ec9846a6abbdd5a 100644 (file)
@@ -197,14 +197,14 @@ 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;
        }
 
 
-       if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+       if (!cli_nt_session_open (cli, PI_LSARPC)) {
                fprintf(stderr, "could not initialise lsa pipe\n");
                goto error;
        }
@@ -377,18 +377,18 @@ static struct cmd_set rpcclient_commands[] = {
 
        { "GENERAL OPTIONS" },
 
-       { "help",       cmd_help,       NULL,   "Get help on commands", "[command]" },
-       { "?",          cmd_help,       NULL,   "Get help on commands", "[command]" },
-       { "debuglevel", cmd_debuglevel, NULL,   "Set debug level", "level" },
-       { "list",       cmd_listcommands, NULL, "List available commands on <pipe>", "pipe" },
-       { "exit",       cmd_quit,       NULL,   "Exit program", "" },
-       { "quit",       cmd_quit,       NULL,   "Exit program", "" },
+       { "help",       cmd_help,         -1,   "Get help on commands", "[command]" },
+       { "?",          cmd_help,         -1,   "Get help on commands", "[command]" },
+       { "debuglevel", cmd_debuglevel,   -1,   "Set debug level", "level" },
+       { "list",       cmd_listcommands, -1,   "List available commands on <pipe>", "pipe" },
+       { "exit",       cmd_quit,         -1,   "Exit program", "" },
+       { "quit",       cmd_quit,         -1,   "Exit program", "" },
 
        { NULL }
 };
 
 static struct cmd_set separator_command[] = {
-       { "---------------", NULL,      NULL,   "----------------------" },
+       { "---------------", NULL,      -1,     "----------------------" },
        { NULL }
 };
 
@@ -402,10 +402,12 @@ extern struct cmd_set netlogon_commands[];
 extern struct cmd_set srvsvc_commands[];
 extern struct cmd_set dfs_commands[];
 extern struct cmd_set reg_commands[];
+extern struct cmd_set ds_commands[];
 
 static struct cmd_set *rpcclient_command_list[] = {
        rpcclient_commands,
        lsarpc_commands,
+       ds_commands,
        samr_commands,
        spoolss_commands,
        netlogon_commands,
@@ -433,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;
@@ -476,17 +479,16 @@ 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;
                 }
 
                 /* Open pipe */
 
-                if (cmd_entry->pipe)
-                        if (!cli_nt_session_open(cli, cmd_entry->pipe)) {
-                                DEBUG(0, ("Could not initialise %s\n",
-                                          cmd_entry->pipe));
+                if (cmd_entry->pipe_idx != -1)
+                        if (!cli_nt_session_open(cli, cmd_entry->pipe_idx)) {
+                                DEBUG(0, ("Could not initialise pipe\n"));
                                 goto done;
                         }
 
@@ -496,7 +498,7 @@ static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry,
 
                 /* Cleanup */
 
-                if (cmd_entry->pipe)
+                if (cmd_entry->pipe_idx != -1)
                         cli_nt_session_close(cli);
 
                 talloc_destroy(mem_ctx);
@@ -527,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;
 
@@ -577,11 +579,9 @@ 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;
-       int                     olddebug;
        static char             *cmdstr = "";
        const char *server;
        struct cli_state        *cli;
@@ -591,37 +591,32 @@ 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;
        struct cmd_set          **cmd_set;
        struct in_addr          server_ip;
        NTSTATUS                nt_status;
-       extern BOOL             AllowDebugChange;
 
        /* make sure the vars that get altered (4th field) are in
           a fixed location or certain compilers complain */
        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 }
        };
 
        setlinebuf(stdout);
 
-       DEBUGLEVEL = 1;
-       AllowDebugChange = False;
-
        /* Parse options */
 
        pc = poptGetContext("rpcclient", argc, (const char **) argv,
@@ -648,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));
@@ -667,13 +658,13 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
                        break;
                }
                case 'I':
-                       if (!inet_aton(opt_ipaddr, &server_ip)) {
+                       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':
-                       pstrcpy(domain, opt_domain);
+                       fstrcpy(domain, opt_domain);
                        break;
                }
        }
@@ -697,17 +688,14 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
                reopen_logs();
        
        /* Load smb.conf file */
-       /* FIXME!  How to get this DEBUGLEVEL to last over lp_load()? */
-       olddebug = DEBUGLEVEL;
-       if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
+
+       if (!lp_load(dyn_CONFIGFILE,True,False,False))
                fprintf(stderr, "Can't load %s\n", dyn_CONFIGFILE);
-       }
-       DEBUGLEVEL = olddebug;
 
        load_interfaces();
 
-       get_myname((*global_myname)?NULL:global_myname);
-       strupper(global_myname);
+       if (!init_names())
+               return 1;
 
        /* Resolve the IP address */
 
@@ -731,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)));