mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-04 06:01:23 -05:00
DNS SRV meat (a work in progress)
This commit is contained in:
parent
df7ca2c3f3
commit
e87e01b9c5
2 changed files with 136 additions and 3 deletions
|
|
@ -37,8 +37,90 @@ int ldap_dn2domain(
|
|||
LDAP_CONST char *dn_in,
|
||||
char **domainp)
|
||||
{
|
||||
/* not yet implemented */
|
||||
return LDAP_NOT_SUPPORTED;
|
||||
int i;
|
||||
char* domain = NULL;
|
||||
char ** dn;
|
||||
|
||||
if( dn_in == NULL || domainp == NULL ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dn = ldap_explode_dn( dn_in, 0 );
|
||||
|
||||
if( dn == NULL ) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
for( i=0; dn[i] != NULL; i++ ) {
|
||||
char ** rdn = ldap_explode_rdn( dn[i], 0 );
|
||||
|
||||
if( rdn == NULL || *rdn == NULL ) {
|
||||
LDAP_FREE( rdn );
|
||||
LDAP_FREE( domain );
|
||||
LDAP_VFREE( dn );
|
||||
return -3;
|
||||
}
|
||||
|
||||
#define LDAP_DC "dc="
|
||||
#define LDAP_DCOID "0.9.2342.19200300.100.1.25="
|
||||
|
||||
if( *rdn[1] == NULL ) {
|
||||
char *dc;
|
||||
/* single RDN */
|
||||
|
||||
if( strncasecmp( rdn[0],
|
||||
LDAP_DC, sizeof(LDAP_DC)-1 ) == 0 )
|
||||
{
|
||||
dc = &rdn[0][sizeof(LDAP_DC)-1];
|
||||
|
||||
} else if( strncmp( rdn[0],
|
||||
LDAP_DCOID, sizeof(LDAP_DCOID)-1 ) == 0 )
|
||||
{
|
||||
dc = &rdn[0][sizeof(LDAP_DCOID)-1];
|
||||
|
||||
} else {
|
||||
dc == NULL;
|
||||
}
|
||||
|
||||
if( dc != NULL ) {
|
||||
char *ndomain;
|
||||
|
||||
if( *dc == '\0' ) {
|
||||
/* dc value is empty! */
|
||||
LDAP_FREE( rdn );
|
||||
LDAP_FREE( domain );
|
||||
LDAP_VFREE( dn );
|
||||
LDAP_VFREE( rdn );
|
||||
return -4;
|
||||
}
|
||||
|
||||
ndomain = realloc( domain,
|
||||
strlen(domain) + strlen(dc) + 2 );
|
||||
|
||||
if( ndomain == NULL ) {
|
||||
LDAP_FREE( rdn );
|
||||
LDAP_FREE( domain );
|
||||
LDAP_VFREE( dn );
|
||||
LDAP_VFREE( rdn );
|
||||
return -5;
|
||||
}
|
||||
|
||||
if( domain != NULL ) {
|
||||
strcat( ndomain, "." );
|
||||
}
|
||||
strcat( ndomain, dc );
|
||||
domain = ndomain;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
LDAP_VFREE( rdn );
|
||||
LDAP_FREE( domain );
|
||||
domain = NULL;
|
||||
}
|
||||
|
||||
*domainp = domain;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ldap_domain2dn(
|
||||
|
|
|
|||
|
|
@ -23,5 +23,56 @@ dnssrv_back_request(
|
|||
const char *dn,
|
||||
const char *ndn )
|
||||
{
|
||||
return -1;
|
||||
int i;
|
||||
char *domain = NULL;
|
||||
char *hostlist = NULL;
|
||||
char **hosts = NULL;
|
||||
struct berval **urls = NULL;
|
||||
|
||||
if( ldap_dn2domain( dn, &domain ) ) {
|
||||
send_ldap_result( conn, op, LDAP_REFERRAL,
|
||||
NULL, NULL, default_referral, NULL );
|
||||
goto done;
|
||||
}
|
||||
|
||||
if( ldap_domain2hostlist( dn, &domain ) ) {
|
||||
send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
|
||||
NULL, NULL, NULL, NULL );
|
||||
goto done;
|
||||
}
|
||||
|
||||
hosts = str2charray( hostlist, " " );
|
||||
|
||||
if( hosts == NULL ) {
|
||||
send_ldap_result( conn, op, LDAP_OTHER,
|
||||
NULL, NULL, NULL, NULL );
|
||||
goto done;
|
||||
}
|
||||
|
||||
for( i=0; hosts[i] != NULL; i++) {
|
||||
struct berval *url = ch_malloc( sizeof( struct berval ) );
|
||||
|
||||
url->bv_len = sizeof("ldap://") + strlen(hosts[i]);
|
||||
url->bv_val = ch_malloc( url->bv_len );
|
||||
|
||||
strcpy( url->bv_val, "ldap://" );
|
||||
strcpy( &url->bv_val[sizeof("ldap://")-1], hosts[i] );
|
||||
|
||||
if( ber_bvecadd( &urls, url ) < 0) {
|
||||
ber_bvfree( url );
|
||||
send_ldap_result( conn, op, LDAP_OTHER,
|
||||
NULL, NULL, NULL, NULL );
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
send_ldap_result( conn, op, LDAP_REFERRAL,
|
||||
NULL, NULL, urls, NULL );
|
||||
|
||||
done:
|
||||
if( domain != NULL ) ch_free( domain );
|
||||
if( hostlist != NULL ) ch_free( hostlist );
|
||||
if( hosts != NULL ) charray_free( hosts );
|
||||
if( urls != NULL ) ber_bvecfree( urls );
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue