]> git.sur5r.net Git - openldap/blob - servers/slapd/sasl.c
Skip over the "dn:" prefix when passing a DN to dn_normalize().
[openldap] / servers / slapd / sasl.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <ac/stdlib.h>
10 #include <stdio.h>
11
12 #include "slap.h"
13 #include "proto-slap.h"
14
15 #include <lber.h>
16 #include <ldap_log.h>
17
18 #ifdef HAVE_CYRUS_SASL
19 #include <limits.h>
20 #include <sasl.h>
21
22 #include <ldap_pvt.h>
23
24 #ifdef SLAPD_SPASSWD
25 #include <lutil.h>
26 #endif
27
28 static sasl_security_properties_t sasl_secprops;
29
30 static int
31 slap_sasl_log(
32         void *context,
33         int priority,
34         const char *message) 
35 {
36         Connection *conn = context;
37         int level;
38         const char * label;
39
40         if ( message == NULL ) {
41                 return SASL_BADPARAM;
42         }
43
44         switch (priority) {
45         case SASL_LOG_ERR:
46                 level = LDAP_DEBUG_ANY;
47                 label = "Error";
48                 break;
49         case SASL_LOG_WARNING:
50                 level = LDAP_DEBUG_TRACE;
51                 label = "Warning";
52                 break;
53         case SASL_LOG_INFO:
54                 level = LDAP_DEBUG_TRACE;
55                 label = "Info";
56                 break;
57         default:
58                 return SASL_BADPARAM;
59         }
60
61 #ifdef NEW_LOGGING
62         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
63                 "SASL [conn=%d] %s: %s\n",
64                 conn ? conn->c_connid : -1,
65                 label, message ));
66 #else
67         Debug( level, "SASL [conn=%d] %s: %s\n",
68                 conn ? conn->c_connid: -1,
69                 label, message );
70 #endif
71
72
73         return SASL_OK;
74 }
75
76
77 /* Take any sort of identity string and return a DN with the "dn:" prefix. The
78    string returned in *dnptr is in its own allocated memory, and must be free'd 
79    by the calling process.
80    -Mark Adamson, Carnegie Mellon
81 */
82
83 int slap_sasl_getdn( Connection *conn, char *id, char **dnptr, int flags )
84 {
85         char *c=NULL, *c1, *dn=NULL;
86         int rc, len;
87         sasl_conn_t *ctx;
88
89
90 #ifdef NEW_LOGGING
91         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
92                 "slap_sasl_getdn: conn %d id=%s\n",
93                 conn ? conn->c_connid : -1,
94                 id ? (*id ? id : "<empty>") : "NULL" ));
95 #else
96         Debug( LDAP_DEBUG_ARGS, "slap_sasl_getdn: id=%s\n", 
97       id?(*id?id:"<empty>"):"NULL",0,0 );
98 #endif
99
100
101         /* Blatantly anonymous ID */
102         len = strlen( "anonymous" );
103         if( id && !strncasecmp( id, "anonymous", len) && 
104                 ( id[len] == '\0' || id[len] == '@' ) ) {
105                 *dnptr = NULL;
106                 return( LDAP_SUCCESS );
107         }
108         ctx = conn->c_sasl_context;
109         len = strlen( id );
110
111         /* An authcID needs to be converted to authzID form */
112         if( flags & FLAG_GETDN_AUTHCID ) {
113                 if( sasl_external_x509dn_convert && conn->c_sasl_bind_mech
114                         && ( strcasecmp( "EXTERNAL", conn->c_sasl_bind_mech ) == 0 ) 
115                         && len && dn[0] == '/' && dn[len-1]== '/' )
116                 {
117                         /* check SASL external for X.509 style DN and */
118                         /* convert to dn:<dn> form */
119                         char *tmpdn = ldap_dcedn2dn( id );
120                         len = strlen( tmpdn );
121
122                         dn = ch_malloc( len+4 );
123                         dn[0] = 'd';
124                         dn[1] = 'n';
125                         dn[2] = ':';
126                         memmove( &dn[3], tmpdn, len+1 );
127                         len += 3;
128
129                 } else {
130                         /* convert to u:<username> form */
131                         dn = ch_malloc( len+3 );
132                         dn[0] = 'u';
133                         dn[1] = ':';
134                         memmove( &dn[2], id, len+1 );
135                         len += 2;
136                 }
137         } else {
138                 dn = ch_strdup( id );
139         }
140
141         /* An authzID must be properly prefixed */
142         if( flags & FLAG_GETDN_AUTHZID
143                 && strncasecmp( dn, "u:", 2 )
144                 && strncasecmp( dn, "dn:", 3 ) )
145         {
146                 ch_free( dn );
147                 *dnptr = NULL;
148                 return( LDAP_INAPPROPRIATE_AUTH );
149         }
150
151         /* Username strings */
152         if( !strncasecmp( dn, "u:", 2 ) ) {
153                 int len1  = strlen( ",cn=auth" );
154                 len += strlen( "dn:uid=" ) + len1;
155
156                 /* Figure out how much data we have for the dn */
157                 rc = sasl_getprop( ctx, SASL_REALM, (void **)&c );
158                 if( rc != SASL_OK && rc != SASL_NOTDONE ) {
159 #ifdef NEW_LOGGING
160                         LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
161                                 "slap_sasl_getdn: getprop(REALM) failed.\n" ));
162 #else
163                         Debug(LDAP_DEBUG_TRACE,
164                                 "getdn: getprop(REALM) failed!\n", 0,0,0);
165 #endif
166
167                         ch_free( dn );
168                         *dnptr = NULL;
169                         return( LDAP_OPERATIONS_ERROR );
170                 }
171
172                 if( c && *c ) {
173                         len += strlen( c ) + strlen(",cn=" );
174                 }
175
176                 if( conn->c_sasl_bind_mech ) {
177                         len += strlen( conn->c_sasl_bind_mech ) + strlen( ",cn=" );
178                 }
179
180                 /* Build the new dn */
181                 c1 = dn;
182                 dn = ch_malloc( len );
183                 len = sprintf( dn, "dn:uid=%s", c1+2 );
184                 ch_free( c1 );
185
186                 if( c ) {
187                         len += sprintf( dn+len, ",cn=%s", c );
188                 }
189                 if( conn->c_sasl_bind_mech ) {
190                         len += sprintf( dn+len, ",cn=%s", conn->c_sasl_bind_mech );
191                 }
192                 strcpy( dn+len, ",cn=auth" );
193                 len += len1;
194
195 #ifdef NEW_LOGGING
196                 LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
197                         "slap_sasl_getdn: u:id converted to %s.\n", dn ));
198 #else
199                 Debug( LDAP_DEBUG_TRACE, "getdn: u:id converted to %s\n", dn,0,0 );
200 #endif
201         }
202
203         /* DN strings that are a cn=auth identity to run through regexp */
204         if( !strncasecmp( dn, "dn:", 3) && ( ( flags & FLAG_GETDN_FINAL ) == 0 ) ) {
205                 c1 = slap_sasl2dn( dn + 3 );
206                 if( c1 ) {
207                         ch_free( dn );
208                         dn = c1;
209                         /* Reaffix the dn: prefix if it was removed */
210                         if( strncasecmp( dn, "dn:", 3) ) {
211                                 c1 = dn;
212                                 dn = ch_malloc( strlen( c1 ) + 4 );
213                                 sprintf( dn, "dn:%s", c1 );
214                                 ch_free( c1 );
215                         }
216
217 #ifdef NEW_LOGGING
218                         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
219                                    "slap_sasl_getdn: dn:id converted to %s.\n", dn ));
220 #else
221                         Debug( LDAP_DEBUG_TRACE, "getdn: dn:id converted to %s\n", dn,0,0 );
222 #endif
223                 }
224         }
225
226         if( ( flags & FLAG_GETDN_FINAL ) == 0 )  {
227                 dn_normalize( dn+3 );
228         }
229
230         *dnptr = dn;
231         return( LDAP_SUCCESS );
232 }
233
234
235
236 static int
237 slap_sasl_authorize(
238         void *context,
239         const char *authcid,
240         const char *authzid,
241         const char **user,
242         const char **errstr)
243 {
244         char *authcDN, *authzDN;
245         int rc;
246         Connection *conn = context;
247
248         *user = NULL;
249
250 #ifdef NEW_LOGGING
251         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
252                    "slap_sas_authorize: conn %d  authcid=\"%s\" authzid=\"%s\"\n",
253                    conn ? conn->c_connid : -1,
254                    authcid ? authcid : "<empty>",
255                    authzid ? authzid : "<empty>" ));
256 #else
257         Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
258                 "authcid=\"%s\" authzid=\"%s\"\n",
259                 (long) (conn ? conn->c_connid : -1),
260                 authcid ? authcid : "<empty>",
261                 authzid ? authzid : "<empty>" );
262 #endif
263
264
265         /* Convert the identities to DN's. If no authzid was given, client will
266            be bound as the DN matching their username */
267         rc = slap_sasl_getdn( conn, (char *)authcid, &authcDN, FLAG_GETDN_AUTHCID );
268         if( rc != LDAP_SUCCESS ) {
269                 *errstr = ldap_err2string( rc );
270                 return SASL_NOAUTHZ;
271         }
272         if( ( authzid == NULL ) || !strcmp( authcid,authzid ) ) {
273 #ifdef NEW_LOGGING
274                 LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
275                            "slap_sasl_authorize: conn %d  Using authcDN=%s\n",
276                            conn ? conn->c_connid : -1, authcDN ));
277 #else
278                 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
279                  "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN,0 );
280 #endif
281
282                 *user = authcDN;
283                 *errstr = NULL;
284                 return SASL_OK;
285         }
286         rc = slap_sasl_getdn( conn, (char *)authzid, &authzDN, FLAG_GETDN_AUTHZID );
287         if( rc != LDAP_SUCCESS ) {
288                 ch_free( authcDN );
289                 *errstr = ldap_err2string( rc );
290                 return SASL_NOAUTHZ;
291         }
292
293         rc = slap_sasl_authorized( authcDN, authzDN );
294         if( rc ) {
295 #ifdef NEW_LOGGING
296                 LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
297                            "slap_sasl_authorize: conn %ld  authorization disallowed (%d)\n",
298                            (long)(conn ? conn->c_connid : -1), rc ));
299 #else
300                 Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
301                         " authorization disallowed (%d)\n",
302                         (long) (conn ? conn->c_connid : -1), rc, 0 );
303 #endif
304
305                 *errstr = "not authorized";
306                 ch_free( authcDN );
307                 ch_free( authzDN );
308                 return SASL_NOAUTHZ;
309         }
310
311 #ifdef NEW_LOGGING
312         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
313                    "slap_sasl_authorize: conn %d authorization allowed\n",
314                    (long)(conn ? conn->c_connid : -1 ) ));
315 #else
316         Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
317                 " authorization allowed\n",
318                 (long) (conn ? conn->c_connid : -1), 0, 0 );
319 #endif
320
321
322         ch_free( authcDN );
323         *user = authzDN;
324         *errstr = NULL;
325         return SASL_OK;
326 }
327
328
329 static int
330 slap_sasl_err2ldap( int saslerr )
331 {
332         int rc;
333
334         switch (saslerr) {
335                 case SASL_CONTINUE:
336                         rc = LDAP_SASL_BIND_IN_PROGRESS;
337                         break;
338                 case SASL_FAIL:
339                         rc = LDAP_OTHER;
340                         break;
341                 case SASL_NOMEM:
342                         rc = LDAP_OTHER;
343                         break;
344                 case SASL_NOMECH:
345                         rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
346                         break;
347                 case SASL_BADAUTH:
348                         rc = LDAP_INVALID_CREDENTIALS;
349                         break;
350                 case SASL_NOAUTHZ:
351                         rc = LDAP_INSUFFICIENT_ACCESS;
352                         break;
353                 case SASL_TOOWEAK:
354                 case SASL_ENCRYPT:
355                         rc = LDAP_INAPPROPRIATE_AUTH;
356                         break;
357                 default:
358                         rc = LDAP_OTHER;
359                         break;
360         }
361
362         return rc;
363 }
364 #endif
365
366
367 int slap_sasl_init( void )
368 {
369 #ifdef HAVE_CYRUS_SASL
370         int rc;
371         static sasl_callback_t server_callbacks[] = {
372                 { SASL_CB_LOG, &slap_sasl_log, NULL },
373                 { SASL_CB_LIST_END, NULL, NULL }
374         };
375
376         sasl_set_alloc(
377                 ch_malloc,
378                 ch_calloc,
379                 ch_realloc,
380                 ch_free ); 
381
382         sasl_set_mutex(
383                 ldap_pvt_sasl_mutex_new,
384                 ldap_pvt_sasl_mutex_lock,
385                 ldap_pvt_sasl_mutex_unlock,
386                 ldap_pvt_sasl_mutex_dispose );
387
388         /* should provide callbacks for logging */
389         /* server name should be configurable */
390         rc = sasl_server_init( server_callbacks, "slapd" );
391
392         if( rc != SASL_OK ) {
393 #ifdef NEW_LOGGING
394                 LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
395                            "slap_sasl_init: init failed.\n" ));
396 #else
397                 Debug( LDAP_DEBUG_ANY, "sasl_server_init failed\n",
398                         0, 0, 0 );
399 #endif
400
401                 return -1;
402         }
403
404 #ifdef NEW_LOGGING
405         LDAP_LOG(( "sasl", LDAP_LEVEL_INFO,
406                    "slap_sasl_init: initialized!\n"));
407 #else
408         Debug( LDAP_DEBUG_TRACE, "slap_sasl_init: initialized!\n",
409                 0, 0, 0 );
410 #endif
411
412
413         /* default security properties */
414         memset( &sasl_secprops, '\0', sizeof(sasl_secprops) );
415     sasl_secprops.max_ssf = INT_MAX;
416     sasl_secprops.maxbufsize = 65536;
417     sasl_secprops.security_flags = SASL_SEC_NOPLAINTEXT|SASL_SEC_NOANONYMOUS;
418 #endif
419
420         return 0;
421 }
422
423 int slap_sasl_destroy( void )
424 {
425 #ifdef HAVE_CYRUS_SASL
426         sasl_done();
427 #endif
428         return 0;
429 }
430
431 int slap_sasl_open( Connection *conn )
432 {
433         int sc = LDAP_SUCCESS;
434
435 #ifdef HAVE_CYRUS_SASL
436         sasl_conn_t *ctx = NULL;
437         sasl_callback_t *session_callbacks;
438
439         assert( conn->c_sasl_context == NULL );
440         assert( conn->c_sasl_extra == NULL );
441
442         conn->c_sasl_layers = 0;
443
444         session_callbacks =
445                 ch_calloc( 3, sizeof(sasl_callback_t));
446         conn->c_sasl_extra = session_callbacks;
447
448         session_callbacks[0].id = SASL_CB_LOG;
449         session_callbacks[0].proc = &slap_sasl_log;
450         session_callbacks[0].context = conn;
451
452         session_callbacks[1].id = SASL_CB_PROXY_POLICY;
453         session_callbacks[1].proc = &slap_sasl_authorize;
454         session_callbacks[1].context = conn;
455
456         session_callbacks[2].id = SASL_CB_LIST_END;
457         session_callbacks[2].proc = NULL;
458         session_callbacks[2].context = NULL;
459
460         if( global_host == NULL ) {
461                 global_host = ldap_pvt_get_fqdn( NULL );
462         }
463
464         /* create new SASL context */
465         sc = sasl_server_new( "ldap", global_host, global_realm,
466                 session_callbacks, SASL_SECURITY_LAYER, &ctx );
467
468         if( sc != SASL_OK ) {
469 #ifdef NEW_LOGGING
470                 LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
471                            "slap_sasl_open: sasl_server_new failed: %d\n", sc ));
472 #else
473                 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed: %d\n",
474                         sc, 0, 0 );
475 #endif
476
477                 return -1;
478         }
479
480         conn->c_sasl_context = ctx;
481
482         if( sc == SASL_OK ) {
483                 sc = sasl_setprop( ctx,
484                         SASL_SEC_PROPS, &sasl_secprops );
485
486                 if( sc != SASL_OK ) {
487 #ifdef NEW_LOGGING
488                         LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
489                                    "slap_sasl_open: sasl_setprop failed: %d \n", sc ));
490 #else
491                         Debug( LDAP_DEBUG_ANY, "sasl_setprop failed: %d\n",
492                                 sc, 0, 0 );
493 #endif
494
495                         slap_sasl_close( conn );
496                         return -1;
497                 }
498         }
499
500         sc = slap_sasl_err2ldap( sc );
501 #endif
502         return sc;
503 }
504
505 int slap_sasl_external(
506         Connection *conn,
507         slap_ssf_t ssf,
508         const char *auth_id )
509 {
510 #ifdef HAVE_CYRUS_SASL
511         int sc;
512         sasl_conn_t *ctx = conn->c_sasl_context;
513         sasl_external_properties_t extprops;
514
515         if ( ctx == NULL ) {
516                 return LDAP_UNAVAILABLE;
517         }
518
519         memset( &extprops, '\0', sizeof(extprops) );
520         extprops.ssf = ssf;
521         extprops.auth_id = (char *) auth_id;
522
523         sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
524                 (void *) &extprops );
525
526         if ( sc != SASL_OK ) {
527                 return LDAP_OTHER;
528         }
529 #endif
530
531         return LDAP_SUCCESS;
532 }
533
534 int slap_sasl_reset( Connection *conn )
535 {
536 #ifdef HAVE_CYRUS_SASL
537         sasl_conn_t *ctx = conn->c_sasl_context;
538
539         if( ctx != NULL ) {
540         }
541 #endif
542         /* must return "anonymous" */
543         return LDAP_SUCCESS;
544 }
545
546 char ** slap_sasl_mechs( Connection *conn )
547 {
548         char **mechs = NULL;
549
550 #ifdef HAVE_CYRUS_SASL
551         sasl_conn_t *ctx = conn->c_sasl_context;
552
553         if( ctx != NULL ) {
554                 int sc;
555                 char *mechstr;
556
557                 sc = sasl_listmech( ctx,
558                         NULL, NULL, ",", NULL,
559                         &mechstr, NULL, NULL );
560
561                 if( sc != SASL_OK ) {
562 #ifdef NEW_LOGGING
563                         LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
564                                    "slap_sasl_mechs: sasl_listmech failed: %d\n", sc ));
565 #else
566                         Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
567                                 sc, 0, 0 );
568 #endif
569
570                         return NULL;
571                 }
572
573                 mechs = str2charray( mechstr, "," );
574
575                 ch_free( mechstr );
576         }
577 #endif
578
579         return mechs;
580 }
581
582 int slap_sasl_close( Connection *conn )
583 {
584 #ifdef HAVE_CYRUS_SASL
585         sasl_conn_t *ctx = conn->c_sasl_context;
586
587         if( ctx != NULL ) {
588                 sasl_dispose( &ctx );
589         }
590
591         conn->c_sasl_context = NULL;
592
593         free( conn->c_sasl_extra );
594         conn->c_sasl_extra = NULL;
595 #endif
596
597         return LDAP_SUCCESS;
598 }
599
600 int slap_sasl_bind(
601     Connection          *conn,
602     Operation           *op,  
603     const char          *dn,  
604     const char          *ndn,
605     struct berval       *cred,
606         char                            **edn,
607         slap_ssf_t                      *ssfp )
608 {
609         int rc = 1;
610
611 #ifdef HAVE_CYRUS_SASL
612         sasl_conn_t *ctx = conn->c_sasl_context;
613         struct berval response;
614         unsigned reslen;
615         const char *errstr;
616         int sc;
617
618 #ifdef NEW_LOGGING
619         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
620                    "sasl_bind: conn %ld dn=\"%s\" mech=%s datalen=%d\n",
621                    conn->c_connid, dn,
622                    conn->c_sasl_bind_in_progress ? "<continuing>" : conn->c_sasl_bind_mech,
623                    cred ? cred->bv_len : 0 ));
624 #else
625         Debug(LDAP_DEBUG_ARGS,
626           "==> sasl_bind: dn=\"%s\" mech=%s datalen=%d\n", dn,
627           conn->c_sasl_bind_in_progress ? "<continuing>":conn->c_sasl_bind_mech,
628           cred ? cred->bv_len : 0 );
629 #endif
630
631
632         if( ctx == NULL ) {
633                 send_ldap_result( conn, op, LDAP_UNAVAILABLE,
634                         NULL, "SASL unavailable on this session", NULL, NULL );
635                 return rc;
636         }
637
638         if ( !conn->c_sasl_bind_in_progress ) {
639                 sc = sasl_server_start( ctx,
640                         conn->c_sasl_bind_mech,
641                         cred->bv_val, cred->bv_len,
642                         (char **)&response.bv_val, &reslen, &errstr );
643
644         } else {
645                 sc = sasl_server_step( ctx,
646                         cred->bv_val, cred->bv_len,
647                         (char **)&response.bv_val, &reslen, &errstr );
648         }
649
650         response.bv_len = reslen;
651
652         if ( sc == SASL_OK ) {
653                 char *username = NULL;
654
655                 sc = sasl_getprop( ctx,
656                         SASL_USERNAME, (void **)&username );
657
658                 if ( sc != SASL_OK ) {
659 #ifdef NEW_LOGGING
660                         LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
661                                    "slap_sasl_bind: getprop(USERNAME) failed: %d\n", sc ));
662 #else
663                         Debug(LDAP_DEBUG_TRACE,
664                                 "slap_sasl_bind: getprop(USERNAME) failed!\n",
665                                 0, 0, 0);
666 #endif
667
668
669                         send_ldap_result( conn, op, rc = slap_sasl_err2ldap( sc ),
670                                 NULL, "no SASL username", NULL, NULL );
671
672                 } else {
673                         rc = slap_sasl_getdn( conn, username, edn, FLAG_GETDN_FINAL );
674
675                         if( rc == LDAP_SUCCESS ) {
676                                 int i;
677                                 sasl_ssf_t *ssf = NULL;
678                                 (void) sasl_getprop( ctx, SASL_SSF, (void *)&ssf );
679                                 *ssfp = ssf ? *ssf : 0;
680
681                                 if( *ssfp ) {
682                                         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
683                                         conn->c_sasl_layers++;
684                                         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
685                                 }
686
687                                 /* Store the authorization DN as a subjectDN */
688                                 if ( *edn ) {
689                                         i = 2;
690                                         do {
691                                                 i++;
692                                                 (*edn)[i-3] = (*edn)[i];
693                                         } while( (*edn)[i] );
694                                 }
695
696                                 send_ldap_sasl( conn, op, rc,
697                                         NULL, NULL, NULL, NULL,
698                                         response.bv_len ? &response : NULL );
699
700                         } else {
701                                 send_ldap_result( conn, op, rc,
702                                         NULL, errstr, NULL, NULL );
703                         }
704                 }
705
706         } else if ( sc == SASL_CONTINUE ) {
707                 send_ldap_sasl( conn, op, rc = LDAP_SASL_BIND_IN_PROGRESS,
708                         NULL, NULL, NULL, NULL, &response );
709
710         } else {
711                 send_ldap_result( conn, op, rc = slap_sasl_err2ldap( sc ),
712                         NULL, errstr, NULL, NULL );
713         }
714
715 #ifdef NEW_LOGGING
716         LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
717                    "slap_sasl_bind: rc=%d\n", rc ));
718 #else
719         Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: rc=%d\n", rc, 0, 0);
720 #endif
721
722
723 #else
724         send_ldap_result( conn, op, rc = LDAP_UNAVAILABLE,
725                 NULL, "SASL not supported", NULL, NULL );
726 #endif
727
728         return rc;
729 }
730
731 char* slap_sasl_secprops( const char *in )
732 {
733 #ifdef HAVE_CYRUS_SASL
734         int rc = ldap_pvt_sasl_secprops( in, &sasl_secprops );
735
736         return rc == LDAP_SUCCESS ? NULL : "Invalid security properties";
737 #else
738         return "SASL not supported";
739 #endif
740 }