xref: /illumos-gate/usr/src/lib/libnisdb/ldap_cto.c (revision 4db555a5389470c6f15aa8b50a38ca5d533d0641)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <netinet/tcp.h>
32 #include <errno.h>
33 #include <dlfcn.h>
34 #include <rpcsvc/nis.h>
35 
36 #include "ldap_util.h"
37 
38 #include "nis_parse_ldap_conf.h"
39 
40 /*
41  * Interpose socket(3SOCKET), so that we can set the connect timeout.
42  * Obviously, this will affect every socket in the application. However,
43  * NIS+ (or, rather, RPC) uses TLI, not sockets, so the only sockets
44  * should be those used by libldap.
45  */
46 int
47 socket(int domain, int type, int protocol) {
48 	int		ret;
49 	static int	(*fptr)() = 0;
50 	int		timeout = 1000 * proxyInfo.bind_timeout.tv_sec +
51 					proxyInfo.bind_timeout.tv_usec / 1000;
52 
53 	if (fptr == 0) {
54 		fptr = (int (*)())dlsym(RTLD_NEXT, "socket");
55 		if (fptr == 0) {
56 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
57 				"socket: load error: %s",
58 				dlerror());
59 			return (-1);
60 		}
61 	}
62 
63 	ret = (*fptr) (domain, type, protocol);
64 
65 	if (ret >= 0 && timeout > 0) {
66 		if (setsockopt(ret, IPPROTO_TCP, TCP_CONN_ABORT_THRESHOLD,
67 				&timeout, sizeof (timeout)) != 0)
68 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
69 	"setsockopt(IPPROTO_TCP/TCP_CONN_ABORT_THRESHOLD, %d) => errno = %d",
70 				timeout, errno);
71 	}
72 
73 	return (ret);
74 }
75