From: Mitchell Berger Date: Fri, 3 Aug 2001 07:46:05 +0000 (+0000) Subject: * ftpd.c (main): Convert to do option parsing with getopt() rather X-Git-Tag: krb5-1.3-alpha1~1142 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8708daaea59a74b12a7a097c59c8337a9844afb3;p=krb5.git * ftpd.c (main): Convert to do option parsing with getopt() rather than the whitespace-sensitive voodoo we've used in the past. This fixes a bug where use of -u to set a default umask silently failed and granted more permission on files than desired if the -u and the mode were separated by a space, and likely many other such bugs. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13670 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/appl/gssftp/ftpd/ChangeLog b/src/appl/gssftp/ftpd/ChangeLog index 0a5b04445..5370419d7 100644 --- a/src/appl/gssftp/ftpd/ChangeLog +++ b/src/appl/gssftp/ftpd/ChangeLog @@ -1,3 +1,11 @@ +2001-08-03 Mitchell Berger + + * ftpd.c (main): Convert to do option parsing with getopt() rather + than the whitespace-sensitive voodoo we've used in the past. This + fixes a bug where use of -u to set a default umask silently failed and + granted more permission on files than desired if the -u and the mode + were separated by a space, and likely many other such bugs. + 2001-07-04 Ezra Peisach * ftpd.c: Provide prototypes for myoob and lostconn. diff --git a/src/appl/gssftp/ftpd/ftpd.c b/src/appl/gssftp/ftpd/ftpd.c index 4ad23f239..1aaa8f011 100644 --- a/src/appl/gssftp/ftpd/ftpd.c +++ b/src/appl/gssftp/ftpd/ftpd.c @@ -288,8 +288,14 @@ main(argc, argv, envp) char *argv[]; char **envp; { - int addrlen, on = 1, tos, port = -1; - char *cp; + int addrlen, c, on = 1, tos, port = -1; + extern char *optarg; + extern int optopt; +#ifdef KRB5_KRB4_COMPAT + char *option_string = "AaCcdlp:r:s:T:t:U:u:vw:"; +#else /* !KRB5_KRB4_COMPAT */ + char *option_string = "AaCcdlp:r:T:t:U:u:vw:"; +#endif /* KRB5_KRB4_COMPAT */ ftpusers = _PATH_FTPUSERS_DEFAULT; #ifdef KRB5_KRB4_COMPAT @@ -313,9 +319,8 @@ main(argc, argv, envp) #endif #endif - argc--, argv++; - while (argc > 0 && *argv[0] == '-') { - for (cp = &argv[0][1]; *cp; cp++) switch (*cp) { + while ((c = getopt(argc, argv, option_string)) != -1) { + switch (c) { case 'v': debug = 1; @@ -346,89 +351,55 @@ main(argc, argv, envp) break; case 'p': - if (*++cp != '\0') - port = atoi(cp); - else if (argc > 1) { - argc--, argv++; - port = atoi(*argv); - } - else - fprintf(stderr, "ftpd: -p expects argument\n"); - goto nextopt; + port = atoi(optarg); + break; case 'r': - if (*++cp != '\0') - setenv("KRB_CONF", cp, 1); - else if (argc > 1) { - argc--, argv++; - setenv("KRB_CONF", *argv, 1); - } - else - fprintf(stderr, "ftpd: -r expects argument\n"); - goto nextopt; + setenv("KRB_CONF", optarg, 1); + break; #ifdef KRB5_KRB4_COMPAT case 's': - if (*++cp != '\0') - keyfile = cp; - else if (argc > 1) { - argc--, argv++; - keyfile = *argv; - } - else - fprintf(stderr, "ftpd: -s expects argument\n"); - goto nextopt; - + keyfile = optarg; + break; #endif /* KRB5_KRB4_COMPAT */ + case 't': - timeout = atoi(++cp); + timeout = atoi(optarg); if (maxtimeout < timeout) maxtimeout = timeout; - goto nextopt; + break; case 'T': - maxtimeout = atoi(++cp); + maxtimeout = atoi(optarg); if (timeout > maxtimeout) timeout = maxtimeout; - goto nextopt; + break; case 'u': - { - int val = 0; - - while (*++cp && *cp >= '0' && *cp <= '9') - val = val*8 + *cp - '0'; - if (*cp) - fprintf(stderr, "ftpd: Bad value for -u\n"); - else - defumask = val; - goto nextopt; - } + { + int val = 0; + char *umask_val = optarg; + + while (*umask_val >= '0' && *umask_val <= '9') { + val = val*8 + *umask_val - '0'; + umask_val++; + } + if (*umask_val != ' ' && *umask_val != '\0') + fprintf(stderr, "ftpd: Bad value for -u\n"); + else + defumask = val; + break; + } case 'U': - if (*++cp != '\0') - ftpusers = cp; - else if (argc > 1) { - argc--, argv++; - ftpusers = *argv; - } - else - fprintf(stderr, "ftpd: -U expects argument\n"); - goto nextopt; + ftpusers = optarg; + break; case 'w': { char *foptarg; - if (*++cp != '\0') - foptarg = cp; - else if (argc > 1) { - argc--; - argv++; - foptarg = *argv; - } else { - fprintf(stderr, "ftpd: -w expects arg\n"); - exit(1); - } + foptarg = optarg; if (!strcmp(foptarg, "ip")) always_ip = 1; @@ -451,15 +422,13 @@ main(argc, argv, envp) maxhostlen = atoi(foptarg); } } - goto nextopt; + break; } default: fprintf(stderr, "ftpd: Unknown flag -%c ignored.\n", - *cp); + (char)optopt); break; } -nextopt: - argc--, argv++; } if (port != -1) {