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};
558 op2.o_ndn = op->o_conn->c_ndn;
559 lc = ldap_back_getconn(&op2, rs);
560 if (!lc || !ldap_back_dobind( lc, op, rs )) {
563 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
564 c.ldctl_iscritical = 1;
565 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
566 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
567 strcpy(c.ldctl_value.bv_val, "dn:");
568 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
570 rs->sr_err = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
571 if (rs->sr_err == LDAP_SUCCESS) {
572 if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
573 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
575 ldap_back_freeconn( op, lc );
579 rs->sr_err = ldap_parse_whoami(lc->ld, res, &bv);
583 ch_free(c.ldctl_value.bv_val);
584 if (rs->sr_err != LDAP_SUCCESS) {
585 rs->sr_err = slap_map_api2result( rs );
588 /* else just do the same as before */
589 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
590 if( op->o_dn.bv_len ) {
591 bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
592 bv->bv_val = ch_malloc( bv->bv_len + 1 );
593 AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
594 AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
596 bv->bv_val[bv->bv_len] = '\0';
608 #ifdef ENABLE_REWRITE
610 suffix_massage_regexize( const char *s )
617 ( r = strchr( p, ',' ) ) != NULL;
621 res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
623 ptr = lutil_strcopy( res, "(.*)" );
625 ( r = strchr( p, ',' ) ) != NULL;
627 ptr = lutil_strncopy( ptr, p, r - p + 1 );
628 ptr = lutil_strcopy( ptr, "[ ]?" );
630 if ( r[ 1 ] == ' ' ) {
634 lutil_strcopy( ptr, p );
640 suffix_massage_patternize( const char *s )
647 res = ch_calloc( sizeof( char ), len + sizeof( "%1" ) );
653 strcpy( res + sizeof( "%1" ) - 1, s );
659 suffix_massage_config(
660 struct rewrite_info *info,
670 rargv[ 0 ] = "rewriteEngine";
673 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
675 rargv[ 0 ] = "rewriteContext";
676 rargv[ 1 ] = "default";
678 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
680 rargv[ 0 ] = "rewriteRule";
681 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
682 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val );
685 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
686 ch_free( rargv[ 1 ] );
687 ch_free( rargv[ 2 ] );
689 rargv[ 0 ] = "rewriteContext";
690 rargv[ 1 ] = "searchResult";
692 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
694 rargv[ 0 ] = "rewriteRule";
695 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
696 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val );
699 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
700 ch_free( rargv[ 1 ] );
701 ch_free( rargv[ 2 ] );
703 rargv[ 0 ] = "rewriteContext";
704 rargv[ 1 ] = "matchedDN";
705 rargv[ 2 ] = "alias";
706 rargv[ 3 ] = "searchResult";
708 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
710 rargv[ 0 ] = "rewriteContext";
711 rargv[ 1 ] = "searchAttrDN";
712 rargv[ 2 ] = "alias";
713 rargv[ 3 ] = "searchResult";
715 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
719 #endif /* ENABLE_REWRITE */
721 #ifdef LDAP_BACK_PROXY_AUTHZ
731 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
733 /* identity assertion mode */
734 if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
736 Debug( LDAP_DEBUG_ANY,
737 "%s: line %d: illegal args number %d in \"idassert-mode <args>\" line.\n",
738 fname, lineno, argc );
742 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
743 /* will proxyAuthz as client's identity only if bound */
744 li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
746 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
747 /* will proxyAuthz as client's identity */
748 li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
750 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
751 /* will proxyAuthz as anonymous */
752 li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
754 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
755 /* will not proxyAuthz */
756 li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
762 /* will proxyAuthz as argv[1] */
763 ber_str2bv( argv[1], 0, 0, &id );
765 if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
766 /* force lowercase... */
768 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
769 ber_dupbv( &li->idassert_authzID, &id );
775 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
776 id.bv_val += STRLENOF( "dn:" );
777 id.bv_len -= STRLENOF( "dn:" );
780 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
781 if ( rc != LDAP_SUCCESS ) {
782 Debug( LDAP_DEBUG_ANY,
783 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
784 fname, lineno, argv[1] );
788 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
789 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
790 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
791 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
792 ch_free( dn.bv_val );
794 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
798 /* name to use for proxyAuthz propagation */
799 } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
800 || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
805 /* FIXME: "proxyauthzdn" is no longer documented, and
806 * temporarily supported for backwards compatibility */
810 "%s: line %d: missing name in \"%s <name>\" line\n",
811 fname, lineno, argv[0] );
815 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
816 fprintf( stderr, "%s: line %d: "
817 "authcDN already defined; replacing...\n",
819 ch_free( li->idassert_authcDN.bv_val );
822 ber_str2bv( argv[1], 0, 0, &dn );
823 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
824 if ( rc != LDAP_SUCCESS ) {
825 Debug( LDAP_DEBUG_ANY,
826 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
827 fname, lineno, argv[1] );
831 /* password to use for proxyAuthz propagation */
832 } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
833 || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
835 /* FIXME: "proxyauthzpw" is no longer documented, and
836 * temporarily supported for backwards compatibility */
840 "%s: line %d: missing password in \"%s <password>\" line\n",
841 fname, lineno, argv[0] );
845 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
846 fprintf( stderr, "%s: line %d: "
847 "passwd already defined; replacing...\n",
849 ch_free( li->idassert_passwd.bv_val );
852 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
854 /* rules to accept identity assertion... */
855 } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
858 ber_str2bv( argv[1], 0, 1, &rule );
860 ber_bvarray_add( &li->idassert_authz, &rule );
862 } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
865 "%s: line %d: missing method in \"%s <method>\" line\n",
866 fname, lineno, argv[0] );
870 if ( strcasecmp( argv[1], "none" ) == 0 ) {
871 /* FIXME: is this useful? */
872 li->idassert_authmethod = LDAP_AUTH_NONE;
876 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
877 fname, lineno, argv[0], argv[1] );
880 } else if ( strcasecmp( argv[1], "simple" ) == 0 ) {
881 li->idassert_authmethod = LDAP_AUTH_SIMPLE;
885 "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
886 fname, lineno, argv[0], argv[1] );
889 } else if ( strcasecmp( argv[1], "sasl" ) == 0 ) {
890 #ifdef HAVE_CYRUS_SASL
893 for ( arg = 2; arg < argc; arg++ ) {
894 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
895 char *val = argv[arg] + STRLENOF( "mech=" );
897 if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
898 fprintf( stderr, "%s: line %d: "
899 "SASL mech already defined; replacing...\n",
901 ch_free( li->idassert_sasl_mech.bv_val );
903 ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
905 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
906 char *val = argv[arg] + STRLENOF( "realm=" );
908 if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
909 fprintf( stderr, "%s: line %d: "
910 "SASL realm already defined; replacing...\n",
912 ch_free( li->idassert_sasl_realm.bv_val );
914 ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
916 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
917 char *val = argv[arg] + STRLENOF( "authcdn=" );
921 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
922 fprintf( stderr, "%s: line %d: "
923 "SASL authcDN already defined; replacing...\n",
925 ch_free( li->idassert_authcDN.bv_val );
927 if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
928 val += STRLENOF( "dn:" );
931 ber_str2bv( val, 0, 0, &dn );
932 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
933 if ( rc != LDAP_SUCCESS ) {
934 Debug( LDAP_DEBUG_ANY,
935 "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
936 fname, lineno, val );
940 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
941 char *val = argv[arg] + STRLENOF( "authcid=" );
943 if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
944 fprintf( stderr, "%s: line %d: "
945 "SASL authcID already defined; replacing...\n",
947 ch_free( li->idassert_authcID.bv_val );
949 if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
950 val += STRLENOF( "u:" );
952 ber_str2bv( val, 0, 1, &li->idassert_authcID );
954 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
955 char *val = argv[arg] + STRLENOF( "cred=" );
957 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
958 fprintf( stderr, "%s: line %d: "
959 "SASL cred already defined; replacing...\n",
961 ch_free( li->idassert_passwd.bv_val );
963 ber_str2bv( val, 0, 1, &li->idassert_passwd );
965 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
966 char *val = argv[arg] + STRLENOF( "authz=" );
968 if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
969 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
971 } else if ( strcasecmp( val, "native" ) == 0 ) {
972 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
975 fprintf( stderr, "%s: line %s: "
976 "unknown authz mode \"%s\"\n",
977 fname, lineno, val );
982 fprintf( stderr, "%s: line %d: "
983 "unknown SASL parameter %s\n",
984 fname, lineno, argv[arg] );
989 li->idassert_authmethod = LDAP_AUTH_SASL;
991 #else /* !HAVE_CYRUS_SASL */
992 fprintf( stderr, "%s: line %d: "
993 "compile --with-cyrus-sasl to enable SASL auth\n",
996 #endif /* !HAVE_CYRUS_SASL */
999 fprintf( stderr, "%s: line %d: "
1000 "unhandled idassert-method method %s\n",
1001 fname, lineno, argv[1] );
1006 return SLAP_CONF_UNKNOWN;
1011 #endif /* LDAP_BACK_PROXY_AUTHZ */