]> git.sur5r.net Git - openldap/commitdiff
ITS#4893 fix prev commit
authorHoward Chu <hyc@openldap.org>
Sun, 25 Mar 2007 12:18:06 +0000 (12:18 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 25 Mar 2007 12:18:06 +0000 (12:18 +0000)
libraries/liblber/sockbuf.c
libraries/liblutil/getpeereid.c
servers/slapd/connection.c
servers/slapd/daemon.c
servers/slapd/proto-slap.h
servers/slapd/slap.h

index 2739b185e18f9aeb8b5b6ef6106a153495be2092..a828d078302a9f37aeaf03d4ae5bec04186b835c 100644 (file)
@@ -726,8 +726,8 @@ sb_fd_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
                AC_MEMCPY( buf, sbiod->sbiod_sb->sb_ungetbuf, blen );
                buf += blen;
                len -= blen;
-               if ( blen < sbiod->sbiod_sb->sb_ungetlen ) {
-                       sbiod->sbiod_sb->sb_ungetlen -= blen;
+               sbiod->sbiod_sb->sb_ungetlen -= blen;
+               if ( sbiod->sbiod_sb->sb_ungetlen ) {
                        AC_MEMCPY( sbiod->sbiod_sb->sb_ungetbuf,
                                sbiod->sbiod_sb->sb_ungetbuf+blen,
                                sbiod->sbiod_sb->sb_ungetlen );
index 08e482e16a73f042b49686864cc1b0b73e885ad2..fee069a893e96fbde5e2d4d057549de1c9c73b53 100644 (file)
 #include <sys/types.h>
 #include <ac/unistd.h>
 
+#include <ac/socket.h>
+#include <ac/errno.h>
+
+#ifdef HAVE_GETPEERUCRED
+#include <ucred.h>
+#endif
+
 #ifdef LDAP_PF_LOCAL_SENDMSG
 #include <lber.h>
 #ifdef HAVE_SYS_UIO_H
 #include <sys/stat.h>
 #endif
 
-#include <ac/socket.h>
-#include <ac/errno.h>
-
-#ifdef HAVE_GETPEERUCRED
-#include <ucred.h>
-#endif
-
 #ifdef HAVE_SYS_UCRED_H
 #ifdef HAVE_GRP_H
 #include <grp.h>       /* for NGROUPS on Tru64 5.1 */
@@ -151,8 +151,8 @@ int lutil_getpeereid( int s, uid_t *euid, gid_t *egid
                        *egid = st.st_gid;
                        return 0;
                }
-       } else if ( peer->bv_len < 0 ) {
-               peer->bv_len = 0;
+       } else if ( peerbv->bv_len < 0 ) {
+               peerbv->bv_len = 0;
        }
 #elif defined(SOCKCREDSIZE)
        struct msghdr msg;
index 9c0c05e77810ad27726981bf3ae618c97d092bad..41bca5cb84a48bdd805d6fa8bf665503b55e6b5b 100644 (file)
@@ -366,7 +366,11 @@ Connection * connection_init(
        const char* peername,
        int flags,
        slap_ssf_t ssf,
-       struct berval *authid )
+       struct berval *authid
+#ifdef LDAP_PF_LOCAL_SENDMSG
+       , struct berval *peerbv
+#endif
+)
 {
        unsigned long id;
        Connection *c;
@@ -379,7 +383,7 @@ Connection * connection_init(
        assert( peername != NULL );
 
 #ifndef HAVE_TLS
-       assert( flags != CONN_IS_TLS );
+       assert( !( flags & CONN_IS_TLS ));
 #endif
 
        if( s == AC_SOCKET_INVALID ) {
@@ -525,7 +529,7 @@ Connection * connection_init(
 
        c->c_listener = listener;
 
-       if ( flags == CONN_IS_CLIENT ) {
+       if ( flags & CONN_IS_CLIENT ) {
                c->c_connid = 0;
                c->c_conn_state = SLAP_C_CLIENT;
                c->c_struct_state = SLAP_C_USED;
@@ -560,7 +564,7 @@ Connection * connection_init(
 
 #ifdef LDAP_CONNECTIONLESS
        c->c_is_udp = 0;
-       if( flags == CONN_IS_UDP ) {
+       if( flags & CONN_IS_UDP ) {
                c->c_is_udp = 1;
 #ifdef LDAP_DEBUG
                ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
@@ -571,7 +575,21 @@ Connection * connection_init(
                ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_readahead,
                        LBER_SBIOD_LEVEL_PROVIDER, NULL );
        } else
+#endif /* LDAP_CONNECTIONLESS */
+#ifdef LDAP_PF_LOCAL
+       if ( flags & CONN_IS_IPC ) {
+#ifdef LDAP_DEBUG
+               ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
+                       LBER_SBIOD_LEVEL_PROVIDER, (void*)"ipc_" );
 #endif
+               ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_fd,
+                       LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
+#ifdef LDAP_PF_LOCAL_SENDMSG
+               if ( !BER_BVISEMPTY( peerbv ))
+                       ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_UNGET_BUF, peerbv );
+#endif
+       } else
+#endif /* LDAP_PF_LOCAL */
        {
 #ifdef LDAP_DEBUG
                ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
@@ -606,7 +624,7 @@ Connection * connection_init(
        c->c_tls_ssf = 0;
 
 #ifdef HAVE_TLS
-       if ( flags == CONN_IS_TLS ) {
+       if ( flags & CONN_IS_TLS ) {
                c->c_is_tls = 1;
                c->c_needs_tls_accept = 1;
        } else {
@@ -1189,7 +1207,11 @@ int connection_client_setup(
        Connection *c;
 
        c = connection_init( s, (Listener *)&dummy_list, "", "",
-               CONN_IS_CLIENT, 0, NULL );
+               CONN_IS_CLIENT, 0, NULL
+#ifdef LDAP_PF_LOCAL_SENDMSG
+               , NULL
+#endif
+               );
        if ( !c ) return -1;
 
        c->c_clientfunc = func;
index 2675eb84b80fa03744513c80c2b749ba4ae7a8da..59986a6009d36ac7399ecacb244848658dd990b6 100644 (file)
@@ -1592,6 +1592,7 @@ slap_listener(
 #else /* ! LDAP_PF_LOCAL && ! LDAP_PF_INET6 */
        char peername[sizeof("IP=255.255.255.255:65336")];
 #endif /* LDAP_PF_LOCAL */
+       int cflag;
 
        Debug( LDAP_DEBUG_TRACE,
                ">>> slap_listener(%s)\n",
@@ -1704,9 +1705,12 @@ slap_listener(
                "daemon: listen=%ld, new connection on %ld\n",
                (long) sl->sl_sd, (long) s, 0 );
 
+       cflag = 0;
        switch ( from.sa_addr.sa_family ) {
 #  ifdef LDAP_PF_LOCAL
        case AF_LOCAL:
+               cflag |= CONN_IS_IPC;
+
                /* FIXME: apparently accept doesn't fill
                 * the sun_path sun_path member */
                if ( from.sa_un_addr.sun_path[0] == '\0' ) {
@@ -1818,16 +1822,17 @@ slap_listener(
 #endif /* HAVE_TCPD */
        }
 
+#ifdef HAVE_TLS
+       if ( sl->sl_is_tls ) cflag |= CONN_IS_TLS;
+#endif
        c = connection_init(s, sl,
                dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
-               peername,
-#ifdef HAVE_TLS
-               sl->sl_is_tls ? CONN_IS_TLS : 0,
-#else /* ! HAVE_TLS */
-               0,
-#endif /* ! HAVE_TLS */
-               ssf,
-               authid.bv_val ? &authid : NULL );
+               peername, cflag, ssf,
+               authid.bv_val ? &authid : NULL
+#ifdef LDAP_PF_LOCAL_SENDMSG
+               , &peerbv
+#endif
+       );
 
        if( authid.bv_val ) ch_free(authid.bv_val);
 
@@ -1839,11 +1844,6 @@ slap_listener(
                return 0;
        }
 
-#ifdef LDAP_PF_LOCAL_SENDMSG
-       if ( !BER_BVISEMPTY( &peerbv ))
-               ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_UNGET_BUF, &peerbv );
-#endif
-
        Statslog( LDAP_DEBUG_STATS,
                "conn=%ld fd=%ld ACCEPT from %s (%s)\n",
                c->c_connid, (long) s, peername, sl->sl_name.bv_val,
@@ -2537,7 +2537,11 @@ connectionless_init( void )
                }
 
                c = connection_init( lr->sl_sd, lr, "", "",
-                       CONN_IS_UDP, (slap_ssf_t) 0, NULL );
+                       CONN_IS_UDP, (slap_ssf_t) 0, NULL
+#ifdef LDAP_PF_LOCAL_SENDMSG
+                       , NULL
+#endif
+                       );
 
                if ( !c ) {
                        Debug( LDAP_DEBUG_TRACE,
index 666ca13679bfe8efdabae0b73224e03e869c6882..f5cc8eb1649b5cb96bf64394153d645c1ddb7b4c 100644 (file)
@@ -693,7 +693,11 @@ LDAP_SLAPD_F (Connection *) connection_init LDAP_P((
        const char* peername,
        int use_tls,
        slap_ssf_t ssf,
-       struct berval *id ));
+       struct berval *id
+#ifdef LDAP_PF_LOCAL_SENDMSG
+       , struct berval *peerbv
+#endif
+       ));
 
 LDAP_SLAPD_F (void) connection_closing LDAP_P((
        Connection *c, const char *why ));
index fb825c97cb5c0ae717b2c7c31f5293ea36a2c138..75d74994d2580649ffe486a22562edf2a0f7db8f 100644 (file)
@@ -2682,7 +2682,8 @@ struct Connection {
 
 #define        CONN_IS_TLS     1
 #define        CONN_IS_UDP     2
-#define        CONN_IS_CLIENT  3
+#define        CONN_IS_CLIENT  4
+#define        CONN_IS_IPC     8
 
 #ifdef LDAP_CONNECTIONLESS
        int     c_is_udp;               /* true if this is (C)LDAP over UDP */