]> git.sur5r.net Git - openldap/blob - servers/slapd/sasl.c
ITS#1882: fix typo
[openldap] / servers / slapd / sasl.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10 #include <ac/stdlib.h>
11 #include <ac/string.h>
12
13 #include <lber.h>
14 #include <ldap_log.h>
15
16 #include "slap.h"
17
18 #ifdef HAVE_CYRUS_SASL
19 #include <limits.h>
20
21 #ifdef HAVE_SASL_SASL_H
22 #include <sasl/sasl.h>
23 #else
24 #include <sasl.h>
25 #endif
26
27 #if SASL_VERSION_MAJOR >= 2
28 #include <lutil.h>
29 #include <sasl/saslplug.h>
30 #define SASL_CONST const
31 #else
32 #define SASL_CONST
33 #endif
34
35 #include <ldap_pvt.h>
36
37 #ifdef SLAPD_SPASSWD
38 #include <lutil.h>
39 #endif
40
41 /* Flags for telling slap_sasl_getdn() what type of identity is being passed */
42 #define FLAG_GETDN_AUTHCID 2
43 #define FLAG_GETDN_AUTHZID 4
44
45 static sasl_security_properties_t sasl_secprops;
46
47 static int
48 slap_sasl_log(
49         void *context,
50         int priority,
51         const char *message) 
52 {
53         Connection *conn = context;
54         int level;
55         const char * label;
56
57         if ( message == NULL ) {
58                 return SASL_BADPARAM;
59         }
60
61         switch (priority) {
62 #if SASL_VERSION_MAJOR >= 2
63         case SASL_LOG_NONE:
64                 level = LDAP_DEBUG_NONE;
65                 label = "None";
66                 break;
67         case SASL_LOG_ERR:
68                 level = LDAP_DEBUG_ANY;
69                 label = "Error";
70                 break;
71         case SASL_LOG_FAIL:
72                 level = LDAP_DEBUG_ANY;
73                 label = "Failure";
74                 break;
75         case SASL_LOG_WARN:
76                 level = LDAP_DEBUG_TRACE;
77                 label = "Warning";
78                 break;
79         case SASL_LOG_NOTE:
80                 level = LDAP_DEBUG_TRACE;
81                 label = "Notice";
82                 break;
83         case SASL_LOG_DEBUG:
84                 level = LDAP_DEBUG_TRACE;
85                 label = "Debug";
86                 break;
87         case SASL_LOG_TRACE:
88                 level = LDAP_DEBUG_TRACE;
89                 label = "Trace";
90                 break;
91         case SASL_LOG_PASS:
92                 level = LDAP_DEBUG_TRACE;
93                 label = "Password Trace";
94                 break;
95 #else
96         case SASL_LOG_ERR:
97                 level = LDAP_DEBUG_ANY;
98                 label = "Error";
99                 break;
100         case SASL_LOG_WARNING:
101                 level = LDAP_DEBUG_TRACE;
102                 label = "Warning";
103                 break;
104         case SASL_LOG_INFO:
105                 level = LDAP_DEBUG_TRACE;
106                 label = "Info";
107                 break;
108 #endif
109         default:
110                 return SASL_BADPARAM;
111         }
112
113 #ifdef NEW_LOGGING
114         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
115                 "SASL [conn=%ld] %s: %s\n",
116                 conn ? conn->c_connid : -1,
117                 label, message ));
118 #else
119         Debug( level, "SASL [conn=%ld] %s: %s\n",
120                 conn ? conn->c_connid: -1,
121                 label, message );
122 #endif
123
124
125         return SASL_OK;
126 }
127
128
129 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
130    string returned in *dn is in its own allocated memory, and must be free'd 
131    by the calling process.
132    -Mark Adamson, Carnegie Mellon
133
134    The "dn:" prefix is no longer used anywhere inside slapd. It is only used
135    on strings passed in directly from SASL.
136    -Howard Chu, Symas Corp.
137 */
138
139 #define SET_DN  1
140 #define SET_U   2
141
142 static struct berval ext_bv = { sizeof("EXTERNAL")-1, "EXTERNAL" };
143
144 int slap_sasl_getdn( Connection *conn, char *id, int len,
145         char *user_realm, struct berval *dn, int flags )
146 {
147         char *c1;
148         int rc, is_dn = 0, do_norm = 1;
149         sasl_conn_t *ctx;
150         struct berval dn2;
151
152 #ifdef NEW_LOGGING
153         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
154                 "slap_sasl_getdn: conn %d id=%s\n",
155                 conn ? conn->c_connid : -1,
156                 id ? (*id ? id : "<empty>") : "NULL" ));
157 #else
158         Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: id=%s\n", 
159       id?(*id?id:"<empty>"):"NULL",0,0 );
160 #endif
161
162         dn->bv_val = NULL;
163         dn->bv_len = 0;
164
165         if ( id ) {
166                 if ( len == 0 ) len = strlen( id );
167
168                 /* Blatantly anonymous ID */
169                 if ( len == sizeof("anonymous") - 1 &&
170                         !strcasecmp( id, "anonymous" ) ) {
171                         return( LDAP_SUCCESS );
172                 }
173         } else {
174                 len = 0;
175         }
176
177         ctx = conn->c_sasl_context;
178
179         /* An authcID needs to be converted to authzID form. Set the
180          * values directly into *dn; they will be normalized later. (and
181          * normalizing always makes a new copy.) An ID from a TLS certificate
182          * is already normalized, so copy it and skip normalization.
183          */
184         if( flags & FLAG_GETDN_AUTHCID ) {
185 #ifdef HAVE_TLS
186                 if( conn->c_is_tls && conn->c_sasl_bind_mech.bv_len == ext_bv.bv_len
187                         && ( strcasecmp( ext_bv.bv_val, conn->c_sasl_bind_mech.bv_val ) == 0 ) ) {
188                         /* X.509 DN is already normalized */
189                         do_norm = 0;
190                         is_dn = SET_DN;
191                         ber_str2bv( id, len, 1, dn );
192
193                 } else
194 #endif
195                 {
196                         /* convert to u:<username> form */
197                         is_dn = SET_U;
198                         dn->bv_val = id;
199                         dn->bv_len = len;
200                 }
201         }
202         if( !is_dn ) {
203                 if( !strncasecmp( id, "u:", sizeof("u:")-1 )) {
204                         is_dn = SET_U;
205                         dn->bv_val = id+2;
206                         dn->bv_len = len-2;
207                 } else if ( !strncasecmp( id, "dn:", sizeof("dn:")-1) ) {
208                         is_dn = SET_DN;
209                         dn->bv_val = id+3;
210                         dn->bv_len = len-3;
211                 }
212         }
213
214         /* No other possibilities from here */
215         if( !is_dn ) {
216                 dn->bv_val = NULL;
217                 dn->bv_len = 0;
218                 return( LDAP_INAPPROPRIATE_AUTH );
219         }
220
221         /* Username strings */
222         if( is_dn == SET_U ) {
223                 char *p, *realm;
224                 len = dn->bv_len + sizeof("uid=")-1 + sizeof(",cn=auth")-1;
225
226                 /* username may have embedded realm name */
227                 if( realm = strchr( dn->bv_val, '@') ) {
228                         *realm++ = '\0';
229                         len += sizeof(",cn=")-2;
230                 } else if( user_realm && *user_realm ) {
231                         len += strlen( user_realm ) + sizeof(",cn=")-1;
232                 }
233
234                 if( conn->c_sasl_bind_mech.bv_len ) {
235                         len += conn->c_sasl_bind_mech.bv_len + sizeof(",cn=")-1;
236                 }
237
238                 /* Build the new dn */
239                 c1 = dn->bv_val;
240                 dn->bv_val = ch_malloc( len+1 );
241                 p = slap_strcopy( dn->bv_val, "uid=" );
242                 p = slap_strncopy( p, c1, dn->bv_len );
243
244                 if( realm ) {
245                         int rlen = dn->bv_len - ( realm - c1 );
246                         p = slap_strcopy( p, ",cn=" );
247                         p = slap_strncopy( p, realm, rlen );
248                         realm[-1] = '@';
249                 } else if( user_realm && *user_realm ) {
250                         p = slap_strcopy( p, ",cn=" );
251                         p = slap_strcopy( p, user_realm );
252                 }
253
254                 if( conn->c_sasl_bind_mech.bv_len ) {
255                         p = slap_strcopy( p, ",cn=" );
256                         p = slap_strcopy( p, conn->c_sasl_bind_mech.bv_val );
257                 }
258                 p = slap_strcopy( p, ",cn=auth" );
259                 dn->bv_len = p - dn->bv_val;
260
261 #ifdef NEW_LOGGING
262                 LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
263                         "slap_sasl_getdn: u:id converted to %s.\n", dn->bv_val ));
264 #else
265                 Debug( LDAP_DEBUG_TRACE, "getdn: u:id converted to %s\n", dn->bv_val,0,0 );
266 #endif
267         }
268
269         /* All strings are in DN form now. Normalize if needed. */
270         if ( do_norm ) {
271                 rc = dnNormalize2( NULL, dn, &dn2 );
272
273                 /* User DNs were constructed above and must be freed now */
274                 if ( is_dn == SET_U )
275                         ch_free( dn->bv_val );
276
277                 if ( rc != LDAP_SUCCESS ) {
278                         dn->bv_val = NULL;
279                         dn->bv_len = 0;
280                         return rc;
281                 }
282                 *dn = dn2;
283         }
284
285         /* Run thru regexp */
286         slap_sasl2dn( conn, dn, &dn2 );
287         if( dn2.bv_val ) {
288                 ch_free( dn->bv_val );
289                 *dn = dn2;
290 #ifdef NEW_LOGGING
291                 LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
292                         "slap_sasl_getdn: dn:id converted to %s.\n", dn->bv_val ));
293 #else
294                 Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n",
295                         dn->bv_val, 0, 0 );
296 #endif
297         }
298
299         return( LDAP_SUCCESS );
300 }
301
302 #if SASL_VERSION_MAJOR >= 2
303 static const char *slap_propnames[] = { "*authcDN", "*authzDN", NULL };
304
305 static void
306 slap_auxprop_lookup(
307         void *glob_context,
308         sasl_server_params_t *sparams,
309         unsigned flags,
310         const char *user,
311         unsigned ulen)
312 {
313         int rc, i, last;
314         struct berval dn;
315         const struct propval *list;
316         BerVarray vals, bv;
317         AttributeDescription *ad;
318         const char *text;
319
320         list = sparams->utils->prop_get( sparams->propctx );
321
322         /* Find our DN first */
323         for( i = 0, last = 0; list[i].name; i++ ) {
324                 if ( list[i].name[0] == '*' ) {
325                         if ( (flags & SASL_AUXPROP_AUTHZID) &&
326                                 !strcmp( list[i].name, slap_propnames[1] ) ) {
327                                 if ( list[i].values && list[i].values[0] )
328                                         AC_MEMCPY( &dn, list[i].values[0], sizeof( dn ) );
329                                 if ( !last ) last = i;
330                                 break;
331                         }
332                         if ( !strcmp( list[i].name, slap_propnames[0] ) ) {
333                                 if ( !last ) last = i;
334                                 if ( list[i].values && list[i].values[0] ) {
335                                         AC_MEMCPY( &dn, list[i].values[0], sizeof( dn ) );
336                                         if ( !(flags & SASL_AUXPROP_AUTHZID) )
337                                                 break;
338                                 }
339                         }
340                 }
341         }
342
343         /* Now fetch the rest */
344         for( i = 0; i < last; i++ ) {
345                 const char *name = list[i].name;
346
347                 if ( name[0] == '*' ) {
348                         if ( flags & SASL_AUXPROP_AUTHZID ) continue;
349                         name++;
350                 } else if ( !(flags & SASL_AUXPROP_AUTHZID ) )
351                         continue;
352
353                 if ( list[i].values ) {
354                         if ( !(flags & SASL_AUXPROP_OVERRIDE) ) continue;
355                         sparams->utils->prop_erase( sparams->propctx, list[i].name );
356                 }
357                 ad = NULL;
358                 rc = slap_str2ad( name, &ad, &text );
359                 if ( rc != LDAP_SUCCESS ) {
360 #ifdef NEW_LOGGING
361                         LDAP_LOG(( "sasl", LDAP_LEVEL_DETAIL1,
362                                 "slap_auxprop: str2ad(%s): %s\n", name, text ));
363 #else
364                         Debug( LDAP_DEBUG_TRACE,
365                                 "slap_auxprop: str2ad(%s): %s\n", name, text, 0 );
366 #endif
367                         rc = slap_str2undef_ad( name, &ad, &text );
368                         if ( rc != LDAP_SUCCESS ) continue;
369                 }
370                 rc = backend_attribute( NULL,NULL,NULL,NULL, &dn, ad, &vals );
371                 if ( rc != LDAP_SUCCESS ) continue;
372                 for ( bv = vals; bv->bv_val; bv++ ) {
373                         sparams->utils->prop_set( sparams->propctx, list[i].name,
374                                 bv->bv_val, bv->bv_len );
375                 }
376                 ber_bvarray_free( vals );
377         }
378 }
379
380 static sasl_auxprop_plug_t slap_auxprop_plugin = {
381         0,      /* Features */
382         0,      /* spare */
383         NULL,   /* glob_context */
384         NULL,   /* auxprop_free */
385         slap_auxprop_lookup,
386         "slapd",        /* name */
387         NULL    /* spare */
388 };
389
390 static int
391 slap_auxprop_init(
392         const sasl_utils_t *utils,
393         int max_version,
394         int *out_version,
395         sasl_auxprop_plug_t **plug,
396         const char *plugname)
397 {
398         if ( !out_version | !plug ) return SASL_BADPARAM;
399
400         if ( max_version < SASL_AUXPROP_PLUG_VERSION ) return SASL_BADVERS;
401
402         *out_version = SASL_AUXPROP_PLUG_VERSION;
403         *plug = &slap_auxprop_plugin;
404         return SASL_OK;
405 }
406
407 static int
408 slap_sasl_checkpass(
409         sasl_conn_t *sconn,
410         void *context,
411         const char *username,
412         const char *pass,
413         unsigned passlen,
414         struct propctx *propctx)
415 {
416         Connection *conn = (Connection *)context;
417         struct berval dn, cred;
418         int rc;
419         BerVarray vals, bv;
420
421         cred.bv_val = (char *)pass;
422         cred.bv_len = passlen;
423
424         /* SASL will fallback to its own mechanisms if we don't
425          * find an answer here.
426          */
427
428         rc = slap_sasl_getdn( conn, (char *)username, 0, NULL, &dn,
429                 FLAG_GETDN_AUTHCID );
430         if ( rc != LDAP_SUCCESS ) {
431                 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
432                 return SASL_NOUSER;
433         }
434
435         if ( dn.bv_len == 0 ) {
436                 sasl_seterror( sconn, 0,
437                         "No password is associated with the Root DSE" );
438                 if ( dn.bv_val != NULL ) {
439                         ch_free( dn.bv_val );
440                 }
441                 return SASL_NOUSER;
442         }
443
444         rc = backend_attribute( NULL, NULL, NULL, NULL, &dn,
445                 slap_schema.si_ad_userPassword, &vals);
446         if ( rc != LDAP_SUCCESS ) {
447                 ch_free( dn.bv_val );
448                 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
449                 return SASL_NOVERIFY;
450         }
451
452         rc = SASL_NOVERIFY;
453
454         if ( vals != NULL ) {
455                 for ( bv = vals; bv->bv_val != NULL; bv++ ) {
456                         if ( !lutil_passwd( bv, &cred, NULL ) ) {
457                                 rc = SASL_OK;
458                                 break;
459                         }
460                 }
461                 ber_bvarray_free( vals );
462         }
463
464         if ( rc != SASL_OK ) {
465                 sasl_seterror( sconn, 0,
466                         ldap_err2string( LDAP_INVALID_CREDENTIALS ) );
467         }
468
469         ch_free( dn.bv_val );
470
471         return rc;
472 }
473
474 /* Convert a SASL authcid or authzid into a DN. Store the DN in an
475  * auxiliary property, so that we can refer to it in sasl_authorize
476  * without interfering with anything else. Also, the SASL username
477  * buffer is constrained to 256 characters, and our DNs could be
478  * much longer (totally arbitrary length)...
479  */
480 static int
481 slap_sasl_canonicalize(
482         sasl_conn_t *sconn,
483         void *context,
484         const char *in,
485         unsigned inlen,
486         unsigned flags,
487         const char *user_realm,
488         char *out,
489         unsigned out_max,
490         unsigned *out_len)
491 {
492         Connection *conn = (Connection *)context;
493         struct propctx *props = sasl_auxprop_getctx( sconn );
494         struct propval auxvals[3];
495         struct berval dn;
496         int rc, which;
497         const char *names[2];
498
499         *out_len = 0;
500
501 #ifdef NEW_LOGGING
502         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
503                 "slap_sasl_canonicalize: conn %d %s=\"%s\"\n",
504                         conn ? conn->c_connid : -1,
505                         (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
506                         in ? in : "<empty>" ));
507 #else
508         Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: "
509                 "%s=\"%s\"\n",
510                         conn ? conn->c_connid : -1,
511                         (flags & SASL_CU_AUTHID) ? "authcid" : "authzid",
512                         in ? in : "<empty>" );
513 #endif
514
515         /* If name is too big, just truncate. We don't care, we're
516          * using DNs, not the usernames.
517          */
518         if ( inlen > out_max )
519                 inlen = out_max-1;
520
521         /* See if we need to add request, can only do it once */
522         prop_getnames( props, slap_propnames, auxvals );
523         if ( !auxvals[0].name )
524                 prop_request( props, slap_propnames );
525
526         if ( flags & SASL_CU_AUTHID )
527                 which = 0;
528         else
529                 which = 1;
530
531         /* Already been here? */
532         if ( auxvals[which].values )
533                 goto done;
534
535         if ( flags == SASL_CU_AUTHZID ) {
536         /* If we got unqualified authzid's, they probably came from SASL
537          * itself just passing the authcid to us. Look inside the oparams
538          * structure to see if that's true. (HACK: the out_len pointer is
539          * the address of a member of a sasl_out_params_t structure...)
540          */
541                 sasl_out_params_t dummy;
542                 int offset = (void *)&dummy.ulen - (void *)&dummy.authid;
543                 char **authid = (void *)out_len - offset;
544                 if ( *authid && !strcmp( in, *authid ) )
545                         goto done;
546         }
547
548         rc = slap_sasl_getdn( conn, (char *)in, inlen, (char *)user_realm, &dn,
549                 (flags & SASL_CU_AUTHID) ? FLAG_GETDN_AUTHCID : FLAG_GETDN_AUTHZID );
550         if ( rc != LDAP_SUCCESS ) {
551                 sasl_seterror( sconn, 0, ldap_err2string( rc ) );
552                 return SASL_NOAUTHZ;
553         }               
554
555         names[0] = slap_propnames[which];
556         names[1] = NULL;
557
558         prop_set( props, names[0], (char *)&dn, sizeof( dn ) );
559                 
560 #ifdef NEW_LOGGING
561         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
562                 "slap_sasl_canonicalize: conn %d %s=\"%s\"\n",
563                         conn ? conn->c_connid : -1,
564                         names[0]+1, dn.bv_val ));
565 #else
566         Debug( LDAP_DEBUG_ARGS, "SASL Canonicalize [conn=%ld]: "
567                 "%s=\"%s\"\n",
568                         conn ? conn->c_connid : -1,
569                         names[0]+1, dn.bv_val );
570 #endif
571 done:   AC_MEMCPY( out, in, inlen );
572         out[inlen] = '\0';
573
574         *out_len = inlen;
575
576         return SASL_OK;
577 }
578
579 static int
580 slap_sasl_authorize(
581         sasl_conn_t *sconn,
582         void *context,
583         char *requested_user,
584         unsigned rlen,
585         char *auth_identity,
586         unsigned alen,
587         const char *def_realm,
588         unsigned urlen,
589         struct propctx *props)
590 {
591         Connection *conn = (Connection *)context;
592         struct propval auxvals[3];
593         struct berval authcDN, authzDN;
594         int rc;
595
596 #ifdef NEW_LOGGING
597         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
598                 "slap_sasl_authorize: conn %d authcid=\"%s\" authzid=\"%s\"\n",
599                         conn ? conn->c_connid : -1, auth_identity, requested_user));
600 #else
601         Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
602                 "authcid=\"%s\" authzid=\"%s\"\n",
603                 conn ? conn->c_connid : -1, auth_identity, requested_user );
604 #endif
605         if ( conn->c_sasl_dn.bv_val ) {
606                 ch_free( conn->c_sasl_dn.bv_val );
607                 conn->c_sasl_dn.bv_val = NULL;
608                 conn->c_sasl_dn.bv_len = 0;
609         }
610
611         prop_getnames( props, slap_propnames, auxvals );
612         
613         AC_MEMCPY( &authcDN, auxvals[0].values[0], sizeof(authcDN) );
614
615         /* Nothing to do if no authzID was given */
616         if ( !auxvals[1].name || !auxvals[1].values ) {
617                 conn->c_sasl_dn = authcDN;
618                 return SASL_OK;
619         }
620         
621         AC_MEMCPY( &authzDN, auxvals[1].values[0], sizeof(authzDN) );
622
623         rc = slap_sasl_authorized( &authcDN, &authzDN );
624         ch_free( authcDN.bv_val );
625         if ( rc != LDAP_SUCCESS ) {
626 #ifdef NEW_LOGGING
627                 LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
628                            "slap_sasl_authorize: conn %ld  authorization disallowed (%d)\n",
629                            (long)(conn ? conn->c_connid : -1), rc ));
630 #else
631                 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
632                         " authorization disallowed (%d)\n",
633                         (long) (conn ? conn->c_connid : -1), rc, 0 );
634 #endif
635
636                 sasl_seterror( sconn, 0, "not authorized" );
637                 ch_free( authzDN.bv_val );
638                 return SASL_NOAUTHZ;
639         }
640
641         conn->c_sasl_dn = authzDN;
642
643 #ifdef NEW_LOGGING
644         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
645                    "slap_sasl_authorize: conn %d authorization allowed\n",
646                    (long)(conn ? conn->c_connid : -1 ) ));
647 #else
648         Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
649                 " authorization allowed\n",
650                 (long) (conn ? conn->c_connid : -1), 0, 0 );
651 #endif
652         return SASL_OK;
653
654 #else
655 static int
656 slap_sasl_authorize(
657         void *context,
658         char *authcid,
659         char *authzid,
660         const char **user,
661         const char **errstr)
662 {
663         struct berval authcDN, authzDN;
664         int rc;
665         Connection *conn = context;
666         char *realm;
667
668         *user = NULL;
669         if ( conn->c_sasl_dn.bv_val ) {
670                 ch_free( conn->c_sasl_dn.bv_val );
671                 conn->c_sasl_dn.bv_val = NULL;
672                 conn->c_sasl_dn.bv_len = 0;
673         }
674
675 #ifdef NEW_LOGGING
676         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
677                    "slap_sasl_authorize: conn %d         authcid=\"%s\" authzid=\"%s\"\n",
678                    conn ? conn->c_connid : -1,
679                    authcid ? authcid : "<empty>",
680                    authzid ? authzid : "<empty>" ));
681 #else
682         Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
683                 "authcid=\"%s\" authzid=\"%s\"\n",
684                 (long) (conn ? conn->c_connid : -1),
685                 authcid ? authcid : "<empty>",
686                 authzid ? authzid : "<empty>" );
687 #endif
688
689         /* Figure out how much data we have for the dn */
690         rc = sasl_getprop( conn->c_sasl_context, SASL_REALM, (void **)&realm );
691         if( rc != SASL_OK && rc != SASL_NOTDONE ) {
692 #ifdef NEW_LOGGING
693                 LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
694                         "slap_sasl_authorize: getprop(REALM) failed.\n" ));
695 #else
696                 Debug(LDAP_DEBUG_TRACE,
697                         "authorize: getprop(REALM) failed!\n", 0,0,0);
698 #endif
699                 *errstr = "Could not extract realm";
700                 return SASL_NOAUTHZ;
701         }
702
703         /* Convert the identities to DN's. If no authzid was given, client will
704            be bound as the DN matching their username */
705         rc = slap_sasl_getdn( conn, (char *)authcid, 0, realm, &authcDN, FLAG_GETDN_AUTHCID );
706         if( rc != LDAP_SUCCESS ) {
707                 *errstr = ldap_err2string( rc );
708                 return SASL_NOAUTHZ;
709         }
710         if( ( authzid == NULL ) || !strcmp( authcid,authzid ) ) {
711 #ifdef NEW_LOGGING
712                 LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
713                            "slap_sasl_authorize: conn %d  Using authcDN=%s\n",
714                            conn ? conn->c_connid : -1, authcDN.bv_val ));
715 #else
716                 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
717                  "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
718 #endif
719
720                 conn->c_sasl_dn = authcDN;
721                 *errstr = NULL;
722                 return SASL_OK;
723         }
724         rc = slap_sasl_getdn( conn, (char *)authzid, 0, realm, &authzDN, FLAG_GETDN_AUTHZID );
725         if( rc != LDAP_SUCCESS ) {
726                 ch_free( authcDN.bv_val );
727                 *errstr = ldap_err2string( rc );
728                 return SASL_NOAUTHZ;
729         }
730
731         rc = slap_sasl_authorized( &authcDN, &authzDN );
732         ch_free( authcDN.bv_val );
733         if( rc ) {
734 #ifdef NEW_LOGGING
735                 LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
736                            "slap_sasl_authorize: conn %ld  authorization disallowed (%d)\n",
737                            (long)(conn ? conn->c_connid : -1), rc ));
738 #else
739                 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
740                         " authorization disallowed (%d)\n",
741                         (long) (conn ? conn->c_connid : -1), rc, 0 );
742 #endif
743
744                 *errstr = "not authorized";
745                 ch_free( authzDN.bv_val );
746                 return SASL_NOAUTHZ;
747         }
748
749 #ifdef NEW_LOGGING
750         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
751                    "slap_sasl_authorize: conn %d authorization allowed\n",
752                    (long)(conn ? conn->c_connid : -1 ) ));
753 #else
754         Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
755                 " authorization allowed\n",
756                 (long) (conn ? conn->c_connid : -1), 0, 0 );
757 #endif
758
759         conn->c_sasl_dn = authzDN;
760         *errstr = NULL;
761         return SASL_OK;
762 }
763 #endif /* SASL_VERSION_MAJOR >= 2 */
764
765 static int
766 slap_sasl_err2ldap( int saslerr )
767 {
768         int rc;
769
770         switch (saslerr) {
771                 case SASL_CONTINUE:
772                         rc = LDAP_SASL_BIND_IN_PROGRESS;
773                         break;
774                 case SASL_FAIL:
775                         rc = LDAP_OTHER;
776                         break;
777                 case SASL_NOMEM:
778                         rc = LDAP_OTHER;
779                         break;
780                 case SASL_NOMECH:
781                         rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
782                         break;
783                 case SASL_BADAUTH:
784                         rc = LDAP_INVALID_CREDENTIALS;
785                         break;
786                 case SASL_NOAUTHZ:
787                         rc = LDAP_INSUFFICIENT_ACCESS;
788                         break;
789                 case SASL_TOOWEAK:
790                 case SASL_ENCRYPT:
791                         rc = LDAP_INAPPROPRIATE_AUTH;
792                         break;
793                 default:
794                         rc = LDAP_OTHER;
795                         break;
796         }
797
798         return rc;
799 }
800 #endif
801
802
803 int slap_sasl_init( void )
804 {
805 #ifdef HAVE_CYRUS_SASL
806         int rc;
807         static sasl_callback_t server_callbacks[] = {
808                 { SASL_CB_LOG, &slap_sasl_log, NULL },
809                 { SASL_CB_LIST_END, NULL, NULL }
810         };
811
812         sasl_set_alloc(
813                 ch_malloc,
814                 ch_calloc,
815                 ch_realloc,
816                 ch_free ); 
817
818         sasl_set_mutex(
819                 ldap_pvt_sasl_mutex_new,
820                 ldap_pvt_sasl_mutex_lock,
821                 ldap_pvt_sasl_mutex_unlock,
822                 ldap_pvt_sasl_mutex_dispose );
823
824 #if SASL_VERSION_MAJOR >= 2
825         sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
826 #endif
827         /* should provide callbacks for logging */
828         /* server name should be configurable */
829         rc = sasl_server_init( server_callbacks, "slapd" );
830
831         if( rc != SASL_OK ) {
832 #ifdef NEW_LOGGING
833                 LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
834                            "slap_sasl_init: init failed.\n" ));
835 #else
836                 Debug( LDAP_DEBUG_ANY, "sasl_server_init failed\n",
837                         0, 0, 0 );
838 #endif
839
840                 return -1;
841         }
842
843 #ifdef NEW_LOGGING
844         LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
845                    "slap_sasl_init: initialized!\n"));
846 #else
847         Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
848                 0, 0, 0 );
849 #endif
850
851
852         /* default security properties */
853         memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
854         sasl_secprops.max_ssf = INT_MAX;
855         sasl_secprops.maxbufsize = 65536;
856         sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
857 #endif
858
859         return 0;
860 }
861
862 int slap_sasl_destroy( void )
863 {
864 #ifdef HAVE_CYRUS_SASL
865         sasl_done();
866 #endif
867         free( global_host );
868         global_host = NULL;
869
870         return 0;
871 }
872
873 int slap_sasl_open( Connection *conn )
874 {
875         int cb, sc = LDAP_SUCCESS;
876 #if SASL_VERSION_MAJOR >= 2
877         char *ipremoteport = NULL, *iplocalport = NULL;
878 #endif
879
880 #ifdef HAVE_CYRUS_SASL
881         sasl_conn_t *ctx = NULL;
882         sasl_callback_t *session_callbacks;
883
884         assert( conn->c_sasl_context == NULL );
885         assert( conn->c_sasl_extra == NULL );
886
887         conn->c_sasl_layers = 0;
888
889         session_callbacks =
890 #if SASL_VERSION_MAJOR >= 2
891                 ch_calloc( 5, sizeof(sasl_callback_t));
892 #else
893                 ch_calloc( 3, sizeof(sasl_callback_t));
894 #endif
895         conn->c_sasl_extra = session_callbacks;
896
897         session_callbacks[cb=0].id = SASL_CB_LOG;
898         session_callbacks[cb].proc = &slap_sasl_log;
899         session_callbacks[cb++].context = conn;
900
901         session_callbacks[cb].id = SASL_CB_PROXY_POLICY;
902         session_callbacks[cb].proc = &slap_sasl_authorize;
903         session_callbacks[cb++].context = conn;
904
905 #if SASL_VERSION_MAJOR >= 2
906         session_callbacks[cb].id = SASL_CB_CANON_USER;
907         session_callbacks[cb].proc = &slap_sasl_canonicalize;
908         session_callbacks[cb++].context = conn;
909
910         /* XXXX: this should be conditional */
911         session_callbacks[cb].id = SASL_CB_SERVER_USERDB_CHECKPASS;
912         session_callbacks[cb].proc = &slap_sasl_checkpass;
913         session_callbacks[cb++].context = conn;
914 #endif
915
916         session_callbacks[cb].id = SASL_CB_LIST_END;
917         session_callbacks[cb].proc = NULL;
918         session_callbacks[cb++].context = NULL;
919
920         if( global_host == NULL ) {
921                 global_host = ldap_pvt_get_fqdn( NULL );
922         }
923
924         /* create new SASL context */
925 #if SASL_VERSION_MAJOR >= 2
926         if ( conn->c_sock_name.bv_len != 0 &&
927              strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0) {
928                 char *p;
929
930                 iplocalport = ch_strdup( conn->c_sock_name.bv_val + 3 );
931                 /* Convert IPv6 addresses to address;port syntax. */
932                 p = strrchr( iplocalport, ' ' );
933                 /* Convert IPv4 addresses to address;port syntax. */
934                 if ( p == NULL ) p = strchr( iplocalport, ':' );
935                 if ( p != NULL ) {
936                         *p = ';';
937                 }
938         }
939         if ( conn->c_peer_name.bv_len != 0 &&
940              strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0) {
941                 char *p;
942
943                 ipremoteport = ch_strdup( conn->c_peer_name.bv_val + 3 );
944                 /* Convert IPv6 addresses to address;port syntax. */
945                 p = strrchr( ipremoteport, ' ' );
946                 /* Convert IPv4 addresses to address;port syntax. */
947                 if ( p == NULL ) p = strchr( ipremoteport, ':' );
948                 if ( p != NULL ) {
949                         *p = ';';
950                 }
951         }
952         sc = sasl_server_new( "ldap", global_host, global_realm,
953                 iplocalport, ipremoteport, session_callbacks, 0, &ctx );
954         if ( iplocalport != NULL ) {
955                 ch_free( iplocalport );
956         }
957         if ( ipremoteport != NULL ) {
958                 ch_free( ipremoteport );
959         }
960 #else
961         sc = sasl_server_new( "ldap", global_host, global_realm,
962                 session_callbacks, SASL_SECURITY_LAYER, &ctx );
963 #endif
964
965         if( sc != SASL_OK ) {
966 #ifdef NEW_LOGGING
967                 LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
968                            "slap_sasl_open: sasl_server_new failed: %d\n", sc ));
969 #else
970                 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
971                         sc, 0, 0 );
972 #endif
973
974                 return -1;
975         }
976
977         conn->c_sasl_context = ctx;
978
979         if( sc == SASL_OK ) {
980                 sc = sasl_setprop( ctx,
981                         SASL_SEC_PROPS, &sasl_secprops );
982
983                 if( sc != SASL_OK ) {
984 #ifdef NEW_LOGGING
985                         LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
986                                    "slap_sasl_open: sasl_setprop failed: %d \n", sc ));
987 #else
988                         Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
989                                 sc, 0, 0 );
990 #endif
991
992                         slap_sasl_close( conn );
993                         return -1;
994                 }
995         }
996
997         sc = slap_sasl_err2ldap( sc );
998 #endif
999         return sc;
1000 }
1001
1002 int slap_sasl_external(
1003         Connection *conn,
1004         slap_ssf_t ssf,
1005         const char *auth_id )
1006 {
1007 #if SASL_VERSION_MAJOR >= 2
1008         int sc;
1009         sasl_conn_t *ctx = conn->c_sasl_context;
1010
1011         if ( ctx == NULL ) {
1012                 return LDAP_UNAVAILABLE;
1013         }
1014
1015         sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
1016
1017         if ( sc != SASL_OK ) {
1018                 return LDAP_OTHER;
1019         }
1020
1021         sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, auth_id );
1022
1023         if ( sc != SASL_OK ) {
1024                 return LDAP_OTHER;
1025         }
1026
1027 #elif defined(HAVE_CYRUS_SASL)
1028         int sc;
1029         sasl_conn_t *ctx = conn->c_sasl_context;
1030         sasl_external_properties_t extprops;
1031
1032         if ( ctx == NULL ) {
1033                 return LDAP_UNAVAILABLE;
1034         }
1035
1036         memset( &extprops, '\0', sizeof(extprops) );
1037         extprops.ssf = ssf;
1038         extprops.auth_id = (char *) auth_id;
1039
1040         sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1041                 (void *) &extprops );
1042
1043         if ( sc != SASL_OK ) {
1044                 return LDAP_OTHER;
1045         }
1046 #endif
1047
1048         return LDAP_SUCCESS;
1049 }
1050
1051 int slap_sasl_reset( Connection *conn )
1052 {
1053 #ifdef HAVE_CYRUS_SASL
1054         sasl_conn_t *ctx = conn->c_sasl_context;
1055
1056         if( ctx != NULL ) {
1057         }
1058 #endif
1059         /* must return "anonymous" */
1060         return LDAP_SUCCESS;
1061 }
1062
1063 char ** slap_sasl_mechs( Connection *conn )
1064 {
1065         char **mechs = NULL;
1066
1067 #ifdef HAVE_CYRUS_SASL
1068         sasl_conn_t *ctx = conn->c_sasl_context;
1069
1070         if( ctx != NULL ) {
1071                 int sc;
1072                 SASL_CONST char *mechstr;
1073
1074                 sc = sasl_listmech( ctx,
1075                         NULL, NULL, ",", NULL,
1076                         &mechstr, NULL, NULL );
1077
1078                 if( sc != SASL_OK ) {
1079 #ifdef NEW_LOGGING
1080                         LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
1081                                 "slap_sasl_mechs: sasl_listmech failed: %d\n", sc ));
1082 #else
1083                         Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
1084                                 sc, 0, 0 );
1085 #endif
1086
1087                         return NULL;
1088                 }
1089
1090                 mechs = str2charray( mechstr, "," );
1091
1092 #if SASL_VERSION_MAJOR < 2
1093                 ch_free( mechstr );
1094 #endif
1095         }
1096 #endif
1097
1098         return mechs;
1099 }
1100
1101 int slap_sasl_close( Connection *conn )
1102 {
1103 #ifdef HAVE_CYRUS_SASL
1104         sasl_conn_t *ctx = conn->c_sasl_context;
1105
1106         if( ctx != NULL ) {
1107                 sasl_dispose( &ctx );
1108         }
1109
1110         conn->c_sasl_context = NULL;
1111
1112         free( conn->c_sasl_extra );
1113         conn->c_sasl_extra = NULL;
1114 #endif
1115
1116         return LDAP_SUCCESS;
1117 }
1118
1119 int slap_sasl_bind(
1120     Connection          *conn,
1121     Operation           *op,  
1122     struct berval       *dn,  
1123     struct berval       *ndn,
1124     struct berval       *cred,
1125         struct berval                   *edn,
1126         slap_ssf_t              *ssfp )
1127 {
1128         int rc = 1;
1129
1130 #ifdef HAVE_CYRUS_SASL
1131         sasl_conn_t *ctx = conn->c_sasl_context;
1132         struct berval response;
1133         unsigned reslen = 0;
1134         const char *errstr = NULL;
1135         int sc;
1136
1137 #ifdef NEW_LOGGING
1138         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
1139                 "sasl_bind: conn %ld dn=\"%s\" mech=%s datalen=%ld\n",
1140                 conn->c_connid,
1141                 dn->bv_len ? dn->bv_val : "",
1142                 conn->c_sasl_bind_in_progress ? "<continuing>" : conn->c_sasl_bind_mech.bv_val,
1143                 cred ? cred->bv_len : 0 ));
1144 #else
1145         Debug(LDAP_DEBUG_ARGS,
1146                 "==> sasl_bind: dn=\"%s\" mech=%s datalen=%ld\n",
1147                 dn->bv_len ? dn->bv_val : "",
1148                 conn->c_sasl_bind_in_progress ? "<continuing>":conn->c_sasl_bind_mech.bv_val,
1149                 cred ? cred->bv_len : 0 );
1150 #endif
1151
1152
1153         if( ctx == NULL ) {
1154                 send_ldap_result( conn, op, LDAP_UNAVAILABLE,
1155                         NULL, "SASL unavailable on this session", NULL, NULL );
1156                 return rc;
1157         }
1158
1159 #if SASL_VERSION_MAJOR >= 2
1160 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1161         sasl_server_start( ctx, mech, cred, clen, resp, rlen )
1162 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1163         sasl_server_step( ctx, cred, clen, resp, rlen )
1164 #else
1165 #define START( ctx, mech, cred, clen, resp, rlen, err ) \
1166         sasl_server_start( ctx, mech, cred, clen, resp, rlen, err )
1167 #define STEP( ctx, cred, clen, resp, rlen, err ) \
1168         sasl_server_step( ctx, cred, clen, resp, rlen, err )
1169 #endif
1170
1171         if ( !conn->c_sasl_bind_in_progress ) {
1172                 sc = START( ctx,
1173                         conn->c_sasl_bind_mech.bv_val,
1174                         cred->bv_len ? cred->bv_val : "",
1175                         cred->bv_len,
1176                         (SASL_CONST char **)&response.bv_val, &reslen, &errstr );
1177
1178         } else {
1179                 sc = STEP( ctx,
1180                         cred->bv_val, cred->bv_len,
1181                         (SASL_CONST char **)&response.bv_val, &reslen, &errstr );
1182         }
1183
1184         response.bv_len = reslen;
1185
1186         if ( sc == SASL_OK ) {
1187                 sasl_ssf_t *ssf = NULL;
1188
1189                 *edn = conn->c_sasl_dn;
1190                 conn->c_sasl_dn.bv_val = NULL;
1191                 conn->c_sasl_dn.bv_len = 0;
1192
1193                 rc = LDAP_SUCCESS;
1194
1195                 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
1196                 *ssfp = ssf ? *ssf : 0;
1197
1198                 if( *ssfp ) {
1199                         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1200                         conn->c_sasl_layers++;
1201                         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1202                 }
1203
1204                 send_ldap_sasl( conn, op, rc,
1205                         NULL, NULL, NULL, NULL,
1206                         response.bv_len ? &response : NULL );
1207
1208         } else if ( sc == SASL_CONTINUE ) {
1209                 send_ldap_sasl( conn, op, rc = LDAP_SASL_BIND_IN_PROGRESS,
1210                         NULL, NULL, NULL, NULL, &response );
1211
1212         } else {
1213 #if SASL_VERSION_MAJOR >= 2
1214                 errstr = sasl_errdetail( ctx );
1215 #endif
1216                 send_ldap_result( conn, op, rc = slap_sasl_err2ldap( sc ),
1217                         NULL, errstr, NULL, NULL );
1218         }
1219
1220 #if SASL_VERSION_MAJOR < 2
1221         if( response.bv_len ) {
1222                 ch_free( response.bv_val );
1223         }
1224 #endif
1225
1226 #ifdef NEW_LOGGING
1227         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
1228                 "slap_sasl_bind: rc=%d\n", rc ));
1229 #else
1230         Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rc, 0, 0);
1231 #endif
1232
1233
1234 #else
1235         send_ldap_result( conn, op, rc = LDAP_UNAVAILABLE,
1236                 NULL, "SASL not supported", NULL, NULL );
1237 #endif
1238
1239         return rc;
1240 }
1241
1242 char* slap_sasl_secprops( const char *in )
1243 {
1244 #ifdef HAVE_CYRUS_SASL
1245         int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
1246
1247         return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
1248 #else
1249         return "SASL not supported";
1250 #endif
1251 }
1252
1253 #ifdef HAVE_CYRUS_SASL
1254 int
1255 slap_sasl_setpass(
1256         Connection      *conn,
1257         Operation       *op,
1258         const char      *reqoid,
1259         struct berval   *reqdata,
1260         char            **rspoid,
1261         struct berval   **rspdata,
1262         LDAPControl     *** rspctrls,
1263         const char      **text )
1264 {
1265         int rc;
1266         struct berval id = { 0, NULL }; /* needs to come from connection */
1267         struct berval new = { 0, NULL };
1268         struct berval old = { 0, NULL };
1269
1270         assert( reqoid != NULL );
1271         assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
1272
1273         rc = sasl_getprop( conn->c_sasl_context, SASL_USERNAME,
1274                 (SASL_CONST void **)&id.bv_val );
1275
1276         if( rc != SASL_OK ) {
1277                 *text = "unable to retrieve SASL username";
1278                 rc = LDAP_OTHER;
1279                 goto done;
1280         }
1281
1282 #ifdef NEW_LOGGING
1283         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
1284                 "slap_sasl_setpass: \"%s\"\n",
1285                 id.bv_val ? id.bv_val : "" ));
1286 #else
1287         Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
1288                 id.bv_val ? id.bv_val : "", 0, 0 );
1289 #endif
1290
1291         rc = slap_passwd_parse( reqdata,
1292                 NULL, &old, &new, text );
1293
1294         if( rc != LDAP_SUCCESS ) {
1295                 goto done;
1296         }
1297
1298         if( new.bv_len == 0 ) {
1299                 slap_passwd_generate(&new);
1300
1301                 if( new.bv_len == 0 ) {
1302                         *text = "password generation failed.";
1303                         rc = LDAP_OTHER;
1304                         goto done;
1305                 }
1306                 
1307                 *rspdata = slap_passwd_return( &new );
1308         }
1309
1310 #if SASL_VERSION_MAJOR < 2
1311         rc = sasl_setpass( conn->c_sasl_context,
1312                 id.bv_val, new.bv_val, new.bv_len, 0, text );
1313 #else
1314         rc = sasl_setpass( conn->c_sasl_context, id.bv_val,
1315                 old.bv_val, old.bv_len, new.bv_val, new.bv_len, 0 );
1316         if( rc != SASL_OK ) {
1317                 *text = sasl_errdetail( conn->c_sasl_context );
1318         }
1319 #endif
1320         switch(rc) {
1321                 case SASL_OK:
1322                         rc = LDAP_SUCCESS;
1323                         break;
1324
1325                 case SASL_NOCHANGE:
1326                 case SASL_NOMECH:
1327                 case SASL_DISABLED:
1328                 case SASL_PWLOCK:
1329                 case SASL_FAIL:
1330                 case SASL_BADPARAM:
1331                 default:
1332                         rc = LDAP_OTHER;
1333         }
1334
1335 done:
1336         return rc;
1337 }
1338 #endif