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_BERVAL|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_BERVAL|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_BIND,
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... */
304 ber_dupbv( &c->value_bv, &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, &c->value_bv );
320 for ( i = 0; isspace( c->value_bv.bv_val[ i ] ); i++ )
324 c->value_bv.bv_len -= i;
325 AC_MEMCPY( c->value_bv.bv_val, &c->value_bv.bv_val[ i ],
326 c->value_bv.bv_len + 1 );
332 case LDAP_BACK_CFG_IDASSERT_MODE:
333 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
334 case LDAP_BACK_CFG_IDASSERT_PASSWD:
335 case LDAP_BACK_CFG_IDASSERT_METHOD:
336 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
340 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
343 if ( li->idassert_authz == NULL ) {
348 for ( i = 0; !BER_BVISNULL( &li->idassert_authz[ i ] ); i++ )
352 ber_dupbv( &bv, &li->idassert_authz[ i ] );
353 ber_bvarray_add( &c->rvalue_vals, &bv );
358 case LDAP_BACK_CFG_IDASSERT_BIND: {
360 struct berval bv = BER_BVNULL,
364 if ( li->idassert_authmethod != LDAP_AUTH_NONE ) {
365 ber_len_t len = bv.bv_len
366 + STRLENOF( "flags=override,non-prescriptive" );
368 switch ( li->idassert_mode ) {
369 case LDAP_BACK_IDASSERT_OTHERID:
370 case LDAP_BACK_IDASSERT_OTHERDN:
374 struct berval mode = BER_BVNULL;
376 enum_to_verb( idassert_mode, li->idassert_mode, &mode );
377 if ( BER_BVISNULL( &mode ) ) {
378 /* there's something wrong... */
383 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
384 bv.bv_val = ch_malloc( bv.bv_len + 1 );
386 ptr = lutil_strcopy( bv.bv_val, "mode=" );
387 ptr = lutil_strcopy( ptr, mode.bv_val );
393 if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
394 ber_len_t len = bv.bv_len + STRLENOF( "authz=native" );
396 if ( !BER_BVISEMPTY( &bv ) ) {
397 len += STRLENOF( " " );
400 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
402 ptr = bv.bv_val + bv.bv_len;
404 if ( !BER_BVISEMPTY( &bv ) ) {
405 ptr = lutil_strcopy( ptr, " " );
408 (void)lutil_strcopy( ptr, "authz=native" );
412 if ( !BER_BVISEMPTY( &bv ) ) {
413 len += STRLENOF( " " );
416 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
418 ptr = &bv.bv_val[ bv.bv_len ];
420 if ( !BER_BVISEMPTY( &bv ) ) {
421 ptr = lutil_strcopy( ptr, " " );
424 ptr = lutil_strcopy( ptr, "flags=" );
426 if ( li->idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
427 ptr = lutil_strcopy( ptr, "prescriptive" );
429 ptr = lutil_strcopy( ptr, "non-prescriptive" );
432 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
433 ptr = lutil_strcopy( ptr, ",override" );
436 bv.bv_len = ( ptr - bv.bv_val );
440 bindconf_unparse( &li->idassert_sb, &bc );
442 if ( !BER_BVISNULL( &bv ) ) {
445 c->value_bv.bv_len = bv.bv_len + bc.bv_len;
446 c->value_bv.bv_val = ch_realloc( bv.bv_val, c->value_bv.bv_len + 1 );
448 assert( bc.bv_val[ 0 ] == ' ' );
450 ptr = lutil_strcopy( c->value_bv.bv_val, bv.bv_val );
451 (void)lutil_strcopy( ptr, bc.bv_val );
456 for ( i = 0; isspace( bc.bv_val[ i ] ); i++ )
461 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
470 case LDAP_BACK_CFG_REBIND:
471 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv );
472 if ( BER_BVISNULL( &bv ) ) {
473 /* there's something wrong... */
478 ber_dupbv( &c->value_bv, &bv );
482 case LDAP_BACK_CFG_CHASE:
483 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv );
484 if ( BER_BVISNULL( &bv ) ) {
485 /* there's something wrong... */
490 ber_dupbv( &c->value_bv, &bv );
494 case LDAP_BACK_CFG_T_F:
495 enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv );
496 if ( BER_BVISNULL( &bv ) ) {
497 /* there's something wrong... */
502 ber_dupbv( &c->value_bv, &bv );
506 case LDAP_BACK_CFG_WHOAMI:
507 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv );
508 if ( BER_BVISNULL( &bv ) ) {
509 /* there's something wrong... */
514 ber_dupbv( &c->value_bv, &bv );
519 /* we need to handle all... */
525 } else if ( c->op == LDAP_MOD_DELETE ) {
528 case LDAP_BACK_CFG_URI:
529 if ( li->url != NULL ) {
534 if ( li->lud != NULL ) {
535 ldap_free_urllist( li->lud );
539 /* better cleanup the cached connections... */
540 /* NOTE: don't worry about locking: if we got here,
541 * other threads are suspended. */
542 avl_free( li->conntree, ldap_back_conn_free );
547 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 /* we need to handle all... */
595 case LDAP_BACK_CFG_URI: {
596 LDAPURLDesc *tmpludp;
600 if ( c->argc != 2 ) {
601 fprintf( stderr, "%s: line %d: "
603 "in \"uri <uri>\" line\n",
604 c->fname, c->lineno );
608 if ( li->url != NULL ) {
612 if ( li->lud != NULL ) {
613 ldap_free_urllist( li->lud );
617 /* PARANOID: DN and more are not required nor allowed */
618 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
620 urlrc = ldap_url_parselist( &li->lud, c->value_string );
622 if ( urlrc != LDAP_URL_SUCCESS ) {
626 case LDAP_URL_ERR_MEM:
629 case LDAP_URL_ERR_PARAM:
630 why = "parameter is bad";
632 case LDAP_URL_ERR_BADSCHEME:
633 why = "URL doesn't begin with \"[c]ldap[si]://\"";
635 case LDAP_URL_ERR_BADENCLOSURE:
636 why = "URL is missing trailing \">\"";
638 case LDAP_URL_ERR_BADURL:
640 case LDAP_URL_ERR_BADHOST:
641 why = "host/port is bad";
643 case LDAP_URL_ERR_BADATTRS:
644 why = "bad (or missing) attributes";
646 case LDAP_URL_ERR_BADSCOPE:
647 why = "scope string is invalid (or missing)";
649 case LDAP_URL_ERR_BADFILTER:
650 why = "bad or missing filter";
652 case LDAP_URL_ERR_BADEXTS:
653 why = "bad or missing extensions";
656 why = "unknown reason";
659 fprintf( stderr, "%s: line %d: "
660 "unable to parse uri \"%s\" "
661 "in \"uri <uri>\" line: %s\n",
662 c->fname, c->lineno, c->value_string, why );
666 for ( i = 0, tmpludp = li->lud;
668 i++, tmpludp = tmpludp->lud_next )
670 if ( ( tmpludp->lud_dn != NULL
671 && tmpludp->lud_dn[0] != '\0' )
672 || tmpludp->lud_attrs != NULL
673 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
674 || tmpludp->lud_filter != NULL
675 || tmpludp->lud_exts != NULL )
677 fprintf( stderr, "%s: line %d: "
678 "warning, only protocol, "
679 "host and port allowed "
680 "in \"uri <uri>\" statement "
681 "for uri #%d of \"%s\"\n",
682 c->fname, c->lineno, i, c->value_string );
687 for ( i = 0, tmpludp = li->lud;
689 i++, tmpludp = tmpludp->lud_next )
692 urllist = ch_calloc( sizeof( char * ), i + 1 );
694 for ( i = 0, tmpludp = li->lud;
696 i++, tmpludp = tmpludp->lud_next )
699 ber_len_t oldlen = 0, len;
703 tmplud.lud_attrs = NULL;
704 tmplud.lud_filter = NULL;
705 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
706 tmplud.lud_exts = NULL;
707 tmplud.lud_crit_exts = 0;
710 urllist[ i ] = ldap_url_desc2str( &tmplud );
712 if ( urllist[ i ] == NULL ) {
713 fprintf( stderr, "%s: line %d: "
714 "unable to rebuild uri "
715 "in \"uri <uri>\" statement "
717 c->fname, c->lineno, argv[ 1 ] );
722 li->url = ldap_charray2str( urllist, " " );
723 ldap_charray_free( urllist );
725 li->url = ch_strdup( c->value_string );
730 case LDAP_BACK_CFG_TLS:
731 i = verb_to_mask( c->argv[1], tls_mode );
732 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
735 li->flags &= ~LDAP_BACK_F_TLS_MASK;
736 li->flags |= tls_mode[i].mask;
739 case LDAP_BACK_CFG_ACL_AUTHCDN:
740 switch ( li->acl_authmethod ) {
742 li->acl_authmethod = LDAP_AUTH_SIMPLE;
745 case LDAP_AUTH_SIMPLE:
749 fprintf( stderr, "%s: line %d: "
750 "\"acl-authcDN <DN>\" incompatible "
751 "with auth method %d.",
752 c->fname, c->lineno, li->acl_authmethod );
755 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
756 free( li->acl_authcDN.bv_val );
758 li->acl_authcDN = c->value_ndn;
761 case LDAP_BACK_CFG_ACL_PASSWD:
762 switch ( li->acl_authmethod ) {
764 li->acl_authmethod = LDAP_AUTH_SIMPLE;
767 case LDAP_AUTH_SIMPLE:
771 fprintf( stderr, "%s: line %d: "
772 "\"acl-passwd <cred>\" incompatible "
773 "with auth method %d.",
774 c->fname, c->lineno, li->acl_authmethod );
777 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
778 free( li->acl_passwd.bv_val );
780 li->acl_passwd = c->value_bv;
783 case LDAP_BACK_CFG_ACL_METHOD:
784 case LDAP_BACK_CFG_ACL_BIND:
785 for ( i = 1; i < c->argc; i++ ) {
786 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
792 case LDAP_BACK_CFG_IDASSERT_MODE:
793 i = verb_to_mask( c->argv[1], idassert_mode );
794 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
795 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
796 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
797 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
798 li->idassert_authzID.bv_val[ 0 ] = 'u';
801 struct berval id, ndn;
803 ber_str2bv( c->argv[1], 0, 0, &id );
805 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
806 id.bv_val += STRLENOF( "dn:" );
807 id.bv_len -= STRLENOF( "dn:" );
810 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
811 if ( rc != LDAP_SUCCESS ) {
812 Debug( LDAP_DEBUG_ANY,
813 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
814 c->fname, c->lineno, c->argv[1] );
818 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
819 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
820 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
821 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
822 ch_free( ndn.bv_val );
824 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
828 li->idassert_mode = idassert_mode[i].mask;
834 for ( i = 2; i < c->argc; i++ ) {
835 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
836 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
838 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
839 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
841 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
842 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
845 Debug( LDAP_DEBUG_ANY,
846 "%s: line %d: unknown flag #%d "
847 "in \"idassert-mode <args> "
848 "[<flags>]\" line.\n",
849 c->fname, c->lineno, i - 2 );
856 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
857 switch ( li->idassert_authmethod ) {
859 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
862 case LDAP_AUTH_SIMPLE:
866 fprintf( stderr, "%s: line %d: "
867 "\"idassert-authcDN <DN>\" incompatible "
868 "with auth method %d.",
869 c->fname, c->lineno, li->idassert_authmethod );
872 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
873 free( li->idassert_authcDN.bv_val );
875 li->idassert_authcDN = c->value_ndn;
878 case LDAP_BACK_CFG_IDASSERT_PASSWD:
879 switch ( li->idassert_authmethod ) {
881 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
884 case LDAP_AUTH_SIMPLE:
888 fprintf( stderr, "%s: line %d: "
889 "\"idassert-passwd <cred>\" incompatible "
890 "with auth method %d.",
891 c->fname, c->lineno, li->idassert_authmethod );
894 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
895 free( li->idassert_passwd.bv_val );
897 li->idassert_passwd = c->value_bv;
900 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
901 ber_bvarray_add( &li->idassert_authz, &c->value_bv );
904 case LDAP_BACK_CFG_IDASSERT_METHOD:
905 /* no longer supported */
906 fprintf( stderr, "%s: %d: "
907 "\"idassert-method <args>\": "
908 "no longer supported; use \"idassert-bind\".\n",
909 c->fname, c->lineno );
912 case LDAP_BACK_CFG_IDASSERT_BIND:
913 for ( i = 1; i < c->argc; i++ ) {
914 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
915 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
918 j = verb_to_mask( argvi, idassert_mode );
919 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
920 fprintf( stderr, "%s: %d: "
921 "\"idassert-bind <args>\": "
922 "unknown mode \"%s\".\n",
923 c->fname, c->lineno, argvi );
927 li->idassert_mode = idassert_mode[ j ].mask;
929 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
930 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
932 if ( strcasecmp( argvi, "native" ) == 0 ) {
933 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
934 fprintf( stderr, "%s: %d: "
935 "\"idassert-bind <args>\": "
936 "authz=\"native\" incompatible "
937 "with auth method.\n",
938 c->fname, c->lineno );
941 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
943 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
944 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
947 fprintf( stderr, "%s: %d: "
948 "\"idassert-bind <args>\": "
949 "unknown authz \"%s\".\n",
950 c->fname, c->lineno, argvi );
954 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
955 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
956 char **flags = ldap_str2charray( argvi, "," );
959 if ( flags == NULL ) {
960 fprintf( stderr, "%s: %d: "
961 "\"idassert-bind <args>\": "
962 "unable to parse flags \"%s\".\n",
963 c->fname, c->lineno, argvi );
967 for ( j = 0; flags[ j ] != NULL; j++ ) {
968 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
969 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
971 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
972 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
974 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
975 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
978 fprintf( stderr, "%s: %d: "
979 "\"idassert-bind <args>\": "
980 "unknown flag \"%s\".\n",
981 c->fname, c->lineno, flags[ j ] );
986 ldap_charray_free( flags );
988 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
994 case LDAP_BACK_CFG_REBIND: {
997 if ( c->argc == 1 ) {
1002 i = verb_to_mask( c->argv[1], yn_mode );
1003 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1006 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1012 li->flags |= LDAP_BACK_F_SAVECRED;
1015 li->flags &= ~LDAP_BACK_F_SAVECRED;
1020 case LDAP_BACK_CFG_CHASE: {
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_CHASE_REFERRALS;
1041 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1046 case LDAP_BACK_CFG_T_F:
1047 i = verb_to_mask( c->argv[1], t_f_mode );
1048 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1051 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1052 li->flags |= t_f_mode[i].mask;
1055 case LDAP_BACK_CFG_WHOAMI: {
1058 if ( c->argc == 1 ) {
1063 i = verb_to_mask( c->argv[1], yn_mode );
1064 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1067 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1073 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1075 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1076 0, ldap_back_exop_whoami );
1079 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1084 case LDAP_BACK_CFG_REWRITE:
1085 fprintf( stderr, "%s: line %d: "
1086 "rewrite/remap capabilities have been moved "
1087 "to the \"rwm\" overlay; see slapo-rwm(5) "
1088 "for details (hint: add \"overlay rwm\" "
1089 "and prefix all directives with \"rwm-\").\n",
1090 c->fname, c->lineno );
1101 ldap_back_init_cf( BackendInfo *bi )
1104 AttributeDescription *ad = NULL;
1107 bi->bi_cf_ocs = ldapocs;
1109 rc = config_register_schema( ldapcfg, ldapocs );
1114 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1115 * to be base64-encoded when written in LDIF form;
1116 * basically, we don't care if it fails */
1117 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1119 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1120 "warning, unable to get \"olcDbACLPasswd\" "
1121 "attribute description: %d: %s\n",
1124 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1125 ad->ad_type->sat_oid );
1129 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1131 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1132 "warning, unable to get \"olcDbIDAssertPasswd\" "
1133 "attribute description: %d: %s\n",
1136 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1137 ad->ad_type->sat_oid );
1145 parse_idassert( BackendDB *be, const char *fname, int lineno,
1146 int argc, char **argv );
1149 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1150 int argc, char **argv );
1153 ldap_back_db_config(
1160 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1163 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1168 /* server address to query (no longer supported, use "uri" directive) */
1169 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1171 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1175 /* URI of server to query (obsoletes "server" directive) */
1176 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1177 LDAPURLDesc *tmpludp;
1182 fprintf( stderr, "%s: line %d: "
1184 "in \"uri <uri>\" line\n",
1188 if ( li->url != NULL ) {
1191 if ( li->lud != NULL ) {
1192 ldap_free_urllist( li->lud );
1196 /* PARANOID: DN and more are not required nor allowed */
1197 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1199 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1201 if ( urlrc != LDAP_URL_SUCCESS ) {
1205 case LDAP_URL_ERR_MEM:
1208 case LDAP_URL_ERR_PARAM:
1209 why = "parameter is bad";
1211 case LDAP_URL_ERR_BADSCHEME:
1212 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1214 case LDAP_URL_ERR_BADENCLOSURE:
1215 why = "URL is missing trailing \">\"";
1217 case LDAP_URL_ERR_BADURL:
1219 case LDAP_URL_ERR_BADHOST:
1220 why = "host/port is bad";
1222 case LDAP_URL_ERR_BADATTRS:
1223 why = "bad (or missing) attributes";
1225 case LDAP_URL_ERR_BADSCOPE:
1226 why = "scope string is invalid (or missing)";
1228 case LDAP_URL_ERR_BADFILTER:
1229 why = "bad or missing filter";
1231 case LDAP_URL_ERR_BADEXTS:
1232 why = "bad or missing extensions";
1235 why = "unknown reason";
1238 fprintf( stderr, "%s: line %d: "
1239 "unable to parse uri \"%s\" "
1240 "in \"uri <uri>\" line: %s\n",
1241 fname, lineno, argv[ 1 ], why );
1245 for ( i = 0, tmpludp = li->lud;
1247 i++, tmpludp = tmpludp->lud_next )
1249 if ( ( tmpludp->lud_dn != NULL
1250 && tmpludp->lud_dn[0] != '\0' )
1251 || tmpludp->lud_attrs != NULL
1252 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1253 || tmpludp->lud_filter != NULL
1254 || tmpludp->lud_exts != NULL )
1256 fprintf( stderr, "%s: line %d: "
1257 "warning, only protocol, "
1258 "host and port allowed "
1259 "in \"uri <uri>\" statement "
1260 "for uri #%d of \"%s\"\n",
1261 fname, lineno, i, argv[1] );
1266 for ( i = 0, tmpludp = li->lud;
1268 i++, tmpludp = tmpludp->lud_next )
1271 urllist = ch_calloc( sizeof( char * ), i + 1 );
1273 for ( i = 0, tmpludp = li->lud;
1275 i++, tmpludp = tmpludp->lud_next )
1278 ber_len_t oldlen = 0, len;
1282 tmplud.lud_attrs = NULL;
1283 tmplud.lud_filter = NULL;
1284 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1285 tmplud.lud_exts = NULL;
1286 tmplud.lud_crit_exts = 0;
1289 urllist[ i ] = ldap_url_desc2str( &tmplud );
1291 if ( urllist[ i ] == NULL ) {
1292 fprintf( stderr, "%s: line %d: "
1293 "unable to rebuild uri "
1294 "in \"uri <uri>\" statement "
1296 fname, lineno, argv[ 1 ] );
1301 li->url = ldap_charray2str( urllist, " " );
1302 ldap_charray_free( urllist );
1304 li->url = ch_strdup( argv[ 1 ] );
1307 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1310 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1316 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1317 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1320 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1321 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1324 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1325 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1326 li->flags |= LDAP_BACK_F_USE_TLS;
1328 /* propagate start tls */
1329 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1330 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1333 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1334 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1335 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1339 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1340 fname, lineno, argv[1] );
1344 /* remote ACL stuff... */
1345 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1346 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1348 /* NOTE: "bind{DN,pw}" was initially used; it's now
1349 * deprected and undocumented, it can be dropped at some
1350 * point, since nobody should be really using it */
1351 return parse_acl_auth( be, fname, lineno, argc, argv );
1353 /* identity assertion stuff... */
1354 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1355 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1357 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1358 * deprected and undocumented, it can be dropped at some
1359 * point, since nobody should be really using it */
1360 return parse_idassert( be, fname, lineno, argc, argv );
1362 /* save bind creds for referral rebinds? */
1363 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1367 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1370 li->flags |= LDAP_BACK_F_SAVECRED;
1374 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1375 li->flags |= LDAP_BACK_F_SAVECRED;
1377 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1378 li->flags &= ~LDAP_BACK_F_SAVECRED;
1382 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1383 fname, lineno, argv[ 1 ] );
1390 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1395 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1398 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1403 /* this is the default; we add it because the default might change... */
1404 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1405 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1407 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1408 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1412 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1413 fname, lineno, argv[1] );
1417 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1420 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1425 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1426 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1428 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1429 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1431 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1432 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1436 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1437 fname, lineno, argv[ 1 ] );
1441 /* intercept exop_who_am_i? */
1442 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1443 int doload_extop = 0;
1448 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1455 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1458 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1460 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1461 fname, lineno, argv[ 1 ] );
1468 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1473 if ( doload_extop ) {
1474 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1476 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1477 0, ldap_back_exop_whoami );
1480 /* FIXME: legacy: intercept old rewrite/remap directives
1481 * and try to start the rwm overlay */
1482 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1483 || strcasecmp( argv[0], "map" ) == 0
1484 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1487 fprintf( stderr, "%s: line %d: "
1488 "rewrite/remap capabilities have been moved "
1489 "to the \"rwm\" overlay; see slapo-rwm(5) "
1490 "for details. I'm trying to do my best "
1491 "to preserve backwards compatibility...\n",
1494 if ( li->rwm_started == 0 ) {
1495 if ( overlay_config( be, "rwm" ) ) {
1496 fprintf( stderr, "%s: line %d: "
1497 "unable to configure the \"rwm\" "
1498 "overlay, required by directive "
1500 fname, lineno, argv[0] );
1501 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1502 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1503 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1507 fprintf( stderr, "%s: line %d: back-ldap: "
1508 "automatically starting \"rwm\" overlay, "
1509 "triggered by \"%s\" directive.\n",
1510 fname, lineno, argv[ 0 ] );
1512 /* this is the default; we add it because the default might change... */
1513 li->rwm_started = 1;
1515 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1518 fprintf( stderr, "%s: line %d: "
1519 "rewrite/remap capabilities have been moved "
1520 "to the \"rwm\" overlay; see slapo-rwm(5) "
1521 "for details (hint: add \"overlay rwm\" "
1522 "and prefix all directives with \"rwm-\").\n",
1530 return SLAP_CONF_UNKNOWN;
1537 ldap_back_exop_whoami(
1541 struct berval *bv = NULL;
1543 if ( op->oq_extended.rs_reqdata != NULL ) {
1544 /* no request data should be provided */
1545 rs->sr_text = "no request data expected";
1546 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1549 rs->sr_err = backend_check_restrictions( op, rs,
1550 (struct berval *)&slap_EXOP_WHOAMI );
1551 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1553 /* if auth'd by back-ldap and request is proxied, forward it */
1554 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)) {
1555 struct ldapconn *lc;
1557 LDAPControl c, *ctrls[2] = {NULL, NULL};
1559 Operation op2 = *op;
1564 op2.o_ndn = op->o_conn->c_ndn;
1565 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1566 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1569 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1570 c.ldctl_iscritical = 1;
1571 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1572 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1573 strcpy(c.ldctl_value.bv_val, "dn:");
1574 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1577 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1578 if (rs->sr_err == LDAP_SUCCESS) {
1579 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1580 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1582 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1584 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1587 ldap_back_freeconn( op, lc );
1591 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1595 ch_free(c.ldctl_value.bv_val);
1596 if (rs->sr_err != LDAP_SUCCESS) {
1597 rs->sr_err = slap_map_api2result( rs );
1601 ldap_back_release_conn( &op2, rs, lc );
1605 /* else just do the same as before */
1606 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1607 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1608 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
1609 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1610 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
1611 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
1613 bv->bv_val[bv->bv_len] = '\0';
1620 rs->sr_rspdata = bv;
1634 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1636 /* identity assertion mode */
1637 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1639 Debug( LDAP_DEBUG_ANY,
1640 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1641 fname, lineno, argc );
1645 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1646 /* will proxyAuthz as client's identity only if bound */
1647 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1649 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1650 /* will proxyAuthz as client's identity */
1651 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1653 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1654 /* will proxyAuthz as anonymous */
1655 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1657 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1658 /* will not proxyAuthz */
1659 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1665 /* will proxyAuthz as argv[1] */
1666 ber_str2bv( argv[1], 0, 0, &id );
1668 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1669 /* force lowercase... */
1671 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1672 ber_dupbv( &li->idassert_authzID, &id );
1677 /* default is DN? */
1678 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1679 id.bv_val += STRLENOF( "dn:" );
1680 id.bv_len -= STRLENOF( "dn:" );
1683 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1684 if ( rc != LDAP_SUCCESS ) {
1685 Debug( LDAP_DEBUG_ANY,
1686 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1687 fname, lineno, argv[1] );
1691 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1692 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1693 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1694 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1695 ch_free( dn.bv_val );
1697 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1701 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1702 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1703 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1706 Debug( LDAP_DEBUG_ANY,
1707 "%s: line %d: unknown flag \"%s\" "
1708 "in \"idassert-mode <args> "
1709 "[<flags>]\" line.\n",
1710 fname, lineno, argv[0] );
1715 /* name to use for proxyAuthz propagation */
1716 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1717 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1722 /* FIXME: "proxyauthzdn" is no longer documented, and
1723 * temporarily supported for backwards compatibility */
1727 "%s: line %d: missing name in \"%s <name>\" line\n",
1728 fname, lineno, argv[0] );
1732 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1733 fprintf( stderr, "%s: line %d: "
1734 "authcDN already defined; replacing...\n",
1736 ch_free( li->idassert_authcDN.bv_val );
1739 ber_str2bv( argv[1], 0, 0, &dn );
1740 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1741 if ( rc != LDAP_SUCCESS ) {
1742 Debug( LDAP_DEBUG_ANY,
1743 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1744 fname, lineno, argv[1] );
1748 /* password to use for proxyAuthz propagation */
1749 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1750 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1752 /* FIXME: "proxyauthzpw" is no longer documented, and
1753 * temporarily supported for backwards compatibility */
1757 "%s: line %d: missing password in \"%s <password>\" line\n",
1758 fname, lineno, argv[0] );
1762 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1763 fprintf( stderr, "%s: line %d: "
1764 "passwd already defined; replacing...\n",
1766 ch_free( li->idassert_passwd.bv_val );
1769 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1771 /* rules to accept identity assertion... */
1772 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1775 ber_str2bv( argv[1], 0, 1, &rule );
1777 ber_bvarray_add( &li->idassert_authz, &rule );
1779 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1784 "%s: line %d: missing method in \"%s <method>\" line\n",
1785 fname, lineno, argv[0] );
1790 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1791 argv1 += STRLENOF( "bindmethod=" );
1794 if ( strcasecmp( argv1, "none" ) == 0 ) {
1795 /* FIXME: is this at all useful? */
1796 li->idassert_authmethod = LDAP_AUTH_NONE;
1800 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1801 fname, lineno, argv[0], argv[1] );
1804 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1807 for ( arg = 2; arg < argc; arg++ ) {
1808 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1809 char *val = argv[arg] + STRLENOF( "authcdn=" );
1813 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1814 fprintf( stderr, "%s: line %d: "
1815 "SASL authcDN already defined; replacing...\n",
1817 ch_free( li->idassert_authcDN.bv_val );
1819 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1820 val += STRLENOF( "dn:" );
1823 ber_str2bv( val, 0, 0, &dn );
1824 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1825 if ( rc != LDAP_SUCCESS ) {
1826 Debug( LDAP_DEBUG_ANY,
1827 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1828 fname, lineno, val );
1832 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1833 char *val = argv[arg] + STRLENOF( "cred=" );
1835 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1836 fprintf( stderr, "%s: line %d: "
1837 "SASL cred already defined; replacing...\n",
1839 ch_free( li->idassert_passwd.bv_val );
1841 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1844 fprintf( stderr, "%s: line %d: "
1845 "unknown parameter %s\n",
1846 fname, lineno, argv[arg] );
1851 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1853 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1854 #ifdef HAVE_CYRUS_SASL
1857 for ( arg = 2; arg < argc; arg++ ) {
1858 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1859 char *val = argv[arg] + STRLENOF( "mech=" );
1861 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1862 fprintf( stderr, "%s: line %d: "
1863 "SASL mech already defined; replacing...\n",
1865 ch_free( li->idassert_sasl_mech.bv_val );
1867 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1869 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1870 char *val = argv[arg] + STRLENOF( "realm=" );
1872 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1873 fprintf( stderr, "%s: line %d: "
1874 "SASL realm already defined; replacing...\n",
1876 ch_free( li->idassert_sasl_realm.bv_val );
1878 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1880 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1881 char *val = argv[arg] + STRLENOF( "authcdn=" );
1885 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1886 fprintf( stderr, "%s: line %d: "
1887 "SASL authcDN already defined; replacing...\n",
1889 ch_free( li->idassert_authcDN.bv_val );
1891 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1892 val += STRLENOF( "dn:" );
1895 ber_str2bv( val, 0, 0, &dn );
1896 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1897 if ( rc != LDAP_SUCCESS ) {
1898 Debug( LDAP_DEBUG_ANY,
1899 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1900 fname, lineno, val );
1904 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1905 char *val = argv[arg] + STRLENOF( "authcid=" );
1907 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1908 fprintf( stderr, "%s: line %d: "
1909 "SASL authcID already defined; replacing...\n",
1911 ch_free( li->idassert_authcID.bv_val );
1913 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1914 val += STRLENOF( "u:" );
1916 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1918 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1919 char *val = argv[arg] + STRLENOF( "cred=" );
1921 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1922 fprintf( stderr, "%s: line %d: "
1923 "SASL cred already defined; replacing...\n",
1925 ch_free( li->idassert_passwd.bv_val );
1927 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1929 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1930 char *val = argv[arg] + STRLENOF( "authz=" );
1932 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1933 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1935 } else if ( strcasecmp( val, "native" ) == 0 ) {
1936 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1939 fprintf( stderr, "%s: line %d: "
1940 "unknown authz mode \"%s\"\n",
1941 fname, lineno, val );
1946 fprintf( stderr, "%s: line %d: "
1947 "unknown SASL parameter %s\n",
1948 fname, lineno, argv[arg] );
1953 li->idassert_authmethod = LDAP_AUTH_SASL;
1955 #else /* !HAVE_CYRUS_SASL */
1956 fprintf( stderr, "%s: line %d: "
1957 "compile --with-cyrus-sasl to enable SASL auth\n",
1960 #endif /* !HAVE_CYRUS_SASL */
1963 fprintf( stderr, "%s: line %d: "
1964 "unhandled idassert-method method %s\n",
1965 fname, lineno, argv[1] );
1970 return SLAP_CONF_UNKNOWN;
1985 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1987 /* name to use for remote ACL access */
1988 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
1989 || strcasecmp( argv[0], "binddn" ) == 0 )
1994 /* FIXME: "binddn" is no longer documented, and
1995 * temporarily supported for backwards compatibility */
1999 "%s: line %d: missing name in \"%s <name>\" line\n",
2000 fname, lineno, argv[0] );
2004 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2005 fprintf( stderr, "%s: line %d: "
2006 "authcDN already defined; replacing...\n",
2008 ch_free( li->acl_authcDN.bv_val );
2011 ber_str2bv( argv[1], 0, 0, &dn );
2012 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2013 if ( rc != LDAP_SUCCESS ) {
2014 Debug( LDAP_DEBUG_ANY,
2015 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
2016 fname, lineno, argv[1] );
2020 /* password to use for remote ACL access */
2021 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
2022 || strcasecmp( argv[0], "bindpw" ) == 0 )
2024 /* FIXME: "bindpw" is no longer documented, and
2025 * temporarily supported for backwards compatibility */
2029 "%s: line %d: missing password in \"%s <password>\" line\n",
2030 fname, lineno, argv[0] );
2034 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2035 fprintf( stderr, "%s: line %d: "
2036 "passwd already defined; replacing...\n",
2038 ch_free( li->acl_passwd.bv_val );
2041 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2043 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2048 "%s: line %d: missing method in \"%s <method>\" line\n",
2049 fname, lineno, argv[0] );
2054 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2055 argv1 += STRLENOF( "bindmethod=" );
2058 if ( strcasecmp( argv1, "none" ) == 0 ) {
2059 /* FIXME: is this at all useful? */
2060 li->acl_authmethod = LDAP_AUTH_NONE;
2064 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2065 fname, lineno, argv[0], argv[1] );
2068 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2069 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2073 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2074 fname, lineno, argv[0], argv[1] );
2077 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2078 #ifdef HAVE_CYRUS_SASL
2081 for ( arg = 2; arg < argc; arg++ ) {
2082 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2083 char *val = argv[arg] + STRLENOF( "mech=" );
2085 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2086 fprintf( stderr, "%s: line %d: "
2087 "SASL mech already defined; replacing...\n",
2089 ch_free( li->acl_sasl_mech.bv_val );
2091 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2093 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2094 char *val = argv[arg] + STRLENOF( "realm=" );
2096 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2097 fprintf( stderr, "%s: line %d: "
2098 "SASL realm already defined; replacing...\n",
2100 ch_free( li->acl_sasl_realm.bv_val );
2102 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2104 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2105 char *val = argv[arg] + STRLENOF( "authcdn=" );
2109 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2110 fprintf( stderr, "%s: line %d: "
2111 "SASL authcDN already defined; replacing...\n",
2113 ch_free( li->acl_authcDN.bv_val );
2115 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2116 val += STRLENOF( "dn:" );
2119 ber_str2bv( val, 0, 0, &dn );
2120 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2121 if ( rc != LDAP_SUCCESS ) {
2122 Debug( LDAP_DEBUG_ANY,
2123 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2124 fname, lineno, val );
2128 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2129 char *val = argv[arg] + STRLENOF( "authcid=" );
2131 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2132 fprintf( stderr, "%s: line %d: "
2133 "SASL authcID already defined; replacing...\n",
2135 ch_free( li->acl_authcID.bv_val );
2137 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2138 val += STRLENOF( "u:" );
2140 ber_str2bv( val, 0, 1, &li->acl_authcID );
2142 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2143 char *val = argv[arg] + STRLENOF( "cred=" );
2145 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2146 fprintf( stderr, "%s: line %d: "
2147 "SASL cred already defined; replacing...\n",
2149 ch_free( li->acl_passwd.bv_val );
2151 ber_str2bv( val, 0, 1, &li->acl_passwd );
2154 fprintf( stderr, "%s: line %d: "
2155 "unknown SASL parameter %s\n",
2156 fname, lineno, argv[arg] );
2161 li->acl_authmethod = LDAP_AUTH_SASL;
2163 #else /* !HAVE_CYRUS_SASL */
2164 fprintf( stderr, "%s: line %d: "
2165 "compile --with-cyrus-sasl to enable SASL auth\n",
2168 #endif /* !HAVE_CYRUS_SASL */
2171 fprintf( stderr, "%s: line %d: "
2172 "unhandled acl-method method %s\n",
2173 fname, lineno, argv[1] );
2178 return SLAP_CONF_UNKNOWN;