Use getarg.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3310 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-08-31 17:45:11 +00:00
parent 7cd9fec174
commit d4f46d9de4

View File

@@ -16,7 +16,6 @@ krb4_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
char instance[INST_SZ]; char instance[INST_SZ];
char version[9]; char version[9];
int auth; int auth;
u_char buf2[BUFSIZ];
if (memcmp (buf, KRB_SENDAUTH_VERS, 4) != 0) if (memcmp (buf, KRB_SENDAUTH_VERS, 4) != 0)
return -1; return -1;
@@ -138,6 +137,32 @@ plain_authenticate (POP *p, struct sockaddr_in *addr)
return(POP_SUCCESS); return(POP_SUCCESS);
} }
static int kerberos_flag;
static char *auth_str;
static int debug_flag;
static interactive_flag;
static char *port_str;
static char *trace_file;
static int timeout;
static int help_flag;
static int version_flag;
static struct getargs args[] = {
#ifdef KERBEROS
{ "kerberos", 'k', arg_flag, &kerberos_flag, "use kerberos" },
#endif
{ "auth-mode", 'a', arg_string, &auth_str, "required authentication" },
{ "debug", 'd', arg_flag, &debug_flag },
{ "interactive", 'i', arg_flag, &interactive_flag, "create new socket" },
{ "port", 'p', arg_string, &port_str, "port to listen to", "port" },
{ "trace-file", 't', arg_string, &trace_file, "trace all command to file", "file" },
{ "timeout", 'T', arg_integer, &timeout, "timeout", "seconds" },
{ "help", 'h', arg_flag, &help_flag },
{ "version", 'v', arg_flag, &version_flag }
};
static int num_args = sizeof(args) / sizeof(args[0]);
/* /*
* init: Start a Post Office Protocol session * init: Start a Post Office Protocol session
*/ */
@@ -148,101 +173,82 @@ pop_init(POP *p,int argcount,char **argmessage)
struct sockaddr_in cs; /* Communication parameters */ struct sockaddr_in cs; /* Communication parameters */
struct hostent * ch; /* Client host information */ struct hostent * ch; /* Client host information */
int errflag = 0;
int c;
int len; int len;
int options = 0;
char * trace_file_name = "/tmp/popper-trace"; char * trace_file_name = "/tmp/popper-trace";
int inetd = 0;
int portnum = 0; int portnum = 0;
int optind = 0;
/* Initialize the POP parameter block */ /* Initialize the POP parameter block */
memset (p, 0, sizeof(POP)); memset (p, 0, sizeof(POP));
set_progname(argmessage[0]);
/* Save my name in a global variable */ /* Save my name in a global variable */
p->myname = argmessage[0]; p->myname = (char*)__progname;
/* Get the name of our host */ /* Get the name of our host */
gethostname(p->myhost,MaxHostNameLen); gethostname(p->myhost,MaxHostNameLen);
#ifdef KERBEROS
krb5_init_context (&p->context);
krb5_openlog(p->context, p->myname, &p->logf);
krb5_set_warn_dest(p->context, p->logf);
#else
/* Open the log file */ /* Open the log file */
openlog(p->myname,POP_LOGOPTS,POP_FACILITY); openlog(p->myname,POP_LOGOPTS,POP_FACILITY);
#endif
p->auth_level = AUTH_NONE; p->auth_level = AUTH_NONE;
/* Process command line arguments */ if(getarg(args, num_args, argcount, argmessage, &optind)){
while ((c = getopt(argcount,argmessage, arg_printusage(args, num_args, "");
#ifdef KERBEROS exit(1);
"k" }
#endif if(help_flag){
"a:dip:T:t:")) != EOF) arg_printusage(args, num_args, "");
switch (c) { exit(0);
/* Auth level */ }
case 'a': if(version_flag)
if (strcmp (optarg, "none") == 0) krb5_errx(p->context, 0, "%s", heimdal_version);
p->auth_level = AUTH_NONE;
else if(strcmp(optarg, "otp") == 0)
p->auth_level = AUTH_OTP;
else
warnx ("bad value for -a: %s", optarg);
break;
/* Debugging requested */
case 'd':
p->debug++;
options |= SO_DEBUG;
break;
/* Port number */ if(auth_str){
case 'p': if (strcmp (auth_str, "none") == 0)
portnum = htons(atoi(optarg)); p->auth_level = AUTH_NONE;
break; else if(strcmp(auth_str, "otp") == 0)
/* Debugging trace file specified */ p->auth_level = AUTH_OTP;
case 't': else
p->debug++; warnx ("bad value for -a: %s", optarg);
if ((p->trace = fopen(optarg,"a+")) == NULL) { }
pop_log(p,POP_PRIORITY, /* Debugging requested */
"Unable to open trace file \"%s\", err = %d", p->debug = debug_flag;
optarg,errno);
exit (1);
}
trace_file_name = optarg;
break;
#ifdef KERBEROS if(port_str)
/* Use kerberos version of POP3 protocol */ portnum = htons(atoi(port_str));
case 'k': if(trace_file){
p->kerberosp = 1; p->debug++;
break; if ((p->trace = fopen(trace_file, "a+")) == NULL) {
#endif pop_log(p, POP_PRIORITY,
"Unable to open trace file \"%s\", err = %d",
/* Timeout value passed. Default changed */ optarg,errno);
case 'T': exit (1);
pop_timeout = atoi(optarg); }
break; trace_file_name = trace_file;
/* Fake inetd */
case 'i':
inetd = 1;
break;
/* Unknown option received */
default:
errflag++;
}
/* Exit if bad options specified */
if (errflag) {
fprintf(stderr,
"Usage: %s [-T timeout] [-a] [-d] [-k] [-i] [-t tracefile]\n",
argmessage[0]);
exit (1);
} }
#ifdef KERBEROS
p->kerberosp = kerberos_flag;
#endif
if(timeout)
pop_timeout = timeout;
/* Fake inetd */ /* Fake inetd */
if (inetd) { if (interactive_flag) {
if (portnum == 0) if (portnum == 0)
portnum = p->kerberosp ? portnum = p->kerberosp ?
krb5_getportbyname("kpop", "tcp", htons(1109)) : krb5_getportbyname(p->context, "kpop", "tcp", 1109) :
krb5_getportbyname("pop", "tcp", htons(110)); krb5_getportbyname(p->context, "pop", "tcp", 110);
mini_inetd (portnum); mini_inetd (portnum);
} }
@@ -333,9 +339,6 @@ pop_init(POP *p,int argcount,char **argmessage)
pop_log(p,POP_PRIORITY,"Debugging turned on"); pop_log(p,POP_PRIORITY,"Debugging turned on");
#endif /* DEBUG */ #endif /* DEBUG */
#ifdef KERBEROS
krb5_init_context (&p->context);
#endif
return((p->kerberosp ? krb_authenticate : plain_authenticate)(p, &cs)); return((p->kerberosp ? krb_authenticate : plain_authenticate)(p, &cs));
} }