]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/connection.c
also log cookie parsing
[openldap] / servers / slapd / connection.c
index ce2c8f6e92c75fabdfa30c846a7fc29f4525c2ee..9ec67f503a6d049ee48eec22e6e75089100234c6 100644 (file)
@@ -359,14 +359,15 @@ static void connection_return( Connection *c )
        ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 }
 
-long connection_init(
+Connection * connection_init(
        ber_socket_t s,
        Listener *listener,
        const char* dnsname,
        const char* peername,
        int flags,
        slap_ssf_t ssf,
-       struct berval *authid )
+       struct berval *authid
+       LDAP_PF_LOCAL_SENDMSG_ARG(struct berval *peerbv))
 {
        unsigned long id;
        Connection *c;
@@ -379,13 +380,13 @@ long connection_init(
        assert( peername != NULL );
 
 #ifndef HAVE_TLS
-       assert( flags != CONN_IS_TLS );
+       assert( !( flags & CONN_IS_TLS ));
 #endif
 
        if( s == AC_SOCKET_INVALID ) {
                Debug( LDAP_DEBUG_ANY,
                        "connection_init: init of socket %ld invalid.\n", (long)s, 0, 0 );
-               return -1;
+               return NULL;
        }
 
        assert( s >= 0 );
@@ -442,7 +443,7 @@ long connection_init(
                        Debug( LDAP_DEBUG_ANY,
                                "connection_init(%d): connection table full "
                                "(%d/%d)\n", s, i, dtblsize);
-                       return -1;
+                       return NULL;
                }
        }
 #endif
@@ -525,14 +526,15 @@ long 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;
                c->c_close_reason = "?";                        /* should never be needed */
                ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
                ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 
-               return 0;
+               return c;
        }
 
        ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
@@ -559,7 +561,7 @@ long 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,
@@ -570,7 +572,21 @@ long 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,
@@ -605,7 +621,7 @@ long 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 {
@@ -622,7 +638,7 @@ long connection_init(
 
        backend_connection_init(c);
 
-       return id;
+       return c;
 }
 
 void connection2anonymous( Connection *c )
@@ -1022,12 +1038,12 @@ void connection_done( Connection *c )
 static BI_op_func *opfun[] = {
        do_bind,
        do_unbind,
+       do_search,
+       do_compare,
+       do_modify,
+       do_modrdn,
        do_add,
        do_delete,
-       do_modrdn,
-       do_modify,
-       do_compare,
-       do_search,
        do_abandon,
        do_extended,
        NULL
@@ -1111,7 +1127,7 @@ connection_operation( void *ctx, void *arg_v )
 #endif
        memsiz = SLAP_SLAB_SIZE;
 
-       memctx = slap_sl_mem_create( memsiz, SLAP_SLAB_STACK, ctx );
+       memctx = slap_sl_mem_create( memsiz, SLAP_SLAB_STACK, ctx, 1 );
        op->o_tmpmemctx = memctx;
        op->o_tmpmfuncs = &slap_sl_mfuncs;
        if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) {
@@ -1157,7 +1173,7 @@ operations_error:
 
        ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx_null );
 
-       LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
+       LDAP_STAILQ_REMOVE( &conn->c_ops, op, Operation, o_next);
        LDAP_STAILQ_NEXT(op, o_next) = NULL;
        slap_op_free( op );
        conn->c_n_ops_executing--;
@@ -1184,20 +1200,18 @@ int connection_client_setup(
        ldap_pvt_thread_start_t *func,
        void *arg )
 {
-       int rc;
        Connection *c;
 
-       rc = connection_init( s, (Listener *)&dummy_list, "", "",
-               CONN_IS_CLIENT, 0, NULL );
-       if ( rc < 0 ) return -1;
+       c = connection_init( s, (Listener *)&dummy_list, "", "",
+               CONN_IS_CLIENT, 0, NULL
+               LDAP_PF_LOCAL_SENDMSG_ARG(NULL));
+       if ( !c ) return -1;
 
-       c = connection_get( s );
        c->c_clientfunc = func;
        c->c_clientarg = arg;
 
        slapd_add_internal( s, 0 );
        slapd_set_read( s, 1 );
-       connection_return( c );
        return 0;
 }
 
@@ -1438,7 +1452,7 @@ int connection_read(ber_socket_t s)
        }
 #ifdef DATA_READY_LOOP
        while( !rc && ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ));
-#elif CONNECTION_INPUT_LOOP
+#elif defined CONNECTION_INPUT_LOOP
        while(!rc);
 #else
        while(0);
