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 #include <sys/types.h> 28 #include <sys/socket.h> 29 #include <netinet/tcp.h> 30 #include <errno.h> 31 #include <dlfcn.h> 32 #include <rpcsvc/nis.h> 33 34 #include "ldap_util.h" 35 36 #include "nis_parse_ldap_conf.h" 37 38 /* 39 * Interpose socket(3SOCKET), so that we can set the connect timeout. 40 * Obviously, this will affect every socket in the application. However, 41 * NIS+ (or, rather, RPC) uses TLI, not sockets, so the only sockets 42 * should be those used by libldap. 43 */ 44 int 45 socket(int domain, int type, int protocol) { 46 int ret; 47 static int (*fptr)() = 0; 48 int timeout = 1000 * proxyInfo.bind_timeout.tv_sec + 49 proxyInfo.bind_timeout.tv_usec / 1000; 50 51 if (fptr == 0) { 52 fptr = (int (*)())dlsym(RTLD_NEXT, "socket"); 53 if (fptr == 0) { 54 logmsg(MSG_NOTIMECHECK, LOG_ERR, 55 "socket: load error: %s", 56 dlerror()); 57 return (-1); 58 } 59 } 60 61 ret = (*fptr) (domain, type, protocol); 62 63 if (ret >= 0 && timeout > 0) { 64 if (setsockopt(ret, IPPROTO_TCP, TCP_CONN_ABORT_THRESHOLD, 65 &timeout, sizeof (timeout)) != 0) 66 logmsg(MSG_NOTIMECHECK, LOG_ERR, 67 "setsockopt(IPPROTO_TCP/TCP_CONN_ABORT_THRESHOLD, %d) => errno = %d", 68 timeout, errno); 69 } 70 71 return (ret); 72 } 73