diff --git a/kdc/hprop.c b/kdc/hprop.c index 81edb5c9a..3d96f546d 100644 --- a/kdc/hprop.c +++ b/kdc/hprop.c @@ -67,30 +67,53 @@ static int kaspecials_flag; static int open_socket(krb5_context context, const char *hostname) { - int s; - struct hostent *hp; - struct sockaddr_in sin; - s = socket(AF_INET, SOCK_STREAM, 0); - if(s < 0){ - warn("socket"); - return -1; - } - hp = roken_gethostbyname(hostname); + struct hostent *hp = NULL; + int error; + int af; + char **h; + int port; + +#ifdef HAVE_IPV6 + if (hp == NULL) + hp = getipnodebyname (hostname, AF_INET6, 0, &error); +#endif + if (hp == NULL) + hp = getipnodebyname (hostname, AF_INET, 0, &error); + if(hp == NULL){ - warnx("%s: %s", hostname, hstrerror(h_errno)); - close(s); + warnx("%s: %s", hostname, hstrerror(error)); return -1; } - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = krb5_getportbyname (context, "hprop", "tcp", HPROP_PORT); - memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); - if(connect(s, (struct sockaddr*)&sin, sizeof(sin)) < 0){ - warn("connect"); - close(s); - return -1; + + port = krb5_getportbyname (context, "hprop", "tcp", HPROP_PORT); + + af = hp->h_addrtype; + + for (h = hp->h_addr_list; *h != NULL; ++h) { + int s; + struct sockaddr_storage sa_ss; + struct sockaddr *sa = (struct sockaddr *)&sa_ss; + + s = socket(af, SOCK_STREAM, 0); + if(s < 0){ + warn("socket"); + freehostent (hp); + return -1; + } + + sa->sa_family = af; + socket_set_address_and_port (sa, *h, port); + + if (connect (s, sa, socket_sockaddr_size(sa)) < 0) { + warn ("connect(%s)", hostname); + close (s); + continue; + } + freehostent (hp); + return s; } - return s; + freehostent (hp); + return -1; } struct prop_data{ @@ -158,6 +181,10 @@ v4_prop(void *arg, Principal *p) ent.keys.len = 3; ent.keys.val = malloc(ent.keys.len * sizeof(*ent.keys.val)); ent.keys.val[0].mkvno = NULL; +#if 0 + ent.keys.val[0].mkvno = malloc (sizeof(*ent.keys.val[0].mkvno)); + *(ent.keys.val[0].mkvno) = p->kdc_key_ver; /* XXX */ +#endif ent.keys.val[0].salt = calloc(1, sizeof(*ent.keys.val[0].salt)); ent.keys.val[0].salt->type = pa_pw_salt; ent.keys.val[0].key.keytype = ETYPE_DES_CBC_MD5; diff --git a/kdc/hpropd.c b/kdc/hpropd.c index 86840bfb5..27c997bf0 100644 --- a/kdc/hpropd.c +++ b/kdc/hpropd.c @@ -145,46 +145,6 @@ dump_krb4(krb5_context context, hdb_entry *ent, int fd) } #endif /* KRB4 */ -static int -open_socket(krb5_context context) -{ - int s, s2; - int sin_len; - struct sockaddr_in sin; - int one = 1; - - sin_len = sizeof(sin); - if(getpeername(0, (struct sockaddr*)&sin, &sin_len)){ - s = socket(AF_INET, SOCK_STREAM, 0); - if(s < 0){ - krb5_warn(context, errno, "socket"); - return -1; - } - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = krb5_getportbyname (context, "hprop", "tcp", - HPROP_PORT); - if(bind(s, (struct sockaddr*)&sin, sizeof(sin)) < 0){ - krb5_warn(context, errno, "bind"); - close(s); - return -1; - } - if(listen(s, 5) < 0){ - krb5_warn(context, errno, "listen"); - close(s); - return -1; - } - - s2 = accept(s, NULL, 0); - if(s2 < 0) - krb5_warn(context, errno, "accept"); - close(s); - return s2; - } - return 0; -} - static int help_flag; static int version_flag; static int print_dump; @@ -271,18 +231,26 @@ main(int argc, char **argv) if(from_stdin) fd = STDIN_FILENO; else { - fd = open_socket(context); - if(fd < 0) - krb5_errx(context, 1, "Failed to obtain socket - exiting"); - + mini_inetd (krb5_getportbyname (context, "hprop", "tcp", + HPROP_PORT)); + fd = STDIN_FILENO; { - int sin_len; - struct sockaddr_in sin; - sin_len = sizeof(sin); - if(getpeername(fd, (struct sockaddr*)&sin, &sin_len) < 0) + int sa_len; + struct sockaddr_storage ss; + struct sockaddr *sa = (struct sockaddr *)&ss; + char addr_name[256]; + + sa_len = sizeof(ss); + if(getpeername(fd, sa, &sa_len) < 0) krb5_err(context, 1, errno, "getpeername"); - krb5_log(context, fac, 0, "Connection from %s", - inet_ntoa(sin.sin_addr)); + if (inet_ntop(sa->sa_family, + socket_get_address (sa), + addr_name, + sizeof(addr_name)) == NULL) + strcpy_truncate (addr_name, "unknown address", + sizeof(addr_name)); + + krb5_log(context, fac, 0, "Connection from %s", addr_name); } gethostname(hostname, sizeof(hostname));