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;
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 );
311 sasl_getprop( p->sasl_context, SASL_MAXOUTBUF, (const void **)&max );
313 ber_pvt_sb_buf_destroy( &p->buf_out );
314 sasl_getprop( p->sasl_context, SASL_MAXOUTBUF, (void **)&max );
316 if ( len > *max - 100 )
317 len = *max - 100; /* For safety margin */
318 ret = sasl_encode( p->sasl_context, buf, len,
319 (SASL_CONST char **)&p->buf_out.buf_base,
320 (unsigned *)&p->buf_out.buf_size );
321 if ( ret != SASL_OK ) {
322 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
323 "sb_sasl_write: failed to encode packet: %s\n",
324 sasl_errstring( ret, NULL, NULL ) );
327 p->buf_out.buf_end = p->buf_out.buf_size;
329 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
336 sb_sasl_ctrl( Sockbuf_IO_Desc *sbiod, int opt, void *arg )
338 struct sb_sasl_data *p;
340 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
342 if ( opt == LBER_SB_OPT_DATA_READY ) {
343 if ( p->buf_in.buf_ptr != p->buf_in.buf_end )
347 return LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg );
350 Sockbuf_IO ldap_pvt_sockbuf_io_sasl = {
351 sb_sasl_setup, /* sbi_setup */
352 sb_sasl_remove, /* sbi_remove */
353 sb_sasl_ctrl, /* sbi_ctrl */
354 sb_sasl_read, /* sbi_read */
355 sb_sasl_write, /* sbi_write */
359 int ldap_pvt_sasl_install( Sockbuf *sb, void *ctx_arg )
362 LDAP_LOG (( "cyrus", LDAP_LEVEL_ENTRY, "ldap_pvt_sasl_install\n" ));
364 Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
368 /* don't install the stuff unless security has been negotiated */
370 if ( !ber_sockbuf_ctrl( sb, LBER_SB_OPT_HAS_IO,
371 &ldap_pvt_sockbuf_io_sasl ) )
374 ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
375 LBER_SBIOD_LEVEL_APPLICATION, (void *)"sasl_" );
377 ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_sasl,
378 LBER_SBIOD_LEVEL_APPLICATION, ctx_arg );
385 sasl_err2ldap( int saslerr )
391 rc = LDAP_MORE_RESULTS_TO_RETURN;
394 rc = LDAP_LOCAL_ERROR;
400 rc = LDAP_LOCAL_ERROR;
406 rc = LDAP_AUTH_UNKNOWN;
409 rc = LDAP_AUTH_UNKNOWN;
412 rc = LDAP_PARAM_ERROR;
416 rc = LDAP_AUTH_UNKNOWN;
419 rc = LDAP_LOCAL_ERROR;
423 assert( rc == LDAP_SUCCESS || LDAP_API_ERROR( rc ) );
437 assert( lc->lconn_sasl_ctx == NULL );
439 if ( host == NULL ) {
440 ld->ld_errno = LDAP_LOCAL_ERROR;
444 #if SASL_VERSION_MAJOR >= 2
445 rc = sasl_client_new( "ldap", host, NULL, NULL,
448 rc = sasl_client_new( "ldap", host, NULL,
449 SASL_SECURITY_LAYER, &ctx );
452 if ( rc != SASL_OK ) {
453 ld->ld_errno = sasl_err2ldap( rc );
458 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
459 "ldap_int_sasl_open: host=%s\n", host ));
461 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: host=%s\n",
465 lc->lconn_sasl_ctx = ctx;
468 #if SASL_VERSION_MAJOR >= 2
469 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
472 sasl_external_properties_t extprops;
473 memset(&extprops, 0L, sizeof(extprops));
476 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
477 (void *) &extprops );
480 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
481 "ldap_int_sasl_open: ssf=%ld\n", (long) ssf ));
483 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: ssf=%ld\n",
491 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
493 sasl_conn_t *ctx = lc->lconn_sasl_ctx;
496 sasl_dispose( &ctx );
497 lc->lconn_sasl_ctx = NULL;
508 LDAPControl **sctrls,
509 LDAPControl **cctrls,
511 LDAP_SASL_INTERACT_PROC *interact,
515 const char *mech = NULL;
516 const char *pmech = NULL;
518 sasl_ssf_t *ssf = NULL;
520 sasl_interact_t *prompts = NULL;
526 LDAP_LOG (( "cyrus", LDAP_LEVEL_ARGS,
527 "ldap_int_sasl_bind: %s\n", mechs ? mechs : "<null>" ));
529 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_bind: %s\n",
530 mechs ? mechs : "<null>", 0, 0 );
533 /* do a quick !LDAPv3 check... ldap_sasl_bind will do the rest. */
534 if (ld->ld_version < LDAP_VERSION3) {
535 ld->ld_errno = LDAP_NOT_SUPPORTED;
539 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
541 if ( sd == AC_SOCKET_INVALID ) {
542 /* not connected yet */
545 rc = ldap_open_defconn( ld );
546 if( rc < 0 ) return ld->ld_errno;
548 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
550 if( sd == AC_SOCKET_INVALID ) {
551 ld->ld_errno = LDAP_LOCAL_ERROR;
556 ctx = ld->ld_defconn->lconn_sasl_ctx;
559 ld->ld_errno = LDAP_LOCAL_ERROR;
563 /* (re)set security properties */
564 sasl_setprop( ctx, SASL_SEC_PROPS,
565 &ld->ld_options.ldo_sasl_secprops );
571 saslrc = sasl_client_start( ctx,
573 #if SASL_VERSION_MAJOR < 2
577 (SASL_CONST char **)&ccred.bv_val,
581 if( pmech == NULL && mech != NULL ) {
584 if( flags != LDAP_SASL_QUIET ) {
586 "SASL/%s authentication started\n",
591 #if SASL_VERSION_MAJOR >= 2
592 /* XXX the application should free interact results. */
593 if ( prompts != NULL && prompts->result != NULL ) {
594 LDAP_FREE( (void *)prompts->result );
595 prompts->result = NULL;
599 if( saslrc == SASL_INTERACT ) {
601 if( !interact ) break;
602 res = (interact)( ld, flags, defaults, prompts );
603 if( res != LDAP_SUCCESS ) {
607 } while ( saslrc == SASL_INTERACT );
609 ccred.bv_len = credlen;
611 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
612 ld->ld_errno = sasl_err2ldap( saslrc );
613 #if SASL_VERSION_MAJOR >= 2
614 ld->ld_error = (char *)sasl_errdetail( ctx );
620 struct berval *scred;
625 rc = ldap_sasl_bind_s( ld, dn, mech, &ccred, sctrls, cctrls, &scred );
627 if ( ccred.bv_val != NULL ) {
628 #if SASL_VERSION_MAJOR < 2
629 LDAP_FREE( ccred.bv_val );
634 if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) {
635 if( scred && scred->bv_len ) {
636 /* and server provided us with data? */
638 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
639 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
640 rc, saslrc, scred->bv_len ));
642 Debug( LDAP_DEBUG_TRACE,
643 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
644 rc, saslrc, scred->bv_len );
651 if( rc == LDAP_SUCCESS && saslrc == SASL_OK ) {
652 /* we're done, no need to step */
653 if( scred && scred->bv_len ) {
654 /* but server provided us with data! */
656 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
657 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
658 rc, saslrc, scred->bv_len ));
660 Debug( LDAP_DEBUG_TRACE,
661 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
662 rc, saslrc, scred->bv_len );
665 return ld->ld_errno = LDAP_LOCAL_ERROR;
671 saslrc = sasl_client_step( ctx,
672 (scred == NULL) ? NULL : scred->bv_val,
673 (scred == NULL) ? 0 : scred->bv_len,
675 (SASL_CONST char **)&ccred.bv_val,
679 LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1,
680 "ldap_int_sasl_bind: sasl_client_step: %d\n", saslrc ));
682 Debug( LDAP_DEBUG_TRACE, "sasl_client_step: %d\n",
686 #if SASL_VERSION_MAJOR >= 2
687 /* XXX the application should free interact results. */
688 if ( prompts != NULL && prompts->result != NULL ) {
689 LDAP_FREE( (void *)prompts->result );
690 prompts->result = NULL;
694 if( saslrc == SASL_INTERACT ) {
696 if( !interact ) break;
697 res = (interact)( ld, flags, defaults, prompts );
698 if( res != LDAP_SUCCESS ) {
702 } while ( saslrc == SASL_INTERACT );
704 ccred.bv_len = credlen;
707 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
708 ld->ld_errno = sasl_err2ldap( saslrc );
709 #if SASL_VERSION_MAJOR >= 2
710 ld->ld_error = (char *)sasl_errdetail( ctx );
714 } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
716 if ( rc != LDAP_SUCCESS ) {
720 if ( saslrc != SASL_OK ) {
721 #if SASL_VERSION_MAJOR >= 2
722 ld->ld_error = (char *)sasl_errdetail( ctx );
724 return ld->ld_errno = sasl_err2ldap( saslrc );
727 if( flags != LDAP_SASL_QUIET ) {
728 saslrc = sasl_getprop( ctx, SASL_USERNAME, (SASL_CONST void **) &data );
729 if( saslrc == SASL_OK && data && *data ) {
730 fprintf( stderr, "SASL username: %s\n", data );
733 #if SASL_VERSION_MAJOR >= 2
734 saslrc = sasl_getprop( ctx, SASL_DEFUSERREALM, (SASL_CONST void **) &data );
736 saslrc = sasl_getprop( ctx, SASL_REALM, (SASL_CONST void **) &data );
738 if( saslrc == SASL_OK && data && *data ) {
739 fprintf( stderr, "SASL realm: %s\n", data );
743 saslrc = sasl_getprop( ctx, SASL_SSF, (SASL_CONST void **) &ssf );
744 if( saslrc == SASL_OK ) {
745 if( flags != LDAP_SASL_QUIET ) {
746 fprintf( stderr, "SASL SSF: %lu\n",
747 (unsigned long) *ssf );
751 if( flags != LDAP_SASL_QUIET ) {
752 fprintf( stderr, "SASL installing layers\n" );
754 ldap_pvt_sasl_install( ld->ld_conns->lconn_sb, ctx );
762 ldap_int_sasl_external(
770 #if SASL_VERSION_MAJOR < 2
771 sasl_external_properties_t extprops;
774 ctx = conn->lconn_sasl_ctx;
777 return LDAP_LOCAL_ERROR;
780 #if SASL_VERSION_MAJOR >= 2
781 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
783 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
785 memset( &extprops, '\0', sizeof(extprops) );
787 extprops.auth_id = (char *) authid;
789 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
790 (void *) &extprops );
793 if ( sc != SASL_OK ) {
794 return LDAP_LOCAL_ERROR;
801 int ldap_pvt_sasl_secprops(
803 sasl_security_properties_t *secprops )
806 char **props = ldap_str2charray( in, "," );
809 sasl_ssf_t max_ssf = 0;
811 sasl_ssf_t min_ssf = 0;
813 unsigned maxbufsize = 0;
814 int got_maxbufsize = 0;
816 if( props == NULL || secprops == NULL ) {
817 return LDAP_PARAM_ERROR;
820 for( i=0; props[i]; i++ ) {
821 if( !strcasecmp(props[i], "none") ) {
824 } else if( !strcasecmp(props[i], "noplain") ) {
826 sflags |= SASL_SEC_NOPLAINTEXT;
828 } else if( !strcasecmp(props[i], "noactive") ) {
830 sflags |= SASL_SEC_NOACTIVE;
832 } else if( !strcasecmp(props[i], "nodict") ) {
834 sflags |= SASL_SEC_NODICTIONARY;
836 } else if( !strcasecmp(props[i], "forwardsec") ) {
838 sflags |= SASL_SEC_FORWARD_SECRECY;
840 } else if( !strcasecmp(props[i], "noanonymous")) {
842 sflags |= SASL_SEC_NOANONYMOUS;
844 } else if( !strcasecmp(props[i], "passcred") ) {
846 sflags |= SASL_SEC_PASS_CREDENTIALS;
848 } else if( !strncasecmp(props[i],
849 "minssf=", sizeof("minssf")) )
851 if( isdigit( (unsigned char) props[i][sizeof("minssf")] ) ) {
853 min_ssf = atoi( &props[i][sizeof("minssf")] );
855 return LDAP_NOT_SUPPORTED;
858 } else if( !strncasecmp(props[i],
859 "maxssf=", sizeof("maxssf")) )
861 if( isdigit( (unsigned char) props[i][sizeof("maxssf")] ) ) {
863 max_ssf = atoi( &props[i][sizeof("maxssf")] );
865 return LDAP_NOT_SUPPORTED;
868 } else if( !strncasecmp(props[i],
869 "maxbufsize=", sizeof("maxbufsize")) )
871 if( isdigit( (unsigned char) props[i][sizeof("maxbufsize")] ) ) {
873 maxbufsize = atoi( &props[i][sizeof("maxbufsize")] );
875 return LDAP_NOT_SUPPORTED;
878 if( maxbufsize && (( maxbufsize < SASL_MIN_BUFF_SIZE )
879 || (maxbufsize > SASL_MAX_BUFF_SIZE )))
882 return LDAP_PARAM_ERROR;
886 return LDAP_NOT_SUPPORTED;
891 secprops->security_flags = sflags;
894 secprops->min_ssf = min_ssf;
897 secprops->max_ssf = max_ssf;
900 secprops->maxbufsize = maxbufsize;
903 ldap_charray_free( props );
908 ldap_int_sasl_config( struct ldapoptions *lo, int option, const char *arg )
913 case LDAP_OPT_X_SASL_SECPROPS:
914 rc = ldap_pvt_sasl_secprops( arg, &lo->ldo_sasl_secprops );
915 if( rc == LDAP_SUCCESS ) return 0;
922 ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
928 case LDAP_OPT_X_SASL_MECH: {
929 *(char **)arg = ld->ld_options.ldo_def_sasl_mech
930 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_mech ) : NULL;
932 case LDAP_OPT_X_SASL_REALM: {
933 *(char **)arg = ld->ld_options.ldo_def_sasl_realm
934 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_realm ) : NULL;
936 case LDAP_OPT_X_SASL_AUTHCID: {
937 *(char **)arg = ld->ld_options.ldo_def_sasl_authcid
938 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authcid ) : NULL;
940 case LDAP_OPT_X_SASL_AUTHZID: {
941 *(char **)arg = ld->ld_options.ldo_def_sasl_authzid
942 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authzid ) : NULL;
945 case LDAP_OPT_X_SASL_SSF: {
950 if( ld->ld_defconn == NULL ) {
954 ctx = ld->ld_defconn->lconn_sasl_ctx;
960 sc = sasl_getprop( ctx, SASL_SSF,
961 (SASL_CONST void **) &ssf );
963 if ( sc != SASL_OK ) {
967 *(ber_len_t *)arg = *ssf;
970 case LDAP_OPT_X_SASL_SSF_EXTERNAL:
971 /* this option is write only */
974 case LDAP_OPT_X_SASL_SSF_MIN:
975 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.min_ssf;
977 case LDAP_OPT_X_SASL_SSF_MAX:
978 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.max_ssf;
980 case LDAP_OPT_X_SASL_MAXBUFSIZE:
981 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
984 case LDAP_OPT_X_SASL_SECPROPS:
985 /* this option is write only */
995 ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
1001 case LDAP_OPT_X_SASL_SSF:
1002 /* This option is read-only */
1005 case LDAP_OPT_X_SASL_SSF_EXTERNAL: {
1007 #if SASL_VERSION_MAJOR < 2
1008 sasl_external_properties_t extprops;
1012 if( ld->ld_defconn == NULL ) {
1016 ctx = ld->ld_defconn->lconn_sasl_ctx;
1018 if ( ctx == NULL ) {
1022 #if SASL_VERSION_MAJOR >= 2
1023 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, arg);
1025 memset(&extprops, 0L, sizeof(extprops));
1027 extprops.ssf = * (ber_len_t *) arg;
1029 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1030 (void *) &extprops );
1033 if ( sc != SASL_OK ) {
1038 case LDAP_OPT_X_SASL_SSF_MIN:
1039 ld->ld_options.ldo_sasl_secprops.min_ssf = *(ber_len_t *)arg;
1041 case LDAP_OPT_X_SASL_SSF_MAX:
1042 ld->ld_options.ldo_sasl_secprops.max_ssf = *(ber_len_t *)arg;
1044 case LDAP_OPT_X_SASL_MAXBUFSIZE:
1045 ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
1048 case LDAP_OPT_X_SASL_SECPROPS: {
1050 sc = ldap_pvt_sasl_secprops( (char *) arg,
1051 &ld->ld_options.ldo_sasl_secprops );
1053 return sc == LDAP_SUCCESS ? 0 : -1;
1062 #ifdef LDAP_R_COMPILE
1063 void *ldap_pvt_sasl_mutex_new(void)
1065 ldap_pvt_thread_mutex_t *mutex;
1067 mutex = (ldap_pvt_thread_mutex_t *) LDAP_MALLOC(
1068 sizeof(ldap_pvt_thread_mutex_t) );
1070 if ( ldap_pvt_thread_mutex_init( mutex ) == 0 ) {
1076 int ldap_pvt_sasl_mutex_lock(void *mutex)
1078 return ldap_pvt_thread_mutex_lock( (ldap_pvt_thread_mutex_t *)mutex )
1079 ? SASL_FAIL : SASL_OK;
1082 int ldap_pvt_sasl_mutex_unlock(void *mutex)
1084 return ldap_pvt_thread_mutex_unlock( (ldap_pvt_thread_mutex_t *)mutex )
1085 ? SASL_FAIL : SASL_OK;
1088 void ldap_pvt_sasl_mutex_dispose(void *mutex)
1090 (void) ldap_pvt_thread_mutex_destroy( (ldap_pvt_thread_mutex_t *)mutex );
1096 int ldap_int_sasl_init( void )
1097 { return LDAP_SUCCESS; }
1099 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
1100 { return LDAP_SUCCESS; }
1107 LDAPControl **sctrls,
1108 LDAPControl **cctrls,
1110 LDAP_SASL_INTERACT_PROC *interact,
1112 { return LDAP_NOT_SUPPORTED; }
1115 ldap_int_sasl_external(
1118 const char * authid,
1120 { return LDAP_SUCCESS; }
1122 #endif /* HAVE_CYRUS_SASL */