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 switch ( li->idassert_mode ) {
366 case LDAP_BACK_IDASSERT_OTHERID:
367 case LDAP_BACK_IDASSERT_OTHERDN:
371 struct berval mode = BER_BVNULL;
373 enum_to_verb( idassert_mode, li->idassert_mode, &mode );
374 if ( BER_BVISNULL( &mode ) ) {
375 /* there's something wrong... */
380 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
381 bv.bv_val = ch_malloc( bv.bv_len + 1 );
383 ptr = lutil_strcopy( bv.bv_val, "mode=" );
384 ptr = lutil_strcopy( ptr, mode.bv_val );
390 if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
391 ber_len_t len = bv.bv_len + STRLENOF( "authz=native" );
393 if ( !BER_BVISEMPTY( &bv ) ) {
394 len += STRLENOF( " " );
397 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
399 ptr = bv.bv_val + bv.bv_len;
401 if ( !BER_BVISEMPTY( &bv ) ) {
402 ptr = lutil_strcopy( ptr, " " );
405 (void)lutil_strcopy( ptr, "authz=native" );
408 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
409 ber_len_t len = bv.bv_len + STRLENOF( "flags=override" );
411 if ( !BER_BVISEMPTY( &bv ) ) {
412 len += STRLENOF( " " );
415 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
417 ptr = bv.bv_val + bv.bv_len;
419 if ( !BER_BVISEMPTY( &bv ) ) {
420 ptr = lutil_strcopy( ptr, " " );
423 (void)lutil_strcopy( ptr, "flags=override" );
429 bindconf_unparse( &li->idassert_sb, &bc );
431 if ( !BER_BVISNULL( &bv ) ) {
434 c->value_bv.bv_len = bv.bv_len + bc.bv_len;
435 c->value_bv.bv_val = ch_realloc( bv.bv_val, c->value_bv.bv_len + 1 );
437 assert( bc.bv_val[ 0 ] == ' ' );
439 ptr = lutil_strcopy( c->value_bv.bv_val, bv.bv_val );
440 (void)lutil_strcopy( ptr, bc.bv_val );
445 for ( i = 0; isspace( bc.bv_val[ i ] ); i++ )
450 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
459 case LDAP_BACK_CFG_REBIND:
460 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv );
461 if ( BER_BVISNULL( &bv ) ) {
462 /* there's something wrong... */
467 ber_dupbv( &c->value_bv, &bv );
471 case LDAP_BACK_CFG_CHASE:
472 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv );
473 if ( BER_BVISNULL( &bv ) ) {
474 /* there's something wrong... */
479 ber_dupbv( &c->value_bv, &bv );
483 case LDAP_BACK_CFG_T_F:
484 enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv );
485 if ( BER_BVISNULL( &bv ) ) {
486 /* there's something wrong... */
491 ber_dupbv( &c->value_bv, &bv );
495 case LDAP_BACK_CFG_WHOAMI:
496 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv );
497 if ( BER_BVISNULL( &bv ) ) {
498 /* there's something wrong... */
503 ber_dupbv( &c->value_bv, &bv );
508 /* we need to handle all... */
514 } else if ( c->op == LDAP_MOD_DELETE ) {
517 case LDAP_BACK_CFG_URI:
518 if ( li->url != NULL ) {
523 if ( li->lud != NULL ) {
524 ldap_free_urllist( li->lud );
529 case LDAP_BACK_CFG_TLS:
530 case LDAP_BACK_CFG_ACL_AUTHCDN:
531 case LDAP_BACK_CFG_ACL_PASSWD:
532 case LDAP_BACK_CFG_ACL_METHOD:
533 /* handled by LDAP_BACK_CFG_ACL_BIND */
537 case LDAP_BACK_CFG_ACL_BIND:
538 bindconf_free( &li->acl_sb );
541 case LDAP_BACK_CFG_IDASSERT_MODE:
542 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
543 case LDAP_BACK_CFG_IDASSERT_PASSWD:
544 case LDAP_BACK_CFG_IDASSERT_METHOD:
545 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
549 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
550 if ( li->idassert_authz != NULL ) {
551 ber_bvarray_free( li->idassert_authz );
552 li->idassert_authz = NULL;
556 case LDAP_BACK_CFG_IDASSERT_BIND:
557 bindconf_free( &li->idassert_sb );
560 case LDAP_BACK_CFG_REBIND:
561 case LDAP_BACK_CFG_CHASE:
562 case LDAP_BACK_CFG_T_F:
563 case LDAP_BACK_CFG_WHOAMI:
568 /* we need to handle all... */
577 case LDAP_BACK_CFG_URI: {
578 LDAPURLDesc *tmpludp;
582 if ( c->argc != 2 ) {
583 fprintf( stderr, "%s: line %d: "
585 "in \"uri <uri>\" line\n",
586 c->fname, c->lineno );
590 if ( li->url != NULL ) {
594 if ( li->lud != NULL ) {
595 ldap_free_urllist( li->lud );
599 /* PARANOID: DN and more are not required nor allowed */
600 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
602 urlrc = ldap_url_parselist( &li->lud, c->value_string );
604 if ( urlrc != LDAP_URL_SUCCESS ) {
608 case LDAP_URL_ERR_MEM:
611 case LDAP_URL_ERR_PARAM:
612 why = "parameter is bad";
614 case LDAP_URL_ERR_BADSCHEME:
615 why = "URL doesn't begin with \"[c]ldap[si]://\"";
617 case LDAP_URL_ERR_BADENCLOSURE:
618 why = "URL is missing trailing \">\"";
620 case LDAP_URL_ERR_BADURL:
622 case LDAP_URL_ERR_BADHOST:
623 why = "host/port is bad";
625 case LDAP_URL_ERR_BADATTRS:
626 why = "bad (or missing) attributes";
628 case LDAP_URL_ERR_BADSCOPE:
629 why = "scope string is invalid (or missing)";
631 case LDAP_URL_ERR_BADFILTER:
632 why = "bad or missing filter";
634 case LDAP_URL_ERR_BADEXTS:
635 why = "bad or missing extensions";
638 why = "unknown reason";
641 fprintf( stderr, "%s: line %d: "
642 "unable to parse uri \"%s\" "
643 "in \"uri <uri>\" line: %s\n",
644 c->fname, c->lineno, c->value_string, why );
648 for ( i = 0, tmpludp = li->lud;
650 i++, tmpludp = tmpludp->lud_next )
652 if ( ( tmpludp->lud_dn != NULL
653 && tmpludp->lud_dn[0] != '\0' )
654 || tmpludp->lud_attrs != NULL
655 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
656 || tmpludp->lud_filter != NULL
657 || tmpludp->lud_exts != NULL )
659 fprintf( stderr, "%s: line %d: "
660 "warning, only protocol, "
661 "host and port allowed "
662 "in \"uri <uri>\" statement "
663 "for uri #%d of \"%s\"\n",
664 c->fname, c->lineno, i, c->value_string );
669 for ( i = 0, tmpludp = li->lud;
671 i++, tmpludp = tmpludp->lud_next )
674 urllist = ch_calloc( sizeof( char * ), i + 1 );
676 for ( i = 0, tmpludp = li->lud;
678 i++, tmpludp = tmpludp->lud_next )
681 ber_len_t oldlen = 0, len;
685 tmplud.lud_attrs = NULL;
686 tmplud.lud_filter = NULL;
687 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
688 tmplud.lud_exts = NULL;
689 tmplud.lud_crit_exts = 0;
692 urllist[ i ] = ldap_url_desc2str( &tmplud );
694 if ( urllist[ i ] == NULL ) {
695 fprintf( stderr, "%s: line %d: "
696 "unable to rebuild uri "
697 "in \"uri <uri>\" statement "
699 c->fname, c->lineno, argv[ 1 ] );
704 li->url = ldap_charray2str( urllist, " " );
705 ldap_charray_free( urllist );
707 li->url = ch_strdup( c->value_string );
712 case LDAP_BACK_CFG_TLS:
713 i = verb_to_mask( c->argv[1], tls_mode );
714 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
717 li->flags &= ~LDAP_BACK_F_TLS_MASK;
718 li->flags |= tls_mode[i].mask;
721 case LDAP_BACK_CFG_ACL_AUTHCDN:
722 switch ( li->acl_authmethod ) {
724 li->acl_authmethod = LDAP_AUTH_SIMPLE;
727 case LDAP_AUTH_SIMPLE:
731 fprintf( stderr, "%s: line %d: "
732 "\"acl-authcDN <DN>\" incompatible "
733 "with auth method %d.",
734 c->fname, c->lineno, li->acl_authmethod );
737 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
738 free( li->acl_authcDN.bv_val );
740 li->acl_authcDN = c->value_ndn;
743 case LDAP_BACK_CFG_ACL_PASSWD:
744 switch ( li->acl_authmethod ) {
746 li->acl_authmethod = LDAP_AUTH_SIMPLE;
749 case LDAP_AUTH_SIMPLE:
753 fprintf( stderr, "%s: line %d: "
754 "\"acl-passwd <cred>\" incompatible "
755 "with auth method %d.",
756 c->fname, c->lineno, li->acl_authmethod );
759 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
760 free( li->acl_passwd.bv_val );
762 li->acl_passwd = c->value_bv;
765 case LDAP_BACK_CFG_ACL_METHOD:
766 case LDAP_BACK_CFG_ACL_BIND:
767 for ( i = 1; i < c->argc; i++ ) {
768 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
774 case LDAP_BACK_CFG_IDASSERT_MODE:
775 i = verb_to_mask( c->argv[1], idassert_mode );
776 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
777 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
778 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
779 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
780 li->idassert_authzID.bv_val[ 0 ] = 'u';
783 struct berval id, ndn;
785 ber_str2bv( c->argv[1], 0, 0, &id );
787 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
788 id.bv_val += STRLENOF( "dn:" );
789 id.bv_len -= STRLENOF( "dn:" );
792 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
793 if ( rc != LDAP_SUCCESS ) {
794 Debug( LDAP_DEBUG_ANY,
795 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
796 c->fname, c->lineno, c->argv[1] );
800 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
801 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
802 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
803 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
804 ch_free( ndn.bv_val );
806 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
810 li->idassert_mode = idassert_mode[i].mask;
816 for ( i = 2; i < c->argc; i++ ) {
817 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
818 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
821 Debug( LDAP_DEBUG_ANY,
822 "%s: line %d: unknown flag #%d "
823 "in \"idassert-mode <args> "
824 "[<flags>]\" line.\n",
825 c->fname, c->lineno, i - 2 );
832 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
833 switch ( li->idassert_authmethod ) {
835 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
838 case LDAP_AUTH_SIMPLE:
842 fprintf( stderr, "%s: line %d: "
843 "\"idassert-authcDN <DN>\" incompatible "
844 "with auth method %d.",
845 c->fname, c->lineno, li->idassert_authmethod );
848 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
849 free( li->idassert_authcDN.bv_val );
851 li->idassert_authcDN = c->value_ndn;
854 case LDAP_BACK_CFG_IDASSERT_PASSWD:
855 switch ( li->idassert_authmethod ) {
857 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
860 case LDAP_AUTH_SIMPLE:
864 fprintf( stderr, "%s: line %d: "
865 "\"idassert-passwd <cred>\" incompatible "
866 "with auth method %d.",
867 c->fname, c->lineno, li->idassert_authmethod );
870 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
871 free( li->idassert_passwd.bv_val );
873 li->idassert_passwd = c->value_bv;
876 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
877 ber_bvarray_add( &li->idassert_authz, &c->value_bv );
880 case LDAP_BACK_CFG_IDASSERT_METHOD:
881 /* no longer supported */
882 fprintf( stderr, "%s: %d: "
883 "\"idassert-method <args>\": "
884 "no longer supported; use \"idassert-bind\".\n",
885 c->fname, c->lineno );
888 case LDAP_BACK_CFG_IDASSERT_BIND:
889 for ( i = 1; i < c->argc; i++ ) {
890 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
891 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
894 j = verb_to_mask( argvi, idassert_mode );
895 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
896 fprintf( stderr, "%s: %d: "
897 "\"idassert-bind <args>\": "
898 "unknown mode \"%s\".\n",
899 c->fname, c->lineno, argvi );
903 li->idassert_mode = idassert_mode[ j ].mask;
905 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
906 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
908 if ( strcasecmp( argvi, "native" ) == 0 ) {
909 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
910 fprintf( stderr, "%s: %d: "
911 "\"idassert-bind <args>\": "
912 "authz=\"native\" incompatible "
913 "with auth method.\n",
914 c->fname, c->lineno );
917 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
919 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
920 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
923 fprintf( stderr, "%s: %d: "
924 "\"idassert-bind <args>\": "
925 "unknown authz \"%s\".\n",
926 c->fname, c->lineno, argvi );
930 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
931 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
932 char **flags = ldap_str2charray( argvi, "," );
935 if ( flags == NULL ) {
936 fprintf( stderr, "%s: %d: "
937 "\"idassert-bind <args>\": "
938 "unable to parse flags \"%s\".\n",
939 c->fname, c->lineno, argvi );
943 for ( j = 0; flags[ j ] != NULL; j++ ) {
944 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
945 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
948 fprintf( stderr, "%s: %d: "
949 "\"idassert-bind <args>\": "
950 "unknown flag \"%s\".\n",
951 c->fname, c->lineno, flags[ j ] );
956 ldap_charray_free( flags );
958 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
964 case LDAP_BACK_CFG_REBIND: {
967 if ( c->argc == 1 ) {
972 i = verb_to_mask( c->argv[1], yn_mode );
973 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
976 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
982 li->flags |= LDAP_BACK_F_SAVECRED;
985 li->flags &= ~LDAP_BACK_F_SAVECRED;
990 case LDAP_BACK_CFG_CHASE: {
993 if ( c->argc == 1 ) {
998 i = verb_to_mask( c->argv[1], yn_mode );
999 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1002 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1008 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1011 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1016 case LDAP_BACK_CFG_T_F:
1017 i = verb_to_mask( c->argv[1], t_f_mode );
1018 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1021 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1022 li->flags |= t_f_mode[i].mask;
1025 case LDAP_BACK_CFG_WHOAMI: {
1028 if ( c->argc == 1 ) {
1033 i = verb_to_mask( c->argv[1], yn_mode );
1034 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1037 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1043 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1045 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1046 0, ldap_back_exop_whoami );
1049 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1054 case LDAP_BACK_CFG_REWRITE:
1055 fprintf( stderr, "%s: line %d: "
1056 "rewrite/remap capabilities have been moved "
1057 "to the \"rwm\" overlay; see slapo-rwm(5) "
1058 "for details (hint: add \"overlay rwm\" "
1059 "and prefix all directives with \"rwm-\").\n",
1060 c->fname, c->lineno );
1071 ldap_back_init_cf( BackendInfo *bi )
1074 AttributeDescription *ad = NULL;
1077 bi->bi_cf_ocs = ldapocs;
1079 rc = config_register_schema( ldapcfg, ldapocs );
1084 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1085 * to be base64-encoded when written in LDIF form;
1086 * basically, we don't care if it fails */
1087 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1089 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1090 "warning, unable to get \"olcDbACLPasswd\" "
1091 "attribute description: %d: %s\n",
1094 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1095 ad->ad_type->sat_oid );
1099 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1101 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1102 "warning, unable to get \"olcDbIDAssertPasswd\" "
1103 "attribute description: %d: %s\n",
1106 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1107 ad->ad_type->sat_oid );
1115 parse_idassert( BackendDB *be, const char *fname, int lineno,
1116 int argc, char **argv );
1119 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1120 int argc, char **argv );
1123 ldap_back_db_config(
1130 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1133 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1138 /* server address to query (no longer supported, use "uri" directive) */
1139 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1141 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1145 /* URI of server to query (obsoletes "server" directive) */
1146 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1147 LDAPURLDesc *tmpludp;
1152 fprintf( stderr, "%s: line %d: "
1154 "in \"uri <uri>\" line\n",
1158 if ( li->url != NULL ) {
1161 if ( li->lud != NULL ) {
1162 ldap_free_urllist( li->lud );
1166 /* PARANOID: DN and more are not required nor allowed */
1167 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1169 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1171 if ( urlrc != LDAP_URL_SUCCESS ) {
1175 case LDAP_URL_ERR_MEM:
1178 case LDAP_URL_ERR_PARAM:
1179 why = "parameter is bad";
1181 case LDAP_URL_ERR_BADSCHEME:
1182 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1184 case LDAP_URL_ERR_BADENCLOSURE:
1185 why = "URL is missing trailing \">\"";
1187 case LDAP_URL_ERR_BADURL:
1189 case LDAP_URL_ERR_BADHOST:
1190 why = "host/port is bad";
1192 case LDAP_URL_ERR_BADATTRS:
1193 why = "bad (or missing) attributes";
1195 case LDAP_URL_ERR_BADSCOPE:
1196 why = "scope string is invalid (or missing)";
1198 case LDAP_URL_ERR_BADFILTER:
1199 why = "bad or missing filter";
1201 case LDAP_URL_ERR_BADEXTS:
1202 why = "bad or missing extensions";
1205 why = "unknown reason";
1208 fprintf( stderr, "%s: line %d: "
1209 "unable to parse uri \"%s\" "
1210 "in \"uri <uri>\" line: %s\n",
1211 fname, lineno, argv[ 1 ], why );
1215 for ( i = 0, tmpludp = li->lud;
1217 i++, tmpludp = tmpludp->lud_next )
1219 if ( ( tmpludp->lud_dn != NULL
1220 && tmpludp->lud_dn[0] != '\0' )
1221 || tmpludp->lud_attrs != NULL
1222 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1223 || tmpludp->lud_filter != NULL
1224 || tmpludp->lud_exts != NULL )
1226 fprintf( stderr, "%s: line %d: "
1227 "warning, only protocol, "
1228 "host and port allowed "
1229 "in \"uri <uri>\" statement "
1230 "for uri #%d of \"%s\"\n",
1231 fname, lineno, i, argv[1] );
1236 for ( i = 0, tmpludp = li->lud;
1238 i++, tmpludp = tmpludp->lud_next )
1241 urllist = ch_calloc( sizeof( char * ), i + 1 );
1243 for ( i = 0, tmpludp = li->lud;
1245 i++, tmpludp = tmpludp->lud_next )
1248 ber_len_t oldlen = 0, len;
1252 tmplud.lud_attrs = NULL;
1253 tmplud.lud_filter = NULL;
1254 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1255 tmplud.lud_exts = NULL;
1256 tmplud.lud_crit_exts = 0;
1259 urllist[ i ] = ldap_url_desc2str( &tmplud );
1261 if ( urllist[ i ] == NULL ) {
1262 fprintf( stderr, "%s: line %d: "
1263 "unable to rebuild uri "
1264 "in \"uri <uri>\" statement "
1266 fname, lineno, argv[ 1 ] );
1271 li->url = ldap_charray2str( urllist, " " );
1272 ldap_charray_free( urllist );
1274 li->url = ch_strdup( argv[ 1 ] );
1277 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1280 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1286 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1287 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1290 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1291 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1294 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1295 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1296 li->flags |= LDAP_BACK_F_USE_TLS;
1298 /* propagate start tls */
1299 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1300 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1303 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1304 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1305 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1309 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1310 fname, lineno, argv[1] );
1314 /* remote ACL stuff... */
1315 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1316 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1318 /* NOTE: "bind{DN,pw}" was initially used; it's now
1319 * deprected and undocumented, it can be dropped at some
1320 * point, since nobody should be really using it */
1321 return parse_acl_auth( be, fname, lineno, argc, argv );
1323 /* identity assertion stuff... */
1324 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1325 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1327 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1328 * deprected and undocumented, it can be dropped at some
1329 * point, since nobody should be really using it */
1330 return parse_idassert( be, fname, lineno, argc, argv );
1332 /* save bind creds for referral rebinds? */
1333 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1337 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1340 li->flags |= LDAP_BACK_F_SAVECRED;
1344 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1345 li->flags |= LDAP_BACK_F_SAVECRED;
1347 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1348 li->flags &= ~LDAP_BACK_F_SAVECRED;
1352 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1353 fname, lineno, argv[ 1 ] );
1360 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1365 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1368 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1373 /* this is the default; we add it because the default might change... */
1374 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1375 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1377 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1378 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1382 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1383 fname, lineno, argv[1] );
1387 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1390 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1395 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1396 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1398 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1399 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1401 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1402 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1406 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1407 fname, lineno, argv[ 1 ] );
1411 /* intercept exop_who_am_i? */
1412 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1413 int doload_extop = 0;
1418 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1425 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1428 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1430 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1431 fname, lineno, argv[ 1 ] );
1438 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1443 if ( doload_extop ) {
1444 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1446 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1447 0, ldap_back_exop_whoami );
1450 /* FIXME: legacy: intercept old rewrite/remap directives
1451 * and try to start the rwm overlay */
1452 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1453 || strcasecmp( argv[0], "map" ) == 0
1454 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1457 fprintf( stderr, "%s: line %d: "
1458 "rewrite/remap capabilities have been moved "
1459 "to the \"rwm\" overlay; see slapo-rwm(5) "
1460 "for details. I'm trying to do my best "
1461 "to preserve backwards compatibility...\n",
1464 if ( li->rwm_started == 0 ) {
1465 if ( overlay_config( be, "rwm" ) ) {
1466 fprintf( stderr, "%s: line %d: "
1467 "unable to configure the \"rwm\" "
1468 "overlay, required by directive "
1470 fname, lineno, argv[0] );
1471 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1472 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1473 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1477 fprintf( stderr, "%s: line %d: back-ldap: "
1478 "automatically starting \"rwm\" overlay, "
1479 "triggered by \"%s\" directive.\n",
1480 fname, lineno, argv[ 0 ] );
1482 /* this is the default; we add it because the default might change... */
1483 li->rwm_started = 1;
1485 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1488 fprintf( stderr, "%s: line %d: "
1489 "rewrite/remap capabilities have been moved "
1490 "to the \"rwm\" overlay; see slapo-rwm(5) "
1491 "for details (hint: add \"overlay rwm\" "
1492 "and prefix all directives with \"rwm-\").\n",
1500 return SLAP_CONF_UNKNOWN;
1507 ldap_back_exop_whoami(
1511 struct berval *bv = NULL;
1513 if ( op->oq_extended.rs_reqdata != NULL ) {
1514 /* no request data should be provided */
1515 rs->sr_text = "no request data expected";
1516 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1519 rs->sr_err = backend_check_restrictions( op, rs,
1520 (struct berval *)&slap_EXOP_WHOAMI );
1521 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1523 /* if auth'd by back-ldap and request is proxied, forward it */
1524 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)) {
1525 struct ldapconn *lc;
1527 LDAPControl c, *ctrls[2] = {NULL, NULL};
1529 Operation op2 = *op;
1534 op2.o_ndn = op->o_conn->c_ndn;
1535 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1536 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1539 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1540 c.ldctl_iscritical = 1;
1541 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1542 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1543 strcpy(c.ldctl_value.bv_val, "dn:");
1544 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1547 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1548 if (rs->sr_err == LDAP_SUCCESS) {
1549 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1550 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1552 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1554 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1557 ldap_back_freeconn( op, lc );
1561 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1565 ch_free(c.ldctl_value.bv_val);
1566 if (rs->sr_err != LDAP_SUCCESS) {
1567 rs->sr_err = slap_map_api2result( rs );
1570 /* else just do the same as before */
1571 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1572 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1573 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
1574 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1575 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
1576 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
1578 bv->bv_val[bv->bv_len] = '\0';
1585 rs->sr_rspdata = bv;
1599 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1601 /* identity assertion mode */
1602 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1604 Debug( LDAP_DEBUG_ANY,
1605 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1606 fname, lineno, argc );
1610 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1611 /* will proxyAuthz as client's identity only if bound */
1612 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1614 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1615 /* will proxyAuthz as client's identity */
1616 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1618 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1619 /* will proxyAuthz as anonymous */
1620 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1622 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1623 /* will not proxyAuthz */
1624 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1630 /* will proxyAuthz as argv[1] */
1631 ber_str2bv( argv[1], 0, 0, &id );
1633 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1634 /* force lowercase... */
1636 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1637 ber_dupbv( &li->idassert_authzID, &id );
1642 /* default is DN? */
1643 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1644 id.bv_val += STRLENOF( "dn:" );
1645 id.bv_len -= STRLENOF( "dn:" );
1648 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1649 if ( rc != LDAP_SUCCESS ) {
1650 Debug( LDAP_DEBUG_ANY,
1651 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1652 fname, lineno, argv[1] );
1656 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1657 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1658 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1659 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1660 ch_free( dn.bv_val );
1662 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1666 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1667 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1668 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1671 Debug( LDAP_DEBUG_ANY,
1672 "%s: line %d: unknown flag \"%s\" "
1673 "in \"idassert-mode <args> "
1674 "[<flags>]\" line.\n",
1675 fname, lineno, argv[0] );
1680 /* name to use for proxyAuthz propagation */
1681 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1682 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1687 /* FIXME: "proxyauthzdn" is no longer documented, and
1688 * temporarily supported for backwards compatibility */
1692 "%s: line %d: missing name in \"%s <name>\" line\n",
1693 fname, lineno, argv[0] );
1697 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1698 fprintf( stderr, "%s: line %d: "
1699 "authcDN already defined; replacing...\n",
1701 ch_free( li->idassert_authcDN.bv_val );
1704 ber_str2bv( argv[1], 0, 0, &dn );
1705 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1706 if ( rc != LDAP_SUCCESS ) {
1707 Debug( LDAP_DEBUG_ANY,
1708 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1709 fname, lineno, argv[1] );
1713 /* password to use for proxyAuthz propagation */
1714 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1715 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1717 /* FIXME: "proxyauthzpw" is no longer documented, and
1718 * temporarily supported for backwards compatibility */
1722 "%s: line %d: missing password in \"%s <password>\" line\n",
1723 fname, lineno, argv[0] );
1727 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1728 fprintf( stderr, "%s: line %d: "
1729 "passwd already defined; replacing...\n",
1731 ch_free( li->idassert_passwd.bv_val );
1734 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1736 /* rules to accept identity assertion... */
1737 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1740 ber_str2bv( argv[1], 0, 1, &rule );
1742 ber_bvarray_add( &li->idassert_authz, &rule );
1744 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1749 "%s: line %d: missing method in \"%s <method>\" line\n",
1750 fname, lineno, argv[0] );
1755 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1756 argv1 += STRLENOF( "bindmethod=" );
1759 if ( strcasecmp( argv1, "none" ) == 0 ) {
1760 /* FIXME: is this at all useful? */
1761 li->idassert_authmethod = LDAP_AUTH_NONE;
1765 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1766 fname, lineno, argv[0], argv[1] );
1769 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1772 for ( arg = 2; arg < argc; arg++ ) {
1773 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1774 char *val = argv[arg] + STRLENOF( "authcdn=" );
1778 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1779 fprintf( stderr, "%s: line %d: "
1780 "SASL authcDN already defined; replacing...\n",
1782 ch_free( li->idassert_authcDN.bv_val );
1784 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1785 val += STRLENOF( "dn:" );
1788 ber_str2bv( val, 0, 0, &dn );
1789 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1790 if ( rc != LDAP_SUCCESS ) {
1791 Debug( LDAP_DEBUG_ANY,
1792 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1793 fname, lineno, val );
1797 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1798 char *val = argv[arg] + STRLENOF( "cred=" );
1800 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1801 fprintf( stderr, "%s: line %d: "
1802 "SASL cred already defined; replacing...\n",
1804 ch_free( li->idassert_passwd.bv_val );
1806 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1809 fprintf( stderr, "%s: line %d: "
1810 "unknown parameter %s\n",
1811 fname, lineno, argv[arg] );
1816 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1818 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1819 #ifdef HAVE_CYRUS_SASL
1822 for ( arg = 2; arg < argc; arg++ ) {
1823 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1824 char *val = argv[arg] + STRLENOF( "mech=" );
1826 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1827 fprintf( stderr, "%s: line %d: "
1828 "SASL mech already defined; replacing...\n",
1830 ch_free( li->idassert_sasl_mech.bv_val );
1832 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1834 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1835 char *val = argv[arg] + STRLENOF( "realm=" );
1837 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1838 fprintf( stderr, "%s: line %d: "
1839 "SASL realm already defined; replacing...\n",
1841 ch_free( li->idassert_sasl_realm.bv_val );
1843 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1845 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1846 char *val = argv[arg] + STRLENOF( "authcdn=" );
1850 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1851 fprintf( stderr, "%s: line %d: "
1852 "SASL authcDN already defined; replacing...\n",
1854 ch_free( li->idassert_authcDN.bv_val );
1856 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1857 val += STRLENOF( "dn:" );
1860 ber_str2bv( val, 0, 0, &dn );
1861 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1862 if ( rc != LDAP_SUCCESS ) {
1863 Debug( LDAP_DEBUG_ANY,
1864 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1865 fname, lineno, val );
1869 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1870 char *val = argv[arg] + STRLENOF( "authcid=" );
1872 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1873 fprintf( stderr, "%s: line %d: "
1874 "SASL authcID already defined; replacing...\n",
1876 ch_free( li->idassert_authcID.bv_val );
1878 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1879 val += STRLENOF( "u:" );
1881 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1883 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1884 char *val = argv[arg] + STRLENOF( "cred=" );
1886 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1887 fprintf( stderr, "%s: line %d: "
1888 "SASL cred already defined; replacing...\n",
1890 ch_free( li->idassert_passwd.bv_val );
1892 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1894 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1895 char *val = argv[arg] + STRLENOF( "authz=" );
1897 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1898 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1900 } else if ( strcasecmp( val, "native" ) == 0 ) {
1901 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1904 fprintf( stderr, "%s: line %d: "
1905 "unknown authz mode \"%s\"\n",
1906 fname, lineno, val );
1911 fprintf( stderr, "%s: line %d: "
1912 "unknown SASL parameter %s\n",
1913 fname, lineno, argv[arg] );
1918 li->idassert_authmethod = LDAP_AUTH_SASL;
1920 #else /* !HAVE_CYRUS_SASL */
1921 fprintf( stderr, "%s: line %d: "
1922 "compile --with-cyrus-sasl to enable SASL auth\n",
1925 #endif /* !HAVE_CYRUS_SASL */
1928 fprintf( stderr, "%s: line %d: "
1929 "unhandled idassert-method method %s\n",
1930 fname, lineno, argv[1] );
1935 return SLAP_CONF_UNKNOWN;
1950 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1952 /* name to use for remote ACL access */
1953 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
1954 || strcasecmp( argv[0], "binddn" ) == 0 )
1959 /* FIXME: "binddn" is no longer documented, and
1960 * temporarily supported for backwards compatibility */
1964 "%s: line %d: missing name in \"%s <name>\" line\n",
1965 fname, lineno, argv[0] );
1969 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
1970 fprintf( stderr, "%s: line %d: "
1971 "authcDN already defined; replacing...\n",
1973 ch_free( li->acl_authcDN.bv_val );
1976 ber_str2bv( argv[1], 0, 0, &dn );
1977 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
1978 if ( rc != LDAP_SUCCESS ) {
1979 Debug( LDAP_DEBUG_ANY,
1980 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
1981 fname, lineno, argv[1] );
1985 /* password to use for remote ACL access */
1986 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
1987 || strcasecmp( argv[0], "bindpw" ) == 0 )
1989 /* FIXME: "bindpw" is no longer documented, and
1990 * temporarily supported for backwards compatibility */
1994 "%s: line %d: missing password in \"%s <password>\" line\n",
1995 fname, lineno, argv[0] );
1999 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2000 fprintf( stderr, "%s: line %d: "
2001 "passwd already defined; replacing...\n",
2003 ch_free( li->acl_passwd.bv_val );
2006 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2008 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2013 "%s: line %d: missing method in \"%s <method>\" line\n",
2014 fname, lineno, argv[0] );
2019 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2020 argv1 += STRLENOF( "bindmethod=" );
2023 if ( strcasecmp( argv1, "none" ) == 0 ) {
2024 /* FIXME: is this at all useful? */
2025 li->acl_authmethod = LDAP_AUTH_NONE;
2029 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2030 fname, lineno, argv[0], argv[1] );
2033 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2034 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2038 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2039 fname, lineno, argv[0], argv[1] );
2042 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2043 #ifdef HAVE_CYRUS_SASL
2046 for ( arg = 2; arg < argc; arg++ ) {
2047 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2048 char *val = argv[arg] + STRLENOF( "mech=" );
2050 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2051 fprintf( stderr, "%s: line %d: "
2052 "SASL mech already defined; replacing...\n",
2054 ch_free( li->acl_sasl_mech.bv_val );
2056 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2058 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2059 char *val = argv[arg] + STRLENOF( "realm=" );
2061 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2062 fprintf( stderr, "%s: line %d: "
2063 "SASL realm already defined; replacing...\n",
2065 ch_free( li->acl_sasl_realm.bv_val );
2067 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2069 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2070 char *val = argv[arg] + STRLENOF( "authcdn=" );
2074 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2075 fprintf( stderr, "%s: line %d: "
2076 "SASL authcDN already defined; replacing...\n",
2078 ch_free( li->acl_authcDN.bv_val );
2080 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2081 val += STRLENOF( "dn:" );
2084 ber_str2bv( val, 0, 0, &dn );
2085 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2086 if ( rc != LDAP_SUCCESS ) {
2087 Debug( LDAP_DEBUG_ANY,
2088 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2089 fname, lineno, val );
2093 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2094 char *val = argv[arg] + STRLENOF( "authcid=" );
2096 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2097 fprintf( stderr, "%s: line %d: "
2098 "SASL authcID already defined; replacing...\n",
2100 ch_free( li->acl_authcID.bv_val );
2102 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2103 val += STRLENOF( "u:" );
2105 ber_str2bv( val, 0, 1, &li->acl_authcID );
2107 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2108 char *val = argv[arg] + STRLENOF( "cred=" );
2110 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2111 fprintf( stderr, "%s: line %d: "
2112 "SASL cred already defined; replacing...\n",
2114 ch_free( li->acl_passwd.bv_val );
2116 ber_str2bv( val, 0, 1, &li->acl_passwd );
2119 fprintf( stderr, "%s: line %d: "
2120 "unknown SASL parameter %s\n",
2121 fname, lineno, argv[arg] );
2126 li->acl_authmethod = LDAP_AUTH_SASL;
2128 #else /* !HAVE_CYRUS_SASL */
2129 fprintf( stderr, "%s: line %d: "
2130 "compile --with-cyrus-sasl to enable SASL auth\n",
2133 #endif /* !HAVE_CYRUS_SASL */
2136 fprintf( stderr, "%s: line %d: "
2137 "unhandled acl-method method %s\n",
2138 fname, lineno, argv[1] );
2143 return SLAP_CONF_UNKNOWN;