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