2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/string.h>
28 #include <ac/socket.h>
32 #include "../back-ldap/back-ldap.h"
33 #undef ldap_debug /* silence a warning in ldap-int.h */
34 #include "../../../libraries/libldap/ldap-int.h"
35 #include "back-meta.h"
41 struct ldapmapping *mapping;
44 memset( mt, 0, sizeof( metatarget_t ) );
46 mt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
47 if ( mt->mt_rwmap.rwm_rw == NULL ) {
53 * the filter rewrite as a string must be disabled
54 * by default; it can be re-enabled by adding rules;
55 * this creates an empty rewriteContext
57 rargv[ 0 ] = "rewriteContext";
58 rargv[ 1 ] = "searchFilter";
60 rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
62 rargv[ 0 ] = "rewriteContext";
63 rargv[ 1 ] = "default";
65 rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
67 ldap_back_map_init( &mt->mt_rwmap.rwm_at, &mapping );
73 check_true_false( char *str )
75 if ( strcasecmp( str, "true" ) == 0 || strcasecmp( str, "yes" ) == 0 ) {
79 if ( strcasecmp( str, "false" ) == 0 || strcasecmp( str, "no" ) == 0 ) {
96 metainfo_t *mi = ( metainfo_t * )be->be_private;
100 "%s: line %d: meta backend info is null!\n",
105 /* URI of server to query */
106 if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
107 int i = mi->mi_ntargets;
110 #endif /* uncomment if uri MUST be a branch of suffix */
111 LDAPURLDesc *ludp, *tmpludp;
119 "%s: line %d: missing URI "
120 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
129 "%s: line %d: too many args "
130 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
135 if ( be->be_nsuffix == NULL ) {
137 "%s: line %d: the suffix must be defined before any target.\n",
144 mi->mi_targets = ( metatarget_t * )ch_realloc( mi->mi_targets,
145 sizeof( metatarget_t ) * mi->mi_ntargets );
146 if ( mi->mi_targets == NULL ) {
148 "%s: line %d: out of memory while storing server name"
149 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
154 if ( new_target( &mi->mi_targets[ i ] ) != 0 ) {
156 "%s: line %d: unable to init server"
157 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
162 mi->mi_targets[ i ].mt_nretries = mi->mi_nretries;
163 mi->mi_targets[ i ].mt_flags = mi->mi_flags;
164 mi->mi_targets[ i ].mt_version = mi->mi_version;
166 for ( c = 0; c < LDAP_BACK_OP_LAST; c++ ) {
167 mi->mi_targets[ i ].mt_timeout[ c ] = mi->mi_timeout[ c ];
173 if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t" ) != LDAP_SUCCESS ) {
175 "%s: line %d: unable to parse URI"
176 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
182 * uri MUST have the <dn> part!
184 if ( ludp->lud_dn == NULL ) {
186 "%s: line %d: missing <naming context> "
187 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
191 } else if ( ludp->lud_dn[ 0 ] == '\0' ) {
194 for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) {
195 if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) {
200 if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) {
202 "%s: line %d: missing <naming context> "
203 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
210 * copies and stores uri and suffix
212 ber_str2bv( ludp->lud_dn, 0, 0, &dn );
213 rc = dnPrettyNormal( NULL, &dn, &mi->mi_targets[ i ].mt_psuffix,
214 &mi->mi_targets[ i ].mt_nsuffix, NULL );
215 if( rc != LDAP_SUCCESS ) {
216 fprintf( stderr, "%s: line %d: "
217 "target '%s' DN is invalid\n",
218 fname, lineno, argv[ 1 ] );
222 ludp->lud_dn[ 0 ] = '\0';
224 switch ( ludp->lud_scope ) {
225 case LDAP_SCOPE_DEFAULT:
226 mi->mi_targets[ i ].mt_scope = LDAP_SCOPE_SUBTREE;
229 case LDAP_SCOPE_SUBTREE:
230 #ifdef LDAP_SCOPE_SUBORDINATE
231 case LDAP_SCOPE_SUBORDINATE:
232 #endif /* LDAP_SCOPE_SUBORDINATE */
233 mi->mi_targets[ i ].mt_scope = ludp->lud_scope;
237 fprintf( stderr, "%s: line %d: "
238 "invalid scope for target '%s'\n",
239 fname, lineno, argv[ 1 ] );
243 /* check all, to apply the scope check on the first one */
244 for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) {
245 if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) {
246 fprintf( stderr, "%s: line %d: "
247 "multiple URIs must have "
255 mi->mi_targets[ i ].mt_uri = ldap_url_list2urls( ludp );
256 ldap_free_urllist( ludp );
257 if ( mi->mi_targets[ i ].mt_uri == NULL) {
258 fprintf( stderr, "%s: line %d: no memory?\n",
264 * uri MUST be a branch of suffix!
266 #if 0 /* too strict a constraint */
267 if ( select_backend( &mi->mi_targets[ i ].suffix, 0, 0 ) != be ) {
269 "%s: line %d: <naming context> of URI does not refer to current backend"
270 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
276 * uri MUST be a branch of a suffix!
278 if ( select_backend( &mi->mi_targets[ i ].mt_nsuffix, 0, 0 ) == NULL ) {
280 "%s: line %d: <naming context> of URI does not resolve to a backend"
281 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
287 /* default target directive */
288 } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
289 int i = mi->mi_ntargets - 1;
294 "%s: line %d: \"default-target\" alone need be"
295 " inside a \"uri\" directive\n",
299 mi->mi_defaulttarget = i;
301 if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
304 "%s: line %d: \"default-target none\""
305 " should go before uri definitions\n",
308 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
312 int n = strtol( argv[ 1 ], &next, 10 );
313 if ( n < 0 || n >= i - 1 ) {
315 "%s: line %d: illegal target number %d\n",
319 mi->mi_defaulttarget = n;
323 /* ttl of dn cache */
324 } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
327 "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
332 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
333 mi->mi_cache.ttl = META_DNCACHE_FOREVER;
334 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
335 mi->mi_cache.ttl = META_DNCACHE_DISABLED;
339 mi->mi_cache.ttl = strtol( argv[ 1 ], &next, 10 );
340 if ( next == argv[ 1 ] || next[ 0 ] != '\0' ) {
342 "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
343 fname, lineno, argv[ 1 ] );
348 /* network timeout when connecting to ldap servers */
349 } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
352 "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
356 mi->mi_network_timeout = atol(argv[ 1 ]);
358 /* name to use for meta_back_group */
359 } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
360 || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
362 int i = mi->mi_ntargets - 1;
367 "%s: line %d: need \"uri\" directive first\n",
374 "%s: line %d: missing name in \"binddn <name>\" line\n",
379 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
380 fprintf( stderr, "%s: line %d: "
381 "\"binddn\" statement is deprecated; "
382 "use \"acl-authcDN\" instead\n",
384 /* FIXME: some day we'll need to throw an error */
387 dn.bv_val = argv[ 1 ];
388 dn.bv_len = strlen( argv[ 1 ] );
389 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ].mt_binddn,
390 NULL ) != LDAP_SUCCESS )
392 fprintf( stderr, "%s: line %d: "
393 "bind DN '%s' is invalid\n",
394 fname, lineno, argv[ 1 ] );
398 /* password to use for meta_back_group */
399 } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
400 || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
402 int i = mi->mi_ntargets - 1;
406 "%s: line %d: need \"uri\" directive first\n",
413 "%s: line %d: missing password in \"bindpw <password>\" line\n",
418 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
419 fprintf( stderr, "%s: line %d: "
420 "\"bindpw\" statement is deprecated; "
421 "use \"acl-passwd\" instead\n",
423 /* FIXME: some day we'll need to throw an error */
426 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_bindpw );
428 /* save bind creds for referral rebinds? */
429 } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
432 "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
439 "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
441 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
444 switch ( check_true_false( argv[ 1 ] ) ) {
446 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
450 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
455 "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
456 fname, lineno, argv[ 1 ] );
461 } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
462 unsigned *flagsp = mi->mi_ntargets ?
463 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
468 "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
473 /* this is the default; we add it because the default might change... */
474 switch ( check_true_false( argv[ 1 ] ) ) {
476 *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
480 *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
485 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
486 fname, lineno, argv[ 1 ] );
490 } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
491 unsigned *flagsp = mi->mi_ntargets ?
492 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
497 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
503 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
504 *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
507 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
508 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
509 *flagsp |= LDAP_BACK_F_USE_TLS;
511 /* propagate start tls */
512 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
513 *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
516 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
517 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
518 *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
522 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
523 fname, lineno, argv[ 1 ] );
527 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
528 unsigned *flagsp = mi->mi_ntargets ?
529 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
534 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
539 switch ( check_true_false( argv[ 1 ] ) ) {
541 *flagsp &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
545 *flagsp |= LDAP_BACK_F_SUPPORT_T_F;
549 if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
550 *flagsp |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
554 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
555 fname, lineno, argv[ 1 ] );
562 } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
565 "%s: line %d: \"onerr {CONTINUE|stop}\" takes 1 argument\n",
570 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
571 mi->mi_flags &= ~META_BACK_F_ONERR_STOP;
573 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
574 mi->mi_flags |= META_BACK_F_ONERR_STOP;
578 "%s: line %d: \"onerr {CONTINUE|stop}\": invalid arg \"%s\".\n",
579 fname, lineno, argv[ 1 ] );
584 } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0 ) {
587 "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\" takes 1 argument\n",
592 switch ( check_true_false( argv[ 1 ] ) ) {
594 mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
598 mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
603 "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
604 fname, lineno, argv[ 1 ] );
608 } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
610 time_t *tv = mi->mi_ntargets ?
611 mi->mi_targets[ mi->mi_ntargets - 1 ].mt_timeout
617 "%s: line %d: \"timeout [{add|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
622 for ( c = 1; c < argc; c++ ) {
623 time_t *t = NULL, val;
625 sep = strchr( argv[ c ], '=' );
627 size_t len = sep - argv[ c ];
629 if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
630 t = &tv[ LDAP_BACK_OP_ADD ];
631 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
632 t = &tv[ LDAP_BACK_OP_DELETE ];
633 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
634 t = &tv[ LDAP_BACK_OP_MODIFY ];
635 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
636 t = &tv[ LDAP_BACK_OP_MODRDN ];
639 "%s: line %d: unknown operation \"%s\" for timeout #%d.\n",
640 fname, lineno, argv[ c ], c );
649 val = strtoul( sep, &next, 10 );
650 if ( next == sep || next[ 0 ] != '\0' ) {
652 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
653 fname, lineno, sep );
663 for ( i = 0; i < LDAP_BACK_OP_LAST; i++ ) {
669 /* name to use as pseudo-root dn */
670 } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
671 int i = mi->mi_ntargets - 1;
676 "%s: line %d: need \"uri\" directive first\n",
683 "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
688 dn.bv_val = argv[ 1 ];
689 dn.bv_len = strlen( argv[ 1 ] );
690 if ( dnNormalize( 0, NULL, NULL, &dn,
691 &mi->mi_targets[ i ].mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
693 fprintf( stderr, "%s: line %d: "
694 "pseudoroot DN '%s' is invalid\n",
695 fname, lineno, argv[ 1 ] );
699 /* password to use as pseudo-root */
700 } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
701 int i = mi->mi_ntargets - 1;
705 "%s: line %d: need \"uri\" directive first\n",
712 "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
716 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_pseudorootpw );
719 } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
721 int i = mi->mi_ntargets - 1, rc;
722 struct berval dn, nvnc, pvnc, nrnc, prnc;
726 "%s: line %d: need \"uri\" directive first\n",
734 * suffixmassage <suffix> <massaged suffix>
736 * the <suffix> field must be defined as a valid suffix
737 * (or suffixAlias?) for the current database;
738 * the <massaged suffix> shouldn't have already been
739 * defined as a valid suffix or suffixAlias for the
744 "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
749 ber_str2bv( argv[ 1 ], 0, 0, &dn );
750 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
751 fprintf( stderr, "%s: line %d: "
752 "suffix '%s' is invalid\n",
753 fname, lineno, argv[ 1 ] );
757 tmp_be = select_backend( &nvnc, 0, 0 );
758 if ( tmp_be != NULL && tmp_be != be ) {
760 "%s: line %d: suffix already in use by another backend in"
761 " \"suffixMassage <suffix> <massaged suffix>\"\n",
768 ber_str2bv( argv[ 2 ], 0, 0, &dn );
769 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
770 fprintf( stderr, "%s: line %d: "
771 "massaged suffix '%s' is invalid\n",
772 fname, lineno, argv[ 2 ] );
779 tmp_be = select_backend( &nrnc, 0, 0 );
780 if ( tmp_be != NULL ) {
782 "%s: line %d: massaged suffix already in use by another backend in"
783 " \"suffixMassage <suffix> <massaged suffix>\"\n",
794 * The suffix massaging is emulated by means of the
795 * rewrite capabilities
796 * FIXME: no extra rewrite capabilities should be added
799 rc = suffix_massage_config( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
800 &pvnc, &nvnc, &prnc, &nrnc );
809 /* rewrite stuff ... */
810 } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
811 int i = mi->mi_ntargets - 1;
814 fprintf( stderr, "%s: line %d: \"rewrite\" "
815 "statement outside target definition.\n",
820 return rewrite_parse( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
821 fname, lineno, argc, argv );
823 /* objectclass/attribute mapping */
824 } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
825 int i = mi->mi_ntargets - 1;
829 "%s: line %d: need \"uri\" directive first\n",
834 return ldap_back_map_config( &mi->mi_targets[ i ].mt_rwmap.rwm_oc,
835 &mi->mi_targets[ i ].mt_rwmap.rwm_at,
836 fname, lineno, argc, argv );
838 } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
839 int i = mi->mi_ntargets - 1;
840 int nretries = META_RETRY_UNDEFINED;
844 "%s: line %d: need value in \"nretries <value>\"\n",
849 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
850 nretries = META_RETRY_FOREVER;
852 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
853 nretries = META_RETRY_NEVER;
858 nretries = strtol( argv[ 1 ], &next, 10 );
859 if ( next == argv[ 1 ] || next[ 0 ] != '\0' ) {
861 "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
862 fname, lineno, argv[ 1 ] );
868 mi->mi_nretries = nretries;
871 mi->mi_targets[ i ].mt_nretries = nretries;
876 return SLAP_CONF_UNKNOWN;
882 ldap_back_map_config(
883 struct ldapmap *oc_map,
884 struct ldapmap *at_map,
891 struct ldapmapping *mapping;
895 if ( argc < 3 || argc > 4 ) {
897 "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
902 if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
906 } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
910 fprintf( stderr, "%s: line %d: syntax is "
911 "\"map {objectclass | attribute} [<local> | *] "
912 "{<foreign> | *}\"\n",
917 if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
918 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
919 map->drop_missing = ( argc < 4 );
922 src = dst = argv[ 3 ];
924 } else if ( argc < 4 ) {
930 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
933 if ( ( map == at_map )
934 && ( strcasecmp( src, "objectclass" ) == 0
935 || strcasecmp( dst, "objectclass" ) == 0 ) )
938 "%s: line %d: objectclass attribute cannot be mapped\n",
942 mapping = (struct ldapmapping *)ch_calloc( 2,
943 sizeof(struct ldapmapping) );
944 if ( mapping == NULL ) {
946 "%s: line %d: out of memory\n",
950 ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
951 ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
952 mapping[ 1 ].src = mapping[ 0 ].dst;
953 mapping[ 1 ].dst = mapping[ 0 ].src;
959 if ( src[ 0 ] != '\0' ) {
960 if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
962 "%s: line %d: warning, source objectClass '%s' "
963 "should be defined in schema\n",
964 fname, lineno, src );
967 * FIXME: this should become an err
973 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
975 "%s: line %d: warning, destination objectClass '%s' "
976 "is not defined in schema\n",
977 fname, lineno, dst );
981 const char *text = NULL;
982 AttributeDescription *ad = NULL;
984 if ( src[ 0 ] != '\0' ) {
985 rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
986 if ( rc != LDAP_SUCCESS ) {
988 "%s: line %d: warning, source attributeType '%s' "
989 "should be defined in schema\n",
990 fname, lineno, src );
993 * FIXME: this should become an err
996 * we create a fake "proxied" ad
1000 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1001 &ad, &text, SLAP_AD_PROXIED );
1002 if ( rc != LDAP_SUCCESS ) {
1004 "%s: line %d: source attributeType '%s': %d (%s)\n",
1006 rc, text ? text : "" );
1014 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1015 if ( rc != LDAP_SUCCESS ) {
1017 "%s: line %d: warning, destination attributeType '%s' "
1018 "is not defined in schema\n",
1019 fname, lineno, dst );
1022 * we create a fake "proxied" ad
1026 rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1027 &ad, &text, SLAP_AD_PROXIED );
1028 if ( rc != LDAP_SUCCESS ) {
1030 "%s: line %d: source attributeType '%s': %d (%s)\n",
1032 rc, text ? text : "" );
1038 if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1039 || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1042 "%s: line %d: duplicate mapping found" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1047 if ( src[ 0 ] != '\0' ) {
1048 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1049 mapping_cmp, mapping_dup );
1051 avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1052 mapping_cmp, mapping_dup );
1058 ch_free( mapping[ 0 ].src.bv_val );
1059 ch_free( mapping[ 0 ].dst.bv_val );
1067 #ifdef ENABLE_REWRITE
1069 suffix_massage_regexize( const char *s )
1075 if ( s[ 0 ] == '\0' ) {
1076 return ch_strdup( "^(.+)$" );
1080 ( r = strchr( p, ',' ) ) != NULL;
1084 res = ch_calloc( sizeof( char ),
1086 + STRLENOF( "((.+),)?" )
1087 + STRLENOF( "[ ]?" ) * i
1088 + STRLENOF( "$" ) + 1 );
1090 ptr = lutil_strcopy( res, "((.+),)?" );
1092 ( r = strchr( p, ',' ) ) != NULL;
1094 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1095 ptr = lutil_strcopy( ptr, "[ ]?" );
1097 if ( r[ 1 ] == ' ' ) {
1101 ptr = lutil_strcopy( ptr, p );
1110 suffix_massage_patternize( const char *s, const char *p )
1117 if ( s[ 0 ] == '\0' ) {
1121 res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1122 if ( res == NULL ) {
1126 ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1127 if ( s[ 0 ] == '\0' ) {
1131 lutil_strcopy( ptr, p );
1137 suffix_massage_config(
1138 struct rewrite_info *info,
1139 struct berval *pvnc,
1140 struct berval *nvnc,
1141 struct berval *prnc,
1148 rargv[ 0 ] = "rewriteEngine";
1151 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1153 rargv[ 0 ] = "rewriteContext";
1154 rargv[ 1 ] = "default";
1156 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1158 rargv[ 0 ] = "rewriteRule";
1159 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1160 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1163 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1164 ch_free( rargv[ 1 ] );
1165 ch_free( rargv[ 2 ] );
1167 if ( BER_BVISEMPTY( pvnc ) ) {
1168 rargv[ 0 ] = "rewriteRule";
1170 rargv[ 2 ] = prnc->bv_val;
1173 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1176 rargv[ 0 ] = "rewriteContext";
1177 rargv[ 1 ] = "searchEntryDN";
1179 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1181 rargv[ 0 ] = "rewriteRule";
1182 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1183 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1186 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1187 ch_free( rargv[ 1 ] );
1188 ch_free( rargv[ 2 ] );
1190 if ( BER_BVISEMPTY( prnc ) ) {
1191 rargv[ 0 ] = "rewriteRule";
1193 rargv[ 2 ] = pvnc->bv_val;
1196 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1199 /* backward compatibility */
1200 rargv[ 0 ] = "rewriteContext";
1201 rargv[ 1 ] = "searchResult";
1202 rargv[ 2 ] = "alias";
1203 rargv[ 3 ] = "searchEntryDN";
1205 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1207 rargv[ 0 ] = "rewriteContext";
1208 rargv[ 1 ] = "matchedDN";
1209 rargv[ 2 ] = "alias";
1210 rargv[ 3 ] = "searchEntryDN";
1212 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1214 rargv[ 0 ] = "rewriteContext";
1215 rargv[ 1 ] = "searchAttrDN";
1216 rargv[ 2 ] = "alias";
1217 rargv[ 3 ] = "searchEntryDN";
1219 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1221 /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1222 * see servers/slapd/overlays/rwm.h for details */
1223 rargv[ 0 ] = "rewriteContext";
1224 rargv[ 1 ] = "referralAttrDN";
1226 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1228 rargv[ 0 ] = "rewriteContext";
1229 rargv[ 1 ] = "referralDN";
1231 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1235 #endif /* ENABLE_REWRITE */