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