(main): make this use getarg; add `list_file'

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7088 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1999-10-03 16:38:14 +00:00
parent 333c91b357
commit 4baca61c54

View File

@@ -36,6 +36,7 @@
#ifdef KRB5
#include <krb5.h>
#endif
#include "getarg.h"
RCSID("$Id$");
@@ -143,7 +144,6 @@ static RETSIGTYPE lostconn (int);
static int receive_data (FILE *, FILE *);
static void send_data (FILE *, FILE *);
static struct passwd * sgetpwnam (char *);
static void usage(void);
static char *
curdir(void)
@@ -195,15 +195,42 @@ parse_auth_level(char *str)
* Print usage and die.
*/
static int debug_flag;
static int interactive_flag;
static char *guest_umask_string;
static int logflag;
static char *port_string;
static char *umask_string;
static char *auth_string;
int use_builtin_ls;
static int help_flag;
static int version_flag;
struct getargs args[] = {
{ NULL, 'a', arg_string, &auth_string, "required authentication" },
{ NULL, 'i', arg_flag, &interactive_flag, "don't assume stdin is a socket" },
{ NULL, 'p', arg_string, &port_string, "what port to listen to" },
{ NULL, 'g', arg_string, &guest_umask_string, "umask for guest logins" },
{ NULL, 'l', arg_flag, &logflag, "log more stuff" },
{ NULL, 't', arg_integer, &ftpd_timeout, "initial timeout" },
{ NULL, 'T', arg_integer, &maxtimeout, "max timeout" },
{ NULL, 'u', arg_string, &umask_string, "umask for user logins" },
{ NULL, 'd', arg_flag, &debug_flag, "enable debugging" },
{ NULL, 'v', arg_flag, &debug_flag, "enable debugging" },
{ "builtin-ls", 0, arg_flag, &use_builtin_ls, "use built-in ls to list files" },
{ "version", 0, arg_flag, &version_flag },
{ "help", 'h', arg_flag, &help_flag }
};
static int num_args = sizeof(args) / sizeof(args[0]);
static void
usage (void)
usage (int code)
{
fprintf (stderr,
"Usage: %s [-d] [-i] [-g guest_umask] [-l] [-p port]"
" [-t timeout] [-T max_timeout] [-u umask] [-v]"
" [-a auth_level] \n",
__progname);
exit (1);
arg_printusage(args, num_args, NULL, "");
exit (code);
}
int
@@ -212,10 +239,11 @@ main(int argc, char **argv)
int addrlen, ch, on = 1, tos;
char *cp, line[LINE_MAX];
FILE *fd;
int not_inetd = 0;
int port;
struct servent *sp;
int optind = 0;
set_progname (argv[0]);
#ifdef KRB4
@@ -229,84 +257,65 @@ main(int argc, char **argv)
k_setpag();
}
#endif
if(getarg(args, num_args, argc, argv, &optind))
usage(1);
if(help_flag)
usage(0);
if(version_flag) {
print_version(NULL);
exit(0);
}
if(auth_string)
auth_level = parse_auth_level(auth_string);
{
char *p;
long val = 0;
if(guest_umask_string) {
val = strtol(guest_umask_string, &p, 8);
if (*p != '\0' || val < 0)
warnx("bad value for -g");
else
guest_umask = val;
}
if(umask_string) {
val = strtol(umask_string, &p, 8);
if (*p != '\0' || val < 0)
warnx("bad value for -u");
else
defumask = val;
}
}
if(port_string) {
sp = getservbyname(port_string, "tcp");
if(sp)
port = sp->s_port;
else
if(isdigit(port_string[0]))
port = htons(atoi(port_string));
else
warnx("bad value for -p");
} else {
sp = getservbyname("ftp", "tcp");
if(sp)
port = sp->s_port;
else
port = htons(21);
while ((ch = getopt(argc, argv, "a:dg:ilp:t:T:u:v")) != EOF) {
switch (ch) {
case 'a':
auth_level = parse_auth_level(optarg);
break;
case 'd':
debug = 1;
break;
case 'i':
not_inetd = 1;
break;
case 'g':
{
long val = 0;
val = strtol(optarg, &optarg, 8);
if (*optarg != '\0' || val < 0)
warnx("bad value for -g");
else
guest_umask = val;
break;
}
case 'l':
logging++; /* > 1 == extra logging */
break;
case 'p':
sp = getservbyname(optarg, "tcp");
if(sp)
port = sp->s_port;
else
if(isdigit(optarg[0]))
port = htons(atoi(optarg));
else
warnx("bad value for -p");
break;
case 't':
ftpd_timeout = atoi(optarg);
if (maxtimeout < ftpd_timeout)
maxtimeout = ftpd_timeout;
break;
case 'T':
maxtimeout = atoi(optarg);
#if 0
if (ftpd_timeout > maxtimeout)
ftpd_timeout = maxtimeout;
break;
#endif
case 'u':
{
long val = 0;
val = strtol(optarg, &optarg, 8);
if (*optarg != '\0' || val < 0)
warnx("bad value for -u");
else
defumask = val;
break;
}
case 'v':
debug = 1;
break;
default:
usage ();
}
}
if(not_inetd)
if(interactive_flag)
mini_inetd (port);
/*
@@ -940,6 +949,7 @@ retrieve(char *cmd, char *name)
closefunc = fclose;
st.st_size = 0;
if(fin == NULL){
int save_errno = errno;
struct cmds {
const char *ext;
const char *cmd;
@@ -986,7 +996,8 @@ retrieve(char *cmd, char *name)
closefunc = ftpd_pclose;
st.st_size = -1;
cmd = line;
}
} else
errno = save_errno;
}
} else {
snprintf(line, sizeof(line), cmd, name);
@@ -2067,6 +2078,30 @@ static char *onefile[] = {
0
};
void
list_file(const char *file)
{
if(use_builtin_ls) {
FILE *dout;
dout = dataconn(file, -1, "w");
if (dout == NULL)
return;
set_buffer_size(fileno(dout), 0);
builtin_ls(dout, file);
reply(226, "Transfer complete.");
fclose(dout);
data = -1;
pdata = -1;
} else {
#ifdef HAVE_LS_A
char *cmd = "/bin/ls -lA";
#else
char *cmd = "/bin/ls -la";
#endif
retrieve(cmd, file);
}
}
void
send_file_list(char *whichf)
{