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_BERVAL|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; 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_BERVAL|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; aliases "acl-passwd" */
105 { "bindpw", "cred", 2, 2, 0,
106 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
107 ldap_back_cf_gen, NULL, NULL, NULL },
108 { "acl-bind", "args", 2, 0, 0,
109 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
110 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
111 "NAME 'olcDbACLBind' "
112 "DESC 'Remote ACL administrative identity auth bind configuration' "
113 "SYNTAX OMsDirectoryString "
116 /* deprecated; aliases "acl-bind" */
117 { "acl-method", "args", 2, 0, 0,
118 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
119 ldap_back_cf_gen, NULL, NULL, NULL },
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; 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_BERVAL|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; partially aliases "idassert-passwd" */
143 { "proxyauthzpw", "cred", 2, 2, 0,
144 ARG_BERVAL|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_BERVAL|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_BERVAL|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_BERVAL|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_BERVAL|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_BERVAL|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_BERVAL|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... */
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 c->value_string = bv.bv_val;
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 c->value_string = ch_realloc( bv.bv_val, len + 1 );
444 assert( bc.bv_val[ 0 ] == ' ' );
446 (void)lutil_strcopy( &c->value_string[ bv.bv_len ], bc.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 );
459 c->value_string = bv.bv_val;
465 case LDAP_BACK_CFG_REBIND:
466 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv );
467 if ( BER_BVISNULL( &bv ) ) {
468 /* there's something wrong... */
477 case LDAP_BACK_CFG_CHASE:
478 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv );
479 if ( BER_BVISNULL( &bv ) ) {
480 /* there's something wrong... */
489 case LDAP_BACK_CFG_T_F:
490 enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv );
491 if ( BER_BVISNULL( &bv ) ) {
492 /* there's something wrong... */
501 case LDAP_BACK_CFG_WHOAMI:
502 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv );
503 if ( BER_BVISNULL( &bv ) ) {
504 /* there's something wrong... */
514 /* we need to handle all... */
520 } else if ( c->op == LDAP_MOD_DELETE ) {
523 case LDAP_BACK_CFG_URI:
524 if ( li->url != NULL ) {
529 if ( li->lud != NULL ) {
530 ldap_free_urllist( li->lud );
534 /* better cleanup the cached connections... */
535 /* NOTE: don't worry about locking: if we got here,
536 * other threads are suspended. */
537 avl_free( li->conntree, ldap_back_conn_free );
542 case LDAP_BACK_CFG_TLS:
543 case LDAP_BACK_CFG_ACL_AUTHCDN:
544 case LDAP_BACK_CFG_ACL_PASSWD:
545 case LDAP_BACK_CFG_ACL_METHOD:
546 /* handled by LDAP_BACK_CFG_ACL_BIND */
550 case LDAP_BACK_CFG_ACL_BIND:
551 bindconf_free( &li->acl_sb );
554 case LDAP_BACK_CFG_IDASSERT_MODE:
555 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
556 case LDAP_BACK_CFG_IDASSERT_PASSWD:
557 case LDAP_BACK_CFG_IDASSERT_METHOD:
558 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
562 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
563 if ( li->idassert_authz != NULL ) {
564 ber_bvarray_free( li->idassert_authz );
565 li->idassert_authz = NULL;
569 case LDAP_BACK_CFG_IDASSERT_BIND:
570 bindconf_free( &li->idassert_sb );
573 case LDAP_BACK_CFG_REBIND:
574 case LDAP_BACK_CFG_CHASE:
575 case LDAP_BACK_CFG_T_F:
576 case LDAP_BACK_CFG_WHOAMI:
581 /* we need to handle all... */
590 case LDAP_BACK_CFG_URI: {
591 LDAPURLDesc *tmpludp;
597 if ( c->argc != 2 ) {
598 fprintf( stderr, "%s: line %d: "
600 "in \"uri <uri>\" line\n",
601 c->fname, c->lineno );
605 if ( li->url != NULL ) {
609 if ( li->lud != NULL ) {
610 ldap_free_urllist( li->lud );
614 /* PARANOID: DN and more are not required nor allowed */
615 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
617 urlrc = ldap_url_parselist( &li->lud, c->value_string );
619 if ( urlrc != LDAP_URL_SUCCESS ) {
623 case LDAP_URL_ERR_MEM:
626 case LDAP_URL_ERR_PARAM:
627 why = "parameter is bad";
629 case LDAP_URL_ERR_BADSCHEME:
630 why = "URL doesn't begin with \"[c]ldap[si]://\"";
632 case LDAP_URL_ERR_BADENCLOSURE:
633 why = "URL is missing trailing \">\"";
635 case LDAP_URL_ERR_BADURL:
637 case LDAP_URL_ERR_BADHOST:
638 why = "host/port is bad";
640 case LDAP_URL_ERR_BADATTRS:
641 why = "bad (or missing) attributes";
643 case LDAP_URL_ERR_BADSCOPE:
644 why = "scope string is invalid (or missing)";
646 case LDAP_URL_ERR_BADFILTER:
647 why = "bad or missing filter";
649 case LDAP_URL_ERR_BADEXTS:
650 why = "bad or missing extensions";
653 why = "unknown reason";
656 fprintf( stderr, "%s: line %d: "
657 "unable to parse uri \"%s\" "
658 "in \"uri <uri>\" line: %s\n",
659 c->fname, c->lineno, c->value_string, why );
663 for ( i = 0, tmpludp = li->lud;
665 i++, tmpludp = tmpludp->lud_next )
667 if ( ( tmpludp->lud_dn != NULL
668 && tmpludp->lud_dn[0] != '\0' )
669 || tmpludp->lud_attrs != NULL
670 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
671 || tmpludp->lud_filter != NULL
672 || tmpludp->lud_exts != NULL )
674 fprintf( stderr, "%s: line %d: "
675 "warning, only protocol, "
676 "host and port allowed "
677 "in \"uri <uri>\" statement "
678 "for uri #%d of \"%s\"\n",
679 c->fname, c->lineno, i, c->value_string );
684 for ( i = 0, tmpludp = li->lud;
686 i++, tmpludp = tmpludp->lud_next )
689 urllist = ch_calloc( sizeof( char * ), i + 1 );
691 for ( i = 0, tmpludp = li->lud;
693 i++, tmpludp = tmpludp->lud_next )
696 ber_len_t oldlen = 0, len;
700 tmplud.lud_attrs = NULL;
701 tmplud.lud_filter = NULL;
702 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
703 tmplud.lud_exts = NULL;
704 tmplud.lud_crit_exts = 0;
707 urllist[ i ] = ldap_url_desc2str( &tmplud );
709 if ( urllist[ i ] == NULL ) {
710 fprintf( stderr, "%s: line %d: "
711 "unable to rebuild uri "
712 "in \"uri <uri>\" statement "
714 c->fname, c->lineno, argv[ 1 ] );
719 li->url = ldap_charray2str( urllist, " " );
720 ldap_charray_free( urllist );
722 li->url = c->value_string;
727 case LDAP_BACK_CFG_TLS:
728 i = verb_to_mask( c->argv[1], tls_mode );
729 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
732 li->flags &= ~LDAP_BACK_F_TLS_MASK;
733 li->flags |= tls_mode[i].mask;
736 case LDAP_BACK_CFG_ACL_AUTHCDN:
737 switch ( li->acl_authmethod ) {
739 li->acl_authmethod = LDAP_AUTH_SIMPLE;
742 case LDAP_AUTH_SIMPLE:
746 fprintf( stderr, "%s: line %d: "
747 "\"acl-authcDN <DN>\" incompatible "
748 "with auth method %d.",
749 c->fname, c->lineno, li->acl_authmethod );
752 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
753 free( li->acl_authcDN.bv_val );
755 li->acl_authcDN = c->value_ndn;
758 case LDAP_BACK_CFG_ACL_PASSWD:
759 switch ( li->acl_authmethod ) {
761 li->acl_authmethod = LDAP_AUTH_SIMPLE;
764 case LDAP_AUTH_SIMPLE:
768 fprintf( stderr, "%s: line %d: "
769 "\"acl-passwd <cred>\" incompatible "
770 "with auth method %d.",
771 c->fname, c->lineno, li->acl_authmethod );
774 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
775 free( li->acl_passwd.bv_val );
777 li->acl_passwd = c->value_bv;
780 case LDAP_BACK_CFG_ACL_METHOD:
781 case LDAP_BACK_CFG_ACL_BIND:
782 for ( i = 1; i < c->argc; i++ ) {
783 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
789 case LDAP_BACK_CFG_IDASSERT_MODE:
790 i = verb_to_mask( c->argv[1], idassert_mode );
791 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
792 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
793 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
794 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
795 li->idassert_authzID.bv_val[ 0 ] = 'u';
798 struct berval id, ndn;
800 ber_str2bv( c->argv[1], 0, 0, &id );
802 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
803 id.bv_val += STRLENOF( "dn:" );
804 id.bv_len -= STRLENOF( "dn:" );
807 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
808 if ( rc != LDAP_SUCCESS ) {
809 Debug( LDAP_DEBUG_ANY,
810 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
811 c->fname, c->lineno, c->argv[1] );
815 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
816 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
817 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
818 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
819 ch_free( ndn.bv_val );
821 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
825 li->idassert_mode = idassert_mode[i].mask;
831 for ( i = 2; i < c->argc; i++ ) {
832 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
833 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
835 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
836 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
838 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
839 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
842 Debug( LDAP_DEBUG_ANY,
843 "%s: line %d: unknown flag #%d "
844 "in \"idassert-mode <args> "
845 "[<flags>]\" line.\n",
846 c->fname, c->lineno, i - 2 );
853 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
854 switch ( li->idassert_authmethod ) {
856 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
859 case LDAP_AUTH_SIMPLE:
863 fprintf( stderr, "%s: line %d: "
864 "\"idassert-authcDN <DN>\" incompatible "
865 "with auth method %d.",
866 c->fname, c->lineno, li->idassert_authmethod );
869 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
870 free( li->idassert_authcDN.bv_val );
872 li->idassert_authcDN = c->value_ndn;
875 case LDAP_BACK_CFG_IDASSERT_PASSWD:
876 switch ( li->idassert_authmethod ) {
878 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
881 case LDAP_AUTH_SIMPLE:
885 fprintf( stderr, "%s: line %d: "
886 "\"idassert-passwd <cred>\" incompatible "
887 "with auth method %d.",
888 c->fname, c->lineno, li->idassert_authmethod );
891 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
892 free( li->idassert_passwd.bv_val );
894 li->idassert_passwd = c->value_bv;
897 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
898 ber_bvarray_add( &li->idassert_authz, &c->value_bv );
901 case LDAP_BACK_CFG_IDASSERT_METHOD:
902 /* no longer supported */
903 fprintf( stderr, "%s: %d: "
904 "\"idassert-method <args>\": "
905 "no longer supported; use \"idassert-bind\".\n",
906 c->fname, c->lineno );
909 case LDAP_BACK_CFG_IDASSERT_BIND:
910 for ( i = 1; i < c->argc; i++ ) {
911 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
912 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
915 j = verb_to_mask( argvi, idassert_mode );
916 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
917 fprintf( stderr, "%s: %d: "
918 "\"idassert-bind <args>\": "
919 "unknown mode \"%s\".\n",
920 c->fname, c->lineno, argvi );
924 li->idassert_mode = idassert_mode[ j ].mask;
926 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
927 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
929 if ( strcasecmp( argvi, "native" ) == 0 ) {
930 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
931 fprintf( stderr, "%s: %d: "
932 "\"idassert-bind <args>\": "
933 "authz=\"native\" incompatible "
934 "with auth method.\n",
935 c->fname, c->lineno );
938 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
940 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
941 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
944 fprintf( stderr, "%s: %d: "
945 "\"idassert-bind <args>\": "
946 "unknown authz \"%s\".\n",
947 c->fname, c->lineno, argvi );
951 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
952 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
953 char **flags = ldap_str2charray( argvi, "," );
956 if ( flags == NULL ) {
957 fprintf( stderr, "%s: %d: "
958 "\"idassert-bind <args>\": "
959 "unable to parse flags \"%s\".\n",
960 c->fname, c->lineno, argvi );
964 for ( j = 0; flags[ j ] != NULL; j++ ) {
965 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
966 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
968 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
969 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
971 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
972 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
975 fprintf( stderr, "%s: %d: "
976 "\"idassert-bind <args>\": "
977 "unknown flag \"%s\".\n",
978 c->fname, c->lineno, flags[ j ] );
983 ldap_charray_free( flags );
985 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
991 case LDAP_BACK_CFG_REBIND: {
994 if ( c->argc == 1 ) {
999 i = verb_to_mask( c->argv[1], yn_mode );
1000 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1003 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1009 li->flags |= LDAP_BACK_F_SAVECRED;
1012 li->flags &= ~LDAP_BACK_F_SAVECRED;
1017 case LDAP_BACK_CFG_CHASE: {
1020 if ( c->argc == 1 ) {
1025 i = verb_to_mask( c->argv[1], yn_mode );
1026 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1029 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1035 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1038 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1043 case LDAP_BACK_CFG_T_F:
1044 i = verb_to_mask( c->argv[1], t_f_mode );
1045 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1048 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1049 li->flags |= t_f_mode[i].mask;
1052 case LDAP_BACK_CFG_WHOAMI: {
1055 if ( c->argc == 1 ) {
1060 i = verb_to_mask( c->argv[1], yn_mode );
1061 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1064 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1070 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1072 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1073 0, ldap_back_exop_whoami );
1076 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1081 case LDAP_BACK_CFG_REWRITE:
1082 fprintf( stderr, "%s: line %d: "
1083 "rewrite/remap capabilities have been moved "
1084 "to the \"rwm\" overlay; see slapo-rwm(5) "
1085 "for details (hint: add \"overlay rwm\" "
1086 "and prefix all directives with \"rwm-\").\n",
1087 c->fname, c->lineno );
1098 ldap_back_init_cf( BackendInfo *bi )
1101 AttributeDescription *ad = NULL;
1104 bi->bi_cf_ocs = ldapocs;
1106 rc = config_register_schema( ldapcfg, ldapocs );
1111 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1112 * to be base64-encoded when written in LDIF form;
1113 * basically, we don't care if it fails */
1114 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1116 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1117 "warning, unable to get \"olcDbACLPasswd\" "
1118 "attribute description: %d: %s\n",
1121 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1122 ad->ad_type->sat_oid );
1126 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1128 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1129 "warning, unable to get \"olcDbIDAssertPasswd\" "
1130 "attribute description: %d: %s\n",
1133 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1134 ad->ad_type->sat_oid );
1142 parse_idassert( BackendDB *be, const char *fname, int lineno,
1143 int argc, char **argv );
1146 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1147 int argc, char **argv );
1150 ldap_back_db_config(
1157 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1160 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1165 /* server address to query (no longer supported, use "uri" directive) */
1166 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1168 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1172 /* URI of server to query (obsoletes "server" directive) */
1173 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1174 LDAPURLDesc *tmpludp;
1181 fprintf( stderr, "%s: line %d: "
1183 "in \"uri <uri>\" line\n",
1187 if ( li->url != NULL ) {
1190 if ( li->lud != NULL ) {
1191 ldap_free_urllist( li->lud );
1195 /* PARANOID: DN and more are not required nor allowed */
1196 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1198 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1200 if ( urlrc != LDAP_URL_SUCCESS ) {
1204 case LDAP_URL_ERR_MEM:
1207 case LDAP_URL_ERR_PARAM:
1208 why = "parameter is bad";
1210 case LDAP_URL_ERR_BADSCHEME:
1211 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1213 case LDAP_URL_ERR_BADENCLOSURE:
1214 why = "URL is missing trailing \">\"";
1216 case LDAP_URL_ERR_BADURL:
1218 case LDAP_URL_ERR_BADHOST:
1219 why = "host/port is bad";
1221 case LDAP_URL_ERR_BADATTRS:
1222 why = "bad (or missing) attributes";
1224 case LDAP_URL_ERR_BADSCOPE:
1225 why = "scope string is invalid (or missing)";
1227 case LDAP_URL_ERR_BADFILTER:
1228 why = "bad or missing filter";
1230 case LDAP_URL_ERR_BADEXTS:
1231 why = "bad or missing extensions";
1234 why = "unknown reason";
1237 fprintf( stderr, "%s: line %d: "
1238 "unable to parse uri \"%s\" "
1239 "in \"uri <uri>\" line: %s\n",
1240 fname, lineno, argv[ 1 ], why );
1244 for ( i = 0, tmpludp = li->lud;
1246 i++, tmpludp = tmpludp->lud_next )
1248 if ( ( tmpludp->lud_dn != NULL
1249 && tmpludp->lud_dn[0] != '\0' )
1250 || tmpludp->lud_attrs != NULL
1251 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1252 || tmpludp->lud_filter != NULL
1253 || tmpludp->lud_exts != NULL )
1255 fprintf( stderr, "%s: line %d: "
1256 "warning, only protocol, "
1257 "host and port allowed "
1258 "in \"uri <uri>\" statement "
1259 "for uri #%d of \"%s\"\n",
1260 fname, lineno, i, argv[1] );
1265 for ( i = 0, tmpludp = li->lud;
1267 i++, tmpludp = tmpludp->lud_next )
1270 urllist = ch_calloc( sizeof( char * ), i + 1 );
1272 for ( i = 0, tmpludp = li->lud;
1274 i++, tmpludp = tmpludp->lud_next )
1277 ber_len_t oldlen = 0, len;
1281 tmplud.lud_attrs = NULL;
1282 tmplud.lud_filter = NULL;
1283 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1284 tmplud.lud_exts = NULL;
1285 tmplud.lud_crit_exts = 0;
1288 urllist[ i ] = ldap_url_desc2str( &tmplud );
1290 if ( urllist[ i ] == NULL ) {
1291 fprintf( stderr, "%s: line %d: "
1292 "unable to rebuild uri "
1293 "in \"uri <uri>\" statement "
1295 fname, lineno, argv[ 1 ] );
1300 li->url = ldap_charray2str( urllist, " " );
1301 ldap_charray_free( urllist );
1303 li->url = ch_strdup( argv[ 1 ] );
1306 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1309 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1315 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1316 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1319 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1320 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1323 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1324 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1325 li->flags |= LDAP_BACK_F_USE_TLS;
1327 /* propagate start tls */
1328 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1329 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1332 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1333 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1334 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1338 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1339 fname, lineno, argv[1] );
1343 /* remote ACL stuff... */
1344 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1345 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1347 /* NOTE: "bind{DN,pw}" was initially used; it's now
1348 * deprected and undocumented, it can be dropped at some
1349 * point, since nobody should be really using it */
1350 return parse_acl_auth( be, fname, lineno, argc, argv );
1352 /* identity assertion stuff... */
1353 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1354 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1356 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1357 * deprected and undocumented, it can be dropped at some
1358 * point, since nobody should be really using it */
1359 return parse_idassert( be, fname, lineno, argc, argv );
1361 /* save bind creds for referral rebinds? */
1362 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1366 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1369 li->flags |= LDAP_BACK_F_SAVECRED;
1373 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1374 li->flags |= LDAP_BACK_F_SAVECRED;
1376 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1377 li->flags &= ~LDAP_BACK_F_SAVECRED;
1381 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1382 fname, lineno, argv[ 1 ] );
1389 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1394 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1397 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1402 /* this is the default; we add it because the default might change... */
1403 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1404 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1406 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1407 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1411 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1412 fname, lineno, argv[1] );
1416 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1419 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1424 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1425 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1427 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1428 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1430 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1431 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1435 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1436 fname, lineno, argv[ 1 ] );
1440 /* intercept exop_who_am_i? */
1441 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1442 int doload_extop = 0;
1447 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1454 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1457 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1459 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1460 fname, lineno, argv[ 1 ] );
1467 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1472 if ( doload_extop ) {
1473 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1475 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1476 0, ldap_back_exop_whoami );
1479 /* FIXME: legacy: intercept old rewrite/remap directives
1480 * and try to start the rwm overlay */
1481 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1482 || strcasecmp( argv[0], "map" ) == 0
1483 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1486 fprintf( stderr, "%s: line %d: "
1487 "rewrite/remap capabilities have been moved "
1488 "to the \"rwm\" overlay; see slapo-rwm(5) "
1489 "for details. I'm trying to do my best "
1490 "to preserve backwards compatibility...\n",
1493 if ( li->rwm_started == 0 ) {
1494 if ( overlay_config( be, "rwm" ) ) {
1495 fprintf( stderr, "%s: line %d: "
1496 "unable to configure the \"rwm\" "
1497 "overlay, required by directive "
1499 fname, lineno, argv[0] );
1500 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1501 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1502 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1506 fprintf( stderr, "%s: line %d: back-ldap: "
1507 "automatically starting \"rwm\" overlay, "
1508 "triggered by \"%s\" directive.\n",
1509 fname, lineno, argv[ 0 ] );
1511 /* this is the default; we add it because the default might change... */
1512 li->rwm_started = 1;
1514 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
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 (hint: add \"overlay rwm\" "
1521 "and prefix all directives with \"rwm-\").\n",
1529 return SLAP_CONF_UNKNOWN;
1536 ldap_back_exop_whoami(
1540 struct berval *bv = NULL;
1542 if ( op->oq_extended.rs_reqdata != NULL ) {
1543 /* no request data should be provided */
1544 rs->sr_text = "no request data expected";
1545 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1548 rs->sr_err = backend_check_restrictions( op, rs,
1549 (struct berval *)&slap_EXOP_WHOAMI );
1550 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1552 /* if auth'd by back-ldap and request is proxied, forward it */
1553 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)) {
1554 struct ldapconn *lc;
1556 LDAPControl c, *ctrls[2] = {NULL, NULL};
1558 Operation op2 = *op;
1563 op2.o_ndn = op->o_conn->c_ndn;
1564 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1565 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1568 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1569 c.ldctl_iscritical = 1;
1570 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1571 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1572 strcpy(c.ldctl_value.bv_val, "dn:");
1573 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1576 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1577 if (rs->sr_err == LDAP_SUCCESS) {
1578 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1579 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1581 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1583 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1586 ldap_back_freeconn( op, lc );
1590 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1594 ch_free(c.ldctl_value.bv_val);
1595 if (rs->sr_err != LDAP_SUCCESS) {
1596 rs->sr_err = slap_map_api2result( rs );
1600 ldap_back_release_conn( &op2, rs, lc );
1604 /* else just do the same as before */
1605 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1606 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1607 bv->bv_len = op->o_dn.bv_len + STRLENOF("dn:");
1608 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1609 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF("dn:") );
1610 AC_MEMCPY( &bv->bv_val[STRLENOF("dn:")], op->o_dn.bv_val,
1612 bv->bv_val[bv->bv_len] = '\0';
1619 rs->sr_rspdata = bv;
1633 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1635 /* identity assertion mode */
1636 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1638 Debug( LDAP_DEBUG_ANY,
1639 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1640 fname, lineno, argc );
1644 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1645 /* will proxyAuthz as client's identity only if bound */
1646 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1648 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1649 /* will proxyAuthz as client's identity */
1650 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1652 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1653 /* will proxyAuthz as anonymous */
1654 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1656 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1657 /* will not proxyAuthz */
1658 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1664 /* will proxyAuthz as argv[1] */
1665 ber_str2bv( argv[1], 0, 0, &id );
1667 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1668 /* force lowercase... */
1670 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1671 ber_dupbv( &li->idassert_authzID, &id );
1676 /* default is DN? */
1677 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1678 id.bv_val += STRLENOF( "dn:" );
1679 id.bv_len -= STRLENOF( "dn:" );
1682 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1683 if ( rc != LDAP_SUCCESS ) {
1684 Debug( LDAP_DEBUG_ANY,
1685 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1686 fname, lineno, argv[1] );
1690 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1691 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1692 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1693 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1694 ch_free( dn.bv_val );
1696 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1700 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1701 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1702 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1705 Debug( LDAP_DEBUG_ANY,
1706 "%s: line %d: unknown flag \"%s\" "
1707 "in \"idassert-mode <args> "
1708 "[<flags>]\" line.\n",
1709 fname, lineno, argv[0] );
1714 /* name to use for proxyAuthz propagation */
1715 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1716 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1721 /* FIXME: "proxyauthzdn" is no longer documented, and
1722 * temporarily supported for backwards compatibility */
1726 "%s: line %d: missing name in \"%s <name>\" line\n",
1727 fname, lineno, argv[0] );
1731 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1732 fprintf( stderr, "%s: line %d: "
1733 "authcDN already defined; replacing...\n",
1735 ch_free( li->idassert_authcDN.bv_val );
1738 ber_str2bv( argv[1], 0, 0, &dn );
1739 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1740 if ( rc != LDAP_SUCCESS ) {
1741 Debug( LDAP_DEBUG_ANY,
1742 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1743 fname, lineno, argv[1] );
1747 /* password to use for proxyAuthz propagation */
1748 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1749 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1751 /* FIXME: "proxyauthzpw" is no longer documented, and
1752 * temporarily supported for backwards compatibility */
1756 "%s: line %d: missing password in \"%s <password>\" line\n",
1757 fname, lineno, argv[0] );
1761 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1762 fprintf( stderr, "%s: line %d: "
1763 "passwd already defined; replacing...\n",
1765 ch_free( li->idassert_passwd.bv_val );
1768 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1770 /* rules to accept identity assertion... */
1771 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1774 ber_str2bv( argv[1], 0, 1, &rule );
1776 ber_bvarray_add( &li->idassert_authz, &rule );
1778 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1783 "%s: line %d: missing method in \"%s <method>\" line\n",
1784 fname, lineno, argv[0] );
1789 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1790 argv1 += STRLENOF( "bindmethod=" );
1793 if ( strcasecmp( argv1, "none" ) == 0 ) {
1794 /* FIXME: is this at all useful? */
1795 li->idassert_authmethod = LDAP_AUTH_NONE;
1799 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1800 fname, lineno, argv[0], argv[1] );
1803 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1806 for ( arg = 2; arg < argc; arg++ ) {
1807 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1808 char *val = argv[arg] + STRLENOF( "authcdn=" );
1812 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1813 fprintf( stderr, "%s: line %d: "
1814 "SASL authcDN already defined; replacing...\n",
1816 ch_free( li->idassert_authcDN.bv_val );
1818 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1819 val += STRLENOF( "dn:" );
1822 ber_str2bv( val, 0, 0, &dn );
1823 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1824 if ( rc != LDAP_SUCCESS ) {
1825 Debug( LDAP_DEBUG_ANY,
1826 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1827 fname, lineno, val );
1831 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1832 char *val = argv[arg] + STRLENOF( "cred=" );
1834 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1835 fprintf( stderr, "%s: line %d: "
1836 "SASL cred already defined; replacing...\n",
1838 ch_free( li->idassert_passwd.bv_val );
1840 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1843 fprintf( stderr, "%s: line %d: "
1844 "unknown parameter %s\n",
1845 fname, lineno, argv[arg] );
1850 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1852 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1853 #ifdef HAVE_CYRUS_SASL
1856 for ( arg = 2; arg < argc; arg++ ) {
1857 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1858 char *val = argv[arg] + STRLENOF( "mech=" );
1860 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1861 fprintf( stderr, "%s: line %d: "
1862 "SASL mech already defined; replacing...\n",
1864 ch_free( li->idassert_sasl_mech.bv_val );
1866 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1868 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1869 char *val = argv[arg] + STRLENOF( "realm=" );
1871 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1872 fprintf( stderr, "%s: line %d: "
1873 "SASL realm already defined; replacing...\n",
1875 ch_free( li->idassert_sasl_realm.bv_val );
1877 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1879 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1880 char *val = argv[arg] + STRLENOF( "authcdn=" );
1884 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1885 fprintf( stderr, "%s: line %d: "
1886 "SASL authcDN already defined; replacing...\n",
1888 ch_free( li->idassert_authcDN.bv_val );
1890 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1891 val += STRLENOF( "dn:" );
1894 ber_str2bv( val, 0, 0, &dn );
1895 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1896 if ( rc != LDAP_SUCCESS ) {
1897 Debug( LDAP_DEBUG_ANY,
1898 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1899 fname, lineno, val );
1903 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1904 char *val = argv[arg] + STRLENOF( "authcid=" );
1906 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1907 fprintf( stderr, "%s: line %d: "
1908 "SASL authcID already defined; replacing...\n",
1910 ch_free( li->idassert_authcID.bv_val );
1912 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1913 val += STRLENOF( "u:" );
1915 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1917 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1918 char *val = argv[arg] + STRLENOF( "cred=" );
1920 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1921 fprintf( stderr, "%s: line %d: "
1922 "SASL cred already defined; replacing...\n",
1924 ch_free( li->idassert_passwd.bv_val );
1926 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1928 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1929 char *val = argv[arg] + STRLENOF( "authz=" );
1931 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1932 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1934 } else if ( strcasecmp( val, "native" ) == 0 ) {
1935 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1938 fprintf( stderr, "%s: line %d: "
1939 "unknown authz mode \"%s\"\n",
1940 fname, lineno, val );
1945 fprintf( stderr, "%s: line %d: "
1946 "unknown SASL parameter %s\n",
1947 fname, lineno, argv[arg] );
1952 li->idassert_authmethod = LDAP_AUTH_SASL;
1954 #else /* !HAVE_CYRUS_SASL */
1955 fprintf( stderr, "%s: line %d: "
1956 "compile --with-cyrus-sasl to enable SASL auth\n",
1959 #endif /* !HAVE_CYRUS_SASL */
1962 fprintf( stderr, "%s: line %d: "
1963 "unhandled idassert-method method %s\n",
1964 fname, lineno, argv[1] );
1969 return SLAP_CONF_UNKNOWN;
1984 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1986 /* name to use for remote ACL access */
1987 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
1988 || strcasecmp( argv[0], "binddn" ) == 0 )
1993 /* FIXME: "binddn" is no longer documented, and
1994 * temporarily supported for backwards compatibility */
1998 "%s: line %d: missing name in \"%s <name>\" line\n",
1999 fname, lineno, argv[0] );
2003 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2004 fprintf( stderr, "%s: line %d: "
2005 "authcDN already defined; replacing...\n",
2007 ch_free( li->acl_authcDN.bv_val );
2010 ber_str2bv( argv[1], 0, 0, &dn );
2011 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2012 if ( rc != LDAP_SUCCESS ) {
2013 Debug( LDAP_DEBUG_ANY,
2014 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
2015 fname, lineno, argv[1] );
2019 /* password to use for remote ACL access */
2020 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
2021 || strcasecmp( argv[0], "bindpw" ) == 0 )
2023 /* FIXME: "bindpw" is no longer documented, and
2024 * temporarily supported for backwards compatibility */
2028 "%s: line %d: missing password in \"%s <password>\" line\n",
2029 fname, lineno, argv[0] );
2033 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2034 fprintf( stderr, "%s: line %d: "
2035 "passwd already defined; replacing...\n",
2037 ch_free( li->acl_passwd.bv_val );
2040 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2042 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2047 "%s: line %d: missing method in \"%s <method>\" line\n",
2048 fname, lineno, argv[0] );
2053 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2054 argv1 += STRLENOF( "bindmethod=" );
2057 if ( strcasecmp( argv1, "none" ) == 0 ) {
2058 /* FIXME: is this at all useful? */
2059 li->acl_authmethod = LDAP_AUTH_NONE;
2063 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2064 fname, lineno, argv[0], argv[1] );
2067 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2068 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2072 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2073 fname, lineno, argv[0], argv[1] );
2076 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2077 #ifdef HAVE_CYRUS_SASL
2080 for ( arg = 2; arg < argc; arg++ ) {
2081 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2082 char *val = argv[arg] + STRLENOF( "mech=" );
2084 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2085 fprintf( stderr, "%s: line %d: "
2086 "SASL mech already defined; replacing...\n",
2088 ch_free( li->acl_sasl_mech.bv_val );
2090 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2092 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2093 char *val = argv[arg] + STRLENOF( "realm=" );
2095 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2096 fprintf( stderr, "%s: line %d: "
2097 "SASL realm already defined; replacing...\n",
2099 ch_free( li->acl_sasl_realm.bv_val );
2101 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2103 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2104 char *val = argv[arg] + STRLENOF( "authcdn=" );
2108 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2109 fprintf( stderr, "%s: line %d: "
2110 "SASL authcDN already defined; replacing...\n",
2112 ch_free( li->acl_authcDN.bv_val );
2114 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2115 val += STRLENOF( "dn:" );
2118 ber_str2bv( val, 0, 0, &dn );
2119 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2120 if ( rc != LDAP_SUCCESS ) {
2121 Debug( LDAP_DEBUG_ANY,
2122 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2123 fname, lineno, val );
2127 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2128 char *val = argv[arg] + STRLENOF( "authcid=" );
2130 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2131 fprintf( stderr, "%s: line %d: "
2132 "SASL authcID already defined; replacing...\n",
2134 ch_free( li->acl_authcID.bv_val );
2136 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2137 val += STRLENOF( "u:" );
2139 ber_str2bv( val, 0, 1, &li->acl_authcID );
2141 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2142 char *val = argv[arg] + STRLENOF( "cred=" );
2144 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2145 fprintf( stderr, "%s: line %d: "
2146 "SASL cred already defined; replacing...\n",
2148 ch_free( li->acl_passwd.bv_val );
2150 ber_str2bv( val, 0, 1, &li->acl_passwd );
2153 fprintf( stderr, "%s: line %d: "
2154 "unknown SASL parameter %s\n",
2155 fname, lineno, argv[arg] );
2160 li->acl_authmethod = LDAP_AUTH_SASL;
2162 #else /* !HAVE_CYRUS_SASL */
2163 fprintf( stderr, "%s: line %d: "
2164 "compile --with-cyrus-sasl to enable SASL auth\n",
2167 #endif /* !HAVE_CYRUS_SASL */
2170 fprintf( stderr, "%s: line %d: "
2171 "unhandled acl-method method %s\n",
2172 fname, lineno, argv[1] );
2177 return SLAP_CONF_UNKNOWN;