summaryrefslogtreecommitdiff
path: root/source3/rpcclient/rpcclient.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-04-17 06:43:47 +0000
committerTim Potter <tpot@samba.org>2002-04-17 06:43:47 +0000
commit67d99a88c4f8dbb49a62bace4b1619465b7a50f4 (patch)
treee9dfbf948133db78ab6fdc4e6f2ba3107d68cb7e /source3/rpcclient/rpcclient.c
parent0e6ac42b4d6debba880190e6a1cdad3ac87dd0cc (diff)
downloadsamba-67d99a88c4f8dbb49a62bace4b1619465b7a50f4.tar.gz
samba-67d99a88c4f8dbb49a62bace4b1619465b7a50f4.tar.bz2
samba-67d99a88c4f8dbb49a62bace4b1619465b7a50f4.zip
Fixed command line argument parsing.
(This used to be commit 28c1fae4d89399ec4d15bfb3ccd17d8b5b0495fc)
Diffstat (limited to 'source3/rpcclient/rpcclient.c')
-rw-r--r--source3/rpcclient/rpcclient.c124
1 files changed, 54 insertions, 70 deletions
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 7d49e7a9cb..1b3d0a756d 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -594,19 +594,16 @@ static void usage(void)
int main(int argc, char *argv[])
{
- extern char *optarg;
- extern int optind;
extern pstring global_myname;
static int got_pass = 0;
BOOL interactive = True;
int opt;
int olddebug;
- static char *cmdstr = "";
+ static char *cmdstr = "", *server;
struct cli_state *cli;
fstring password="",
username="",
- domain="",
- server="";
+ domain="";
static char *opt_authfile=NULL,
*opt_username=NULL,
*opt_domain=NULL,
@@ -649,78 +646,65 @@ static void usage(void)
return 0;
}
- if (strncmp("//", argv[1], 2) == 0 || strncmp("\\\\", argv[1], 2) == 0)
- argv[1] += 2;
-
- pstrcpy(server, argv[1]);
+ pc = poptGetContext("rpcclient", argc, (const char **) argv,
+ long_options, 0);
+
+ 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 's':
+ pstrcpy(dyn_CONFIGFILE, opt_configfile);
+ break;
+
+ case 'd':
+ DEBUGLEVEL = opt_debuglevel;
+ break;
+
+ case 'U': {
+ char *lp;
- argv++;
- argc--;
+ pstrcpy(username,opt_username);
- pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
-
- while (argc > optind) {
- 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 's':
- pstrcpy(dyn_CONFIGFILE, opt_configfile);
- break;
-
- case 'd':
- DEBUGLEVEL = opt_debuglevel;
- break;
-
- case 'U': {
- char *lp;
- pstrcpy(username,opt_username);
- if ((lp=strchr_m(username,'%'))) {
- *lp = 0;
- pstrcpy(password,lp+1);
- got_pass = 1;
- memset(strchr_m(opt_username,'%')+1,'X',strlen(password));
- }
- break;
- }
-
- case 'W':
- pstrcpy(domain, opt_domain);
- break;
-
- case 'h':
- default:
- usage();
- exit(1);
+ if ((lp=strchr_m(username,'%'))) {
+ *lp = 0;
+ pstrcpy(password,lp+1);
+ got_pass = 1;
+ memset(strchr_m(opt_username,'%') + 1, 'X',
+ strlen(password));
}
+ break;
}
-
- if (argc > optind) {
- if (strncmp("//", argv[optind], 2) == 0 ||
- strncmp("\\\\", argv[optind], 2) == 0)
- {
- argv[optind] += 2;
- }
-
- pstrcpy(server, argv[optind]);
- optind ++;
+
+ case 'W':
+ pstrcpy(domain, opt_domain);
+ break;
+
+ case 'h':
+ default:
+ usage();
+ exit(1);
}
}
- if (!server[0]) {
+ /* Get server as remaining unparsed argument. Print usage if more
+ than one unparsed argument is present. */
+
+ server = poptGetArg(pc);
+
+ if (!server || poptGetArg(pc)) {
usage();
return 1;
}