2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2001 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <sys/types.h>
2N/A#include <sys/socket.h>
2N/A#include <netinet/tcp.h>
2N/A#include <errno.h>
2N/A#include <dlfcn.h>
2N/A#include <rpcsvc/nis.h>
2N/A
2N/A#include "ldap_util.h"
2N/A
2N/A#include "nis_parse_ldap_conf.h"
2N/A
2N/A/*
2N/A * Interpose socket(3SOCKET), so that we can set the connect timeout.
2N/A * Obviously, this will affect every socket in the application. However,
2N/A * NIS+ (or, rather, RPC) uses TLI, not sockets, so the only sockets
2N/A * should be those used by libldap.
2N/A */
2N/Aint
2N/Asocket(int domain, int type, int protocol) {
2N/A int ret;
2N/A static int (*fptr)() = 0;
2N/A int timeout = 1000 * proxyInfo.bind_timeout.tv_sec +
2N/A proxyInfo.bind_timeout.tv_usec / 1000;
2N/A
2N/A if (fptr == 0) {
2N/A fptr = (int (*)())dlsym(RTLD_NEXT, "socket");
2N/A if (fptr == 0) {
2N/A logmsg(MSG_NOTIMECHECK, LOG_ERR,
2N/A "socket: load error: %s",
2N/A dlerror());
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A ret = (*fptr) (domain, type, protocol);
2N/A
2N/A if (ret >= 0 && timeout > 0) {
2N/A if (setsockopt(ret, IPPROTO_TCP, TCP_CONN_ABORT_THRESHOLD,
2N/A &timeout, sizeof (timeout)) != 0)
2N/A logmsg(MSG_NOTIMECHECK, LOG_ERR,
2N/A "setsockopt(IPPROTO_TCP/TCP_CONN_ABORT_THRESHOLD, %d) => errno = %d",
2N/A timeout, errno);
2N/A }
2N/A
2N/A return (ret);
2N/A}