diff options
Diffstat (limited to 'source3/rpcclient/rpcclient.c')
-rw-r--r-- | source3/rpcclient/rpcclient.c | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 880fdc599a..2d86fb1d3d 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -573,6 +573,24 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) } +/* Print usage information */ +static void usage(void) +{ + printf("Usage: rpcclient [options] server\n"); + + printf("\t-A or --authfile authfile File containing user credentials\n"); + printf("\t-c or --command \"command string\" Execute semicolon separated cmds\n"); + printf("\t-d or --debug debuglevel Set the debuglevel\n"); + printf("\t-l or --logfile logfile Logfile to use instead of stdout\n"); + printf("\t-h or --help Print this help message.\n"); + printf("\t-N or --nopass Don't ask for a password\n"); + printf("\t-s or --conf configfile Specify an alternative config file\n"); + printf("\t-U or --user username Set the network username\n"); + printf("\t-W or --workgroup domain Set the domain name for user account\n"); + printf("\t-I or --dest-ip ip Specify destination IP address\n"); + printf("\n"); +} + /* Main function */ int main(int argc, char *argv[]) @@ -581,6 +599,7 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) static int got_pass = 0; BOOL interactive = True; int opt; + int olddebug; static char *cmdstr = ""; const char *server; struct cli_state *cli; @@ -597,36 +616,41 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) 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"}, - {"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"}, + {"authfile", 'A', POPT_ARG_STRING, &opt_authfile, 'A'}, + {"conf", 's', POPT_ARG_STRING, &opt_configfile, 's'}, + {"nopass", 'N', POPT_ARG_NONE, &got_pass}, + {"user", 'U', POPT_ARG_STRING, &opt_username, 'U'}, + {"workgroup", 'W', POPT_ARG_STRING, &opt_domain, 'W'}, + {"command", 'c', POPT_ARG_STRING, &cmdstr}, + {"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l'}, + {"help", 'h', POPT_ARG_NONE, 0, 'h'}, + {"dest-ip", 'I', POPT_ARG_STRING, &opt_ipaddr, 'I'}, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, { NULL } }; + setlinebuf(stdout); - /* Parse options */ + DEBUGLEVEL = 1; + AllowDebugChange = False; - pc = poptGetContext("rpcclient", argc, (const char **) argv, - long_options, 0); + /* Parse options */ if (argc == 1) { - poptPrintHelp(pc, stderr, 0); + usage(); return 0; } + pc = poptGetContext("rpcclient", argc, (const char **) argv, + long_options, 0); + while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'A': @@ -662,7 +686,7 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) break; } case 'I': - if ( (server_ip.s_addr=inet_addr(opt_ipaddr)) == INADDR_NONE ) { + if (!inet_aton(opt_ipaddr, &server_ip)) { fprintf(stderr, "%s not a valid IP address\n", opt_ipaddr); return 1; @@ -670,6 +694,11 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) case 'W': pstrcpy(domain, opt_domain); break; + + case 'h': + default: + usage(); + exit(1); } } @@ -679,7 +708,7 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) server = poptGetArg(pc); if (!server || poptGetArg(pc)) { - poptPrintHelp(pc, stderr, 0); + usage(); return 1; } @@ -692,9 +721,12 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd) reopen_logs(); /* Load smb.conf file */ - - if (!lp_load(dyn_CONFIGFILE,True,False,False)) + /* FIXME! How to get this DEBUGLEVEL to last over lp_load()? */ + olddebug = DEBUGLEVEL; + if (!lp_load(dyn_CONFIGFILE,True,False,False)) { fprintf(stderr, "Can't load %s\n", dyn_CONFIGFILE); + } + DEBUGLEVEL = olddebug; load_interfaces(); |