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