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 );
536 case LDAP_BACK_CFG_TLS:
537 case LDAP_BACK_CFG_ACL_AUTHCDN:
538 case LDAP_BACK_CFG_ACL_PASSWD:
539 case LDAP_BACK_CFG_ACL_METHOD:
540 /* handled by LDAP_BACK_CFG_ACL_BIND */
544 case LDAP_BACK_CFG_ACL_BIND:
545 bindconf_free( &li->acl_sb );
548 case LDAP_BACK_CFG_IDASSERT_MODE:
549 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
550 case LDAP_BACK_CFG_IDASSERT_PASSWD:
551 case LDAP_BACK_CFG_IDASSERT_METHOD:
552 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
556 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
557 if ( li->idassert_authz != NULL ) {
558 ber_bvarray_free( li->idassert_authz );
559 li->idassert_authz = NULL;
563 case LDAP_BACK_CFG_IDASSERT_BIND:
564 bindconf_free( &li->idassert_sb );
567 case LDAP_BACK_CFG_REBIND:
568 case LDAP_BACK_CFG_CHASE:
569 case LDAP_BACK_CFG_T_F:
570 case LDAP_BACK_CFG_WHOAMI:
575 /* we need to handle all... */
584 case LDAP_BACK_CFG_URI: {
585 LDAPURLDesc *tmpludp;
589 if ( c->argc != 2 ) {
590 fprintf( stderr, "%s: line %d: "
592 "in \"uri <uri>\" line\n",
593 c->fname, c->lineno );
597 if ( li->url != NULL ) {
601 if ( li->lud != NULL ) {
602 ldap_free_urllist( li->lud );
606 /* PARANOID: DN and more are not required nor allowed */
607 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
609 urlrc = ldap_url_parselist( &li->lud, c->value_string );
611 if ( urlrc != LDAP_URL_SUCCESS ) {
615 case LDAP_URL_ERR_MEM:
618 case LDAP_URL_ERR_PARAM:
619 why = "parameter is bad";
621 case LDAP_URL_ERR_BADSCHEME:
622 why = "URL doesn't begin with \"[c]ldap[si]://\"";
624 case LDAP_URL_ERR_BADENCLOSURE:
625 why = "URL is missing trailing \">\"";
627 case LDAP_URL_ERR_BADURL:
629 case LDAP_URL_ERR_BADHOST:
630 why = "host/port is bad";
632 case LDAP_URL_ERR_BADATTRS:
633 why = "bad (or missing) attributes";
635 case LDAP_URL_ERR_BADSCOPE:
636 why = "scope string is invalid (or missing)";
638 case LDAP_URL_ERR_BADFILTER:
639 why = "bad or missing filter";
641 case LDAP_URL_ERR_BADEXTS:
642 why = "bad or missing extensions";
645 why = "unknown reason";
648 fprintf( stderr, "%s: line %d: "
649 "unable to parse uri \"%s\" "
650 "in \"uri <uri>\" line: %s\n",
651 c->fname, c->lineno, c->value_string, why );
655 for ( i = 0, tmpludp = li->lud;
657 i++, tmpludp = tmpludp->lud_next )
659 if ( ( tmpludp->lud_dn != NULL
660 && tmpludp->lud_dn[0] != '\0' )
661 || tmpludp->lud_attrs != NULL
662 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
663 || tmpludp->lud_filter != NULL
664 || tmpludp->lud_exts != NULL )
666 fprintf( stderr, "%s: line %d: "
667 "warning, only protocol, "
668 "host and port allowed "
669 "in \"uri <uri>\" statement "
670 "for uri #%d of \"%s\"\n",
671 c->fname, c->lineno, i, c->value_string );
676 for ( i = 0, tmpludp = li->lud;
678 i++, tmpludp = tmpludp->lud_next )
681 urllist = ch_calloc( sizeof( char * ), i + 1 );
683 for ( i = 0, tmpludp = li->lud;
685 i++, tmpludp = tmpludp->lud_next )
688 ber_len_t oldlen = 0, len;
692 tmplud.lud_attrs = NULL;
693 tmplud.lud_filter = NULL;
694 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
695 tmplud.lud_exts = NULL;
696 tmplud.lud_crit_exts = 0;
699 urllist[ i ] = ldap_url_desc2str( &tmplud );
701 if ( urllist[ i ] == NULL ) {
702 fprintf( stderr, "%s: line %d: "
703 "unable to rebuild uri "
704 "in \"uri <uri>\" statement "
706 c->fname, c->lineno, argv[ 1 ] );
711 li->url = ldap_charray2str( urllist, " " );
712 ldap_charray_free( urllist );
714 li->url = ch_strdup( c->value_string );
719 case LDAP_BACK_CFG_TLS:
720 i = verb_to_mask( c->argv[1], tls_mode );
721 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
724 li->flags &= ~LDAP_BACK_F_TLS_MASK;
725 li->flags |= tls_mode[i].mask;
728 case LDAP_BACK_CFG_ACL_AUTHCDN:
729 switch ( li->acl_authmethod ) {
731 li->acl_authmethod = LDAP_AUTH_SIMPLE;
734 case LDAP_AUTH_SIMPLE:
738 fprintf( stderr, "%s: line %d: "
739 "\"acl-authcDN <DN>\" incompatible "
740 "with auth method %d.",
741 c->fname, c->lineno, li->acl_authmethod );
744 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
745 free( li->acl_authcDN.bv_val );
747 li->acl_authcDN = c->value_ndn;
750 case LDAP_BACK_CFG_ACL_PASSWD:
751 switch ( li->acl_authmethod ) {
753 li->acl_authmethod = LDAP_AUTH_SIMPLE;
756 case LDAP_AUTH_SIMPLE:
760 fprintf( stderr, "%s: line %d: "
761 "\"acl-passwd <cred>\" incompatible "
762 "with auth method %d.",
763 c->fname, c->lineno, li->acl_authmethod );
766 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
767 free( li->acl_passwd.bv_val );
769 li->acl_passwd = c->value_bv;
772 case LDAP_BACK_CFG_ACL_METHOD:
773 case LDAP_BACK_CFG_ACL_BIND:
774 for ( i = 1; i < c->argc; i++ ) {
775 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
781 case LDAP_BACK_CFG_IDASSERT_MODE:
782 i = verb_to_mask( c->argv[1], idassert_mode );
783 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
784 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
785 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
786 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
787 li->idassert_authzID.bv_val[ 0 ] = 'u';
790 struct berval id, ndn;
792 ber_str2bv( c->argv[1], 0, 0, &id );
794 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
795 id.bv_val += STRLENOF( "dn:" );
796 id.bv_len -= STRLENOF( "dn:" );
799 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
800 if ( rc != LDAP_SUCCESS ) {
801 Debug( LDAP_DEBUG_ANY,
802 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
803 c->fname, c->lineno, c->argv[1] );
807 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
808 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
809 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
810 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
811 ch_free( ndn.bv_val );
813 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
817 li->idassert_mode = idassert_mode[i].mask;
823 for ( i = 2; i < c->argc; i++ ) {
824 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
825 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
828 Debug( LDAP_DEBUG_ANY,
829 "%s: line %d: unknown flag #%d "
830 "in \"idassert-mode <args> "
831 "[<flags>]\" line.\n",
832 c->fname, c->lineno, i - 2 );
839 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
840 switch ( li->idassert_authmethod ) {
842 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
845 case LDAP_AUTH_SIMPLE:
849 fprintf( stderr, "%s: line %d: "
850 "\"idassert-authcDN <DN>\" incompatible "
851 "with auth method %d.",
852 c->fname, c->lineno, li->idassert_authmethod );
855 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
856 free( li->idassert_authcDN.bv_val );
858 li->idassert_authcDN = c->value_ndn;
861 case LDAP_BACK_CFG_IDASSERT_PASSWD:
862 switch ( li->idassert_authmethod ) {
864 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
867 case LDAP_AUTH_SIMPLE:
871 fprintf( stderr, "%s: line %d: "
872 "\"idassert-passwd <cred>\" incompatible "
873 "with auth method %d.",
874 c->fname, c->lineno, li->idassert_authmethod );
877 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
878 free( li->idassert_passwd.bv_val );
880 li->idassert_passwd = c->value_bv;
883 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
884 ber_bvarray_add( &li->idassert_authz, &c->value_bv );
887 case LDAP_BACK_CFG_IDASSERT_METHOD:
888 /* no longer supported */
889 fprintf( stderr, "%s: %d: "
890 "\"idassert-method <args>\": "
891 "no longer supported; use \"idassert-bind\".\n",
892 c->fname, c->lineno );
895 case LDAP_BACK_CFG_IDASSERT_BIND:
896 for ( i = 1; i < c->argc; i++ ) {
897 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
898 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
901 j = verb_to_mask( argvi, idassert_mode );
902 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
903 fprintf( stderr, "%s: %d: "
904 "\"idassert-bind <args>\": "
905 "unknown mode \"%s\".\n",
906 c->fname, c->lineno, argvi );
910 li->idassert_mode = idassert_mode[ j ].mask;
912 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
913 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
915 if ( strcasecmp( argvi, "native" ) == 0 ) {
916 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
917 fprintf( stderr, "%s: %d: "
918 "\"idassert-bind <args>\": "
919 "authz=\"native\" incompatible "
920 "with auth method.\n",
921 c->fname, c->lineno );
924 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
926 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
927 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
930 fprintf( stderr, "%s: %d: "
931 "\"idassert-bind <args>\": "
932 "unknown authz \"%s\".\n",
933 c->fname, c->lineno, argvi );
937 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
938 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
939 char **flags = ldap_str2charray( argvi, "," );
942 if ( flags == NULL ) {
943 fprintf( stderr, "%s: %d: "
944 "\"idassert-bind <args>\": "
945 "unable to parse flags \"%s\".\n",
946 c->fname, c->lineno, argvi );
950 for ( j = 0; flags[ j ] != NULL; j++ ) {
951 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
952 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
955 fprintf( stderr, "%s: %d: "
956 "\"idassert-bind <args>\": "
957 "unknown flag \"%s\".\n",
958 c->fname, c->lineno, flags[ j ] );
963 ldap_charray_free( flags );
965 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
971 case LDAP_BACK_CFG_REBIND: {
974 if ( c->argc == 1 ) {
979 i = verb_to_mask( c->argv[1], yn_mode );
980 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
983 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
989 li->flags |= LDAP_BACK_F_SAVECRED;
992 li->flags &= ~LDAP_BACK_F_SAVECRED;
997 case LDAP_BACK_CFG_CHASE: {
1000 if ( c->argc == 1 ) {
1005 i = verb_to_mask( c->argv[1], yn_mode );
1006 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1009 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1015 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1018 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1023 case LDAP_BACK_CFG_T_F:
1024 i = verb_to_mask( c->argv[1], t_f_mode );
1025 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1028 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1029 li->flags |= t_f_mode[i].mask;
1032 case LDAP_BACK_CFG_WHOAMI: {
1035 if ( c->argc == 1 ) {
1040 i = verb_to_mask( c->argv[1], yn_mode );
1041 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1044 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1050 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1052 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1053 0, ldap_back_exop_whoami );
1056 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1061 case LDAP_BACK_CFG_REWRITE:
1062 fprintf( stderr, "%s: line %d: "
1063 "rewrite/remap capabilities have been moved "
1064 "to the \"rwm\" overlay; see slapo-rwm(5) "
1065 "for details (hint: add \"overlay rwm\" "
1066 "and prefix all directives with \"rwm-\").\n",
1067 c->fname, c->lineno );
1078 ldap_back_init_cf( BackendInfo *bi )
1081 AttributeDescription *ad = NULL;
1084 bi->bi_cf_ocs = ldapocs;
1086 rc = config_register_schema( ldapcfg, ldapocs );
1091 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1092 * to be base64-encoded when written in LDIF form;
1093 * basically, we don't care if it fails */
1094 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1096 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1097 "warning, unable to get \"olcDbACLPasswd\" "
1098 "attribute description: %d: %s\n",
1101 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1102 ad->ad_type->sat_oid );
1106 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1108 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1109 "warning, unable to get \"olcDbIDAssertPasswd\" "
1110 "attribute description: %d: %s\n",
1113 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1114 ad->ad_type->sat_oid );
1122 parse_idassert( BackendDB *be, const char *fname, int lineno,
1123 int argc, char **argv );
1126 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1127 int argc, char **argv );
1130 ldap_back_db_config(
1137 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1140 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1145 /* server address to query (no longer supported, use "uri" directive) */
1146 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1148 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1152 /* URI of server to query (obsoletes "server" directive) */
1153 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1154 LDAPURLDesc *tmpludp;
1159 fprintf( stderr, "%s: line %d: "
1161 "in \"uri <uri>\" line\n",
1165 if ( li->url != NULL ) {
1168 if ( li->lud != NULL ) {
1169 ldap_free_urllist( li->lud );
1173 /* PARANOID: DN and more are not required nor allowed */
1174 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1176 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1178 if ( urlrc != LDAP_URL_SUCCESS ) {
1182 case LDAP_URL_ERR_MEM:
1185 case LDAP_URL_ERR_PARAM:
1186 why = "parameter is bad";
1188 case LDAP_URL_ERR_BADSCHEME:
1189 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1191 case LDAP_URL_ERR_BADENCLOSURE:
1192 why = "URL is missing trailing \">\"";
1194 case LDAP_URL_ERR_BADURL:
1196 case LDAP_URL_ERR_BADHOST:
1197 why = "host/port is bad";
1199 case LDAP_URL_ERR_BADATTRS:
1200 why = "bad (or missing) attributes";
1202 case LDAP_URL_ERR_BADSCOPE:
1203 why = "scope string is invalid (or missing)";
1205 case LDAP_URL_ERR_BADFILTER:
1206 why = "bad or missing filter";
1208 case LDAP_URL_ERR_BADEXTS:
1209 why = "bad or missing extensions";
1212 why = "unknown reason";
1215 fprintf( stderr, "%s: line %d: "
1216 "unable to parse uri \"%s\" "
1217 "in \"uri <uri>\" line: %s\n",
1218 fname, lineno, argv[ 1 ], why );
1222 for ( i = 0, tmpludp = li->lud;
1224 i++, tmpludp = tmpludp->lud_next )
1226 if ( ( tmpludp->lud_dn != NULL
1227 && tmpludp->lud_dn[0] != '\0' )
1228 || tmpludp->lud_attrs != NULL
1229 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1230 || tmpludp->lud_filter != NULL
1231 || tmpludp->lud_exts != NULL )
1233 fprintf( stderr, "%s: line %d: "
1234 "warning, only protocol, "
1235 "host and port allowed "
1236 "in \"uri <uri>\" statement "
1237 "for uri #%d of \"%s\"\n",
1238 fname, lineno, i, argv[1] );
1243 for ( i = 0, tmpludp = li->lud;
1245 i++, tmpludp = tmpludp->lud_next )
1248 urllist = ch_calloc( sizeof( char * ), i + 1 );
1250 for ( i = 0, tmpludp = li->lud;
1252 i++, tmpludp = tmpludp->lud_next )
1255 ber_len_t oldlen = 0, len;
1259 tmplud.lud_attrs = NULL;
1260 tmplud.lud_filter = NULL;
1261 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1262 tmplud.lud_exts = NULL;
1263 tmplud.lud_crit_exts = 0;
1266 urllist[ i ] = ldap_url_desc2str( &tmplud );
1268 if ( urllist[ i ] == NULL ) {
1269 fprintf( stderr, "%s: line %d: "
1270 "unable to rebuild uri "
1271 "in \"uri <uri>\" statement "
1273 fname, lineno, argv[ 1 ] );
1278 li->url = ldap_charray2str( urllist, " " );
1279 ldap_charray_free( urllist );
1281 li->url = ch_strdup( argv[ 1 ] );
1284 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1287 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1293 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1294 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1297 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1298 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1301 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1302 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1303 li->flags |= LDAP_BACK_F_USE_TLS;
1305 /* propagate start tls */
1306 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1307 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1310 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1311 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1312 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1316 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1317 fname, lineno, argv[1] );
1321 /* remote ACL stuff... */
1322 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1323 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1325 /* NOTE: "bind{DN,pw}" was initially used; it's now
1326 * deprected and undocumented, it can be dropped at some
1327 * point, since nobody should be really using it */
1328 return parse_acl_auth( be, fname, lineno, argc, argv );
1330 /* identity assertion stuff... */
1331 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1332 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1334 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1335 * deprected and undocumented, it can be dropped at some
1336 * point, since nobody should be really using it */
1337 return parse_idassert( be, fname, lineno, argc, argv );
1339 /* save bind creds for referral rebinds? */
1340 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1344 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1347 li->flags |= LDAP_BACK_F_SAVECRED;
1351 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1352 li->flags |= LDAP_BACK_F_SAVECRED;
1354 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1355 li->flags &= ~LDAP_BACK_F_SAVECRED;
1359 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1360 fname, lineno, argv[ 1 ] );
1367 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1372 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1375 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1380 /* this is the default; we add it because the default might change... */
1381 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1382 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1384 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1385 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1389 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1390 fname, lineno, argv[1] );
1394 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1397 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1402 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1403 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1405 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1406 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1408 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1409 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1413 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1414 fname, lineno, argv[ 1 ] );
1418 /* intercept exop_who_am_i? */
1419 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1420 int doload_extop = 0;
1425 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1432 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1435 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1437 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1438 fname, lineno, argv[ 1 ] );
1445 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1450 if ( doload_extop ) {
1451 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1453 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1454 0, ldap_back_exop_whoami );
1457 /* FIXME: legacy: intercept old rewrite/remap directives
1458 * and try to start the rwm overlay */
1459 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1460 || strcasecmp( argv[0], "map" ) == 0
1461 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1464 fprintf( stderr, "%s: line %d: "
1465 "rewrite/remap capabilities have been moved "
1466 "to the \"rwm\" overlay; see slapo-rwm(5) "
1467 "for details. I'm trying to do my best "
1468 "to preserve backwards compatibility...\n",
1471 if ( li->rwm_started == 0 ) {
1472 if ( overlay_config( be, "rwm" ) ) {
1473 fprintf( stderr, "%s: line %d: "
1474 "unable to configure the \"rwm\" "
1475 "overlay, required by directive "
1477 fname, lineno, argv[0] );
1478 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1479 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1480 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1484 fprintf( stderr, "%s: line %d: back-ldap: "
1485 "automatically starting \"rwm\" overlay, "
1486 "triggered by \"%s\" directive.\n",
1487 fname, lineno, argv[ 0 ] );
1489 /* this is the default; we add it because the default might change... */
1490 li->rwm_started = 1;
1492 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1495 fprintf( stderr, "%s: line %d: "
1496 "rewrite/remap capabilities have been moved "
1497 "to the \"rwm\" overlay; see slapo-rwm(5) "
1498 "for details (hint: add \"overlay rwm\" "
1499 "and prefix all directives with \"rwm-\").\n",
1507 return SLAP_CONF_UNKNOWN;
1514 ldap_back_exop_whoami(
1518 struct berval *bv = NULL;
1520 if ( op->oq_extended.rs_reqdata != NULL ) {
1521 /* no request data should be provided */
1522 rs->sr_text = "no request data expected";
1523 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1526 rs->sr_err = backend_check_restrictions( op, rs,
1527 (struct berval *)&slap_EXOP_WHOAMI );
1528 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1530 /* if auth'd by back-ldap and request is proxied, forward it */
1531 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)) {
1532 struct ldapconn *lc;
1534 LDAPControl c, *ctrls[2] = {NULL, NULL};
1536 Operation op2 = *op;
1541 op2.o_ndn = op->o_conn->c_ndn;
1542 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1543 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1546 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1547 c.ldctl_iscritical = 1;
1548 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1549 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1550 strcpy(c.ldctl_value.bv_val, "dn:");
1551 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1554 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1555 if (rs->sr_err == LDAP_SUCCESS) {
1556 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1557 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1559 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1561 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1564 ldap_back_freeconn( op, lc );
1568 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1572 ch_free(c.ldctl_value.bv_val);
1573 if (rs->sr_err != LDAP_SUCCESS) {
1574 rs->sr_err = slap_map_api2result( rs );
1578 ldap_back_release_conn( &op2, rs, lc );
1582 /* else just do the same as before */
1583 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1584 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1585 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
1586 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1587 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
1588 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
1590 bv->bv_val[bv->bv_len] = '\0';
1597 rs->sr_rspdata = bv;
1611 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1613 /* identity assertion mode */
1614 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1616 Debug( LDAP_DEBUG_ANY,
1617 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1618 fname, lineno, argc );
1622 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1623 /* will proxyAuthz as client's identity only if bound */
1624 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1626 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1627 /* will proxyAuthz as client's identity */
1628 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1630 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1631 /* will proxyAuthz as anonymous */
1632 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1634 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1635 /* will not proxyAuthz */
1636 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1642 /* will proxyAuthz as argv[1] */
1643 ber_str2bv( argv[1], 0, 0, &id );
1645 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1646 /* force lowercase... */
1648 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1649 ber_dupbv( &li->idassert_authzID, &id );
1654 /* default is DN? */
1655 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1656 id.bv_val += STRLENOF( "dn:" );
1657 id.bv_len -= STRLENOF( "dn:" );
1660 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1661 if ( rc != LDAP_SUCCESS ) {
1662 Debug( LDAP_DEBUG_ANY,
1663 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1664 fname, lineno, argv[1] );
1668 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1669 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1670 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1671 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1672 ch_free( dn.bv_val );
1674 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1678 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1679 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1680 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1683 Debug( LDAP_DEBUG_ANY,
1684 "%s: line %d: unknown flag \"%s\" "
1685 "in \"idassert-mode <args> "
1686 "[<flags>]\" line.\n",
1687 fname, lineno, argv[0] );
1692 /* name to use for proxyAuthz propagation */
1693 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1694 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1699 /* FIXME: "proxyauthzdn" is no longer documented, and
1700 * temporarily supported for backwards compatibility */
1704 "%s: line %d: missing name in \"%s <name>\" line\n",
1705 fname, lineno, argv[0] );
1709 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1710 fprintf( stderr, "%s: line %d: "
1711 "authcDN already defined; replacing...\n",
1713 ch_free( li->idassert_authcDN.bv_val );
1716 ber_str2bv( argv[1], 0, 0, &dn );
1717 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1718 if ( rc != LDAP_SUCCESS ) {
1719 Debug( LDAP_DEBUG_ANY,
1720 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1721 fname, lineno, argv[1] );
1725 /* password to use for proxyAuthz propagation */
1726 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1727 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1729 /* FIXME: "proxyauthzpw" is no longer documented, and
1730 * temporarily supported for backwards compatibility */
1734 "%s: line %d: missing password in \"%s <password>\" line\n",
1735 fname, lineno, argv[0] );
1739 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1740 fprintf( stderr, "%s: line %d: "
1741 "passwd already defined; replacing...\n",
1743 ch_free( li->idassert_passwd.bv_val );
1746 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1748 /* rules to accept identity assertion... */
1749 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1752 ber_str2bv( argv[1], 0, 1, &rule );
1754 ber_bvarray_add( &li->idassert_authz, &rule );
1756 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1761 "%s: line %d: missing method in \"%s <method>\" line\n",
1762 fname, lineno, argv[0] );
1767 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1768 argv1 += STRLENOF( "bindmethod=" );
1771 if ( strcasecmp( argv1, "none" ) == 0 ) {
1772 /* FIXME: is this at all useful? */
1773 li->idassert_authmethod = LDAP_AUTH_NONE;
1777 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1778 fname, lineno, argv[0], argv[1] );
1781 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1784 for ( arg = 2; arg < argc; arg++ ) {
1785 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1786 char *val = argv[arg] + STRLENOF( "authcdn=" );
1790 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1791 fprintf( stderr, "%s: line %d: "
1792 "SASL authcDN already defined; replacing...\n",
1794 ch_free( li->idassert_authcDN.bv_val );
1796 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1797 val += STRLENOF( "dn:" );
1800 ber_str2bv( val, 0, 0, &dn );
1801 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1802 if ( rc != LDAP_SUCCESS ) {
1803 Debug( LDAP_DEBUG_ANY,
1804 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1805 fname, lineno, val );
1809 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1810 char *val = argv[arg] + STRLENOF( "cred=" );
1812 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1813 fprintf( stderr, "%s: line %d: "
1814 "SASL cred already defined; replacing...\n",
1816 ch_free( li->idassert_passwd.bv_val );
1818 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1821 fprintf( stderr, "%s: line %d: "
1822 "unknown parameter %s\n",
1823 fname, lineno, argv[arg] );
1828 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1830 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1831 #ifdef HAVE_CYRUS_SASL
1834 for ( arg = 2; arg < argc; arg++ ) {
1835 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1836 char *val = argv[arg] + STRLENOF( "mech=" );
1838 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1839 fprintf( stderr, "%s: line %d: "
1840 "SASL mech already defined; replacing...\n",
1842 ch_free( li->idassert_sasl_mech.bv_val );
1844 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1846 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1847 char *val = argv[arg] + STRLENOF( "realm=" );
1849 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1850 fprintf( stderr, "%s: line %d: "
1851 "SASL realm already defined; replacing...\n",
1853 ch_free( li->idassert_sasl_realm.bv_val );
1855 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1857 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1858 char *val = argv[arg] + STRLENOF( "authcdn=" );
1862 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1863 fprintf( stderr, "%s: line %d: "
1864 "SASL authcDN already defined; replacing...\n",
1866 ch_free( li->idassert_authcDN.bv_val );
1868 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1869 val += STRLENOF( "dn:" );
1872 ber_str2bv( val, 0, 0, &dn );
1873 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1874 if ( rc != LDAP_SUCCESS ) {
1875 Debug( LDAP_DEBUG_ANY,
1876 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1877 fname, lineno, val );
1881 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1882 char *val = argv[arg] + STRLENOF( "authcid=" );
1884 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1885 fprintf( stderr, "%s: line %d: "
1886 "SASL authcID already defined; replacing...\n",
1888 ch_free( li->idassert_authcID.bv_val );
1890 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1891 val += STRLENOF( "u:" );
1893 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1895 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1896 char *val = argv[arg] + STRLENOF( "cred=" );
1898 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1899 fprintf( stderr, "%s: line %d: "
1900 "SASL cred already defined; replacing...\n",
1902 ch_free( li->idassert_passwd.bv_val );
1904 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1906 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1907 char *val = argv[arg] + STRLENOF( "authz=" );
1909 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1910 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1912 } else if ( strcasecmp( val, "native" ) == 0 ) {
1913 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1916 fprintf( stderr, "%s: line %d: "
1917 "unknown authz mode \"%s\"\n",
1918 fname, lineno, val );
1923 fprintf( stderr, "%s: line %d: "
1924 "unknown SASL parameter %s\n",
1925 fname, lineno, argv[arg] );
1930 li->idassert_authmethod = LDAP_AUTH_SASL;
1932 #else /* !HAVE_CYRUS_SASL */
1933 fprintf( stderr, "%s: line %d: "
1934 "compile --with-cyrus-sasl to enable SASL auth\n",
1937 #endif /* !HAVE_CYRUS_SASL */
1940 fprintf( stderr, "%s: line %d: "
1941 "unhandled idassert-method method %s\n",
1942 fname, lineno, argv[1] );
1947 return SLAP_CONF_UNKNOWN;
1962 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1964 /* name to use for remote ACL access */
1965 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
1966 || strcasecmp( argv[0], "binddn" ) == 0 )
1971 /* FIXME: "binddn" is no longer documented, and
1972 * temporarily supported for backwards compatibility */
1976 "%s: line %d: missing name in \"%s <name>\" line\n",
1977 fname, lineno, argv[0] );
1981 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
1982 fprintf( stderr, "%s: line %d: "
1983 "authcDN already defined; replacing...\n",
1985 ch_free( li->acl_authcDN.bv_val );
1988 ber_str2bv( argv[1], 0, 0, &dn );
1989 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
1990 if ( rc != LDAP_SUCCESS ) {
1991 Debug( LDAP_DEBUG_ANY,
1992 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
1993 fname, lineno, argv[1] );
1997 /* password to use for remote ACL access */
1998 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
1999 || strcasecmp( argv[0], "bindpw" ) == 0 )
2001 /* FIXME: "bindpw" is no longer documented, and
2002 * temporarily supported for backwards compatibility */
2006 "%s: line %d: missing password in \"%s <password>\" line\n",
2007 fname, lineno, argv[0] );
2011 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2012 fprintf( stderr, "%s: line %d: "
2013 "passwd already defined; replacing...\n",
2015 ch_free( li->acl_passwd.bv_val );
2018 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2020 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2025 "%s: line %d: missing method in \"%s <method>\" line\n",
2026 fname, lineno, argv[0] );
2031 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2032 argv1 += STRLENOF( "bindmethod=" );
2035 if ( strcasecmp( argv1, "none" ) == 0 ) {
2036 /* FIXME: is this at all useful? */
2037 li->acl_authmethod = LDAP_AUTH_NONE;
2041 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2042 fname, lineno, argv[0], argv[1] );
2045 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2046 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2050 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2051 fname, lineno, argv[0], argv[1] );
2054 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2055 #ifdef HAVE_CYRUS_SASL
2058 for ( arg = 2; arg < argc; arg++ ) {
2059 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2060 char *val = argv[arg] + STRLENOF( "mech=" );
2062 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2063 fprintf( stderr, "%s: line %d: "
2064 "SASL mech already defined; replacing...\n",
2066 ch_free( li->acl_sasl_mech.bv_val );
2068 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2070 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2071 char *val = argv[arg] + STRLENOF( "realm=" );
2073 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2074 fprintf( stderr, "%s: line %d: "
2075 "SASL realm already defined; replacing...\n",
2077 ch_free( li->acl_sasl_realm.bv_val );
2079 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2081 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2082 char *val = argv[arg] + STRLENOF( "authcdn=" );
2086 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2087 fprintf( stderr, "%s: line %d: "
2088 "SASL authcDN already defined; replacing...\n",
2090 ch_free( li->acl_authcDN.bv_val );
2092 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2093 val += STRLENOF( "dn:" );
2096 ber_str2bv( val, 0, 0, &dn );
2097 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2098 if ( rc != LDAP_SUCCESS ) {
2099 Debug( LDAP_DEBUG_ANY,
2100 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2101 fname, lineno, val );
2105 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2106 char *val = argv[arg] + STRLENOF( "authcid=" );
2108 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2109 fprintf( stderr, "%s: line %d: "
2110 "SASL authcID already defined; replacing...\n",
2112 ch_free( li->acl_authcID.bv_val );
2114 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2115 val += STRLENOF( "u:" );
2117 ber_str2bv( val, 0, 1, &li->acl_authcID );
2119 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2120 char *val = argv[arg] + STRLENOF( "cred=" );
2122 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2123 fprintf( stderr, "%s: line %d: "
2124 "SASL cred already defined; replacing...\n",
2126 ch_free( li->acl_passwd.bv_val );
2128 ber_str2bv( val, 0, 1, &li->acl_passwd );
2131 fprintf( stderr, "%s: line %d: "
2132 "unknown SASL parameter %s\n",
2133 fname, lineno, argv[arg] );
2138 li->acl_authmethod = LDAP_AUTH_SASL;
2140 #else /* !HAVE_CYRUS_SASL */
2141 fprintf( stderr, "%s: line %d: "
2142 "compile --with-cyrus-sasl to enable SASL auth\n",
2145 #endif /* !HAVE_CYRUS_SASL */
2148 fprintf( stderr, "%s: line %d: "
2149 "unhandled acl-method method %s\n",
2150 fname, lineno, argv[1] );
2155 return SLAP_CONF_UNKNOWN;