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 );
528 /* better cleanup the cached connections... */
529 /* NOTE: don't worry about locking: if we got here,
530 * other threads are suspended. */
531 avl_free( li->conntree, ldap_back_conn_free );
535 case LDAP_BACK_CFG_TLS:
536 case LDAP_BACK_CFG_ACL_AUTHCDN:
537 case LDAP_BACK_CFG_ACL_PASSWD:
538 case LDAP_BACK_CFG_ACL_METHOD:
539 /* handled by LDAP_BACK_CFG_ACL_BIND */
543 case LDAP_BACK_CFG_ACL_BIND:
544 bindconf_free( &li->acl_sb );
547 case LDAP_BACK_CFG_IDASSERT_MODE:
548 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
549 case LDAP_BACK_CFG_IDASSERT_PASSWD:
550 case LDAP_BACK_CFG_IDASSERT_METHOD:
551 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
555 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
556 if ( li->idassert_authz != NULL ) {
557 ber_bvarray_free( li->idassert_authz );
558 li->idassert_authz = NULL;
562 case LDAP_BACK_CFG_IDASSERT_BIND:
563 bindconf_free( &li->idassert_sb );
566 case LDAP_BACK_CFG_REBIND:
567 case LDAP_BACK_CFG_CHASE:
568 case LDAP_BACK_CFG_T_F:
569 case LDAP_BACK_CFG_WHOAMI:
574 /* we need to handle all... */
583 case LDAP_BACK_CFG_URI: {
584 LDAPURLDesc *tmpludp;
588 if ( c->argc != 2 ) {
589 fprintf( stderr, "%s: line %d: "
591 "in \"uri <uri>\" line\n",
592 c->fname, c->lineno );
596 if ( li->url != NULL ) {
600 if ( li->lud != NULL ) {
601 ldap_free_urllist( li->lud );
605 /* PARANOID: DN and more are not required nor allowed */
606 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
608 urlrc = ldap_url_parselist( &li->lud, c->value_string );
610 if ( urlrc != LDAP_URL_SUCCESS ) {
614 case LDAP_URL_ERR_MEM:
617 case LDAP_URL_ERR_PARAM:
618 why = "parameter is bad";
620 case LDAP_URL_ERR_BADSCHEME:
621 why = "URL doesn't begin with \"[c]ldap[si]://\"";
623 case LDAP_URL_ERR_BADENCLOSURE:
624 why = "URL is missing trailing \">\"";
626 case LDAP_URL_ERR_BADURL:
628 case LDAP_URL_ERR_BADHOST:
629 why = "host/port is bad";
631 case LDAP_URL_ERR_BADATTRS:
632 why = "bad (or missing) attributes";
634 case LDAP_URL_ERR_BADSCOPE:
635 why = "scope string is invalid (or missing)";
637 case LDAP_URL_ERR_BADFILTER:
638 why = "bad or missing filter";
640 case LDAP_URL_ERR_BADEXTS:
641 why = "bad or missing extensions";
644 why = "unknown reason";
647 fprintf( stderr, "%s: line %d: "
648 "unable to parse uri \"%s\" "
649 "in \"uri <uri>\" line: %s\n",
650 c->fname, c->lineno, c->value_string, why );
654 for ( i = 0, tmpludp = li->lud;
656 i++, tmpludp = tmpludp->lud_next )
658 if ( ( tmpludp->lud_dn != NULL
659 && tmpludp->lud_dn[0] != '\0' )
660 || tmpludp->lud_attrs != NULL
661 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
662 || tmpludp->lud_filter != NULL
663 || tmpludp->lud_exts != NULL )
665 fprintf( stderr, "%s: line %d: "
666 "warning, only protocol, "
667 "host and port allowed "
668 "in \"uri <uri>\" statement "
669 "for uri #%d of \"%s\"\n",
670 c->fname, c->lineno, i, c->value_string );
675 for ( i = 0, tmpludp = li->lud;
677 i++, tmpludp = tmpludp->lud_next )
680 urllist = ch_calloc( sizeof( char * ), i + 1 );
682 for ( i = 0, tmpludp = li->lud;
684 i++, tmpludp = tmpludp->lud_next )
687 ber_len_t oldlen = 0, len;
691 tmplud.lud_attrs = NULL;
692 tmplud.lud_filter = NULL;
693 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
694 tmplud.lud_exts = NULL;
695 tmplud.lud_crit_exts = 0;
698 urllist[ i ] = ldap_url_desc2str( &tmplud );
700 if ( urllist[ i ] == NULL ) {
701 fprintf( stderr, "%s: line %d: "
702 "unable to rebuild uri "
703 "in \"uri <uri>\" statement "
705 c->fname, c->lineno, argv[ 1 ] );
710 li->url = ldap_charray2str( urllist, " " );
711 ldap_charray_free( urllist );
713 li->url = ch_strdup( c->value_string );
718 case LDAP_BACK_CFG_TLS:
719 i = verb_to_mask( c->argv[1], tls_mode );
720 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
723 li->flags &= ~LDAP_BACK_F_TLS_MASK;
724 li->flags |= tls_mode[i].mask;
727 case LDAP_BACK_CFG_ACL_AUTHCDN:
728 switch ( li->acl_authmethod ) {
730 li->acl_authmethod = LDAP_AUTH_SIMPLE;
733 case LDAP_AUTH_SIMPLE:
737 fprintf( stderr, "%s: line %d: "
738 "\"acl-authcDN <DN>\" incompatible "
739 "with auth method %d.",
740 c->fname, c->lineno, li->acl_authmethod );
743 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
744 free( li->acl_authcDN.bv_val );
746 li->acl_authcDN = c->value_ndn;
749 case LDAP_BACK_CFG_ACL_PASSWD:
750 switch ( li->acl_authmethod ) {
752 li->acl_authmethod = LDAP_AUTH_SIMPLE;
755 case LDAP_AUTH_SIMPLE:
759 fprintf( stderr, "%s: line %d: "
760 "\"acl-passwd <cred>\" incompatible "
761 "with auth method %d.",
762 c->fname, c->lineno, li->acl_authmethod );
765 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
766 free( li->acl_passwd.bv_val );
768 li->acl_passwd = c->value_bv;
771 case LDAP_BACK_CFG_ACL_METHOD:
772 case LDAP_BACK_CFG_ACL_BIND:
773 for ( i = 1; i < c->argc; i++ ) {
774 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
780 case LDAP_BACK_CFG_IDASSERT_MODE:
781 i = verb_to_mask( c->argv[1], idassert_mode );
782 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
783 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
784 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
785 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
786 li->idassert_authzID.bv_val[ 0 ] = 'u';
789 struct berval id, ndn;
791 ber_str2bv( c->argv[1], 0, 0, &id );
793 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
794 id.bv_val += STRLENOF( "dn:" );
795 id.bv_len -= STRLENOF( "dn:" );
798 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
799 if ( rc != LDAP_SUCCESS ) {
800 Debug( LDAP_DEBUG_ANY,
801 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
802 c->fname, c->lineno, c->argv[1] );
806 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
807 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
808 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
809 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
810 ch_free( ndn.bv_val );
812 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
816 li->idassert_mode = idassert_mode[i].mask;
822 for ( i = 2; i < c->argc; i++ ) {
823 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
824 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
827 Debug( LDAP_DEBUG_ANY,
828 "%s: line %d: unknown flag #%d "
829 "in \"idassert-mode <args> "
830 "[<flags>]\" line.\n",
831 c->fname, c->lineno, i - 2 );
838 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
839 switch ( li->idassert_authmethod ) {
841 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
844 case LDAP_AUTH_SIMPLE:
848 fprintf( stderr, "%s: line %d: "
849 "\"idassert-authcDN <DN>\" incompatible "
850 "with auth method %d.",
851 c->fname, c->lineno, li->idassert_authmethod );
854 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
855 free( li->idassert_authcDN.bv_val );
857 li->idassert_authcDN = c->value_ndn;
860 case LDAP_BACK_CFG_IDASSERT_PASSWD:
861 switch ( li->idassert_authmethod ) {
863 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
866 case LDAP_AUTH_SIMPLE:
870 fprintf( stderr, "%s: line %d: "
871 "\"idassert-passwd <cred>\" incompatible "
872 "with auth method %d.",
873 c->fname, c->lineno, li->idassert_authmethod );
876 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
877 free( li->idassert_passwd.bv_val );
879 li->idassert_passwd = c->value_bv;
882 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
883 ber_bvarray_add( &li->idassert_authz, &c->value_bv );
886 case LDAP_BACK_CFG_IDASSERT_METHOD:
887 /* no longer supported */
888 fprintf( stderr, "%s: %d: "
889 "\"idassert-method <args>\": "
890 "no longer supported; use \"idassert-bind\".\n",
891 c->fname, c->lineno );
894 case LDAP_BACK_CFG_IDASSERT_BIND:
895 for ( i = 1; i < c->argc; i++ ) {
896 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
897 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
900 j = verb_to_mask( argvi, idassert_mode );
901 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
902 fprintf( stderr, "%s: %d: "
903 "\"idassert-bind <args>\": "
904 "unknown mode \"%s\".\n",
905 c->fname, c->lineno, argvi );
909 li->idassert_mode = idassert_mode[ j ].mask;
911 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
912 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
914 if ( strcasecmp( argvi, "native" ) == 0 ) {
915 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
916 fprintf( stderr, "%s: %d: "
917 "\"idassert-bind <args>\": "
918 "authz=\"native\" incompatible "
919 "with auth method.\n",
920 c->fname, c->lineno );
923 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
925 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
926 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
929 fprintf( stderr, "%s: %d: "
930 "\"idassert-bind <args>\": "
931 "unknown authz \"%s\".\n",
932 c->fname, c->lineno, argvi );
936 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
937 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
938 char **flags = ldap_str2charray( argvi, "," );
941 if ( flags == NULL ) {
942 fprintf( stderr, "%s: %d: "
943 "\"idassert-bind <args>\": "
944 "unable to parse flags \"%s\".\n",
945 c->fname, c->lineno, argvi );
949 for ( j = 0; flags[ j ] != NULL; j++ ) {
950 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
951 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
954 fprintf( stderr, "%s: %d: "
955 "\"idassert-bind <args>\": "
956 "unknown flag \"%s\".\n",
957 c->fname, c->lineno, flags[ j ] );
962 ldap_charray_free( flags );
964 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
970 case LDAP_BACK_CFG_REBIND: {
973 if ( c->argc == 1 ) {
978 i = verb_to_mask( c->argv[1], yn_mode );
979 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
982 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
988 li->flags |= LDAP_BACK_F_SAVECRED;
991 li->flags &= ~LDAP_BACK_F_SAVECRED;
996 case LDAP_BACK_CFG_CHASE: {
999 if ( c->argc == 1 ) {
1004 i = verb_to_mask( c->argv[1], yn_mode );
1005 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1008 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1014 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1017 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1022 case LDAP_BACK_CFG_T_F:
1023 i = verb_to_mask( c->argv[1], t_f_mode );
1024 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1027 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1028 li->flags |= t_f_mode[i].mask;
1031 case LDAP_BACK_CFG_WHOAMI: {
1034 if ( c->argc == 1 ) {
1039 i = verb_to_mask( c->argv[1], yn_mode );
1040 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1043 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1049 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1051 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1052 0, ldap_back_exop_whoami );
1055 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1060 case LDAP_BACK_CFG_REWRITE:
1061 fprintf( stderr, "%s: line %d: "
1062 "rewrite/remap capabilities have been moved "
1063 "to the \"rwm\" overlay; see slapo-rwm(5) "
1064 "for details (hint: add \"overlay rwm\" "
1065 "and prefix all directives with \"rwm-\").\n",
1066 c->fname, c->lineno );
1077 ldap_back_init_cf( BackendInfo *bi )
1080 AttributeDescription *ad = NULL;
1083 bi->bi_cf_ocs = ldapocs;
1085 rc = config_register_schema( ldapcfg, ldapocs );
1090 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1091 * to be base64-encoded when written in LDIF form;
1092 * basically, we don't care if it fails */
1093 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1095 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1096 "warning, unable to get \"olcDbACLPasswd\" "
1097 "attribute description: %d: %s\n",
1100 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1101 ad->ad_type->sat_oid );
1105 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1107 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1108 "warning, unable to get \"olcDbIDAssertPasswd\" "
1109 "attribute description: %d: %s\n",
1112 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1113 ad->ad_type->sat_oid );
1121 parse_idassert( BackendDB *be, const char *fname, int lineno,
1122 int argc, char **argv );
1125 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1126 int argc, char **argv );
1129 ldap_back_db_config(
1136 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1139 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1144 /* server address to query (no longer supported, use "uri" directive) */
1145 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1147 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1151 /* URI of server to query (obsoletes "server" directive) */
1152 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1153 LDAPURLDesc *tmpludp;
1158 fprintf( stderr, "%s: line %d: "
1160 "in \"uri <uri>\" line\n",
1164 if ( li->url != NULL ) {
1167 if ( li->lud != NULL ) {
1168 ldap_free_urllist( li->lud );
1172 /* PARANOID: DN and more are not required nor allowed */
1173 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1175 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1177 if ( urlrc != LDAP_URL_SUCCESS ) {
1181 case LDAP_URL_ERR_MEM:
1184 case LDAP_URL_ERR_PARAM:
1185 why = "parameter is bad";
1187 case LDAP_URL_ERR_BADSCHEME:
1188 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1190 case LDAP_URL_ERR_BADENCLOSURE:
1191 why = "URL is missing trailing \">\"";
1193 case LDAP_URL_ERR_BADURL:
1195 case LDAP_URL_ERR_BADHOST:
1196 why = "host/port is bad";
1198 case LDAP_URL_ERR_BADATTRS:
1199 why = "bad (or missing) attributes";
1201 case LDAP_URL_ERR_BADSCOPE:
1202 why = "scope string is invalid (or missing)";
1204 case LDAP_URL_ERR_BADFILTER:
1205 why = "bad or missing filter";
1207 case LDAP_URL_ERR_BADEXTS:
1208 why = "bad or missing extensions";
1211 why = "unknown reason";
1214 fprintf( stderr, "%s: line %d: "
1215 "unable to parse uri \"%s\" "
1216 "in \"uri <uri>\" line: %s\n",
1217 fname, lineno, argv[ 1 ], why );
1221 for ( i = 0, tmpludp = li->lud;
1223 i++, tmpludp = tmpludp->lud_next )
1225 if ( ( tmpludp->lud_dn != NULL
1226 && tmpludp->lud_dn[0] != '\0' )
1227 || tmpludp->lud_attrs != NULL
1228 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1229 || tmpludp->lud_filter != NULL
1230 || tmpludp->lud_exts != NULL )
1232 fprintf( stderr, "%s: line %d: "
1233 "warning, only protocol, "
1234 "host and port allowed "
1235 "in \"uri <uri>\" statement "
1236 "for uri #%d of \"%s\"\n",
1237 fname, lineno, i, argv[1] );
1242 for ( i = 0, tmpludp = li->lud;
1244 i++, tmpludp = tmpludp->lud_next )
1247 urllist = ch_calloc( sizeof( char * ), i + 1 );
1249 for ( i = 0, tmpludp = li->lud;
1251 i++, tmpludp = tmpludp->lud_next )
1254 ber_len_t oldlen = 0, len;
1258 tmplud.lud_attrs = NULL;
1259 tmplud.lud_filter = NULL;
1260 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1261 tmplud.lud_exts = NULL;
1262 tmplud.lud_crit_exts = 0;
1265 urllist[ i ] = ldap_url_desc2str( &tmplud );
1267 if ( urllist[ i ] == NULL ) {
1268 fprintf( stderr, "%s: line %d: "
1269 "unable to rebuild uri "
1270 "in \"uri <uri>\" statement "
1272 fname, lineno, argv[ 1 ] );
1277 li->url = ldap_charray2str( urllist, " " );
1278 ldap_charray_free( urllist );
1280 li->url = ch_strdup( argv[ 1 ] );
1283 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1286 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1292 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1293 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1296 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1297 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1300 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1301 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1302 li->flags |= LDAP_BACK_F_USE_TLS;
1304 /* propagate start tls */
1305 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1306 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1309 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1310 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1311 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1315 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1316 fname, lineno, argv[1] );
1320 /* remote ACL stuff... */
1321 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1322 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1324 /* NOTE: "bind{DN,pw}" was initially used; it's now
1325 * deprected and undocumented, it can be dropped at some
1326 * point, since nobody should be really using it */
1327 return parse_acl_auth( be, fname, lineno, argc, argv );
1329 /* identity assertion stuff... */
1330 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1331 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1333 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1334 * deprected and undocumented, it can be dropped at some
1335 * point, since nobody should be really using it */
1336 return parse_idassert( be, fname, lineno, argc, argv );
1338 /* save bind creds for referral rebinds? */
1339 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1343 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1346 li->flags |= LDAP_BACK_F_SAVECRED;
1350 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1351 li->flags |= LDAP_BACK_F_SAVECRED;
1353 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1354 li->flags &= ~LDAP_BACK_F_SAVECRED;
1358 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1359 fname, lineno, argv[ 1 ] );
1366 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1371 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1374 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1379 /* this is the default; we add it because the default might change... */
1380 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1381 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1383 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1384 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1388 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1389 fname, lineno, argv[1] );
1393 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1396 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1401 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1402 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1404 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1405 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1407 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1408 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1412 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1413 fname, lineno, argv[ 1 ] );
1417 /* intercept exop_who_am_i? */
1418 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1419 int doload_extop = 0;
1424 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1431 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1434 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1436 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1437 fname, lineno, argv[ 1 ] );
1444 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1449 if ( doload_extop ) {
1450 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1452 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1453 0, ldap_back_exop_whoami );
1456 /* FIXME: legacy: intercept old rewrite/remap directives
1457 * and try to start the rwm overlay */
1458 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1459 || strcasecmp( argv[0], "map" ) == 0
1460 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1463 fprintf( stderr, "%s: line %d: "
1464 "rewrite/remap capabilities have been moved "
1465 "to the \"rwm\" overlay; see slapo-rwm(5) "
1466 "for details. I'm trying to do my best "
1467 "to preserve backwards compatibility...\n",
1470 if ( li->rwm_started == 0 ) {
1471 if ( overlay_config( be, "rwm" ) ) {
1472 fprintf( stderr, "%s: line %d: "
1473 "unable to configure the \"rwm\" "
1474 "overlay, required by directive "
1476 fname, lineno, argv[0] );
1477 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1478 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1479 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1483 fprintf( stderr, "%s: line %d: back-ldap: "
1484 "automatically starting \"rwm\" overlay, "
1485 "triggered by \"%s\" directive.\n",
1486 fname, lineno, argv[ 0 ] );
1488 /* this is the default; we add it because the default might change... */
1489 li->rwm_started = 1;
1491 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1494 fprintf( stderr, "%s: line %d: "
1495 "rewrite/remap capabilities have been moved "
1496 "to the \"rwm\" overlay; see slapo-rwm(5) "
1497 "for details (hint: add \"overlay rwm\" "
1498 "and prefix all directives with \"rwm-\").\n",
1506 return SLAP_CONF_UNKNOWN;
1513 ldap_back_exop_whoami(
1517 struct berval *bv = NULL;
1519 if ( op->oq_extended.rs_reqdata != NULL ) {
1520 /* no request data should be provided */
1521 rs->sr_text = "no request data expected";
1522 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1525 rs->sr_err = backend_check_restrictions( op, rs,
1526 (struct berval *)&slap_EXOP_WHOAMI );
1527 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1529 /* if auth'd by back-ldap and request is proxied, forward it */
1530 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)) {
1531 struct ldapconn *lc;
1533 LDAPControl c, *ctrls[2] = {NULL, NULL};
1535 Operation op2 = *op;
1540 op2.o_ndn = op->o_conn->c_ndn;
1541 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1542 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1545 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1546 c.ldctl_iscritical = 1;
1547 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1548 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1549 strcpy(c.ldctl_value.bv_val, "dn:");
1550 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1553 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1554 if (rs->sr_err == LDAP_SUCCESS) {
1555 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1556 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1558 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1560 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1563 ldap_back_freeconn( op, lc );
1567 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1571 ch_free(c.ldctl_value.bv_val);
1572 if (rs->sr_err != LDAP_SUCCESS) {
1573 rs->sr_err = slap_map_api2result( rs );
1576 /* else just do the same as before */
1577 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1578 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1579 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
1580 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1581 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
1582 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
1584 bv->bv_val[bv->bv_len] = '\0';
1591 rs->sr_rspdata = bv;
1605 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1607 /* identity assertion mode */
1608 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1610 Debug( LDAP_DEBUG_ANY,
1611 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1612 fname, lineno, argc );
1616 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1617 /* will proxyAuthz as client's identity only if bound */
1618 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1620 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1621 /* will proxyAuthz as client's identity */
1622 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1624 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1625 /* will proxyAuthz as anonymous */
1626 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1628 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1629 /* will not proxyAuthz */
1630 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1636 /* will proxyAuthz as argv[1] */
1637 ber_str2bv( argv[1], 0, 0, &id );
1639 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1640 /* force lowercase... */
1642 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1643 ber_dupbv( &li->idassert_authzID, &id );
1648 /* default is DN? */
1649 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1650 id.bv_val += STRLENOF( "dn:" );
1651 id.bv_len -= STRLENOF( "dn:" );
1654 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1655 if ( rc != LDAP_SUCCESS ) {
1656 Debug( LDAP_DEBUG_ANY,
1657 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1658 fname, lineno, argv[1] );
1662 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1663 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1664 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1665 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1666 ch_free( dn.bv_val );
1668 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1672 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1673 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1674 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1677 Debug( LDAP_DEBUG_ANY,
1678 "%s: line %d: unknown flag \"%s\" "
1679 "in \"idassert-mode <args> "
1680 "[<flags>]\" line.\n",
1681 fname, lineno, argv[0] );
1686 /* name to use for proxyAuthz propagation */
1687 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1688 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1693 /* FIXME: "proxyauthzdn" is no longer documented, and
1694 * temporarily supported for backwards compatibility */
1698 "%s: line %d: missing name in \"%s <name>\" line\n",
1699 fname, lineno, argv[0] );
1703 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1704 fprintf( stderr, "%s: line %d: "
1705 "authcDN already defined; replacing...\n",
1707 ch_free( li->idassert_authcDN.bv_val );
1710 ber_str2bv( argv[1], 0, 0, &dn );
1711 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1712 if ( rc != LDAP_SUCCESS ) {
1713 Debug( LDAP_DEBUG_ANY,
1714 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1715 fname, lineno, argv[1] );
1719 /* password to use for proxyAuthz propagation */
1720 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1721 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1723 /* FIXME: "proxyauthzpw" is no longer documented, and
1724 * temporarily supported for backwards compatibility */
1728 "%s: line %d: missing password in \"%s <password>\" line\n",
1729 fname, lineno, argv[0] );
1733 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1734 fprintf( stderr, "%s: line %d: "
1735 "passwd already defined; replacing...\n",
1737 ch_free( li->idassert_passwd.bv_val );
1740 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1742 /* rules to accept identity assertion... */
1743 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1746 ber_str2bv( argv[1], 0, 1, &rule );
1748 ber_bvarray_add( &li->idassert_authz, &rule );
1750 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1755 "%s: line %d: missing method in \"%s <method>\" line\n",
1756 fname, lineno, argv[0] );
1761 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1762 argv1 += STRLENOF( "bindmethod=" );
1765 if ( strcasecmp( argv1, "none" ) == 0 ) {
1766 /* FIXME: is this at all useful? */
1767 li->idassert_authmethod = LDAP_AUTH_NONE;
1771 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1772 fname, lineno, argv[0], argv[1] );
1775 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1778 for ( arg = 2; arg < argc; arg++ ) {
1779 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1780 char *val = argv[arg] + STRLENOF( "authcdn=" );
1784 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1785 fprintf( stderr, "%s: line %d: "
1786 "SASL authcDN already defined; replacing...\n",
1788 ch_free( li->idassert_authcDN.bv_val );
1790 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1791 val += STRLENOF( "dn:" );
1794 ber_str2bv( val, 0, 0, &dn );
1795 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1796 if ( rc != LDAP_SUCCESS ) {
1797 Debug( LDAP_DEBUG_ANY,
1798 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1799 fname, lineno, val );
1803 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1804 char *val = argv[arg] + STRLENOF( "cred=" );
1806 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1807 fprintf( stderr, "%s: line %d: "
1808 "SASL cred already defined; replacing...\n",
1810 ch_free( li->idassert_passwd.bv_val );
1812 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1815 fprintf( stderr, "%s: line %d: "
1816 "unknown parameter %s\n",
1817 fname, lineno, argv[arg] );
1822 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1824 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1825 #ifdef HAVE_CYRUS_SASL
1828 for ( arg = 2; arg < argc; arg++ ) {
1829 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1830 char *val = argv[arg] + STRLENOF( "mech=" );
1832 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1833 fprintf( stderr, "%s: line %d: "
1834 "SASL mech already defined; replacing...\n",
1836 ch_free( li->idassert_sasl_mech.bv_val );
1838 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1840 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1841 char *val = argv[arg] + STRLENOF( "realm=" );
1843 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1844 fprintf( stderr, "%s: line %d: "
1845 "SASL realm already defined; replacing...\n",
1847 ch_free( li->idassert_sasl_realm.bv_val );
1849 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1851 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1852 char *val = argv[arg] + STRLENOF( "authcdn=" );
1856 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1857 fprintf( stderr, "%s: line %d: "
1858 "SASL authcDN already defined; replacing...\n",
1860 ch_free( li->idassert_authcDN.bv_val );
1862 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1863 val += STRLENOF( "dn:" );
1866 ber_str2bv( val, 0, 0, &dn );
1867 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1868 if ( rc != LDAP_SUCCESS ) {
1869 Debug( LDAP_DEBUG_ANY,
1870 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1871 fname, lineno, val );
1875 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1876 char *val = argv[arg] + STRLENOF( "authcid=" );
1878 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1879 fprintf( stderr, "%s: line %d: "
1880 "SASL authcID already defined; replacing...\n",
1882 ch_free( li->idassert_authcID.bv_val );
1884 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1885 val += STRLENOF( "u:" );
1887 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1889 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1890 char *val = argv[arg] + STRLENOF( "cred=" );
1892 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1893 fprintf( stderr, "%s: line %d: "
1894 "SASL cred already defined; replacing...\n",
1896 ch_free( li->idassert_passwd.bv_val );
1898 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1900 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1901 char *val = argv[arg] + STRLENOF( "authz=" );
1903 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1904 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1906 } else if ( strcasecmp( val, "native" ) == 0 ) {
1907 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1910 fprintf( stderr, "%s: line %d: "
1911 "unknown authz mode \"%s\"\n",
1912 fname, lineno, val );
1917 fprintf( stderr, "%s: line %d: "
1918 "unknown SASL parameter %s\n",
1919 fname, lineno, argv[arg] );
1924 li->idassert_authmethod = LDAP_AUTH_SASL;
1926 #else /* !HAVE_CYRUS_SASL */
1927 fprintf( stderr, "%s: line %d: "
1928 "compile --with-cyrus-sasl to enable SASL auth\n",
1931 #endif /* !HAVE_CYRUS_SASL */
1934 fprintf( stderr, "%s: line %d: "
1935 "unhandled idassert-method method %s\n",
1936 fname, lineno, argv[1] );
1941 return SLAP_CONF_UNKNOWN;
1956 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1958 /* name to use for remote ACL access */
1959 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
1960 || strcasecmp( argv[0], "binddn" ) == 0 )
1965 /* FIXME: "binddn" is no longer documented, and
1966 * temporarily supported for backwards compatibility */
1970 "%s: line %d: missing name in \"%s <name>\" line\n",
1971 fname, lineno, argv[0] );
1975 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
1976 fprintf( stderr, "%s: line %d: "
1977 "authcDN already defined; replacing...\n",
1979 ch_free( li->acl_authcDN.bv_val );
1982 ber_str2bv( argv[1], 0, 0, &dn );
1983 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
1984 if ( rc != LDAP_SUCCESS ) {
1985 Debug( LDAP_DEBUG_ANY,
1986 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
1987 fname, lineno, argv[1] );
1991 /* password to use for remote ACL access */
1992 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
1993 || strcasecmp( argv[0], "bindpw" ) == 0 )
1995 /* FIXME: "bindpw" is no longer documented, and
1996 * temporarily supported for backwards compatibility */
2000 "%s: line %d: missing password in \"%s <password>\" line\n",
2001 fname, lineno, argv[0] );
2005 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2006 fprintf( stderr, "%s: line %d: "
2007 "passwd already defined; replacing...\n",
2009 ch_free( li->acl_passwd.bv_val );
2012 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2014 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2019 "%s: line %d: missing method in \"%s <method>\" line\n",
2020 fname, lineno, argv[0] );
2025 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2026 argv1 += STRLENOF( "bindmethod=" );
2029 if ( strcasecmp( argv1, "none" ) == 0 ) {
2030 /* FIXME: is this at all useful? */
2031 li->acl_authmethod = LDAP_AUTH_NONE;
2035 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2036 fname, lineno, argv[0], argv[1] );
2039 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2040 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2044 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2045 fname, lineno, argv[0], argv[1] );
2048 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2049 #ifdef HAVE_CYRUS_SASL
2052 for ( arg = 2; arg < argc; arg++ ) {
2053 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2054 char *val = argv[arg] + STRLENOF( "mech=" );
2056 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2057 fprintf( stderr, "%s: line %d: "
2058 "SASL mech already defined; replacing...\n",
2060 ch_free( li->acl_sasl_mech.bv_val );
2062 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2064 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2065 char *val = argv[arg] + STRLENOF( "realm=" );
2067 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2068 fprintf( stderr, "%s: line %d: "
2069 "SASL realm already defined; replacing...\n",
2071 ch_free( li->acl_sasl_realm.bv_val );
2073 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2075 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2076 char *val = argv[arg] + STRLENOF( "authcdn=" );
2080 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2081 fprintf( stderr, "%s: line %d: "
2082 "SASL authcDN already defined; replacing...\n",
2084 ch_free( li->acl_authcDN.bv_val );
2086 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2087 val += STRLENOF( "dn:" );
2090 ber_str2bv( val, 0, 0, &dn );
2091 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2092 if ( rc != LDAP_SUCCESS ) {
2093 Debug( LDAP_DEBUG_ANY,
2094 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2095 fname, lineno, val );
2099 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2100 char *val = argv[arg] + STRLENOF( "authcid=" );
2102 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2103 fprintf( stderr, "%s: line %d: "
2104 "SASL authcID already defined; replacing...\n",
2106 ch_free( li->acl_authcID.bv_val );
2108 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2109 val += STRLENOF( "u:" );
2111 ber_str2bv( val, 0, 1, &li->acl_authcID );
2113 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2114 char *val = argv[arg] + STRLENOF( "cred=" );
2116 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2117 fprintf( stderr, "%s: line %d: "
2118 "SASL cred already defined; replacing...\n",
2120 ch_free( li->acl_passwd.bv_val );
2122 ber_str2bv( val, 0, 1, &li->acl_passwd );
2125 fprintf( stderr, "%s: line %d: "
2126 "unknown SASL parameter %s\n",
2127 fname, lineno, argv[arg] );
2132 li->acl_authmethod = LDAP_AUTH_SASL;
2134 #else /* !HAVE_CYRUS_SASL */
2135 fprintf( stderr, "%s: line %d: "
2136 "compile --with-cyrus-sasl to enable SASL auth\n",
2139 #endif /* !HAVE_CYRUS_SASL */
2142 fprintf( stderr, "%s: line %d: "
2143 "unhandled acl-method method %s\n",
2144 fname, lineno, argv[1] );
2149 return SLAP_CONF_UNKNOWN;