]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/config.c
Fix startup check
[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         } else if ( strncasecmp( argv[0], "tls-", STRLENOF( "tls-" ) ) == 0 ) {
217
218                 /* start tls */
219                 if ( strcasecmp( argv[0], "tls-start" ) == 0 ) {
220                         if ( argc != 1 ) {
221                                 fprintf( stderr,
222                 "%s: line %d: tls-start takes no arguments\n",
223                                                 fname, lineno );
224                                 return( 1 );
225                         }
226                         li->flags |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
227         
228                 /* try start tls */
229                 } else if ( strcasecmp( argv[0], "tls-try-start" ) == 0 ) {
230                         if ( argc != 1 ) {
231                                 fprintf( stderr,
232                 "%s: line %d: tls-try-start takes no arguments\n",
233                                                 fname, lineno );
234                                 return( 1 );
235                         }
236                         li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
237                         li->flags |= LDAP_BACK_F_USE_TLS;
238         
239                 /* propagate start tls */
240                 } else if ( strcasecmp( argv[0], "tls-propagate" ) == 0 ) {
241                         if ( argc != 1 ) {
242                                 fprintf( stderr,
243                 "%s: line %d: tls-propagate takes no arguments\n",
244                                                 fname, lineno );
245                                 return( 1 );
246                         }
247                         li->flags |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
248                 
249                 /* try start tls */
250                 } else if ( strcasecmp( argv[0], "tls-try-propagate" ) == 0 ) {
251                         if ( argc != 1 ) {
252                                 fprintf( stderr,
253                 "%s: line %d: tls-try-propagate takes no arguments\n",
254                                                 fname, lineno );
255                                 return( 1 );
256                         }
257                         li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
258                         li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
259                 }
260         
261         /* name to use for ldap_back_group */
262         } else if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
263                         || strcasecmp( argv[0], "binddn" ) == 0 )
264         {
265                 if ( argc != 2 ) {
266                         fprintf( stderr,
267         "%s: line %d: missing name in \"%s <name>\" line\n",
268                                         fname, lineno, argv[0] );
269                         return( 1 );
270                 }
271
272                 if ( strcasecmp( argv[0], "binddn" ) == 0 ) {
273                         fprintf( stderr, "%s: line %d: "
274                                 "\"binddn\" statement is deprecated; "
275                                 "use \"acl-authcDN\" instead\n",
276                                 fname, lineno );
277                         /* FIXME: some day we'll need to throw an error */
278                 }
279
280                 ber_str2bv( argv[1], 0, 1, &li->acl_authcDN );
281
282         /* password to use for ldap_back_group */
283         } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
284                         || strcasecmp( argv[0], "bindpw" ) == 0 )
285         {
286                 if ( argc != 2 ) {
287                         fprintf( stderr,
288         "%s: line %d: missing password in \"%s <password>\" line\n",
289                                         fname, lineno, argv[0] );
290                         return( 1 );
291                 }
292
293                 if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
294                         fprintf( stderr, "%s: line %d: "
295                                 "\"bindpw\" statement is deprecated; "
296                                 "use \"acl-passwd\" instead\n",
297                                 fname, lineno );
298                         /* FIXME: some day we'll need to throw an error */
299                 }
300
301                 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
302
303         /* identity assertion stuff... */
304         } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
305                         || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
306         {
307                 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
308                  * deprected and undocumented, it can be dropped at some
309                  * point, since nobody should be really using it */
310                 return parse_idassert( be, fname, lineno, argc, argv );
311
312         /* save bind creds for referral rebinds? */
313         } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
314                 if ( argc != 1 ) {
315                         fprintf( stderr,
316         "%s: line %d: \"rebind-as-user\" takes no arguments\n",
317                                         fname, lineno );
318                         return( 1 );
319                 }
320                 li->flags |= LDAP_BACK_F_SAVECRED;
321
322         } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
323                 if ( argc != 1 ) {
324                         fprintf( stderr,
325         "%s: line %d: \"chase-referrals\" takes no arguments\n",
326                                         fname, lineno );
327                         return( 1 );
328                 }
329
330                 li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
331
332         } else if ( strcasecmp( argv[0], "dont-chase-referrals" ) == 0 ) {
333                 if ( argc != 1 ) {
334                         fprintf( stderr,
335         "%s: line %d: \"dont-chase-referrals\" takes no arguments\n",
336                                         fname, lineno );
337                         return( 1 );
338                 }
339
340                 li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
341
342         /* intercept exop_who_am_i? */
343         } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
344                 if ( argc != 1 ) {
345                         fprintf( stderr,
346         "%s: line %d: proxy-whoami takes no arguments\n",
347                                         fname, lineno );
348                         return( 1 );
349                 }
350                 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
351                                 0, ldap_back_exop_whoami );
352
353         /* FIXME: legacy: intercept old rewrite/remap directives
354          * and try to start the rwm overlay */
355         } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
356                         || strcasecmp( argv[0], "map" ) == 0
357                         || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
358         {
359                 fprintf( stderr, "%s: line %d: "
360                         "rewrite/remap capabilities have been moved "
361                         "to the \"rwm\" overlay; see slapo-rwm(5) "
362                         "for details.  I'm trying to do my best "
363                         "to preserve backwards compatibility...\n",
364                         fname, lineno );
365
366                 if ( li->rwm_started == 0 ) {
367                         if ( overlay_config( be, "rwm" ) ) {
368                                 fprintf( stderr, "%s: line %d: "
369                                         "unable to configure the \"rwm\" "
370                                         "overlay, required by directive "
371                                         "\"%s\".\n",
372                                         fname, lineno, argv[0] );
373 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
374                                 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
375 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
376                                 return( 1 );
377                         }
378
379                         fprintf( stderr, "%s: line %d: back-ldap: "
380                                 "automatically starting \"rwm\" overlay, "
381                                 "triggered by \"%s\" directive.\n",
382                                 fname, lineno, argv[ 0 ] );
383
384                         li->rwm_started = 1;
385
386                         return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
387                 }
388
389                 return SLAP_CONF_UNKNOWN;
390         
391         /* anything else */
392         } else {
393                 return SLAP_CONF_UNKNOWN;
394         }
395
396         return 0;
397 }
398
399 static int
400 ldap_back_exop_whoami(
401                 Operation       *op,
402                 SlapReply       *rs )
403 {
404         struct berval *bv = NULL;
405
406         if ( op->oq_extended.rs_reqdata != NULL ) {
407                 /* no request data should be provided */
408                 rs->sr_text = "no request data expected";
409                 return rs->sr_err = LDAP_PROTOCOL_ERROR;
410         }
411
412         rs->sr_err = backend_check_restrictions( op, rs, 
413                         (struct berval *)&slap_EXOP_WHOAMI );
414         if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
415
416         /* if auth'd by back-ldap and request is proxied, forward it */
417         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)) {
418                 struct ldapconn *lc;
419
420                 LDAPControl c, *ctrls[2] = {NULL, NULL};
421                 LDAPMessage *res;
422                 Operation op2 = *op;
423                 ber_int_t msgid;
424                 int do_retry = 1;
425
426                 ctrls[0] = &c;
427                 op2.o_ndn = op->o_conn->c_ndn;
428                 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
429                 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
430                         return -1;
431                 }
432                 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
433                 c.ldctl_iscritical = 1;
434                 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
435                 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
436                 strcpy(c.ldctl_value.bv_val, "dn:");
437                 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
438
439 retry:
440                 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
441                 if (rs->sr_err == LDAP_SUCCESS) {
442                         if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
443                                 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
444                                         &rs->sr_err);
445                                 if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
446                                         do_retry = 0;
447                                         if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
448                                                 goto retry;
449                                 }
450                                 ldap_back_freeconn( op, lc );
451                                 lc = NULL;
452
453                         } else {
454                                 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
455                                 ldap_msgfree(res);
456                         }
457                 }
458                 ch_free(c.ldctl_value.bv_val);
459                 if (rs->sr_err != LDAP_SUCCESS) {
460                         rs->sr_err = slap_map_api2result( rs );
461                 }
462         } else {
463         /* else just do the same as before */
464                 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
465                 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
466                         bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
467                         bv->bv_val = ch_malloc( bv->bv_len + 1 );
468                         AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
469                         AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
470                                 op->o_dn.bv_len );
471                         bv->bv_val[bv->bv_len] = '\0';
472                 } else {
473                         bv->bv_len = 0;
474                         bv->bv_val = NULL;
475                 }
476         }
477
478         rs->sr_rspdata = bv;
479         return rs->sr_err;
480 }
481
482
483 static int
484 parse_idassert(
485     BackendDB   *be,
486     const char  *fname,
487     int         lineno,
488     int         argc,
489     char        **argv
490 )
491 {
492         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
493
494         /* identity assertion mode */
495         if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
496                 if ( argc < 2 ) {
497                         Debug( LDAP_DEBUG_ANY,
498                                 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
499                                 fname, lineno, argc );
500                         return 1;
501                 }
502
503                 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
504                         /* will proxyAuthz as client's identity only if bound */
505                         li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
506
507                 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
508                         /* will proxyAuthz as client's identity */
509                         li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
510
511                 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
512                         /* will proxyAuthz as anonymous */
513                         li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
514
515                 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
516                         /* will not proxyAuthz */
517                         li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
518
519                 } else {
520                         struct berval   id;
521                         int             rc;
522
523                         /* will proxyAuthz as argv[1] */
524                         ber_str2bv( argv[1], 0, 0, &id );
525
526                         if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
527                                 /* force lowercase... */
528                                 id.bv_val[0] = 'u';
529                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
530                                 ber_dupbv( &li->idassert_authzID, &id );
531
532                         } else {
533                                 struct berval   dn;
534
535                                 /* default is DN? */
536                                 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
537                                         id.bv_val += STRLENOF( "dn:" );
538                                         id.bv_len -= STRLENOF( "dn:" );
539                                 }
540
541                                 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
542                                 if ( rc != LDAP_SUCCESS ) {
543                                         Debug( LDAP_DEBUG_ANY,
544                                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
545                                                 fname, lineno, argv[1] );
546                                         return 1;
547                                 }
548
549                                 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
550                                 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
551                                 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
552                                 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
553                                 ch_free( dn.bv_val );
554
555                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
556                         }
557                 }
558
559                 for ( argc -= 2, argv += 2; argc--; argv++ ) {
560                         if ( strcasecmp( argv[0], "override" ) == 0 ) {
561                                 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
562
563                         } else {
564                                 Debug( LDAP_DEBUG_ANY,
565                                         "%s: line %d: unknown flag \"%s\" "
566                                         "in \"idassert-mode <args> "
567                                         "[<flags>]\" line.\n",
568                                         fname, lineno, argv[0] );
569                                 return 1;
570                         }
571                 }
572
573         /* name to use for proxyAuthz propagation */
574         } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
575                         || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
576         {
577                 struct berval   dn;
578                 int             rc;
579
580                 /* FIXME: "proxyauthzdn" is no longer documented, and
581                  * temporarily supported for backwards compatibility */
582
583                 if ( argc != 2 ) {
584                         fprintf( stderr,
585         "%s: line %d: missing name in \"%s <name>\" line\n",
586                             fname, lineno, argv[0] );
587                         return( 1 );
588                 }
589
590                 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
591                         fprintf( stderr, "%s: line %d: "
592                                         "authcDN already defined; replacing...\n",
593                                         fname, lineno );
594                         ch_free( li->idassert_authcDN.bv_val );
595                 }
596                 
597                 ber_str2bv( argv[1], 0, 0, &dn );
598                 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
599                 if ( rc != LDAP_SUCCESS ) {
600                         Debug( LDAP_DEBUG_ANY,
601                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
602                                 fname, lineno, argv[1] );
603                         return 1;
604                 }
605
606         /* password to use for proxyAuthz propagation */
607         } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
608                         || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
609         {
610                 /* FIXME: "proxyauthzpw" is no longer documented, and
611                  * temporarily supported for backwards compatibility */
612
613                 if ( argc != 2 ) {
614                         fprintf( stderr,
615         "%s: line %d: missing password in \"%s <password>\" line\n",
616                             fname, lineno, argv[0] );
617                         return( 1 );
618                 }
619
620                 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
621                         fprintf( stderr, "%s: line %d: "
622                                         "passwd already defined; replacing...\n",
623                                         fname, lineno );
624                         ch_free( li->idassert_passwd.bv_val );
625                 }
626                 
627                 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
628
629         /* rules to accept identity assertion... */
630         } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
631                 struct berval   rule;
632
633                 ber_str2bv( argv[1], 0, 1, &rule );
634
635                 ber_bvarray_add( &li->idassert_authz, &rule );
636
637         } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
638                 if ( argc < 2 ) {
639                         fprintf( stderr,
640         "%s: line %d: missing method in \"%s <method>\" line\n",
641                             fname, lineno, argv[0] );
642                         return( 1 );
643                 }
644
645                 if ( strcasecmp( argv[1], "none" ) == 0 ) {
646                         /* FIXME: is this at all useful? */
647                         li->idassert_authmethod = LDAP_AUTH_NONE;
648
649                         if ( argc != 2 ) {
650                                 fprintf( stderr,
651         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
652                                         fname, lineno, argv[0], argv[1] );
653                         }
654
655                 } else if ( strcasecmp( argv[1], "simple" ) == 0 ) {
656                         li->idassert_authmethod = LDAP_AUTH_SIMPLE;
657
658                         if ( argc != 2 ) {
659                                 fprintf( stderr,
660         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
661                                         fname, lineno, argv[0], argv[1] );
662                         }
663
664                 } else if ( strcasecmp( argv[1], "sasl" ) == 0 ) {
665 #ifdef HAVE_CYRUS_SASL
666                         int     arg;
667
668                         for ( arg = 2; arg < argc; arg++ ) {
669                                 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
670                                         char    *val = argv[arg] + STRLENOF( "mech=" );
671
672                                         if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
673                                                 fprintf( stderr, "%s: line %d: "
674                                                                 "SASL mech already defined; replacing...\n",
675                                                                 fname, lineno );
676                                                 ch_free( li->idassert_sasl_mech.bv_val );
677                                         }
678                                         ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
679
680                                 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
681                                         char    *val = argv[arg] + STRLENOF( "realm=" );
682
683                                         if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
684                                                 fprintf( stderr, "%s: line %d: "
685                                                                 "SASL realm already defined; replacing...\n",
686                                                                 fname, lineno );
687                                                 ch_free( li->idassert_sasl_realm.bv_val );
688                                         }
689                                         ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
690
691                                 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
692                                         char            *val = argv[arg] + STRLENOF( "authcdn=" );
693                                         struct berval   dn;
694                                         int             rc;
695
696                                         if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
697                                                 fprintf( stderr, "%s: line %d: "
698                                                                 "SASL authcDN already defined; replacing...\n",
699                                                                 fname, lineno );
700                                                 ch_free( li->idassert_authcDN.bv_val );
701                                         }
702                                         if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
703                                                 val += STRLENOF( "dn:" );
704                                         }
705
706                                         ber_str2bv( val, 0, 0, &dn );
707                                         rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
708                                         if ( rc != LDAP_SUCCESS ) {
709                                                 Debug( LDAP_DEBUG_ANY,
710                                                         "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
711                                                         fname, lineno, val );
712                                                 return 1;
713                                         }
714
715                                 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
716                                         char    *val = argv[arg] + STRLENOF( "authcid=" );
717
718                                         if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
719                                                 fprintf( stderr, "%s: line %d: "
720                                                                 "SASL authcID already defined; replacing...\n",
721                                                                 fname, lineno );
722                                                 ch_free( li->idassert_authcID.bv_val );
723                                         }
724                                         if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
725                                                 val += STRLENOF( "u:" );
726                                         }
727                                         ber_str2bv( val, 0, 1, &li->idassert_authcID );
728
729                                 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
730                                         char    *val = argv[arg] + STRLENOF( "cred=" );
731
732                                         if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
733                                                 fprintf( stderr, "%s: line %d: "
734                                                                 "SASL cred already defined; replacing...\n",
735                                                                 fname, lineno );
736                                                 ch_free( li->idassert_passwd.bv_val );
737                                         }
738                                         ber_str2bv( val, 0, 1, &li->idassert_passwd );
739
740                                 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
741                                         char    *val = argv[arg] + STRLENOF( "authz=" );
742
743                                         if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
744                                                 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
745
746                                         } else if ( strcasecmp( val, "native" ) == 0 ) {
747                                                 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
748
749                                         } else {
750                                                 fprintf( stderr, "%s: line %d: "
751                                                         "unknown authz mode \"%s\"\n",
752                                                         fname, lineno, val );
753                                                 return 1;
754                                         }
755
756                                 } else {
757                                         fprintf( stderr, "%s: line %d: "
758                                                         "unknown SASL parameter %s\n",
759                                                         fname, lineno, argv[arg] );
760                                         return 1;
761                                 }
762                         }
763
764                         li->idassert_authmethod = LDAP_AUTH_SASL;
765
766 #else /* !HAVE_CYRUS_SASL */
767                         fprintf( stderr, "%s: line %d: "
768                                         "compile --with-cyrus-sasl to enable SASL auth\n",
769                                         fname, lineno );
770                         return 1;
771 #endif /* !HAVE_CYRUS_SASL */
772
773                 } else {
774                         fprintf( stderr, "%s: line %d: "
775                                         "unhandled idassert-method method %s\n",
776                                         fname, lineno, argv[1] );
777                         return 1;
778                 }
779
780         } else {
781                 return SLAP_CONF_UNKNOWN;
782         }
783
784         return 0;
785 }