From 32589f0ada3aba210233f2821cd4553218148911 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Sat, 16 Sep 1995 07:40:20 +0000 Subject: [PATCH] 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 --- src/appl/sample/sserver/ChangeLog | 7 ++++ 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 7a9b8199b..8d311f66e 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 + + * 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 * configure.in: Don't link with -lkadm. diff --git a/src/appl/sample/sserver/sserver.c b/src/appl/sample/sserver/sserver.c index c7826760a..474a31ba9 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 \n", cname); + sprintf(repbuf, "You are \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); } -- 2.26.2