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