/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
#include "portable.h"
-#ifdef LDAP_PF_UNIX
+#ifdef LDAP_PF_LOCAL
#include <stdio.h>
#include <ac/time.h>
#include <ac/unistd.h>
-/* XXX non-portable */
+#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
#ifdef HAVE_IO_H
#include <io.h>
static ber_socket_t
ldap_pvt_socket(LDAP *ld)
{
- ber_socket_t s = socket(AF_UNIX, SOCK_STREAM, 0);
+ ber_socket_t s = socket(PF_LOCAL, SOCK_STREAM, 0);
oslocal_debug(ld, "ldap_new_socket: %d\n",s,0,0);
return ( s );
}
#if defined( notyet ) /* && defined( SO_ERROR ) */
{
int so_errno;
- int dummy = sizeof(so_errno);
- if ( getsockopt( s, SOL_SOCKET, SO_ERROR, &so_errno, &dummy ) == -1 ) {
+ socklen_t dummy = sizeof(so_errno);
+ if ( getsockopt( s, SOL_SOCKET, SO_ERROR, &so_errno, &dummy )
+ == AC_SOCKET_ERROR )
+ {
return -1;
}
if ( so_errno ) {
/* error slippery */
struct sockaddr_un sa;
char ch;
- int dummy = sizeof(sa);
- if ( getpeername( s, (struct sockaddr *) &sa, &dummy ) == -1 ) {
+ socklen_t dummy = sizeof(sa);
+ if ( getpeername( s, (struct sockaddr *) &sa, &dummy )
+ == AC_SOCKET_ERROR )
+ {
/* XXX: needs to be replace with ber_stream_read() */
read(s, &ch, 1);
TRACE;
}
#undef TRACE
+#if !defined(HAVE_GETPEEREID) && \
+ !defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && \
+ defined(HAVE_SENDMSG) && defined(HAVE_MSGHDR_MSG_ACCRIGHTS)
+#define DO_SENDMSG
+static const char abandonPDU[] = {LDAP_TAG_MESSAGE, 6,
+ LDAP_TAG_MSGID, 1, 0, LDAP_REQ_ABANDON, 1, 0};
+#endif
+
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;
fd_set wfds, *z=NULL;
if ( ldap_pvt_ndelay_on(ld, s) == -1 )
return ( -1 );
- if ( connect(s, (struct sockaddr *) sa, sizeof(struct sockaddr_un)) == 0 )
+ if ( connect(s, (struct sockaddr *) sa, sizeof(struct sockaddr_un))
+ != AC_SOCKET_ERROR )
{
- if ( ldap_pvt_ndelay_off(ld, s) == -1 )
+ if ( ldap_pvt_ndelay_off(ld, s) == -1 ) {
return ( -1 );
+ }
+#ifdef DO_SENDMSG
+ /* Send a dummy message with access rights. Remote side will
+ * obtain our uid/gid by fstat'ing this descriptor.
+ */
+sendcred:
+ {
+ int fds[2];
+ /* Abandon, noop, has no reply */
+ struct iovec iov = {abandonPDU, sizeof(abandonPDU)};
+ struct msghdr msg = {0};
+ if (pipe(fds) == 0) {
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_accrights = (char *)fds;
+ msg.msg_accrightslen = sizeof(int);
+ sendmsg( s, &msg, 0 );
+ close(fds[0]);
+ close(fds[1]);
+ }
+ }
+#endif
return ( 0 );
}
FD_ZERO(&wfds);
FD_SET(s, &wfds );
- if ( select(ldap_int_tblsize, z, &wfds, z, opt_tv ? &tv : NULL) == -1)
- return ( -1 );
+ do {
+ rc = select(ldap_int_tblsize, z, &wfds, z, opt_tv ? &tv : NULL);
+ } while( rc == AC_SOCKET_ERROR && errno == EINTR &&
+ LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART ));
+
+ if( rc == AC_SOCKET_ERROR ) return rc;
if ( FD_ISSET(s, &wfds) ) {
if ( ldap_pvt_is_socket_ready(ld, s) == -1 )
return ( -1 );
if ( ldap_pvt_ndelay_off(ld, s) == -1 )
return ( -1 );
+#ifdef DO_SENDMSG
+ goto sendcred;
+#else
return ( 0 );
+#endif
}
oslocal_debug(ld, "ldap_connect_timeout: timed out\n",0,0,0);
ldap_pvt_set_errno( ETIMEDOUT );
ldap_connect_to_path(LDAP *ld, Sockbuf *sb, const char *path, int async)
{
struct sockaddr_un server;
- ber_socket_t s = AC_SOCKET_INVALID;
- int rc, i, len;
- char *ha_buf=NULL, *p, *q;
+ ber_socket_t s;
+ int rc;
oslocal_debug(ld, "ldap_connect_to_path\n",0,0,0);
- if ( (s = ldap_pvt_socket( ld )) == -1 ) {
+ s = ldap_pvt_socket( ld );
+ if ( s == AC_SOCKET_INVALID ) {
return -1;
}
oslocal_debug(ld, "ldap_connect_to_path: Trying %s\n", path, 0, 0);
memset( &server, '\0', sizeof(server) );
- server.sun_family = AF_UNIX;
+ server.sun_family = AF_LOCAL;
strcpy( server.sun_path, path );
rc = ldap_pvt_connect(ld, s, &server, async);
}
#else
static int dummy;
-#endif /* LDAP_PF_UNIX */
+#endif /* LDAP_PF_LOCAL */