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>
29 #include <ac/socket.h>
32 #include "back-ldap.h"
35 /* for advanced URL parsing */
36 #include "../../../libraries/libldap/ldap-int.h"
38 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
41 parse_idassert( BackendDB *be, const char *fname, int lineno,
42 int argc, char **argv );
45 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
46 int argc, char **argv );
56 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
59 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
64 /* server address to query (depricated, use "uri" directive) */
65 if ( strcasecmp( argv[0], "server" ) == 0 ) {
69 "%s: line %d: \"server <address>\" directive is deprecated\n",
74 "%s: line %d: missing address in \"server <address>\" line\n",
78 if ( li->url != NULL ) {
82 l = strlen( argv[1] ) + STRLENOF( "ldap:///") + 1;
83 li->url = ch_calloc( l, sizeof( char ) );
84 if ( li->url == NULL ) {
85 fprintf( stderr, "%s: line %d: malloc failed\n" );
89 snprintf( li->url, l, "ldap://%s/", argv[1] );
91 /* URI of server to query (preferred over "server" directive) */
92 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
97 fprintf( stderr, "%s: line %d: "
99 "in \"uri <uri>\" line\n",
103 if ( li->url != NULL ) {
106 if ( li->lud != NULL ) {
107 ldap_free_urllist( li->lud );
111 /* PARANOID: DN and more are not required nor allowed */
112 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
114 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
116 if ( urlrc != LDAP_URL_SUCCESS ) {
120 case LDAP_URL_ERR_MEM:
123 case LDAP_URL_ERR_PARAM:
124 why = "parameter is bad";
126 case LDAP_URL_ERR_BADSCHEME:
127 why = "URL doesn't begin with \"[c]ldap[si]://\"";
129 case LDAP_URL_ERR_BADENCLOSURE:
130 why = "URL is missing trailing \">\"";
132 case LDAP_URL_ERR_BADURL:
134 case LDAP_URL_ERR_BADHOST:
135 why = "host/port is bad";
137 case LDAP_URL_ERR_BADATTRS:
138 why = "bad (or missing) attributes";
140 case LDAP_URL_ERR_BADSCOPE:
141 why = "scope string is invalid (or missing)";
143 case LDAP_URL_ERR_BADFILTER:
144 why = "bad or missing filter";
146 case LDAP_URL_ERR_BADEXTS:
147 why = "bad or missing extensions";
150 why = "unknown reason";
153 fprintf( stderr, "%s: line %d: "
154 "unable to parse uri \"%s\" "
155 "in \"uri <uri>\" line: %s\n",
156 fname, lineno, argv[ 1 ], why );
160 for ( i = 0, tmpludp = li->lud;
162 i++, tmpludp = tmpludp->lud_next )
164 if ( ( tmpludp->lud_dn != NULL
165 && tmpludp->lud_dn[0] != '\0' )
166 || tmpludp->lud_attrs != NULL
167 || tmpludp->lud_filter != NULL
168 || tmpludp->lud_exts != NULL )
170 fprintf( stderr, "%s: line %d: "
171 "warning, only protocol, "
172 "host and port allowed "
173 "in \"uri <uri>\" statement "
174 "for uri #%d of \"%s\"\n",
175 fname, lineno, i, argv[1] );
180 for ( tmpludp = li->lud; tmpludp; tmpludp = tmpludp->lud_next ) {
183 ber_len_t oldlen = 0, len;
187 tmplud.lud_attrs = NULL;
188 tmplud.lud_filter = NULL;
189 if ( !ldap_is_ldapi_url( argv[ 1 ] ) ) {
190 tmplud.lud_exts = NULL;
191 tmplud.lud_crit_exts = 0;
194 tmpurl = ldap_url_desc2str( &tmplud );
196 if ( tmpurl == NULL ) {
197 fprintf( stderr, "%s: line %d: "
198 "unable to rebuild uri "
199 "in \"uri <uri>\" statement "
201 fname, lineno, argv[ 1 ] );
205 len = strlen( tmpurl );
207 oldlen = strlen( li->url ) + STRLENOF( " " );
209 li->url = ch_realloc( li->url, oldlen + len + 1);
211 li->url[oldlen - 1] = " ";
213 AC_MEMCPY( &li->url[oldlen], tmpurl, len + 1 );
217 li->url = ch_strdup( argv[ 1 ] );
220 } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
223 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
229 if ( strcasecmp( argv[1], "start" ) == 0 ) {
230 li->flags |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
233 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
234 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
235 li->flags |= LDAP_BACK_F_USE_TLS;
237 /* propagate start tls */
238 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
239 li->flags |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
242 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
243 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
244 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
248 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
249 fname, lineno, argv[1] );
253 /* remote ACL stuff... */
254 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
255 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
257 /* NOTE: "bind{DN,pw}" was initially used; it's now
258 * deprected and undocumented, it can be dropped at some
259 * point, since nobody should be really using it */
260 return parse_acl_auth( be, fname, lineno, argc, argv );
262 /* identity assertion stuff... */
263 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
264 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
266 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
267 * deprected and undocumented, it can be dropped at some
268 * point, since nobody should be really using it */
269 return parse_idassert( be, fname, lineno, argc, argv );
271 /* save bind creds for referral rebinds? */
272 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
275 "%s: line %d: \"rebind-as-user\" takes no arguments\n",
279 li->flags |= LDAP_BACK_F_SAVECRED;
281 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
284 "%s: line %d: \"chase-referrals\" needs 1 argument.\n",
289 /* this is the default; we add it because the default might change... */
290 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
291 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
293 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
294 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
298 "%s: line %d: \"chase-referrals {yes|no}\": unknown argument \"%s\".\n",
299 fname, lineno, argv[1] );
303 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
306 "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
311 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
312 li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
314 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
315 li->flags |= LDAP_BACK_F_SUPPORT_T_F;
317 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
318 li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
322 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
323 fname, lineno, argv[ 1 ] );
327 /* intercept exop_who_am_i? */
328 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
331 "%s: line %d: proxy-whoami takes no arguments\n",
335 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
336 0, ldap_back_exop_whoami );
338 /* FIXME: legacy: intercept old rewrite/remap directives
339 * and try to start the rwm overlay */
340 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
341 || strcasecmp( argv[0], "map" ) == 0
342 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
344 fprintf( stderr, "%s: line %d: "
345 "rewrite/remap capabilities have been moved "
346 "to the \"rwm\" overlay; see slapo-rwm(5) "
347 "for details. I'm trying to do my best "
348 "to preserve backwards compatibility...\n",
351 if ( li->rwm_started == 0 ) {
352 if ( overlay_config( be, "rwm" ) ) {
353 fprintf( stderr, "%s: line %d: "
354 "unable to configure the \"rwm\" "
355 "overlay, required by directive "
357 fname, lineno, argv[0] );
358 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
359 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
360 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
364 fprintf( stderr, "%s: line %d: back-ldap: "
365 "automatically starting \"rwm\" overlay, "
366 "triggered by \"%s\" directive.\n",
367 fname, lineno, argv[ 0 ] );
369 /* this is the default; we add it because the default might change... */
372 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
375 return SLAP_CONF_UNKNOWN;
379 return SLAP_CONF_UNKNOWN;
386 ldap_back_exop_whoami(
390 struct berval *bv = NULL;
392 if ( op->oq_extended.rs_reqdata != NULL ) {
393 /* no request data should be provided */
394 rs->sr_text = "no request data expected";
395 return rs->sr_err = LDAP_PROTOCOL_ERROR;
398 rs->sr_err = backend_check_restrictions( op, rs,
399 (struct berval *)&slap_EXOP_WHOAMI );
400 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
402 /* if auth'd by back-ldap and request is proxied, forward it */
403 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)) {
406 LDAPControl c, *ctrls[2] = {NULL, NULL};
413 op2.o_ndn = op->o_conn->c_ndn;
414 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
415 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
418 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
419 c.ldctl_iscritical = 1;
420 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
421 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
422 strcpy(c.ldctl_value.bv_val, "dn:");
423 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
426 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
427 if (rs->sr_err == LDAP_SUCCESS) {
428 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
429 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
431 if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
433 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
436 ldap_back_freeconn( op, lc );
440 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
444 ch_free(c.ldctl_value.bv_val);
445 if (rs->sr_err != LDAP_SUCCESS) {
446 rs->sr_err = slap_map_api2result( rs );
449 /* else just do the same as before */
450 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
451 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
452 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
453 bv->bv_val = ch_malloc( bv->bv_len + 1 );
454 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
455 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
457 bv->bv_val[bv->bv_len] = '\0';
478 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
480 /* identity assertion mode */
481 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
483 Debug( LDAP_DEBUG_ANY,
484 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
485 fname, lineno, argc );
489 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
490 /* will proxyAuthz as client's identity only if bound */
491 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
493 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
494 /* will proxyAuthz as client's identity */
495 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
497 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
498 /* will proxyAuthz as anonymous */
499 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
501 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
502 /* will not proxyAuthz */
503 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
509 /* will proxyAuthz as argv[1] */
510 ber_str2bv( argv[1], 0, 0, &id );
512 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
513 /* force lowercase... */
515 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
516 ber_dupbv( &li->idassert_authzID, &id );
522 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
523 id.bv_val += STRLENOF( "dn:" );
524 id.bv_len -= STRLENOF( "dn:" );
527 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
528 if ( rc != LDAP_SUCCESS ) {
529 Debug( LDAP_DEBUG_ANY,
530 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
531 fname, lineno, argv[1] );
535 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
536 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
537 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
538 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
539 ch_free( dn.bv_val );
541 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
545 for ( argc -= 2, argv += 2; argc--; argv++ ) {
546 if ( strcasecmp( argv[0], "override" ) == 0 ) {
547 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
550 Debug( LDAP_DEBUG_ANY,
551 "%s: line %d: unknown flag \"%s\" "
552 "in \"idassert-mode <args> "
553 "[<flags>]\" line.\n",
554 fname, lineno, argv[0] );
559 /* name to use for proxyAuthz propagation */
560 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
561 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
566 /* FIXME: "proxyauthzdn" is no longer documented, and
567 * temporarily supported for backwards compatibility */
571 "%s: line %d: missing name in \"%s <name>\" line\n",
572 fname, lineno, argv[0] );
576 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
577 fprintf( stderr, "%s: line %d: "
578 "authcDN already defined; replacing...\n",
580 ch_free( li->idassert_authcDN.bv_val );
583 ber_str2bv( argv[1], 0, 0, &dn );
584 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
585 if ( rc != LDAP_SUCCESS ) {
586 Debug( LDAP_DEBUG_ANY,
587 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
588 fname, lineno, argv[1] );
592 /* password to use for proxyAuthz propagation */
593 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
594 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
596 /* FIXME: "proxyauthzpw" is no longer documented, and
597 * temporarily supported for backwards compatibility */
601 "%s: line %d: missing password in \"%s <password>\" line\n",
602 fname, lineno, argv[0] );
606 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
607 fprintf( stderr, "%s: line %d: "
608 "passwd already defined; replacing...\n",
610 ch_free( li->idassert_passwd.bv_val );
613 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
615 /* rules to accept identity assertion... */
616 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
619 ber_str2bv( argv[1], 0, 1, &rule );
621 ber_bvarray_add( &li->idassert_authz, &rule );
623 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
628 "%s: line %d: missing method in \"%s <method>\" line\n",
629 fname, lineno, argv[0] );
634 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
635 argv1 += STRLENOF( "bindmethod=" );
638 if ( strcasecmp( argv1, "none" ) == 0 ) {
639 /* FIXME: is this at all useful? */
640 li->idassert_authmethod = LDAP_AUTH_NONE;
644 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
645 fname, lineno, argv[0], argv[1] );
648 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
649 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
653 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
654 fname, lineno, argv[0], argv[1] );
657 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
658 #ifdef HAVE_CYRUS_SASL
661 for ( arg = 2; arg < argc; arg++ ) {
662 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
663 char *val = argv[arg] + STRLENOF( "mech=" );
665 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
666 fprintf( stderr, "%s: line %d: "
667 "SASL mech already defined; replacing...\n",
669 ch_free( li->idassert_sasl_mech.bv_val );
671 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
673 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
674 char *val = argv[arg] + STRLENOF( "realm=" );
676 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
677 fprintf( stderr, "%s: line %d: "
678 "SASL realm already defined; replacing...\n",
680 ch_free( li->idassert_sasl_realm.bv_val );
682 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
684 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
685 char *val = argv[arg] + STRLENOF( "authcdn=" );
689 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
690 fprintf( stderr, "%s: line %d: "
691 "SASL authcDN already defined; replacing...\n",
693 ch_free( li->idassert_authcDN.bv_val );
695 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
696 val += STRLENOF( "dn:" );
699 ber_str2bv( val, 0, 0, &dn );
700 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
701 if ( rc != LDAP_SUCCESS ) {
702 Debug( LDAP_DEBUG_ANY,
703 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
704 fname, lineno, val );
708 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
709 char *val = argv[arg] + STRLENOF( "authcid=" );
711 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
712 fprintf( stderr, "%s: line %d: "
713 "SASL authcID already defined; replacing...\n",
715 ch_free( li->idassert_authcID.bv_val );
717 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
718 val += STRLENOF( "u:" );
720 ber_str2bv( val, 0, 1, &li->idassert_authcID );
722 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
723 char *val = argv[arg] + STRLENOF( "cred=" );
725 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
726 fprintf( stderr, "%s: line %d: "
727 "SASL cred already defined; replacing...\n",
729 ch_free( li->idassert_passwd.bv_val );
731 ber_str2bv( val, 0, 1, &li->idassert_passwd );
733 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
734 char *val = argv[arg] + STRLENOF( "authz=" );
736 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
737 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
739 } else if ( strcasecmp( val, "native" ) == 0 ) {
740 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
743 fprintf( stderr, "%s: line %d: "
744 "unknown authz mode \"%s\"\n",
745 fname, lineno, val );
750 fprintf( stderr, "%s: line %d: "
751 "unknown SASL parameter %s\n",
752 fname, lineno, argv[arg] );
757 li->idassert_authmethod = LDAP_AUTH_SASL;
759 #else /* !HAVE_CYRUS_SASL */
760 fprintf( stderr, "%s: line %d: "
761 "compile --with-cyrus-sasl to enable SASL auth\n",
764 #endif /* !HAVE_CYRUS_SASL */
767 fprintf( stderr, "%s: line %d: "
768 "unhandled idassert-method method %s\n",
769 fname, lineno, argv[1] );
774 return SLAP_CONF_UNKNOWN;
789 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
791 /* name to use for remote ACL access */
792 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
793 || strcasecmp( argv[0], "binddn" ) == 0 )
798 /* FIXME: "binddn" is no longer documented, and
799 * temporarily supported for backwards compatibility */
803 "%s: line %d: missing name in \"%s <name>\" line\n",
804 fname, lineno, argv[0] );
808 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
809 fprintf( stderr, "%s: line %d: "
810 "authcDN already defined; replacing...\n",
812 ch_free( li->acl_authcDN.bv_val );
815 ber_str2bv( argv[1], 0, 0, &dn );
816 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
817 if ( rc != LDAP_SUCCESS ) {
818 Debug( LDAP_DEBUG_ANY,
819 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
820 fname, lineno, argv[1] );
824 /* password to use for remote ACL access */
825 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
826 || strcasecmp( argv[0], "bindpw" ) == 0 )
828 /* FIXME: "bindpw" is no longer documented, and
829 * temporarily supported for backwards compatibility */
833 "%s: line %d: missing password in \"%s <password>\" line\n",
834 fname, lineno, argv[0] );
838 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
839 fprintf( stderr, "%s: line %d: "
840 "passwd already defined; replacing...\n",
842 ch_free( li->acl_passwd.bv_val );
845 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
847 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
852 "%s: line %d: missing method in \"%s <method>\" line\n",
853 fname, lineno, argv[0] );
858 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
859 argv1 += STRLENOF( "bindmethod=" );
862 if ( strcasecmp( argv1, "none" ) == 0 ) {
863 /* FIXME: is this at all useful? */
864 li->acl_authmethod = LDAP_AUTH_NONE;
868 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
869 fname, lineno, argv[0], argv[1] );
872 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
873 li->acl_authmethod = LDAP_AUTH_SIMPLE;
877 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
878 fname, lineno, argv[0], argv[1] );
881 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
882 #ifdef HAVE_CYRUS_SASL
885 for ( arg = 2; arg < argc; arg++ ) {
886 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
887 char *val = argv[arg] + STRLENOF( "mech=" );
889 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
890 fprintf( stderr, "%s: line %d: "
891 "SASL mech already defined; replacing...\n",
893 ch_free( li->acl_sasl_mech.bv_val );
895 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
897 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
898 char *val = argv[arg] + STRLENOF( "realm=" );
900 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
901 fprintf( stderr, "%s: line %d: "
902 "SASL realm already defined; replacing...\n",
904 ch_free( li->acl_sasl_realm.bv_val );
906 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
908 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
909 char *val = argv[arg] + STRLENOF( "authcdn=" );
913 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
914 fprintf( stderr, "%s: line %d: "
915 "SASL authcDN already defined; replacing...\n",
917 ch_free( li->acl_authcDN.bv_val );
919 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
920 val += STRLENOF( "dn:" );
923 ber_str2bv( val, 0, 0, &dn );
924 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
925 if ( rc != LDAP_SUCCESS ) {
926 Debug( LDAP_DEBUG_ANY,
927 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
928 fname, lineno, val );
932 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
933 char *val = argv[arg] + STRLENOF( "authcid=" );
935 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
936 fprintf( stderr, "%s: line %d: "
937 "SASL authcID already defined; replacing...\n",
939 ch_free( li->acl_authcID.bv_val );
941 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
942 val += STRLENOF( "u:" );
944 ber_str2bv( val, 0, 1, &li->acl_authcID );
946 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
947 char *val = argv[arg] + STRLENOF( "cred=" );
949 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
950 fprintf( stderr, "%s: line %d: "
951 "SASL cred already defined; replacing...\n",
953 ch_free( li->acl_passwd.bv_val );
955 ber_str2bv( val, 0, 1, &li->acl_passwd );
958 fprintf( stderr, "%s: line %d: "
959 "unknown SASL parameter %s\n",
960 fname, lineno, argv[arg] );
965 li->acl_authmethod = LDAP_AUTH_SASL;
967 #else /* !HAVE_CYRUS_SASL */
968 fprintf( stderr, "%s: line %d: "
969 "compile --with-cyrus-sasl to enable SASL auth\n",
972 #endif /* !HAVE_CYRUS_SASL */
975 fprintf( stderr, "%s: line %d: "
976 "unhandled acl-method method %s\n",
977 fname, lineno, argv[1] );
982 return SLAP_CONF_UNKNOWN;