]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/saslauthz.c
ITS#2846 - make veryclean
[openldap] / servers / slapd / saslauthz.c
index 56cfc60021fe579e148e55aa9b00c25d0cc065ab..ca9a416d0da1f1b869eae7982aac2c988cb9db4d 100644 (file)
@@ -1,9 +1,19 @@
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
-/*
- * Copyright (c) 2000, Mark Adamson, Carnegie Mellon.  All rights reserved.
+/* Portions Copyright (c) 2000, Mark Adamson, Carnegie Mellon.
+ * All rights reserved.
  * This software is not subject to any license of Carnegie Mellon University.
  *
  * Redistribution and use in source and binary forms are permitted without 
@@ -11,7 +21,6 @@
  *
  * The name "Carnegie Mellon" must not be used to endorse or promote
  * products derived from this software without prior written permission.
- *
  */
 
 #include "portable.h"
@@ -64,18 +73,21 @@ int slap_sasl_setpolicy( const char *arg )
        return rc;
 }
 
-/* URI format: ldap://<host>/<base>[?[<attrs>][?[<scope>][?[<filter>]]]] */
-
 static int slap_parseURI( Operation *op, struct berval *uri,
-       struct berval *searchbase, int *scope, Filter **filter )
+       struct berval *base, struct berval *nbase,
+       int *scope, Filter **filter, struct berval *fstr )
 {
        struct berval bv;
        int rc;
        LDAPURLDesc *ludp;
 
        assert( uri != NULL && uri->bv_val != NULL );
-       searchbase->bv_val = NULL;
-       searchbase->bv_len = 0;
+       base->bv_val = NULL;
+       base->bv_len = 0;
+       nbase->bv_val = NULL;
+       nbase->bv_len = 0;
+       fstr->bv_val = NULL;
+       fstr->bv_len = 0;
        *scope = -1;
        *filter = NULL;
 
@@ -83,7 +95,8 @@ static int slap_parseURI( Operation *op, struct berval *uri,
        LDAP_LOG( TRANSPORT, ENTRY, 
                "slap_parseURI: parsing %s\n", uri->bv_val, 0, 0 );
 #else
-       Debug( LDAP_DEBUG_TRACE, "slap_parseURI: parsing %s\n", uri->bv_val, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE,
+               "slap_parseURI: parsing %s\n", uri->bv_val, 0, 0 );
 #endif
 
        /* If it does not look like a URI, assume it is a DN */
@@ -93,7 +106,7 @@ static int slap_parseURI( Operation *op, struct berval *uri,
 
 is_dn: bv.bv_len = uri->bv_len - (bv.bv_val - uri->bv_val);
 
-               rc = dnNormalize( 0, NULL, NULL, &bv, searchbase, op->o_tmpmemctx );
+               rc = dnNormalize( 0, NULL, NULL, &bv, nbase, op->o_tmpmemctx );
                if( rc == LDAP_SUCCESS ) {
                        *scope = LDAP_SCOPE_BASE;
                }
@@ -113,9 +126,10 @@ is_dn:     bv.bv_len = uri->bv_len - (bv.bv_val - uri->bv_val);
        if (( ludp->lud_host && *ludp->lud_host )
                || ludp->lud_attrs || ludp->lud_exts )
        {
-               /* host part should be empty */
-               /* attrs and extensions parts should be empty */
-               return LDAP_PROTOCOL_ERROR;
+               /* host part must be empty */
+               /* attrs and extensions parts must be empty */
+               rc =  LDAP_PROTOCOL_ERROR;
+               goto done;
        }
 
        /* Grab the scope */
@@ -128,16 +142,24 @@ is_dn:    bv.bv_len = uri->bv_len - (bv.bv_val - uri->bv_val);
                        rc = LDAP_PROTOCOL_ERROR;
                        goto done;
                }
+               ber_str2bv( ludp->lud_filter, 0, 0, fstr );
        }
 
        /* Grab the searchbase */
-       bv.bv_val = ludp->lud_dn;
-       bv.bv_len = strlen( bv.bv_val );
-       rc = dnNormalize( 0, NULL, NULL, &bv, searchbase, op->o_tmpmemctx );
+       ber_str2bv( ludp->lud_dn, 0, 0, base );
+       rc = dnNormalize( 0, NULL, NULL, base, nbase, op->o_tmpmemctx );
 
 done:
        if( rc != LDAP_SUCCESS ) {
                if( *filter ) filter_free_x( op, *filter );
+               base->bv_val = NULL;
+               base->bv_len = 0;
+               fstr->bv_val = NULL;
+               fstr->bv_len = 0;
+       } else {
+               /* Don't free these, return them to caller */
+               ludp->lud_filter = NULL;
+               ludp->lud_dn= NULL;
        }
 
        ldap_free_urldesc( ludp );
@@ -384,7 +406,8 @@ static int sasl_sc_smatch( Operation *o, SlapReply *rs )
  */
 
 static
-int slap_sasl_match(Operation *opx, struct berval *rule, struct berval *assertDN, struct berval *authc )
+int slap_sasl_match( Operation *opx, struct berval *rule,
+       struct berval *assertDN, struct berval *authc )
 {
        int rc; 
        regex_t reg;
@@ -403,7 +426,9 @@ int slap_sasl_match(Operation *opx, struct berval *rule, struct berval *assertDN
                assertDN->bv_val, rule->bv_val, 0 );
 #endif
 
-       rc = slap_parseURI( opx, rule, &op.o_req_ndn, &op.oq_search.rs_scope, &op.oq_search.rs_filter );
+       rc = slap_parseURI( opx, rule, &op.o_req_dn,
+               &op.o_req_ndn, &op.oq_search.rs_scope, &op.oq_search.rs_filter,
+               &op.ors_filterstr );
        if( rc != LDAP_SUCCESS ) goto CONCLUDED;
 
        /* Massive shortcut: search scope == base */
@@ -454,8 +479,12 @@ int slap_sasl_match(Operation *opx, struct berval *rule, struct berval *assertDN
        op.o_threadctx = opx->o_threadctx;
        op.o_tmpmemctx = opx->o_tmpmemctx;
        op.o_tmpmfuncs = opx->o_tmpmfuncs;
+#ifdef LDAP_SLAPI
+       op.o_pb = opx->o_pb;
+#endif
        op.o_conn = opx->o_conn;
        op.o_connid = opx->o_connid;
+       op.o_req_dn = op.o_req_ndn;
 
        op.o_bd->be_search( &op, &rs );
 
@@ -466,8 +495,10 @@ int slap_sasl_match(Operation *opx, struct berval *rule, struct berval *assertDN
        }
 
 CONCLUDED:
+       if( op.o_req_dn.bv_len ) ch_free( op.o_req_dn.bv_val );
        if( op.o_req_ndn.bv_len ) sl_free( op.o_req_ndn.bv_val, opx->o_tmpmemctx );
        if( op.oq_search.rs_filter ) filter_free_x( opx, op.oq_search.rs_filter );
+       if( op.ors_filterstr.bv_len ) ch_free( op.ors_filterstr.bv_val );
 
 #ifdef NEW_LOGGING
        LDAP_LOG( TRANSPORT, ENTRY, 
@@ -514,9 +545,11 @@ slap_sasl_check_authz( Operation *op,
        if( rc != LDAP_SUCCESS ) goto COMPLETE;
 
        /* Check if the *assertDN matches any **vals */
-       for( i=0; vals[i].bv_val != NULL; i++ ) {
-               rc = slap_sasl_match( op, &vals[i], assertDN, authc );
-               if ( rc == LDAP_SUCCESS ) goto COMPLETE;
+       if( vals != NULL ) {
+               for( i=0; vals[i].bv_val != NULL; i++ ) {
+                       rc = slap_sasl_match( op, &vals[i], assertDN, authc );
+                       if ( rc == LDAP_SUCCESS ) goto COMPLETE;
+               }
        }
        rc = LDAP_INAPPROPRIATE_AUTH;
 
@@ -572,7 +605,9 @@ void slap_sasl2dn( Operation *opx,
                goto FINISHED;
        }
 
-       rc = slap_parseURI( opx, &regout, &op.o_req_ndn, &op.oq_search.rs_scope, &op.oq_search.rs_filter );
+       rc = slap_parseURI( opx, &regout, &op.o_req_dn,
+               &op.o_req_ndn, &op.oq_search.rs_scope, &op.oq_search.rs_filter,
+               &op.ors_filterstr );
        if( regout.bv_val ) sl_free( regout.bv_val, opx->o_tmpmemctx );
        if( rc != LDAP_SUCCESS ) {
                goto FINISHED;
@@ -615,9 +650,13 @@ void slap_sasl2dn( Operation *opx,
        op.o_threadctx = opx->o_threadctx;
        op.o_tmpmemctx = opx->o_tmpmemctx;
        op.o_tmpmfuncs = opx->o_tmpmfuncs;
+#ifdef LDAP_SLAPI
+       op.o_pb = opx->o_pb;
+#endif
        op.oq_search.rs_deref = LDAP_DEREF_NEVER;
        op.oq_search.rs_slimit = 1;
        op.oq_search.rs_attrsonly = 1;
+       op.o_req_dn = op.o_req_ndn;
 
        op.o_bd->be_search( &op, &rs );
        
@@ -625,8 +664,10 @@ FINISHED:
        if( sasldn->bv_len ) {
                opx->o_conn->c_authz_backend = op.o_bd;
        }
-       if( op.o_req_ndn.bv_len ) ch_free( op.o_req_ndn.bv_val );
+       if( op.o_req_dn.bv_len ) ch_free( op.o_req_dn.bv_val );
+       if( op.o_req_ndn.bv_len ) sl_free( op.o_req_ndn.bv_val, opx->o_tmpmemctx );
        if( op.oq_search.rs_filter ) filter_free_x( opx, op.oq_search.rs_filter );
+       if( op.ors_filterstr.bv_len ) ch_free( op.ors_filterstr.bv_val );
 
 #ifdef NEW_LOGGING
        LDAP_LOG( TRANSPORT, ENTRY,