Problem with getopt() in rpcclient.c

Andrew Bartlett abartlet at pcug.org.au
Fri Dec 7 15:26:01 GMT 2001


> "Woodrich, Jason D (Jason)" wrote:
> 
> I'm having a problem with rpcclient in samba 2.2.2.  No matter what
> commandline options I execute it with the options are not processed.
> I've experienced the same problem from the source distribution and the
> binary distribution, but only on this machine I'm trying to run it on.
> 
> Here's what I'm running it on:
>         Solaris 2.6 (SPARC)
>         GLIBC 2.95.2
> 
> Forgive me for the length of this message, I'm trying to make it as
> easy to understand as possible.
> 
> I made the following modifications to rpcclient/rpcclient.c for
> testing purposes:
> 
>  int main(int argc, char *argv[])
> {
>         extern char             *optarg;
>         extern int              optind;
>         extern pstring          global_myname;
>         BOOL                    got_pass = False;
>         BOOL                    interactive = True;
>         int                     opt;
>         int                     olddebug;
>         pstring                 cmdstr = "",
>                                 servicesf = CONFIGFILE;
>         struct ntuser_creds     creds;
>         struct cli_state        cli;
>         fstring                 password,
>                                 username,
>                                 domain,
>                                 server;
>         int i;
>         struct cmd_set **cmd_set;
> 
>         charset_initialise();
>         setlinebuf(stdout);
> 
>         DEBUGLEVEL = 1;
>         printf("arguments: %d\n",argc);
>         for (i=0;i<argc;i++) { printf("arg[%d]=(%s)\n",i,argv[i]); }
> 
>         while ((opt = getopt(argc, argv, "A:s:Nd:U:W:c:l:")) != EOF) {
> 
>                 printf("processing opt: %d\n",opt);
>                 switch (opt) {
>                 case 'A':
>                         /* only get the username, password, and domain
> from the file */
>                         read_authfile (optarg, username, password,
> domain);
>                         if (strlen (password))
>                                 got_pass = True;
>                         break;
> 
>                 case 'c':
>                         pstrcpy(cmdstr, optarg);
>                         break;
> 
>                 case 'd':
>                         DEBUGLEVEL = atoi(optarg);
>                         break;
> 
>                 case 'l':
>                         slprintf(debugf, sizeof(debugf) - 1,
> "%s.client", optarg);
>                         interactive = False;
>                         break;
> 
>                 case 'N':
>                         got_pass = True;
>                         break;
> 
>                 case 's':
>                         pstrcpy(servicesf, optarg);
>                         break;
> 
>                 case 'U': {
>                         char *lp;
>                         printf("processing optarg as [%s]\n",optarg);
>                         pstrcpy(username,optarg);
>                         if ((lp=strchr(username,'%'))) {
>                                 *lp = 0;
>                                 pstrcpy(password,lp+1);
>                                 got_pass = True;
> 
> memset(strchr(optarg,'%')+1,'X',strlen(password));
>                         }
>                         break;
>                 }
> 
>                 case 'W':
>                         pstrcpy(domain, optarg);
>                         break;
> 
>                 case 'h':
>                 default:
>                         usage();
>                         exit(1);
>                 }
>         }
>         printf("OPT: %d EOF: %d\n",opt,EOF);
> ---
> This is what is returned:
> 
> root at myserver > ./rpcclient 192.168.0.1 -d 10 -c quit -N -U
> jasonw%mypassword -W DOMAINNAME
> arguments: 11
> arg[0]=(./rpcclient)
> arg[1]=(192.168.0.1)
> arg[2]=(-d)
> arg[3]=(10)
> arg[4]=(-c)
> arg[5]=(quit)
> arg[6]=(-N)
> arg[7]=(-U)
> arg[8]=(jasonw%mypassword)
> arg[9]=(-W)
> arg[10]=(DOMAINNAME)
> OPT: -1 EOF: -1
> INFO: Debug class all level = 3   (pid 23890 from pid 23890)
> username: root
> password:
> Enter Password:
> ---
> As you can see from the source, it should say "processing opt:" with
> the results from getopt() in each loop from the while() statement, but
> it doesn't.
> 
> Has anyone else experienced this problem?

Did I miss the 'today is rpcclient getopt() day' or somthing?  See my
reply to the similar message on samba at samba.org:  That is, getopt() may
well be broken, and a patch to convert rpcclient to popt would go down
very nicely.  (Popt is much nicer to work with, and still works when the
first argument doesn't have a - on it, or so I understand).

Send patches to samba-patches at samba.org (instructions at
samba.org/samba-patches) and I hope someone else on the team will be
able to pick it up.

Andrew Bartlett

-- 
Andrew Bartlett                                 abartlet at pcug.org.au
Manager, Authentication Subsystems, Samba Team  abartlet at samba.org
Student Network Administrator, Hawker College   abartlet at hawkerc.net
http://samba.org     http://build.samba.org     http://hawkerc.net




More information about the samba-technical mailing list