diff options
author | Theodore Tso <tytso@mit.edu> | 1995-09-16 07:40:20 +0000 |
---|---|---|
committer | Theodore Tso <tytso@mit.edu> | 1995-09-16 07:40:20 +0000 |
commit | 32589f0ada3aba210233f2821cd4553218148911 (patch) | |
tree | cb5e927b02c19e094ddd53e43bc8a522fdb43fe1 /src/appl/sample | |
parent | 6b73ee11b7296ca0becbbe5a69c5891b651f18d5 (diff) | |
download | krb5-32589f0ada3aba210233f2821cd4553218148911.zip krb5-32589f0ada3aba210233f2821cd4553218148911.tar.gz krb5-32589f0ada3aba210233f2821cd4553218148911.tar.bz2 |
Allow the user to specify the service instance using the -s option.
Use SO_REUSEEADDR so that the port can be immediately reused. Free
the context and auth_context before exiting.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6800 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/appl/sample')
-rw-r--r-- | src/appl/sample/sserver/ChangeLog | 7 | ||||
-rw-r--r-- | src/appl/sample/sserver/sserver.c | 63 |
2 files changed, 44 insertions, 26 deletions
diff --git a/src/appl/sample/sserver/ChangeLog b/src/appl/sample/sserver/ChangeLog index 7a9b819..8d311f6 100644 --- a/src/appl/sample/sserver/ChangeLog +++ b/src/appl/sample/sserver/ChangeLog @@ -1,3 +1,10 @@ +Sat Sep 16 00:21:01 1995 Theodore Y. Ts'o <tytso@dcl> + + * sserver.c (main): Allow the user to specify the service instance + using the -s option. Use SO_REUSEEADDR so that the port + can be immediately reused. Free the context and + auth_context before exiting. + Sat Jul 29 04:39:02 1995 Tom Yu <tlyu@dragons-lair.MIT.EDU> * configure.in: Don't link with -lkadm. diff --git a/src/appl/sample/sserver/sserver.c b/src/appl/sample/sserver/sserver.c index c782676..474a31b 100644 --- a/src/appl/sample/sserver/sserver.c +++ b/src/appl/sample/sserver/sserver.c @@ -56,7 +56,8 @@ void usage(name) char *name; { - fprintf(stderr, "usage: %s [-p port] [-S keytab]\n"); + fprintf(stderr, "usage: %s [-p port] [-s service] [-S keytab]\n", + name); } void @@ -77,12 +78,14 @@ main(argc, argv) krb5_principal server, client; char repbuf[BUFSIZ]; char *cname; + char *service = SAMPLE_SERVICE; 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; + int on = 1; progname = *argv; @@ -92,37 +95,33 @@ main(argc, argv) /* open a log connection */ openlog("sserver", 0, LOG_DAEMON); - if (retval = krb5_sname_to_principal(context, NULL, SAMPLE_SERVICE, - KRB5_NT_SRV_HST, &server)) { - syslog(LOG_ERR, "while generating service name (%s): %s", - SAMPLE_SERVICE, error_message(retval)); - exit(1); - } - /* * 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; + while ((ch = getopt(argc, argv, "p:S:s:")) != EOF) + switch (ch) { + case 'p': + port = atoi(optarg); + break; + case 's': + service = 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; - } + default: + usage(progname); + exit(1); + break; + } argc -= optind; argv += optind; @@ -132,6 +131,13 @@ main(argc, argv) port = atoi(argv[1]); } + if (retval = krb5_sname_to_principal(context, NULL, service, + KRB5_NT_SRV_HST, &server)) { + syslog(LOG_ERR, "while generating service name (%s): %s", + service, error_message(retval)); + exit(1); + } + /* * If user specified a port, then listen on that port; otherwise, * assume we've been started out of inetd. @@ -145,6 +151,9 @@ main(argc, argv) syslog(LOG_ERR, "socket: %m"); exit(3); } + /* Let the socket be reused right away */ + (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, + sizeof(on)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = 0; @@ -192,7 +201,7 @@ main(argc, argv) /* Get client name */ if (retval = krb5_unparse_name(context, ticket->enc_part2->client, &cname)){ syslog(LOG_ERR, "unparse failed: %s", error_message(retval)); - sprintf(repbuf, "You are <unparse error>\n", cname); + sprintf(repbuf, "You are <unparse error>\n"); } else { sprintf(repbuf, "You are %s\n", cname); free(cname); @@ -210,5 +219,7 @@ main(argc, argv) syslog(LOG_ERR, "%m: while writing data to client"); exit(1); } + krb5_auth_con_free(context, auth_context); + krb5_free_context(context); exit(0); } |