return( 1 );
}
- if ( SLAPD_GLOBAL(host) != NULL ) {
+ if ( global_host != NULL ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: already set sasl-host!\n",
fname, lineno, 0 );
return 1;
} else {
- SLAPD_GLOBAL(host) = ch_strdup( cargv[1] );
+ global_host = ch_strdup( cargv[1] );
}
/* set SASL realm */
return( 1 );
}
- if ( SLAPD_GLOBAL(realm) != NULL ) {
+ if ( global_realm != NULL ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: already set sasl-realm!\n",
fname, lineno, 0 );
return 1;
} else {
- SLAPD_GLOBAL(realm) = ch_strdup( cargv[1] );
+ global_realm = ch_strdup( cargv[1] );
}
/* SASL security properties */
if ( op.o_bd && op.o_bd->be_search ) {
SlapReply rs = {REP_RESULT};
+ op.o_hdr = conn->c_sasl_bindop->o_hdr;
op.o_tag = LDAP_REQ_SEARCH;
- op.o_protocol = LDAP_VERSION3;
op.o_ndn = conn->c_ndn;
op.o_callback = &cb;
op.o_time = slap_get_time();
op.o_do_not_cache = 1;
op.o_is_auth_check = 1;
- op.o_threadctx = conn->c_sasl_bindop->o_threadctx;
- op.o_tmpmemctx = conn->c_sasl_bindop->o_tmpmemctx;
- op.o_tmpmfuncs = conn->c_sasl_bindop->o_tmpmfuncs;
- op.o_conn = conn;
- op.o_connid = conn->c_connid;
op.o_req_dn = op.o_req_ndn;
op.ors_scope = LDAP_SCOPE_BASE;
op.ors_deref = LDAP_DEREF_NEVER;
}
if ( rc == LDAP_SUCCESS ) {
+ op.o_hdr = conn->c_sasl_bindop->o_hdr;
op.o_tag = LDAP_REQ_MODIFY;
- op.o_protocol = LDAP_VERSION3;
op.o_ndn = op.o_req_ndn;
op.o_callback = &cb;
op.o_time = slap_get_time();
op.o_do_not_cache = 1;
op.o_is_auth_check = 1;
- op.o_threadctx = conn->c_sasl_bindop->o_threadctx;
- op.o_tmpmemctx = conn->c_sasl_bindop->o_tmpmemctx;
- op.o_tmpmfuncs = conn->c_sasl_bindop->o_tmpmfuncs;
- op.o_conn = conn;
- op.o_connid = conn->c_connid;
op.o_req_dn = op.o_req_ndn;
op.orm_modlist = modlist;
char version[sizeof("xxx.xxx.xxxxx")];
sprintf( version, "%u.%d.%d", (unsigned)rc >> 24, (rc >> 16) & 0xff,
rc & 0xffff );
- Debug( LDAP_DEBUG_ANY,
- "slap_sasl_init: SASL library version mismatch:"
- " expected " SASL_VERSION_STRING ","
- " got %s\n", version, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "slap_sasl_init: SASL library version mismatch:"
+ " expected " SASL_VERSION_STRING ","
+ " got %s\n", version, 0, 0 );
return -1;
}
#endif
#if SASL_VERSION_MAJOR >= 2
generic_filter.f_desc = slap_schema.si_ad_objectClass;
- sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
+ rc = sasl_auxprop_add_plugin( "slapd", slap_auxprop_init );
+ if( rc != SASL_OK ) {
+ Debug( LDAP_DEBUG_ANY, "slap_sasl_init: auxprop add plugin failed\n",
+ 0, 0, 0 );
+ return -1;
+ }
#endif
/* should provide callbacks for logging */
/* server name should be configurable */
rc = sasl_server_init( server_callbacks, "slapd" );
if( rc != SASL_OK ) {
- Debug( LDAP_DEBUG_ANY, "sasl_server_init failed\n",
+ Debug( LDAP_DEBUG_ANY, "slap_sasl_init: server init failed\n",
0, 0, 0 );
#if SASL_VERSION_MAJOR < 2
/* A no-op used to make sure we linked with Cyrus 1.5 */
#ifdef HAVE_CYRUS_SASL
sasl_done();
#endif
- free( SLAPD_GLOBAL(host) );
- SLAPD_GLOBAL(host) = NULL;
+ free( global_host );
+ global_host = NULL;
return 0;
}
conn->c_sasl_layers = 0;
- if( SLAPD_GLOBAL(host) == NULL ) {
- SLAPD_GLOBAL(host) = ldap_pvt_get_fqdn( NULL );
+ if( global_host == NULL ) {
+ global_host = ldap_pvt_get_fqdn( NULL );
}
/* create new SASL context */
*p = ';';
}
}
- sc = sasl_server_new( "ldap", SLAPD_GLOBAL(host), SLAPD_GLOBAL(realm),
+ sc = sasl_server_new( "ldap", global_host, global_realm,
iplocalport, ipremoteport, session_callbacks, SASL_SUCCESS_DATA, &ctx );
if ( iplocalport != NULL ) {
ch_free( iplocalport );
ch_free( ipremoteport );
}
#else
- sc = sasl_server_new( "ldap", SLAPD_GLOBAL(host), SLAPD_GLOBAL(realm),
+ sc = sasl_server_new( "ldap", global_host, global_realm,
session_callbacks, SASL_SECURITY_LAYER, &ctx );
#endif
/* Username strings */
if( is_dn == SET_U ) {
- char *p;
- struct berval realm = BER_BVNULL, c1 = *dn;
- ber_len_t len;
-
- len = dn->bv_len + STRLENOF( "uid=" ) + STRLENOF( ",cn=auth" );
-
- if( user_realm && *user_realm ) {
- ber_str2bv( user_realm, 0, 0, &realm );
- len += realm.bv_len + STRLENOF( ",cn=" );
+ /* ITS#3419: values may need escape */
+ LDAPRDN DN[ 5 ];
+ LDAPAVA *RDNs[ 4 ][ 2 ];
+ LDAPAVA AVAs[ 4 ];
+ int irdn;
+
+ irdn = 0;
+ DN[ irdn ] = RDNs[ irdn ];
+ RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
+ AVAs[ irdn ].la_attr = slap_schema.si_ad_uid->ad_cname;
+ AVAs[ irdn ].la_value = *dn;
+ AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
+ AVAs[ irdn ].la_private = NULL;
+ RDNs[ irdn ][ 1 ] = NULL;
+
+ if ( user_realm && *user_realm ) {
+ irdn++;
+ DN[ irdn ] = RDNs[ irdn ];
+ RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
+ AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
+ ber_str2bv( user_realm, 0, 0, &AVAs[ irdn ].la_value );
+ AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
+ AVAs[ irdn ].la_private = NULL;
+ RDNs[ irdn ][ 1 ] = NULL;
}
- if( mech->bv_len ) {
- len += mech->bv_len + STRLENOF( ",cn=" );
+ if ( !BER_BVISNULL( mech ) ) {
+ irdn++;
+ DN[ irdn ] = RDNs[ irdn ];
+ RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
+ AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
+ AVAs[ irdn ].la_value = *mech;
+ AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
+ AVAs[ irdn ].la_private = NULL;
+ RDNs[ irdn ][ 1 ] = NULL;
}
- /* Build the new dn */
- dn->bv_val = slap_sl_malloc( len + 1, op->o_tmpmemctx );
- if( dn->bv_val == NULL ) {
- Debug( LDAP_DEBUG_ANY,
- "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
- return LDAP_OTHER;
- }
- p = lutil_strcopy( dn->bv_val, "uid=" );
- p = lutil_strncopy( p, c1.bv_val, c1.bv_len );
+ irdn++;
+ DN[ irdn ] = RDNs[ irdn ];
+ RDNs[ irdn ][ 0 ] = &AVAs[ irdn ];
+ AVAs[ irdn ].la_attr = slap_schema.si_ad_cn->ad_cname;
+ BER_BVSTR( &AVAs[ irdn ].la_value, "auth" );
+ AVAs[ irdn ].la_flags = LDAP_AVA_NULL;
+ AVAs[ irdn ].la_private = NULL;
+ RDNs[ irdn ][ 1 ] = NULL;
- if( realm.bv_len ) {
- p = lutil_strcopy( p, ",cn=" );
- p = lutil_strncopy( p, realm.bv_val, realm.bv_len );
- }
+ irdn++;
+ DN[ irdn ] = NULL;
- if( mech->bv_len ) {
- p = lutil_strcopy( p, ",cn=" );
- p = lutil_strcopy( p, mech->bv_val );
+ rc = ldap_dn2bv_x( DN, dn, LDAP_DN_FORMAT_LDAPV3, op->o_tmpmemctx );
+ if ( rc != LDAP_SUCCESS ) {
+ BER_BVZERO( dn );
+ return rc;
}
- p = lutil_strcopy( p, ",cn=auth" );
- dn->bv_len = p - dn->bv_val;
Debug( LDAP_DEBUG_TRACE, "slap_sasl_getdn: u:id converted to %s\n", dn->bv_val,0,0 );
+
} else {
/* Dup the DN in any case, so we don't risk