From: Theodore Tso Date: Thu, 26 Jan 1995 04:21:45 +0000 (+0000) Subject: Allow the primary port that the KDC listens on be configurable on the X-Git-Tag: krb5-1.0-beta5~804 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64a370c19fb420c84a112effb23925875a6d201f;p=krb5.git Allow the primary port that the KDC listens on be configurable on the command line. If the appropriate /etc/services entries aren't found, use compiled in defaults. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4851 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kdc/ChangeLog b/src/kdc/ChangeLog index 8abd67adb..afa6c3cf3 100644 --- a/src/kdc/ChangeLog +++ b/src/kdc/ChangeLog @@ -1,3 +1,10 @@ +Wed Jan 25 23:20:07 1995 Theodore Y. Ts'o (tytso@dcl) + + * network.c (setup_network), main.c (process_args): Allow the + primary port that the KDC listens on be configurable on the + command line. If the appropriate /etc/services entries + aren't found, use compiled in defaults. + Wed Jan 25 16:54:40 1995 Chris Provenzano (proven@mit.edu) * Removed all narrow types and references to wide.h and narrow.h diff --git a/src/kdc/extern.c b/src/kdc/extern.c index c5ee07b0f..e80994597 100644 --- a/src/kdc/extern.c +++ b/src/kdc/extern.c @@ -55,3 +55,5 @@ krb5_kvno tgs_kvno; static krb5_data tgs_data[3] = { {0, KRB5_TGS_NAME_SIZE, KRB5_TGS_NAME}, {0, 0, 0}}; krb5_principal_data tgs_server_struct = { 0, { 0, 0, 0}, tgs_data, 2, 0}; + +short primary_port = 0; diff --git a/src/kdc/extern.h b/src/kdc/extern.h index cb294aca7..81c5f5ccc 100644 --- a/src/kdc/extern.h +++ b/src/kdc/extern.h @@ -50,4 +50,6 @@ extern krb5_kvno tgs_kvno; extern krb5_principal_data tgs_server_struct; #define tgs_server (&tgs_server_struct) +extern short primary_port; + #endif /* __KRB5_KDC_EXTERN__ */ diff --git a/src/kdc/main.c b/src/kdc/main.c index 5de4b4aa5..12c40f0af 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -133,7 +133,7 @@ void usage(name) char *name; { - fprintf(stderr, "usage: %s [-d dbpathname] [-r dbrealmname] [-R replaycachename ]\n\t[-m] [-k masterkeytype] [-M masterkeyname]\n", name); + fprintf(stderr, "usage: %s [-d dbpathname] [-r dbrealmname] [-R replaycachename ]\n\t[-m] [-k masterkeytype] [-M masterkeyname] [-p port]\n", name); return; } @@ -156,7 +156,7 @@ char **argv; extern char *optarg; - while ((c = getopt(argc, argv, "r:d:mM:k:R:e:")) != EOF) { + while ((c = getopt(argc, argv, "r:d:mM:k:R:e:p:")) != EOF) { switch(c) { case 'r': /* realm name for db */ db_realm = optarg; @@ -177,6 +177,9 @@ char **argv; case 'R': rcname = optarg; break; + case 'p': + primary_port = atoi(optarg); + break; case 'e': kdc_etype = atoi(optarg); break; diff --git a/src/kdc/network.c b/src/kdc/network.c index ed5f2820f..35b350166 100644 --- a/src/kdc/network.c +++ b/src/kdc/network.c @@ -49,6 +49,7 @@ extern char *krb5_kdc_udp_portname; extern char *krb5_kdc_sec_udp_portname; extern int errno; +extern short primary_port; static int udp_port_fd = -1; static int sec_udp_port_fd = -1; @@ -65,22 +66,26 @@ const char *prog; FD_ZERO(&select_fds); select_nfsd = 0; - sp = getservbyname(krb5_kdc_udp_portname, "udp"); - if (!sp) { - com_err(prog, 0, "%s/udp service unknown\n", - krb5_kdc_udp_portname); - return KDC5_NOPORT; + memset((char *)&sin, 0, sizeof(sin)); + if (primary_port) { + sin.sin_port = htons(primary_port); + } else { + sp = getservbyname(krb5_kdc_udp_portname, "udp"); + if (!sp) + sin.sin_port = htons(KRB5_DEFAULT_PORT); + else + sin.sin_port = sp->s_port; } + if ((udp_port_fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { - retval = errno; - com_err(prog, 0, "Cannot create server socket"); - return retval; + retval = errno; + com_err(prog, 0, "Cannot create server socket"); + return retval; } - memset((char *)&sin, 0, sizeof(sin)); - sin.sin_port = sp->s_port; + if (bind(udp_port_fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { retval = errno; - com_err(prog, 0, "Cannot bind server socket"); + com_err(prog, 0, "Cannot bind server socket to fd %d", udp_port_fd); return retval; } FD_SET(udp_port_fd, &select_fds); @@ -94,7 +99,7 @@ const char *prog; return 0; /* No secondary listening port defined */ sp = getservbyname(krb5_kdc_sec_udp_portname, "udp"); - if (!sp) { + if (!sp && sin.sin_port != htons(KRB5_DEFAULT_SEC_PORT)) { com_err(prog, 0, "%s/udp service unknown\n", krb5_kdc_sec_udp_portname); return 0; /* Don't give an error if we can't */ @@ -105,7 +110,7 @@ const char *prog; return 0; /* Don't give an error we we can't do this */ } memset((char *)&sin, 0, sizeof(sin)); - sin.sin_port = sp->s_port; + sin.sin_port = sp ? sp->s_port : htons(KRB5_DEFAULT_SEC_PORT); if (bind(sec_udp_port_fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { com_err(prog, errno, "while trying to bind secondary server socket"); return 0; /* Don't give an error if we can't do this */