1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2005 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
30 #include <ac/socket.h>
34 #include "back-ldap.h"
38 /* for advanced URL parsing */
39 #include "../../../libraries/libldap/ldap-int.h"
41 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
43 static ConfigDriver ldap_back_cf_gen;
46 LDAP_BACK_CFG_URI = 1,
48 LDAP_BACK_CFG_ACL_AUTHCDN,
49 LDAP_BACK_CFG_ACL_PASSWD,
50 LDAP_BACK_CFG_ACL_METHOD,
51 LDAP_BACK_CFG_ACL_BIND,
52 LDAP_BACK_CFG_IDASSERT_MODE,
53 LDAP_BACK_CFG_IDASSERT_AUTHCDN,
54 LDAP_BACK_CFG_IDASSERT_PASSWD,
55 LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
56 LDAP_BACK_CFG_IDASSERT_METHOD,
57 LDAP_BACK_CFG_IDASSERT_BIND,
65 static ConfigTable ldapcfg[] = {
66 { "uri", "uri", 2, 2, 0,
67 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_URI,
68 ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
70 "DESC 'URI (list) for remote DSA' "
71 "SYNTAX OMsDirectoryString "
74 { "tls", "what", 2, 2, 0,
75 ARG_MAGIC|LDAP_BACK_CFG_TLS,
76 ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
77 "NAME 'olcDbStartTLS' "
79 "SYNTAX OMsDirectoryString "
82 { "acl-authcDN", "DN", 2, 2, 0,
83 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
84 ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
85 "NAME 'olcDbACLAuthcDn' "
86 "DESC 'Remote ACL administrative identity' "
91 /* deprecated, will be removed; aliases "acl-authcDN" */
92 { "binddn", "DN", 2, 2, 0,
93 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
94 ldap_back_cf_gen, NULL, NULL, NULL },
95 { "acl-passwd", "cred", 2, 2, 0,
96 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
97 ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
98 "NAME 'olcDbACLPasswd' "
99 "DESC 'Remote ACL administrative identity credentials' "
101 "SYNTAX OMsDirectoryString "
104 /* deprecated, will be removed; aliases "acl-passwd" */
105 { "bindpw", "cred", 2, 2, 0,
106 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
107 ldap_back_cf_gen, NULL, NULL, NULL },
108 /* deprecated, will be removed; aliases "acl-bind" */
109 { "acl-method", "args", 2, 0, 0,
110 ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
111 ldap_back_cf_gen, NULL, NULL, NULL },
112 { "acl-bind", "args", 2, 0, 0,
113 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
114 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
115 "NAME 'olcDbACLBind' "
116 "DESC 'Remote ACL administrative identity auth bind configuration' "
117 "SYNTAX OMsDirectoryString "
120 { "idassert-authcDN", "DN", 2, 2, 0,
121 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
122 ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
123 "NAME 'olcDbIDAssertAuthcDn' "
124 "DESC 'Remote Identity Assertion administrative identity' "
129 /* deprecated, will be removed; partially aliases "idassert-authcDN" */
130 { "proxyauthzdn", "DN", 2, 2, 0,
131 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
132 ldap_back_cf_gen, NULL, NULL, NULL },
133 { "idassert-passwd", "cred", 2, 2, 0,
134 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
135 ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
136 "NAME 'olcDbIDAssertPasswd' "
137 "DESC 'Remote Identity Assertion administrative identity credentials' "
139 "SYNTAX OMsDirectoryString "
142 /* deprecated, will be removed; partially aliases "idassert-passwd" */
143 { "proxyauthzpw", "cred", 2, 2, 0,
144 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
145 ldap_back_cf_gen, NULL, NULL, NULL },
146 { "idassert-bind", "args", 2, 0, 0,
147 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
148 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
149 "NAME 'olcDbIDAssertBind' "
150 "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
151 "SYNTAX OMsDirectoryString "
154 { "idassert-method", "args", 2, 0, 0,
155 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
156 ldap_back_cf_gen, NULL, NULL, NULL },
157 { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
158 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
159 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
160 "NAME 'olcDbIDAssertMode' "
161 "DESC 'Remote Identity Assertion mode' "
163 "SYNTAX OMsDirectoryString "
166 { "idassert-authzFrom", "authzRule", 2, 2, 0,
167 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
168 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
169 "NAME 'olcDbIDAssertAuthzFrom' "
170 "DESC 'Remote Identity Assertion authz rules' "
171 "SYNTAX OMsDirectoryString "
172 "X-ORDERED 'VALUES' )",
174 { "rebind-as-user", "NO|yes", 1, 2, 0,
175 ARG_MAGIC|LDAP_BACK_CFG_REBIND,
176 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
177 "NAME 'olcDbRebindAsUser' "
178 "DESC 'Rebind as user' "
179 "SYNTAX OMsDirectoryString "
182 { "chase-referrals", "YES|no", 2, 2, 0,
183 ARG_MAGIC|LDAP_BACK_CFG_CHASE,
184 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
185 "NAME 'olcDbChaseReferrals' "
186 "DESC 'Chase referrals' "
187 "SYNTAX OMsDirectoryString "
190 { "t-f-support", "NO|yes|discover", 2, 2, 0,
191 ARG_MAGIC|LDAP_BACK_CFG_T_F,
192 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
193 "NAME 'olcDbTFSupport' "
194 "DESC 'Absolute filters support' "
195 "SYNTAX OMsDirectoryString "
198 { "proxy-whoami", "NO|yes", 1, 2, 0,
199 ARG_MAGIC|LDAP_BACK_CFG_WHOAMI,
200 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
201 "NAME 'olcDbProxyWhoAmI' "
202 "DESC 'Proxy whoAmI exop' "
203 "SYNTAX OMsDirectoryString "
206 { "suffixmassage", "[virtual]> <real", 2, 3, 0,
207 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
208 ldap_back_cf_gen, NULL, NULL, NULL },
209 { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
210 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
211 ldap_back_cf_gen, NULL, NULL, NULL },
212 { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
213 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
214 ldap_back_cf_gen, NULL, NULL, NULL },
215 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
216 NULL, NULL, NULL, NULL }
219 static ConfigOCs ldapocs[] = {
221 "NAME 'olcLDAPConfig' "
222 "DESC 'LDAP backend configuration' "
223 "SUP olcDatabaseConfig "
225 "MAY ( olcDbStartTLS "
229 "$ olcDbIDAssertAuthcDn "
230 "$ olcDbIDAssertPasswd "
231 "$ olcDbIDAssertBind "
232 "$ olcDbIDAssertMode "
233 "$ olcDbIDAssertAuthzFrom "
234 "$ olcDbRebindAsUser "
235 "$ olcDbChaseReferrals "
237 "$ olcDbProxyWhoAmI "
239 Cft_Database, ldapcfg},
243 #define LDAP_BACK_C_NO (0x0U)
244 #define LDAP_BACK_C_YES (0x1U)
245 static slap_verbmasks yn_mode[] = {
246 { BER_BVC( "yes" ), LDAP_BACK_C_YES},
247 { BER_BVC( "no" ), LDAP_BACK_C_NO },
251 static slap_verbmasks idassert_mode[] = {
252 { BER_BVC("self"), LDAP_BACK_IDASSERT_SELF },
253 { BER_BVC("anonymous"), LDAP_BACK_IDASSERT_ANONYMOUS },
254 { BER_BVC("none"), LDAP_BACK_IDASSERT_NOASSERT },
255 { BER_BVC("legacy"), LDAP_BACK_IDASSERT_LEGACY },
259 static slap_verbmasks tls_mode[] = {
260 { BER_BVC( "propagate" ), LDAP_BACK_F_TLS_PROPAGATE_MASK },
261 { BER_BVC( "try-propagate" ), LDAP_BACK_F_PROPAGATE_TLS },
262 { BER_BVC( "start" ), LDAP_BACK_F_TLS_USE_MASK },
263 { BER_BVC( "try-start" ), LDAP_BACK_F_USE_TLS },
264 { BER_BVC( "none" ), LDAP_BACK_C_NO },
268 static slap_verbmasks t_f_mode[] = {
269 { BER_BVC( "yes" ), LDAP_BACK_F_SUPPORT_T_F },
270 { BER_BVC( "discover" ), LDAP_BACK_F_SUPPORT_T_F_DISCOVER },
271 { BER_BVC( "no" ), LDAP_BACK_C_NO },
276 ldap_back_cf_gen( ConfigArgs *c )
278 struct ldapinfo *li = ( struct ldapinfo * )c->be->be_private;
282 if ( c->op == SLAP_CONFIG_EMIT ) {
283 struct berval bv = BER_BVNULL;
287 case LDAP_BACK_CFG_URI:
288 if ( li->url != NULL ) {
289 c->value_string = ch_strdup( li->url );
296 case LDAP_BACK_CFG_TLS:
297 enum_to_verb( tls_mode, ( li->flags & LDAP_BACK_F_TLS_MASK ), &bv );
298 if ( BER_BVISNULL( &bv ) ) {
299 /* there's something wrong... */
304 value_add_one( &c->rvalue_vals, &bv );
308 case LDAP_BACK_CFG_ACL_AUTHCDN:
309 case LDAP_BACK_CFG_ACL_PASSWD:
310 case LDAP_BACK_CFG_ACL_METHOD:
311 /* handled by LDAP_BACK_CFG_ACL_BIND */
315 case LDAP_BACK_CFG_ACL_BIND: {
318 bindconf_unparse( &li->acl_sb, &bv );
320 for ( i = 0; isspace( bv.bv_val[ i ] ); i++ )
325 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
329 ber_bvarray_add( &c->rvalue_vals, &bv );
333 case LDAP_BACK_CFG_IDASSERT_MODE:
334 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
335 case LDAP_BACK_CFG_IDASSERT_PASSWD:
336 case LDAP_BACK_CFG_IDASSERT_METHOD:
337 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
341 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
344 if ( li->idassert_authz == NULL ) {
349 for ( i = 0; !BER_BVISNULL( &li->idassert_authz[ i ] ); i++ )
351 value_add_one( &c->rvalue_vals, &li->idassert_authz[ i ] );
356 case LDAP_BACK_CFG_IDASSERT_BIND: {
358 struct berval bc = BER_BVNULL;
361 if ( li->idassert_authmethod != LDAP_AUTH_NONE ) {
364 switch ( li->idassert_mode ) {
365 case LDAP_BACK_IDASSERT_OTHERID:
366 case LDAP_BACK_IDASSERT_OTHERDN:
370 struct berval mode = BER_BVNULL;
372 enum_to_verb( idassert_mode, li->idassert_mode, &mode );
373 if ( BER_BVISNULL( &mode ) ) {
374 /* there's something wrong... */
379 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
380 bv.bv_val = ch_malloc( bv.bv_len + 1 );
382 ptr = lutil_strcopy( bv.bv_val, "mode=" );
383 ptr = lutil_strcopy( ptr, mode.bv_val );
389 if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
390 len = bv.bv_len + STRLENOF( "authz=native" );
392 if ( !BER_BVISEMPTY( &bv ) ) {
393 len += STRLENOF( " " );
396 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
398 ptr = &bv.bv_val[ bv.bv_len ];
400 if ( !BER_BVISEMPTY( &bv ) ) {
401 ptr = lutil_strcopy( ptr, " " );
404 (void)lutil_strcopy( ptr, "authz=native" );
407 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override" );
409 if ( !BER_BVISEMPTY( &bv ) ) {
410 len += STRLENOF( " " );
413 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
415 ptr = &bv.bv_val[ bv.bv_len ];
417 if ( !BER_BVISEMPTY( &bv ) ) {
418 ptr = lutil_strcopy( ptr, " " );
421 ptr = lutil_strcopy( ptr, "flags=" );
423 if ( li->idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
424 ptr = lutil_strcopy( ptr, "prescriptive" );
426 ptr = lutil_strcopy( ptr, "non-prescriptive" );
429 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
430 ptr = lutil_strcopy( ptr, ",override" );
433 bv.bv_len = ( ptr - bv.bv_val );
437 bindconf_unparse( &li->idassert_sb, &bc );
439 if ( !BER_BVISNULL( &bv ) ) {
440 ber_len_t len = bv.bv_len + bc.bv_len;
442 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
444 assert( bc.bv_val[ 0 ] == ' ' );
446 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
448 bv.bv_len = ptr - bv.bv_val;
451 for ( i = 0; isspace( bc.bv_val[ i ] ); i++ )
456 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
462 ber_bvarray_add( &c->rvalue_vals, &bv );
467 case LDAP_BACK_CFG_REBIND:
468 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv );
469 if ( BER_BVISNULL( &bv ) ) {
470 /* there's something wrong... */
475 value_add_one( &c->rvalue_vals, &bv );
479 case LDAP_BACK_CFG_CHASE:
480 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv );
481 if ( BER_BVISNULL( &bv ) ) {
482 /* there's something wrong... */
487 value_add_one( &c->rvalue_vals, &bv );
491 case LDAP_BACK_CFG_T_F:
492 enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv );
493 if ( BER_BVISNULL( &bv ) ) {
494 /* there's something wrong... */
499 value_add_one( &c->rvalue_vals, &bv );
503 case LDAP_BACK_CFG_WHOAMI:
504 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv );
505 if ( BER_BVISNULL( &bv ) ) {
506 /* there's something wrong... */
511 value_add_one( &c->rvalue_vals, &bv );
516 /* FIXME: we need to handle all... */
522 } else if ( c->op == LDAP_MOD_DELETE ) {
525 case LDAP_BACK_CFG_URI:
526 if ( li->url != NULL ) {
531 if ( li->lud != NULL ) {
532 ldap_free_urllist( li->lud );
536 /* better cleanup the cached connections... */
537 /* NOTE: don't worry about locking: if we got here,
538 * other threads are suspended. */
539 avl_free( li->conntree, ldap_back_conn_free );
544 case LDAP_BACK_CFG_TLS:
548 case LDAP_BACK_CFG_ACL_AUTHCDN:
549 case LDAP_BACK_CFG_ACL_PASSWD:
550 case LDAP_BACK_CFG_ACL_METHOD:
551 /* handled by LDAP_BACK_CFG_ACL_BIND */
555 case LDAP_BACK_CFG_ACL_BIND:
556 bindconf_free( &li->acl_sb );
559 case LDAP_BACK_CFG_IDASSERT_MODE:
560 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
561 case LDAP_BACK_CFG_IDASSERT_PASSWD:
562 case LDAP_BACK_CFG_IDASSERT_METHOD:
563 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
567 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
568 if ( li->idassert_authz != NULL ) {
569 ber_bvarray_free( li->idassert_authz );
570 li->idassert_authz = NULL;
574 case LDAP_BACK_CFG_IDASSERT_BIND:
575 bindconf_free( &li->idassert_sb );
578 case LDAP_BACK_CFG_REBIND:
579 case LDAP_BACK_CFG_CHASE:
580 case LDAP_BACK_CFG_T_F:
581 case LDAP_BACK_CFG_WHOAMI:
586 /* FIXME: we need to handle all... */
595 case LDAP_BACK_CFG_URI: {
596 LDAPURLDesc *tmpludp;
602 if ( c->argc != 2 ) {
603 fprintf( stderr, "%s: line %d: "
605 "in \"uri <uri>\" line\n",
606 c->fname, c->lineno );
610 if ( li->url != NULL ) {
614 if ( li->lud != NULL ) {
615 ldap_free_urllist( li->lud );
619 /* PARANOID: DN and more are not required nor allowed */
620 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
622 urlrc = ldap_url_parselist( &li->lud, c->value_string );
624 if ( urlrc != LDAP_URL_SUCCESS ) {
628 case LDAP_URL_ERR_MEM:
631 case LDAP_URL_ERR_PARAM:
632 why = "parameter is bad";
634 case LDAP_URL_ERR_BADSCHEME:
635 why = "URL doesn't begin with \"[c]ldap[si]://\"";
637 case LDAP_URL_ERR_BADENCLOSURE:
638 why = "URL is missing trailing \">\"";
640 case LDAP_URL_ERR_BADURL:
642 case LDAP_URL_ERR_BADHOST:
643 why = "host/port is bad";
645 case LDAP_URL_ERR_BADATTRS:
646 why = "bad (or missing) attributes";
648 case LDAP_URL_ERR_BADSCOPE:
649 why = "scope string is invalid (or missing)";
651 case LDAP_URL_ERR_BADFILTER:
652 why = "bad or missing filter";
654 case LDAP_URL_ERR_BADEXTS:
655 why = "bad or missing extensions";
658 why = "unknown reason";
661 fprintf( stderr, "%s: line %d: "
662 "unable to parse uri \"%s\" "
663 "in \"uri <uri>\" line: %s\n",
664 c->fname, c->lineno, c->value_string, why );
668 for ( i = 0, tmpludp = li->lud;
670 i++, tmpludp = tmpludp->lud_next )
672 if ( ( tmpludp->lud_dn != NULL
673 && tmpludp->lud_dn[0] != '\0' )
674 || tmpludp->lud_attrs != NULL
675 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
676 || tmpludp->lud_filter != NULL
677 || tmpludp->lud_exts != NULL )
679 fprintf( stderr, "%s: line %d: "
680 "warning, only protocol, "
681 "host and port allowed "
682 "in \"uri <uri>\" statement "
683 "for uri #%d of \"%s\"\n",
684 c->fname, c->lineno, i, c->value_string );
689 for ( i = 0, tmpludp = li->lud;
691 i++, tmpludp = tmpludp->lud_next )
694 urllist = ch_calloc( sizeof( char * ), i + 1 );
696 for ( i = 0, tmpludp = li->lud;
698 i++, tmpludp = tmpludp->lud_next )
701 ber_len_t oldlen = 0, len;
705 tmplud.lud_attrs = NULL;
706 tmplud.lud_filter = NULL;
707 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
708 tmplud.lud_exts = NULL;
709 tmplud.lud_crit_exts = 0;
712 urllist[ i ] = ldap_url_desc2str( &tmplud );
714 if ( urllist[ i ] == NULL ) {
715 fprintf( stderr, "%s: line %d: "
716 "unable to rebuild uri "
717 "in \"uri <uri>\" statement "
719 c->fname, c->lineno, argv[ 1 ] );
724 li->url = ldap_charray2str( urllist, " " );
725 ldap_charray_free( urllist );
727 li->url = c->value_string;
728 c->value_string = NULL;
733 case LDAP_BACK_CFG_TLS:
734 i = verb_to_mask( c->argv[1], tls_mode );
735 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
738 li->flags &= ~LDAP_BACK_F_TLS_MASK;
739 li->flags |= tls_mode[i].mask;
742 case LDAP_BACK_CFG_ACL_AUTHCDN:
743 switch ( li->acl_authmethod ) {
745 li->acl_authmethod = LDAP_AUTH_SIMPLE;
748 case LDAP_AUTH_SIMPLE:
752 fprintf( stderr, "%s: line %d: "
753 "\"acl-authcDN <DN>\" incompatible "
754 "with auth method %d.",
755 c->fname, c->lineno, li->acl_authmethod );
758 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
759 free( li->acl_authcDN.bv_val );
761 ber_memfree_x( c->value_dn.bv_val, NULL );
762 li->acl_authcDN = c->value_ndn;
763 BER_BVZERO( &c->value_dn );
764 BER_BVZERO( &c->value_ndn );
767 case LDAP_BACK_CFG_ACL_PASSWD:
768 switch ( li->acl_authmethod ) {
770 li->acl_authmethod = LDAP_AUTH_SIMPLE;
773 case LDAP_AUTH_SIMPLE:
777 fprintf( stderr, "%s: line %d: "
778 "\"acl-passwd <cred>\" incompatible "
779 "with auth method %d.",
780 c->fname, c->lineno, li->acl_authmethod );
783 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
784 free( li->acl_passwd.bv_val );
786 ber_str2bv( c->argv[ 1 ], 0, 1, &li->acl_passwd );
789 case LDAP_BACK_CFG_ACL_METHOD:
790 case LDAP_BACK_CFG_ACL_BIND:
791 for ( i = 1; i < c->argc; i++ ) {
792 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
798 case LDAP_BACK_CFG_IDASSERT_MODE:
799 i = verb_to_mask( c->argv[1], idassert_mode );
800 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
801 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
802 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
803 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
804 li->idassert_authzID.bv_val[ 0 ] = 'u';
807 struct berval id, ndn;
809 ber_str2bv( c->argv[1], 0, 0, &id );
811 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
812 id.bv_val += STRLENOF( "dn:" );
813 id.bv_len -= STRLENOF( "dn:" );
816 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
817 if ( rc != LDAP_SUCCESS ) {
818 Debug( LDAP_DEBUG_ANY,
819 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
820 c->fname, c->lineno, c->argv[1] );
824 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
825 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
826 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
827 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
828 ch_free( ndn.bv_val );
830 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
834 li->idassert_mode = idassert_mode[i].mask;
840 for ( i = 2; i < c->argc; i++ ) {
841 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
842 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
844 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
845 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
847 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
848 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
851 Debug( LDAP_DEBUG_ANY,
852 "%s: line %d: unknown flag #%d "
853 "in \"idassert-mode <args> "
854 "[<flags>]\" line.\n",
855 c->fname, c->lineno, i - 2 );
862 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
863 switch ( li->idassert_authmethod ) {
865 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
868 case LDAP_AUTH_SIMPLE:
872 fprintf( stderr, "%s: line %d: "
873 "\"idassert-authcDN <DN>\" incompatible "
874 "with auth method %d.",
875 c->fname, c->lineno, li->idassert_authmethod );
878 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
879 free( li->idassert_authcDN.bv_val );
881 ber_memfree_x( c->value_dn.bv_val, NULL );
882 li->idassert_authcDN = c->value_ndn;
883 BER_BVZERO( &c->value_dn );
884 BER_BVZERO( &c->value_ndn );
887 case LDAP_BACK_CFG_IDASSERT_PASSWD:
888 switch ( li->idassert_authmethod ) {
890 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
893 case LDAP_AUTH_SIMPLE:
897 fprintf( stderr, "%s: line %d: "
898 "\"idassert-passwd <cred>\" incompatible "
899 "with auth method %d.",
900 c->fname, c->lineno, li->idassert_authmethod );
903 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
904 free( li->idassert_passwd.bv_val );
906 ber_str2bv( c->argv[ 1 ], 0, 1, &li->idassert_passwd );
909 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
911 #ifdef SLAP_AUTHZ_SYNTAX
915 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
916 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
917 if ( rc != LDAP_SUCCESS ) {
918 fprintf( stderr, "%s: %d: "
919 "\"idassert-authzFrom <authz>\": "
921 c->fname, c->lineno );
924 #else /* !SLAP_AUTHZ_SYNTAX */
925 ber_str2bv( c->argv[ 1 ], 0, 1, &bv );
926 #endif /* !SLAP_AUTHZ_SYNTAX */
927 ber_bvarray_add( &li->idassert_authz, &bv );
930 case LDAP_BACK_CFG_IDASSERT_METHOD:
931 /* no longer supported */
932 fprintf( stderr, "%s: %d: "
933 "\"idassert-method <args>\": "
934 "no longer supported; use \"idassert-bind\".\n",
935 c->fname, c->lineno );
938 case LDAP_BACK_CFG_IDASSERT_BIND:
939 for ( i = 1; i < c->argc; i++ ) {
940 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
941 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
944 j = verb_to_mask( argvi, idassert_mode );
945 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
946 fprintf( stderr, "%s: %d: "
947 "\"idassert-bind <args>\": "
948 "unknown mode \"%s\".\n",
949 c->fname, c->lineno, argvi );
953 li->idassert_mode = idassert_mode[ j ].mask;
955 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
956 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
958 if ( strcasecmp( argvi, "native" ) == 0 ) {
959 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
960 fprintf( stderr, "%s: %d: "
961 "\"idassert-bind <args>\": "
962 "authz=\"native\" incompatible "
963 "with auth method.\n",
964 c->fname, c->lineno );
967 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
969 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
970 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
973 fprintf( stderr, "%s: %d: "
974 "\"idassert-bind <args>\": "
975 "unknown authz \"%s\".\n",
976 c->fname, c->lineno, argvi );
980 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
981 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
982 char **flags = ldap_str2charray( argvi, "," );
985 if ( flags == NULL ) {
986 fprintf( stderr, "%s: %d: "
987 "\"idassert-bind <args>\": "
988 "unable to parse flags \"%s\".\n",
989 c->fname, c->lineno, argvi );
993 for ( j = 0; flags[ j ] != NULL; j++ ) {
994 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
995 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
997 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
998 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1000 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
1001 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1004 fprintf( stderr, "%s: %d: "
1005 "\"idassert-bind <args>\": "
1006 "unknown flag \"%s\".\n",
1007 c->fname, c->lineno, flags[ j ] );
1012 ldap_charray_free( flags );
1014 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
1020 case LDAP_BACK_CFG_REBIND: {
1023 if ( c->argc == 1 ) {
1028 i = verb_to_mask( c->argv[1], yn_mode );
1029 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1032 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1038 li->flags |= LDAP_BACK_F_SAVECRED;
1041 li->flags &= ~LDAP_BACK_F_SAVECRED;
1046 case LDAP_BACK_CFG_CHASE: {
1049 if ( c->argc == 1 ) {
1054 i = verb_to_mask( c->argv[1], yn_mode );
1055 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1058 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1064 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1067 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1072 case LDAP_BACK_CFG_T_F:
1073 i = verb_to_mask( c->argv[1], t_f_mode );
1074 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1077 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1078 li->flags |= t_f_mode[i].mask;
1081 case LDAP_BACK_CFG_WHOAMI: {
1084 if ( c->argc == 1 ) {
1089 i = verb_to_mask( c->argv[1], yn_mode );
1090 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1093 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1099 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1101 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1102 0, ldap_back_exop_whoami );
1105 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1110 case LDAP_BACK_CFG_REWRITE:
1111 fprintf( stderr, "%s: line %d: "
1112 "rewrite/remap capabilities have been moved "
1113 "to the \"rwm\" overlay; see slapo-rwm(5) "
1114 "for details (hint: add \"overlay rwm\" "
1115 "and prefix all directives with \"rwm-\").\n",
1116 c->fname, c->lineno );
1120 /* FIXME: try to catch inconsistencies */
1129 ldap_back_init_cf( BackendInfo *bi )
1132 AttributeDescription *ad = NULL;
1135 bi->bi_cf_ocs = ldapocs;
1137 rc = config_register_schema( ldapcfg, ldapocs );
1142 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1143 * to be base64-encoded when written in LDIF form;
1144 * basically, we don't care if it fails */
1145 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1147 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1148 "warning, unable to get \"olcDbACLPasswd\" "
1149 "attribute description: %d: %s\n",
1152 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1153 ad->ad_type->sat_oid );
1157 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1159 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1160 "warning, unable to get \"olcDbIDAssertPasswd\" "
1161 "attribute description: %d: %s\n",
1164 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1165 ad->ad_type->sat_oid );
1173 parse_idassert( BackendDB *be, const char *fname, int lineno,
1174 int argc, char **argv );
1177 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1178 int argc, char **argv );
1181 ldap_back_db_config(
1188 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1191 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1196 /* server address to query (no longer supported, use "uri" directive) */
1197 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1199 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1203 /* URI of server to query (obsoletes "server" directive) */
1204 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1205 LDAPURLDesc *tmpludp;
1212 fprintf( stderr, "%s: line %d: "
1214 "in \"uri <uri>\" line\n",
1218 if ( li->url != NULL ) {
1221 if ( li->lud != NULL ) {
1222 ldap_free_urllist( li->lud );
1226 /* PARANOID: DN and more are not required nor allowed */
1227 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1229 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1231 if ( urlrc != LDAP_URL_SUCCESS ) {
1235 case LDAP_URL_ERR_MEM:
1238 case LDAP_URL_ERR_PARAM:
1239 why = "parameter is bad";
1241 case LDAP_URL_ERR_BADSCHEME:
1242 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1244 case LDAP_URL_ERR_BADENCLOSURE:
1245 why = "URL is missing trailing \">\"";
1247 case LDAP_URL_ERR_BADURL:
1249 case LDAP_URL_ERR_BADHOST:
1250 why = "host/port is bad";
1252 case LDAP_URL_ERR_BADATTRS:
1253 why = "bad (or missing) attributes";
1255 case LDAP_URL_ERR_BADSCOPE:
1256 why = "scope string is invalid (or missing)";
1258 case LDAP_URL_ERR_BADFILTER:
1259 why = "bad or missing filter";
1261 case LDAP_URL_ERR_BADEXTS:
1262 why = "bad or missing extensions";
1265 why = "unknown reason";
1268 fprintf( stderr, "%s: line %d: "
1269 "unable to parse uri \"%s\" "
1270 "in \"uri <uri>\" line: %s\n",
1271 fname, lineno, argv[ 1 ], why );
1275 for ( i = 0, tmpludp = li->lud;
1277 i++, tmpludp = tmpludp->lud_next )
1279 if ( ( tmpludp->lud_dn != NULL
1280 && tmpludp->lud_dn[0] != '\0' )
1281 || tmpludp->lud_attrs != NULL
1282 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1283 || tmpludp->lud_filter != NULL
1284 || tmpludp->lud_exts != NULL )
1286 fprintf( stderr, "%s: line %d: "
1287 "warning, only protocol, "
1288 "host and port allowed "
1289 "in \"uri <uri>\" statement "
1290 "for uri #%d of \"%s\"\n",
1291 fname, lineno, i, argv[1] );
1296 for ( i = 0, tmpludp = li->lud;
1298 i++, tmpludp = tmpludp->lud_next )
1301 urllist = ch_calloc( sizeof( char * ), i + 1 );
1303 for ( i = 0, tmpludp = li->lud;
1305 i++, tmpludp = tmpludp->lud_next )
1308 ber_len_t oldlen = 0, len;
1312 tmplud.lud_attrs = NULL;
1313 tmplud.lud_filter = NULL;
1314 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1315 tmplud.lud_exts = NULL;
1316 tmplud.lud_crit_exts = 0;
1319 urllist[ i ] = ldap_url_desc2str( &tmplud );
1321 if ( urllist[ i ] == NULL ) {
1322 fprintf( stderr, "%s: line %d: "
1323 "unable to rebuild uri "
1324 "in \"uri <uri>\" statement "
1326 fname, lineno, argv[ 1 ] );
1331 li->url = ldap_charray2str( urllist, " " );
1332 ldap_charray_free( urllist );
1334 li->url = ch_strdup( argv[ 1 ] );
1337 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1340 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1346 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1347 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1350 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1351 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1354 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1355 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1356 li->flags |= LDAP_BACK_F_USE_TLS;
1358 /* propagate start tls */
1359 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1360 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1363 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1364 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1365 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1369 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1370 fname, lineno, argv[1] );
1374 /* remote ACL stuff... */
1375 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1376 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1378 /* NOTE: "bind{DN,pw}" was initially used; it's now
1379 * deprected and undocumented, it can be dropped at some
1380 * point, since nobody should be really using it */
1381 return parse_acl_auth( be, fname, lineno, argc, argv );
1383 /* identity assertion stuff... */
1384 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1385 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1387 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1388 * deprected and undocumented, it can be dropped at some
1389 * point, since nobody should be really using it */
1390 return parse_idassert( be, fname, lineno, argc, argv );
1392 /* save bind creds for referral rebinds? */
1393 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1397 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1400 li->flags |= LDAP_BACK_F_SAVECRED;
1404 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1405 li->flags |= LDAP_BACK_F_SAVECRED;
1407 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1408 li->flags &= ~LDAP_BACK_F_SAVECRED;
1412 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1413 fname, lineno, argv[ 1 ] );
1420 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1425 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1428 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1433 /* this is the default; we add it because the default might change... */
1434 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1435 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1437 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1438 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1442 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1443 fname, lineno, argv[1] );
1447 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1450 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1455 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1456 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1458 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1459 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1461 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1462 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1466 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1467 fname, lineno, argv[ 1 ] );
1471 /* intercept exop_who_am_i? */
1472 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1473 int doload_extop = 0;
1478 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1485 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1488 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1490 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1491 fname, lineno, argv[ 1 ] );
1498 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1503 if ( doload_extop ) {
1504 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1506 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1507 0, ldap_back_exop_whoami );
1510 /* FIXME: legacy: intercept old rewrite/remap directives
1511 * and try to start the rwm overlay */
1512 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1513 || strcasecmp( argv[0], "map" ) == 0
1514 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1517 fprintf( stderr, "%s: line %d: "
1518 "rewrite/remap capabilities have been moved "
1519 "to the \"rwm\" overlay; see slapo-rwm(5) "
1520 "for details. I'm trying to do my best "
1521 "to preserve backwards compatibility...\n",
1524 if ( li->rwm_started == 0 ) {
1525 if ( overlay_config( be, "rwm" ) ) {
1526 fprintf( stderr, "%s: line %d: "
1527 "unable to configure the \"rwm\" "
1528 "overlay, required by directive "
1530 fname, lineno, argv[0] );
1531 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1532 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1533 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1537 fprintf( stderr, "%s: line %d: back-ldap: "
1538 "automatically starting \"rwm\" overlay, "
1539 "triggered by \"%s\" directive.\n",
1540 fname, lineno, argv[ 0 ] );
1542 /* this is the default; we add it because the default might change... */
1543 li->rwm_started = 1;
1545 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1548 fprintf( stderr, "%s: line %d: "
1549 "rewrite/remap capabilities have been moved "
1550 "to the \"rwm\" overlay; see slapo-rwm(5) "
1551 "for details (hint: add \"overlay rwm\" "
1552 "and prefix all directives with \"rwm-\").\n",
1560 return SLAP_CONF_UNKNOWN;
1567 ldap_back_exop_whoami(
1571 struct berval *bv = NULL;
1573 if ( op->oq_extended.rs_reqdata != NULL ) {
1574 /* no request data should be provided */
1575 rs->sr_text = "no request data expected";
1576 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1579 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
1580 op->o_log_prefix, 0, 0, 0, 0 );
1582 rs->sr_err = backend_check_restrictions( op, rs,
1583 (struct berval *)&slap_EXOP_WHOAMI );
1584 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1586 /* if auth'd by back-ldap and request is proxied, forward it */
1587 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)) {
1588 struct ldapconn *lc;
1590 LDAPControl c, *ctrls[2] = {NULL, NULL};
1592 Operation op2 = *op;
1597 op2.o_ndn = op->o_conn->c_ndn;
1598 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1599 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1602 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1603 c.ldctl_iscritical = 1;
1604 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1605 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1606 strcpy(c.ldctl_value.bv_val, "dn:");
1607 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1610 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1611 if (rs->sr_err == LDAP_SUCCESS) {
1612 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1613 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1615 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1617 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1620 ldap_back_freeconn( op, lc );
1624 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1628 ch_free(c.ldctl_value.bv_val);
1629 if (rs->sr_err != LDAP_SUCCESS) {
1630 rs->sr_err = slap_map_api2result( rs );
1634 ldap_back_release_conn( &op2, rs, lc );
1638 /* else just do the same as before */
1639 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1640 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1641 bv->bv_len = op->o_dn.bv_len + STRLENOF("dn:");
1642 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1643 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF("dn:") );
1644 AC_MEMCPY( &bv->bv_val[STRLENOF("dn:")], op->o_dn.bv_val,
1646 bv->bv_val[bv->bv_len] = '\0';
1653 rs->sr_rspdata = bv;
1667 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1669 /* identity assertion mode */
1670 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1672 Debug( LDAP_DEBUG_ANY,
1673 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1674 fname, lineno, argc );
1678 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1679 /* will proxyAuthz as client's identity only if bound */
1680 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1682 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1683 /* will proxyAuthz as client's identity */
1684 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1686 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1687 /* will proxyAuthz as anonymous */
1688 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1690 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1691 /* will not proxyAuthz */
1692 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1698 /* will proxyAuthz as argv[1] */
1699 ber_str2bv( argv[1], 0, 0, &id );
1701 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1702 /* force lowercase... */
1704 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1705 ber_dupbv( &li->idassert_authzID, &id );
1710 /* default is DN? */
1711 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1712 id.bv_val += STRLENOF( "dn:" );
1713 id.bv_len -= STRLENOF( "dn:" );
1716 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1717 if ( rc != LDAP_SUCCESS ) {
1718 Debug( LDAP_DEBUG_ANY,
1719 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1720 fname, lineno, argv[1] );
1724 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1725 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1726 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1727 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1728 ch_free( dn.bv_val );
1730 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1734 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1735 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1736 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1739 Debug( LDAP_DEBUG_ANY,
1740 "%s: line %d: unknown flag \"%s\" "
1741 "in \"idassert-mode <args> "
1742 "[<flags>]\" line.\n",
1743 fname, lineno, argv[0] );
1748 /* name to use for proxyAuthz propagation */
1749 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1750 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1755 /* FIXME: "proxyauthzdn" is no longer documented, and
1756 * temporarily supported for backwards compatibility */
1760 "%s: line %d: missing name in \"%s <name>\" line\n",
1761 fname, lineno, argv[0] );
1765 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1766 fprintf( stderr, "%s: line %d: "
1767 "authcDN already defined; replacing...\n",
1769 ch_free( li->idassert_authcDN.bv_val );
1772 ber_str2bv( argv[1], 0, 0, &dn );
1773 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1774 if ( rc != LDAP_SUCCESS ) {
1775 Debug( LDAP_DEBUG_ANY,
1776 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1777 fname, lineno, argv[1] );
1781 /* password to use for proxyAuthz propagation */
1782 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1783 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1785 /* FIXME: "proxyauthzpw" is no longer documented, and
1786 * temporarily supported for backwards compatibility */
1790 "%s: line %d: missing password in \"%s <password>\" line\n",
1791 fname, lineno, argv[0] );
1795 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1796 fprintf( stderr, "%s: line %d: "
1797 "passwd already defined; replacing...\n",
1799 ch_free( li->idassert_passwd.bv_val );
1802 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1804 /* rules to accept identity assertion... */
1805 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1808 ber_str2bv( argv[1], 0, 1, &rule );
1810 ber_bvarray_add( &li->idassert_authz, &rule );
1812 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1817 "%s: line %d: missing method in \"%s <method>\" line\n",
1818 fname, lineno, argv[0] );
1823 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1824 argv1 += STRLENOF( "bindmethod=" );
1827 if ( strcasecmp( argv1, "none" ) == 0 ) {
1828 /* FIXME: is this at all useful? */
1829 li->idassert_authmethod = LDAP_AUTH_NONE;
1833 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1834 fname, lineno, argv[0], argv[1] );
1837 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1840 for ( arg = 2; arg < argc; arg++ ) {
1841 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1842 char *val = argv[arg] + STRLENOF( "authcdn=" );
1846 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1847 fprintf( stderr, "%s: line %d: "
1848 "SASL authcDN already defined; replacing...\n",
1850 ch_free( li->idassert_authcDN.bv_val );
1852 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1853 val += STRLENOF( "dn:" );
1856 ber_str2bv( val, 0, 0, &dn );
1857 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1858 if ( rc != LDAP_SUCCESS ) {
1859 Debug( LDAP_DEBUG_ANY,
1860 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1861 fname, lineno, val );
1865 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1866 char *val = argv[arg] + STRLENOF( "cred=" );
1868 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1869 fprintf( stderr, "%s: line %d: "
1870 "SASL cred already defined; replacing...\n",
1872 ch_free( li->idassert_passwd.bv_val );
1874 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1877 fprintf( stderr, "%s: line %d: "
1878 "unknown parameter %s\n",
1879 fname, lineno, argv[arg] );
1884 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1886 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1887 #ifdef HAVE_CYRUS_SASL
1890 for ( arg = 2; arg < argc; arg++ ) {
1891 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1892 char *val = argv[arg] + STRLENOF( "mech=" );
1894 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1895 fprintf( stderr, "%s: line %d: "
1896 "SASL mech already defined; replacing...\n",
1898 ch_free( li->idassert_sasl_mech.bv_val );
1900 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1902 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1903 char *val = argv[arg] + STRLENOF( "realm=" );
1905 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1906 fprintf( stderr, "%s: line %d: "
1907 "SASL realm already defined; replacing...\n",
1909 ch_free( li->idassert_sasl_realm.bv_val );
1911 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1913 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1914 char *val = argv[arg] + STRLENOF( "authcdn=" );
1918 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1919 fprintf( stderr, "%s: line %d: "
1920 "SASL authcDN already defined; replacing...\n",
1922 ch_free( li->idassert_authcDN.bv_val );
1924 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1925 val += STRLENOF( "dn:" );
1928 ber_str2bv( val, 0, 0, &dn );
1929 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1930 if ( rc != LDAP_SUCCESS ) {
1931 Debug( LDAP_DEBUG_ANY,
1932 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1933 fname, lineno, val );
1937 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1938 char *val = argv[arg] + STRLENOF( "authcid=" );
1940 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1941 fprintf( stderr, "%s: line %d: "
1942 "SASL authcID already defined; replacing...\n",
1944 ch_free( li->idassert_authcID.bv_val );
1946 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1947 val += STRLENOF( "u:" );
1949 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1951 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1952 char *val = argv[arg] + STRLENOF( "cred=" );
1954 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1955 fprintf( stderr, "%s: line %d: "
1956 "SASL cred already defined; replacing...\n",
1958 ch_free( li->idassert_passwd.bv_val );
1960 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1962 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1963 char *val = argv[arg] + STRLENOF( "authz=" );
1965 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1966 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1968 } else if ( strcasecmp( val, "native" ) == 0 ) {
1969 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1972 fprintf( stderr, "%s: line %d: "
1973 "unknown authz mode \"%s\"\n",
1974 fname, lineno, val );
1979 fprintf( stderr, "%s: line %d: "
1980 "unknown SASL parameter %s\n",
1981 fname, lineno, argv[arg] );
1986 li->idassert_authmethod = LDAP_AUTH_SASL;
1988 #else /* !HAVE_CYRUS_SASL */
1989 fprintf( stderr, "%s: line %d: "
1990 "compile --with-cyrus-sasl to enable SASL auth\n",
1993 #endif /* !HAVE_CYRUS_SASL */
1996 fprintf( stderr, "%s: line %d: "
1997 "unhandled idassert-method method %s\n",
1998 fname, lineno, argv[1] );
2003 return SLAP_CONF_UNKNOWN;
2018 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
2020 /* name to use for remote ACL access */
2021 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
2022 || strcasecmp( argv[0], "binddn" ) == 0 )
2027 /* FIXME: "binddn" is no longer documented, and
2028 * temporarily supported for backwards compatibility */
2032 "%s: line %d: missing name in \"%s <name>\" line\n",
2033 fname, lineno, argv[0] );
2037 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2038 fprintf( stderr, "%s: line %d: "
2039 "authcDN already defined; replacing...\n",
2041 ch_free( li->acl_authcDN.bv_val );
2044 ber_str2bv( argv[1], 0, 0, &dn );
2045 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2046 if ( rc != LDAP_SUCCESS ) {
2047 Debug( LDAP_DEBUG_ANY,
2048 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
2049 fname, lineno, argv[1] );
2053 /* password to use for remote ACL access */
2054 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
2055 || strcasecmp( argv[0], "bindpw" ) == 0 )
2057 /* FIXME: "bindpw" is no longer documented, and
2058 * temporarily supported for backwards compatibility */
2062 "%s: line %d: missing password in \"%s <password>\" line\n",
2063 fname, lineno, argv[0] );
2067 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2068 fprintf( stderr, "%s: line %d: "
2069 "passwd already defined; replacing...\n",
2071 ch_free( li->acl_passwd.bv_val );
2074 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2076 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2081 "%s: line %d: missing method in \"%s <method>\" line\n",
2082 fname, lineno, argv[0] );
2087 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2088 argv1 += STRLENOF( "bindmethod=" );
2091 if ( strcasecmp( argv1, "none" ) == 0 ) {
2092 /* FIXME: is this at all useful? */
2093 li->acl_authmethod = LDAP_AUTH_NONE;
2097 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2098 fname, lineno, argv[0], argv[1] );
2101 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2102 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2106 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2107 fname, lineno, argv[0], argv[1] );
2110 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2111 #ifdef HAVE_CYRUS_SASL
2114 for ( arg = 2; arg < argc; arg++ ) {
2115 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2116 char *val = argv[arg] + STRLENOF( "mech=" );
2118 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2119 fprintf( stderr, "%s: line %d: "
2120 "SASL mech already defined; replacing...\n",
2122 ch_free( li->acl_sasl_mech.bv_val );
2124 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2126 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2127 char *val = argv[arg] + STRLENOF( "realm=" );
2129 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2130 fprintf( stderr, "%s: line %d: "
2131 "SASL realm already defined; replacing...\n",
2133 ch_free( li->acl_sasl_realm.bv_val );
2135 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2137 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2138 char *val = argv[arg] + STRLENOF( "authcdn=" );
2142 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2143 fprintf( stderr, "%s: line %d: "
2144 "SASL authcDN already defined; replacing...\n",
2146 ch_free( li->acl_authcDN.bv_val );
2148 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2149 val += STRLENOF( "dn:" );
2152 ber_str2bv( val, 0, 0, &dn );
2153 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2154 if ( rc != LDAP_SUCCESS ) {
2155 Debug( LDAP_DEBUG_ANY,
2156 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2157 fname, lineno, val );
2161 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2162 char *val = argv[arg] + STRLENOF( "authcid=" );
2164 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2165 fprintf( stderr, "%s: line %d: "
2166 "SASL authcID already defined; replacing...\n",
2168 ch_free( li->acl_authcID.bv_val );
2170 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2171 val += STRLENOF( "u:" );
2173 ber_str2bv( val, 0, 1, &li->acl_authcID );
2175 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2176 char *val = argv[arg] + STRLENOF( "cred=" );
2178 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2179 fprintf( stderr, "%s: line %d: "
2180 "SASL cred already defined; replacing...\n",
2182 ch_free( li->acl_passwd.bv_val );
2184 ber_str2bv( val, 0, 1, &li->acl_passwd );
2187 fprintf( stderr, "%s: line %d: "
2188 "unknown SASL parameter %s\n",
2189 fname, lineno, argv[arg] );
2194 li->acl_authmethod = LDAP_AUTH_SASL;
2196 #else /* !HAVE_CYRUS_SASL */
2197 fprintf( stderr, "%s: line %d: "
2198 "compile --with-cyrus-sasl to enable SASL auth\n",
2201 #endif /* !HAVE_CYRUS_SASL */
2204 fprintf( stderr, "%s: line %d: "
2205 "unhandled acl-method method %s\n",
2206 fname, lineno, argv[1] );
2211 return SLAP_CONF_UNKNOWN;