batch-commits-windows-20040529
[openafs.git] / src / WINNT / afsd / cm_config.c
index af94ede..ce6f925 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <afs/param.h>
 #include <afs/stds.h>
+#include <afs/cellconfig.h>
 
 #ifndef DJGPP
 #include <windows.h>
 
 #include "cm_config.h"
 #ifdef AFS_AFSDB_ENV
-#if !defined(DJGPP) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x500
-#include <windns.h>
-#define DNSAPI_ENV
-#else
 #include "cm_dns.h"
-#endif
 #include <afs/afsint.h>
 #endif
 
@@ -165,9 +161,6 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep,
     long code;
        int tracking = 1, partial = 0;
 #if defined(DJGPP) || defined(AFS_WIN95_ENV)
-       long ip_addr;
-    int c1, c2, c3, c4;
-    char aname[241];
     char *afsconf_path;
 #endif
 
@@ -334,23 +327,32 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep,
                     foundCell = 1;
                                }
 #else
-                /* For DJGPP, we will read IP address instead
-                of name/comment field */
-                code = sscanf(lineBuffer, "%d.%d.%d.%d #%s",
-                               &c1, &c2, &c3, &c4, aname);
-                tp = (char *) &ip_addr;
-                *tp++ = c1;
-                *tp++ = c2;
-                *tp++ = c3;
-                *tp++ = c4;
-                memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
-                        sizeof(long));
-                vlSockAddr.sin_family = AF_INET;
-                /* sin_port supplied by connection code */
-                if (procp)
-                    (*procp)(rockp, &vlSockAddr, valuep);
-                foundCell = 1;
+                thp = 0;
 #endif /* !DJGPP */
+                if (!thp) {
+                    long ip_addr;
+                                       int c1, c2, c3, c4;
+                                       char aname[241] = "";                    
+                    
+                    /* Since there is no gethostbyname() data 
+                     * available we will read the IP address
+                     * stored in the CellServDB file
+                     */
+                    code = sscanf(lineBuffer, "%d.%d.%d.%d #%s",
+                                   &c1, &c2, &c3, &c4, aname);
+                    tp = (char *) &ip_addr;
+                    *tp++ = c1;
+                    *tp++ = c2;
+                    *tp++ = c3;
+                    *tp++ = c4;
+                    memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
+                            sizeof(long));
+                    vlSockAddr.sin_family = AF_INET;
+                    /* sin_port supplied by connection code */
+                    if (procp)
+                        (*procp)(rockp, &vlSockAddr, valuep);
+                    foundCell = 1;
+                }
             }
         }      /* a vldb line */
     }          /* while loop processing all lines */
