X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fos-local.c;h=4e3a19e5a29c20fa0fe19f1f73195f1996890230;hb=de01a6e3d791d3458549d2ceeccf4d7e0477ff78;hp=0c3245412facc2ea3ca1c6317ab7abf1c23fd962;hpb=547ebf66c4eaae4ce85181de3fa47617803e9196;p=openldap diff --git a/libraries/libldap/os-local.c b/libraries/libldap/os-local.c index 0c3245412f..4e3a19e5a2 100644 --- a/libraries/libldap/os-local.c +++ b/libraries/libldap/os-local.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2004 The OpenLDAP Foundation. + * Copyright 1998-2007 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -155,8 +155,10 @@ ldap_pvt_is_socket_ready(LDAP *ld, int s) #undef TRACE #if !defined(HAVE_GETPEEREID) && \ + !defined(HAVE_GETPEERUCRED) && \ !defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && \ - defined(HAVE_SENDMSG) && defined(HAVE_MSGHDR_MSG_ACCRIGHTS) + defined(HAVE_SENDMSG) && (defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTSLEN) || \ + defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)) #define DO_SENDMSG static const char abandonPDU[] = {LDAP_TAG_MESSAGE, 6, LDAP_TAG_MSGID, 1, 0, LDAP_REQ_ABANDON, 1, 0}; @@ -166,11 +168,11 @@ static int ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async) { int rc; - struct timeval tv, *opt_tv=NULL; + struct timeval tv, *opt_tv = NULL; - if ( (opt_tv = ld->ld_options.ldo_tm_net) != NULL ) { - tv.tv_usec = opt_tv->tv_usec; - tv.tv_sec = opt_tv->tv_sec; + if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) { + tv = ld->ld_options.ldo_tm_net; + opt_tv = &tv; } oslocal_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n", @@ -194,12 +196,40 @@ sendcred: /* Abandon, noop, has no reply */ struct iovec iov; struct msghdr msg = {0}; +# ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL +# ifndef CMSG_SPACE +# define CMSG_SPACE(len) (_CMSG_ALIGN( sizeof(struct cmsghdr)) + _CMSG_ALIGN(len) ) +# endif +# ifndef CMSG_LEN +# define CMSG_LEN(len) (_CMSG_ALIGN( sizeof(struct cmsghdr)) + (len) ) +# endif + union { + struct cmsghdr cm; + unsigned char control[CMSG_SPACE(sizeof(int))]; + } control_un; + struct cmsghdr *cmsg; +# endif /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */ + msg.msg_name = NULL; + msg.msg_namelen = 0; iov.iov_base = (char *) abandonPDU; iov.iov_len = sizeof abandonPDU; msg.msg_iov = &iov; msg.msg_iovlen = 1; +# ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL + msg.msg_control = control_un.control; + msg.msg_controllen = sizeof( control_un.control ); + msg.msg_flags = 0; + + cmsg = CMSG_FIRSTHDR( &msg ); + cmsg->cmsg_len = CMSG_LEN( sizeof(int) ); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + + *((int *)CMSG_DATA(cmsg)) = fds[0]; +# else msg.msg_accrights = (char *)fds; msg.msg_accrightslen = sizeof(int); +# endif /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */ sendmsg( s, &msg, 0 ); close(fds[0]); close(fds[1]); @@ -247,6 +277,14 @@ sendcred: { fd_set wfds, *z=NULL; +#ifdef FD_SETSIZE + if ( s >= FD_SETSIZE ) { + rc = AC_SOCKET_ERROR; + tcp_close( s ); + ldap_pvt_set_errno( EMFILE ); + return rc; + } +#endif do { FD_ZERO(&wfds); FD_SET(s, &wfds );