This is a multi-part message in MIME format.
------=_NextPart_000_00A9_01C98D2A.7E1AFAD0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Here is a first result (patch integration) ...
It doen't more remains to write the actual SRV search ... (coming soon)
Here is a running log :
root@testldap0:/var/log# >syslog
root@testldap0:/var/log# grep "^[^#].*ldapsam:" /etc/samba/smb.conf
passdb backend = ldapsam:"ldap://ns0
ldap://ns0/ou=profile%2cdc=gov%2cdc=pf??sub?(objectClass=*)?x-dnssrv=dc=gov%
2cdc=pf ldap://newldap/dc=srv%2cdc=gov%2cdc=pf??sub?(objectClass=*)?toto
ldap:///dc=srv%2cdc=gov%2cdc=pf??sub??toto"
root@testldap0:/var/log# /etc/rc.d/rc.samba restart
Starting Samba: /usr/local/samba/sbin/smbd -D
/usr/local/samba/sbin/nmbd -D
root@testldap0:/var/log# cat syslog
Feb 13 01:38:25 testldap0 smbd: the final url is: "ldap://ns0
ldap://ldap1.gov.pf ldap://ldap2.gov.pf ldap://ldap3.gov.pf
ldap://newldap/dc=srv%2cdc=gov%2cdc=pf??sub?(objectClass=*)?toto
ldap://ldap1.gov.pf ldap://ldap2.gov.pf ldap://ldap3.gov.pf-"
--
PE
------=_NextPart_000_00A9_01C98D2A.7E1AFAD0
Content-Type: application/octet-stream;
name="open.c.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="open.c.patch"
--- openldap-2.4.13/libraries/libldap/open.c 2008-10-31 =
23:23:58.000000000 +0000=0A=
+++ openldap-2.4.13/libraries/libldap/open.c 2009-02-13 =
01:30:35.000000000 +0000=0A=
@@ -212,19 +212,128 @@=0A=
return( ld );=0A=
}=0A=
=0A=
+int=0A=
+url_expand_on_srv_search ( char ***result, LDAP_CONST char *url_in, =
char *domain )=0A=
+{ int rc =3D 0;=0A=
+=0A=
+if ( (*result =3D ldap_str2charray( "ldap://ldap1.gov.pf =
ldap://ldap2.gov.pf ldap://ldap3.gov.pf", " " )) !=3D NULL ) rc =3D 3; =
// line to delete ...=0A=
+=0A=
+ // Coming soon ...=0A=
+=0A=
+ return rc;=0A=
+}=0A=
+=0A=
+char *=0A=
+expand_dnssrv_definitions ( LDAP_CONST char *url_in )=0A=
+{=0A=
+ char *dom, *s, *dn =3D NULL, **srvSearchResult =3D NULL;=0A=
+ char **urls =3D NULL, **extentions =3D NULL;=0A=
+ int i, ii, urlsNb=3D0;=0A=
+=0A=
+ if( url_in =3D=3D NULL ) {=0A=
+ return NULL;=0A=
+ }=0A=
+=0A=
+ urls =3D ldap_str2charray( url_in, " " );=0A=
+=0A=
+ while( urls[urlsNb] ) urlsNb++; // How many urls is there ?...=0A=
+=0A=
+ for( i=3D0; (dom=3Durls[i]); i++ ) { // for each URL, search SRV =
domain ...=0A=
+=0A=
+ // Search for "x-dnssrv" extention (fifth field) ...=0A=
+ if ( *(dom =3D (char *)strchrnul( dom, '?' )) !=3D '?' || ! *(++dom) =
) continue;=0A=
+ if ( *(dom =3D (char *)strchrnul( dom, '?' )) !=3D '?' || ! *(++dom) =
) continue;=0A=
+ if ( *(dom =3D (char *)strchrnul( dom, '?' )) !=3D '?' || ! *(++dom) =
) continue;=0A=
+ if ( *(dom =3D (char *)strchrnul( dom, '?' )) !=3D '?' || ! *(++dom) =
) continue;=0A=
+ extentions =3D ldap_str2charray( dom, "," );=0A=
+ for ( dom=3DNULL,ii=3D0; extentions[ii]; ii++ ) {=0A=
+ ldap_pvt_str2lower ( extentions[ii]+1 );=0A=
+ if ( strncmp( extentions[ii], "x-dnssrv=3D", sizeof ( "x-dnssrv=3D" =
)-1) =3D=3D 0 ) {=0A=
+ dom =3D extentions[ii] + sizeof ( "x-dnssrv=3D" ) - 1;=0A=
+ break;=0A=
+ } }=0A=
+=0A=
+ // Search for dn =3D=3D "dc=3D.*[,dc=3D.*]*" - only in case there was =
not any "x-dnssrv" extension ...=0A=
+ if ( ! dom ) { dom=3Durls[i];=0A=
+ if ( *(dom =3D (char *)strchrnul( dom, '/' )) !=3D '/' =
|| !strncmp ( dom, "///dc=3D", 6 ) =3D=3D 0 ) continue;=0A=
+ dom=3Ddn=3D (char *) LDAP_STRDUP ( dom+3 );=0A=
+ if ( dom ) *(char *)strchrnul( dom, '?' ) =3D '\0';=0A=
+ }=0A=
+ =0A=
+ // Does dom realy look like a domain name (if a dn format is =
detected) ?...=0A=
+ if ( dom && strncmp(dom, "dc=3D", 3) =3D=3D 0 ) // It's effectively a =
dn definition (not just a domaine name) ?...=0A=
+ for ( s=3Ddom+3; *s; s++ ) // Nothing else than "dc=3D" in the =
string ?...=0A=
+ if ( *s =3D=3D '=3D' && *(s-1) !=3D 'c' && *(s-2) !=3D 'd') {=0A=
+ dom =3D NULL; // never mind, a next time !...=0A=
+ break; =0A=
+ }=0A=
+=0A=
+ // Replace the current url with the result of the SRV search ...=0A=
+ if ( dom ) {=0A=
+ int rc =3D url_expand_on_srv_search ( &srvSearchResult, urls[i], dom =
);=0A=
+=0A=
+ if ( rc > 0 ) { // Substitution (must keep the initial order of =
the urls) ...=0A=
+ char **u, **result =3D srvSearchResult;=0A=
+ if ( (u =3D (char **)LDAP_MALLOC( (urlsNb + rc) * sizeof(char *) )) =
) {=0A=
+ for ( ii=3DurlsNb + rc; ii; ) u[--ii] =3D NULL;=0A=
+ while ( ii<i ) {=0A=
+ u[ii] =3D urls[ii];=0A=
+ ii++;=0A=
+ } while ( ii<i+rc && rc ) { // replace url[i] with url(s) =
resulting from the SRV search ...=0A=
+ u[ii] =3D *result++;=0A=
+ ii++;=0A=
+ } while ( urls[ii-rc+1] && rc ) {=0A=
+ u[ii] =3D urls[ii-rc+1];=0A=
+ ii++;=0A=
+ } u[ii] =3D NULL;=0A=
+ LDAP_FREE ( urls );=0A=
+ urls =3D u;=0A=
+ rc--; i +=3D rc; urlsNb +=3D rc;=0A=
+ }=0A=
+ LDAP_FREE ( srvSearchResult );=0A=
+ } }=0A=
+=0A=
+ // it's done for the current url ...=0A=
+ LDAP_FREE( dn );=0A=
+ ldap_charray_free( extentions );=0A=
+ }=0A=
+=0A=
+ // last job : to construct the result string ...=0A=
+ for ( i=3D0; urls[i]; i++ ) {=0A=
+ urlsNb +=3D strlen( urls[i] );=0A=
+ urlsNb++; // for urls separator: ' ' ...=0A=
+ } if ( (s =3D (char *)LDAP_MALLOC( ++urlsNb )) !=3D NULL ) {=0A=
+ for ( *s=3D'\0',i=3D0; urls[i]; i++ )=0A=
+ sprintf ( &s[strlen(s)], "%s ", urls[i] );=0A=
+ s[strlen(s)-1] =3D '\0'; // delete last ' ' ...=0A=
+ }=0A=
+=0A=
+ ldap_charray_free( urls );=0A=
+=0A=
+ // bye ...=0A=
+ return ( s );=0A=
+}=0A=
+=0A=
=0A=
int=0A=
-ldap_initialize( LDAP **ldp, LDAP_CONST char *url )=0A=
+ldap_initialize( LDAP **ldp, LDAP_CONST char *url_in )=0A=
{=0A=
int rc;=0A=
LDAP *ld;=0A=
+ char *url;=0A=
=0A=
*ldp =3D NULL;=0A=
rc =3D ldap_create(&ld);=0A=
if ( rc !=3D LDAP_SUCCESS )=0A=
return rc;=0A=
=0A=
- if (url !=3D NULL) {=0A=
+ if (url_in !=3D NULL) {=0A=
+ url =3D expand_dnssrv_definitions ( url_in );=0A=
+ if ( url =3D=3D NULL ) {=0A=
+ return LDAP_URL_ERR_MEM;=0A=
+ }=0A=
+syslog ( 3, "the final url is: \"%s-\"", url ); // to delete ...=0A=
+=0A=
rc =3D ldap_set_option(ld, LDAP_OPT_URI, url);=0A=
if ( rc !=3D LDAP_SUCCESS ) {=0A=
ldap_ld_free(ld, 1, NULL, NULL);=0A=
@@ -234,6 +343,7 @@=0A=
if (ldap_is_ldapc_url(url))=0A=
LDAP_IS_UDP(ld) =3D 1;=0A=
#endif=0A=
+ LDAP_FREE( url );=0A=
}=0A=
=0A=
*ldp =3D ld;=0A=
------=_NextPart_000_00A9_01C98D2A.7E1AFAD0--