@@ -363,9 +365,9 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
                cm_configProc_t *procp, void *rockp)
 {
 #ifdef AFS_AFSDB_ENV
-#ifndef DNSAPI_ENV
     int rc;
-    int cellHosts[AFSMAXCELLHOSTS];
+    int  cellHostAddrs[AFSMAXCELLHOSTS];
+    char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
     int numServers;
     int i;
     struct sockaddr_in vlSockAddr;
@@ -373,15 +375,15 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
 #ifdef DEBUG
     DebugEvent_local("AFS SearchCellDNS-","Doing search for [%s]", cellNamep);
 #endif
-    rc = getAFSServer(cellNamep, cellHosts, &numServers, ttl);
+    rc = getAFSServer(cellNamep, cellHostAddrs, cellHostNames, &numServers, ttl);
     if (rc == 0 && numServers > 0) {     /* found the cell */
         for (i = 0; i < numServers; i++) {
-            memcpy(&vlSockAddr.sin_addr.s_addr, &cellHosts[i],
+            memcpy(&vlSockAddr.sin_addr.s_addr, &cellHostAddrs[i],
                    sizeof(long));
            vlSockAddr.sin_family = AF_INET;
            /* sin_port supplied by connection code */
            if (procp)
-          (*procp)(rockp, &vlSockAddr, NULL);
+          (*procp)(rockp, &vlSockAddr, cellHostNames[i]);
            if(newCellNamep)
           strcpy(newCellNamep,cellNamep);
         }
@@ -389,98 +391,6 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
     }
     else
        return -1;  /* not found */
-#else /* DNSAPI_ENV */
-       PDNS_RECORD pDnsCell, pDnsIter, pDnsVol,pDnsVolIter, pDnsCIter;
-       LPSTR vlServers[AFSMAXCELLHOSTS];
-       IP4_ADDRESS vlAddrs[AFSMAXCELLHOSTS];
-       WORD nvlServers;
-       DWORD wttl, i;
-       BOOL success;
-    struct sockaddr_in vlSockAddr;
-
-       success = FALSE;
-
-#ifdef DEBUG
-    DebugEvent_local("AFS SearchCellDNS-","Doing search for [%s]", cellNamep);
-#endif 
-
-    /* query the AFSDB records of cell */
-       if(DnsQuery_A(cellNamep, DNS_TYPE_AFSDB, DNS_QUERY_STANDARD, NULL, &pDnsCell, NULL) == ERROR_SUCCESS) {
-
-               memset((void*) &vlSockAddr, 0, sizeof(vlSockAddr));
-               
-               nvlServers = 0; wttl = 0;
-
-               /* go through the returned records */
-               for(pDnsIter = pDnsCell;pDnsIter; pDnsIter = pDnsIter->pNext) {
-                       /* if we find an AFSDB record with Preference set to 1, we found a volserver */
-                       if(pDnsIter->wType == DNS_TYPE_AFSDB && pDnsIter->Data.Afsdb.wPreference == 1) {
-                               vlServers[nvlServers++] = pDnsIter->Data.Afsdb.pNameExchange;
-                               if(!wttl) wttl = pDnsIter->dwTtl;
-                               if(nvlServers == AFSMAXCELLHOSTS) break;
-                       }
-               }
-
-               for(i=0;i<nvlServers;i++) vlAddrs[i] = 0;
-
-               /* now check if there are any A records in the results */
-               for(pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
-                       if(pDnsIter->wType == DNS_TYPE_A)
-                               /* check if its for one of the volservers */
-                               for(i=0;i<nvlServers;i++)
-                                       if(stricmp(pDnsIter->pName, vlServers[i]) == 0)
-                                               vlAddrs[i] = pDnsIter->Data.A.IpAddress;
-               }
-
-               for(i=0;i<nvlServers;i++) {
-                       /* if we don't have an IP yet, then we should try resolving the volserver hostname
-                          in a separate query. */
-                       if(!vlAddrs[i]) {
-                               if(DnsQuery_A(vlServers[i], DNS_TYPE_A, DNS_QUERY_STANDARD, NULL, &pDnsVol, NULL) == ERROR_SUCCESS) {
-                                       for(pDnsVolIter = pDnsVol; pDnsVolIter; pDnsVolIter=pDnsVolIter->pNext) {
-                                               /* if we get an A record, keep it */
-                                               if(pDnsVolIter->wType == DNS_TYPE_A && stricmp(vlServers[i], pDnsVolIter->pName)==0) {
-                                                       vlAddrs[i] = pDnsVolIter->Data.A.IpAddress;
-                                                       break;
-                                               }
-                                               /* if we get a CNAME, look for a corresponding A record */
-                                               if(pDnsVolIter->wType == DNS_TYPE_CNAME && stricmp(vlServers[i], pDnsVolIter->pName)==0) {
-                                                       for(pDnsCIter=pDnsVolIter; pDnsCIter; pDnsCIter=pDnsCIter->pNext) {
-                                                               if(pDnsCIter->wType == DNS_TYPE_A && stricmp(pDnsVolIter->Data.CNAME.pNameHost, pDnsCIter->pName)==0) {
-                                                                       vlAddrs[i] = pDnsCIter->Data.A.IpAddress;
-                                                                       break;
-                                                               }
-                                                       }
-                                                       if(vlAddrs[i]) break;
-                                                       /* TODO: if the additional section is missing, then do another lookup for the CNAME */
-                                               }
-                                       }
-                                       /* we are done with the volserver lookup */
-                                       DnsRecordListFree(pDnsVol, DnsFreeRecordListDeep);
-                               }
-                       }
-
-                       /* if we found a volserver, then add it */
-                       if(vlAddrs[i]) {
-                               vlSockAddr.sin_family = AF_INET;
-                               vlSockAddr.sin_addr.s_addr = vlAddrs[i];
-                               if(procp)
-                                       (*procp)(rockp, &vlSockAddr, vlServers[i]);
-                               success = TRUE;
-                       }
-               }
-
-               DnsRecordListFree(pDnsCell, DnsFreeRecordListDeep);
-       }
-
-       if(!success) return -1;
-       else {
-               strcpy(newCellNamep, cellNamep);
-               if(ttl) *ttl = (int) wttl;
-               return 0;
-       }
-
-#endif /* DNSAPI_ENV */
 #else
        return -1;  /* not found */
 #endif /* AFS_AFSDB_ENV */