@@ -1801,13 +1815,14 @@ static int connection_bind_cb( Operation *op, SlapReply *rs )
 
                        /* log authorization identity */
                        Statslog( LDAP_DEBUG_STATS,
-                               "%s BIND dn=\"%s\" mech=%s ssf=%d\n",
+                               "%s BIND dn=\"%s\" mech=%s sasl_ssf=%d ssf=%d\n",
                                op->o_log_prefix,
                                BER_BVISNULL( &op->o_conn->c_dn ) ? "<empty>" : op->o_conn->c_dn.bv_val,
-                               op->o_conn->c_authmech.bv_val, op->orb_ssf, 0 );
+                               op->o_conn->c_authmech.bv_val,
+                               op->orb_ssf, op->o_conn->c_ssf );
 
                        Debug( LDAP_DEBUG_TRACE,
-                               "do_bind: SASL/%s bind: dn=\"%s\" ssf=%d\n",
+                               "do_bind: SASL/%s bind: dn=\"%s\" sasl_ssf=%d\n",
                                op->o_conn->c_authmech.bv_val,
                                BER_BVISNULL( &op->o_conn->c_dn ) ? "<empty>" : op->o_conn->c_dn.bv_val,
                                op->orb_ssf );
@@ -1946,12 +1961,54 @@ int connection_write(ber_socket_t s)
        return 0;
 }
 
+#ifdef LDAP_SLAPI
+typedef struct conn_fake_extblock {
+       void *eb_conn;
+       void *eb_op;
+} conn_fake_extblock;
+
+static void
+connection_fake_destroy(
+       void *key,
+       void *data )
+{
+       Connection conn = {0};
+       Operation op = {0};
+       Opheader ohdr = {0};
+
+       conn_fake_extblock *eb = data;
+       
+       op.o_hdr = &ohdr;
+       op.o_hdr->oh_extensions = eb->eb_op;
+       conn.c_extensions = eb->eb_conn;
+       op.o_conn = &conn;
+       conn.c_connid = -1;
+       op.o_connid = -1;
+
+       ber_memfree_x( eb, NULL );
+       slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, &op );
+       slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, &conn );
+}
+#endif
+
 void
 connection_fake_init(
        Connection *conn,
-       Operation *op,
+       OperationBuffer *opbuf,
        void *ctx )
 {
+       connection_fake_init2( conn, opbuf, ctx, 1 );
+}
+
+void
+connection_fake_init2(
+       Connection *conn,
+       OperationBuffer *opbuf,
+       void *ctx,
+       int newmem )
+{
+       Operation *op = (Operation *) opbuf;
+
        conn->c_connid = -1;
        conn->c_send_ldap_result = slap_send_ldap_result;
        conn->c_send_search_entry = slap_send_search_entry;
@@ -1960,11 +2017,13 @@ connection_fake_init(
        conn->c_peer_domain = slap_empty_bv;
        conn->c_peer_name = slap_empty_bv;
 
-       memset(op, 0, OPERATION_BUFFER_SIZE);
-       op->o_hdr = (Opheader *)(op+1);
-       op->o_controls = (void **)(op->o_hdr+1);
+       memset( opbuf, 0, sizeof( *opbuf ));
+       op->o_hdr = &opbuf->ob_hdr;
+       op->o_controls = opbuf->ob_controls;
+
        /* set memory context */
-       op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx);
+       op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx,
+               newmem );
        op->o_tmpmfuncs = &slap_sl_mfuncs;
        op->o_threadctx = ctx;
        op->o_tid = ldap_pvt_thread_pool_tid( ctx );
@@ -1974,12 +2033,25 @@ connection_fake_init(
        connection_init_log_prefix( op );
 
 #ifdef LDAP_SLAPI
-       /* FIXME: somebody needs to destroy these. Perhaps they should
-        * only be allocated on the slab.
-        */
        if ( slapi_plugins_used ) {
-               slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
-               slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
+               conn_fake_extblock *eb;
+               void *ebx = NULL;
+
+               /* Use thread keys to make sure these eventually get cleaned up */
+               if ( ldap_pvt_thread_pool_getkey( ctx, connection_fake_init, &ebx,
+                       NULL )) {
+                       eb = ch_malloc( sizeof( *eb ));
+                       slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
+                       slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
+                       eb->eb_conn = conn->c_extensions;
+                       eb->eb_op = op->o_hdr->oh_extensions;
+                       ldap_pvt_thread_pool_setkey( ctx, connection_fake_init, eb,
+                               connection_fake_destroy );
+               } else {
+                       eb = ebx;
+                       conn->c_extensions = eb->eb_conn;
+                       op->o_hdr->oh_extensions = eb->eb_op;
+               }
        }
 #endif /* LDAP_SLAPI */