]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/sasl.c
Plug mutex/rwlock leaks (destroy them)
[openldap] / servers / slapd / sasl.c
index eb9d0661d8093e395034513fe46ea4366ca43f52..fd25cf363fada1b5aa517740b530a46013a2e937 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -63,8 +63,29 @@ typedef struct sasl_ctx {
 
 static struct berval ext_bv = BER_BVC( "EXTERNAL" );
 
+char *slap_sasl_auxprops;
+
 #ifdef HAVE_CYRUS_SASL
 
+/* Just use our internal auxprop by default */
+static int
+slap_sasl_getopt(
+       void *context,
+       const char *plugin_name,
+       const char *option,
+       const char **result,
+       unsigned *len)
+{
+       if ( strcmp( option, "auxprop_plugin" )) {
+               return SASL_FAIL;
+       }
+       if ( slap_sasl_auxprops )
+               *result = slap_sasl_auxprops;
+       else
+               *result = "slapd";
+       return SASL_OK;
+}
+
 int
 slap_sasl_log(
        void *context,
@@ -117,7 +138,7 @@ slap_sasl_log(
        }
 
        Debug( level, "SASL [conn=%ld] %s: %s\n",
-               conn ? conn->c_connid: -1,
+               conn ? (long) conn->c_connid: -1L,
                label, message );
 
 
@@ -216,7 +237,8 @@ sasl_ap_lookup( Operation *op, SlapReply *rs )
                                         * past the scheme name, skip this value.
                                         */
 #ifdef SLAPD_CLEARTEXT
-                                       if ( !ber_bvstrcasecmp( bv, &sc_cleartext ) ) {
+                                       if ( !strncasecmp( bv->bv_val, sc_cleartext.bv_val,
+                                               sc_cleartext.bv_len )) {
                                                struct berval cbv;
                                                cbv.bv_len = bv->bv_len - sc_cleartext.bv_len;
                                                if ( cbv.bv_len > 0 ) {
@@ -236,7 +258,11 @@ sasl_ap_lookup( Operation *op, SlapReply *rs )
        return LDAP_SUCCESS;
 }
 
+#if SASL_VERSION_FULL >= 0x020118
+static int
+#else
 static void
+#endif
 slap_auxprop_lookup(
        void *glob_context,
        sasl_server_params_t *sparams,
@@ -244,10 +270,12 @@ slap_auxprop_lookup(
        const char *user,
        unsigned ulen)
 {
-       Operation op = {0};
+       OperationBuffer opbuf = {{ NULL }};
+       Operation *op = (Operation *)&opbuf;
        int i, doit = 0;
        Connection *conn = NULL;
        lookup_info sl;
+       int rc = LDAP_SUCCESS;
 
        sl.list = sparams->utils->prop_get( sparams->propctx );
        sl.sparams = sparams;
@@ -264,22 +292,22 @@ slap_auxprop_lookup(
                        if ( flags & SASL_AUXPROP_AUTHZID ) {
                                if ( !strcmp( sl.list[i].name, slap_propnames[SLAP_SASL_PROP_AUTHZLEN] )) {
                                        if ( sl.list[i].values && sl.list[i].values[0] )
-                                               AC_MEMCPY( &op.o_req_ndn.bv_len, sl.list[i].values[0],
-                                                       sizeof( op.o_req_ndn.bv_len ) );
+                                               AC_MEMCPY( &op->o_req_ndn.bv_len, sl.list[i].values[0],
+                                                       sizeof( op->o_req_ndn.bv_len ) );
                                } else if ( !strcmp( sl.list[i].name, slap_propnames[SLAP_SASL_PROP_AUTHZ] )) {
                                        if ( sl.list[i].values )
-                                               op.o_req_ndn.bv_val = (char *)sl.list[i].values[0];
+                                               op->o_req_ndn.bv_val = (char *)sl.list[i].values[0];
                                        break;
                                }
                        }
 
                        if ( !strcmp( sl.list[i].name, slap_propnames[SLAP_SASL_PROP_AUTHCLEN] )) {
                                if ( sl.list[i].values && sl.list[i].values[0] )
-                                       AC_MEMCPY( &op.o_req_ndn.bv_len, sl.list[i].values[0],
-                                               sizeof( op.o_req_ndn.bv_len ) );
+                                       AC_MEMCPY( &op->o_req_ndn.bv_len, sl.list[i].values[0],
+                                               sizeof( op->o_req_ndn.bv_len ) );
                        } else if ( !strcmp( sl.list[i].name, slap_propnames[SLAP_SASL_PROP_AUTHC] ) ) {
                                if ( sl.list[i].values ) {
-                                       op.o_req_ndn.bv_val = (char *)sl.list[i].values[0];
+                                       op->o_req_ndn.bv_val = (char *)sl.list[i].values[0];
                                        if ( !(flags & SASL_AUXPROP_AUTHZID) )
                                                break;
                                }
@@ -314,30 +342,30 @@ slap_auxprop_lookup(
 
                cb.sc_private = &sl;
 
-               op.o_bd = select_backend( &op.o_req_ndn, 1 );
+               op->o_bd = select_backend( &op->o_req_ndn, 1 );
 
-               if ( op.o_bd ) {
+               if ( op->o_bd ) {
                        /* For rootdn, see if we can use the rootpw */
-                       if ( be_isroot_dn( op.o_bd, &op.o_req_ndn ) &&
-                               !BER_BVISEMPTY( &op.o_bd->be_rootpw )) {
+                       if ( be_isroot_dn( op->o_bd, &op->o_req_ndn ) &&
+                               !BER_BVISEMPTY( &op->o_bd->be_rootpw )) {
                                struct berval cbv = BER_BVNULL;
 
                                /* If there's a recognized scheme, see if it's CLEARTEXT */
-                               if ( lutil_passwd_scheme( op.o_bd->be_rootpw.bv_val )) {
-                                       if ( !strncasecmp( op.o_bd->be_rootpw.bv_val,
+                               if ( lutil_passwd_scheme( op->o_bd->be_rootpw.bv_val )) {
+                                       if ( !strncasecmp( op->o_bd->be_rootpw.bv_val,
                                                sc_cleartext.bv_val, sc_cleartext.bv_len )) {
 
                                                /* If it's CLEARTEXT, skip past scheme spec */
-                                               cbv.bv_len = op.o_bd->be_rootpw.bv_len -
+                                               cbv.bv_len = op->o_bd->be_rootpw.bv_len -
                                                        sc_cleartext.bv_len;
                                                if ( cbv.bv_len ) {
-                                                       cbv.bv_val = op.o_bd->be_rootpw.bv_val +
+                                                       cbv.bv_val = op->o_bd->be_rootpw.bv_val +
                                                                sc_cleartext.bv_len;
                                                }
                                        }
                                /* No scheme, use the whole value */
                                } else {
-                                       cbv = op.o_bd->be_rootpw;
+                                       cbv = op->o_bd->be_rootpw;
                                }
                                if ( !BER_BVISEMPTY( &cbv )) {
                                        for( i = 0; sl.list[i].name; i++ ) {
@@ -358,30 +386,35 @@ slap_auxprop_lookup(
                                }
                        }
 
-                       if ( op.o_bd->be_search ) {
+                       if ( op->o_bd->be_search ) {
                                SlapReply rs = {REP_RESULT};
-                               op.o_hdr = conn->c_sasl_bindop->o_hdr;
-                               op.o_tag = LDAP_REQ_SEARCH;
-                               op.o_dn = conn->c_ndn;
-                               op.o_ndn = conn->c_ndn;
-                               op.o_callback = &cb;
-                               slap_op_time( &op.o_time, &op.o_tincr );
-                               op.o_do_not_cache = 1;
-                               op.o_is_auth_check = 1;
-                               op.o_req_dn = op.o_req_ndn;
-                               op.ors_scope = LDAP_SCOPE_BASE;
-                               op.ors_deref = LDAP_DEREF_NEVER;
-                               op.ors_tlimit = SLAP_NO_LIMIT;
-                               op.ors_slimit = 1;
-                               op.ors_filter = &generic_filter;
-                               op.ors_filterstr = generic_filterstr;
+                               op->o_hdr = conn->c_sasl_bindop->o_hdr;
+                               op->o_controls = opbuf.ob_controls;
+                               op->o_tag = LDAP_REQ_SEARCH;
+                               op->o_dn = conn->c_ndn;
+                               op->o_ndn = conn->c_ndn;
+                               op->o_callback = &cb;
+                               slap_op_time( &op->o_time, &op->o_tincr );
+                               op->o_do_not_cache = 1;
+                               op->o_is_auth_check = 1;
+                               op->o_req_dn = op->o_req_ndn;
+                               op->ors_scope = LDAP_SCOPE_BASE;
+                               op->ors_deref = LDAP_DEREF_NEVER;
+                               op->ors_tlimit = SLAP_NO_LIMIT;
+                               op->ors_slimit = 1;
+                               op->ors_filter = &generic_filter;
+                               op->ors_filterstr = generic_filterstr;
+                               op->o_authz = conn->c_authz;
                                /* FIXME: we want all attributes, right? */
-                               op.ors_attrs = NULL;
+                               op->ors_attrs = NULL;
 
-                               op.o_bd->be_search( &op, &rs );
+                               rc = op->o_bd->be_search( op, &rs );
                        }
                }
        }
+#if SASL_VERSION_FULL >= 0x020118
+       return rc != LDAP_SUCCESS ? SASL_FAIL : SASL_OK;
+#endif
 }
 
 #if SASL_VERSION_FULL >= 0x020110
@@ -396,7 +429,8 @@ slap_auxprop_store(
        Operation op = {0};
        Opheader oph;
        SlapReply rs = {REP_RESULT};
-       int rc, i, j;
+       int rc, i;
+       unsigned j;
        Connection *conn = NULL;
        const struct propval *pr;
        Modifications *modlist = NULL, **modtail = &modlist, *mod;
@@ -553,7 +587,7 @@ slap_sasl_canonicalize(
        *out_len = 0;
 
        Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
-               conn ? conn->c_connid : -1,
+               conn ? (long) conn->c_connid : -1L,
                (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
                in ? in : "<empty>");
 
@@ -635,7 +669,7 @@ slap_sasl_canonicalize(
        prop_set( props, names[0], dn.bv_val, dn.bv_len );
 
        Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: %s=\"%s\"\n",
-               conn ? conn->c_connid : -1, names[0]+1,
+               conn ? (long) conn->c_connid : -1L, names[0]+1,
                dn.bv_val ? dn.bv_val : "<EMPTY>" );
 
        /* Not needed any more, SASL has copied it */
@@ -678,7 +712,7 @@ slap_sasl_authorize(
 
        Debug( LDAP_DEBUG_ARGS, "SASL proxy authorize [conn=%ld]: "
                "authcid=\"%s\" authzid=\"%s\"\n",
-               conn ? conn->c_connid : -1, auth_identity, requested_user );
+               conn ? (long) conn->c_connid : -1L, auth_identity, requested_user );
        if ( conn->c_sasl_dn.bv_val ) {
                BER_BVZERO( &conn->c_sasl_dn );
        }
@@ -708,7 +742,7 @@ slap_sasl_authorize(
        if ( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "SASL Proxy Authorize [conn=%ld]: "
                        "proxy authorization disallowed (%d)\n",
-                       (long) (conn ? conn->c_connid : -1), rc, 0 );
+                       conn ? (long) conn->c_connid : -1L, rc, 0 );
 
                sasl_seterror( sconn, 0, "not authorized" );
                return SASL_NOAUTHZ;
@@ -728,7 +762,7 @@ ok:
 
        Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
                " proxy authorization allowed authzDN=\"%s\"\n",
-               (long) (conn ? conn->c_connid : -1)
+               conn ? (long) conn->c_connid : -1L
                authzDN.bv_val ? authzDN.bv_val : "", 0 );
        return SASL_OK;
 } 
@@ -829,7 +863,7 @@ static int chk_sasl(
        rtn = LUTIL_PASSWD_ERR;
 
        ctx = ldap_pvt_thread_pool_context();
-       ldap_pvt_thread_pool_getkey( ctx, slap_sasl_bind, &sconn, NULL );
+       ldap_pvt_thread_pool_getkey( ctx, (void *)slap_sasl_bind, &sconn, NULL );
 
        if( sconn != NULL ) {
                int sc;
@@ -1043,7 +1077,7 @@ slapd_rw_apply( void *private, const char *filter, struct berval *val )
                }
                rc = REWRITE_ERR;
        }
-       filter_free_x( op, op->ors_filter );
+       filter_free_x( op, op->ors_filter, 1 );
        op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
        return rc;
 }
@@ -1076,6 +1110,7 @@ int slap_sasl_init( void )
        int rc;
        static sasl_callback_t server_callbacks[] = {
                { SASL_CB_LOG, &slap_sasl_log, NULL },
+               { SASL_CB_GETOPT, &slap_sasl_getopt, NULL },
                { SASL_CB_LIST_END, NULL, NULL }
        };
 #endif
@@ -1516,7 +1551,7 @@ int slap_sasl_bind( Operation *op, SlapReply *rs )
                }
 
                /* Must send response using old security layer */
-               if (response.bv_len) rs->sr_sasldata = &response;
+               rs->sr_sasldata = (response.bv_len ? &response : NULL);
                send_ldap_sasl( op, rs );
                
                /* Now dispose of the old security layer.