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 ( strncasecmp( argv[0], "tls-", STRLENOF( "tls-" ) ) == 0 ) {
223 if ( strcasecmp( argv[0], "tls-start" ) == 0 ) {
226 "%s: line %d: tls-start takes no arguments\n",
230 li->flags |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
233 } else if ( strcasecmp( argv[0], "tls-try-start" ) == 0 ) {
236 "%s: line %d: tls-try-start takes no arguments\n",
240 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
241 li->flags |= LDAP_BACK_F_USE_TLS;
243 /* propagate start tls */
244 } else if ( strcasecmp( argv[0], "tls-propagate" ) == 0 ) {
247 "%s: line %d: tls-propagate takes no arguments\n",
251 li->flags |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
254 } else if ( strcasecmp( argv[0], "tls-try-propagate" ) == 0 ) {
257 "%s: line %d: tls-try-propagate takes no arguments\n",
261 li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
262 li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
265 /* remote ACL stuff... */
266 } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
267 || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
269 /* NOTE: "bind{DN,pw}" was initially used; it's now
270 * deprected and undocumented, it can be dropped at some
271 * point, since nobody should be really using it */
272 return parse_acl_auth( be, fname, lineno, argc, argv );
274 /* identity assertion stuff... */
275 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
276 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
278 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
279 * deprected and undocumented, it can be dropped at some
280 * point, since nobody should be really using it */
281 return parse_idassert( be, fname, lineno, argc, argv );
283 /* save bind creds for referral rebinds? */
284 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
287 "%s: line %d: \"rebind-as-user\" takes no arguments\n",
291 li->flags |= LDAP_BACK_F_SAVECRED;
293 } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
296 "%s: line %d: \"chase-referrals\" takes no arguments\n",
301 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
303 } else if ( strcasecmp( argv[0], "dont-chase-referrals" ) == 0 ) {
306 "%s: line %d: \"dont-chase-referrals\" takes no arguments\n",
311 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
313 /* intercept exop_who_am_i? */
314 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
317 "%s: line %d: proxy-whoami takes no arguments\n",
321 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
322 0, ldap_back_exop_whoami );
324 /* FIXME: legacy: intercept old rewrite/remap directives
325 * and try to start the rwm overlay */
326 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
327 || strcasecmp( argv[0], "map" ) == 0
328 || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
330 fprintf( stderr, "%s: line %d: "
331 "rewrite/remap capabilities have been moved "
332 "to the \"rwm\" overlay; see slapo-rwm(5) "
333 "for details. I'm trying to do my best "
334 "to preserve backwards compatibility...\n",
337 if ( li->rwm_started == 0 ) {
338 if ( overlay_config( be, "rwm" ) ) {
339 fprintf( stderr, "%s: line %d: "
340 "unable to configure the \"rwm\" "
341 "overlay, required by directive "
343 fname, lineno, argv[0] );
344 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
345 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
346 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
350 fprintf( stderr, "%s: line %d: back-ldap: "
351 "automatically starting \"rwm\" overlay, "
352 "triggered by \"%s\" directive.\n",
353 fname, lineno, argv[ 0 ] );
357 return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
360 return SLAP_CONF_UNKNOWN;
364 return SLAP_CONF_UNKNOWN;
371 ldap_back_exop_whoami(
375 struct berval *bv = NULL;
377 if ( op->oq_extended.rs_reqdata != NULL ) {
378 /* no request data should be provided */
379 rs->sr_text = "no request data expected";
380 return rs->sr_err = LDAP_PROTOCOL_ERROR;
383 rs->sr_err = backend_check_restrictions( op, rs,
384 (struct berval *)&slap_EXOP_WHOAMI );
385 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
387 /* if auth'd by back-ldap and request is proxied, forward it */
388 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)) {
391 LDAPControl c, *ctrls[2] = {NULL, NULL};
398 op2.o_ndn = op->o_conn->c_ndn;
399 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
400 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
403 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
404 c.ldctl_iscritical = 1;
405 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
406 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
407 strcpy(c.ldctl_value.bv_val, "dn:");
408 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
411 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
412 if (rs->sr_err == LDAP_SUCCESS) {
413 if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
414 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
416 if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
418 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
421 ldap_back_freeconn( op, lc );
425 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
429 ch_free(c.ldctl_value.bv_val);
430 if (rs->sr_err != LDAP_SUCCESS) {
431 rs->sr_err = slap_map_api2result( rs );
434 /* else just do the same as before */
435 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
436 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
437 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
438 bv->bv_val = ch_malloc( bv->bv_len + 1 );
439 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
440 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
442 bv->bv_val[bv->bv_len] = '\0';
463 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
465 /* identity assertion mode */
466 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
468 Debug( LDAP_DEBUG_ANY,
469 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
470 fname, lineno, argc );
474 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
475 /* will proxyAuthz as client's identity only if bound */
476 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
478 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
479 /* will proxyAuthz as client's identity */
480 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
482 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
483 /* will proxyAuthz as anonymous */
484 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
486 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
487 /* will not proxyAuthz */
488 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
494 /* will proxyAuthz as argv[1] */
495 ber_str2bv( argv[1], 0, 0, &id );
497 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
498 /* force lowercase... */
500 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
501 ber_dupbv( &li->idassert_authzID, &id );
507 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
508 id.bv_val += STRLENOF( "dn:" );
509 id.bv_len -= STRLENOF( "dn:" );
512 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
513 if ( rc != LDAP_SUCCESS ) {
514 Debug( LDAP_DEBUG_ANY,
515 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
516 fname, lineno, argv[1] );
520 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
521 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
522 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
523 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
524 ch_free( dn.bv_val );
526 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
530 for ( argc -= 2, argv += 2; argc--; argv++ ) {
531 if ( strcasecmp( argv[0], "override" ) == 0 ) {
532 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
535 Debug( LDAP_DEBUG_ANY,
536 "%s: line %d: unknown flag \"%s\" "
537 "in \"idassert-mode <args> "
538 "[<flags>]\" line.\n",
539 fname, lineno, argv[0] );
544 /* name to use for proxyAuthz propagation */
545 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
546 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
551 /* FIXME: "proxyauthzdn" is no longer documented, and
552 * temporarily supported for backwards compatibility */
556 "%s: line %d: missing name in \"%s <name>\" line\n",
557 fname, lineno, argv[0] );
561 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
562 fprintf( stderr, "%s: line %d: "
563 "authcDN already defined; replacing...\n",
565 ch_free( li->idassert_authcDN.bv_val );
568 ber_str2bv( argv[1], 0, 0, &dn );
569 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
570 if ( rc != LDAP_SUCCESS ) {
571 Debug( LDAP_DEBUG_ANY,
572 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
573 fname, lineno, argv[1] );
577 /* password to use for proxyAuthz propagation */
578 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
579 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
581 /* FIXME: "proxyauthzpw" is no longer documented, and
582 * temporarily supported for backwards compatibility */
586 "%s: line %d: missing password in \"%s <password>\" line\n",
587 fname, lineno, argv[0] );
591 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
592 fprintf( stderr, "%s: line %d: "
593 "passwd already defined; replacing...\n",
595 ch_free( li->idassert_passwd.bv_val );
598 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
600 /* rules to accept identity assertion... */
601 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
604 ber_str2bv( argv[1], 0, 1, &rule );
606 ber_bvarray_add( &li->idassert_authz, &rule );
608 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
611 "%s: line %d: missing method in \"%s <method>\" line\n",
612 fname, lineno, argv[0] );
616 if ( strcasecmp( argv[1], "none" ) == 0 ) {
617 /* FIXME: is this at all useful? */
618 li->idassert_authmethod = LDAP_AUTH_NONE;
622 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
623 fname, lineno, argv[0], argv[1] );
626 } else if ( strcasecmp( argv[1], "simple" ) == 0 ) {
627 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
631 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
632 fname, lineno, argv[0], argv[1] );
635 } else if ( strcasecmp( argv[1], "sasl" ) == 0 ) {
636 #ifdef HAVE_CYRUS_SASL
639 for ( arg = 2; arg < argc; arg++ ) {
640 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
641 char *val = argv[arg] + STRLENOF( "mech=" );
643 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
644 fprintf( stderr, "%s: line %d: "
645 "SASL mech already defined; replacing...\n",
647 ch_free( li->idassert_sasl_mech.bv_val );
649 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
651 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
652 char *val = argv[arg] + STRLENOF( "realm=" );
654 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
655 fprintf( stderr, "%s: line %d: "
656 "SASL realm already defined; replacing...\n",
658 ch_free( li->idassert_sasl_realm.bv_val );
660 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
662 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
663 char *val = argv[arg] + STRLENOF( "authcdn=" );
667 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
668 fprintf( stderr, "%s: line %d: "
669 "SASL authcDN already defined; replacing...\n",
671 ch_free( li->idassert_authcDN.bv_val );
673 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
674 val += STRLENOF( "dn:" );
677 ber_str2bv( val, 0, 0, &dn );
678 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
679 if ( rc != LDAP_SUCCESS ) {
680 Debug( LDAP_DEBUG_ANY,
681 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
682 fname, lineno, val );
686 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
687 char *val = argv[arg] + STRLENOF( "authcid=" );
689 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
690 fprintf( stderr, "%s: line %d: "
691 "SASL authcID already defined; replacing...\n",
693 ch_free( li->idassert_authcID.bv_val );
695 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
696 val += STRLENOF( "u:" );
698 ber_str2bv( val, 0, 1, &li->idassert_authcID );
700 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
701 char *val = argv[arg] + STRLENOF( "cred=" );
703 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
704 fprintf( stderr, "%s: line %d: "
705 "SASL cred already defined; replacing...\n",
707 ch_free( li->idassert_passwd.bv_val );
709 ber_str2bv( val, 0, 1, &li->idassert_passwd );
711 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
712 char *val = argv[arg] + STRLENOF( "authz=" );
714 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
715 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
717 } else if ( strcasecmp( val, "native" ) == 0 ) {
718 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
721 fprintf( stderr, "%s: line %d: "
722 "unknown authz mode \"%s\"\n",
723 fname, lineno, val );
728 fprintf( stderr, "%s: line %d: "
729 "unknown SASL parameter %s\n",
730 fname, lineno, argv[arg] );
735 li->idassert_authmethod = LDAP_AUTH_SASL;
737 #else /* !HAVE_CYRUS_SASL */
738 fprintf( stderr, "%s: line %d: "
739 "compile --with-cyrus-sasl to enable SASL auth\n",
742 #endif /* !HAVE_CYRUS_SASL */
745 fprintf( stderr, "%s: line %d: "
746 "unhandled idassert-method method %s\n",
747 fname, lineno, argv[1] );
752 return SLAP_CONF_UNKNOWN;
767 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
769 /* name to use for remote ACL access */
770 if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
771 || strcasecmp( argv[0], "binddn" ) == 0 )
776 /* FIXME: "binddn" is no longer documented, and
777 * temporarily supported for backwards compatibility */
781 "%s: line %d: missing name in \"%s <name>\" line\n",
782 fname, lineno, argv[0] );
786 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
787 fprintf( stderr, "%s: line %d: "
788 "authcDN already defined; replacing...\n",
790 ch_free( li->acl_authcDN.bv_val );
793 ber_str2bv( argv[1], 0, 0, &dn );
794 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
795 if ( rc != LDAP_SUCCESS ) {
796 Debug( LDAP_DEBUG_ANY,
797 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
798 fname, lineno, argv[1] );
802 /* password to use for remote ACL access */
803 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
804 || strcasecmp( argv[0], "bindpw" ) == 0 )
806 /* FIXME: "bindpw" is no longer documented, and
807 * temporarily supported for backwards compatibility */
811 "%s: line %d: missing password in \"%s <password>\" line\n",
812 fname, lineno, argv[0] );
816 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
817 fprintf( stderr, "%s: line %d: "
818 "passwd already defined; replacing...\n",
820 ch_free( li->acl_passwd.bv_val );
823 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
825 } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
828 "%s: line %d: missing method in \"%s <method>\" line\n",
829 fname, lineno, argv[0] );
833 if ( strcasecmp( argv[1], "none" ) == 0 ) {
834 /* FIXME: is this at all useful? */
835 li->acl_authmethod = LDAP_AUTH_NONE;
839 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
840 fname, lineno, argv[0], argv[1] );
843 } else if ( strcasecmp( argv[1], "simple" ) == 0 ) {
844 li->acl_authmethod = LDAP_AUTH_SIMPLE;
848 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
849 fname, lineno, argv[0], argv[1] );
852 } else if ( strcasecmp( argv[1], "sasl" ) == 0 ) {
853 #ifdef HAVE_CYRUS_SASL
856 for ( arg = 2; arg < argc; arg++ ) {
857 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
858 char *val = argv[arg] + STRLENOF( "mech=" );
860 if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
861 fprintf( stderr, "%s: line %d: "
862 "SASL mech already defined; replacing...\n",
864 ch_free( li->acl_sasl_mech.bv_val );
866 ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
868 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
869 char *val = argv[arg] + STRLENOF( "realm=" );
871 if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
872 fprintf( stderr, "%s: line %d: "
873 "SASL realm already defined; replacing...\n",
875 ch_free( li->acl_sasl_realm.bv_val );
877 ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
879 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
880 char *val = argv[arg] + STRLENOF( "authcdn=" );
884 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
885 fprintf( stderr, "%s: line %d: "
886 "SASL authcDN already defined; replacing...\n",
888 ch_free( li->acl_authcDN.bv_val );
890 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
891 val += STRLENOF( "dn:" );
894 ber_str2bv( val, 0, 0, &dn );
895 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
896 if ( rc != LDAP_SUCCESS ) {
897 Debug( LDAP_DEBUG_ANY,
898 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
899 fname, lineno, val );
903 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
904 char *val = argv[arg] + STRLENOF( "authcid=" );
906 if ( !BER_BVISNULL( &li->acl_authcID ) ) {
907 fprintf( stderr, "%s: line %d: "
908 "SASL authcID already defined; replacing...\n",
910 ch_free( li->acl_authcID.bv_val );
912 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
913 val += STRLENOF( "u:" );
915 ber_str2bv( val, 0, 1, &li->acl_authcID );
917 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
918 char *val = argv[arg] + STRLENOF( "cred=" );
920 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
921 fprintf( stderr, "%s: line %d: "
922 "SASL cred already defined; replacing...\n",
924 ch_free( li->acl_passwd.bv_val );
926 ber_str2bv( val, 0, 1, &li->acl_passwd );
929 fprintf( stderr, "%s: line %d: "
930 "unknown SASL parameter %s\n",
931 fname, lineno, argv[arg] );
936 li->acl_authmethod = LDAP_AUTH_SASL;
938 #else /* !HAVE_CYRUS_SASL */
939 fprintf( stderr, "%s: line %d: "
940 "compile --with-cyrus-sasl to enable SASL auth\n",
943 #endif /* !HAVE_CYRUS_SASL */
946 fprintf( stderr, "%s: line %d: "
947 "unhandled acl-method method %s\n",
948 fname, lineno, argv[1] );
953 return SLAP_CONF_UNKNOWN;