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 );
164 if ( size > SASL_MAX_BUFF_SIZE ) {
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. */
170 } else if ( size > max ) {
171 ber_log_printf( LDAP_DEBUG_ANY, debuglevel,
172 "sb_sasl_pkt_length: received packet length "
173 "of %lu exceeds negotiated max of %lu bytes\n", (unsigned long)size, (unsigned long)max );
176 return size + 4; /* include the size !!! */
179 /* Drop a processed packet from the input buffer */
181 sb_sasl_drop_packet ( Sockbuf_Buf *sec_buf_in, unsigned max, int debuglevel )
185 len = sec_buf_in->buf_ptr - sec_buf_in->buf_end;
187 AC_MEMCPY( sec_buf_in->buf_base, sec_buf_in->buf_base +
188 sec_buf_in->buf_end, len );
191 sec_buf_in->buf_end = sb_sasl_pkt_length( sec_buf_in->buf_base,
195 sec_buf_in->buf_end = 0;
197 sec_buf_in->buf_ptr = len;
201 sb_sasl_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
203 struct sb_sasl_data *p;
204 ber_slen_t ret, bufptr;
206 assert( sbiod != NULL );
207 assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
209 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
211 /* Are there anything left in the buffer? */
212 ret = ber_pvt_sb_copy_out( &p->buf_in, buf, len );
219 #if SASL_VERSION_MAJOR >= 2
220 ber_pvt_sb_buf_init( &p->buf_in );
222 ber_pvt_sb_buf_destroy( &p->buf_in );
225 /* Read the length of the packet */
226 while ( p->sec_buf_in.buf_ptr < 4 ) {
227 ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base,
228 4 - p->sec_buf_in.buf_ptr );
230 if ( ( ret < 0 ) && ( errno == EINTR ) )
236 p->sec_buf_in.buf_ptr += ret;
239 /* The new packet always starts at p->sec_buf_in.buf_base */
240 ret = sb_sasl_pkt_length( p->sec_buf_in.buf_base,
241 *p->sasl_maxbuf, sbiod->sbiod_sb->sb_debug );
243 /* Grow the packet buffer if neccessary */
244 if ( ( p->sec_buf_in.buf_size < (ber_len_t) ret ) &&
245 ber_pvt_sb_grow_buffer( &p->sec_buf_in, ret ) < 0 )
250 p->sec_buf_in.buf_end = ret;
252 /* Did we read the whole encrypted packet? */
253 while ( p->sec_buf_in.buf_ptr < p->sec_buf_in.buf_end ) {
254 /* No, we have got only a part of it */
255 ret = p->sec_buf_in.buf_end - p->sec_buf_in.buf_ptr;
257 ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base +
258 p->sec_buf_in.buf_ptr, ret );
260 if ( ( ret < 0 ) && ( errno == EINTR ) )
266 p->sec_buf_in.buf_ptr += ret;
269 /* Decode the packet */
270 ret = sasl_decode( p->sasl_context, p->sec_buf_in.buf_base,
271 p->sec_buf_in.buf_end,
272 (SASL_CONST char **)&p->buf_in.buf_base,
273 (unsigned *)&p->buf_in.buf_end );
275 /* Drop the packet from the input buffer */
276 sb_sasl_drop_packet( &p->sec_buf_in,
277 *p->sasl_maxbuf, sbiod->sbiod_sb->sb_debug );
279 if ( ret != SASL_OK ) {
280 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
281 "sb_sasl_read: failed to decode packet: %s\n",
282 sasl_errstring( ret, NULL, NULL ) );
287 p->buf_in.buf_size = p->buf_in.buf_end;
289 bufptr += ber_pvt_sb_copy_out( &p->buf_in, (char*) buf + bufptr, len );
295 sb_sasl_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
297 struct sb_sasl_data *p;
300 assert( sbiod != NULL );
301 assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
303 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
305 /* Are there anything left in the buffer? */
306 if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) {
307 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
312 /* now encode the next packet. */
313 #if SASL_VERSION_MAJOR >= 2
314 ber_pvt_sb_buf_init( &p->buf_out );
316 ber_pvt_sb_buf_destroy( &p->buf_out );
318 if ( len > *p->sasl_maxbuf - 100 )
319 len = *p->sasl_maxbuf - 100; /* For safety margin */
320 ret = sasl_encode( p->sasl_context, buf, len,
321 (SASL_CONST char **)&p->buf_out.buf_base,
322 (unsigned *)&p->buf_out.buf_size );
323 if ( ret != SASL_OK ) {
324 ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
325 "sb_sasl_write: failed to encode packet: %s\n",
326 sasl_errstring( ret, NULL, NULL ) );
329 p->buf_out.buf_end = p->buf_out.buf_size;
331 ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
338 sb_sasl_ctrl( Sockbuf_IO_Desc *sbiod, int opt, void *arg )
340 struct sb_sasl_data *p;
342 p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
344 if ( opt == LBER_SB_OPT_DATA_READY ) {
345 if ( p->buf_in.buf_ptr != p->buf_in.buf_end )
349 return LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg );
352 Sockbuf_IO ldap_pvt_sockbuf_io_sasl = {
353 sb_sasl_setup, /* sbi_setup */
354 sb_sasl_remove, /* sbi_remove */
355 sb_sasl_ctrl, /* sbi_ctrl */
356 sb_sasl_read, /* sbi_read */
357 sb_sasl_write, /* sbi_write */
361 int ldap_pvt_sasl_install( Sockbuf *sb, void *ctx_arg )
364 LDAP_LOG ( TRANSPORT, ENTRY, "ldap_pvt_sasl_install\n", 0, 0, 0 );
366 Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
370 /* don't install the stuff unless security has been negotiated */
372 if ( !ber_sockbuf_ctrl( sb, LBER_SB_OPT_HAS_IO,
373 &ldap_pvt_sockbuf_io_sasl ) )
376 ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
377 LBER_SBIOD_LEVEL_APPLICATION, (void *)"sasl_" );
379 ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_sasl,
380 LBER_SBIOD_LEVEL_APPLICATION, ctx_arg );
387 sasl_err2ldap( int saslerr )
393 rc = LDAP_MORE_RESULTS_TO_RETURN;
396 rc = LDAP_LOCAL_ERROR;
402 rc = LDAP_LOCAL_ERROR;
408 rc = LDAP_AUTH_UNKNOWN;
411 rc = LDAP_AUTH_UNKNOWN;
414 rc = LDAP_PARAM_ERROR;
418 rc = LDAP_AUTH_UNKNOWN;
421 rc = LDAP_LOCAL_ERROR;
425 assert( rc == LDAP_SUCCESS || LDAP_API_ERROR( rc ) );
439 assert( lc->lconn_sasl_ctx == NULL );
441 if ( host == NULL ) {
442 ld->ld_errno = LDAP_LOCAL_ERROR;
446 #if SASL_VERSION_MAJOR >= 2
447 rc = sasl_client_new( "ldap", host, NULL, NULL,
450 rc = sasl_client_new( "ldap", host, NULL,
451 SASL_SECURITY_LAYER, &ctx );
454 if ( rc != SASL_OK ) {
455 ld->ld_errno = sasl_err2ldap( rc );
460 LDAP_LOG ( TRANSPORT, DETAIL1, "ldap_int_sasl_open: host=%s\n",
463 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: host=%s\n",
467 lc->lconn_sasl_ctx = ctx;
470 #if SASL_VERSION_MAJOR >= 2
471 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
474 sasl_external_properties_t extprops;
475 memset(&extprops, 0L, sizeof(extprops));
478 (void) sasl_setprop( ctx, SASL_SSF_EXTERNAL,
479 (void *) &extprops );
482 LDAP_LOG ( TRANSPORT, DETAIL1,
483 "ldap_int_sasl_open: ssf=%ld\n", (long) ssf, 0, 0 );
485 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: ssf=%ld\n",
493 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
495 sasl_conn_t *ctx = lc->lconn_sasl_ctx;
498 sasl_dispose( &ctx );
499 lc->lconn_sasl_ctx = NULL;
510 LDAPControl **sctrls,
511 LDAPControl **cctrls,
513 LDAP_SASL_INTERACT_PROC *interact,
517 const char *mech = NULL;
518 const char *pmech = NULL;
520 sasl_ssf_t *ssf = NULL;
522 sasl_interact_t *prompts = NULL;
528 LDAP_LOG ( TRANSPORT, ARGS, "ldap_int_sasl_bind: %s\n",
529 mechs ? mechs : "<null>", 0, 0 );
531 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_bind: %s\n",
532 mechs ? mechs : "<null>", 0, 0 );
535 /* do a quick !LDAPv3 check... ldap_sasl_bind will do the rest. */
536 if (ld->ld_version < LDAP_VERSION3) {
537 ld->ld_errno = LDAP_NOT_SUPPORTED;
541 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
543 if ( sd == AC_SOCKET_INVALID ) {
544 /* not connected yet */
547 rc = ldap_open_defconn( ld );
548 if( rc < 0 ) return ld->ld_errno;
550 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
552 if( sd == AC_SOCKET_INVALID ) {
553 ld->ld_errno = LDAP_LOCAL_ERROR;
558 ctx = ld->ld_defconn->lconn_sasl_ctx;
561 ld->ld_errno = LDAP_LOCAL_ERROR;
565 /* (re)set security properties */
566 sasl_setprop( ctx, SASL_SEC_PROPS,
567 &ld->ld_options.ldo_sasl_secprops );
573 saslrc = sasl_client_start( ctx,
575 #if SASL_VERSION_MAJOR < 2
579 (SASL_CONST char **)&ccred.bv_val,
583 if( pmech == NULL && mech != NULL ) {
586 if( flags != LDAP_SASL_QUIET ) {
588 "SASL/%s authentication started\n",
593 #if SASL_VERSION_MAJOR >= 2
594 /* XXX the application should free interact results. */
595 if ( prompts != NULL && prompts->result != NULL ) {
596 LDAP_FREE( (void *)prompts->result );
597 prompts->result = NULL;
601 if( saslrc == SASL_INTERACT ) {
603 if( !interact ) break;
604 res = (interact)( ld, flags, defaults, prompts );
605 if( res != LDAP_SUCCESS ) {
609 } while ( saslrc == SASL_INTERACT );
611 ccred.bv_len = credlen;
613 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
614 ld->ld_errno = sasl_err2ldap( saslrc );
615 #if SASL_VERSION_MAJOR >= 2
616 ld->ld_error = (char *)sasl_errdetail( ctx );
622 struct berval *scred;
627 rc = ldap_sasl_bind_s( ld, dn, mech, &ccred, sctrls, cctrls, &scred );
629 if ( ccred.bv_val != NULL ) {
630 #if SASL_VERSION_MAJOR < 2
631 LDAP_FREE( ccred.bv_val );
636 if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) {
637 if( scred && scred->bv_len ) {
638 /* and server provided us with data? */
640 LDAP_LOG ( TRANSPORT, DETAIL1,
641 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
642 rc, saslrc, scred->bv_len );
644 Debug( LDAP_DEBUG_TRACE,
645 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
646 rc, saslrc, scred->bv_len );
653 if( rc == LDAP_SUCCESS && saslrc == SASL_OK ) {
654 /* we're done, no need to step */
655 if( scred && scred->bv_len ) {
656 /* but server provided us with data! */
658 LDAP_LOG ( TRANSPORT, DETAIL1,
659 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
660 rc, saslrc, scred->bv_len );
662 Debug( LDAP_DEBUG_TRACE,
663 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
664 rc, saslrc, scred->bv_len );
667 return ld->ld_errno = LDAP_LOCAL_ERROR;
673 saslrc = sasl_client_step( ctx,
674 (scred == NULL) ? NULL : scred->bv_val,
675 (scred == NULL) ? 0 : scred->bv_len,
677 (SASL_CONST char **)&ccred.bv_val,
681 LDAP_LOG ( TRANSPORT, DETAIL1,
682 "ldap_int_sasl_bind: sasl_client_step: %d\n", saslrc,0,0 );
684 Debug( LDAP_DEBUG_TRACE, "sasl_client_step: %d\n",
688 #if SASL_VERSION_MAJOR >= 2
689 /* XXX the application should free interact results. */
690 if ( prompts != NULL && prompts->result != NULL ) {
691 LDAP_FREE( (void *)prompts->result );
692 prompts->result = NULL;
696 if( saslrc == SASL_INTERACT ) {
698 if( !interact ) break;
699 res = (interact)( ld, flags, defaults, prompts );
700 if( res != LDAP_SUCCESS ) {
704 } while ( saslrc == SASL_INTERACT );
706 ccred.bv_len = credlen;
709 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
710 ld->ld_errno = sasl_err2ldap( saslrc );
711 #if SASL_VERSION_MAJOR >= 2
712 ld->ld_error = (char *)sasl_errdetail( ctx );
716 } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
718 if ( rc != LDAP_SUCCESS ) {
722 if ( saslrc != SASL_OK ) {
723 #if SASL_VERSION_MAJOR >= 2
724 ld->ld_error = (char *)sasl_errdetail( ctx );
726 return ld->ld_errno = sasl_err2ldap( saslrc );
729 if( flags != LDAP_SASL_QUIET ) {
730 saslrc = sasl_getprop( ctx, SASL_USERNAME, (SASL_CONST void **) &data );
731 if( saslrc == SASL_OK && data && *data ) {
732 fprintf( stderr, "SASL username: %s\n", data );
735 #if SASL_VERSION_MAJOR >= 2
736 saslrc = sasl_getprop( ctx, SASL_DEFUSERREALM, (SASL_CONST void **) &data );
738 saslrc = sasl_getprop( ctx, SASL_REALM, (SASL_CONST void **) &data );
740 if( saslrc == SASL_OK && data && *data ) {
741 fprintf( stderr, "SASL realm: %s\n", data );
745 saslrc = sasl_getprop( ctx, SASL_SSF, (SASL_CONST void **) &ssf );
746 if( saslrc == SASL_OK ) {
747 if( flags != LDAP_SASL_QUIET ) {
748 fprintf( stderr, "SASL SSF: %lu\n",
749 (unsigned long) *ssf );
753 if( flags != LDAP_SASL_QUIET ) {
754 fprintf( stderr, "SASL installing layers\n" );
756 ldap_pvt_sasl_install( ld->ld_conns->lconn_sb, ctx );
764 ldap_int_sasl_external(
772 #if SASL_VERSION_MAJOR < 2
773 sasl_external_properties_t extprops;
776 ctx = conn->lconn_sasl_ctx;
779 return LDAP_LOCAL_ERROR;
782 #if SASL_VERSION_MAJOR >= 2
783 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
785 sc = sasl_setprop( ctx, SASL_AUTH_EXTERNAL, authid );
787 memset( &extprops, '\0', sizeof(extprops) );
789 extprops.auth_id = (char *) authid;
791 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
792 (void *) &extprops );
795 if ( sc != SASL_OK ) {
796 return LDAP_LOCAL_ERROR;
803 int ldap_pvt_sasl_secprops(
805 sasl_security_properties_t *secprops )
808 char **props = ldap_str2charray( in, "," );
811 sasl_ssf_t max_ssf = 0;
813 sasl_ssf_t min_ssf = 0;
815 unsigned maxbufsize = 0;
816 int got_maxbufsize = 0;
818 if( props == NULL || secprops == NULL ) {
819 return LDAP_PARAM_ERROR;
822 for( i=0; props[i]; i++ ) {
823 if( !strcasecmp(props[i], "none") ) {
826 } else if( !strcasecmp(props[i], "noplain") ) {
828 sflags |= SASL_SEC_NOPLAINTEXT;
830 } else if( !strcasecmp(props[i], "noactive") ) {
832 sflags |= SASL_SEC_NOACTIVE;
834 } else if( !strcasecmp(props[i], "nodict") ) {
836 sflags |= SASL_SEC_NODICTIONARY;
838 } else if( !strcasecmp(props[i], "forwardsec") ) {
840 sflags |= SASL_SEC_FORWARD_SECRECY;
842 } else if( !strcasecmp(props[i], "noanonymous")) {
844 sflags |= SASL_SEC_NOANONYMOUS;
846 } else if( !strcasecmp(props[i], "passcred") ) {
848 sflags |= SASL_SEC_PASS_CREDENTIALS;
850 } else if( !strncasecmp(props[i],
851 "minssf=", sizeof("minssf")) )
853 if( isdigit( (unsigned char) props[i][sizeof("minssf")] ) ) {
855 min_ssf = atoi( &props[i][sizeof("minssf")] );
857 return LDAP_NOT_SUPPORTED;
860 } else if( !strncasecmp(props[i],
861 "maxssf=", sizeof("maxssf")) )
863 if( isdigit( (unsigned char) props[i][sizeof("maxssf")] ) ) {
865 max_ssf = atoi( &props[i][sizeof("maxssf")] );
867 return LDAP_NOT_SUPPORTED;
870 } else if( !strncasecmp(props[i],
871 "maxbufsize=", sizeof("maxbufsize")) )
873 if( isdigit( (unsigned char) props[i][sizeof("maxbufsize")] ) ) {
875 maxbufsize = atoi( &props[i][sizeof("maxbufsize")] );
877 return LDAP_NOT_SUPPORTED;
880 if( maxbufsize && (( maxbufsize < SASL_MIN_BUFF_SIZE )
881 || (maxbufsize > SASL_MAX_BUFF_SIZE )))
884 return LDAP_PARAM_ERROR;
888 return LDAP_NOT_SUPPORTED;
893 secprops->security_flags = sflags;
896 secprops->min_ssf = min_ssf;
899 secprops->max_ssf = max_ssf;
902 secprops->maxbufsize = maxbufsize;
905 ldap_charray_free( props );
910 ldap_int_sasl_config( struct ldapoptions *lo, int option, const char *arg )
915 case LDAP_OPT_X_SASL_SECPROPS:
916 rc = ldap_pvt_sasl_secprops( arg, &lo->ldo_sasl_secprops );
917 if( rc == LDAP_SUCCESS ) return 0;
924 ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
930 case LDAP_OPT_X_SASL_MECH: {
931 *(char **)arg = ld->ld_options.ldo_def_sasl_mech
932 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_mech ) : NULL;
934 case LDAP_OPT_X_SASL_REALM: {
935 *(char **)arg = ld->ld_options.ldo_def_sasl_realm
936 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_realm ) : NULL;
938 case LDAP_OPT_X_SASL_AUTHCID: {
939 *(char **)arg = ld->ld_options.ldo_def_sasl_authcid
940 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authcid ) : NULL;
942 case LDAP_OPT_X_SASL_AUTHZID: {
943 *(char **)arg = ld->ld_options.ldo_def_sasl_authzid
944 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authzid ) : NULL;
947 case LDAP_OPT_X_SASL_SSF: {
952 if( ld->ld_defconn == NULL ) {
956 ctx = ld->ld_defconn->lconn_sasl_ctx;
962 sc = sasl_getprop( ctx, SASL_SSF,
963 (SASL_CONST void **) &ssf );
965 if ( sc != SASL_OK ) {
969 *(ber_len_t *)arg = *ssf;
972 case LDAP_OPT_X_SASL_SSF_EXTERNAL:
973 /* this option is write only */
976 case LDAP_OPT_X_SASL_SSF_MIN:
977 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.min_ssf;
979 case LDAP_OPT_X_SASL_SSF_MAX:
980 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.max_ssf;
982 case LDAP_OPT_X_SASL_MAXBUFSIZE:
983 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
986 case LDAP_OPT_X_SASL_SECPROPS:
987 /* this option is write only */
997 ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
1003 case LDAP_OPT_X_SASL_SSF:
1004 /* This option is read-only */
1007 case LDAP_OPT_X_SASL_SSF_EXTERNAL: {
1009 #if SASL_VERSION_MAJOR < 2
1010 sasl_external_properties_t extprops;
1014 if( ld->ld_defconn == NULL ) {
1018 ctx = ld->ld_defconn->lconn_sasl_ctx;
1020 if ( ctx == NULL ) {
1024 #if SASL_VERSION_MAJOR >= 2
1025 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, arg);
1027 memset(&extprops, 0L, sizeof(extprops));
1029 extprops.ssf = * (ber_len_t *) arg;
1031 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
1032 (void *) &extprops );
1035 if ( sc != SASL_OK ) {
1040 case LDAP_OPT_X_SASL_SSF_MIN:
1041 ld->ld_options.ldo_sasl_secprops.min_ssf = *(ber_len_t *)arg;
1043 case LDAP_OPT_X_SASL_SSF_MAX:
1044 ld->ld_options.ldo_sasl_secprops.max_ssf = *(ber_len_t *)arg;
1046 case LDAP_OPT_X_SASL_MAXBUFSIZE:
1047 ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
1050 case LDAP_OPT_X_SASL_SECPROPS: {
1052 sc = ldap_pvt_sasl_secprops( (char *) arg,
1053 &ld->ld_options.ldo_sasl_secprops );
1055 return sc == LDAP_SUCCESS ? 0 : -1;
1064 #ifdef LDAP_R_COMPILE
1065 void *ldap_pvt_sasl_mutex_new(void)
1067 ldap_pvt_thread_mutex_t *mutex;
1069 mutex = (ldap_pvt_thread_mutex_t *) LDAP_MALLOC(
1070 sizeof(ldap_pvt_thread_mutex_t) );
1072 if ( ldap_pvt_thread_mutex_init( mutex ) == 0 ) {
1078 int ldap_pvt_sasl_mutex_lock(void *mutex)
1080 return ldap_pvt_thread_mutex_lock( (ldap_pvt_thread_mutex_t *)mutex )
1081 ? SASL_FAIL : SASL_OK;
1084 int ldap_pvt_sasl_mutex_unlock(void *mutex)
1086 return ldap_pvt_thread_mutex_unlock( (ldap_pvt_thread_mutex_t *)mutex )
1087 ? SASL_FAIL : SASL_OK;
1090 void ldap_pvt_sasl_mutex_dispose(void *mutex)
1092 (void) ldap_pvt_thread_mutex_destroy( (ldap_pvt_thread_mutex_t *)mutex );
1098 int ldap_int_sasl_init( void )
1099 { return LDAP_SUCCESS; }
1101 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
1102 { return LDAP_SUCCESS; }
1109 LDAPControl **sctrls,
1110 LDAPControl **cctrls,
1112 LDAP_SASL_INTERACT_PROC *interact,
1114 { return LDAP_NOT_SUPPORTED; }
1117 ldap_int_sasl_external(
1120 const char * authid,
1122 { return LDAP_SUCCESS; }
1124 #endif /* HAVE_CYRUS_SASL */