From: Kurt Zeilenga Date: Tue, 25 Apr 2000 10:38:03 +0000 (+0000) Subject: replace ldap_dnssrv_init() with lower level calls X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~3083 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=274bf59441d73701877bc0214e71c8dd29551472;p=openldap replace ldap_dnssrv_init() with lower level calls ldap_domain2dn() ldap_domain2hostlist() and provide prototype to soon-to-be-implemented ldap_dn2domain(). ldap_dnssrv_init(), if needed, can easily be implemented using ldap_create(), ldap_set_option() and the above commands. --- diff --git a/include/ldap.h b/include/ldap.h index f81cf4e5a9..14325afb98 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -562,9 +562,19 @@ ldap_controls_free LDAP_P(( * in dnssrv.c: */ LIBLDAP_F( int ) -ldap_dnssrv_init LDAP_P(( - LDAP **ldp, - LDAP_CONST char *domain )); +ldap_domain2dn LDAP_P(( + LDAP_CONST char* domain, + char** dn )); + +LIBLDAP_F( int ) +ldap_dn2domain LDAP_P(( + LDAP_CONST char* dn, + char** domain )); + +LIBLDAP_F( int ) +ldap_domain2hostlist LDAP_P(( + LDAP_CONST char *domain, + char** hostlist )); /* * in extended.c: diff --git a/libraries/libldap/dnssrv.c b/libraries/libldap/dnssrv.c index 3b87e3c9cc..d5597c57ec 100644 --- a/libraries/libldap/dnssrv.c +++ b/libraries/libldap/dnssrv.c @@ -5,8 +5,8 @@ */ /* - * locate using DNS SRV records. Location code based on - * MIT Kerberos KDC location code. + * locate LDAP servers using DNS SRV records. + * Location code based on MIT Kerberos KDC location code. */ #include "portable.h" @@ -33,7 +33,17 @@ #define T_SRV 33 #endif /* T_SRV */ -int ldap_pvt_domain2dn(LDAP_CONST char *domain_in, char **dnp) +int ldap_dn2domain( + LDAP_CONST char *dn_in, + char **domainp) +{ + /* not yet implemented */ + return LDAP_NOT_SUPPORTED; +} + +int ldap_domain2dn( + LDAP_CONST char *domain_in, + char **dnp) { char *domain, *s, *tok_r, *dn; size_t loc; @@ -53,7 +63,7 @@ int ldap_pvt_domain2dn(LDAP_CONST char *domain_in, char **dnp) s = ldap_pvt_strtok(NULL, ".", &tok_r)) { size_t len = strlen(s); - dn = (char *) LDAP_REALLOC(dn, loc + len + 4); + dn = (char *) LDAP_REALLOC(dn, loc + sizeof(",dc=") + len ); if (dn == NULL) { LDAP_FREE(domain); return LDAP_NO_MEMORY; @@ -64,7 +74,7 @@ int ldap_pvt_domain2dn(LDAP_CONST char *domain_in, char **dnp) loc++; } strcpy(dn + loc, "dc="); - loc += 3; + loc += sizeof("dc=")-1; strcpy(dn + loc, s); loc += len; @@ -78,21 +88,28 @@ int ldap_pvt_domain2dn(LDAP_CONST char *domain_in, char **dnp) } /* - * Lookup LDAP servers for domain (using the DNS - * SRV record _ldap._tcp.domain), set the default - * base using an algorithmic mapping of the domain, - * and return a session. + * Lookup and return LDAP servers for domain (using the DNS + * SRV record _ldap._tcp.domain). */ -int ldap_dnssrv_init(LDAP ** ldp, LDAP_CONST char *domain) +int ldap_domain2hostlist( + LDAP_CONST char *domain, + char **list ) { #ifdef HAVE_RES_SEARCH char *request; char *dn; char *hostlist = NULL; - LDAP *ld = NULL; int rc, len, cur = 0; unsigned char reply[1024]; + if( domain == NULL || *domain == '\0' ) { + return LDAP_PARAM_ERROR; + } + + if( list == NULL ) { + return LDAP_PARAM_ERROR; + } + request = LDAP_MALLOC(strlen(domain) + sizeof("_ldap._tcp.")); if (request == NULL) { rc = LDAP_NO_MEMORY; @@ -110,7 +127,7 @@ int ldap_dnssrv_init(LDAP ** ldp, LDAP_CONST char *domain) char host[1024]; int status; u_short port; - int priority, weight; + /* int priority, weight; */ /* Parse out query */ p = reply; @@ -143,11 +160,12 @@ int ldap_dnssrv_init(LDAP ** ldp, LDAP_CONST char *domain) if (status < 0) { goto out; } - priority = (p[0] << 8) | p[1]; - weight = (p[2] << 8) | p[3]; + /* ignore priority and weight for now */ + /* priority = (p[0] << 8) | p[1]; */ + /* weight = (p[2] << 8) | p[3]; */ port = (p[4] << 8) | p[5]; - buflen = strlen(host) + /* :XXXXX\0 */ 7; + buflen = strlen(host) + sizeof(":65355"); hostlist = (char *) LDAP_REALLOC(hostlist, cur + buflen); if (hostlist == NULL) { rc = LDAP_NO_MEMORY; @@ -167,26 +185,9 @@ int ldap_dnssrv_init(LDAP ** ldp, LDAP_CONST char *domain) rc = LDAP_UNAVAILABLE; goto out; } - rc = ldap_create(&ld); - if (rc != LDAP_SUCCESS) { - goto out; - } - rc = ldap_set_option(ld, LDAP_OPT_HOST_NAME, hostlist); - if (rc != LDAP_SUCCESS) { - goto out; - } - rc = ldap_pvt_domain2dn(domain, &dn); - if (rc != LDAP_SUCCESS) { - goto out; - } - if (ld->ld_options.ldo_defbase != NULL) { - LDAP_FREE(ld->ld_options.ldo_defbase); - } - ld->ld_options.ldo_defbase = dn; - - *ldp = ld; rc = LDAP_SUCCESS; + *list = hostlist; out: #ifdef LDAP_R_COMPILE @@ -196,12 +197,9 @@ int ldap_dnssrv_init(LDAP ** ldp, LDAP_CONST char *domain) if (request != NULL) { LDAP_FREE(request); } - if (hostlist != NULL) { + if (rc != LDAP_SUCCESS && hostlist != NULL) { LDAP_FREE(hostlist); } - if (rc != LDAP_SUCCESS && ld != NULL) { - ldap_ld_free(ld, 1, NULL, NULL); - } return rc; #else return LDAP_NOT_SUPPORTED; diff --git a/libraries/libldap/libldap.dsp b/libraries/libldap/libldap.dsp index e5f9125fff..a10d119f3e 100644 --- a/libraries/libldap/libldap.dsp +++ b/libraries/libldap/libldap.dsp @@ -41,6 +41,7 @@ CPP=cl.exe # PROP Output_Dir "..\..\Release" # PROP Intermediate_Dir "..\..\Release\libldap" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_WINDOWS" /YX /FD /c BSC32=bscmake.exe @@ -62,6 +63,7 @@ LIB32=link.exe -lib # PROP Output_Dir "..\..\Debug" # PROP Intermediate_Dir "..\..\Debug\libldap" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c BSC32=bscmake.exe @@ -83,6 +85,7 @@ LIB32=link.exe -lib # PROP Output_Dir "..\..\SDebug" # PROP Intermediate_Dir "..\..\SDebug\libldap" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c BSC32=bscmake.exe @@ -104,6 +107,7 @@ LIB32=link.exe -lib # PROP Output_Dir "..\..\SRelease" # PROP Intermediate_Dir "..\..\SRelease\libldap" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_WINDOWS" /YX /FD /c BSC32=bscmake.exe @@ -183,6 +187,10 @@ SOURCE=.\dn.c # End Source File # Begin Source File +SOURCE=.\dnssrv.c +# End Source File +# Begin Source File + SOURCE=.\dsparse.c # End Source File # Begin Source File diff --git a/libraries/libldap_r/libldap_r.dsp b/libraries/libldap_r/libldap_r.dsp index f4790c35e5..960a823740 100644 --- a/libraries/libldap_r/libldap_r.dsp +++ b/libraries/libldap_r/libldap_r.dsp @@ -42,6 +42,7 @@ CPP=cl.exe # PROP Output_Dir "..\..\Release" # PROP Intermediate_Dir "..\..\Release\libldap_r" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "LDAP_R_COMPILE" /D "WIN32" /D "_WINDOWS" /D _WIN32_WINNT=0x0400 /YX /FD /c BSC32=bscmake.exe @@ -63,6 +64,7 @@ LIB32=link.exe -lib # PROP Output_Dir "..\..\Debug" # PROP Intermediate_Dir "..\..\Debug\libldap_r" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "_DEBUG" /D "LDAP_R_COMPILE" /D "WIN32" /D "_WINDOWS" /D _WIN32_WINNT=0x0400 /FR /YX /FD /c BSC32=bscmake.exe @@ -84,6 +86,7 @@ LIB32=link.exe -lib # PROP Output_Dir "..\..\SDebug" # PROP Intermediate_Dir "..\..\SDebug\libldap_r" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "_DEBUG" /D "LDAP_R_COMPILE" /D "WIN32" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "_DEBUG" /D "LDAP_R_COMPILE" /D "WIN32" /D "_WINDOWS" /FR /YX /FD /c BSC32=bscmake.exe @@ -105,6 +108,7 @@ LIB32=link.exe -lib # PROP Output_Dir "..\..\SRelease" # PROP Intermediate_Dir "..\..\SRelease\libldap_r" # PROP Target_Dir "" +RSC=rc.exe # ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "NDEBUG" /D "LDAP_R_COMPILE" /D "WIN32" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "LDAP_R_COMPILE" /D "WIN32" /D "_WINDOWS" /YX /FD /c BSC32=bscmake.exe @@ -180,6 +184,10 @@ SOURCE=..\..\include\disptmpl.h # End Source File # Begin Source File +SOURCE=..\libldap\dnssrv.c +# End Source File +# Begin Source File + SOURCE=..\libldap\dsparse.c # End Source File # Begin Source File