1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 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 );
53 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
56 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
61 /* server address to query (depricated, use "uri" directive) */
62 if ( strcasecmp( argv[0], "server" ) == 0 ) {
67 "%s: line %d: missing address in \"server <address>\" line\n",
73 l = strlen( argv[1] ) + STRLENOF( "ldap:///") + 1;
74 li->url = ch_calloc( l, sizeof( char ) );
75 if (li->url == NULL) {
76 fprintf( stderr, "%s: line %d: malloc failed\n" );
80 snprintf( li->url, l, "ldap://%s/", argv[1] );
82 /* URI of server to query (preferred over "server" directive) */
83 } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
84 LDAPURLDesc tmplud, *tmpludp;
88 fprintf( stderr, "%s: line %d: "
90 "in \"uri <uri>\" line\n",
94 if ( li->url != NULL ) {
97 if ( li->lud != NULL ) {
98 ldap_free_urllist( li->lud );
102 /* PARANOID: DN and more are not required nor allowed */
103 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
105 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
107 if ( urlrc != LDAP_URL_SUCCESS ) {
111 case LDAP_URL_ERR_MEM:
114 case LDAP_URL_ERR_PARAM:
115 why = "parameter is bad";
117 case LDAP_URL_ERR_BADSCHEME:
118 why = "URL doesn't begin with \"[c]ldap[si]://\"";
120 case LDAP_URL_ERR_BADENCLOSURE:
121 why = "URL is missing trailing \">\"";
123 case LDAP_URL_ERR_BADURL:
125 case LDAP_URL_ERR_BADHOST:
126 why = "host/port is bad";
128 case LDAP_URL_ERR_BADATTRS:
129 why = "bad (or missing) attributes";
131 case LDAP_URL_ERR_BADSCOPE:
132 why = "scope string is invalid (or missing)";
134 case LDAP_URL_ERR_BADFILTER:
135 why = "bad or missing filter";
137 case LDAP_URL_ERR_BADEXTS:
138 why = "bad or missing extensions";
141 why = "unknown reason";
144 fprintf( stderr, "%s: line %d: "
145 "unable to parse uri \"%s\" "
146 "in \"uri <uri>\" line: %s\n",
147 fname, lineno, argv[ 1 ], why );
151 for ( tmpludp = li->lud; tmpludp; tmpludp = tmpludp->lud_next ) {
152 if ( ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[0] != '\0' )
153 || tmpludp->lud_attrs != NULL
154 || tmpludp->lud_filter != NULL
155 || tmpludp->lud_exts != NULL )
157 fprintf( stderr, "%s: line %d: "
158 "warning, only protocol, "
159 "host and port allowed "
160 "in \"uri <uri>\" statement "
162 fname, lineno, argv[1] );
167 for ( tmpludp = li->lud; tmpludp; tmpludp = tmpludp->lud_next ) {
169 ber_len_t oldlen = 0, len;
173 tmplud.lud_attrs = NULL;
174 tmplud.lud_filter = NULL;
175 if ( !ldap_is_ldapi_url( argv[ 1 ] ) ) {
176 tmplud.lud_exts = NULL;
177 tmplud.lud_crit_exts = 0;
180 tmpurl = ldap_url_desc2str( &tmplud );
182 if ( tmpurl == NULL ) {
183 fprintf( stderr, "%s: line %d: "
184 "unable to rebuild uri "
185 "in \"uri <uri>\" statement "
187 fname, lineno, argv[ 1 ] );
191 len = strlen( tmpurl );
193 oldlen = strlen( li->url ) + STRLENOF( " " );
195 li->url = ch_realloc( li->url, oldlen + len + 1);
197 li->url[oldlen - 1] = " ";
199 AC_MEMCPY( &li->url[oldlen], tmpurl, len + 1 );
203 li->url = ch_strdup( argv[ 1 ] );
206 /* name to use for ldap_back_group */
207 } else if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
208 || strcasecmp( argv[0], "binddn" ) == 0 ) {
211 "%s: line %d: missing name in \"%s <name>\" line\n",
212 fname, lineno, argv[0] );
215 ber_str2bv( argv[1], 0, 1, &li->acl_authcDN );
217 /* password to use for ldap_back_group */
218 } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
219 || strcasecmp( argv[0], "bindpw" ) == 0 ) {
222 "%s: line %d: missing password in \"%s <password>\" line\n",
223 fname, lineno, argv[0] );
226 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
228 #ifdef LDAP_BACK_PROXY_AUTHZ
229 /* identity assertion stuff... */
230 } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
231 || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 ) {
232 return parse_idassert( be, fname, lineno, argc, argv );
233 #endif /* LDAP_BACK_PROXY_AUTHZ */
235 /* save bind creds for referral rebinds? */
236 } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
239 "%s: line %d: rebind-as-user takes no arguments\n",
245 /* intercept exop_who_am_i? */
246 } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
249 "%s: line %d: proxy-whoami takes no arguments\n",
253 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
254 0, ldap_back_exop_whoami );
257 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
259 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
260 #ifdef ENABLE_REWRITE
262 #endif /* ENABLE_REWRITE */
267 * suffixmassage <suffix> <massaged suffix>
269 * the <suffix> field must be defined as a valid suffix
270 * (or suffixAlias?) for the current database;
271 * the <massaged suffix> shouldn't have already been
272 * defined as a valid suffix or suffixAlias for the
276 fprintf( stderr, "%s: line %d: syntax is"
277 " \"suffixMassage <suffix>"
278 " <massaged suffix>\"\n",
283 ber_str2bv( argv[1], 0, 0, &bvnc );
284 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
285 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
286 fname, lineno, bvnc.bv_val );
289 tmp_be = select_backend( &nvnc, 0, 0 );
290 if ( tmp_be != NULL && tmp_be != be ) {
291 fprintf( stderr, "%s: line %d: suffix already in use"
292 " by another backend in"
293 " \"suffixMassage <suffix>"
294 " <massaged suffix>\"\n",
301 ber_str2bv( argv[2], 0, 0, &brnc );
302 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
303 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
304 fname, lineno, brnc.bv_val );
311 tmp_be = select_backend( &nrnc, 0, 0 );
312 if ( tmp_be != NULL ) {
313 fprintf( stderr, "%s: line %d: massaged suffix"
314 " already in use by another backend in"
315 " \"suffixMassage <suffix>"
316 " <massaged suffix>\"\n",
326 #ifdef ENABLE_REWRITE
328 * The suffix massaging is emulated by means of the
329 * rewrite capabilities
330 * FIXME: no extra rewrite capabilities should be added
333 rc = suffix_massage_config( li->rwmap.rwm_rw,
334 &pvnc, &nvnc, &prnc, &nrnc );
342 #else /* !ENABLE_REWRITE */
343 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &pvnc );
344 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nvnc );
346 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &prnc );
347 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nrnc );
348 #endif /* !ENABLE_REWRITE */
350 /* rewrite stuff ... */
351 } else if ( strncasecmp( argv[0], "rewrite", 7 ) == 0 ) {
352 #ifdef ENABLE_REWRITE
353 return rewrite_parse( li->rwmap.rwm_rw,
354 fname, lineno, argc, argv );
356 #else /* !ENABLE_REWRITE */
357 fprintf( stderr, "%s: line %d: rewrite capabilities "
358 "are not enabled\n", fname, lineno );
359 #endif /* !ENABLE_REWRITE */
361 /* objectclass/attribute mapping */
362 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
363 return ldap_back_map_config( &li->rwmap.rwm_oc,
365 fname, lineno, argc, argv );
369 return SLAP_CONF_UNKNOWN;
375 ldap_back_map_config(
376 struct ldapmap *oc_map,
377 struct ldapmap *at_map,
384 struct ldapmapping *mapping;
388 if ( argc < 3 || argc > 4 ) {
390 "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
395 if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
399 } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
403 fprintf( stderr, "%s: line %d: syntax is "
404 "\"map {objectclass | attribute} [<local> | *] "
405 "{<foreign> | *}\"\n",
410 if ( strcmp( argv[2], "*" ) == 0 ) {
411 if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
412 map->drop_missing = ( argc < 4 );
417 } else if ( argc < 4 ) {
423 dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
426 if ( ( map == at_map )
427 && ( strcasecmp( src, "objectclass" ) == 0
428 || strcasecmp( dst, "objectclass" ) == 0 ) )
431 "%s: line %d: objectclass attribute cannot be mapped\n",
435 mapping = (struct ldapmapping *)ch_calloc( 2,
436 sizeof(struct ldapmapping) );
437 if ( mapping == NULL ) {
439 "%s: line %d: out of memory\n",
443 ber_str2bv( src, 0, 1, &mapping->src );
444 ber_str2bv( dst, 0, 1, &mapping->dst );
445 mapping[1].src = mapping->dst;
446 mapping[1].dst = mapping->src;
452 if ( src[0] != '\0' ) {
453 if ( oc_bvfind( &mapping->src ) == NULL ) {
455 "%s: line %d: warning, source objectClass '%s' "
456 "should be defined in schema\n",
457 fname, lineno, src );
460 * FIXME: this should become an err
466 if ( oc_bvfind( &mapping->dst ) == NULL ) {
468 "%s: line %d: warning, destination objectClass '%s' "
469 "is not defined in schema\n",
470 fname, lineno, dst );
474 const char *text = NULL;
475 AttributeDescription *ad = NULL;
477 if ( src[0] != '\0' ) {
478 rc = slap_bv2ad( &mapping->src, &ad, &text );
479 if ( rc != LDAP_SUCCESS ) {
481 "%s: line %d: warning, source attributeType '%s' "
482 "should be defined in schema\n",
483 fname, lineno, src );
486 * FIXME: this should become an err
494 rc = slap_bv2ad( &mapping->dst, &ad, &text );
495 if ( rc != LDAP_SUCCESS ) {
497 "%s: line %d: warning, destination attributeType '%s' "
498 "is not defined in schema\n",
499 fname, lineno, dst );
503 if ( (src[0] != '\0' && avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL)
504 || avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
507 "%s: line %d: duplicate mapping found (ignored)\n",
512 if ( src[0] != '\0' ) {
513 avl_insert( &map->map, (caddr_t)mapping,
514 mapping_cmp, mapping_dup );
516 avl_insert( &map->remap, (caddr_t)&mapping[1],
517 mapping_cmp, mapping_dup );
523 ch_free( mapping->src.bv_val );
524 ch_free( mapping->dst.bv_val );
532 ldap_back_exop_whoami(
536 struct berval *bv = NULL;
538 if ( op->oq_extended.rs_reqdata != NULL ) {
539 /* no request data should be provided */
540 rs->sr_text = "no request data expected";
541 return rs->sr_err = LDAP_PROTOCOL_ERROR;
544 rs->sr_err = backend_check_restrictions( op, rs,
545 (struct berval *)&slap_EXOP_WHOAMI );
546 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
548 /* if auth'd by back-ldap and request is proxied, forward it */
549 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)) {
552 LDAPControl c, *ctrls[2] = {NULL, NULL};
559 op2.o_ndn = op->o_conn->c_ndn;
560 lc = ldap_back_getconn(&op2, rs);
561 if (!lc || !ldap_back_dobind( lc, op, rs )) {
564 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
565 c.ldctl_iscritical = 1;
566 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
567 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
568 strcpy(c.ldctl_value.bv_val, "dn:");
569 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
572 rs->sr_err = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
573 if (rs->sr_err == LDAP_SUCCESS) {
574 if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
575 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
577 if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
579 if ( ldap_back_retry( lc, op, rs ) )
582 ldap_back_freeconn( op, lc );
586 rs->sr_err = ldap_parse_whoami(lc->ld, res, &bv);
590 ch_free(c.ldctl_value.bv_val);
591 if (rs->sr_err != LDAP_SUCCESS) {
592 rs->sr_err = slap_map_api2result( rs );
595 /* else just do the same as before */
596 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
597 if( op->o_dn.bv_len ) {
598 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
599 bv->bv_val = ch_malloc( bv->bv_len + 1 );
600 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
601 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
603 bv->bv_val[bv->bv_len] = '\0';
615 #ifdef ENABLE_REWRITE
617 suffix_massage_regexize( const char *s )
624 ( r = strchr( p, ',' ) ) != NULL;
628 res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
630 ptr = lutil_strcopy( res, "(.*)" );
632 ( r = strchr( p, ',' ) ) != NULL;
634 ptr = lutil_strncopy( ptr, p, r - p + 1 );
635 ptr = lutil_strcopy( ptr, "[ ]?" );
637 if ( r[ 1 ] == ' ' ) {
641 lutil_strcopy( ptr, p );
647 suffix_massage_patternize( const char *s )
654 res = ch_calloc( sizeof( char ), len + sizeof( "%1" ) );
660 strcpy( res + sizeof( "%1" ) - 1, s );
666 suffix_massage_config(
667 struct rewrite_info *info,
677 rargv[ 0 ] = "rewriteEngine";
680 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
682 rargv[ 0 ] = "rewriteContext";
683 rargv[ 1 ] = "default";
685 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
687 rargv[ 0 ] = "rewriteRule";
688 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
689 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val );
692 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
693 ch_free( rargv[ 1 ] );
694 ch_free( rargv[ 2 ] );
696 rargv[ 0 ] = "rewriteContext";
697 rargv[ 1 ] = "searchResult";
699 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
701 rargv[ 0 ] = "rewriteRule";
702 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
703 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val );
706 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
707 ch_free( rargv[ 1 ] );
708 ch_free( rargv[ 2 ] );
710 rargv[ 0 ] = "rewriteContext";
711 rargv[ 1 ] = "matchedDN";
712 rargv[ 2 ] = "alias";
713 rargv[ 3 ] = "searchResult";
715 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
717 rargv[ 0 ] = "rewriteContext";
718 rargv[ 1 ] = "searchAttrDN";
719 rargv[ 2 ] = "alias";
720 rargv[ 3 ] = "searchResult";
722 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
726 #endif /* ENABLE_REWRITE */
728 #ifdef LDAP_BACK_PROXY_AUTHZ
738 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
740 /* identity assertion mode */
741 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
743 Debug( LDAP_DEBUG_ANY,
744 "%s: line %d: illegal args number %d in \"idassert-mode <args>\" line.\n",
745 fname, lineno, argc );
749 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
750 /* will proxyAuthz as client's identity only if bound */
751 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
753 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
754 /* will proxyAuthz as client's identity */
755 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
757 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
758 /* will proxyAuthz as anonymous */
759 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
761 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
762 /* will not proxyAuthz */
763 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
769 /* will proxyAuthz as argv[1] */
770 ber_str2bv( argv[1], 0, 0, &id );
772 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
773 /* force lowercase... */
775 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
776 ber_dupbv( &li->idassert_authzID, &id );
782 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
783 id.bv_val += STRLENOF( "dn:" );
784 id.bv_len -= STRLENOF( "dn:" );
787 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
788 if ( rc != LDAP_SUCCESS ) {
789 Debug( LDAP_DEBUG_ANY,
790 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
791 fname, lineno, argv[1] );
795 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
796 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
797 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
798 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
799 ch_free( dn.bv_val );
801 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
805 /* name to use for proxyAuthz propagation */
806 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
807 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
812 /* FIXME: "proxyauthzdn" is no longer documented, and
813 * temporarily supported for backwards compatibility */
817 "%s: line %d: missing name in \"%s <name>\" line\n",
818 fname, lineno, argv[0] );
822 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
823 fprintf( stderr, "%s: line %d: "
824 "authcDN already defined; replacing...\n",
826 ch_free( li->idassert_authcDN.bv_val );
829 ber_str2bv( argv[1], 0, 0, &dn );
830 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
831 if ( rc != LDAP_SUCCESS ) {
832 Debug( LDAP_DEBUG_ANY,
833 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
834 fname, lineno, argv[1] );
838 /* password to use for proxyAuthz propagation */
839 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
840 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
842 /* FIXME: "proxyauthzpw" is no longer documented, and
843 * temporarily supported for backwards compatibility */
847 "%s: line %d: missing password in \"%s <password>\" line\n",
848 fname, lineno, argv[0] );
852 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
853 fprintf( stderr, "%s: line %d: "
854 "passwd already defined; replacing...\n",
856 ch_free( li->idassert_passwd.bv_val );
859 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
861 /* rules to accept identity assertion... */
862 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
865 ber_str2bv( argv[1], 0, 1, &rule );
867 ber_bvarray_add( &li->idassert_authz, &rule );
869 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
872 "%s: line %d: missing method in \"%s <method>\" line\n",
873 fname, lineno, argv[0] );
877 if ( strcasecmp( argv[1], "none" ) == 0 ) {
878 /* FIXME: is this useful? */
879 li->idassert_authmethod = LDAP_AUTH_NONE;
883 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
884 fname, lineno, argv[0], argv[1] );
887 } else if ( strcasecmp( argv[1], "simple" ) == 0 ) {
888 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
892 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
893 fname, lineno, argv[0], argv[1] );
896 } else if ( strcasecmp( argv[1], "sasl" ) == 0 ) {
897 #ifdef HAVE_CYRUS_SASL
900 for ( arg = 2; arg < argc; arg++ ) {
901 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
902 char *val = argv[arg] + STRLENOF( "mech=" );
904 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
905 fprintf( stderr, "%s: line %d: "
906 "SASL mech already defined; replacing...\n",
908 ch_free( li->idassert_sasl_mech.bv_val );
910 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
912 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
913 char *val = argv[arg] + STRLENOF( "realm=" );
915 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
916 fprintf( stderr, "%s: line %d: "
917 "SASL realm already defined; replacing...\n",
919 ch_free( li->idassert_sasl_realm.bv_val );
921 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
923 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
924 char *val = argv[arg] + STRLENOF( "authcdn=" );
928 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
929 fprintf( stderr, "%s: line %d: "
930 "SASL authcDN already defined; replacing...\n",
932 ch_free( li->idassert_authcDN.bv_val );
934 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
935 val += STRLENOF( "dn:" );
938 ber_str2bv( val, 0, 0, &dn );
939 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
940 if ( rc != LDAP_SUCCESS ) {
941 Debug( LDAP_DEBUG_ANY,
942 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
943 fname, lineno, val );
947 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
948 char *val = argv[arg] + STRLENOF( "authcid=" );
950 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
951 fprintf( stderr, "%s: line %d: "
952 "SASL authcID already defined; replacing...\n",
954 ch_free( li->idassert_authcID.bv_val );
956 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
957 val += STRLENOF( "u:" );
959 ber_str2bv( val, 0, 1, &li->idassert_authcID );
961 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
962 char *val = argv[arg] + STRLENOF( "cred=" );
964 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
965 fprintf( stderr, "%s: line %d: "
966 "SASL cred already defined; replacing...\n",
968 ch_free( li->idassert_passwd.bv_val );
970 ber_str2bv( val, 0, 1, &li->idassert_passwd );
972 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
973 char *val = argv[arg] + STRLENOF( "authz=" );
975 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
976 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
978 } else if ( strcasecmp( val, "native" ) == 0 ) {
979 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
982 fprintf( stderr, "%s: line %s: "
983 "unknown authz mode \"%s\"\n",
984 fname, lineno, val );
989 fprintf( stderr, "%s: line %d: "
990 "unknown SASL parameter %s\n",
991 fname, lineno, argv[arg] );
996 li->idassert_authmethod = LDAP_AUTH_SASL;
998 #else /* !HAVE_CYRUS_SASL */
999 fprintf( stderr, "%s: line %d: "
1000 "compile --with-cyrus-sasl to enable SASL auth\n",
1003 #endif /* !HAVE_CYRUS_SASL */
1006 fprintf( stderr, "%s: line %d: "
1007 "unhandled idassert-method method %s\n",
1008 fname, lineno, argv[1] );
1013 return SLAP_CONF_UNKNOWN;
1018 #endif /* LDAP_BACK_PROXY_AUTHZ */