/** * Get the current localcell name. * * Internal function to get a pointer to the local cell name. * This function must be called with the global afsconf lock held. * * @param[in] adir afsconf object * @param[out] aname address to a char pointer * @param[in] check always perform a config check, even if the * the AFSCELL name is set. * * @return status * @retval 0 success * @retval AFSCONF_NOCELLNAME cannot determine local cell name * * @internal */ int _afsconf_GetLocalCell(struct afsconf_dir *adir, char **pname, int check) { static int afsconf_showcell = 0; char *afscell_path; afs_int32 code = 0; /* * If a cell switch was specified in a command, then it should override the * AFSCELL variable. If a cell was specified, then the afsconf_SawCell flag * is set and the cell name in the adir structure is used. * Read the AFSCELL var each time: in case it changes (unsetenv AFSCELL). * Optionally, check the configuration, even if using the environment variable. */ if (!afsconf_SawCell && (afscell_path = getenv("AFSCELL"))) { if (check) { _afsconf_Check(adir); } if (!afsconf_showcell) { fprintf(stderr, "Note: Operation is performed on cell %s\n", afscell_path); afsconf_showcell = 1; } *pname = afscell_path; } else { _afsconf_Check(adir); if (adir->cellName) { *pname = adir->cellName; } else code = AFSCONF_NOCELLNAME; } return code; }
int afsconf_GetLocalCell(struct afsconf_dir *adir, char *aname, afs_int32 alen) { static int afsconf_showcell = 0; char *afscell_path; afs_int32 code = 0; LOCK_GLOBAL_MUTEX; /* * If a cell switch was specified in a command, then it should override the * AFSCELL variable. If a cell was specified, then the afsconf_SawCell flag * is set and the cell name in the adir structure is used. * Read the AFSCELL var each time: in case it changes (unsetenv AFSCELL). */ if (!afsconf_SawCell && (afscell_path = getenv("AFSCELL"))) { if (!afsconf_showcell) { fprintf(stderr, "Note: Operation is performed on cell %s\n", afscell_path); afsconf_showcell = 1; } strncpy(aname, afscell_path, alen); } else { _afsconf_Check(adir); if (adir->cellName) { strncpy(aname, adir->cellName, alen); } else code = AFSCONF_UNKNOWN; } UNLOCK_GLOBAL_MUTEX; return (code); }
int afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice, struct afsconf_cell *acellInfo) { struct afsconf_entry *tce; struct afsconf_aliasentry *tcae; struct afsconf_entry *bestce; afs_int32 i; int tservice; char *tcell; int cnLen; int ambig; char tbuffer[64]; LOCK_GLOBAL_MUTEX; if (adir) _afsconf_Check(adir); if (acellName) { tcell = acellName; cnLen = (int)(strlen(tcell) + 1); lcstring(tcell, tcell, cnLen); afsconf_SawCell = 1; /* will ignore the AFSCELL switch on future */ /* call to afsconf_GetLocalCell: like klog */ } else { i = afsconf_GetLocalCell(adir, tbuffer, sizeof(tbuffer)); if (i) { UNLOCK_GLOBAL_MUTEX; return i; } tcell = tbuffer; } cnLen = strlen(tcell); bestce = (struct afsconf_entry *)0; ambig = 0; if (!adir) { UNLOCK_GLOBAL_MUTEX; return 0; } /* Look through the list of aliases */ for (tcae = adir->alias_entries; tcae; tcae = tcae->next) { if (strcasecmp(tcae->aliasInfo.aliasName, tcell) == 0) { tcell = tcae->aliasInfo.realName; break; } } for (tce = adir->entries; tce; tce = tce->next) { if (strcasecmp(tce->cellInfo.name, tcell) == 0) { /* found our cell */ bestce = tce; ambig = 0; break; } if (strlen(tce->cellInfo.name) < cnLen) continue; /* clearly wrong */ if (strncasecmp(tce->cellInfo.name, tcell, cnLen) == 0) { if (bestce) ambig = 1; /* ambiguous unless we get exact match */ bestce = tce; } } if (!ambig && bestce && bestce->cellInfo.numServers) { *acellInfo = bestce->cellInfo; /* structure assignment */ if (aservice) { tservice = afsconf_FindService(aservice); if (tservice < 0) { UNLOCK_GLOBAL_MUTEX; return AFSCONF_NOTFOUND; /* service not found */ } for (i = 0; i < acellInfo->numServers; i++) { acellInfo->hostAddr[i].sin_port = tservice; } } acellInfo->timeout = 0; /* * Until we figure out how to separate out ubik server * queries from other server queries, only perform gethostbyname() * lookup on the specified hostnames for the client CellServDB files. */ if (_afsconf_IsClientConfigDirectory(adir->name) && !(acellInfo->flags & AFSCONF_CELL_FLAG_DNS_QUERIED)) { int j; short numServers=0; /*Num active servers for the cell */ struct sockaddr_in hostAddr[MAXHOSTSPERCELL]; /*IP addresses for cell's servers */ char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS]; /*Names for cell's servers */ char clone[MAXHOSTSPERCELL]; /*Indicates which ones are clones. */ memset(&hostAddr, 0, sizeof(hostAddr)); memset(&hostName, 0, sizeof(hostName)); memset(&clone, 0, sizeof(clone)); for ( j=0; j<acellInfo->numServers && numServers < MAXHOSTSPERCELL; j++ ) { struct hostent *he = gethostbyname(acellInfo->hostName[j]); int foundAddr = 0; if (he && he->h_addrtype == AF_INET) { int i; /* obtain all the valid address from the list */ for (i=0 ; he->h_addr_list[i] && numServers < MAXHOSTSPERCELL; i++) { /* check to see if this is a new address; if so insert it into the list */ int k, dup; afs_uint32 addr; memcpy(&addr, he->h_addr_list[i], sizeof(addr)); for (k=0, dup=0; !dup && k < numServers; k++) { if (hostAddr[k].sin_addr.s_addr == addr) { dup = 1; } } if (dup) continue; hostAddr[numServers].sin_family = AF_INET; hostAddr[numServers].sin_port = acellInfo->hostAddr[0].sin_port; #ifdef STRUCT_SOCKADDR_HAS_SA_LEN hostAddr[numServers].sin_len = sizeof(struct sockaddr_in); #endif memcpy(&hostAddr[numServers].sin_addr.s_addr, he->h_addr_list[i], sizeof(afs_uint32)); strcpy(hostName[numServers], acellInfo->hostName[j]); clone[numServers] = acellInfo->clone[j]; foundAddr = 1; numServers++; } } if (!foundAddr) { hostAddr[numServers] = acellInfo->hostAddr[j]; strcpy(hostName[numServers], acellInfo->hostName[j]); clone[numServers] = acellInfo->clone[j]; numServers++; } } for (i=0; i<numServers; i++) { acellInfo->hostAddr[i] = hostAddr[i]; strcpy(acellInfo->hostName[i], hostName[i]); acellInfo->clone[i] = clone[i]; } acellInfo->numServers = numServers; acellInfo->flags |= AFSCONF_CELL_FLAG_DNS_QUERIED; } UNLOCK_GLOBAL_MUTEX; return 0; } else { UNLOCK_GLOBAL_MUTEX; return afsconf_GetAfsdbInfo(tcell, aservice, acellInfo); } }