-/*
- * 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
*
* The name "Carnegie Mellon" must not be used to endorse or promote
* products derived from this software without prior written permission.
- *
*/
#include "portable.h"
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;
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 */
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;
}
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 */
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 );
*/
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;
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 */
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 );
}
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,
* The DNs should not have the dn: prefix
*/
static int
-slap_sasl_check_authz( Connection *conn,
+slap_sasl_check_authz( Operation *op,
struct berval *searchDN,
struct berval *assertDN,
AttributeDescription *ad,
assertDN->bv_val, ad->ad_cname.bv_val, searchDN->bv_val);
#endif
- rc = backend_attribute( conn->c_sasl_bindop, NULL,
+ rc = backend_attribute( op, NULL,
searchDN, ad, &vals );
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( conn->c_sasl_bindop, &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;
COMPLETE:
- if( vals ) ber_bvarray_free( vals );
+ if( vals ) ber_bvarray_free_x( vals, op->o_tmpmemctx );
#ifdef NEW_LOGGING
LDAP_LOG( TRANSPORT, RESULTS,
goto FINISHED;
}
- rc = slap_parseURI( opx, ®out, &op.o_req_ndn, &op.oq_search.rs_scope, &op.oq_search.rs_filter );
+ rc = slap_parseURI( opx, ®out, &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;
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 );
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,
* The DNs should not have the dn: prefix
*/
-int slap_sasl_authorized( Connection *conn,
+int slap_sasl_authorized( Operation *op,
struct berval *authcDN, struct berval *authzDN )
{
int rc = LDAP_INAPPROPRIATE_AUTH;
}
/* Allow the manager to authorize as any DN. */
- if( conn->c_authz_backend && be_isroot( conn->c_authz_backend, authcDN )) {
+ if( op->o_conn->c_authz_backend && be_isroot( op->o_conn->c_authz_backend, authcDN )) {
rc = LDAP_SUCCESS;
goto DONE;
}
/* Check source rules */
if( authz_policy & SASL_AUTHZ_TO ) {
- rc = slap_sasl_check_authz( conn, authcDN, authzDN,
+ rc = slap_sasl_check_authz( op, authcDN, authzDN,
slap_schema.si_ad_saslAuthzTo, authcDN );
if( rc == LDAP_SUCCESS ) {
goto DONE;
/* Check destination rules */
if( authz_policy & SASL_AUTHZ_FROM ) {
- rc = slap_sasl_check_authz( conn, authzDN, authcDN,
+ rc = slap_sasl_check_authz( op, authzDN, authcDN,
slap_schema.si_ad_saslAuthzFrom, authcDN );
if( rc == LDAP_SUCCESS ) {
goto DONE;