#include <afs/stds.h>
#include <roken.h>
+#include <afs/opr.h>
#ifdef AFS_NT40_ENV
#include <sys/utime.h>
char *cellservDB;
struct stat tstat;
int code;
+ time_t now = time(0);
+
+ if (adir->timeCheck == now) {
+ return 1; /* stat no more than once a second */
+ }
+ adir->timeCheck = now;
_afsconf_CellServDBPath(adir, &cellservDB);
if (cellservDB == NULL)
#endif
adir->timeRead = 0; /* just in case */
+ adir->timeCheck = 0;
_afsconf_CellServDBPath(adir, &cellservDB);
if (cellservDB == NULL)
return -1;
}
+ /* init the keys queue before any call to afsconf_CloseInternal() */
+ _afsconf_InitKeys(adir);
+
/* The CellServDB file is now open.
* The following code parses the contents of the
* file and creates a list with the first cell entry
if (tf != NULL)
fclose(tf);
- /* now read the fs keys, if possible */
- _afsconf_InitKeys(adir);
+ /* now read the fs keys, if possible */
code = _afsconf_LoadKeys(adir);
+ if (code) {
+ return code;
+ }
+ code = _afsconf_LoadRealms(adir);
return code;
}
if ((afsdb_type == 1) && (server_num < MAXHOSTSPERCELL) &&
/* Do we want to get TTL data for the A record as well? */
(he = gethostbyname(host))) {
- afs_int32 ipaddr;
- memcpy(&ipaddr, he->h_addr, he->h_length);
- cellHostAddrs[server_num] = ipaddr;
- ports[server_num] = afsdbPort;
- ipRanks[server_num] = 0;
- strncpy(cellHostNames[server_num], host,
- sizeof(cellHostNames[server_num]));
- server_num++;
-
- if (!minttl || ttl < minttl)
- minttl = ttl;
+ if (he->h_addrtype == AF_INET) {
+ afs_int32 ipaddr;
+ memcpy(&ipaddr, he->h_addr, sizeof(ipaddr));
+ cellHostAddrs[server_num] = ipaddr;
+ ports[server_num] = afsdbPort;
+ ipRanks[server_num] = 0;
+ strncpy(cellHostNames[server_num], host,
+ sizeof(cellHostNames[server_num]));
+ server_num++;
+ if (!minttl || ttl < minttl)
+ minttl = ttl;
+ }
}
}
if (type == T_SRV) {
if ((server_num < MAXHOSTSPERCELL) &&
/* Do we want to get TTL data for the A record as well? */
(he = gethostbyname(host))) {
- afs_int32 ipaddr;
- memcpy(&ipaddr, he->h_addr, he->h_length);
- cellHostAddrs[server_num] = ipaddr;
- ipRanks[server_num] = (p[0] << 8) | p[1];
- ports[server_num] = htons((p[4] << 8) | p[5]);
- /* weight = (p[2] << 8) | p[3]; */
- strncpy(cellHostNames[server_num], host,
- sizeof(cellHostNames[server_num]));
- server_num++;
-
- if (!minttl || ttl < minttl)
- minttl = ttl;
+ if (he->h_addrtype == AF_INET) {
+ afs_int32 ipaddr;
+
+ memcpy(&ipaddr, he->h_addr, sizeof(ipaddr));
+ cellHostAddrs[server_num] = ipaddr;
+ ipRanks[server_num] = (p[0] << 8) | p[1];
+ ports[server_num] = htons((p[4] << 8) | p[5]);
+ /* weight = (p[2] << 8) | p[3]; */
+ strncpy(cellHostNames[server_num], host,
+ sizeof(cellHostNames[server_num]));
+ server_num++;
+
+ if (!minttl || ttl < minttl)
+ minttl = ttl;
+ }
}
}
}
}
+/**
+ * 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_UNKNOWN failed to get cellname
+ *
+ * @internal
+ */
int
-afsconf_GetLocalCell(struct afsconf_dir *adir, char *aname,
- afs_int32 alen)
+_afsconf_GetLocalCell(struct afsconf_dir *adir, char **pname, int check)
{
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).
+ * 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;
}
- strncpy(aname, afscell_path, alen);
+ *pname = afscell_path;
} else {
_afsconf_Check(adir);
if (adir->cellName) {
- strncpy(aname, adir->cellName, alen);
+ *pname = adir->cellName;
} else
code = AFSCONF_UNKNOWN;
}
+ return code;
+}
+int
+afsconf_GetLocalCell(struct afsconf_dir *adir, char *aname, afs_int32 alen)
+{
+ afs_int32 code = 0;
+ char *cellname = NULL;
+
+ LOCK_GLOBAL_MUTEX;
+ code = _afsconf_GetLocalCell(adir, &cellname, 0);
+ if (!code && cellname) {
+ strlcpy(aname, cellname, alen);
+ }
UNLOCK_GLOBAL_MUTEX;
return (code);
}
}
_afsconf_FreeAllKeys(adir);
+ _afsconf_FreeRealms(adir);
/* reinit */
memset(adir, 0, sizeof(struct afsconf_dir));