]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/config.c
Happy New Year!
[openldap] / servers / slapd / back-ldap / config.c
1 /* config.c - ldap backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-2005 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
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>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33 #include "lutil.h"
34 #undef ldap_debug
35 /* for advanced URL parsing */
36 #include "../../../libraries/libldap/ldap-int.h"
37
38 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
39
40 static int
41 parse_idassert( BackendDB *be, const char *fname, int lineno,
42                 int argc, char **argv );
43
44 int
45 ldap_back_db_config(
46                 BackendDB       *be,
47                 const char      *fname,
48                 int             lineno,
49                 int             argc,
50                 char            **argv )
51 {
52         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
53
54         if ( li == NULL ) {
55                 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
56                                 fname, lineno );
57                 return 1;
58         }
59
60         /* server address to query (depricated, use "uri" directive) */
61         if ( strcasecmp( argv[0], "server" ) == 0 ) {
62                 ber_len_t       l;
63
64                 fprintf( stderr,
65         "%s: line %d: \"server <address>\" directive is deprecated\n",
66                                         fname, lineno );
67
68                 if ( argc != 2 ) {
69                         fprintf( stderr,
70         "%s: line %d: missing address in \"server <address>\" line\n",
71                                         fname, lineno );
72                         return 1;
73                 }
74                 if ( li->url != NULL ) {
75                         ch_free( li->url );
76                 }
77
78                 l = strlen( argv[1] ) + STRLENOF( "ldap:///") + 1;
79                 li->url = ch_calloc( l, sizeof( char ) );
80                 if ( li->url == NULL ) {
81                         fprintf( stderr, "%s: line %d: malloc failed\n" );
82                         return 1;
83                 }
84
85                 snprintf( li->url, l, "ldap://%s/", argv[1] );
86
87         /* URI of server to query (preferred over "server" directive) */
88         } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
89                 LDAPURLDesc     *tmpludp;
90                 int             urlrc, i;
91
92                 if ( argc != 2 ) {
93                         fprintf( stderr, "%s: line %d: "
94                                         "missing uri "
95                                         "in \"uri <uri>\" line\n",
96                                         fname, lineno );
97                         return 1;
98                 }
99                 if ( li->url != NULL ) {
100                         ch_free( li->url );
101                 }
102                 if ( li->lud != NULL ) {
103                         ldap_free_urllist( li->lud );
104                 }
105
106 #if 0
107                 /* PARANOID: DN and more are not required nor allowed */
108                 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
109 #else
110                 urlrc =  ldap_url_parselist( &li->lud, argv[ 1 ] );
111 #endif
112                 if ( urlrc != LDAP_URL_SUCCESS ) {
113                         char    *why;
114
115                         switch ( urlrc ) {
116                         case LDAP_URL_ERR_MEM:
117                                 why = "no memory";
118                                 break;
119                         case LDAP_URL_ERR_PARAM:
120                                 why = "parameter is bad";
121                                 break;
122                         case LDAP_URL_ERR_BADSCHEME:
123                                 why = "URL doesn't begin with \"[c]ldap[si]://\"";
124                                 break;
125                         case LDAP_URL_ERR_BADENCLOSURE:
126                                 why = "URL is missing trailing \">\"";
127                                 break;
128                         case LDAP_URL_ERR_BADURL:
129                                 why = "URL is bad";
130                         case LDAP_URL_ERR_BADHOST:
131                                 why = "host/port is bad";
132                                 break;
133                         case LDAP_URL_ERR_BADATTRS:
134                                 why = "bad (or missing) attributes";
135                                 break;
136                         case LDAP_URL_ERR_BADSCOPE:
137                                 why = "scope string is invalid (or missing)";
138                                 break;
139                         case LDAP_URL_ERR_BADFILTER:
140                                 why = "bad or missing filter";
141                                 break;
142                         case LDAP_URL_ERR_BADEXTS:
143                                 why = "bad or missing extensions";
144                                 break;
145                         default:
146                                 why = "unknown reason";
147                                 break;
148                         }
149                         fprintf( stderr, "%s: line %d: "
150                                         "unable to parse uri \"%s\" "
151                                         "in \"uri <uri>\" line: %s\n",
152                                         fname, lineno, argv[ 1 ], why );
153                         return 1;
154                 }
155
156                 for ( i = 0, tmpludp = li->lud;
157                                 tmpludp;
158                                 i++, tmpludp = tmpludp->lud_next )
159                 {
160                         if ( ( tmpludp->lud_dn != NULL
161                                                 && tmpludp->lud_dn[0] != '\0' )
162                                         || tmpludp->lud_attrs != NULL
163                                         || tmpludp->lud_filter != NULL
164                                         || tmpludp->lud_exts != NULL )
165                         {
166                                 fprintf( stderr, "%s: line %d: "
167                                                 "warning, only protocol, "
168                                                 "host and port allowed "
169                                                 "in \"uri <uri>\" statement "
170                                                 "for uri #%d of \"%s\"\n",
171                                                 fname, lineno, i, argv[1] );
172                         }
173                 }
174
175 #if 0
176                 for ( tmpludp = li->lud; tmpludp; tmpludp = tmpludp->lud_next ) {
177                         LDAPURLDesc     tmplud;
178                         char            *tmpurl;
179                         ber_len_t       oldlen = 0, len;
180
181                         tmplud = *tmpludp;
182                         tmplud.lud_dn = "";
183                         tmplud.lud_attrs = NULL;
184                         tmplud.lud_filter = NULL;
185                         if ( !ldap_is_ldapi_url( argv[ 1 ] ) ) {
186                                 tmplud.lud_exts = NULL;
187                                 tmplud.lud_crit_exts = 0;
188                         }
189
190                         tmpurl = ldap_url_desc2str( &tmplud );
191
192                         if ( tmpurl == NULL ) {
193                                 fprintf( stderr, "%s: line %d: "
194                                         "unable to rebuild uri "
195                                         "in \"uri <uri>\" statement "
196                                         "for \"%s\"\n",
197                                         fname, lineno, argv[ 1 ] );
198                                 return 1;
199                         }
200
201                         len = strlen( tmpurl );
202                         if ( li->url ) {
203                                 oldlen = strlen( li->url ) + STRLENOF( " " );
204                         }
205                         li->url = ch_realloc( li->url, oldlen + len + 1);
206                         if ( oldlen ) {
207                                 li->url[oldlen - 1] = " ";
208                         }
209                         AC_MEMCPY( &li->url[oldlen], tmpurl, len + 1 );
210                         ch_free( tmpurl );
211                 }
212 #else
213                 li->url = ch_strdup( argv[ 1 ] );
214 #endif
215
216         /* name to use for ldap_back_group */
217         } else if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
218                         || strcasecmp( argv[0], "binddn" ) == 0 ) {
219                 if ( argc != 2 ) {
220                         fprintf( stderr,
221         "%s: line %d: missing name in \"%s <name>\" line\n",
222                                         fname, lineno, argv[0] );
223                         return( 1 );
224                 }
225                 ber_str2bv( argv[1], 0, 1, &li->acl_authcDN );
226
227         /* password to use for ldap_back_group */
228         } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
229                         || strcasecmp( argv[0], "bindpw" ) == 0 ) {
230                 if ( argc != 2 ) {
231                         fprintf( stderr,
232         "%s: line %d: missing password in \"%s <password>\" line\n",
233                                         fname, lineno, argv[0] );
234                         return( 1 );
235                 }
236                 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
237
238 #ifdef LDAP_BACK_PROXY_AUTHZ
239         /* identity assertion stuff... */
240         } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
241                         || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 ) {
242                 return parse_idassert( be, fname, lineno, argc, argv );
243 #endif /* LDAP_BACK_PROXY_AUTHZ */
244
245         /* save bind creds for referral rebinds? */
246         } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
247                 if ( argc != 1 ) {
248                         fprintf( stderr,
249         "%s: line %d: rebind-as-user takes no arguments\n",
250                                         fname, lineno );
251                         return( 1 );
252                 }
253                 li->savecred = 1;
254         
255         /* intercept exop_who_am_i? */
256         } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
257                 if ( argc != 1 ) {
258                         fprintf( stderr,
259         "%s: line %d: proxy-whoami takes no arguments\n",
260                                         fname, lineno );
261                         return( 1 );
262                 }
263                 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
264                                 0, ldap_back_exop_whoami );
265
266         /* FIXME: legacy: intercept old rewrite/remap directives
267          * and try to start the rwm overlay */
268         } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
269                         || strcasecmp( argv[0], "map" ) == 0
270                         || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
271         {
272                 fprintf( stderr, "%s: line %d: "
273                         "rewrite/remap capabilities have been moved "
274                         "to the \"rwm\" overlay; see slapo-rwm(5) "
275                         "for details.  I'm trying to do my best "
276                         "to preserve backwards compatibility...\n",
277                         fname, lineno );
278
279                 if ( li->rwm_started == 0 ) {
280                         if ( overlay_config( be, "rwm" ) ) {
281                                 fprintf( stderr, "%s: line %d: "
282                                         "unable to configure the \"rwm\" "
283                                         "overlay, required by directive "
284                                         "\"%s\".\n",
285                                         fname, lineno, argv[0] );
286 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
287                                 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
288 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
289                                 return( 1 );
290                         }
291
292                         fprintf( stderr, "%s: line %d: back-ldap: "
293                                 "automatically starting \"rwm\" overlay, "
294                                 "triggered by \"%s\" directive.\n",
295                                 fname, lineno, argv[ 0 ] );
296
297                         li->rwm_started = 1;
298
299                         return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
300                 }
301
302                 return SLAP_CONF_UNKNOWN;
303         
304         /* anything else */
305         } else {
306                 return SLAP_CONF_UNKNOWN;
307         }
308
309         return 0;
310 }
311
312 static int
313 ldap_back_exop_whoami(
314                 Operation       *op,
315                 SlapReply       *rs )
316 {
317         struct berval *bv = NULL;
318
319         if ( op->oq_extended.rs_reqdata != NULL ) {
320                 /* no request data should be provided */
321                 rs->sr_text = "no request data expected";
322                 return rs->sr_err = LDAP_PROTOCOL_ERROR;
323         }
324
325         rs->sr_err = backend_check_restrictions( op, rs, 
326                         (struct berval *)&slap_EXOP_WHOAMI );
327         if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
328
329         /* if auth'd by back-ldap and request is proxied, forward it */
330         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)) {
331                 struct ldapconn *lc;
332
333                 LDAPControl c, *ctrls[2] = {NULL, NULL};
334                 LDAPMessage *res;
335                 Operation op2 = *op;
336                 ber_int_t msgid;
337                 int do_retry = 1;
338
339                 ctrls[0] = &c;
340                 op2.o_ndn = op->o_conn->c_ndn;
341                 lc = ldap_back_getconn(&op2, rs);
342                 if (!lc || !ldap_back_dobind( lc, op, rs )) {
343                         return -1;
344                 }
345                 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
346                 c.ldctl_iscritical = 1;
347                 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
348                 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
349                 strcpy(c.ldctl_value.bv_val, "dn:");
350                 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
351
352 retry:
353                 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
354                 if (rs->sr_err == LDAP_SUCCESS) {
355                         if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
356                                 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
357                                         &rs->sr_err);
358                                 if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
359                                         do_retry = 0;
360                                         if ( ldap_back_retry( lc, op, rs ) )
361                                                 goto retry;
362                                 }
363                                 ldap_back_freeconn( op, lc );
364                                 lc = NULL;
365
366                         } else {
367                                 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
368                                 ldap_msgfree(res);
369                         }
370                 }
371                 ch_free(c.ldctl_value.bv_val);
372                 if (rs->sr_err != LDAP_SUCCESS) {
373                         rs->sr_err = slap_map_api2result( rs );
374                 }
375         } else {
376         /* else just do the same as before */
377                 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
378                 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
379                         bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
380                         bv->bv_val = ch_malloc( bv->bv_len + 1 );
381                         AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
382                         AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
383                                 op->o_dn.bv_len );
384                         bv->bv_val[bv->bv_len] = '\0';
385                 } else {
386                         bv->bv_len = 0;
387                         bv->bv_val = NULL;
388                 }
389         }
390
391         rs->sr_rspdata = bv;
392         return rs->sr_err;
393 }
394
395
396 #ifdef LDAP_BACK_PROXY_AUTHZ
397 static int
398 parse_idassert(
399     BackendDB   *be,
400     const char  *fname,
401     int         lineno,
402     int         argc,
403     char        **argv
404 )
405 {
406         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
407
408         /* identity assertion mode */
409         if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
410                 if ( argc < 2 ) {
411                         Debug( LDAP_DEBUG_ANY,
412                                 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
413                                 fname, lineno, argc );
414                         return 1;
415                 }
416
417                 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
418                         /* will proxyAuthz as client's identity only if bound */
419                         li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
420
421                 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
422                         /* will proxyAuthz as client's identity */
423                         li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
424
425                 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
426                         /* will proxyAuthz as anonymous */
427                         li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
428
429                 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
430                         /* will not proxyAuthz */
431                         li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
432
433                 } else {
434                         struct berval   id;
435                         int             rc;
436
437                         /* will proxyAuthz as argv[1] */
438                         ber_str2bv( argv[1], 0, 0, &id );
439
440                         if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
441                                 /* force lowercase... */
442                                 id.bv_val[0] = 'u';
443                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
444                                 ber_dupbv( &li->idassert_authzID, &id );
445
446                         } else {
447                                 struct berval   dn;
448
449                                 /* default is DN? */
450                                 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
451                                         id.bv_val += STRLENOF( "dn:" );
452                                         id.bv_len -= STRLENOF( "dn:" );
453                                 }
454
455                                 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
456                                 if ( rc != LDAP_SUCCESS ) {
457                                         Debug( LDAP_DEBUG_ANY,
458                                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
459                                                 fname, lineno, argv[1] );
460                                         return 1;
461                                 }
462
463                                 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
464                                 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
465                                 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
466                                 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
467                                 ch_free( dn.bv_val );
468
469                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
470                         }
471                 }
472
473                 for ( argc -= 2, argv += 2; argc--; argv++ ) {
474                         if ( strcasecmp( argv[0], "override" ) == 0 ) {
475                                 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
476
477                         } else {
478                                 Debug( LDAP_DEBUG_ANY,
479                                         "%s: line %d: unknown flag \"%s\" "
480                                         "in \"idassert-mode <args> "
481                                         "[<flags>]\" line.\n",
482                                         fname, lineno, argv[0] );
483                                 return 1;
484                         }
485                 }
486
487         /* name to use for proxyAuthz propagation */
488         } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
489                         || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
490         {
491                 struct berval   dn;
492                 int             rc;
493
494                 /* FIXME: "proxyauthzdn" is no longer documented, and
495                  * temporarily supported for backwards compatibility */
496
497                 if ( argc != 2 ) {
498                         fprintf( stderr,
499         "%s: line %d: missing name in \"%s <name>\" line\n",
500                             fname, lineno, argv[0] );
501                         return( 1 );
502                 }
503
504                 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
505                         fprintf( stderr, "%s: line %d: "
506                                         "authcDN already defined; replacing...\n",
507                                         fname, lineno );
508                         ch_free( li->idassert_authcDN.bv_val );
509                 }
510                 
511                 ber_str2bv( argv[1], 0, 0, &dn );
512                 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, 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] );
517                         return 1;
518                 }
519
520         /* password to use for proxyAuthz propagation */
521         } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
522                         || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
523         {
524                 /* FIXME: "proxyauthzpw" is no longer documented, and
525                  * temporarily supported for backwards compatibility */
526
527                 if ( argc != 2 ) {
528                         fprintf( stderr,
529         "%s: line %d: missing password in \"%s <password>\" line\n",
530                             fname, lineno, argv[0] );
531                         return( 1 );
532                 }
533
534                 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
535                         fprintf( stderr, "%s: line %d: "
536                                         "passwd already defined; replacing...\n",
537                                         fname, lineno );
538                         ch_free( li->idassert_passwd.bv_val );
539                 }
540                 
541                 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
542
543         /* rules to accept identity assertion... */
544         } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
545                 struct berval   rule;
546
547                 ber_str2bv( argv[1], 0, 1, &rule );
548
549                 ber_bvarray_add( &li->idassert_authz, &rule );
550
551         } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
552                 if ( argc < 2 ) {
553                         fprintf( stderr,
554         "%s: line %d: missing method in \"%s <method>\" line\n",
555                             fname, lineno, argv[0] );
556                         return( 1 );
557                 }
558
559                 if ( strcasecmp( argv[1], "none" ) == 0 ) {
560                         /* FIXME: is this useful? */
561                         li->idassert_authmethod = LDAP_AUTH_NONE;
562
563                         if ( argc != 2 ) {
564                                 fprintf( stderr,
565         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
566                                         fname, lineno, argv[0], argv[1] );
567                         }
568
569                 } else if ( strcasecmp( argv[1], "simple" ) == 0 ) {
570                         li->idassert_authmethod = LDAP_AUTH_SIMPLE;
571
572                         if ( argc != 2 ) {
573                                 fprintf( stderr,
574         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
575                                         fname, lineno, argv[0], argv[1] );
576                         }
577
578                 } else if ( strcasecmp( argv[1], "sasl" ) == 0 ) {
579 #ifdef HAVE_CYRUS_SASL
580                         int     arg;
581
582                         for ( arg = 2; arg < argc; arg++ ) {
583                                 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
584                                         char    *val = argv[arg] + STRLENOF( "mech=" );
585
586                                         if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
587                                                 fprintf( stderr, "%s: line %d: "
588                                                                 "SASL mech already defined; replacing...\n",
589                                                                 fname, lineno );
590                                                 ch_free( li->idassert_sasl_mech.bv_val );
591                                         }
592                                         ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
593
594                                 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
595                                         char    *val = argv[arg] + STRLENOF( "realm=" );
596
597                                         if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
598                                                 fprintf( stderr, "%s: line %d: "
599                                                                 "SASL realm already defined; replacing...\n",
600                                                                 fname, lineno );
601                                                 ch_free( li->idassert_sasl_realm.bv_val );
602                                         }
603                                         ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
604
605                                 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
606                                         char            *val = argv[arg] + STRLENOF( "authcdn=" );
607                                         struct berval   dn;
608                                         int             rc;
609
610                                         if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
611                                                 fprintf( stderr, "%s: line %d: "
612                                                                 "SASL authcDN already defined; replacing...\n",
613                                                                 fname, lineno );
614                                                 ch_free( li->idassert_authcDN.bv_val );
615                                         }
616                                         if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
617                                                 val += STRLENOF( "dn:" );
618                                         }
619
620                                         ber_str2bv( val, 0, 0, &dn );
621                                         rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
622                                         if ( rc != LDAP_SUCCESS ) {
623                                                 Debug( LDAP_DEBUG_ANY,
624                                                         "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
625                                                         fname, lineno, val );
626                                                 return 1;
627                                         }
628
629                                 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
630                                         char    *val = argv[arg] + STRLENOF( "authcid=" );
631
632                                         if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
633                                                 fprintf( stderr, "%s: line %d: "
634                                                                 "SASL authcID already defined; replacing...\n",
635                                                                 fname, lineno );
636                                                 ch_free( li->idassert_authcID.bv_val );
637                                         }
638                                         if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
639                                                 val += STRLENOF( "u:" );
640                                         }
641                                         ber_str2bv( val, 0, 1, &li->idassert_authcID );
642
643                                 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
644                                         char    *val = argv[arg] + STRLENOF( "cred=" );
645
646                                         if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
647                                                 fprintf( stderr, "%s: line %d: "
648                                                                 "SASL cred already defined; replacing...\n",
649                                                                 fname, lineno );
650                                                 ch_free( li->idassert_passwd.bv_val );
651                                         }
652                                         ber_str2bv( val, 0, 1, &li->idassert_passwd );
653
654                                 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
655                                         char    *val = argv[arg] + STRLENOF( "authz=" );
656
657                                         if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
658                                                 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
659
660                                         } else if ( strcasecmp( val, "native" ) == 0 ) {
661                                                 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
662
663                                         } else {
664                                                 fprintf( stderr, "%s: line %s: "
665                                                         "unknown authz mode \"%s\"\n",
666                                                         fname, lineno, val );
667                                                 return 1;
668                                         }
669
670                                 } else {
671                                         fprintf( stderr, "%s: line %d: "
672                                                         "unknown SASL parameter %s\n",
673                                                         fname, lineno, argv[arg] );
674                                         return 1;
675                                 }
676                         }
677
678                         li->idassert_authmethod = LDAP_AUTH_SASL;
679
680 #else /* !HAVE_CYRUS_SASL */
681                         fprintf( stderr, "%s: line %d: "
682                                         "compile --with-cyrus-sasl to enable SASL auth\n",
683                                         fname, lineno );
684                         return 1;
685 #endif /* !HAVE_CYRUS_SASL */
686
687                 } else {
688                         fprintf( stderr, "%s: line %d: "
689                                         "unhandled idassert-method method %s\n",
690                                         fname, lineno, argv[1] );
691                         return 1;
692                 }
693
694         } else {
695                 return SLAP_CONF_UNKNOWN;
696         }
697
698         return 0;
699 }
700 #endif /* LDAP_BACK_PROXY_AUTHZ */