/* config.c - ldap backend configuration file routine */
/* $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 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>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
*/
/* This is an altered version */
/*
fname, lineno );
return( 1 );
}
- li->binddn = ch_strdup(argv[1]);
+ ber_str2bv( argv[1], 0, 1, &li->binddn );
/* password to use for ldap_back_group */
} else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
fname, lineno );
return( 1 );
}
- li->bindpw = ch_strdup(argv[1]);
+ ber_str2bv( argv[1], 0, 1, &li->bindpw );
/* save bind creds for referral rebinds? */
} else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
fname, lineno );
return( 1 );
}
- load_extop( (struct berval *)&slap_EXOP_WHOAMI, ldap_back_exop_whoami );
+ load_extop( (struct berval *)&slap_EXOP_WHOAMI,
+ 0, ldap_back_exop_whoami );
/* dn massaging */
} else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
}
ber_str2bv( argv[1], 0, 0, &bvnc );
- if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc ) != LDAP_SUCCESS ) {
+ if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
fname, lineno, bvnc.bv_val );
return( 1 );
}
ber_str2bv( argv[2], 0, 0, &brnc );
- if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc ) != LDAP_SUCCESS ) {
+ if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
fname, lineno, brnc.bv_val );
free( nvnc.bv_val );
* FIXME: no extra rewrite capabilities should be added
* to the database
*/
- rc = suffix_massage_config( li->rwinfo, &pvnc, &nvnc, &prnc, &nrnc );
+ rc = suffix_massage_config( li->rwmap.rwm_rw,
+ &pvnc, &nvnc, &prnc, &nrnc );
free( nvnc.bv_val );
free( pvnc.bv_val );
free( nrnc.bv_val );
return( rc );
#else /* !ENABLE_REWRITE */
- ber_bvarray_add( &li->suffix_massage, &pvnc );
- ber_bvarray_add( &li->suffix_massage, &nvnc );
+ ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &pvnc );
+ ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nvnc );
- ber_bvarray_add( &li->suffix_massage, &prnc );
- ber_bvarray_add( &li->suffix_massage, &nrnc );
+ ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &prnc );
+ ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nrnc );
#endif /* !ENABLE_REWRITE */
/* rewrite stuff ... */
} else if ( strncasecmp( argv[0], "rewrite", 7 ) == 0 ) {
#ifdef ENABLE_REWRITE
- return rewrite_parse( li->rwinfo, fname, lineno, argc, argv );
+ return rewrite_parse( li->rwmap.rwm_rw,
+ fname, lineno, argc, argv );
#else /* !ENABLE_REWRITE */
fprintf( stderr, "%s: line %d: rewrite capabilities "
/* objectclass/attribute mapping */
} else if ( strcasecmp( argv[0], "map" ) == 0 ) {
- struct ldapmap *map;
- struct ldapmapping *mapping;
- char *src, *dst;
+ return ldap_back_map_config( &li->rwmap.rwm_oc,
+ &li->rwmap.rwm_at,
+ fname, lineno, argc, argv );
- if ( argc < 3 || argc > 4 ) {
- fprintf( stderr,
+ /* anything else */
+ } else {
+ fprintf( stderr, "%s: line %d: unknown directive \"%s\" "
+ "in ldap database definition (ignored)\n",
+ fname, lineno, argv[0] );
+ }
+ return 0;
+}
+
+int
+ldap_back_map_config(
+ struct ldapmap *oc_map,
+ struct ldapmap *at_map,
+ const char *fname,
+ int lineno,
+ int argc,
+ char **argv )
+{
+ struct ldapmap *map;
+ struct ldapmapping *mapping;
+ char *src, *dst;
+ int is_oc = 0;
+
+ if ( argc < 3 || argc > 4 ) {
+ fprintf( stderr,
"%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
- fname, lineno );
- return( 1 );
- }
+ fname, lineno );
+ return 1;
+ }
- if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
- map = &li->oc_map;
- } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
- map = &li->at_map;
- } else {
- fprintf( stderr, "%s: line %d: syntax is "
- "\"map {objectclass | attribute} [<local> | *] "
- "{<foreign> | *}\"\n",
- fname, lineno );
- return( 1 );
+ if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
+ map = oc_map;
+ is_oc = 1;
+
+ } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
+ map = at_map;
+
+ } else {
+ fprintf( stderr, "%s: line %d: syntax is "
+ "\"map {objectclass | attribute} [<local> | *] "
+ "{<foreign> | *}\"\n",
+ fname, lineno );
+ return 1;
+ }
+
+ if ( strcmp( argv[2], "*" ) == 0 ) {
+ if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
+ map->drop_missing = ( argc < 4 );
+ return 0;
}
+ src = dst = argv[3];
+
+ } else if ( argc < 4 ) {
+ src = "";
+ dst = argv[2];
+
+ } else {
+ src = argv[2];
+ dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
+ }
- if ( strcmp( argv[2], "*" ) == 0 ) {
- if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
- map->drop_missing = ( argc < 4 );
- return 0;
+ if ( ( map == at_map )
+ && ( strcasecmp( src, "objectclass" ) == 0
+ || strcasecmp( dst, "objectclass" ) == 0 ) )
+ {
+ fprintf( stderr,
+ "%s: line %d: objectclass attribute cannot be mapped\n",
+ fname, lineno );
+ }
+
+ mapping = (struct ldapmapping *)ch_calloc( 2,
+ sizeof(struct ldapmapping) );
+ if ( mapping == NULL ) {
+ fprintf( stderr,
+ "%s: line %d: out of memory\n",
+ fname, lineno );
+ return 1;
+ }
+ ber_str2bv( src, 0, 1, &mapping->src );
+ ber_str2bv( dst, 0, 1, &mapping->dst );
+ mapping[1].src = mapping->dst;
+ mapping[1].dst = mapping->src;
+
+ /*
+ * schema check
+ */
+ if ( is_oc ) {
+ if ( src[0] != '\0' ) {
+ if ( oc_bvfind( &mapping->src ) == NULL ) {
+ fprintf( stderr,
+ "%s: line %d: warning, source objectClass '%s' "
+ "should be defined in schema\n",
+ fname, lineno, src );
+
+ /*
+ * FIXME: this should become an err
+ */
}
- src = dst = argv[3];
- } else if ( argc < 4 ) {
- src = "";
- dst = argv[2];
- } else {
- src = argv[2];
- dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
}
- if ( ( map == &li->at_map )
- && ( strcasecmp( src, "objectclass" ) == 0
- || strcasecmp( dst, "objectclass" ) == 0 ) )
- {
+ if ( oc_bvfind( &mapping->dst ) == NULL ) {
fprintf( stderr,
- "%s: line %d: objectclass attribute cannot be mapped\n",
- fname, lineno );
+ "%s: line %d: warning, destination objectClass '%s' "
+ "is not defined in schema\n",
+ fname, lineno, dst );
}
+ } else {
+ int rc;
+ const char *text = NULL;
+ AttributeDescription *ad = NULL;
+
+ if ( src[0] != '\0' ) {
+ rc = slap_bv2ad( &mapping->src, &ad, &text );
+ if ( rc != LDAP_SUCCESS ) {
+ fprintf( stderr,
+ "%s: line %d: warning, source attributeType '%s' "
+ "should be defined in schema\n",
+ fname, lineno, src );
+
+ /*
+ * FIXME: this should become an err
+ */
+ }
- mapping = (struct ldapmapping *)ch_calloc( 2,
- sizeof(struct ldapmapping) );
- if ( mapping == NULL ) {
- fprintf( stderr,
- "%s: line %d: out of memory\n",
- fname, lineno );
- return( 1 );
+ ad = NULL;
}
- ber_str2bv( src, 0, 1, &mapping->src );
- ber_str2bv( dst, 0, 1, &mapping->dst );
- mapping[1].src = mapping->dst;
- mapping[1].dst = mapping->src;
-
- if ( (*src != '\0' &&
- avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL) ||
- avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
- {
+
+ rc = slap_bv2ad( &mapping->dst, &ad, &text );
+ if ( rc != LDAP_SUCCESS ) {
fprintf( stderr,
- "%s: line %d: duplicate mapping found (ignored)\n",
- fname, lineno );
- return 0;
+ "%s: line %d: warning, destination attributeType '%s' "
+ "is not defined in schema\n",
+ fname, lineno, dst );
}
+ }
- if ( *src != '\0' )
- avl_insert( &map->map, (caddr_t)mapping,
- mapping_cmp, mapping_dup );
- avl_insert( &map->remap, (caddr_t)&mapping[1],
- mapping_cmp, mapping_dup );
+ if ( (src[0] != '\0' && avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL)
+ || avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
+ {
+ fprintf( stderr,
+ "%s: line %d: duplicate mapping found (ignored)\n",
+ fname, lineno );
+ /* FIXME: free stuff */
+ goto error_return;
+ }
- /* anything else */
- } else {
- fprintf( stderr, "%s: line %d: unknown directive \"%s\" "
- "in ldap database definition (ignored)\n",
- fname, lineno, argv[0] );
+ if ( src[0] != '\0' ) {
+ avl_insert( &map->map, (caddr_t)mapping,
+ mapping_cmp, mapping_dup );
}
+ avl_insert( &map->remap, (caddr_t)&mapping[1],
+ mapping_cmp, mapping_dup );
+
return 0;
+
+error_return:;
+ if ( mapping ) {
+ ch_free( mapping->src.bv_val );
+ ch_free( mapping->dst.bv_val );
+ ch_free( mapping );
+ }
+
+ return 1;
}
static int
ldap_back_exop_whoami(
- Connection *conn,
Operation *op,
- struct berval *reqoid,
- struct berval *reqdata,
- char **rspoid,
- struct berval **rspdata,
- LDAPControl ***rspctrls,
- const char **text,
- BerVarray *refs )
+ SlapReply *rs )
{
struct berval *bv = NULL;
- int rc = LDAP_SUCCESS;
- if ( reqdata != NULL ) {
+ if ( op->oq_extended.rs_reqdata != NULL ) {
/* no request data should be provided */
- *text = "no request data expected";
- return LDAP_PROTOCOL_ERROR;
+ rs->sr_text = "no request data expected";
+ return rs->sr_err = LDAP_PROTOCOL_ERROR;
}
- {
- rc = backend_check_restrictions( conn->c_authz_backend,
- conn, op, (struct berval *)&slap_EXOP_WHOAMI, text );
-
- if( rc != LDAP_SUCCESS ) return rc;
- }
+ rs->sr_err = backend_check_restrictions( op, rs,
+ (struct berval *)&slap_EXOP_WHOAMI );
+ if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
/* if auth'd by back-ldap and request is proxied, forward it */
- if ( conn->c_authz_backend && !strcmp(conn->c_authz_backend->be_type, "ldap" ) && !dn_match(&op->o_ndn, &conn->c_ndn)) {
- struct ldapinfo *li =
- (struct ldapinfo *)conn->c_authz_backend->be_private;
+ if ( op->o_conn->c_authz_backend && !strcmp(op->o_conn->c_authz_backend->be_type, "ldap" ) && !dn_match(&op->o_ndn, &op->o_conn->c_ndn)) {
struct ldapconn *lc;
- LDAPControl c, *ctrls[2] = {&c, NULL};
+ LDAPControl c, *ctrls[2] = {NULL, NULL};
LDAPMessage *res;
Operation op2 = *op;
ber_int_t msgid;
- op2.o_ndn = conn->c_ndn;
- lc = ldap_back_getconn(li, conn, &op2);
- if (!lc || !ldap_back_dobind( li, lc, conn, op )) {
+ ctrls[0] = &c;
+ op2.o_ndn = op->o_conn->c_ndn;
+ lc = ldap_back_getconn(&op2, rs);
+ if (!lc || !ldap_back_dobind( lc, op, rs )) {
return -1;
}
c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
strcpy(c.ldctl_value.bv_val, "dn:");
strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
- rc = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
- if (rc == LDAP_SUCCESS) {
+ rs->sr_err = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
+ if (rs->sr_err == LDAP_SUCCESS) {
if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
- &rc);
+ &rs->sr_err);
} else {
- rc = ldap_parse_whoami(lc->ld, res, &bv);
+ rs->sr_err = ldap_parse_whoami(lc->ld, res, &bv);
ldap_msgfree(res);
}
}
ch_free(c.ldctl_value.bv_val);
- if (rc != LDAP_SUCCESS) {
- rc = ldap_back_map_result(rc);
+ if (rs->sr_err != LDAP_SUCCESS) {
+ rs->sr_err = ldap_back_map_result(rs);
}
} else {
/* else just do the same as before */
}
}
- *rspdata = bv;
- return rc;
+ rs->sr_rspdata = bv;
+ return rs->sr_err;
}
ch_free( rargv[ 1 ] );
ch_free( rargv[ 2 ] );
+#if 0
+ /*
+ * FIXME: this is no longer required since now we map filters
+ * based on the parsed filter structure, so we can deal directly
+ * with attribute types and values. The rewriteContext
+ * "searchFilter" now refers to the value of attrbutes
+ * with DN syntax.
+ */
+
/*
* the filter should be rewritten as
*
}
}
#endif /* rewrite filters */
+#endif
#if 0 /* "matched" is not normalized */
rargv[ 0 ] = "rewriteContext";
rargv[ 4 ] = NULL;
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
#else /* normalize "matched" */
+
rargv[ 0 ] = "rewriteContext";
- rargv[ 1 ] = "matchedDn";
- rargv[ 2 ] = NULL;
- rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
+ rargv[ 1 ] = "matchedDN";
+ rargv[ 2 ] = "alias";
+ rargv[ 3 ] = "searchResult";
+ rargv[ 4 ] = NULL;
+ rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
+ rargv[ 0 ] = "rewriteContext";
+ rargv[ 1 ] = "searchAttrDN";
+ rargv[ 2 ] = "alias";
+ rargv[ 3 ] = "searchResult";
+ rargv[ 4 ] = NULL;
+ rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
+
+#if 0
rargv[ 0 ] = "rewriteRule";
rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
rargv[ 2 ] = suffix_massage_patternize( nvnc->bv_val );
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
ch_free( rargv[ 1 ] );
ch_free( rargv[ 2 ] );
+#endif /* 0 */
#endif /* normalize "matched" */
return 0;