(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:
		@@ -36,6 +36,7 @@
 | 
				
			|||||||
#ifdef KRB5
 | 
					#ifdef KRB5
 | 
				
			||||||
#include <krb5.h>
 | 
					#include <krb5.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					#include "getarg.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RCSID("$Id$");
 | 
					RCSID("$Id$");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -143,7 +144,6 @@ static RETSIGTYPE	 lostconn (int);
 | 
				
			|||||||
static int	 receive_data (FILE *, FILE *);
 | 
					static int	 receive_data (FILE *, FILE *);
 | 
				
			||||||
static void	 send_data (FILE *, FILE *);
 | 
					static void	 send_data (FILE *, FILE *);
 | 
				
			||||||
static struct passwd * sgetpwnam (char *);
 | 
					static struct passwd * sgetpwnam (char *);
 | 
				
			||||||
static void	 usage(void);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *
 | 
					static char *
 | 
				
			||||||
curdir(void)
 | 
					curdir(void)
 | 
				
			||||||
@@ -195,15 +195,42 @@ parse_auth_level(char *str)
 | 
				
			|||||||
 * Print usage and die.
 | 
					 * 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
 | 
					static void
 | 
				
			||||||
usage (void)
 | 
					usage (int code)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    fprintf (stderr,
 | 
					    arg_printusage(args, num_args, NULL, "");
 | 
				
			||||||
	     "Usage: %s [-d] [-i] [-g guest_umask] [-l] [-p port]"
 | 
					    exit (code);
 | 
				
			||||||
	     " [-t timeout] [-T max_timeout] [-u umask] [-v]"
 | 
					 | 
				
			||||||
	     " [-a auth_level] \n",
 | 
					 | 
				
			||||||
	     __progname);
 | 
					 | 
				
			||||||
    exit (1);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
@@ -212,10 +239,11 @@ main(int argc, char **argv)
 | 
				
			|||||||
    int addrlen, ch, on = 1, tos;
 | 
					    int addrlen, ch, on = 1, tos;
 | 
				
			||||||
    char *cp, line[LINE_MAX];
 | 
					    char *cp, line[LINE_MAX];
 | 
				
			||||||
    FILE *fd;
 | 
					    FILE *fd;
 | 
				
			||||||
	int not_inetd = 0;
 | 
					 | 
				
			||||||
    int port;
 | 
					    int port;
 | 
				
			||||||
    struct servent *sp;
 | 
					    struct servent *sp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int optind = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set_progname (argv[0]);
 | 
					    set_progname (argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef KRB4
 | 
					#ifdef KRB4
 | 
				
			||||||
@@ -229,84 +257,65 @@ main(int argc, char **argv)
 | 
				
			|||||||
	    k_setpag();
 | 
						    k_setpag();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#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");
 | 
						sp = getservbyname("ftp", "tcp");
 | 
				
			||||||
	if(sp)
 | 
						if(sp)
 | 
				
			||||||
	    port = sp->s_port;
 | 
						    port = sp->s_port;
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
	    port = htons(21);
 | 
						    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)
 | 
					    if (maxtimeout < ftpd_timeout)
 | 
				
			||||||
	maxtimeout = ftpd_timeout;
 | 
						maxtimeout = ftpd_timeout;
 | 
				
			||||||
		    break;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case 'T':
 | 
					#if 0
 | 
				
			||||||
		    maxtimeout = atoi(optarg);
 | 
					 | 
				
			||||||
    if (ftpd_timeout > maxtimeout)
 | 
					    if (ftpd_timeout > maxtimeout)
 | 
				
			||||||
	ftpd_timeout = maxtimeout;
 | 
						ftpd_timeout = maxtimeout;
 | 
				
			||||||
		    break;
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case 'u':
 | 
					 | 
				
			||||||
		    {
 | 
					 | 
				
			||||||
			long val = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			val = strtol(optarg, &optarg, 8);
 | 
					    if(interactive_flag)
 | 
				
			||||||
			if (*optarg != '\0' || val < 0)
 | 
					 | 
				
			||||||
			    warnx("bad value for -u");
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			    defumask = val;
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		case 'v':
 | 
					 | 
				
			||||||
		    debug = 1;
 | 
					 | 
				
			||||||
		    break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
		    usage ();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if(not_inetd)
 | 
					 | 
				
			||||||
	mini_inetd (port);
 | 
						mini_inetd (port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@@ -940,6 +949,7 @@ retrieve(char *cmd, char *name)
 | 
				
			|||||||
		closefunc = fclose;
 | 
							closefunc = fclose;
 | 
				
			||||||
		st.st_size = 0;
 | 
							st.st_size = 0;
 | 
				
			||||||
		if(fin == NULL){
 | 
							if(fin == NULL){
 | 
				
			||||||
 | 
							    int save_errno = errno;
 | 
				
			||||||
		    struct cmds {
 | 
							    struct cmds {
 | 
				
			||||||
			const char *ext;
 | 
								const char *ext;
 | 
				
			||||||
			const char *cmd;
 | 
								const char *cmd;
 | 
				
			||||||
@@ -986,7 +996,8 @@ retrieve(char *cmd, char *name)
 | 
				
			|||||||
			closefunc = ftpd_pclose;
 | 
								closefunc = ftpd_pclose;
 | 
				
			||||||
			st.st_size = -1;
 | 
								st.st_size = -1;
 | 
				
			||||||
			cmd = line;
 | 
								cmd = line;
 | 
				
			||||||
		    }
 | 
							    } else
 | 
				
			||||||
 | 
								errno = save_errno;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		snprintf(line, sizeof(line), cmd, name);
 | 
							snprintf(line, sizeof(line), cmd, name);
 | 
				
			||||||
@@ -2067,6 +2078,30 @@ static char *onefile[] = {
 | 
				
			|||||||
	0
 | 
						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
 | 
					void
 | 
				
			||||||
send_file_list(char *whichf)
 | 
					send_file_list(char *whichf)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user