/* newCellNamep is required to be CELL_MAXNAMELEN in size */ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl, cm_configProc_t *procp, void *rockp) { int rc; int cellHostAddrs[AFSMAXCELLHOSTS]; char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS]; unsigned short ipRanks[AFSMAXCELLHOSTS]; unsigned short ports[AFSMAXCELLHOSTS]; /* network byte order */ int numServers; int i; struct sockaddr_in vlSockAddr; #ifdef CELLSERV_DEBUG osi_Log1(afsd_logp,"SearchCellDNS-Doing search for [%s]", osi_LogSaveString(afsd_logp,cellNamep)); #endif /* * Do not perform a DNS lookup if the name is * either a well-known Windows DLL or directory, * or if the name does not contain a top-level * domain, or if the file prefix is the afs pioctl * file name. */ if ( IsWindowsModule(cellNamep) || cm_FsStrChr(cellNamep, '.') == NULL || strncasecmp(cellNamep, CM_IOCTL_FILENAME_NOSLASH, sizeof(CM_IOCTL_FILENAME_NOSLASH)-1) == 0) return -1; rc = getAFSServer("afs3-vlserver", "udp", cellNamep, htons(7003), cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, ttl); if (rc == 0 && numServers > 0) { /* found the cell */ for (i = 0; i < numServers; i++) { memcpy(&vlSockAddr.sin_addr.s_addr, &cellHostAddrs[i], sizeof(long)); vlSockAddr.sin_port = ports[i]; vlSockAddr.sin_family = AF_INET; if (procp) (*procp)(rockp, &vlSockAddr, cellHostNames[i], ipRanks[i]); } if (newCellNamep) { if(FAILED(StringCchCopy(newCellNamep, CELL_MAXNAMELEN, cellNamep))) return -1; strlwr(newCellNamep); } return 0; /* found cell */ } else return -1; /* not found */ }
/* If we couldn't find an entry for the requested service * and that service happens to be the prservice or kaservice * then fallback to searching for afs3-vlserver and assigning * the port number here. */ if (code < 0 && (afsdbport == htons(7002) || afsdbport == htons(7004))) { code = afsconf_LookupServer("afs3-vlserver", "udp", (const char *)acellName, afsdbport, cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, &ttl, &realCellName); if (code >= 0) { for (i = 0; i < numServers; i++) ports[i] = afsdbport; } } if (code == 0) { acellInfo->timeout = ttl; acellInfo->numServers = numServers; for (i = 0; i < numServers; i++) { memcpy(&acellInfo->hostAddr[i].sin_addr.s_addr, &cellHostAddrs[i], sizeof(afs_int32)); memcpy(acellInfo->hostName[i], cellHostNames[i], MAXHOSTCHARS); acellInfo->hostAddr[i].sin_family = AF_INET; acellInfo->hostAddr[i].sin_port = ports[i]; if (realCellName) { strlcpy(acellInfo->name, realCellName, sizeof(acellInfo->name)); free(realCellName); realCellName = NULL; } } acellInfo->linkedCell = NULL; /* no linked cell */ acellInfo->flags = 0; } return code; } #else /* windows */ int afsconf_GetAfsdbInfo(char *acellName, char *aservice, struct afsconf_cell *acellInfo) { afs_int32 i; int tservice = afsconf_FindService(aservice); /* network byte order */ const char *ianaName = afsconf_FindIANAName(aservice); struct afsconf_entry DNSce; afs_uint32 cellHostAddrs[AFSMAXCELLHOSTS]; char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS]; unsigned short ipRanks[AFSMAXCELLHOSTS]; unsigned short ports[AFSMAXCELLHOSTS]; /* network byte order */ int numServers; int rc; int ttl; if (tservice < 0) { if (aservice) return AFSCONF_NOTFOUND; else tservice = 0; /* port will be assigned by caller */ } if (ianaName == NULL) ianaName = "afs3-vlserver"; DNSce.cellInfo.numServers = 0; DNSce.next = NULL; rc = getAFSServer(ianaName, "udp", acellName, tservice, cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, &ttl); /* ignore the ttl here since this code is only called by transitory programs * like klog, etc. */ /* If we couldn't find an entry for the requested service * and that service happens to be the prservice or kaservice * then fallback to searching for afs3-vlserver and assigning * the port number here. */ if (rc < 0 && (tservice == htons(7002) || tservice == htons(7004))) { rc = getAFSServer("afs3-vlserver", "udp", acellName, tservice, cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, &ttl); if (rc >= 0) { for (i = 0; i < numServers; i++) ports[i] = tservice; } } if (rc < 0 || numServers == 0) return -1; for (i = 0; i < numServers; i++) { memcpy(&acellInfo->hostAddr[i].sin_addr.s_addr, &cellHostAddrs[i], sizeof(afs_uint32)); memcpy(acellInfo->hostName[i], cellHostNames[i], MAXHOSTCHARS); acellInfo->hostAddr[i].sin_family = AF_INET; if (aservice) acellInfo->hostAddr[i].sin_port = ports[i]; else acellInfo->hostAddr[i].sin_port = 0; } acellInfo->numServers = numServers; strlcpy(acellInfo->name, acellName, sizeof acellInfo->name); acellInfo->linkedCell = NULL; /* no linked cell */ acellInfo->flags = 0; return 0; }