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 Sockbuf_Buf sec_buf_in;
101 sb_sasl_setup( Sockbuf_IO_Desc *sbiod, void *arg )
103 struct sb_sasl_data *p;
105 assert( sbiod != NULL );
107 p = LBER_MALLOC( sizeof( *p ) );
110 p->sasl_context = (sasl_conn_t *)arg;
111 ber_pvt_sb_buf_init( &p->sec_buf_in );
112 ber_pvt_sb_buf_init( &p->buf_in );
113 ber_pvt_sb_buf_init( &p->buf_out );
114 if ( ber_pvt_sb_grow_buffer( &p->sec_buf_in, SASL_MIN_BUFF_SIZE ) < 0 ) {
119 sbiod->sbiod_pvt = p;
125 sb_sasl_remove( Sockbuf_IO_Desc *sbiod )
127 struct sb_sasl_data *p;
129 assert( sbiod != NULL );
131 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
132 #if SASL_VERSION_MAJOR >= 2
134 * SASLv2 encode/decode buffers are managed by
135 * libsasl2. Ensure they are not freed by liblber.
137 p->buf_in.buf_base = NULL;
138 p->buf_out.buf_base = NULL;
140 ber_pvt_sb_buf_destroy( &p->sec_buf_in );
141 ber_pvt_sb_buf_destroy( &p->buf_in );
142 ber_pvt_sb_buf_destroy( &p->buf_out );
144 sbiod->sbiod_pvt = NULL;
149 sb_sasl_pkt_length( const unsigned char *buf, int debuglevel )
153 assert( buf != NULL );
160 /* we really should check against actual buffer size set
163 if ( size > SASL_MAX_BUFF_SIZE ) {
164 /* somebody is trying to mess me up. */
165 ber_log_printf( LDAP_DEBUG_ANY, debuglevel,
166 "sb_sasl_pkt_length: received illegal packet length "
167 "of %lu bytes\n", (unsigned long)size );
168 size = 16; /* this should lead to an error. */
171 return size + 4; /* include the size !!! */
174 /* Drop a processed packet from the input buffer */
176 sb_sasl_drop_packet ( Sockbuf_Buf *sec_buf_in, int debuglevel )
180 len = sec_buf_in->buf_ptr - sec_buf_in->buf_end;
182 AC_MEMCPY( sec_buf_in->buf_base, sec_buf_in->buf_base +
183 sec_buf_in->buf_end, len );
186 sec_buf_in->buf_end = sb_sasl_pkt_length( sec_buf_in->buf_base,
190 sec_buf_in->buf_end = 0;
192 sec_buf_in->buf_ptr = len;
196 sb_sasl_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
198 struct sb_sasl_data *p;
199 ber_slen_t ret, bufptr;
201 assert( sbiod != NULL );
202 assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
204 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
206 /* Are there anything left in the buffer? */
207 ret = ber_pvt_sb_copy_out( &p->buf_in, buf, len );
214 #if SASL_VERSION_MAJOR >= 2
215 ber_pvt_sb_buf_init( &p->buf_in );
217 ber_pvt_sb_buf_destroy( &p->buf_in );
220 /* Read the length of the packet */
221 while ( p->sec_buf_in.buf_ptr < 4 ) {
222 ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base,
223 4 - p->sec_buf_in.buf_ptr );
225 if ( ( ret < 0 ) && ( errno == EINTR ) )
231 p->sec_buf_in.buf_ptr += ret;
234 /* The new packet always starts at p->sec_buf_in.buf_base */
235 ret = sb_sasl_pkt_length( p->sec_buf_in.buf_base,
236 sbiod->sbiod_sb->sb_debug );
238 /* Grow the packet buffer if neccessary */
239 if ( ( p->sec_buf_in.buf_size < (ber_len_t) ret ) &&
240 ber_pvt_sb_grow_buffer( &p->sec_buf_in, ret ) < 0 )
245 p->sec_buf_in.buf_end = ret;
247 /* Did we read the whole encrypted packet? */
248 while ( p->sec_buf_in.buf_ptr < p->sec_buf_in.buf_end ) {
249 /* No, we have got only a part of it */
250 ret = p->sec_buf_in.buf_end - p->sec_buf_in.buf_ptr;
252 ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base +
253 p->sec_buf_in.buf_ptr, ret );
255 if ( ( ret < 0 ) && ( errno == EINTR ) )
261 p->sec_buf_in.buf_ptr += ret;
264 /* Decode the packet */
265 ret = sasl_decode( p->sasl_context, p->sec_buf_in.buf_base,
266 p->sec_buf_in.buf_end,
267 (SASL_CONST char **)&p->buf_in.buf_base,
268 (unsigned *)&p->buf_in.buf_end );
269 if ( ret != SASL_OK ) {
270 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
271 "sb_sasl_read: failed to decode packet: %s\n",
272 sasl_errstring( ret, NULL, NULL ) );
273 sb_sasl_drop_packet( &p->sec_buf_in,
274 sbiod->sbiod_sb->sb_debug );
279 /* Drop the packet from the input buffer */
280 sb_sasl_drop_packet( &p->sec_buf_in, sbiod->sbiod_sb->sb_debug );
282 p->buf_in.buf_size = p->buf_in.buf_end;
284 bufptr += ber_pvt_sb_copy_out( &p->buf_in, (char*) buf + bufptr, len );
290 sb_sasl_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
292 struct sb_sasl_data *p;
295 assert( sbiod != NULL );
296 assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
298 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
300 /* Are there anything left in the buffer? */
301 if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) {
302 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
307 /* now encode the next packet. */
308 #if SASL_VERSION_MAJOR >= 2
309 ber_pvt_sb_buf_init( &p->buf_out );
311 ber_pvt_sb_buf_destroy( &p->buf_out );
313 ret = sasl_encode( p->sasl_context, buf, len,
314 (SASL_CONST char **)&p->buf_out.buf_base,
315 (unsigned *)&p->buf_out.buf_size );
316 if ( ret != SASL_OK ) {
317 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
318 "sb_sasl_write: failed to encode packet: %s\n",
319 sasl_errstring( ret, NULL, NULL ) );
322 p->buf_out.buf_end = p->buf_out.buf_size;
324 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
331 sb_sasl_ctrl( Sockbuf_IO_Desc *sbiod, int opt, void *arg )
333 struct sb_sasl_data *p;
335 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
337 if ( opt == LBER_SB_OPT_DATA_READY ) {
338 if ( p->buf_in.buf_ptr != p->buf_in.buf_end )
342 return LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg );
345 Sockbuf_IO ldap_pvt_sockbuf_io_sasl = {
346 sb_sasl_setup, /* sbi_setup */
347 sb_sasl_remove, /* sbi_remove */
348 sb_sasl_ctrl, /* sbi_ctrl */
349 sb_sasl_read, /* sbi_read */
350 sb_sasl_write, /* sbi_write */
354 int ldap_pvt_sasl_install( Sockbuf *sb, void *ctx_arg )
357 LDAP_LOG (( "cyrus", LDAP_LEVEL_ENTRY, "ldap_pvt_sasl_install\n" ));
359 Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
363 /* don't install the stuff unless security has been negotiated */
365 if ( !ber_sockbuf_ctrl( sb, LBER_SB_OPT_HAS_IO,
366 &ldap_pvt_sockbuf_io_sasl ) )
369 ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
370 LBER_SBIOD_LEVEL_APPLICATION, (void *)"sasl_" );
372 ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_sasl,
373 LBER_SBIOD_LEVEL_APPLICATION, ctx_arg );
380 sasl_err2ldap( int saslerr )
386 rc = LDAP_MORE_RESULTS_TO_RETURN;
389 rc = LDAP_LOCAL_ERROR;
395 rc = LDAP_LOCAL_ERROR;
401 rc = LDAP_AUTH_UNKNOWN;
404 rc = LDAP_AUTH_UNKNOWN;
407 rc = LDAP_PARAM_ERROR;
411 rc = LDAP_AUTH_UNKNOWN;
414 rc = LDAP_LOCAL_ERROR;
418 assert( rc == LDAP_SUCCESS || LDAP_API_ERROR( rc ) );
432 sasl_callback_t *session_callbacks =
433 LDAP_CALLOC( 2, sizeof( sasl_callback_t ) );
435 if( session_callbacks == NULL ) return LDAP_NO_MEMORY;
437 session_callbacks[0].id = SASL_CB_USER;
438 session_callbacks[0].proc = NULL;
439 session_callbacks[0].context = ld;
441 session_callbacks[1].id = SASL_CB_LIST_END;
442 session_callbacks[1].proc = NULL;
443 session_callbacks[1].context = NULL;
445 assert( lc->lconn_sasl_ctx == NULL );
447 if ( host == NULL ) {
448 ld->ld_errno = LDAP_LOCAL_ERROR;
452 #if SASL_VERSION_MAJOR >= 2
453 rc = sasl_client_new( "ldap", host, NULL, NULL,
454 session_callbacks, 0, &ctx );
456 rc = sasl_client_new( "ldap", host, session_callbacks,
457 SASL_SECURITY_LAYER, &ctx );
459 LDAP_FREE( session_callbacks );
461 if ( rc != SASL_OK ) {
462 ld->ld_errno = sasl_err2ldap( rc );
467 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
468 "ldap_int_sasl_open: host=%s\n", host ));
470 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: host=%s\n",
474 lc->lconn_sasl_ctx = ctx;
477 #if SASL_VERSION_MAJOR >= 2
478 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
481 sasl_external_properties_t extprops;
482 memset(&extprops, 0L, sizeof(extprops));
485 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
486 (void *) &extprops );
489 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
490 "ldap_int_sasl_open: ssf=%ld\n", (long) ssf ));
492 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: ssf=%ld\n",
500 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
502 sasl_conn_t *ctx = lc->lconn_sasl_ctx;
505 sasl_dispose( &ctx );
506 lc->lconn_sasl_ctx = NULL;
517 LDAPControl **sctrls,
518 LDAPControl **cctrls,
520 LDAP_SASL_INTERACT_PROC *interact,
524 const char *mech = NULL;
525 const char *pmech = NULL;
527 sasl_ssf_t *ssf = NULL;
529 sasl_interact_t *prompts = NULL;
535 LDAP_LOG (( "cyrus", LDAP_LEVEL_ARGS,
536 "ldap_int_sasl_bind: %s\n", mechs ? mechs : "<null>" ));
538 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_bind: %s\n",
539 mechs ? mechs : "<null>", 0, 0 );
542 /* do a quick !LDAPv3 check... ldap_sasl_bind will do the rest. */
543 if (ld->ld_version < LDAP_VERSION3) {
544 ld->ld_errno = LDAP_NOT_SUPPORTED;
548 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
550 if ( sd == AC_SOCKET_INVALID ) {
551 /* not connected yet */
554 rc = ldap_open_defconn( ld );
555 if( rc < 0 ) return ld->ld_errno;
557 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
559 if( sd == AC_SOCKET_INVALID ) {
560 ld->ld_errno = LDAP_LOCAL_ERROR;
565 ctx = ld->ld_defconn->lconn_sasl_ctx;
568 ld->ld_errno = LDAP_LOCAL_ERROR;
572 /* (re)set security properties */
573 sasl_setprop( ctx, SASL_SEC_PROPS,
574 &ld->ld_options.ldo_sasl_secprops );
580 saslrc = sasl_client_start( ctx,
582 #if SASL_VERSION_MAJOR < 2
586 (SASL_CONST char **)&ccred.bv_val,
590 if( pmech == NULL && mech != NULL ) {
593 if( flags != LDAP_SASL_QUIET ) {
595 "SASL/%s authentication started\n",
600 #if SASL_VERSION_MAJOR >= 2
601 /* XXX the application should free interact results. */
602 if ( prompts != NULL && prompts->result != NULL ) {
603 LDAP_FREE( (void *)prompts->result );
604 prompts->result = NULL;
608 if( saslrc == SASL_INTERACT ) {
610 if( !interact ) break;
611 res = (interact)( ld, flags, defaults, prompts );
612 if( res != LDAP_SUCCESS ) {
616 } while ( saslrc == SASL_INTERACT );
618 ccred.bv_len = credlen;
620 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
621 ld->ld_errno = sasl_err2ldap( saslrc );
622 #if SASL_VERSION_MAJOR >= 2
623 ld->ld_error = (char *)sasl_errdetail( ctx );
629 struct berval *scred;
634 rc = ldap_sasl_bind_s( ld, dn, mech, &ccred, sctrls, cctrls, &scred );
636 if ( ccred.bv_val != NULL ) {
637 #if SASL_VERSION_MAJOR < 2
638 LDAP_FREE( ccred.bv_val );
643 if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) {
644 if( scred && scred->bv_len ) {
645 /* and server provided us with data? */
647 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
648 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
649 rc, saslrc, scred->bv_len ));
651 Debug( LDAP_DEBUG_TRACE,
652 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
653 rc, saslrc, scred->bv_len );
660 if( rc == LDAP_SUCCESS && saslrc == SASL_OK ) {
661 /* we're done, no need to step */
662 if( scred && scred->bv_len ) {
663 /* but server provided us with data! */
665 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
666 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
667 rc, saslrc, scred->bv_len ));
669 Debug( LDAP_DEBUG_TRACE,
670 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
671 rc, saslrc, scred->bv_len );
674 return ld->ld_errno = LDAP_LOCAL_ERROR;
680 saslrc = sasl_client_step( ctx,
681 (scred == NULL) ? NULL : scred->bv_val,
682 (scred == NULL) ? 0 : scred->bv_len,
684 (SASL_CONST char **)&ccred.bv_val,
688 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
689 "ldap_int_sasl_bind: sasl_client_step: %d\n", saslrc ));
691 Debug( LDAP_DEBUG_TRACE, "sasl_client_step: %d\n",
695 #if SASL_VERSION_MAJOR >= 2
696 /* XXX the application should free interact results. */
697 if ( prompts != NULL && prompts->result != NULL ) {
698 LDAP_FREE( (void *)prompts->result );
699 prompts->result = NULL;
703 if( saslrc == SASL_INTERACT ) {
705 if( !interact ) break;
706 res = (interact)( ld, flags, defaults, prompts );
707 if( res != LDAP_SUCCESS ) {
711 } while ( saslrc == SASL_INTERACT );
713 ccred.bv_len = credlen;
716 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
717 ld->ld_errno = sasl_err2ldap( saslrc );
718 #if SASL_VERSION_MAJOR >= 2
719 ld->ld_error = (char *)sasl_errdetail( ctx );
723 } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
725 if ( rc != LDAP_SUCCESS ) {
729 if ( saslrc != SASL_OK ) {
730 #if SASL_VERSION_MAJOR >= 2
731 ld->ld_error = (char *)sasl_errdetail( ctx );
733 return ld->ld_errno = sasl_err2ldap( saslrc );
736 if( flags != LDAP_SASL_QUIET ) {
737 saslrc = sasl_getprop( ctx, SASL_USERNAME, (SASL_CONST void **) &data );
738 if( saslrc == SASL_OK && data && *data ) {
739 fprintf( stderr, "SASL username: %s\n", data );
742 #if SASL_VERSION_MAJOR >= 2
743 saslrc = sasl_getprop( ctx, SASL_DEFUSERREALM, (SASL_CONST void **) &data );
745 saslrc = sasl_getprop( ctx, SASL_REALM, (SASL_CONST void **) &data );
747 if( saslrc == SASL_OK && data && *data ) {
748 fprintf( stderr, "SASL realm: %s\n", data );
752 saslrc = sasl_getprop( ctx, SASL_SSF, (SASL_CONST void **) &ssf );
753 if( saslrc == SASL_OK ) {
754 if( flags != LDAP_SASL_QUIET ) {
755 fprintf( stderr, "SASL SSF: %lu\n",
756 (unsigned long) *ssf );
760 if( flags != LDAP_SASL_QUIET ) {
761 fprintf( stderr, "SASL installing layers\n" );
763 ldap_pvt_sasl_install( ld->ld_conns->lconn_sb, ctx );
771 ldap_int_sasl_external(
779 #if SASL_VERSION_MAJOR < 2
780 sasl_external_properties_t extprops;
783 ctx = conn->lconn_sasl_ctx;
786 return LDAP_LOCAL_ERROR;
789 #if SASL_VERSION_MAJOR >= 2
790 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
792 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
794 memset( &extprops, '\0', sizeof(extprops) );
796 extprops.auth_id = (char *) authid;
798 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
799 (void *) &extprops );
802 if ( sc != SASL_OK ) {
803 return LDAP_LOCAL_ERROR;
810 int ldap_pvt_sasl_secprops(
812 sasl_security_properties_t *secprops )
815 char **props = ldap_str2charray( in, "," );
818 sasl_ssf_t max_ssf = 0;
820 sasl_ssf_t min_ssf = 0;
822 unsigned maxbufsize = 0;
823 int got_maxbufsize = 0;
825 if( props == NULL || secprops == NULL ) {
826 return LDAP_PARAM_ERROR;
829 for( i=0; props[i]; i++ ) {
830 if( !strcasecmp(props[i], "none") ) {
833 } else if( !strcasecmp(props[i], "noplain") ) {
835 sflags |= SASL_SEC_NOPLAINTEXT;
837 } else if( !strcasecmp(props[i], "noactive") ) {
839 sflags |= SASL_SEC_NOACTIVE;
841 } else if( !strcasecmp(props[i], "nodict") ) {
843 sflags |= SASL_SEC_NODICTIONARY;
845 } else if( !strcasecmp(props[i], "forwardsec") ) {
847 sflags |= SASL_SEC_FORWARD_SECRECY;
849 } else if( !strcasecmp(props[i], "noanonymous")) {
851 sflags |= SASL_SEC_NOANONYMOUS;
853 } else if( !strcasecmp(props[i], "passcred") ) {
855 sflags |= SASL_SEC_PASS_CREDENTIALS;
857 } else if( !strncasecmp(props[i],
858 "minssf=", sizeof("minssf")) )
860 if( isdigit( (unsigned char) props[i][sizeof("minssf")] ) ) {
862 min_ssf = atoi( &props[i][sizeof("minssf")] );
864 return LDAP_NOT_SUPPORTED;
867 } else if( !strncasecmp(props[i],
868 "maxssf=", sizeof("maxssf")) )
870 if( isdigit( (unsigned char) props[i][sizeof("maxssf")] ) ) {
872 max_ssf = atoi( &props[i][sizeof("maxssf")] );
874 return LDAP_NOT_SUPPORTED;
877 } else if( !strncasecmp(props[i],
878 "maxbufsize=", sizeof("maxbufsize")) )
880 if( isdigit( (unsigned char) props[i][sizeof("maxbufsize")] ) ) {
882 maxbufsize = atoi( &props[i][sizeof("maxbufsize")] );
884 return LDAP_NOT_SUPPORTED;
887 if( maxbufsize && (( maxbufsize < SASL_MIN_BUFF_SIZE )
888 || (maxbufsize > SASL_MAX_BUFF_SIZE )))
891 return LDAP_PARAM_ERROR;
895 return LDAP_NOT_SUPPORTED;
900 secprops->security_flags = sflags;
903 secprops->min_ssf = min_ssf;
906 secprops->max_ssf = max_ssf;
909 secprops->maxbufsize = maxbufsize;
912 ldap_charray_free( props );
917 ldap_int_sasl_config( struct ldapoptions *lo, int option, const char *arg )
922 case LDAP_OPT_X_SASL_SECPROPS:
923 rc = ldap_pvt_sasl_secprops( arg, &lo->ldo_sasl_secprops );
924 if( rc == LDAP_SUCCESS ) return 0;
931 ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
937 case LDAP_OPT_X_SASL_MECH: {
938 *(char **)arg = ld->ld_options.ldo_def_sasl_mech
939 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_mech ) : NULL;
941 case LDAP_OPT_X_SASL_REALM: {
942 *(char **)arg = ld->ld_options.ldo_def_sasl_realm
943 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_realm ) : NULL;
945 case LDAP_OPT_X_SASL_AUTHCID: {
946 *(char **)arg = ld->ld_options.ldo_def_sasl_authcid
947 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authcid ) : NULL;
949 case LDAP_OPT_X_SASL_AUTHZID: {
950 *(char **)arg = ld->ld_options.ldo_def_sasl_authzid
951 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authzid ) : NULL;
954 case LDAP_OPT_X_SASL_SSF: {
959 if( ld->ld_defconn == NULL ) {
963 ctx = ld->ld_defconn->lconn_sasl_ctx;
969 sc = sasl_getprop( ctx, SASL_SSF,
970 (SASL_CONST void **) &ssf );
972 if ( sc != SASL_OK ) {
976 *(ber_len_t *)arg = *ssf;
979 case LDAP_OPT_X_SASL_SSF_EXTERNAL:
980 /* this option is write only */
983 case LDAP_OPT_X_SASL_SSF_MIN:
984 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.min_ssf;
986 case LDAP_OPT_X_SASL_SSF_MAX:
987 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.max_ssf;
989 case LDAP_OPT_X_SASL_MAXBUFSIZE:
990 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
993 case LDAP_OPT_X_SASL_SECPROPS:
994 /* this option is write only */
1004 ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
1010 case LDAP_OPT_X_SASL_SSF:
1011 /* This option is read-only */
1014 case LDAP_OPT_X_SASL_SSF_EXTERNAL: {
1016 #if SASL_VERSION_MAJOR < 2
1017 sasl_external_properties_t extprops;
1021 if( ld->ld_defconn == NULL ) {
1025 ctx = ld->ld_defconn->lconn_sasl_ctx;
1027 if ( ctx == NULL ) {
1031 #if SASL_VERSION_MAJOR >= 2
1032 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, arg);
1034 memset(&extprops, 0L, sizeof(extprops));
1036 extprops.ssf = * (ber_len_t *) arg;
1038 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1039 (void *) &extprops );
1042 if ( sc != SASL_OK ) {
1047 case LDAP_OPT_X_SASL_SSF_MIN:
1048 ld->ld_options.ldo_sasl_secprops.min_ssf = *(ber_len_t *)arg;
1050 case LDAP_OPT_X_SASL_SSF_MAX:
1051 ld->ld_options.ldo_sasl_secprops.max_ssf = *(ber_len_t *)arg;
1053 case LDAP_OPT_X_SASL_MAXBUFSIZE:
1054 ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
1057 case LDAP_OPT_X_SASL_SECPROPS: {
1059 sc = ldap_pvt_sasl_secprops( (char *) arg,
1060 &ld->ld_options.ldo_sasl_secprops );
1062 return sc == LDAP_SUCCESS ? 0 : -1;
1071 #ifdef LDAP_R_COMPILE
1072 void *ldap_pvt_sasl_mutex_new(void)
1074 ldap_pvt_thread_mutex_t *mutex;
1076 mutex = (ldap_pvt_thread_mutex_t *) LDAP_MALLOC(
1077 sizeof(ldap_pvt_thread_mutex_t) );
1079 if ( ldap_pvt_thread_mutex_init( mutex ) == 0 ) {
1085 int ldap_pvt_sasl_mutex_lock(void *mutex)
1087 return ldap_pvt_thread_mutex_lock( (ldap_pvt_thread_mutex_t *)mutex )
1088 ? SASL_FAIL : SASL_OK;
1091 int ldap_pvt_sasl_mutex_unlock(void *mutex)
1093 return ldap_pvt_thread_mutex_unlock( (ldap_pvt_thread_mutex_t *)mutex )
1094 ? SASL_FAIL : SASL_OK;
1097 void ldap_pvt_sasl_mutex_dispose(void *mutex)
1099 (void) ldap_pvt_thread_mutex_destroy( (ldap_pvt_thread_mutex_t *)mutex );
1105 int ldap_int_sasl_init( void )
1106 { return LDAP_SUCCESS; }
1108 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
1109 { return LDAP_SUCCESS; }
1116 LDAPControl **sctrls,
1117 LDAPControl **cctrls,
1119 LDAP_SASL_INTERACT_PROC *interact,
1121 { return LDAP_NOT_SUPPORTED; }
1124 ldap_int_sasl_external(
1127 const char * authid,
1129 { return LDAP_SUCCESS; }
1131 #endif /* HAVE_CYRUS_SASL */