1 /* $NetBSD: connect.c,v 1.1.1.2 2014/04/24 12:45:27 pettai Exp $ */
4 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 /* Should we enable the HTTP hack? */
41 /* Log over requests to the KDC */
42 const char *request_log
;
44 /* A string describing on what ports to listen */
47 krb5_addresses explicit_addresses
;
49 size_t max_request_udp
;
50 size_t max_request_tcp
;
53 * a tuple describing on what to listen
62 /* the current ones */
64 static struct port_desc
*ports
;
65 static size_t num_ports
;
68 * add `family, port, protocol' to the list with duplicate suppresion.
72 add_port(krb5_context context
,
73 int family
, int port
, const char *protocol
)
78 if(strcmp(protocol
, "udp") == 0)
80 else if(strcmp(protocol
, "tcp") == 0)
84 for(i
= 0; i
< num_ports
; i
++){
85 if(ports
[i
].type
== type
86 && ports
[i
].port
== port
87 && ports
[i
].family
== family
)
90 ports
= realloc(ports
, (num_ports
+ 1) * sizeof(*ports
));
92 krb5_err (context
, 1, errno
, "realloc");
93 ports
[num_ports
].family
= family
;
94 ports
[num_ports
].type
= type
;
95 ports
[num_ports
].port
= port
;
100 * add a triple but with service -> port lookup
101 * (this prints warnings for stuff that does not exist)
105 add_port_service(krb5_context context
,
106 int family
, const char *service
, int port
,
107 const char *protocol
)
109 port
= krb5_getportbyname (context
, service
, protocol
, port
);
110 add_port (context
, family
, port
, protocol
);
114 * add the port with service -> port lookup or string -> number
115 * (no warning is printed)
119 add_port_string (krb5_context context
,
120 int family
, const char *str
, const char *protocol
)
125 sp
= roken_getservbyname (str
, protocol
);
131 port
= htons(strtol(str
, &end
, 0));
135 add_port (context
, family
, port
, protocol
);
139 * add the standard collection of ports for `family'
143 add_standard_ports (krb5_context context
,
144 krb5_kdc_configuration
*config
,
147 add_port_service(context
, family
, "kerberos", 88, "udp");
148 add_port_service(context
, family
, "kerberos", 88, "tcp");
149 add_port_service(context
, family
, "kerberos-sec", 88, "udp");
150 add_port_service(context
, family
, "kerberos-sec", 88, "tcp");
152 add_port_service(context
, family
, "http", 80, "tcp");
153 if(config
->enable_kx509
) {
154 add_port_service(context
, family
, "kca_service", 9878, "udp");
155 add_port_service(context
, family
, "kca_service", 9878, "tcp");
161 * parse the set of space-delimited ports in `str' and add them.
162 * "+" => all the standard ones
163 * otherwise it's port|service[/protocol]
167 parse_ports(krb5_context context
,
168 krb5_kdc_configuration
*config
,
173 char *str_copy
= strdup (str
);
175 p
= strtok_r(str_copy
, " \t", &pos
);
177 if(strcmp(p
, "+") == 0) {
179 add_standard_ports(context
, config
, AF_INET6
);
181 add_standard_ports(context
, config
, AF_INET
);
183 char *q
= strchr(p
, '/');
187 add_port_string(context
, AF_INET6
, p
, q
);
189 add_port_string(context
, AF_INET
, p
, q
);
192 add_port_string(context
, AF_INET6
, p
, "udp");
193 add_port_string(context
, AF_INET6
, p
, "tcp");
195 add_port_string(context
, AF_INET
, p
, "udp");
196 add_port_string(context
, AF_INET
, p
, "tcp");
200 p
= strtok_r(NULL
, " \t", &pos
);
206 * every socket we listen on
217 struct sockaddr_storage __ss
;
220 char addr_string
[128];
224 init_descr(struct descr
*d
)
226 memset(d
, 0, sizeof(*d
));
227 d
->sa
= (struct sockaddr
*)&d
->__ss
;
228 d
->s
= rk_INVALID_SOCKET
;
232 * re-initialize all `n' ->sa in `d'.
236 reinit_descrs (struct descr
*d
, int n
)
240 for (i
= 0; i
< n
; ++i
)
241 d
[i
].sa
= (struct sockaddr
*)&d
[i
].__ss
;
245 * Create the socket (family, type, port) in `d'
249 init_socket(krb5_context context
,
250 krb5_kdc_configuration
*config
,
251 struct descr
*d
, krb5_address
*a
, int family
, int type
, int port
)
254 struct sockaddr_storage __ss
;
255 struct sockaddr
*sa
= (struct sockaddr
*)&__ss
;
256 krb5_socklen_t sa_size
= sizeof(__ss
);
260 ret
= krb5_addr2sockaddr (context
, a
, sa
, &sa_size
, port
);
262 krb5_warn(context
, ret
, "krb5_addr2sockaddr");
263 rk_closesocket(d
->s
);
264 d
->s
= rk_INVALID_SOCKET
;
268 if (sa
->sa_family
!= family
)
271 d
->s
= socket(family
, type
, 0);
272 if(rk_IS_BAD_SOCKET(d
->s
)){
273 krb5_warn(context
, errno
, "socket(%d, %d, 0)", family
, type
);
274 d
->s
= rk_INVALID_SOCKET
;
277 #if defined(HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_REUSEADDR)
280 setsockopt(d
->s
, SOL_SOCKET
, SO_REUSEADDR
, (void *)&one
, sizeof(one
));
286 if(rk_IS_SOCKET_ERROR(bind(d
->s
, sa
, sa_size
))){
290 krb5_print_address (a
, a_str
, sizeof(a_str
), &len
);
291 krb5_warn(context
, errno
, "bind %s/%d", a_str
, ntohs(port
));
292 rk_closesocket(d
->s
);
293 d
->s
= rk_INVALID_SOCKET
;
296 if(type
== SOCK_STREAM
&& rk_IS_SOCKET_ERROR(listen(d
->s
, SOMAXCONN
))){
300 krb5_print_address (a
, a_str
, sizeof(a_str
), &len
);
301 krb5_warn(context
, errno
, "listen %s/%d", a_str
, ntohs(port
));
302 rk_closesocket(d
->s
);
303 d
->s
= rk_INVALID_SOCKET
;
309 * Allocate descriptors for all the sockets that we should listen on
310 * and return the number of them.
314 init_sockets(krb5_context context
,
315 krb5_kdc_configuration
*config
,
322 krb5_addresses addresses
;
324 if (explicit_addresses
.len
) {
325 addresses
= explicit_addresses
;
327 ret
= krb5_get_all_server_addrs (context
, &addresses
);
329 krb5_err (context
, 1, ret
, "krb5_get_all_server_addrs");
331 parse_ports(context
, config
, port_str
);
332 d
= malloc(addresses
.len
* num_ports
* sizeof(*d
));
334 krb5_errx(context
, 1, "malloc(%lu) failed",
335 (unsigned long)num_ports
* sizeof(*d
));
337 for (i
= 0; i
< num_ports
; i
++){
338 for (j
= 0; j
< addresses
.len
; ++j
) {
339 init_socket(context
, config
, &d
[num
], &addresses
.val
[j
],
340 ports
[i
].family
, ports
[i
].type
, ports
[i
].port
);
341 if(d
[num
].s
!= rk_INVALID_SOCKET
){
345 krb5_print_address (&addresses
.val
[j
], a_str
,
346 sizeof(a_str
), &len
);
348 kdc_log(context
, config
, 5, "listening on %s port %u/%s",
350 ntohs(ports
[i
].port
),
351 (ports
[i
].type
== SOCK_STREAM
) ? "tcp" : "udp");
357 krb5_free_addresses (context
, &addresses
);
358 d
= realloc(d
, num
* sizeof(*d
));
359 if (d
== NULL
&& num
!= 0)
360 krb5_errx(context
, 1, "realloc(%lu) failed",
361 (unsigned long)num
* sizeof(*d
));
362 reinit_descrs (d
, num
);
372 descr_type(struct descr
*d
)
374 if (d
->type
== SOCK_DGRAM
)
376 else if (d
->type
== SOCK_STREAM
)
382 addr_to_string(krb5_context context
,
383 struct sockaddr
*addr
, size_t addr_len
, char *str
, size_t len
)
386 if(krb5_sockaddr2address(context
, addr
, &a
) == 0) {
387 if(krb5_print_address(&a
, str
, len
, &len
) == 0) {
388 krb5_free_address(context
, &a
);
391 krb5_free_address(context
, &a
);
393 snprintf(str
, len
, "<family=%d>", addr
->sa_family
);
401 send_reply(krb5_context context
,
402 krb5_kdc_configuration
*config
,
403 krb5_boolean prependlength
,
407 kdc_log(context
, config
, 5,
408 "sending %lu bytes to %s", (unsigned long)reply
->length
,
412 l
[0] = (reply
->length
>> 24) & 0xff;
413 l
[1] = (reply
->length
>> 16) & 0xff;
414 l
[2] = (reply
->length
>> 8) & 0xff;
415 l
[3] = reply
->length
& 0xff;
416 if(rk_IS_SOCKET_ERROR(sendto(d
->s
, l
, sizeof(l
), 0, d
->sa
, d
->sock_len
))) {
417 kdc_log (context
, config
,
418 0, "sendto(%s): %s", d
->addr_string
,
419 strerror(rk_SOCK_ERRNO
));
423 if(rk_IS_SOCKET_ERROR(sendto(d
->s
, reply
->data
, reply
->length
, 0, d
->sa
, d
->sock_len
))) {
424 kdc_log (context
, config
, 0, "sendto(%s): %s", d
->addr_string
,
425 strerror(rk_SOCK_ERRNO
));
431 * Handle the request in `buf, len' to socket `d'
435 do_request(krb5_context context
,
436 krb5_kdc_configuration
*config
,
437 void *buf
, size_t len
, krb5_boolean prependlength
,
442 int datagram_reply
= (d
->type
== SOCK_DGRAM
);
444 krb5_kdc_update_time(NULL
);
446 krb5_data_zero(&reply
);
447 ret
= krb5_kdc_process_request(context
, config
,
448 buf
, len
, &reply
, &prependlength
,
449 d
->addr_string
, d
->sa
,
452 krb5_kdc_save_request(context
, request_log
, buf
, len
, &reply
, d
->sa
);
454 send_reply(context
, config
, prependlength
, d
, &reply
);
455 krb5_data_free(&reply
);
458 kdc_log(context
, config
, 0,
459 "Failed processing %lu byte request from %s",
460 (unsigned long)len
, d
->addr_string
);
464 * Handle incoming data to the UDP socket in `d'
468 handle_udp(krb5_context context
,
469 krb5_kdc_configuration
*config
,
475 buf
= malloc(max_request_udp
);
477 kdc_log(context
, config
, 0, "Failed to allocate %lu bytes", (unsigned long)max_request_udp
);
481 d
->sock_len
= sizeof(d
->__ss
);
482 n
= recvfrom(d
->s
, buf
, max_request_udp
, 0, d
->sa
, &d
->sock_len
);
483 if(rk_IS_SOCKET_ERROR(n
))
484 krb5_warn(context
, rk_SOCK_ERRNO
, "recvfrom");
486 addr_to_string (context
, d
->sa
, d
->sock_len
,
487 d
->addr_string
, sizeof(d
->addr_string
));
488 if ((size_t)n
== max_request_udp
) {
490 krb5_warn(context
, errno
,
491 "recvfrom: truncated packet from %s, asking for TCP",
493 krb5_mk_error(context
,
494 KRB5KRB_ERR_RESPONSE_TOO_BIG
,
502 send_reply(context
, config
, FALSE
, d
, &data
);
503 krb5_data_free(&data
);
505 do_request(context
, config
, buf
, n
, FALSE
, d
);
512 clear_descr(struct descr
*d
)
515 memset(d
->buf
, 0, d
->size
);
517 if(d
->s
!= rk_INVALID_SOCKET
)
518 rk_closesocket(d
->s
);
519 d
->s
= rk_INVALID_SOCKET
;
523 /* remove HTTP %-quoting from buf */
527 unsigned char *p
, *q
;
528 for(p
= q
= (unsigned char *)buf
; *p
; p
++, q
++) {
529 if(*p
== '%' && isxdigit(p
[1]) && isxdigit(p
[2])) {
531 if(sscanf((char *)p
+ 1, "%2x", &x
) != 1)
542 #define TCP_TIMEOUT 4
545 * accept a new TCP connection on `d[parent]' and store it in `d[child]'
549 add_new_tcp (krb5_context context
,
550 krb5_kdc_configuration
*config
,
551 struct descr
*d
, int parent
, int child
)
558 d
[child
].sock_len
= sizeof(d
[child
].__ss
);
559 s
= accept(d
[parent
].s
, d
[child
].sa
, &d
[child
].sock_len
);
560 if(rk_IS_BAD_SOCKET(s
)) {
561 krb5_warn(context
, rk_SOCK_ERRNO
, "accept");
566 if (s
>= FD_SETSIZE
) {
567 krb5_warnx(context
, "socket FD too large");
574 d
[child
].timeout
= time(NULL
) + TCP_TIMEOUT
;
575 d
[child
].type
= SOCK_STREAM
;
576 addr_to_string (context
,
577 d
[child
].sa
, d
[child
].sock_len
,
578 d
[child
].addr_string
, sizeof(d
[child
].addr_string
));
582 * Grow `d' to handle at least `n'.
583 * Return != 0 if fails
587 grow_descr (krb5_context context
,
588 krb5_kdc_configuration
*config
,
589 struct descr
*d
, size_t n
)
591 if (d
->size
- d
->len
< n
) {
595 grow
= max(1024, d
->len
+ n
);
596 if (d
->size
+ grow
> max_request_tcp
) {
597 kdc_log(context
, config
, 0, "Request exceeds max request size (%lu bytes).",
598 (unsigned long)d
->size
+ grow
);
602 tmp
= realloc (d
->buf
, d
->size
+ grow
);
604 kdc_log(context
, config
, 0, "Failed to re-allocate %lu bytes.",
605 (unsigned long)d
->size
+ grow
);
616 * Try to handle the TCP data at `d->buf, d->len'.
617 * Return -1 if failed, 0 if succesful, and 1 if data is complete.
621 handle_vanilla_tcp (krb5_context context
,
622 krb5_kdc_configuration
*config
,
628 sp
= krb5_storage_from_mem(d
->buf
, d
->len
);
630 kdc_log (context
, config
, 0, "krb5_storage_from_mem failed");
633 krb5_ret_uint32(sp
, &len
);
634 krb5_storage_free(sp
);
635 if(d
->len
- 4 >= len
) {
636 memmove(d
->buf
, d
->buf
+ 4, d
->len
- 4);
644 * Try to handle the TCP/HTTP data at `d->buf, d->len'.
645 * Return -1 if failed, 0 if succesful, and 1 if data is complete.
649 handle_http_tcp (krb5_context context
,
650 krb5_kdc_configuration
*config
,
660 /* If its a multi line query, truncate off the first line */
661 p
= strstr(s
, "\r\n");
666 t
= strtok_r(s
, " \t", &p
);
668 kdc_log(context
, config
, 0,
669 "Missing HTTP operand (GET) request from %s", d
->addr_string
);
673 t
= strtok_r(NULL
, " \t", &p
);
675 kdc_log(context
, config
, 0,
676 "Missing HTTP GET data in request from %s", d
->addr_string
);
680 data
= malloc(strlen(t
));
682 kdc_log(context
, config
, 0, "Failed to allocate %lu bytes",
683 (unsigned long)strlen(t
));
688 if(de_http(t
) != 0) {
689 kdc_log(context
, config
, 0, "Malformed HTTP request from %s", d
->addr_string
);
690 kdc_log(context
, config
, 5, "HTTP request: %s", t
);
694 proto
= strtok_r(NULL
, " \t", &p
);
696 kdc_log(context
, config
, 0, "Malformed HTTP request from %s", d
->addr_string
);
700 len
= base64_decode(t
, data
);
704 "Server: Heimdal/" VERSION
"\r\n"
705 "Cache-Control: no-cache\r\n"
706 "Pragma: no-cache\r\n"
707 "Content-type: text/html\r\n"
708 "Content-transfer-encoding: 8bit\r\n\r\n"
709 "<TITLE>404 Not found</TITLE>\r\n"
710 "<H1>404 Not found</H1>\r\n"
711 "That page doesn't exist, maybe you are looking for "
712 "<A HREF=\"http://www.h5l.org/\">Heimdal</A>?\r\n";
713 kdc_log(context
, config
, 0, "HTTP request from %s is non KDC request", d
->addr_string
);
714 kdc_log(context
, config
, 5, "HTTP request: %s", t
);
716 if (rk_IS_SOCKET_ERROR(send(d
->s
, proto
, strlen(proto
), 0))) {
717 kdc_log(context
, config
, 0, "HTTP write failed: %s: %s",
718 d
->addr_string
, strerror(rk_SOCK_ERRNO
));
721 if (rk_IS_SOCKET_ERROR(send(d
->s
, msg
, strlen(msg
), 0))) {
722 kdc_log(context
, config
, 0, "HTTP write failed: %s: %s",
723 d
->addr_string
, strerror(rk_SOCK_ERRNO
));
731 "Server: Heimdal/" VERSION
"\r\n"
732 "Cache-Control: no-cache\r\n"
733 "Pragma: no-cache\r\n"
734 "Content-type: application/octet-stream\r\n"
735 "Content-transfer-encoding: binary\r\n\r\n";
736 if (rk_IS_SOCKET_ERROR(send(d
->s
, proto
, strlen(proto
), 0))) {
738 kdc_log(context
, config
, 0, "HTTP write failed: %s: %s",
739 d
->addr_string
, strerror(rk_SOCK_ERRNO
));
742 if (rk_IS_SOCKET_ERROR(send(d
->s
, msg
, strlen(msg
), 0))) {
744 kdc_log(context
, config
, 0, "HTTP write failed: %s: %s",
745 d
->addr_string
, strerror(rk_SOCK_ERRNO
));
749 if ((size_t)len
> d
->len
)
751 memcpy(d
->buf
, data
, len
);
758 * Handle incoming data to the TCP socket in `d[index]'
762 handle_tcp(krb5_context context
,
763 krb5_kdc_configuration
*config
,
764 struct descr
*d
, int idx
, int min_free
)
766 unsigned char buf
[1024];
770 if (d
[idx
].timeout
== 0) {
771 add_new_tcp (context
, config
, d
, idx
, min_free
);
775 n
= recvfrom(d
[idx
].s
, buf
, sizeof(buf
), 0, NULL
, NULL
);
776 if(rk_IS_SOCKET_ERROR(n
)){
777 krb5_warn(context
, rk_SOCK_ERRNO
, "recvfrom failed from %s to %s/%d",
778 d
[idx
].addr_string
, descr_type(d
+ idx
),
782 krb5_warnx(context
, "connection closed before end of data after %lu "
783 "bytes from %s to %s/%d", (unsigned long)d
[idx
].len
,
784 d
[idx
].addr_string
, descr_type(d
+ idx
),
786 clear_descr (d
+ idx
);
789 if (grow_descr (context
, config
, &d
[idx
], n
))
791 memcpy(d
[idx
].buf
+ d
[idx
].len
, buf
, n
);
793 if(d
[idx
].len
> 4 && d
[idx
].buf
[0] == 0) {
794 ret
= handle_vanilla_tcp (context
, config
, &d
[idx
]);
795 } else if(enable_http
&&
797 strncmp((char *)d
[idx
].buf
, "GET ", 4) == 0 &&
798 strncmp((char *)d
[idx
].buf
+ d
[idx
].len
- 4,
799 "\r\n\r\n", 4) == 0) {
801 /* remove the trailing \r\n\r\n so the string is NUL terminated */
802 d
[idx
].buf
[d
[idx
].len
- 4] = '\0';
804 ret
= handle_http_tcp (context
, config
, &d
[idx
]);
806 clear_descr (d
+ idx
);
807 } else if (d
[idx
].len
> 4) {
808 kdc_log (context
, config
,
809 0, "TCP data of strange type from %s to %s/%d",
810 d
[idx
].addr_string
, descr_type(d
+ idx
),
812 if (d
[idx
].buf
[0] & 0x80) {
815 kdc_log (context
, config
, 0, "TCP extension not supported");
817 ret
= krb5_mk_error(context
,
818 KRB5KRB_ERR_FIELD_TOOLONG
,
827 send_reply(context
, config
, TRUE
, d
+ idx
, &reply
);
828 krb5_data_free(&reply
);
831 clear_descr(d
+ idx
);
837 do_request(context
, config
,
838 d
[idx
].buf
, d
[idx
].len
, TRUE
, &d
[idx
]);
839 clear_descr(d
+ idx
);
844 realloc_descrs(struct descr
**d
, unsigned int *ndescr
)
849 tmp
= realloc(*d
, (*ndescr
+ 4) * sizeof(**d
));
854 reinit_descrs (*d
, *ndescr
);
855 memset(*d
+ *ndescr
, 0, 4 * sizeof(**d
));
856 for(i
= *ndescr
; i
< *ndescr
+ 4; i
++)
865 next_min_free(krb5_context context
, struct descr
**d
, unsigned int *ndescr
)
870 for(i
= 0; i
< *ndescr
; i
++) {
872 if(rk_IS_BAD_SOCKET(s
))
877 if(!realloc_descrs(d
, ndescr
)) {
879 krb5_warnx(context
, "No memory");
886 loop(krb5_context context
,
887 krb5_kdc_configuration
*config
)
892 ndescr
= init_sockets(context
, config
, &d
);
894 krb5_errx(context
, 1, "No sockets!");
895 kdc_log(context
, config
, 0, "KDC started");
896 while(exit_flag
== 0){
897 struct timeval tmout
;
904 for(i
= 0; i
< ndescr
; i
++) {
905 if(!rk_IS_BAD_SOCKET(d
[i
].s
)){
906 if(d
[i
].type
== SOCK_STREAM
&&
907 d
[i
].timeout
&& d
[i
].timeout
< time(NULL
)) {
908 kdc_log(context
, config
, 1,
909 "TCP-connection from %s expired after %lu bytes",
910 d
[i
].addr_string
, (unsigned long)d
[i
].len
);
914 #ifndef NO_LIMIT_FD_SETSIZE
918 if (max_fd
>= FD_SETSIZE
)
919 krb5_errx(context
, 1, "fd too large");
922 FD_SET(d
[i
].s
, &fds
);
926 tmout
.tv_sec
= TCP_TIMEOUT
;
928 switch(select(max_fd
+ 1, &fds
, 0, 0, &tmout
)){
933 krb5_warn(context
, rk_SOCK_ERRNO
, "select");
936 for(i
= 0; i
< ndescr
; i
++)
937 if(!rk_IS_BAD_SOCKET(d
[i
].s
) && FD_ISSET(d
[i
].s
, &fds
)) {
938 min_free
= next_min_free(context
, &d
, &ndescr
);
940 if(d
[i
].type
== SOCK_DGRAM
)
941 handle_udp(context
, config
, &d
[i
]);
942 else if(d
[i
].type
== SOCK_STREAM
)
943 handle_tcp(context
, config
, d
, i
, min_free
);
949 else if(exit_flag
== SIGXCPU
)
950 kdc_log(context
, config
, 0, "CPU time limit exceeded");
952 else if(exit_flag
== SIGINT
|| exit_flag
== SIGTERM
)
953 kdc_log(context
, config
, 0, "Terminated");
955 kdc_log(context
, config
, 0, "Unexpected exit reason: %d", exit_flag
);