]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/saslauthz.c
ITS#2846 - make veryclean
[openldap] / servers / slapd / saslauthz.c
index 151da5cdc4207f033593494381c317f67b599579..ca9a416d0da1f1b869eae7982aac2c988cb9db4d 100644 (file)
@@ -1,10 +1,19 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* 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 
@@ -12,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"
@@ -66,15 +74,20 @@ int slap_sasl_setpolicy( const char *arg )
 }
 
 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;
 
@@ -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;
                }
@@ -115,7 +128,8 @@ is_dn:      bv.bv_len = uri->bv_len - (bv.bv_val - uri->bv_val);
        {
                /* host part must be empty */
                /* attrs and extensions parts must be empty */
-               return LDAP_PROTOCOL_ERROR;
+               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 );
@@ -404,8 +426,9 @@ int slap_sasl_match( Operation *opx, struct berval *rule,
                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 */
@@ -456,8 +479,12 @@ int slap_sasl_match( Operation *opx, struct berval *rule,
        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 );
 
@@ -468,8 +495,10 @@ int slap_sasl_match( Operation *opx, struct berval *rule,
        }
 
 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, 
@@ -576,8 +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;
@@ -620,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 );
        
@@ -630,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,