3 * Copyright 1999-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/socket.h>
12 #include <ac/stdlib.h>
13 #include <ac/string.h>
20 #ifdef HAVE_CYRUS_SASL
23 ldap_pvt_thread_mutex_t ldap_int_sasl_mutex;
26 #ifdef HAVE_SASL_SASL_H
27 #include <sasl/sasl.h>
32 #if SASL_VERSION_MAJOR >= 2
33 #define SASL_CONST const
39 * Various Cyrus SASL related stuff.
42 int ldap_int_sasl_init( void )
44 /* XXX not threadsafe */
45 static int sasl_initialized = 0;
47 static sasl_callback_t client_callbacks[] = {
48 #ifdef SASL_CB_GETREALM
49 { SASL_CB_GETREALM, NULL, NULL },
51 { SASL_CB_USER, NULL, NULL },
52 { SASL_CB_AUTHNAME, NULL, NULL },
53 { SASL_CB_PASS, NULL, NULL },
54 { SASL_CB_ECHOPROMPT, NULL, NULL },
55 { SASL_CB_NOECHOPROMPT, NULL, NULL },
56 { SASL_CB_LIST_END, NULL, NULL }
59 if ( sasl_initialized ) {
69 #endif /* CSRIMALLOC */
73 ldap_pvt_sasl_mutex_new,
74 ldap_pvt_sasl_mutex_lock,
75 ldap_pvt_sasl_mutex_unlock,
76 ldap_pvt_sasl_mutex_dispose );
78 ldap_pvt_thread_mutex_init( &ldap_int_sasl_mutex );
81 if ( sasl_client_init( client_callbacks ) == SASL_OK ) {
90 * SASL encryption support for LBER Sockbufs
94 sasl_conn_t *sasl_context;
95 unsigned *sasl_maxbuf;
96 Sockbuf_Buf sec_buf_in;
102 sb_sasl_setup( Sockbuf_IO_Desc *sbiod, void *arg )
104 struct sb_sasl_data *p;
106 assert( sbiod != NULL );
108 p = LBER_MALLOC( sizeof( *p ) );
111 p->sasl_context = (sasl_conn_t *)arg;
112 ber_pvt_sb_buf_init( &p->sec_buf_in );
113 ber_pvt_sb_buf_init( &p->buf_in );
114 ber_pvt_sb_buf_init( &p->buf_out );
115 if ( ber_pvt_sb_grow_buffer( &p->sec_buf_in, SASL_MIN_BUFF_SIZE ) < 0 ) {
120 sasl_getprop( p->sasl_context, SASL_MAXOUTBUF,
121 (SASL_CONST void **) &p->sasl_maxbuf );
123 sbiod->sbiod_pvt = p;
129 sb_sasl_remove( Sockbuf_IO_Desc *sbiod )
131 struct sb_sasl_data *p;
133 assert( sbiod != NULL );
135 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
136 #if SASL_VERSION_MAJOR >= 2
138 * SASLv2 encode/decode buffers are managed by
139 * libsasl2. Ensure they are not freed by liblber.
141 p->buf_in.buf_base = NULL;
142 p->buf_out.buf_base = NULL;
144 ber_pvt_sb_buf_destroy( &p->sec_buf_in );
145 ber_pvt_sb_buf_destroy( &p->buf_in );
146 ber_pvt_sb_buf_destroy( &p->buf_out );
148 sbiod->sbiod_pvt = NULL;
153 sb_sasl_pkt_length( const unsigned char *buf, unsigned max, int debuglevel )
157 assert( buf != NULL );
165 /* somebody is trying to mess me up. */
166 ber_log_printf( LDAP_DEBUG_ANY, debuglevel,
167 "sb_sasl_pkt_length: received illegal packet length "
168 "of %lu bytes\n", (unsigned long)size );
169 size = 16; /* this should lead to an error. */
172 return size + 4; /* include the size !!! */
175 /* Drop a processed packet from the input buffer */
177 sb_sasl_drop_packet ( Sockbuf_Buf *sec_buf_in, unsigned max, int debuglevel )
181 len = sec_buf_in->buf_ptr - sec_buf_in->buf_end;
183 AC_MEMCPY( sec_buf_in->buf_base, sec_buf_in->buf_base +
184 sec_buf_in->buf_end, len );
187 sec_buf_in->buf_end = sb_sasl_pkt_length( sec_buf_in->buf_base,
191 sec_buf_in->buf_end = 0;
193 sec_buf_in->buf_ptr = len;
197 sb_sasl_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
199 struct sb_sasl_data *p;
200 ber_slen_t ret, bufptr;
202 assert( sbiod != NULL );
203 assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
205 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
207 /* Are there anything left in the buffer? */
208 ret = ber_pvt_sb_copy_out( &p->buf_in, buf, len );
215 #if SASL_VERSION_MAJOR >= 2
216 ber_pvt_sb_buf_init( &p->buf_in );
218 ber_pvt_sb_buf_destroy( &p->buf_in );
221 /* Read the length of the packet */
222 while ( p->sec_buf_in.buf_ptr < 4 ) {
223 ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base,
224 4 - p->sec_buf_in.buf_ptr );
226 if ( ( ret < 0 ) && ( errno == EINTR ) )
232 p->sec_buf_in.buf_ptr += ret;
235 /* The new packet always starts at p->sec_buf_in.buf_base */
236 ret = sb_sasl_pkt_length( p->sec_buf_in.buf_base,
237 *p->sasl_maxbuf, sbiod->sbiod_sb->sb_debug );
239 /* Grow the packet buffer if neccessary */
240 if ( ( p->sec_buf_in.buf_size < (ber_len_t) ret ) &&
241 ber_pvt_sb_grow_buffer( &p->sec_buf_in, ret ) < 0 )
246 p->sec_buf_in.buf_end = ret;
248 /* Did we read the whole encrypted packet? */
249 while ( p->sec_buf_in.buf_ptr < p->sec_buf_in.buf_end ) {
250 /* No, we have got only a part of it */
251 ret = p->sec_buf_in.buf_end - p->sec_buf_in.buf_ptr;
253 ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base +
254 p->sec_buf_in.buf_ptr, ret );
256 if ( ( ret < 0 ) && ( errno == EINTR ) )
262 p->sec_buf_in.buf_ptr += ret;
265 /* Decode the packet */
266 ret = sasl_decode( p->sasl_context, p->sec_buf_in.buf_base,
267 p->sec_buf_in.buf_end,
268 (SASL_CONST char **)&p->buf_in.buf_base,
269 (unsigned *)&p->buf_in.buf_end );
271 /* Drop the packet from the input buffer */
272 sb_sasl_drop_packet( &p->sec_buf_in,
273 *p->sasl_maxbuf, sbiod->sbiod_sb->sb_debug );
275 if ( ret != SASL_OK ) {
276 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
277 "sb_sasl_read: failed to decode packet: %s\n",
278 sasl_errstring( ret, NULL, NULL ) );
283 p->buf_in.buf_size = p->buf_in.buf_end;
285 bufptr += ber_pvt_sb_copy_out( &p->buf_in, (char*) buf + bufptr, len );
291 sb_sasl_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
293 struct sb_sasl_data *p;
296 assert( sbiod != NULL );
297 assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
299 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
301 /* Are there anything left in the buffer? */
302 if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) {
303 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
308 /* now encode the next packet. */
309 #if SASL_VERSION_MAJOR >= 2
310 ber_pvt_sb_buf_init( &p->buf_out );
312 ber_pvt_sb_buf_destroy( &p->buf_out );
314 if ( len > *p->sasl_maxbuf - 100 )
315 len = *p->sasl_maxbuf - 100; /* For safety margin */
316 ret = sasl_encode( p->sasl_context, buf, len,
317 (SASL_CONST char **)&p->buf_out.buf_base,
318 (unsigned *)&p->buf_out.buf_size );
319 if ( ret != SASL_OK ) {
320 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
321 "sb_sasl_write: failed to encode packet: %s\n",
322 sasl_errstring( ret, NULL, NULL ) );
325 p->buf_out.buf_end = p->buf_out.buf_size;
327 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
334 sb_sasl_ctrl( Sockbuf_IO_Desc *sbiod, int opt, void *arg )
336 struct sb_sasl_data *p;
338 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
340 if ( opt == LBER_SB_OPT_DATA_READY ) {
341 if ( p->buf_in.buf_ptr != p->buf_in.buf_end )
345 return LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg );
348 Sockbuf_IO ldap_pvt_sockbuf_io_sasl = {
349 sb_sasl_setup, /* sbi_setup */
350 sb_sasl_remove, /* sbi_remove */
351 sb_sasl_ctrl, /* sbi_ctrl */
352 sb_sasl_read, /* sbi_read */
353 sb_sasl_write, /* sbi_write */
357 int ldap_pvt_sasl_install( Sockbuf *sb, void *ctx_arg )
360 LDAP_LOG (( "cyrus", LDAP_LEVEL_ENTRY, "ldap_pvt_sasl_install\n" ));
362 Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
366 /* don't install the stuff unless security has been negotiated */
368 if ( !ber_sockbuf_ctrl( sb, LBER_SB_OPT_HAS_IO,
369 &ldap_pvt_sockbuf_io_sasl ) )
372 ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
373 LBER_SBIOD_LEVEL_APPLICATION, (void *)"sasl_" );
375 ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_sasl,
376 LBER_SBIOD_LEVEL_APPLICATION, ctx_arg );
383 sasl_err2ldap( int saslerr )
389 rc = LDAP_MORE_RESULTS_TO_RETURN;
392 rc = LDAP_LOCAL_ERROR;
398 rc = LDAP_LOCAL_ERROR;
404 rc = LDAP_AUTH_UNKNOWN;
407 rc = LDAP_AUTH_UNKNOWN;
410 rc = LDAP_PARAM_ERROR;
414 rc = LDAP_AUTH_UNKNOWN;
417 rc = LDAP_LOCAL_ERROR;
421 assert( rc == LDAP_SUCCESS || LDAP_API_ERROR( rc ) );
435 assert( lc->lconn_sasl_ctx == NULL );
437 if ( host == NULL ) {
438 ld->ld_errno = LDAP_LOCAL_ERROR;
442 #if SASL_VERSION_MAJOR >= 2
443 rc = sasl_client_new( "ldap", host, NULL, NULL,
446 rc = sasl_client_new( "ldap", host, NULL,
447 SASL_SECURITY_LAYER, &ctx );
450 if ( rc != SASL_OK ) {
451 ld->ld_errno = sasl_err2ldap( rc );
456 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
457 "ldap_int_sasl_open: host=%s\n", host ));
459 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: host=%s\n",
463 lc->lconn_sasl_ctx = ctx;
466 #if SASL_VERSION_MAJOR >= 2
467 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
470 sasl_external_properties_t extprops;
471 memset(&extprops, 0L, sizeof(extprops));
474 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
475 (void *) &extprops );
478 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
479 "ldap_int_sasl_open: ssf=%ld\n", (long) ssf ));
481 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: ssf=%ld\n",
489 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
491 sasl_conn_t *ctx = lc->lconn_sasl_ctx;
494 sasl_dispose( &ctx );
495 lc->lconn_sasl_ctx = NULL;
506 LDAPControl **sctrls,
507 LDAPControl **cctrls,
509 LDAP_SASL_INTERACT_PROC *interact,
513 const char *mech = NULL;
514 const char *pmech = NULL;
516 sasl_ssf_t *ssf = NULL;
518 sasl_interact_t *prompts = NULL;
524 LDAP_LOG (( "cyrus", LDAP_LEVEL_ARGS,
525 "ldap_int_sasl_bind: %s\n", mechs ? mechs : "<null>" ));
527 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_bind: %s\n",
528 mechs ? mechs : "<null>", 0, 0 );
531 /* do a quick !LDAPv3 check... ldap_sasl_bind will do the rest. */
532 if (ld->ld_version < LDAP_VERSION3) {
533 ld->ld_errno = LDAP_NOT_SUPPORTED;
537 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
539 if ( sd == AC_SOCKET_INVALID ) {
540 /* not connected yet */
543 rc = ldap_open_defconn( ld );
544 if( rc < 0 ) return ld->ld_errno;
546 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
548 if( sd == AC_SOCKET_INVALID ) {
549 ld->ld_errno = LDAP_LOCAL_ERROR;
554 ctx = ld->ld_defconn->lconn_sasl_ctx;
557 ld->ld_errno = LDAP_LOCAL_ERROR;
561 /* (re)set security properties */
562 sasl_setprop( ctx, SASL_SEC_PROPS,
563 &ld->ld_options.ldo_sasl_secprops );
569 saslrc = sasl_client_start( ctx,
571 #if SASL_VERSION_MAJOR < 2
575 (SASL_CONST char **)&ccred.bv_val,
579 if( pmech == NULL && mech != NULL ) {
582 if( flags != LDAP_SASL_QUIET ) {
584 "SASL/%s authentication started\n",
589 #if SASL_VERSION_MAJOR >= 2
590 /* XXX the application should free interact results. */
591 if ( prompts != NULL && prompts->result != NULL ) {
592 LDAP_FREE( (void *)prompts->result );
593 prompts->result = NULL;
597 if( saslrc == SASL_INTERACT ) {
599 if( !interact ) break;
600 res = (interact)( ld, flags, defaults, prompts );
601 if( res != LDAP_SUCCESS ) {
605 } while ( saslrc == SASL_INTERACT );
607 ccred.bv_len = credlen;
609 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
610 ld->ld_errno = sasl_err2ldap( saslrc );
611 #if SASL_VERSION_MAJOR >= 2
612 ld->ld_error = (char *)sasl_errdetail( ctx );
618 struct berval *scred;
623 rc = ldap_sasl_bind_s( ld, dn, mech, &ccred, sctrls, cctrls, &scred );
625 if ( ccred.bv_val != NULL ) {
626 #if SASL_VERSION_MAJOR < 2
627 LDAP_FREE( ccred.bv_val );
632 if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) {
633 if( scred && scred->bv_len ) {
634 /* and server provided us with data? */
636 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
637 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
638 rc, saslrc, scred->bv_len ));
640 Debug( LDAP_DEBUG_TRACE,
641 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
642 rc, saslrc, scred->bv_len );
649 if( rc == LDAP_SUCCESS && saslrc == SASL_OK ) {
650 /* we're done, no need to step */
651 if( scred && scred->bv_len ) {
652 /* but server provided us with data! */
654 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
655 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
656 rc, saslrc, scred->bv_len ));
658 Debug( LDAP_DEBUG_TRACE,
659 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
660 rc, saslrc, scred->bv_len );
663 return ld->ld_errno = LDAP_LOCAL_ERROR;
669 saslrc = sasl_client_step( ctx,
670 (scred == NULL) ? NULL : scred->bv_val,
671 (scred == NULL) ? 0 : scred->bv_len,
673 (SASL_CONST char **)&ccred.bv_val,
677 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
678 "ldap_int_sasl_bind: sasl_client_step: %d\n", saslrc ));
680 Debug( LDAP_DEBUG_TRACE, "sasl_client_step: %d\n",
684 #if SASL_VERSION_MAJOR >= 2
685 /* XXX the application should free interact results. */
686 if ( prompts != NULL && prompts->result != NULL ) {
687 LDAP_FREE( (void *)prompts->result );
688 prompts->result = NULL;
692 if( saslrc == SASL_INTERACT ) {
694 if( !interact ) break;
695 res = (interact)( ld, flags, defaults, prompts );
696 if( res != LDAP_SUCCESS ) {
700 } while ( saslrc == SASL_INTERACT );
702 ccred.bv_len = credlen;
705 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
706 ld->ld_errno = sasl_err2ldap( saslrc );
707 #if SASL_VERSION_MAJOR >= 2
708 ld->ld_error = (char *)sasl_errdetail( ctx );
712 } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
714 if ( rc != LDAP_SUCCESS ) {
718 if ( saslrc != SASL_OK ) {
719 #if SASL_VERSION_MAJOR >= 2
720 ld->ld_error = (char *)sasl_errdetail( ctx );
722 return ld->ld_errno = sasl_err2ldap( saslrc );
725 if( flags != LDAP_SASL_QUIET ) {
726 saslrc = sasl_getprop( ctx, SASL_USERNAME, (SASL_CONST void **) &data );
727 if( saslrc == SASL_OK && data && *data ) {
728 fprintf( stderr, "SASL username: %s\n", data );
731 #if SASL_VERSION_MAJOR >= 2
732 saslrc = sasl_getprop( ctx, SASL_DEFUSERREALM, (SASL_CONST void **) &data );
734 saslrc = sasl_getprop( ctx, SASL_REALM, (SASL_CONST void **) &data );
736 if( saslrc == SASL_OK && data && *data ) {
737 fprintf( stderr, "SASL realm: %s\n", data );
741 saslrc = sasl_getprop( ctx, SASL_SSF, (SASL_CONST void **) &ssf );
742 if( saslrc == SASL_OK ) {
743 if( flags != LDAP_SASL_QUIET ) {
744 fprintf( stderr, "SASL SSF: %lu\n",
745 (unsigned long) *ssf );
749 if( flags != LDAP_SASL_QUIET ) {
750 fprintf( stderr, "SASL installing layers\n" );
752 ldap_pvt_sasl_install( ld->ld_conns->lconn_sb, ctx );
760 ldap_int_sasl_external(
768 #if SASL_VERSION_MAJOR < 2
769 sasl_external_properties_t extprops;
772 ctx = conn->lconn_sasl_ctx;
775 return LDAP_LOCAL_ERROR;
778 #if SASL_VERSION_MAJOR >= 2
779 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
781 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
783 memset( &extprops, '\0', sizeof(extprops) );
785 extprops.auth_id = (char *) authid;
787 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
788 (void *) &extprops );
791 if ( sc != SASL_OK ) {
792 return LDAP_LOCAL_ERROR;
799 int ldap_pvt_sasl_secprops(
801 sasl_security_properties_t *secprops )
804 char **props = ldap_str2charray( in, "," );
807 sasl_ssf_t max_ssf = 0;
809 sasl_ssf_t min_ssf = 0;
811 unsigned maxbufsize = 0;
812 int got_maxbufsize = 0;
814 if( props == NULL || secprops == NULL ) {
815 return LDAP_PARAM_ERROR;
818 for( i=0; props[i]; i++ ) {
819 if( !strcasecmp(props[i], "none") ) {
822 } else if( !strcasecmp(props[i], "noplain") ) {
824 sflags |= SASL_SEC_NOPLAINTEXT;
826 } else if( !strcasecmp(props[i], "noactive") ) {
828 sflags |= SASL_SEC_NOACTIVE;
830 } else if( !strcasecmp(props[i], "nodict") ) {
832 sflags |= SASL_SEC_NODICTIONARY;
834 } else if( !strcasecmp(props[i], "forwardsec") ) {
836 sflags |= SASL_SEC_FORWARD_SECRECY;
838 } else if( !strcasecmp(props[i], "noanonymous")) {
840 sflags |= SASL_SEC_NOANONYMOUS;
842 } else if( !strcasecmp(props[i], "passcred") ) {
844 sflags |= SASL_SEC_PASS_CREDENTIALS;
846 } else if( !strncasecmp(props[i],
847 "minssf=", sizeof("minssf")) )
849 if( isdigit( (unsigned char) props[i][sizeof("minssf")] ) ) {
851 min_ssf = atoi( &props[i][sizeof("minssf")] );
853 return LDAP_NOT_SUPPORTED;
856 } else if( !strncasecmp(props[i],
857 "maxssf=", sizeof("maxssf")) )
859 if( isdigit( (unsigned char) props[i][sizeof("maxssf")] ) ) {
861 max_ssf = atoi( &props[i][sizeof("maxssf")] );
863 return LDAP_NOT_SUPPORTED;
866 } else if( !strncasecmp(props[i],
867 "maxbufsize=", sizeof("maxbufsize")) )
869 if( isdigit( (unsigned char) props[i][sizeof("maxbufsize")] ) ) {
871 maxbufsize = atoi( &props[i][sizeof("maxbufsize")] );
873 return LDAP_NOT_SUPPORTED;
876 if( maxbufsize && (( maxbufsize < SASL_MIN_BUFF_SIZE )
877 || (maxbufsize > SASL_MAX_BUFF_SIZE )))
880 return LDAP_PARAM_ERROR;
884 return LDAP_NOT_SUPPORTED;
889 secprops->security_flags = sflags;
892 secprops->min_ssf = min_ssf;
895 secprops->max_ssf = max_ssf;
898 secprops->maxbufsize = maxbufsize;
901 ldap_charray_free( props );
906 ldap_int_sasl_config( struct ldapoptions *lo, int option, const char *arg )
911 case LDAP_OPT_X_SASL_SECPROPS:
912 rc = ldap_pvt_sasl_secprops( arg, &lo->ldo_sasl_secprops );
913 if( rc == LDAP_SUCCESS ) return 0;
920 ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
926 case LDAP_OPT_X_SASL_MECH: {
927 *(char **)arg = ld->ld_options.ldo_def_sasl_mech
928 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_mech ) : NULL;
930 case LDAP_OPT_X_SASL_REALM: {
931 *(char **)arg = ld->ld_options.ldo_def_sasl_realm
932 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_realm ) : NULL;
934 case LDAP_OPT_X_SASL_AUTHCID: {
935 *(char **)arg = ld->ld_options.ldo_def_sasl_authcid
936 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authcid ) : NULL;
938 case LDAP_OPT_X_SASL_AUTHZID: {
939 *(char **)arg = ld->ld_options.ldo_def_sasl_authzid
940 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authzid ) : NULL;
943 case LDAP_OPT_X_SASL_SSF: {
948 if( ld->ld_defconn == NULL ) {
952 ctx = ld->ld_defconn->lconn_sasl_ctx;
958 sc = sasl_getprop( ctx, SASL_SSF,
959 (SASL_CONST void **) &ssf );
961 if ( sc != SASL_OK ) {
965 *(ber_len_t *)arg = *ssf;
968 case LDAP_OPT_X_SASL_SSF_EXTERNAL:
969 /* this option is write only */
972 case LDAP_OPT_X_SASL_SSF_MIN:
973 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.min_ssf;
975 case LDAP_OPT_X_SASL_SSF_MAX:
976 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.max_ssf;
978 case LDAP_OPT_X_SASL_MAXBUFSIZE:
979 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
982 case LDAP_OPT_X_SASL_SECPROPS:
983 /* this option is write only */
993 ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
999 case LDAP_OPT_X_SASL_SSF:
1000 /* This option is read-only */
1003 case LDAP_OPT_X_SASL_SSF_EXTERNAL: {
1005 #if SASL_VERSION_MAJOR < 2
1006 sasl_external_properties_t extprops;
1010 if( ld->ld_defconn == NULL ) {
1014 ctx = ld->ld_defconn->lconn_sasl_ctx;
1016 if ( ctx == NULL ) {
1020 #if SASL_VERSION_MAJOR >= 2
1021 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, arg);
1023 memset(&extprops, 0L, sizeof(extprops));
1025 extprops.ssf = * (ber_len_t *) arg;
1027 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1028 (void *) &extprops );
1031 if ( sc != SASL_OK ) {
1036 case LDAP_OPT_X_SASL_SSF_MIN:
1037 ld->ld_options.ldo_sasl_secprops.min_ssf = *(ber_len_t *)arg;
1039 case LDAP_OPT_X_SASL_SSF_MAX:
1040 ld->ld_options.ldo_sasl_secprops.max_ssf = *(ber_len_t *)arg;
1042 case LDAP_OPT_X_SASL_MAXBUFSIZE:
1043 ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
1046 case LDAP_OPT_X_SASL_SECPROPS: {
1048 sc = ldap_pvt_sasl_secprops( (char *) arg,
1049 &ld->ld_options.ldo_sasl_secprops );
1051 return sc == LDAP_SUCCESS ? 0 : -1;
1060 #ifdef LDAP_R_COMPILE
1061 void *ldap_pvt_sasl_mutex_new(void)
1063 ldap_pvt_thread_mutex_t *mutex;
1065 mutex = (ldap_pvt_thread_mutex_t *) LDAP_MALLOC(
1066 sizeof(ldap_pvt_thread_mutex_t) );
1068 if ( ldap_pvt_thread_mutex_init( mutex ) == 0 ) {
1074 int ldap_pvt_sasl_mutex_lock(void *mutex)
1076 return ldap_pvt_thread_mutex_lock( (ldap_pvt_thread_mutex_t *)mutex )
1077 ? SASL_FAIL : SASL_OK;
1080 int ldap_pvt_sasl_mutex_unlock(void *mutex)
1082 return ldap_pvt_thread_mutex_unlock( (ldap_pvt_thread_mutex_t *)mutex )
1083 ? SASL_FAIL : SASL_OK;
1086 void ldap_pvt_sasl_mutex_dispose(void *mutex)
1088 (void) ldap_pvt_thread_mutex_destroy( (ldap_pvt_thread_mutex_t *)mutex );
1094 int ldap_int_sasl_init( void )
1095 { return LDAP_SUCCESS; }
1097 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
1098 { return LDAP_SUCCESS; }
1105 LDAPControl **sctrls,
1106 LDAPControl **cctrls,
1108 LDAP_SASL_INTERACT_PROC *interact,
1110 { return LDAP_NOT_SUPPORTED; }
1113 ldap_int_sasl_external(
1116 const char * authid,
1118 { return LDAP_SUCCESS; }
1120 #endif /* HAVE_CYRUS_SASL */