summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/kadmin/kadm_conn.c
diff options
context:
space:
mode:
authorstas <stas@FreeBSD.org>2012-03-22 08:48:42 +0000
committerstas <stas@FreeBSD.org>2012-03-22 08:48:42 +0000
commite7e0b349883e80d63c4e856f16351aaa6607766d (patch)
tree5518cb944fa25f627a797b58451ccf506b720fcf /crypto/heimdal/kadmin/kadm_conn.c
parente02fd6b8423e63f1fdbfc1f984d7c7291a1bacd1 (diff)
parent2db247d3fc10ef5304f61dbd66448efff8cc6684 (diff)
downloadFreeBSD-src-e7e0b349883e80d63c4e856f16351aaa6607766d.zip
FreeBSD-src-e7e0b349883e80d63c4e856f16351aaa6607766d.tar.gz
- Update FreeBSD Heimdal distribution to version 1.5.1. This also brings
several new kerberos related libraries and applications to FreeBSD: o kgetcred(1) allows one to manually get a ticket for a particular service. o kf(1) securily forwards ticket to another host through an authenticated and encrypted stream. o kcc(1) is an umbrella program around klist(1), kswitch(1), kgetcred(1) and other user kerberos operations. klist and kswitch are just symlinks to kcc(1) now. o kswitch(1) allows you to easily switch between kerberos credentials if you're running KCM. o hxtool(1) is a certificate management tool to use with PKINIT. o string2key(1) maps a password into key. o kdigest(8) is a userland tool to access the KDC's digest interface. o kimpersonate(8) creates a "fake" ticket for a service. We also now install manpages for some lirbaries that were not installed before, libheimntlm and libhx509. - The new HEIMDAL version no longer supports Kerberos 4. All users are recommended to switch to Kerberos 5. - Weak ciphers are now disabled by default. To enable DES support (used by telnet(8)), use "allow_weak_crypto" option in krb5.conf. - libtelnet, pam_ksu and pam_krb5 are now compiled with error on warnings disabled due to the function they use (krb5_get_err_text(3)) being deprecated. I plan to work on this next. - Heimdal's KDC now require sqlite to operate. We use the bundled version and install it as libheimsqlite. If some other FreeBSD components will require it in the future we can rename it to libbsdsqlite and use for these components as well. - This is not a latest Heimdal version, the new one was released while I was working on the update. I will update it to 1.5.2 soon, as it fixes some important bugs and security issues.
Diffstat (limited to 'crypto/heimdal/kadmin/kadm_conn.c')
-rw-r--r--crypto/heimdal/kadmin/kadm_conn.c193
1 files changed, 102 insertions, 91 deletions
diff --git a/crypto/heimdal/kadmin/kadm_conn.c b/crypto/heimdal/kadmin/kadm_conn.c
index f2a0828..e959d03 100644
--- a/crypto/heimdal/kadmin/kadm_conn.c
+++ b/crypto/heimdal/kadmin/kadm_conn.c
@@ -1,34 +1,34 @@
/*
- * Copyright (c) 2000 - 2004 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
+ * Copyright (c) 2000 - 2004 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
*
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
*/
#include "kadmin_locl.h"
@@ -36,8 +36,6 @@
#include <sys/wait.h>
#endif
-RCSID("$Id: kadm_conn.c 16007 2005-09-01 18:49:57Z lha $");
-
struct kadm_port {
char *port;
unsigned short def_port;
@@ -45,16 +43,16 @@ struct kadm_port {
} *kadm_ports;
static void
-add_kadm_port(krb5_context context, const char *service, unsigned int port)
+add_kadm_port(krb5_context contextp, const char *service, unsigned int port)
{
struct kadm_port *p;
p = malloc(sizeof(*p));
if(p == NULL) {
- krb5_warnx(context, "failed to allocate %lu bytes\n",
+ krb5_warnx(contextp, "failed to allocate %lu bytes\n",
(unsigned long)sizeof(*p));
return;
}
-
+
p->port = strdup(service);
p->def_port = port;
@@ -63,9 +61,9 @@ add_kadm_port(krb5_context context, const char *service, unsigned int port)
}
static void
-add_standard_ports (krb5_context context)
+add_standard_ports (krb5_context contextp)
{
- add_kadm_port(context, "kerberos-adm", 749);
+ add_kadm_port(contextp, "kerberos-adm", 749);
}
/*
@@ -75,15 +73,15 @@ add_standard_ports (krb5_context context)
*/
void
-parse_ports(krb5_context context, const char *str)
+parse_ports(krb5_context contextp, const char *str)
{
char p[128];
while(strsep_copy(&str, " \t", p, sizeof(p)) != -1) {
if(strcmp(p, "+") == 0)
- add_standard_ports(context);
+ add_standard_ports(contextp);
else
- add_kadm_port(context, p, 0);
+ add_kadm_port(contextp, p, 0);
}
}
@@ -94,7 +92,12 @@ static RETSIGTYPE
sigchld(int sig)
{
int status;
- waitpid(-1, &status, 0);
+ /*
+ * waitpid() is async safe. will return -1 or 0 on no more zombie
+ * children
+ */
+ while ((waitpid(-1, &status, WNOHANG)) > 0)
+ ;
SIGRETURN(0);
}
@@ -117,68 +120,73 @@ terminate(int sig)
}
static int
-spawn_child(krb5_context context, int *socks, int num_socks, int this_sock)
+spawn_child(krb5_context contextp, int *socks,
+ unsigned int num_socks, int this_sock)
{
- int e, i;
+ int e;
+ size_t i;
struct sockaddr_storage __ss;
struct sockaddr *sa = (struct sockaddr *)&__ss;
socklen_t sa_size = sizeof(__ss);
- int s;
+ krb5_socket_t s;
pid_t pid;
krb5_address addr;
char buf[128];
size_t buf_len;
s = accept(socks[this_sock], sa, &sa_size);
- if(s < 0) {
- krb5_warn(context, errno, "accept");
+ if(rk_IS_BAD_SOCKET(s)) {
+ krb5_warn(contextp, rk_SOCK_ERRNO, "accept");
return 1;
}
- e = krb5_sockaddr2address(context, sa, &addr);
+ e = krb5_sockaddr2address(contextp, sa, &addr);
if(e)
- krb5_warn(context, e, "krb5_sockaddr2address");
+ krb5_warn(contextp, e, "krb5_sockaddr2address");
else {
- e = krb5_print_address (&addr, buf, sizeof(buf),
+ e = krb5_print_address (&addr, buf, sizeof(buf),
&buf_len);
- if(e)
- krb5_warn(context, e, "krb5_print_address");
+ if(e)
+ krb5_warn(contextp, e, "krb5_print_address");
else
- krb5_warnx(context, "connection from %s", buf);
- krb5_free_address(context, &addr);
+ krb5_warnx(contextp, "connection from %s", buf);
+ krb5_free_address(contextp, &addr);
}
-
+
pid = fork();
if(pid == 0) {
for(i = 0; i < num_socks; i++)
- close(socks[i]);
+ rk_closesocket(socks[i]);
dup2(s, STDIN_FILENO);
dup2(s, STDOUT_FILENO);
if(s != STDIN_FILENO && s != STDOUT_FILENO)
- close(s);
+ rk_closesocket(s);
return 0;
} else {
- close(s);
+ rk_closesocket(s);
}
return 1;
}
-static int
-wait_for_connection(krb5_context context,
- int *socks, int num_socks)
+static void
+wait_for_connection(krb5_context contextp,
+ krb5_socket_t *socks, unsigned int num_socks)
{
- int i, e;
+ unsigned int i;
+ int e;
fd_set orig_read_set, read_set;
- int max_fd = -1;
-
+ int status, max_fd = -1;
+
FD_ZERO(&orig_read_set);
-
+
for(i = 0; i < num_socks; i++) {
+#ifdef FD_SETSIZE
if (socks[i] >= FD_SETSIZE)
errx (1, "fd too large");
+#endif
FD_SET(socks[i], &orig_read_set);
max_fd = max(max_fd, socks[i]);
}
-
+
pgrp = getpid();
if(setpgid(0, pgrp) < 0)
@@ -191,41 +199,43 @@ wait_for_connection(krb5_context context,
while (term_flag == 0) {
read_set = orig_read_set;
e = select(max_fd + 1, &read_set, NULL, NULL, NULL);
- if(e < 0) {
- if(errno != EINTR)
- krb5_warn(context, errno, "select");
+ if(rk_IS_SOCKET_ERROR(e)) {
+ if(rk_SOCK_ERRNO != EINTR)
+ krb5_warn(contextp, rk_SOCK_ERRNO, "select");
} else if(e == 0)
- krb5_warnx(context, "select returned 0");
+ krb5_warnx(contextp, "select returned 0");
else {
for(i = 0; i < num_socks; i++) {
if(FD_ISSET(socks[i], &read_set))
- if(spawn_child(context, socks, num_socks, i) == 0)
- return 0;
+ if(spawn_child(contextp, socks, num_socks, i) == 0)
+ return;
}
}
}
signal(SIGCHLD, SIG_IGN);
- while(1) {
- int status;
- pid_t pid;
- pid = waitpid(-1, &status, 0);
- if(pid == -1 && errno == ECHILD)
- break;
- }
+
+ while ((waitpid(-1, &status, WNOHANG)) > 0)
+ ;
+
exit(0);
}
-int
-start_server(krb5_context context)
+void
+start_server(krb5_context contextp, const char *port_str)
{
int e;
struct kadm_port *p;
- int *socks = NULL, *tmp;
- int num_socks = 0;
+ krb5_socket_t *socks = NULL, *tmp;
+ unsigned int num_socks = 0;
int i;
+ if (port_str == NULL)
+ port_str = "+";
+
+ parse_ports(contextp, port_str);
+
for(p = kadm_ports; p; p = p->next) {
struct addrinfo hints, *ai, *ap;
char portstr[32];
@@ -240,38 +250,38 @@ start_server(krb5_context context)
}
if(e) {
- krb5_warn(context, krb5_eai_to_heim_errno(e, errno),
+ krb5_warn(contextp, krb5_eai_to_heim_errno(e, errno),
"%s", portstr);
continue;
}
i = 0;
- for(ap = ai; ap; ap = ap->ai_next)
+ for(ap = ai; ap; ap = ap->ai_next)
i++;
tmp = realloc(socks, (num_socks + i) * sizeof(*socks));
if(tmp == NULL) {
- krb5_warnx(context, "failed to reallocate %lu bytes",
+ krb5_warnx(contextp, "failed to reallocate %lu bytes",
(unsigned long)(num_socks + i) * sizeof(*socks));
continue;
}
socks = tmp;
for(ap = ai; ap; ap = ap->ai_next) {
- int s = socket(ap->ai_family, ap->ai_socktype, ap->ai_protocol);
- if(s < 0) {
- krb5_warn(context, errno, "socket");
+ krb5_socket_t s = socket(ap->ai_family, ap->ai_socktype, ap->ai_protocol);
+ if(rk_IS_BAD_SOCKET(s)) {
+ krb5_warn(contextp, rk_SOCK_ERRNO, "socket");
continue;
}
socket_set_reuseaddr(s, 1);
socket_set_ipv6only(s, 1);
- if (bind (s, ap->ai_addr, ap->ai_addrlen) < 0) {
- krb5_warn(context, errno, "bind");
- close(s);
+ if (rk_IS_SOCKET_ERROR(bind (s, ap->ai_addr, ap->ai_addrlen))) {
+ krb5_warn(contextp, rk_SOCK_ERRNO, "bind");
+ rk_closesocket(s);
continue;
}
- if (listen (s, SOMAXCONN) < 0) {
- krb5_warn(context, errno, "listen");
- close(s);
+ if (rk_IS_SOCKET_ERROR(listen (s, SOMAXCONN))) {
+ krb5_warn(contextp, rk_SOCK_ERRNO, "listen");
+ rk_closesocket(s);
continue;
}
socks[num_socks++] = s;
@@ -279,6 +289,7 @@ start_server(krb5_context context)
freeaddrinfo (ai);
}
if(num_socks == 0)
- krb5_errx(context, 1, "no sockets to listen to - exiting");
- return wait_for_connection(context, socks, num_socks);
+ krb5_errx(contextp, 1, "no sockets to listen to - exiting");
+
+ wait_for_connection(contextp, socks, num_socks);
}
OpenPOWER on IntegriCloud