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 )
356 Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
359 /* don't install the stuff unless security has been negotiated */
361 if ( !ber_sockbuf_ctrl( sb, LBER_SB_OPT_HAS_IO,
362 &ldap_pvt_sockbuf_io_sasl ) )
365 ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
366 LBER_SBIOD_LEVEL_APPLICATION, (void *)"sasl_" );
368 ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_sasl,
369 LBER_SBIOD_LEVEL_APPLICATION, ctx_arg );
376 sasl_err2ldap( int saslerr )
382 rc = LDAP_MORE_RESULTS_TO_RETURN;
385 rc = LDAP_LOCAL_ERROR;
391 rc = LDAP_LOCAL_ERROR;
397 rc = LDAP_AUTH_UNKNOWN;
400 rc = LDAP_AUTH_UNKNOWN;
403 rc = LDAP_PARAM_ERROR;
407 rc = LDAP_AUTH_UNKNOWN;
410 rc = LDAP_LOCAL_ERROR;
414 assert( rc == LDAP_SUCCESS || LDAP_API_ERROR( rc ) );
428 sasl_callback_t *session_callbacks =
429 LDAP_CALLOC( 2, sizeof( sasl_callback_t ) );
431 if( session_callbacks == NULL ) return LDAP_NO_MEMORY;
433 session_callbacks[0].id = SASL_CB_USER;
434 session_callbacks[0].proc = NULL;
435 session_callbacks[0].context = ld;
437 session_callbacks[1].id = SASL_CB_LIST_END;
438 session_callbacks[1].proc = NULL;
439 session_callbacks[1].context = NULL;
441 assert( lc->lconn_sasl_ctx == NULL );
443 if ( host == NULL ) {
444 ld->ld_errno = LDAP_LOCAL_ERROR;
448 #if SASL_VERSION_MAJOR >= 2
449 rc = sasl_client_new( "ldap", host, NULL, NULL,
450 session_callbacks, 0, &ctx );
452 rc = sasl_client_new( "ldap", host, session_callbacks,
453 SASL_SECURITY_LAYER, &ctx );
455 LDAP_FREE( session_callbacks );
457 if ( rc != SASL_OK ) {
458 ld->ld_errno = sasl_err2ldap( rc );
462 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 );
479 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: ssf=%ld\n",
486 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
488 sasl_conn_t *ctx = lc->lconn_sasl_ctx;
491 sasl_dispose( &ctx );
492 lc->lconn_sasl_ctx = NULL;
503 LDAPControl **sctrls,
504 LDAPControl **cctrls,
506 LDAP_SASL_INTERACT_PROC *interact,
510 const char *mech = NULL;
511 const char *pmech = NULL;
513 sasl_ssf_t *ssf = NULL;
515 sasl_interact_t *prompts = NULL;
520 Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_bind: %s\n",
521 mechs ? mechs : "<null>", 0, 0 );
523 /* do a quick !LDAPv3 check... ldap_sasl_bind will do the rest. */
524 if (ld->ld_version < LDAP_VERSION3) {
525 ld->ld_errno = LDAP_NOT_SUPPORTED;
529 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
531 if ( sd == AC_SOCKET_INVALID ) {
532 /* not connected yet */
535 rc = ldap_open_defconn( ld );
536 if( rc < 0 ) return ld->ld_errno;
538 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
540 if( sd == AC_SOCKET_INVALID ) {
541 ld->ld_errno = LDAP_LOCAL_ERROR;
546 ctx = ld->ld_defconn->lconn_sasl_ctx;
549 ld->ld_errno = LDAP_LOCAL_ERROR;
553 /* (re)set security properties */
554 sasl_setprop( ctx, SASL_SEC_PROPS,
555 &ld->ld_options.ldo_sasl_secprops );
561 saslrc = sasl_client_start( ctx,
563 #if SASL_VERSION_MAJOR < 2
567 (SASL_CONST char **)&ccred.bv_val,
571 if( pmech == NULL && mech != NULL ) {
574 if( flags != LDAP_SASL_QUIET ) {
576 "SASL/%s authentication started\n",
581 #if SASL_VERSION_MAJOR >= 2
582 /* XXX the application should free interact results. */
583 if ( prompts != NULL && prompts->result != NULL ) {
584 LDAP_FREE( (void *)prompts->result );
585 prompts->result = NULL;
589 if( saslrc == SASL_INTERACT ) {
591 if( !interact ) break;
592 res = (interact)( ld, flags, defaults, prompts );
593 if( res != LDAP_SUCCESS ) {
597 } while ( saslrc == SASL_INTERACT );
599 ccred.bv_len = credlen;
601 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
602 ld->ld_errno = sasl_err2ldap( saslrc );
607 struct berval *scred;
612 rc = ldap_sasl_bind_s( ld, dn, mech, &ccred, sctrls, cctrls, &scred );
614 if ( ccred.bv_val != NULL ) {
615 #if SASL_VERSION_MAJOR < 2
616 LDAP_FREE( ccred.bv_val );
621 if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) {
622 if( scred && scred->bv_len ) {
623 /* and server provided us with data? */
624 Debug( LDAP_DEBUG_TRACE,
625 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
626 rc, saslrc, scred->bv_len );
632 if( rc == LDAP_SUCCESS && saslrc == SASL_OK ) {
633 /* we're done, no need to step */
634 if( scred && scred->bv_len ) {
635 /* but server provided us with data! */
636 Debug( LDAP_DEBUG_TRACE,
637 "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
638 rc, saslrc, scred->bv_len );
640 return ld->ld_errno = LDAP_LOCAL_ERROR;
646 saslrc = sasl_client_step( ctx,
647 (scred == NULL) ? NULL : scred->bv_val,
648 (scred == NULL) ? 0 : scred->bv_len,
650 (SASL_CONST char **)&ccred.bv_val,
653 Debug( LDAP_DEBUG_TRACE, "sasl_client_step: %d\n",
656 #if SASL_VERSION_MAJOR >= 2
657 /* XXX the application should free interact results. */
658 if ( prompts != NULL && prompts->result != NULL ) {
659 LDAP_FREE( (void *)prompts->result );
660 prompts->result = NULL;
664 if( saslrc == SASL_INTERACT ) {
666 if( !interact ) break;
667 res = (interact)( ld, flags, defaults, prompts );
668 if( res != LDAP_SUCCESS ) {
672 } while ( saslrc == SASL_INTERACT );
674 ccred.bv_len = credlen;
677 if ( (saslrc != SASL_OK) && (saslrc != SASL_CONTINUE) ) {
678 ld->ld_errno = sasl_err2ldap( saslrc );
681 } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
683 if ( rc != LDAP_SUCCESS ) {
687 if ( saslrc != SASL_OK ) {
688 return ld->ld_errno = sasl_err2ldap( saslrc );
691 if( flags != LDAP_SASL_QUIET ) {
692 saslrc = sasl_getprop( ctx, SASL_USERNAME, (SASL_CONST void **) &data );
693 if( saslrc == SASL_OK && data && *data ) {
694 fprintf( stderr, "SASL username: %s\n", data );
697 #if SASL_VERSION_MAJOR >= 2
698 saslrc = sasl_getprop( ctx, SASL_DEFUSERREALM, (SASL_CONST void **) &data );
700 saslrc = sasl_getprop( ctx, SASL_REALM, (SASL_CONST void **) &data );
702 if( saslrc == SASL_OK && data && *data ) {
703 fprintf( stderr, "SASL realm: %s\n", data );
707 saslrc = sasl_getprop( ctx, SASL_SSF, (SASL_CONST void **) &ssf );
708 if( saslrc == SASL_OK ) {
709 if( flags != LDAP_SASL_QUIET ) {
710 fprintf( stderr, "SASL SSF: %lu\n",
711 (unsigned long) *ssf );
715 if( flags != LDAP_SASL_QUIET ) {
716 fprintf( stderr, "SASL installing layers\n" );
718 ldap_pvt_sasl_install( ld->ld_conns->lconn_sb, ctx );
726 ldap_int_sasl_external(
734 #if SASL_VERSION_MAJOR < 2
735 sasl_external_properties_t extprops;
738 ctx = conn->lconn_sasl_ctx;
741 return LDAP_LOCAL_ERROR;
744 #if SASL_VERSION_MAJOR >= 2
745 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, &ssf );
747 memset( &extprops, '\0', sizeof(extprops) );
749 extprops.auth_id = (char *) authid;
751 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
752 (void *) &extprops );
755 if ( sc != SASL_OK ) {
756 return LDAP_LOCAL_ERROR;
763 int ldap_pvt_sasl_secprops(
765 sasl_security_properties_t *secprops )
768 char **props = ldap_str2charray( in, "," );
771 sasl_ssf_t max_ssf = 0;
773 sasl_ssf_t min_ssf = 0;
775 unsigned maxbufsize = 0;
776 int got_maxbufsize = 0;
778 if( props == NULL || secprops == NULL ) {
779 return LDAP_PARAM_ERROR;
782 for( i=0; props[i]; i++ ) {
783 if( !strcasecmp(props[i], "none") ) {
786 } else if( !strcasecmp(props[i], "noplain") ) {
788 sflags |= SASL_SEC_NOPLAINTEXT;
790 } else if( !strcasecmp(props[i], "noactive") ) {
792 sflags |= SASL_SEC_NOACTIVE;
794 } else if( !strcasecmp(props[i], "nodict") ) {
796 sflags |= SASL_SEC_NODICTIONARY;
798 } else if( !strcasecmp(props[i], "forwardsec") ) {
800 sflags |= SASL_SEC_FORWARD_SECRECY;
802 } else if( !strcasecmp(props[i], "noanonymous")) {
804 sflags |= SASL_SEC_NOANONYMOUS;
806 } else if( !strcasecmp(props[i], "passcred") ) {
808 sflags |= SASL_SEC_PASS_CREDENTIALS;
810 } else if( !strncasecmp(props[i],
811 "minssf=", sizeof("minssf")) )
813 if( isdigit( props[i][sizeof("minssf")] ) ) {
815 min_ssf = atoi( &props[i][sizeof("minssf")] );
817 return LDAP_NOT_SUPPORTED;
820 } else if( !strncasecmp(props[i],
821 "maxssf=", sizeof("maxssf")) )
823 if( isdigit( props[i][sizeof("maxssf")] ) ) {
825 max_ssf = atoi( &props[i][sizeof("maxssf")] );
827 return LDAP_NOT_SUPPORTED;
830 } else if( !strncasecmp(props[i],
831 "maxbufsize=", sizeof("maxbufsize")) )
833 if( isdigit( props[i][sizeof("maxbufsize")] ) ) {
835 maxbufsize = atoi( &props[i][sizeof("maxbufsize")] );
837 return LDAP_NOT_SUPPORTED;
840 if( maxbufsize && (( maxbufsize < SASL_MIN_BUFF_SIZE )
841 || (maxbufsize > SASL_MAX_BUFF_SIZE )))
844 return LDAP_PARAM_ERROR;
848 return LDAP_NOT_SUPPORTED;
853 secprops->security_flags = sflags;
856 secprops->min_ssf = min_ssf;
859 secprops->max_ssf = max_ssf;
862 secprops->maxbufsize = maxbufsize;
865 ldap_charray_free( props );
870 ldap_int_sasl_config( struct ldapoptions *lo, int option, const char *arg )
875 case LDAP_OPT_X_SASL_SECPROPS:
876 rc = ldap_pvt_sasl_secprops( arg, &lo->ldo_sasl_secprops );
877 if( rc == LDAP_SUCCESS ) return 0;
884 ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
890 case LDAP_OPT_X_SASL_MECH: {
891 *(char **)arg = ld->ld_options.ldo_def_sasl_mech
892 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_mech ) : NULL;
894 case LDAP_OPT_X_SASL_REALM: {
895 *(char **)arg = ld->ld_options.ldo_def_sasl_realm
896 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_realm ) : NULL;
898 case LDAP_OPT_X_SASL_AUTHCID: {
899 *(char **)arg = ld->ld_options.ldo_def_sasl_authcid
900 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authcid ) : NULL;
902 case LDAP_OPT_X_SASL_AUTHZID: {
903 *(char **)arg = ld->ld_options.ldo_def_sasl_authzid
904 ? LDAP_STRDUP( ld->ld_options.ldo_def_sasl_authzid ) : NULL;
907 case LDAP_OPT_X_SASL_SSF: {
912 if( ld->ld_defconn == NULL ) {
916 ctx = ld->ld_defconn->lconn_sasl_ctx;
922 sc = sasl_getprop( ctx, SASL_SSF,
923 (SASL_CONST void **) &ssf );
925 if ( sc != SASL_OK ) {
929 *(ber_len_t *)arg = *ssf;
932 case LDAP_OPT_X_SASL_SSF_EXTERNAL:
933 /* this option is write only */
936 case LDAP_OPT_X_SASL_SSF_MIN:
937 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.min_ssf;
939 case LDAP_OPT_X_SASL_SSF_MAX:
940 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.max_ssf;
942 case LDAP_OPT_X_SASL_MAXBUFSIZE:
943 *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
946 case LDAP_OPT_X_SASL_SECPROPS:
947 /* this option is write only */
957 ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
963 case LDAP_OPT_X_SASL_SSF:
964 /* This option is read-only */
967 case LDAP_OPT_X_SASL_SSF_EXTERNAL: {
969 #if SASL_VERSION_MAJOR < 2
970 sasl_external_properties_t extprops;
974 if( ld->ld_defconn == NULL ) {
978 ctx = ld->ld_defconn->lconn_sasl_ctx;
984 #if SASL_VERSION_MAJOR >= 2
985 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL, arg);
987 memset(&extprops, 0L, sizeof(extprops));
989 extprops.ssf = * (ber_len_t *) arg;
991 sc = sasl_setprop( ctx, SASL_SSF_EXTERNAL,
992 (void *) &extprops );
995 if ( sc != SASL_OK ) {
1000 case LDAP_OPT_X_SASL_SSF_MIN:
1001 ld->ld_options.ldo_sasl_secprops.min_ssf = *(ber_len_t *)arg;
1003 case LDAP_OPT_X_SASL_SSF_MAX:
1004 ld->ld_options.ldo_sasl_secprops.max_ssf = *(ber_len_t *)arg;
1006 case LDAP_OPT_X_SASL_MAXBUFSIZE:
1007 ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
1010 case LDAP_OPT_X_SASL_SECPROPS: {
1012 sc = ldap_pvt_sasl_secprops( (char *) arg,
1013 &ld->ld_options.ldo_sasl_secprops );
1015 return sc == LDAP_SUCCESS ? 0 : -1;
1024 #ifdef LDAP_R_COMPILE
1025 void *ldap_pvt_sasl_mutex_new(void)
1027 ldap_pvt_thread_mutex_t *mutex;
1029 mutex = (ldap_pvt_thread_mutex_t *) LDAP_MALLOC(
1030 sizeof(ldap_pvt_thread_mutex_t) );
1032 if ( ldap_pvt_thread_mutex_init( mutex ) == 0 ) {
1038 int ldap_pvt_sasl_mutex_lock(void *mutex)
1040 return ldap_pvt_thread_mutex_lock( (ldap_pvt_thread_mutex_t *)mutex )
1041 ? SASL_FAIL : SASL_OK;
1044 int ldap_pvt_sasl_mutex_unlock(void *mutex)
1046 return ldap_pvt_thread_mutex_unlock( (ldap_pvt_thread_mutex_t *)mutex )
1047 ? SASL_FAIL : SASL_OK;
1050 void ldap_pvt_sasl_mutex_dispose(void *mutex)
1052 (void) ldap_pvt_thread_mutex_destroy( (ldap_pvt_thread_mutex_t *)mutex );
1058 int ldap_int_sasl_init( void )
1059 { return LDAP_SUCCESS; }
1061 int ldap_int_sasl_close( LDAP *ld, LDAPConn *lc )
1062 { return LDAP_SUCCESS; }
1069 LDAPControl **sctrls,
1070 LDAPControl **cctrls,
1072 LDAP_SASL_INTERACT_PROC *interact,
1074 { return LDAP_NOT_SUPPORTED; }
1077 ldap_int_sasl_external(
1080 const char * authid,
1082 { return LDAP_SUCCESS; }
1084 #endif /* HAVE_CYRUS_SASL */