From: Ezra Peisach Date: Wed, 10 May 1995 20:25:27 +0000 (+0000) Subject: Add new options -p and -S to specify port and keytab files X-Git-Tag: krb5-1.0-beta6~2007 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1efdd614747a471e0b9671b72ced24ac4c663974;p=krb5.git Add new options -p and -S to specify port and keytab files for use by dejagnu tests. Manual page updated as well. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5790 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/appl/sample/sserver/ChangeLog b/src/appl/sample/sserver/ChangeLog index 21610c2f4..14a79dab7 100644 --- a/src/appl/sample/sserver/ChangeLog +++ b/src/appl/sample/sserver/ChangeLog @@ -1,3 +1,10 @@ +Wed May 10 15:18:19 1995 Ezra Peisach (epeisach@kangaroo.mit.edu) + + * sserver.M: Document options. + + * sserver.c: (main): Add options -p port, -S keytab for use by + dejagnu. Cleaned up warnings in compile. + Wed May 03 03:30:51 1995 Chris Provenzano (proven@mit.edu) * sserver.c: (krb5_recvauth()): No longer needs the rc_type arg. diff --git a/src/appl/sample/sserver/sserver.M b/src/appl/sample/sserver/sserver.M index 2c7070a4d..0debcb739 100644 --- a/src/appl/sample/sserver/sserver.M +++ b/src/appl/sample/sserver/sserver.M @@ -26,6 +26,10 @@ sserver \- sample Kerberos version 5 server .SH SYNOPSIS .B sserver [ +.I \-p +port ] [ +.I \-S +keytab ] [ .I server_port ] .br @@ -46,6 +50,10 @@ the program. The srvtab file is installed in whatever directory is defined by V5Srvtabdir (usually /etc) as "v5srvtab". .PP +The +.B \-S +option allows for a different srvtab than the default. +.PP \fIsserver\fP is normally invoked out of .IR inetd(8), using a line in diff --git a/src/appl/sample/sserver/sserver.c b/src/appl/sample/sserver/sserver.c index 5c04937a7..d97f5febd 100644 --- a/src/appl/sample/sserver/sserver.c +++ b/src/appl/sample/sserver/sserver.c @@ -38,6 +38,7 @@ #include "com_err.h" #include +#include #include #include #include @@ -51,6 +52,13 @@ extern krb5_deltat krb5_clockskew; #define DEBUG +void +usage(name) + char *name; +{ + fprintf(stderr, "usage: %s [-p port] [-S keytab]\n"); +} + void main(argc, argv) int argc; @@ -69,6 +77,14 @@ main(argc, argv) krb5_principal server, client; char repbuf[BUFSIZ]; char *cname; + short port = 0; /* If user specifies port */ + extern int opterr, optind; + extern char * optarg; + int ch; + krb5_keytab keytab = NULL; /* Allow specification on command line */ + char *progname; + + progname = *argv; krb5_init_context(&context); krb5_init_ets(context); @@ -84,10 +100,44 @@ main(argc, argv) } /* - * If user specified a port, then listen on that port; otherwise, - * assume we've been started out of inetd. + * Parse command line arguments + * */ + opterr = 0; + while ((ch = getopt(argc, argv, "p:S:")) != EOF) + switch (ch) { + case 'p': + port = atoi(optarg); + break; + case 'S': + if (retval = krb5_kt_resolve(context, optarg, &keytab)) { + com_err(progname, retval, + "while resolving keytab file %s", optarg); + exit(2); + } + break; + + case '?': + default: + usage(progname); + exit(1); + break; + } + + argc -= optind; + argv += optind; + + /* Backwards compatibility, allow port to be specified at end */ if (argc > 1) { + port = atoi(argv[1]); + } + + /* + * If user specified a port, then listen on that port; otherwise, + * assume we've been started out of inetd. + */ + + if (port) { int acc; struct sockaddr_in sin; @@ -98,8 +148,8 @@ main(argc, argv) sin.sin_family = AF_INET; sin.sin_addr.s_addr = 0; - sin.sin_port = htons(atoi(argv[1])); - if (bind(sock, &sin, sizeof(sin))) { + sin.sin_port = htons(port); + if (bind(sock, (struct sockaddr *) &sin, sizeof(sin))) { syslog(LOG_ERR, "bind: %m"); exit(3); } @@ -132,7 +182,7 @@ main(argc, argv) if (retval = krb5_recvauth(context, &auth_context, (krb5_pointer)&sock, SAMPLE_VERSION, server, 0, /* no flags */ - NULL, /* default keytab */ + keytab, /* default keytab is NULL */ &ticket)) { syslog(LOG_ERR, "recvauth failed--%s", error_message(retval)); exit(1);