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, will be removed; 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, will be removed; 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 /* deprecated, will be removed; aliases "acl-bind" */
109 { "acl-method", "args", 2, 0, 0,
110 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
111 ldap_back_cf_gen, NULL, NULL, NULL },
112 { "acl-bind", "args", 2, 0, 0,
113 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
114 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
115 "NAME 'olcDbACLBind' "
116 "DESC 'Remote ACL administrative identity auth bind configuration' "
117 "SYNTAX OMsDirectoryString "
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, will be removed; 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, will be removed; partially aliases "idassert-passwd" */
143 { "proxyauthzpw", "cred", 2, 2, 0,
144 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
145 ldap_back_cf_gen, NULL, NULL, NULL },
146 { "idassert-bind", "args", 2, 0, 0,
147 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
148 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
149 "NAME 'olcDbIDAssertBind' "
150 "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
151 "SYNTAX OMsDirectoryString "
154 { "idassert-method", "args", 2, 0, 0,
155 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
156 ldap_back_cf_gen, NULL, NULL, NULL },
157 { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
158 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
159 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
160 "NAME 'olcDbIDAssertMode' "
161 "DESC 'Remote Identity Assertion mode' "
163 "SYNTAX OMsDirectoryString "
166 { "idassert-authzFrom", "authzRule", 2, 2, 0,
167 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
168 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
169 "NAME 'olcDbIDAssertAuthzFrom' "
170 "DESC 'Remote Identity Assertion authz rules' "
171 "SYNTAX OMsDirectoryString "
172 "X-ORDERED 'VALUES' )",
174 { "rebind-as-user", "NO|yes", 1, 2, 0,
175 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_REBIND,
176 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
177 "NAME 'olcDbRebindAsUser' "
178 "DESC 'Rebind as user' "
179 "SYNTAX OMsDirectoryString "
182 { "chase-referrals", "YES|no", 2, 2, 0,
183 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_CHASE,
184 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
185 "NAME 'olcDbChaseReferrals' "
186 "DESC 'Chase referrals' "
187 "SYNTAX OMsDirectoryString "
190 { "t-f-support", "NO|yes|discover", 2, 2, 0,
191 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_T_F,
192 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
193 "NAME 'olcDbTFSupport' "
194 "DESC 'Absolute filters support' "
195 "SYNTAX OMsDirectoryString "
198 { "proxy-whoami", "NO|yes", 1, 2, 0,
199 ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_WHOAMI,
200 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
201 "NAME 'olcDbProxyWhoAmI' "
202 "DESC 'Proxy whoAmI exop' "
203 "SYNTAX OMsDirectoryString "
206 { "suffixmassage", "[virtual]> <real", 2, 3, 0,
207 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
208 ldap_back_cf_gen, NULL, NULL, NULL },
209 { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
210 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
211 ldap_back_cf_gen, NULL, NULL, NULL },
212 { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
213 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
214 ldap_back_cf_gen, NULL, NULL, NULL },
215 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
216 NULL, NULL, NULL, NULL }
219 static ConfigOCs ldapocs[] = {
221 "NAME 'olcLDAPConfig' "
222 "DESC 'LDAP backend configuration' "
223 "SUP olcDatabaseConfig "
225 "MAY ( olcDbStartTLS "
229 "$ olcDbIDAssertAuthcDn "
230 "$ olcDbIDAssertPasswd "
231 "$ olcDbIDAssertBind "
232 "$ olcDbIDAssertMode "
233 "$ olcDbIDAssertAuthzFrom "
234 "$ olcDbRebindAsUser "
235 "$ olcDbChaseReferrals "
237 "$ olcDbProxyWhoAmI "
239 Cft_Database, ldapcfg},
243 #define LDAP_BACK_C_NO (0x0U)
244 #define LDAP_BACK_C_YES (0x1U)
245 static slap_verbmasks yn_mode[] = {
246 { BER_BVC( "yes" ), LDAP_BACK_C_YES},
247 { BER_BVC( "no" ), LDAP_BACK_C_NO },
251 static slap_verbmasks idassert_mode[] = {
252 { BER_BVC("self"), LDAP_BACK_IDASSERT_SELF },
253 { BER_BVC("anonymous"), LDAP_BACK_IDASSERT_ANONYMOUS },
254 { BER_BVC("none"), LDAP_BACK_IDASSERT_NOASSERT },
255 { BER_BVC("legacy"), LDAP_BACK_IDASSERT_LEGACY },
259 static slap_verbmasks tls_mode[] = {
260 { BER_BVC( "propagate" ), LDAP_BACK_F_TLS_PROPAGATE_MASK },
261 { BER_BVC( "try-propagate" ), LDAP_BACK_F_PROPAGATE_TLS },
262 { BER_BVC( "start" ), LDAP_BACK_F_TLS_USE_MASK },
263 { BER_BVC( "try-start" ), LDAP_BACK_F_USE_TLS },
264 { BER_BVC( "none" ), LDAP_BACK_C_NO },
268 static slap_verbmasks t_f_mode[] = {
269 { BER_BVC( "yes" ), LDAP_BACK_F_SUPPORT_T_F },
270 { BER_BVC( "discover" ), LDAP_BACK_F_SUPPORT_T_F_DISCOVER },
271 { BER_BVC( "no" ), LDAP_BACK_C_NO },
276 ldap_back_cf_gen( ConfigArgs *c )
278 struct ldapinfo *li = ( struct ldapinfo * )c->be->be_private;
282 if ( c->op == SLAP_CONFIG_EMIT ) {
283 struct berval bv = BER_BVNULL;
287 case LDAP_BACK_CFG_URI:
288 if ( li->url != NULL ) {
289 c->value_string = ch_strdup( li->url );
296 case LDAP_BACK_CFG_TLS:
297 enum_to_verb( tls_mode, ( li->flags & LDAP_BACK_F_TLS_MASK ), &bv );
298 if ( BER_BVISNULL( &bv ) ) {
299 /* there's something wrong... */
308 case LDAP_BACK_CFG_ACL_AUTHCDN:
309 case LDAP_BACK_CFG_ACL_PASSWD:
310 case LDAP_BACK_CFG_ACL_METHOD:
311 /* handled by LDAP_BACK_CFG_ACL_BIND */
315 case LDAP_BACK_CFG_ACL_BIND: {
318 bindconf_unparse( &li->acl_sb, &bv );
320 for ( i = 0; isspace( bv.bv_val[ i ] ); i++ )
325 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
329 ber_bvarray_add( &c->rvalue_vals, &bv );
333 case LDAP_BACK_CFG_IDASSERT_MODE:
334 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
335 case LDAP_BACK_CFG_IDASSERT_PASSWD:
336 case LDAP_BACK_CFG_IDASSERT_METHOD:
337 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
341 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
344 if ( li->idassert_authz == NULL ) {
349 for ( i = 0; !BER_BVISNULL( &li->idassert_authz[ i ] ); i++ )
351 value_add_one( &c->rvalue_vals, &li->idassert_authz[ i ] );
356 case LDAP_BACK_CFG_IDASSERT_BIND: {
358 struct berval bc = BER_BVNULL;
361 if ( li->idassert_authmethod != LDAP_AUTH_NONE ) {
364 switch ( li->idassert_mode ) {
365 case LDAP_BACK_IDASSERT_OTHERID:
366 case LDAP_BACK_IDASSERT_OTHERDN:
370 struct berval mode = BER_BVNULL;
372 enum_to_verb( idassert_mode, li->idassert_mode, &mode );
373 if ( BER_BVISNULL( &mode ) ) {
374 /* there's something wrong... */
379 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
380 bv.bv_val = ch_malloc( bv.bv_len + 1 );
382 ptr = lutil_strcopy( bv.bv_val, "mode=" );
383 ptr = lutil_strcopy( ptr, mode.bv_val );
389 if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
390 len = bv.bv_len + STRLENOF( "authz=native" );
392 if ( !BER_BVISEMPTY( &bv ) ) {
393 len += STRLENOF( " " );
396 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
398 ptr = &bv.bv_val[ bv.bv_len ];
400 if ( !BER_BVISEMPTY( &bv ) ) {
401 ptr = lutil_strcopy( ptr, " " );
404 (void)lutil_strcopy( ptr, "authz=native" );
407 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override" );
409 if ( !BER_BVISEMPTY( &bv ) ) {
410 len += STRLENOF( " " );
413 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
415 ptr = &bv.bv_val[ bv.bv_len ];
417 if ( !BER_BVISEMPTY( &bv ) ) {
418 ptr = lutil_strcopy( ptr, " " );
421 ptr = lutil_strcopy( ptr, "flags=" );
423 if ( li->idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
424 ptr = lutil_strcopy( ptr, "prescriptive" );
426 ptr = lutil_strcopy( ptr, "non-prescriptive" );
429 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
430 ptr = lutil_strcopy( ptr, ",override" );
433 bv.bv_len = ( ptr - bv.bv_val );
437 bindconf_unparse( &li->idassert_sb, &bc );
439 if ( !BER_BVISNULL( &bv ) ) {
440 ber_len_t len = bv.bv_len + bc.bv_len;
442 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
444 assert( bc.bv_val[ 0 ] == ' ' );
446 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
448 bv.bv_len = ptr - bv.bv_val;
451 for ( i = 0; isspace( bc.bv_val[ i ] ); i++ )
456 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
462 ber_bvarray_add( &c->rvalue_vals, &bv );
467 case LDAP_BACK_CFG_REBIND:
468 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv );
469 if ( BER_BVISNULL( &bv ) ) {
470 /* there's something wrong... */
479 case LDAP_BACK_CFG_CHASE:
480 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv );
481 if ( BER_BVISNULL( &bv ) ) {
482 /* there's something wrong... */
491 case LDAP_BACK_CFG_T_F:
492 enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv );
493 if ( BER_BVISNULL( &bv ) ) {
494 /* there's something wrong... */
503 case LDAP_BACK_CFG_WHOAMI:
504 enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv );
505 if ( BER_BVISNULL( &bv ) ) {
506 /* there's something wrong... */
516 /* FIXME: we need to handle all... */
522 } else if ( c->op == LDAP_MOD_DELETE ) {
525 case LDAP_BACK_CFG_URI:
526 if ( li->url != NULL ) {
531 if ( li->lud != NULL ) {
532 ldap_free_urllist( li->lud );
536 /* better cleanup the cached connections... */
537 /* NOTE: don't worry about locking: if we got here,
538 * other threads are suspended. */
539 avl_free( li->conntree, ldap_back_conn_free );
544 case LDAP_BACK_CFG_TLS:
545 case LDAP_BACK_CFG_ACL_AUTHCDN:
546 case LDAP_BACK_CFG_ACL_PASSWD:
547 case LDAP_BACK_CFG_ACL_METHOD:
548 /* handled by LDAP_BACK_CFG_ACL_BIND */
552 case LDAP_BACK_CFG_ACL_BIND:
553 bindconf_free( &li->acl_sb );
556 case LDAP_BACK_CFG_IDASSERT_MODE:
557 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
558 case LDAP_BACK_CFG_IDASSERT_PASSWD:
559 case LDAP_BACK_CFG_IDASSERT_METHOD:
560 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
564 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
565 if ( li->idassert_authz != NULL ) {
566 ber_bvarray_free( li->idassert_authz );
567 li->idassert_authz = NULL;
571 case LDAP_BACK_CFG_IDASSERT_BIND:
572 bindconf_free( &li->idassert_sb );
575 case LDAP_BACK_CFG_REBIND:
576 case LDAP_BACK_CFG_CHASE:
577 case LDAP_BACK_CFG_T_F:
578 case LDAP_BACK_CFG_WHOAMI:
583 /* FIXME: we need to handle all... */
592 case LDAP_BACK_CFG_URI: {
593 LDAPURLDesc *tmpludp;
599 if ( c->argc != 2 ) {
600 fprintf( stderr, "%s: line %d: "
602 "in \"uri <uri>\" line\n",
603 c->fname, c->lineno );
607 if ( li->url != NULL ) {
611 if ( li->lud != NULL ) {
612 ldap_free_urllist( li->lud );
616 /* PARANOID: DN and more are not required nor allowed */
617 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
619 urlrc = ldap_url_parselist( &li->lud, c->value_string );
621 if ( urlrc != LDAP_URL_SUCCESS ) {
625 case LDAP_URL_ERR_MEM:
628 case LDAP_URL_ERR_PARAM:
629 why = "parameter is bad";
631 case LDAP_URL_ERR_BADSCHEME:
632 why = "URL doesn't begin with \"[c]ldap[si]://\"";
634 case LDAP_URL_ERR_BADENCLOSURE:
635 why = "URL is missing trailing \">\"";
637 case LDAP_URL_ERR_BADURL:
639 case LDAP_URL_ERR_BADHOST:
640 why = "host/port is bad";
642 case LDAP_URL_ERR_BADATTRS:
643 why = "bad (or missing) attributes";
645 case LDAP_URL_ERR_BADSCOPE:
646 why = "scope string is invalid (or missing)";
648 case LDAP_URL_ERR_BADFILTER:
649 why = "bad or missing filter";
651 case LDAP_URL_ERR_BADEXTS:
652 why = "bad or missing extensions";
655 why = "unknown reason";
658 fprintf( stderr, "%s: line %d: "
659 "unable to parse uri \"%s\" "
660 "in \"uri <uri>\" line: %s\n",
661 c->fname, c->lineno, c->value_string, why );
665 for ( i = 0, tmpludp = li->lud;
667 i++, tmpludp = tmpludp->lud_next )
669 if ( ( tmpludp->lud_dn != NULL
670 && tmpludp->lud_dn[0] != '\0' )
671 || tmpludp->lud_attrs != NULL
672 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
673 || tmpludp->lud_filter != NULL
674 || tmpludp->lud_exts != NULL )
676 fprintf( stderr, "%s: line %d: "
677 "warning, only protocol, "
678 "host and port allowed "
679 "in \"uri <uri>\" statement "
680 "for uri #%d of \"%s\"\n",
681 c->fname, c->lineno, i, c->value_string );
686 for ( i = 0, tmpludp = li->lud;
688 i++, tmpludp = tmpludp->lud_next )
691 urllist = ch_calloc( sizeof( char * ), i + 1 );
693 for ( i = 0, tmpludp = li->lud;
695 i++, tmpludp = tmpludp->lud_next )
698 ber_len_t oldlen = 0, len;
702 tmplud.lud_attrs = NULL;
703 tmplud.lud_filter = NULL;
704 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
705 tmplud.lud_exts = NULL;
706 tmplud.lud_crit_exts = 0;
709 urllist[ i ] = ldap_url_desc2str( &tmplud );
711 if ( urllist[ i ] == NULL ) {
712 fprintf( stderr, "%s: line %d: "
713 "unable to rebuild uri "
714 "in \"uri <uri>\" statement "
716 c->fname, c->lineno, argv[ 1 ] );
721 li->url = ldap_charray2str( urllist, " " );
722 ldap_charray_free( urllist );
724 li->url = c->value_string;
729 case LDAP_BACK_CFG_TLS:
730 i = verb_to_mask( c->argv[1], tls_mode );
731 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
734 li->flags &= ~LDAP_BACK_F_TLS_MASK;
735 li->flags |= tls_mode[i].mask;
738 case LDAP_BACK_CFG_ACL_AUTHCDN:
739 switch ( li->acl_authmethod ) {
741 li->acl_authmethod = LDAP_AUTH_SIMPLE;
744 case LDAP_AUTH_SIMPLE:
748 fprintf( stderr, "%s: line %d: "
749 "\"acl-authcDN <DN>\" incompatible "
750 "with auth method %d.",
751 c->fname, c->lineno, li->acl_authmethod );
754 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
755 free( li->acl_authcDN.bv_val );
757 li->acl_authcDN = c->value_ndn;
760 case LDAP_BACK_CFG_ACL_PASSWD:
761 switch ( li->acl_authmethod ) {
763 li->acl_authmethod = LDAP_AUTH_SIMPLE;
766 case LDAP_AUTH_SIMPLE:
770 fprintf( stderr, "%s: line %d: "
771 "\"acl-passwd <cred>\" incompatible "
772 "with auth method %d.",
773 c->fname, c->lineno, li->acl_authmethod );
776 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
777 free( li->acl_passwd.bv_val );
779 li->acl_passwd = c->value_bv;
782 case LDAP_BACK_CFG_ACL_METHOD:
783 case LDAP_BACK_CFG_ACL_BIND:
784 for ( i = 1; i < c->argc; i++ ) {
785 if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
791 case LDAP_BACK_CFG_IDASSERT_MODE:
792 i = verb_to_mask( c->argv[1], idassert_mode );
793 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
794 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
795 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
796 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
797 li->idassert_authzID.bv_val[ 0 ] = 'u';
800 struct berval id, ndn;
802 ber_str2bv( c->argv[1], 0, 0, &id );
804 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
805 id.bv_val += STRLENOF( "dn:" );
806 id.bv_len -= STRLENOF( "dn:" );
809 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
810 if ( rc != LDAP_SUCCESS ) {
811 Debug( LDAP_DEBUG_ANY,
812 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
813 c->fname, c->lineno, c->argv[1] );
817 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
818 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
819 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
820 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
821 ch_free( ndn.bv_val );
823 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
827 li->idassert_mode = idassert_mode[i].mask;
833 for ( i = 2; i < c->argc; i++ ) {
834 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
835 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
837 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
838 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
840 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
841 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
844 Debug( LDAP_DEBUG_ANY,
845 "%s: line %d: unknown flag #%d "
846 "in \"idassert-mode <args> "
847 "[<flags>]\" line.\n",
848 c->fname, c->lineno, i - 2 );
855 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
856 switch ( li->idassert_authmethod ) {
858 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
861 case LDAP_AUTH_SIMPLE:
865 fprintf( stderr, "%s: line %d: "
866 "\"idassert-authcDN <DN>\" incompatible "
867 "with auth method %d.",
868 c->fname, c->lineno, li->idassert_authmethod );
871 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
872 free( li->idassert_authcDN.bv_val );
874 li->idassert_authcDN = c->value_ndn;
877 case LDAP_BACK_CFG_IDASSERT_PASSWD:
878 switch ( li->idassert_authmethod ) {
880 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
883 case LDAP_AUTH_SIMPLE:
887 fprintf( stderr, "%s: line %d: "
888 "\"idassert-passwd <cred>\" incompatible "
889 "with auth method %d.",
890 c->fname, c->lineno, li->idassert_authmethod );
893 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
894 free( li->idassert_passwd.bv_val );
896 li->idassert_passwd = c->value_bv;
899 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
900 ber_bvarray_add( &li->idassert_authz, &c->value_bv );
903 case LDAP_BACK_CFG_IDASSERT_METHOD:
904 /* no longer supported */
905 fprintf( stderr, "%s: %d: "
906 "\"idassert-method <args>\": "
907 "no longer supported; use \"idassert-bind\".\n",
908 c->fname, c->lineno );
911 case LDAP_BACK_CFG_IDASSERT_BIND:
912 for ( i = 1; i < c->argc; i++ ) {
913 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
914 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
917 j = verb_to_mask( argvi, idassert_mode );
918 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
919 fprintf( stderr, "%s: %d: "
920 "\"idassert-bind <args>\": "
921 "unknown mode \"%s\".\n",
922 c->fname, c->lineno, argvi );
926 li->idassert_mode = idassert_mode[ j ].mask;
928 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
929 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
931 if ( strcasecmp( argvi, "native" ) == 0 ) {
932 if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
933 fprintf( stderr, "%s: %d: "
934 "\"idassert-bind <args>\": "
935 "authz=\"native\" incompatible "
936 "with auth method.\n",
937 c->fname, c->lineno );
940 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
942 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
943 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
946 fprintf( stderr, "%s: %d: "
947 "\"idassert-bind <args>\": "
948 "unknown authz \"%s\".\n",
949 c->fname, c->lineno, argvi );
953 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
954 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
955 char **flags = ldap_str2charray( argvi, "," );
958 if ( flags == NULL ) {
959 fprintf( stderr, "%s: %d: "
960 "\"idassert-bind <args>\": "
961 "unable to parse flags \"%s\".\n",
962 c->fname, c->lineno, argvi );
966 for ( j = 0; flags[ j ] != NULL; j++ ) {
967 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
968 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
970 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
971 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
973 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
974 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
977 fprintf( stderr, "%s: %d: "
978 "\"idassert-bind <args>\": "
979 "unknown flag \"%s\".\n",
980 c->fname, c->lineno, flags[ j ] );
985 ldap_charray_free( flags );
987 } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
993 case LDAP_BACK_CFG_REBIND: {
996 if ( c->argc == 1 ) {
1001 i = verb_to_mask( c->argv[1], yn_mode );
1002 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1005 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1011 li->flags |= LDAP_BACK_F_SAVECRED;
1014 li->flags &= ~LDAP_BACK_F_SAVECRED;
1019 case LDAP_BACK_CFG_CHASE: {
1022 if ( c->argc == 1 ) {
1027 i = verb_to_mask( c->argv[1], yn_mode );
1028 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1031 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1037 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1040 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1045 case LDAP_BACK_CFG_T_F:
1046 i = verb_to_mask( c->argv[1], t_f_mode );
1047 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1050 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1051 li->flags |= t_f_mode[i].mask;
1054 case LDAP_BACK_CFG_WHOAMI: {
1057 if ( c->argc == 1 ) {
1062 i = verb_to_mask( c->argv[1], yn_mode );
1063 if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1066 if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1072 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1074 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1075 0, ldap_back_exop_whoami );
1078 li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1083 case LDAP_BACK_CFG_REWRITE:
1084 fprintf( stderr, "%s: line %d: "
1085 "rewrite/remap capabilities have been moved "
1086 "to the \"rwm\" overlay; see slapo-rwm(5) "
1087 "for details (hint: add \"overlay rwm\" "
1088 "and prefix all directives with \"rwm-\").\n",
1089 c->fname, c->lineno );
1093 /* FIXME: try to catch inconsistencies */
1102 ldap_back_init_cf( BackendInfo *bi )
1105 AttributeDescription *ad = NULL;
1108 bi->bi_cf_ocs = ldapocs;
1110 rc = config_register_schema( ldapcfg, ldapocs );
1115 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1116 * to be base64-encoded when written in LDIF form;
1117 * basically, we don't care if it fails */
1118 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1120 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1121 "warning, unable to get \"olcDbACLPasswd\" "
1122 "attribute description: %d: %s\n",
1125 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1126 ad->ad_type->sat_oid );
1130 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1132 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1133 "warning, unable to get \"olcDbIDAssertPasswd\" "
1134 "attribute description: %d: %s\n",
1137 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1138 ad->ad_type->sat_oid );
1146 parse_idassert( BackendDB *be, const char *fname, int lineno,
1147 int argc, char **argv );
1150 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1151 int argc, char **argv );
1154 ldap_back_db_config(
1161 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1164 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1169 /* server address to query (no longer supported, use "uri" directive) */
1170 if ( strcasecmp( argv[0], "server" ) == 0 ) {
1172 "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1176 /* URI of server to query (obsoletes "server" directive) */
1177 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1178 LDAPURLDesc *tmpludp;
1185 fprintf( stderr, "%s: line %d: "
1187 "in \"uri <uri>\" line\n",
1191 if ( li->url != NULL ) {
1194 if ( li->lud != NULL ) {
1195 ldap_free_urllist( li->lud );
1199 /* PARANOID: DN and more are not required nor allowed */
1200 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1202 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1204 if ( urlrc != LDAP_URL_SUCCESS ) {
1208 case LDAP_URL_ERR_MEM:
1211 case LDAP_URL_ERR_PARAM:
1212 why = "parameter is bad";
1214 case LDAP_URL_ERR_BADSCHEME:
1215 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1217 case LDAP_URL_ERR_BADENCLOSURE:
1218 why = "URL is missing trailing \">\"";
1220 case LDAP_URL_ERR_BADURL:
1222 case LDAP_URL_ERR_BADHOST:
1223 why = "host/port is bad";
1225 case LDAP_URL_ERR_BADATTRS:
1226 why = "bad (or missing) attributes";
1228 case LDAP_URL_ERR_BADSCOPE:
1229 why = "scope string is invalid (or missing)";
1231 case LDAP_URL_ERR_BADFILTER:
1232 why = "bad or missing filter";
1234 case LDAP_URL_ERR_BADEXTS:
1235 why = "bad or missing extensions";
1238 why = "unknown reason";
1241 fprintf( stderr, "%s: line %d: "
1242 "unable to parse uri \"%s\" "
1243 "in \"uri <uri>\" line: %s\n",
1244 fname, lineno, argv[ 1 ], why );
1248 for ( i = 0, tmpludp = li->lud;
1250 i++, tmpludp = tmpludp->lud_next )
1252 if ( ( tmpludp->lud_dn != NULL
1253 && tmpludp->lud_dn[0] != '\0' )
1254 || tmpludp->lud_attrs != NULL
1255 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1256 || tmpludp->lud_filter != NULL
1257 || tmpludp->lud_exts != NULL )
1259 fprintf( stderr, "%s: line %d: "
1260 "warning, only protocol, "
1261 "host and port allowed "
1262 "in \"uri <uri>\" statement "
1263 "for uri #%d of \"%s\"\n",
1264 fname, lineno, i, argv[1] );
1269 for ( i = 0, tmpludp = li->lud;
1271 i++, tmpludp = tmpludp->lud_next )
1274 urllist = ch_calloc( sizeof( char * ), i + 1 );
1276 for ( i = 0, tmpludp = li->lud;
1278 i++, tmpludp = tmpludp->lud_next )
1281 ber_len_t oldlen = 0, len;
1285 tmplud.lud_attrs = NULL;
1286 tmplud.lud_filter = NULL;
1287 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1288 tmplud.lud_exts = NULL;
1289 tmplud.lud_crit_exts = 0;
1292 urllist[ i ] = ldap_url_desc2str( &tmplud );
1294 if ( urllist[ i ] == NULL ) {
1295 fprintf( stderr, "%s: line %d: "
1296 "unable to rebuild uri "
1297 "in \"uri <uri>\" statement "
1299 fname, lineno, argv[ 1 ] );
1304 li->url = ldap_charray2str( urllist, " " );
1305 ldap_charray_free( urllist );
1307 li->url = ch_strdup( argv[ 1 ] );
1310 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1313 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1319 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1320 li->flags &= ~LDAP_BACK_F_TLS_MASK;
1323 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1324 li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1327 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1328 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1329 li->flags |= LDAP_BACK_F_USE_TLS;
1331 /* propagate start tls */
1332 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1333 li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1336 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1337 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1338 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1342 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1343 fname, lineno, argv[1] );
1347 /* remote ACL stuff... */
1348 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1349 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1351 /* NOTE: "bind{DN,pw}" was initially used; it's now
1352 * deprected and undocumented, it can be dropped at some
1353 * point, since nobody should be really using it */
1354 return parse_acl_auth( be, fname, lineno, argc, argv );
1356 /* identity assertion stuff... */
1357 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1358 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1360 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1361 * deprected and undocumented, it can be dropped at some
1362 * point, since nobody should be really using it */
1363 return parse_idassert( be, fname, lineno, argc, argv );
1365 /* save bind creds for referral rebinds? */
1366 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1370 "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1373 li->flags |= LDAP_BACK_F_SAVECRED;
1377 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1378 li->flags |= LDAP_BACK_F_SAVECRED;
1380 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1381 li->flags &= ~LDAP_BACK_F_SAVECRED;
1385 "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1386 fname, lineno, argv[ 1 ] );
1393 "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1398 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1401 "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1406 /* this is the default; we add it because the default might change... */
1407 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1408 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1410 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1411 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1415 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1416 fname, lineno, argv[1] );
1420 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1423 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1428 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1429 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1431 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1432 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1434 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1435 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1439 "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1440 fname, lineno, argv[ 1 ] );
1444 /* intercept exop_who_am_i? */
1445 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1446 int doload_extop = 0;
1451 "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1458 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1461 } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1463 "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1464 fname, lineno, argv[ 1 ] );
1471 "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1476 if ( doload_extop ) {
1477 li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1479 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1480 0, ldap_back_exop_whoami );
1483 /* FIXME: legacy: intercept old rewrite/remap directives
1484 * and try to start the rwm overlay */
1485 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1486 || strcasecmp( argv[0], "map" ) == 0
1487 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1490 fprintf( stderr, "%s: line %d: "
1491 "rewrite/remap capabilities have been moved "
1492 "to the \"rwm\" overlay; see slapo-rwm(5) "
1493 "for details. I'm trying to do my best "
1494 "to preserve backwards compatibility...\n",
1497 if ( li->rwm_started == 0 ) {
1498 if ( overlay_config( be, "rwm" ) ) {
1499 fprintf( stderr, "%s: line %d: "
1500 "unable to configure the \"rwm\" "
1501 "overlay, required by directive "
1503 fname, lineno, argv[0] );
1504 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1505 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1506 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1510 fprintf( stderr, "%s: line %d: back-ldap: "
1511 "automatically starting \"rwm\" overlay, "
1512 "triggered by \"%s\" directive.\n",
1513 fname, lineno, argv[ 0 ] );
1515 /* this is the default; we add it because the default might change... */
1516 li->rwm_started = 1;
1518 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1521 fprintf( stderr, "%s: line %d: "
1522 "rewrite/remap capabilities have been moved "
1523 "to the \"rwm\" overlay; see slapo-rwm(5) "
1524 "for details (hint: add \"overlay rwm\" "
1525 "and prefix all directives with \"rwm-\").\n",
1533 return SLAP_CONF_UNKNOWN;
1540 ldap_back_exop_whoami(
1544 struct berval *bv = NULL;
1546 if ( op->oq_extended.rs_reqdata != NULL ) {
1547 /* no request data should be provided */
1548 rs->sr_text = "no request data expected";
1549 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1552 rs->sr_err = backend_check_restrictions( op, rs,
1553 (struct berval *)&slap_EXOP_WHOAMI );
1554 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1556 /* if auth'd by back-ldap and request is proxied, forward it */
1557 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)) {
1558 struct ldapconn *lc;
1560 LDAPControl c, *ctrls[2] = {NULL, NULL};
1562 Operation op2 = *op;
1567 op2.o_ndn = op->o_conn->c_ndn;
1568 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1569 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1572 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1573 c.ldctl_iscritical = 1;
1574 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1575 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1576 strcpy(c.ldctl_value.bv_val, "dn:");
1577 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1580 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1581 if (rs->sr_err == LDAP_SUCCESS) {
1582 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1583 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1585 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1587 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1590 ldap_back_freeconn( op, lc );
1594 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1598 ch_free(c.ldctl_value.bv_val);
1599 if (rs->sr_err != LDAP_SUCCESS) {
1600 rs->sr_err = slap_map_api2result( rs );
1604 ldap_back_release_conn( &op2, rs, lc );
1608 /* else just do the same as before */
1609 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1610 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1611 bv->bv_len = op->o_dn.bv_len + STRLENOF("dn:");
1612 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1613 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF("dn:") );
1614 AC_MEMCPY( &bv->bv_val[STRLENOF("dn:")], op->o_dn.bv_val,
1616 bv->bv_val[bv->bv_len] = '\0';
1623 rs->sr_rspdata = bv;
1637 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1639 /* identity assertion mode */
1640 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1642 Debug( LDAP_DEBUG_ANY,
1643 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1644 fname, lineno, argc );
1648 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1649 /* will proxyAuthz as client's identity only if bound */
1650 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1652 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1653 /* will proxyAuthz as client's identity */
1654 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1656 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1657 /* will proxyAuthz as anonymous */
1658 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1660 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1661 /* will not proxyAuthz */
1662 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1668 /* will proxyAuthz as argv[1] */
1669 ber_str2bv( argv[1], 0, 0, &id );
1671 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1672 /* force lowercase... */
1674 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1675 ber_dupbv( &li->idassert_authzID, &id );
1680 /* default is DN? */
1681 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1682 id.bv_val += STRLENOF( "dn:" );
1683 id.bv_len -= STRLENOF( "dn:" );
1686 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1687 if ( rc != LDAP_SUCCESS ) {
1688 Debug( LDAP_DEBUG_ANY,
1689 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1690 fname, lineno, argv[1] );
1694 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1695 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1696 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1697 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1698 ch_free( dn.bv_val );
1700 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1704 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1705 if ( strcasecmp( argv[0], "override" ) == 0 ) {
1706 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1709 Debug( LDAP_DEBUG_ANY,
1710 "%s: line %d: unknown flag \"%s\" "
1711 "in \"idassert-mode <args> "
1712 "[<flags>]\" line.\n",
1713 fname, lineno, argv[0] );
1718 /* name to use for proxyAuthz propagation */
1719 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1720 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1725 /* FIXME: "proxyauthzdn" is no longer documented, and
1726 * temporarily supported for backwards compatibility */
1730 "%s: line %d: missing name in \"%s <name>\" line\n",
1731 fname, lineno, argv[0] );
1735 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1736 fprintf( stderr, "%s: line %d: "
1737 "authcDN already defined; replacing...\n",
1739 ch_free( li->idassert_authcDN.bv_val );
1742 ber_str2bv( argv[1], 0, 0, &dn );
1743 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1744 if ( rc != LDAP_SUCCESS ) {
1745 Debug( LDAP_DEBUG_ANY,
1746 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1747 fname, lineno, argv[1] );
1751 /* password to use for proxyAuthz propagation */
1752 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1753 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1755 /* FIXME: "proxyauthzpw" is no longer documented, and
1756 * temporarily supported for backwards compatibility */
1760 "%s: line %d: missing password in \"%s <password>\" line\n",
1761 fname, lineno, argv[0] );
1765 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1766 fprintf( stderr, "%s: line %d: "
1767 "passwd already defined; replacing...\n",
1769 ch_free( li->idassert_passwd.bv_val );
1772 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1774 /* rules to accept identity assertion... */
1775 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1778 ber_str2bv( argv[1], 0, 1, &rule );
1780 ber_bvarray_add( &li->idassert_authz, &rule );
1782 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1787 "%s: line %d: missing method in \"%s <method>\" line\n",
1788 fname, lineno, argv[0] );
1793 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1794 argv1 += STRLENOF( "bindmethod=" );
1797 if ( strcasecmp( argv1, "none" ) == 0 ) {
1798 /* FIXME: is this at all useful? */
1799 li->idassert_authmethod = LDAP_AUTH_NONE;
1803 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1804 fname, lineno, argv[0], argv[1] );
1807 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1810 for ( arg = 2; arg < argc; arg++ ) {
1811 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1812 char *val = argv[arg] + STRLENOF( "authcdn=" );
1816 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1817 fprintf( stderr, "%s: line %d: "
1818 "SASL authcDN already defined; replacing...\n",
1820 ch_free( li->idassert_authcDN.bv_val );
1822 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1823 val += STRLENOF( "dn:" );
1826 ber_str2bv( val, 0, 0, &dn );
1827 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1828 if ( rc != LDAP_SUCCESS ) {
1829 Debug( LDAP_DEBUG_ANY,
1830 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1831 fname, lineno, val );
1835 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1836 char *val = argv[arg] + STRLENOF( "cred=" );
1838 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1839 fprintf( stderr, "%s: line %d: "
1840 "SASL cred already defined; replacing...\n",
1842 ch_free( li->idassert_passwd.bv_val );
1844 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1847 fprintf( stderr, "%s: line %d: "
1848 "unknown parameter %s\n",
1849 fname, lineno, argv[arg] );
1854 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1856 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1857 #ifdef HAVE_CYRUS_SASL
1860 for ( arg = 2; arg < argc; arg++ ) {
1861 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1862 char *val = argv[arg] + STRLENOF( "mech=" );
1864 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1865 fprintf( stderr, "%s: line %d: "
1866 "SASL mech already defined; replacing...\n",
1868 ch_free( li->idassert_sasl_mech.bv_val );
1870 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1872 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1873 char *val = argv[arg] + STRLENOF( "realm=" );
1875 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1876 fprintf( stderr, "%s: line %d: "
1877 "SASL realm already defined; replacing...\n",
1879 ch_free( li->idassert_sasl_realm.bv_val );
1881 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1883 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1884 char *val = argv[arg] + STRLENOF( "authcdn=" );
1888 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1889 fprintf( stderr, "%s: line %d: "
1890 "SASL authcDN already defined; replacing...\n",
1892 ch_free( li->idassert_authcDN.bv_val );
1894 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1895 val += STRLENOF( "dn:" );
1898 ber_str2bv( val, 0, 0, &dn );
1899 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1900 if ( rc != LDAP_SUCCESS ) {
1901 Debug( LDAP_DEBUG_ANY,
1902 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1903 fname, lineno, val );
1907 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
1908 char *val = argv[arg] + STRLENOF( "authcid=" );
1910 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
1911 fprintf( stderr, "%s: line %d: "
1912 "SASL authcID already defined; replacing...\n",
1914 ch_free( li->idassert_authcID.bv_val );
1916 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
1917 val += STRLENOF( "u:" );
1919 ber_str2bv( val, 0, 1, &li->idassert_authcID );
1921 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1922 char *val = argv[arg] + STRLENOF( "cred=" );
1924 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1925 fprintf( stderr, "%s: line %d: "
1926 "SASL cred already defined; replacing...\n",
1928 ch_free( li->idassert_passwd.bv_val );
1930 ber_str2bv( val, 0, 1, &li->idassert_passwd );
1932 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1933 char *val = argv[arg] + STRLENOF( "authz=" );
1935 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
1936 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1938 } else if ( strcasecmp( val, "native" ) == 0 ) {
1939 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1942 fprintf( stderr, "%s: line %d: "
1943 "unknown authz mode \"%s\"\n",
1944 fname, lineno, val );
1949 fprintf( stderr, "%s: line %d: "
1950 "unknown SASL parameter %s\n",
1951 fname, lineno, argv[arg] );
1956 li->idassert_authmethod = LDAP_AUTH_SASL;
1958 #else /* !HAVE_CYRUS_SASL */
1959 fprintf( stderr, "%s: line %d: "
1960 "compile --with-cyrus-sasl to enable SASL auth\n",
1963 #endif /* !HAVE_CYRUS_SASL */
1966 fprintf( stderr, "%s: line %d: "
1967 "unhandled idassert-method method %s\n",
1968 fname, lineno, argv[1] );
1973 return SLAP_CONF_UNKNOWN;
1988 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1990 /* name to use for remote ACL access */
1991 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
1992 || strcasecmp( argv[0], "binddn" ) == 0 )
1997 /* FIXME: "binddn" is no longer documented, and
1998 * temporarily supported for backwards compatibility */
2002 "%s: line %d: missing name in \"%s <name>\" line\n",
2003 fname, lineno, argv[0] );
2007 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2008 fprintf( stderr, "%s: line %d: "
2009 "authcDN already defined; replacing...\n",
2011 ch_free( li->acl_authcDN.bv_val );
2014 ber_str2bv( argv[1], 0, 0, &dn );
2015 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2016 if ( rc != LDAP_SUCCESS ) {
2017 Debug( LDAP_DEBUG_ANY,
2018 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
2019 fname, lineno, argv[1] );
2023 /* password to use for remote ACL access */
2024 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
2025 || strcasecmp( argv[0], "bindpw" ) == 0 )
2027 /* FIXME: "bindpw" is no longer documented, and
2028 * temporarily supported for backwards compatibility */
2032 "%s: line %d: missing password in \"%s <password>\" line\n",
2033 fname, lineno, argv[0] );
2037 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2038 fprintf( stderr, "%s: line %d: "
2039 "passwd already defined; replacing...\n",
2041 ch_free( li->acl_passwd.bv_val );
2044 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2046 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2051 "%s: line %d: missing method in \"%s <method>\" line\n",
2052 fname, lineno, argv[0] );
2057 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2058 argv1 += STRLENOF( "bindmethod=" );
2061 if ( strcasecmp( argv1, "none" ) == 0 ) {
2062 /* FIXME: is this at all useful? */
2063 li->acl_authmethod = LDAP_AUTH_NONE;
2067 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2068 fname, lineno, argv[0], argv[1] );
2071 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2072 li->acl_authmethod = LDAP_AUTH_SIMPLE;
2076 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2077 fname, lineno, argv[0], argv[1] );
2080 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2081 #ifdef HAVE_CYRUS_SASL
2084 for ( arg = 2; arg < argc; arg++ ) {
2085 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2086 char *val = argv[arg] + STRLENOF( "mech=" );
2088 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2089 fprintf( stderr, "%s: line %d: "
2090 "SASL mech already defined; replacing...\n",
2092 ch_free( li->acl_sasl_mech.bv_val );
2094 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2096 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2097 char *val = argv[arg] + STRLENOF( "realm=" );
2099 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2100 fprintf( stderr, "%s: line %d: "
2101 "SASL realm already defined; replacing...\n",
2103 ch_free( li->acl_sasl_realm.bv_val );
2105 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2107 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2108 char *val = argv[arg] + STRLENOF( "authcdn=" );
2112 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2113 fprintf( stderr, "%s: line %d: "
2114 "SASL authcDN already defined; replacing...\n",
2116 ch_free( li->acl_authcDN.bv_val );
2118 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2119 val += STRLENOF( "dn:" );
2122 ber_str2bv( val, 0, 0, &dn );
2123 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2124 if ( rc != LDAP_SUCCESS ) {
2125 Debug( LDAP_DEBUG_ANY,
2126 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2127 fname, lineno, val );
2131 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2132 char *val = argv[arg] + STRLENOF( "authcid=" );
2134 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2135 fprintf( stderr, "%s: line %d: "
2136 "SASL authcID already defined; replacing...\n",
2138 ch_free( li->acl_authcID.bv_val );
2140 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2141 val += STRLENOF( "u:" );
2143 ber_str2bv( val, 0, 1, &li->acl_authcID );
2145 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2146 char *val = argv[arg] + STRLENOF( "cred=" );
2148 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2149 fprintf( stderr, "%s: line %d: "
2150 "SASL cred already defined; replacing...\n",
2152 ch_free( li->acl_passwd.bv_val );
2154 ber_str2bv( val, 0, 1, &li->acl_passwd );
2157 fprintf( stderr, "%s: line %d: "
2158 "unknown SASL parameter %s\n",
2159 fname, lineno, argv[arg] );
2164 li->acl_authmethod = LDAP_AUTH_SASL;
2166 #else /* !HAVE_CYRUS_SASL */
2167 fprintf( stderr, "%s: line %d: "
2168 "compile --with-cyrus-sasl to enable SASL auth\n",
2171 #endif /* !HAVE_CYRUS_SASL */
2174 fprintf( stderr, "%s: line %d: "
2175 "unhandled acl-method method %s\n",
2176 fname, lineno, argv[1] );
2181 return SLAP_CONF_UNKNOWN;