|
From: | shishi-commit |
Subject: | Use gengetopt for shishid. [...] |
Date: | Thu, 11 Dec 2003 00:12:33 +0100 |
Commit from jas | 2003-12-11 00:12 CET |
Use gengetopt for shishid. Some cleanups.
Module | File name | Revision | |||
---|---|---|---|---|---|
shishi | src/.cvsignore | 1.6 | >>> | 1.7 | |
shishi | src/Makefile.am | 1.36 | >>> | 1.37 | |
- | shishi | src/gettext.h | 1.1 | ||
shishi | src/shishid.c | 1.58 | >>> | 1.59 | |
+ | shishi | src/shishid.ggo | 1.1 |
shishi/src/.cvsignore 1.6 >>> 1.7 |
---|
Line 7 |
shisa_cmd.c shishi shishid |
+ shishid_cmd.h + shishid_cmd.c |
shishi/src/Makefile.am 1.36 >>> 1.37 |
---|
Line 20 |
AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_srcdir)/db -I../lib |
+ BUILT_SOURCES = shisa_cmd.c shisa_cmd.h shishid_cmd.c shishid_cmd.h + |
bin_PROGRAMS = shishi shisa |
+ sbin_PROGRAMS = shishid |
|
- shishi_SOURCES = shishi.c gettext.h |
+ shishi_SOURCES = shishi.c |
shishi_LDADD = @LIBGCRYPT_LIBS@ @CRYPTO_LIBS@ \ @LTLIBINTL@ ../gl/libfoo.la @LIBTASN1_LIBS@ @LIBGNUTLS_LIBS@ \ ../lib/libshishi.la |
- BUILT_SOURCES = shisa_cmd.c shisa_cmd.h - shisa_SOURCES = shisa.c gettext.h shisa.ggo $(BUILT_SOURCES) |
+ shisa_SOURCES = shisa.c shisa.ggo shisa_cmd.h shisa_cmd.c |
shisa_LDADD = ../db/libshisa.la ../lib/libshishi.la |
- - $(BUILT_SOURCES): shisa.ggo |
+ shisa_cmd.c shisa_cmd.h: shisa.ggo |
gengetopt --unamed-opts --no-handle-help --no-handle-error \ --input $< --file-name shisa_cmd perl -pi -e 's/\[FILES\]/\[REALM \[PRINCIPAL\]\]/g' shisa_cmd.c |
- sbin_PROGRAMS = shishid - shishid_SOURCES = shishid.c |
+ shishid_SOURCES = shishid.c shishid.ggo shishid_cmd.h shishid_cmd.c |
shishid_LDADD = @LIBGCRYPT_LIBS@ @CRYPTO_LIBS@ \ @LTLIBINTL@ ../gl/libfoo.la @LIBTASN1_LIBS@ @LIBGNUTLS_LIBS@ \ ../lib/libshishi.la ../db/libshisa.la |
+ shishid_cmd.c shishid_cmd.h: shishid.ggo + gengetopt --no-handle-help --no-handle-error \ + --input $< --file-name shishid_cmd |
localedir = $(datadir)/locale |
shishi/src/shishid.c 1.58 >>> 1.59 |
---|
Line 20 |
*/ #if HAVE_CONFIG_H |
- #include "config.h" |
+ # include "config.h" |
#endif |
- #ifdef STDC_HEADERS |
#include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <ctype.h> |
- #endif |
#ifdef HAVE_UNISTD_H #include <unistd.h> |
Line 118 |
#include <gnutls/gnutls.h> #endif |
+ #ifdef HAVE_LOCALE_H + # include <locale.h> + #else + # define setlocale(Category, Locale) /* empty */ + #endif + + #include <gettext.h> + #define _(String) gettext (String) + #define gettext_noop(String) String + #define N_(String) gettext_noop (String) + + #include "xalloc.h" + #include "progname.h" + |
#include <shishi.h> #include <shisa.h> |
- #include <argp.h> |
+ + #include "shishid_cmd.h" |
#define FAMILY_IPV4 "IPv4" #define FAMILY_IPV6 "IPv6" |
Line 135 |
#endif #define DH_BITS 1024 |
+ #ifdef USE_STARTTLS + static gnutls_dh_params dh_params; + #endif |
|
- const char *program_name = PACKAGE; |
+ static char *fatal_krberror; + static size_t fatal_krberror_len; |
struct listenspec { |
Line 150 |
size_t bufpos; }; |
- struct arguments - { - int silent, verbose; - char *cfgfile; - char *setuid; - struct listenspec *listenspec; - int nlistenspec; - }; - - const char *argp_program_version = PACKAGE_STRING; - const char *argp_program_bug_address = PACKAGE_BUGREPORT; |
+ Shishi * handle; + Shisa * dbh; + struct gengetopt_args_info arg; + struct listenspec *listenspec; + int nlistenspec; |
|
- static error_t - parse_opt (int key, char *arg, struct argp_state *state) |
+ static void + parse_listen (char *listen) |
{ |
- struct arguments *arguments = state->input; |
char *ptrptr; char *val; int i; |
- switch (key) |
+ for (i = 0; (val = strtok_r (i == 0 ? listen : NULL, ", \t", &ptrptr)); i++) |
{ |
- case 'q': - case 's': - arguments->silent = 1; - break; - - case 'v': - arguments->verbose++; - break; - - case 'c': - arguments->cfgfile = strdup (arg); - break; - - case 'u': - arguments->setuid = strdup (arg); - break; - - case ARGP_KEY_END: - if (arguments->nlistenspec > 0) - break; - arg = strdup (LISTEN_DEFAULT); - /* fall through */ - - case 'l': - for (i = 0; (val = strtok_r (i == 0 ? arg : NULL, ", \t", &ptrptr)); - i++) - { - char *service, *proto; - struct servent *se; - struct hostent *he; - struct listenspec *ls; - struct sockaddr_in *sin; |
+ char *service, *proto; + struct servent *se; + struct hostent *he; + struct listenspec *ls; + struct sockaddr_in *sin; |
#ifdef WITH_IPV6 |
- struct sockaddr_in6 *sin6; |
+ struct sockaddr_in6 *sin6; |
#endif |
- arguments->nlistenspec++; - arguments->listenspec = realloc (arguments->listenspec, - sizeof (*arguments->listenspec) * - arguments->nlistenspec); - if (arguments->listenspec == NULL) - argp_error (state, "Fatal memory allocation error"); - ls = &arguments->listenspec[arguments->nlistenspec - 1]; - memset (ls, 0, sizeof (*ls)); - ls->str = strdup (val); - ls->bufpos = 0; - sin = (struct sockaddr_in *) &ls->addr; |
+ nlistenspec++; + listenspec = xrealloc (listenspec, sizeof (*listenspec) * nlistenspec); + ls = &listenspec[nlistenspec - 1]; + memset (ls, 0, sizeof (*ls)); + ls->str = strdup (val); + ls->bufpos = 0; + sin = (struct sockaddr_in *) &ls->addr; |
#ifdef WITH_IPV6 |
- sin6 = (struct sockaddr_in6 *) &ls->addr; |
+ sin6 = (struct sockaddr_in6 *) &ls->addr; |
#endif |
- proto = strrchr (val, '/'); - if (proto == NULL) - argp_error (state, "Could not find type in listen spec: `%s'", - ls->str); - *proto = '\0'; - proto++; |
+ proto = strrchr (val, '/'); + if (proto == NULL) + error (1, 0, "Could not find type in listen spec: `%s'", ls->str); + *proto = '\0'; + proto++; + + if (strcmp (proto, "tcp") == 0) + ls->type = SOCK_STREAM; + else + ls->type = SOCK_DGRAM; + + service = strrchr (val, ':'); + if (service == NULL) + error (1, 0, "Could not find service in listen spec: `%s'", ls->str); + *service = '\0'; + service++; + + se = getservbyname (service, proto); + if (se) + ls->port = ntohs (se->s_port); + else if (strcmp (service, "kerberos") == 0) + ls->port = 88; + else if (atoi (service) != 0) + ls->port = atoi (service); + else + error (1, 0, "Unknown service `%s' in listen spec: `%s'", + service, ls->str); |
|
- if (strcmp (proto, "tcp") == 0) - ls->type = SOCK_STREAM; - else - ls->type = SOCK_DGRAM; |
+ #ifdef WITH_IPV6 + if (ls->family == AF_INET6) + sin6->sin6_port = htons (ls->port); + else + #endif + sin->sin_port = htons (ls->port); |
|
- service = strrchr (val, ':'); - if (service == NULL) - argp_error (state, "Could not find service in listen spec: `%s'", - ls->str); - *service = '\0'; - service++; - - se = getservbyname (service, proto); - if (se) - ls->port = ntohs (se->s_port); - else if (strcmp (service, "kerberos") == 0) - ls->port = 88; - else if (atoi (service) != 0) - ls->port = atoi (service); - else - argp_error (state, "Unknown service `%s' in listen spec: `%s'", - service, ls->str); |
+ if (strncmp (val, FAMILY_IPV4 ":", strlen (FAMILY_IPV4 ":")) == 0) + { + ls->family = AF_INET; + val += strlen (FAMILY_IPV4 ":"); + } + #ifdef WITH_IPV6 + else if (strncmp (val, FAMILY_IPV6 ":", strlen (FAMILY_IPV6 ":")) == + 0) + { + ls->family = AF_INET6; + val += strlen (FAMILY_IPV6 ":"); + } + #endif + else + ls->family = AF_INET; |
|
+ if (strcmp (val, "*") == 0) + { |
#ifdef WITH_IPV6 if (ls->family == AF_INET6) |
- sin6->sin6_port = htons (ls->port); |
+ sin6->sin6_addr = in6addr_any; |
else #endif |
- sin->sin_port = htons (ls->port); - - if (strncmp (val, FAMILY_IPV4 ":", strlen (FAMILY_IPV4 ":")) == 0) |
+ sin->sin_addr.s_addr = htonl (INADDR_ANY); + } + else if ((he = gethostbyname (val))) + { + if (he->h_addrtype == AF_INET) |
{ |
- ls->family = AF_INET; - val += strlen (FAMILY_IPV4 ":"); |
+ sin->sin_family = AF_INET; + memcpy (&sin->sin_addr, he->h_addr_list[0], he->h_length); |
} #ifdef WITH_IPV6 |
- else if (strncmp (val, FAMILY_IPV6 ":", strlen (FAMILY_IPV6 ":")) == - 0) |
+ else if (he->h_addrtype == AF_INET6) |
{ |
- ls->family = AF_INET6; - val += strlen (FAMILY_IPV6 ":"); |
+ sin6->sin6_family = AF_INET6; + memcpy (&sin6->sin6_addr, he->h_addr_list[0], he->h_length); |
} #endif else |
- ls->family = AF_INET; - - if (strcmp (val, "*") == 0) - { - #ifdef WITH_IPV6 - if (ls->family == AF_INET6) - sin6->sin6_addr = in6addr_any; - else - #endif - sin->sin_addr.s_addr = htonl (INADDR_ANY); - } - else if ((he = gethostbyname (val))) - { - if (he->h_addrtype == AF_INET) - { - sin->sin_family = AF_INET; - memcpy (&sin->sin_addr, he->h_addr_list[0], he->h_length); - } - #ifdef WITH_IPV6 - else if (he->h_addrtype == AF_INET6) - { - sin6->sin6_family = AF_INET6; - memcpy (&sin6->sin6_addr, he->h_addr_list[0], he->h_length); - } - #endif - else - argp_error (state, "Unknown protocol family (%d) returned " - "by gethostbyname(\"%s\"): `%s'", he->h_addrtype, - val, ls->str); - } - else - argp_error (state, "Unknown host `%s' in listen spec: `%s'", - val, ls->str); - |
+ error (1, 0, "Unknown protocol family (%d) returned " + "by gethostbyname(\"%s\"): `%s'", he->h_addrtype, + val, ls->str); |
} |
- break; - - case ARGP_KEY_ARG: - argp_error (state, "Too many arguments: `%s'", arg); - break; - - default: - return ARGP_ERR_UNKNOWN; |
+ else + error (1, 0, "Unknown host `%s' in listen spec: `%s'", val, ls->str); |
} |
- - return 0; |
} |
- static struct argp_option options[] = { - - {"verbose", 'v', 0, 0, - "Produce verbose output.", 0}, - - {"quiet", 'q', 0, 0, - "Don't produce any output.", 0}, - - {"silent", 's', 0, OPTION_ALIAS, - NULL, 0}, - - {"configuration-file", 'c', "FILE", 0, - "Read configuration from file. Default is " SYSTEMCFGFILE ".", 0}, - - {"listen", 'l', "[FAMILY:]ADDRESS:SERVICE/TYPE,...", 0, - "What to listen on. Family is \"IPv4\" or \"IPv6\", if absent the " - "family is decided by gethostbyname(ADDRESS). An address of \"*\" " - "indicates all addresses on the local host. " - "The default is \"" LISTEN_DEFAULT "\".", 0}, - - {"setuid", 'u', "NAME", 0, - "After binding socket, set user identity.", 0}, - - {NULL, 0, NULL, 0, - NULL, 0} - }; - - static struct argp argp = { - options, - parse_opt, - NULL, - "Shishid -- Key Distribution Center network daemon", - NULL, - NULL, - NULL - }; - - static char *fatal_krberror; - static size_t fatal_krberror_len; - #ifdef USE_STARTTLS - static gnutls_dh_params dh_params; - #endif - |
static int setup_fatal_krberror (Shishi * handle) { |
Line 389 |
} static int |
- asreq1 (Shishi * handle, struct arguments *arg, Shishi_as * as) |
+ asreq1 (Shishi_as * as) |
{ Shishi_tkt *tkt; Shishi_key *sessionkey, *userkey; int etype, i; |
- char buf[BUFSIZ]; - size_t buflen; |
int err; char *username, *servername, *realm; |
+ Shisa_principal krbtgt; + Shisa_principal user; |
|
- buflen = sizeof (buf) - 1; - err = shishi_kdcreq_cname_get (handle, shishi_as_req (as), buf, &buflen); |
+ err = shishi_kdcreq_server (handle, shishi_as_req (as), &servername, NULL); |
if (err != SHISHI_OK) return err; |
- buf[buflen] = '\0'; - username = strdup (buf); - printf ("username %s\n", username); |
+ printf ("servername %s\n", servername); |
|
- buflen = sizeof (buf) - 1; - err = shishi_kdcreq_sname_get (handle, shishi_as_req (as), buf, &buflen); |
+ err = shishi_kdcreq_realm (handle, shishi_as_req (as), &realm, NULL); |
if (err != SHISHI_OK) return err; |
- buf[buflen] = '\0'; - servername = strdup (buf); - printf ("servername %s\n", servername); |
+ printf ("client & server realm %s\n", realm); |
|
- buflen = sizeof (buf) - 1; - err = shishi_kdcreq_realm_get (handle, shishi_as_req (as), buf, &buflen); |
+ err = shisa_principal_find (dbh, realm, servername, &krbtgt); + if (err != SHISA_OK) + { + printf ("server address@hidden not found\n", servername, realm); + return SHISHI_INVALID_PRINCIPAL_NAME; + } + + err = shishi_kdcreq_client (handle, shishi_as_req (as), &username, NULL); |
if (err != SHISHI_OK) return err; |
- buf[buflen] = '\0'; - realm = strdup (buf); - printf ("client & server realm %s\n", realm); |
+ printf ("username %s\n", username); + + err = shisa_principal_find (dbh, realm, username, &user); + if (err != SHISA_OK) + { + printf ("user address@hidden not found\n", username, realm); + return SHISHI_INVALID_PRINCIPAL_NAME; + } |
tkt = shishi_as_tkt (as); if (!tkt) |
Line 458 |
#if 0 userkey = shishi_keys_for_serverrealm_in_file (handle, |
- arg->keyfile, |
+ arg.keyfile, |
username, realm); if (!userkey) return !SHISHI_OK; |
- err = shishi_tkt_build (tkt, arg->tgskey); |
+ err = shishi_tkt_build (tkt, arg.tgskey); |
if (err) return err; #endif |
Line 472 |
if (err) return err; |
- if (arg->verbose) |
+ if (arg.verbose_flag) |
{ shishi_kdcreq_print (handle, stderr, shishi_as_req (as)); shishi_encticketpart_print (handle, stderr, |
Line 487 |
} static int |
- asreq (Shishi * handle, struct arguments *arg, - Shishi_asn1 kdcreq, char **out, size_t * outlen) |
+ asreq (Shishi_asn1 kdcreq, char **out, size_t * outlen) |
{ Shishi_as *as; int rc; |
Line 506 |
shishi_as_req_set (as, kdcreq); |
- rc = asreq1 (handle, arg, as); |
+ rc = asreq1 (as); |
if (rc != SHISHI_OK) { syslog (LOG_NOTICE, "Could not answer request: %s: %s\n", |
Line 531 |
} static int |
- tgsreq1 (Shishi * handle, struct arguments *arg, Shishi_tgs * tgs) |
+ tgsreq1 (Shishi_tgs * tgs) |
{ int rc; Shishi_tkt *tkt; |
Line 604 |
#if 0 /* decrypt ticket with our key, and decrypt authenticator using key in tkt */ rc = shishi_ap_req_process_keyusage |
- (shishi_tgs_ap (tgs), arg->tgskey, |
+ (shishi_tgs_ap (tgs), arg.tgskey, |
SHISHI_KEYUSAGE_TGSREQ_APREQ_AUTHENTICATOR); if (rc != SHISHI_OK) return rc; |
Line 621 |
return err; #if 0 serverkey = shishi_keys_for_serverrealm_in_file (handle, |
- arg->keyfile, |
+ arg.keyfile, |
servername, realm); if (!serverkey) return !SHISHI_OK; |
Line 655 |
if (err) return err; |
- if (arg->verbose) |
+ if (arg.verbose_flag) |
{ puts ("KDC-REQ in:"); shishi_kdcreq_print (handle, stderr, shishi_tgs_req (tgs)); |
Line 689 |
} static int |
- tgsreq (Shishi * handle, struct arguments *arg, - Shishi_asn1 kdcreq, char **out, size_t * outlen) |
+ tgsreq (Shishi_asn1 kdcreq, char **out, size_t * outlen) |
{ Shishi_tgs *tgs; int rc; |
Line 708 |
shishi_tgs_req_set (tgs, kdcreq); |
- rc = tgsreq1 (handle, arg, tgs); |
+ rc = tgsreq1 (tgs); |
if (rc != SHISHI_OK) { syslog (LOG_NOTICE, "Could not answer request: %s: %s\n", |
Line 733 |
} static int |
- process_1 (Shishi * handle, struct arguments *arg, - char *in, size_t inlen, char **out, size_t * outlen) |
+ process_1 (char *in, size_t inlen, char **out, size_t * outlen) |
{ Shishi_asn1 node; Shishi_asn1 krberr; |
Line 753 |
switch (shishi_asn1_msgtype (handle, node)) { case SHISHI_MSGTYPE_AS_REQ: |
- rc = asreq (handle, arg, node, out, outlen); |
+ rc = asreq (node, out, outlen); |
break; case SHISHI_MSGTYPE_TGS_REQ: |
- rc = tgsreq (handle, arg, node, out, outlen); |
+ rc = tgsreq (node, out, outlen); |
break; default: |
Line 780 |
} static void |
- process (Shishi * handle, struct arguments *arg, - char *in, int inlen, char **out, size_t * outlen) |
+ process (char *in, int inlen, char **out, size_t * outlen) |
{ int rc; *out = NULL; *outlen = 0; |
- rc = process_1 (handle, arg, in, inlen, out, outlen); |
+ rc = process_1 (in, inlen, out, outlen); |
if (rc != SHISHI_OK || *out == NULL || *outlen == 0) { |
Line 806 |
} static int |
- kdc_listen (struct arguments *arg) |
+ kdc_listen () |
{ struct listenspec *ls; int maxfd = 0; int i; int yes; |
- for (i = 0; i < arg->nlistenspec; i++) |
+ for (i = 0; i < nlistenspec; i++) |
{ |
- ls = &arg->listenspec[i]; |
+ ls = &listenspec[i]; |
|
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("Listening on %s...", ls->str); ls->sockfd = socket (ls->family, ls->type, 0); if (ls->sockfd < 0) { |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("failed\n"); perror ("socket"); ls->sockfd = 0; |
Line 834 |
if (setsockopt (ls->sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof (yes)) < 0) { |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("failed\n"); perror ("setsockopt"); close (ls->sockfd); |
Line 844 |
if (bind (ls->sockfd, &ls->addr, sizeof (ls->addr)) != 0) { |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("failed\n"); perror ("bind"); close (ls->sockfd); |
Line 854 |
if (ls->type == SOCK_STREAM && listen (ls->sockfd, 512) != 0) { |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("failed\n"); perror ("listen"); close (ls->sockfd); |
Line 863 |
} maxfd++; |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("done\n"); } |
Line 873 |
return 1; } |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("Listening on %d ports...\n", maxfd); return 0; } static int |
- kdc_loop (Shishi * handle, struct arguments *arg) |
+ kdc_loop (void) |
{ struct listenspec *ls; fd_set readfds; |
Line 897 |
{ FD_ZERO (&readfds); maxfd = 0; |
- for (i = 0; i < arg->nlistenspec; i++) |
+ for (i = 0; i < nlistenspec; i++) |
{ |
- if (arg->listenspec[i].sockfd >= maxfd) - maxfd = arg->listenspec[i].sockfd + 1; - FD_SET (arg->listenspec[i].sockfd, &readfds); |
+ if (listenspec[i].sockfd >= maxfd) + maxfd = listenspec[i].sockfd + 1; + FD_SET (listenspec[i].sockfd, &readfds); |
} } while ((rc = select (maxfd, &readfds, NULL, NULL, NULL)) == 0); |
Line 913 |
continue; } |
- for (i = 0; i < arg->nlistenspec; i++) - if (FD_ISSET (arg->listenspec[i].sockfd, &readfds)) |
+ for (i = 0; i < nlistenspec; i++) + if (FD_ISSET (listenspec[i].sockfd, &readfds)) |
{ |
- if (arg->listenspec[i].type == SOCK_STREAM && - arg->listenspec[i].family != -1) |
+ if (listenspec[i].type == SOCK_STREAM && + listenspec[i].family != -1) |
{ |
+ struct sockaddr_in *sin; + char *str; + |
fprintf (stderr, "New connection on %s...", |
- arg->listenspec[i].str); |
+ listenspec[i].str); |
/* XXX search for closed fd's before allocating new entry */ |
- arg->listenspec = realloc (arg->listenspec, - sizeof (*arg->listenspec) * - (arg->nlistenspec + 1)); - if (arg->listenspec != NULL) - { - struct sockaddr_in *sin; - char *str; |
+ listenspec = xrealloc (listenspec, sizeof (*listenspec) * + (nlistenspec + 1)); |
|
- arg->nlistenspec++; - ls = &arg->listenspec[arg->nlistenspec - 1]; - ls->bufpos = 0; - ls->type = arg->listenspec[i].type; - ls->family = -1; - length = sizeof (ls->addr); - ls->sockfd = accept (arg->listenspec[i].sockfd, - &ls->addr, &length); - sin = (struct sockaddr_in *) &ls->addr; - str = inet_ntoa (sin->sin_addr); - ls->str = malloc (strlen (arg->listenspec[i].str) + - strlen (" peer ") + strlen (str) + 1); - sprintf (ls->str, "%s peer %s", arg->listenspec[i].str, - str); - puts (ls->str); - } |
+ nlistenspec++; + ls = &listenspec[nlistenspec - 1]; + ls->bufpos = 0; + ls->type = listenspec[i].type; + ls->family = -1; + length = sizeof (ls->addr); + ls->sockfd = accept (listenspec[i].sockfd, &ls->addr, &length); + sin = (struct sockaddr_in *) &ls->addr; + str = inet_ntoa (sin->sin_addr); + ls->str = xmalloc (strlen (listenspec[i].str) + + strlen (" peer ") + strlen (str) + 1); + sprintf (ls->str, "%s peer %s", listenspec[i].str, + str); + puts (ls->str); |
} else { |
- ls = &arg->listenspec[i]; |
+ ls = &listenspec[i]; |
read_bytes = recvfrom (ls->sockfd, ls->buf + ls->bufpos, BUFSIZ - ls->bufpos, 0, &addr, &length); |
- if (arg->listenspec[i].type == SOCK_STREAM && - arg->listenspec[i].family == -1 && read_bytes == 0) |
+ if (listenspec[i].type == SOCK_STREAM && + listenspec[i].family == -1 && read_bytes == 0) |
{ printf ("Peer %s disconnected\n", ls->str); close (ls->sockfd); |
Line 972 |
printf ("Has %d bytes from %s\n", ls->bufpos, ls->str); #ifdef USE_STARTTLS |
- if (arg->listenspec[i].type == SOCK_STREAM && |
+ if (listenspec[i].type == SOCK_STREAM && |
ls->bufpos == 4 && memcmp (ls->buf, "\x70\x00\x00\x01", 4) == 0) { |
Line 988 |
const int kx_prio[] = { GNUTLS_KX_ANON_DH, 0 }; gnutls_anon_server_credentials anoncred; |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("Trying to upgrade to TLS...\n"); sent_bytes = sendto (ls->sockfd, "\x70\x00\x00\x02", 4, |
Line 1012 |
if (ret < 0) { gnutls_deinit (session); |
- if (!arg->silent) - printf ("Handshake has failed %d...\n", - gnutls_strerror (ret)); |
+ if (!arg.quiet_flag) + printf ("Handshake has failed %d: %s\n", + ret, gnutls_strerror (ret)); |
} |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("TLS successful\n"); bzero (buffer, BUFSIZ + 1); |
Line 1036 |
char *p; size_t plen; |
- process (handle, arg, buffer, ret, &p, &plen); |
+ process (buffer, ret, &p, &plen); |
printf ("TLS process %d sending %d\n", ret, plen); |
Line 1052 |
} else #endif |
- if (arg->listenspec[i].type == SOCK_DGRAM || |
+ if (listenspec[i].type == SOCK_DGRAM || |
(ls->bufpos > 4 && ntohl (*(int *) ls->buf) + 4 == ls->bufpos)) { char *p; size_t plen; |
- if (arg->listenspec[i].type == SOCK_STREAM) - process (handle, arg, ls->buf + 4, ls->bufpos - 4, - &p, &plen); |
+ if (listenspec[i].type == SOCK_STREAM) + process (ls->buf + 4, ls->bufpos - 4, &p, &plen); |
else |
- process (handle, arg, ls->buf, ls->bufpos, &p, &plen); |
+ process (ls->buf, ls->bufpos, &p, &plen); |
if (p && plen > 0) { |
Line 1096 |
} static int |
- kdc_setuid (struct arguments *arg) |
+ kdc_setuid (void) |
{ struct passwd *passwd; int rc; |
- if (!arg->setuid) |
+ if (!arg.setuid_given) |
return 0; |
- passwd = getpwnam (arg->setuid); |
+ passwd = getpwnam (arg.setuid_arg); |
if (passwd == NULL) { perror ("setuid: getpwnam"); |
Line 1118 |
return 1; } |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("User identity set to `%s' (%d)...\n", passwd->pw_name, passwd->pw_uid); |
Line 1126 |
} static void |
- kdc_unlisten (struct arguments *arg) |
+ kdc_unlisten (void) |
{ int i; int rc; |
- for (i = 0; i < arg->nlistenspec; i++) - if (arg->listenspec[i].sockfd) |
+ for (i = 0; i < nlistenspec; i++) + if (listenspec[i].sockfd) |
{ |
- if (!arg->silent) - printf ("Closing %s...", arg->listenspec[i].str); - rc = close (arg->listenspec[i].sockfd); |
+ if (!arg.quiet_flag) + printf ("Closing %s...", listenspec[i].str); + rc = close (listenspec[i].sockfd); |
if (rc != 0) { |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("failed\n"); perror ("close"); } |
- else if (!arg->silent) |
+ else if (!arg.quiet_flag) |
printf ("done\n"); } } static int |
- launch (Shishi * handle, struct arguments *arg) |
+ launch (void) |
{ int rc; |
- rc = kdc_listen (arg); |
+ rc = kdc_listen (); |
if (rc != 0) return rc; |
- rc = kdc_setuid (arg); |
+ rc = kdc_setuid (); |
if (rc != 0) return rc; signal (SIGINT, ctrlc); signal (SIGTERM, ctrlc); |
- rc = kdc_loop (handle, arg); |
+ rc = kdc_loop (); |
if (rc != 0) return rc; |
- kdc_unlisten (arg); |
+ kdc_unlisten (); |
return 0; } static int |
- setup (Shishi * handle, Shisa * dbh, struct arguments *arg) |
+ setup (void) |
{ int rc; |
Line 1185 |
return 1; } |
- rc = launch (handle, arg); |
+ rc = launch (); |
return rc; } static int |
- init (struct arguments *arg) |
+ init (void) |
{ |
- Shishi *handle; - Shisa *dbh; |
int rc; #ifdef USE_STARTTLS |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("Initializing GNUTLS...\n"); fflush (stdout); gnutls_global_init (); gnutls_dh_params_init (&dh_params); |
- if (!arg->silent) |
+ if (!arg.quiet_flag) |
printf ("Initializing GNUTLS...done\n"); fflush (stdout); #endif |
- rc = shishi_init_server_with_paths (&handle, arg->cfgfile); |
+ rc = shishi_init_server_with_paths (&handle, arg.configuration_file_arg); |
if (rc != SHISHI_OK) { syslog (LOG_ERR, "Aborting due to library initialization failure\n"); return 1; } |
- if (arg->verbose > 1) |
+ if (arg.verbose_flag > 1) |
shishi_cfg (handle, "verbose"); |
- if (arg->verbose > 2) |
+ if (arg.verbose_flag > 2) |
shishi_cfg (handle, "verbose-noice"); |
- if (arg->verbose > 3) |
+ if (arg.verbose_flag > 3) |
shishi_cfg (handle, "verbose-asn1"); |
- if (arg->verbose > 4) |
+ if (arg.verbose_flag > 4) |
shishi_cfg (handle, "verbose-crypto"); rc = shisa_init (&dbh); |
Line 1234 |
return 1; } |
- rc = setup (handle, dbh, arg); |
+ rc = setup (); |
shisa_done (dbh); shishi_done (handle); |
Line 1245 |
int main (int argc, char *argv[]) { |
- struct arguments arg; |
int rc; |
+ setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + set_program_name (argv[0]); + + if (cmdline_parser (argc, argv, &arg) != 0) + { + error (1, 0, "Try `%s --help' for more information.", argv[0]); + return 1; + } + + if (arg.help_given) + { + cmdline_parser_print_help (); + printf ("\nMandatory arguments to long options are " + "mandatory for short options too.\n\n"); + printf ("Report bugs to <%s>.\n", PACKAGE_BUGREPORT); + return 1; + } + |
#ifdef LOG_PERROR openlog (PACKAGE, LOG_CONS | LOG_PERROR, LOG_DAEMON); #else openlog (PACKAGE, LOG_CONS, LOG_DAEMON); #endif |
- memset ((void *) &arg, 0, sizeof (arg)); - argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, &arg); - - if (!arg.cfgfile) - arg.cfgfile = strdup (SYSTEMCFGFILE); - - rc = init (&arg); - - free (arg.cfgfile); - if (arg.setuid) - free (arg.setuid); |
+ if (!arg.configuration_file_arg) + arg.configuration_file_arg = strdup (SYSTEMCFGFILE); + if (!arg.listen_given) + arg.listen_arg = strdup (LISTEN_DEFAULT); + parse_listen (arg.listen_arg); + + rc = init (); + + free (arg.listen_arg); + free (arg.configuration_file_arg); + if (arg.setuid_arg) + free (arg.setuid_arg); |
closelog (); |
shishi/src/shishid.ggo 1.1 |
---|
Line 0 |
+ ## Process this file with gengetopt to produce shishid_cmd.* + # Copyright (C) 2002, 2003 Simon Josefsson. + # + # This file is part of Shishi. + # + # Shishi is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 2, or (at your option) + # any later version. + # + # Shishi is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with Shishi; see the file COPYING. If not, write to + # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + # Boston, MA 02111-1307, USA. + + package "shishid" + + purpose "Network daemon for issuing Kerberos 5 tickets." + + option "configuration-file" c "Use specified configuration file." string typestr="FILE" no + option "listen" l "Sockets to listen for queries on. Family is `IPv4' or `IPv6', if absent the family is decided by gethostbyname(ADDRESS). An address of `*' indicates all addresses on the local host. The default is `IPv4:*:kerberos/udp, IPv4:*:kerberos/tcp, IPv6:*:kerberos/udp, IPv6:*:kerberos/tcp'." string typestr="[FAMILY:]ADDRESS:SERVICE/TYPE" no + option "setuid" u "After binding socket, set user identity." string typestr="NAME" no + + option "verbose" v "Produce verbose output.\n" flag off + option "quiet" q "Don't produce any diagnostic output.\n" flag off |
[Prev in Thread] | Current Thread | [Next in Thread] |