#include <afsconfig.h>
#include <afs/param.h>
-RCSID
- ("$Header$");
#include <afs/stds.h>
#include <afs/pthread_glock.h>
#include "afsincludes.h"
#include "des/des.h"
#include "rx/rxkad.h"
+#include <netdb.h>
+#include <ctype.h>
#else /* UKERNEL */
#include <sys/types.h>
#ifdef AFS_NT40_ENV
#include <netdb.h>
#include <sys/file.h>
#include <sys/time.h>
+#include <ctype.h>
#ifdef AFS_AFSDB_ENV
#include <arpa/nameser.h>
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
#include "keys.h"
#ifdef AFS_NT40_ENV
#ifdef AFS_AFSDB_ENV
+#include <cm.h>
+#include <cm_config.h>
/* cm_dns.h depends on cellconfig.h */
#include <cm_nls.h>
#include <cm_dns.h>
#include <rx/rx.h>
#include <rx/rxkad.h>
+struct afsconf_servPair {
+ const char *name;
+ const char *ianaName;
+ int port;
+};
+
static struct afsconf_servPair serviceTable[] = {
- {"afs", 7000,},
- {"afscb", 7001,},
- {"afsprot", 7002,},
- {"afsvldb", 7003,},
- {"afskauth", 7004,},
- {"afsvol", 7005,},
- {"afserror", 7006,},
- {"afsnanny", 7007,},
- {"afsupdate", 7008,},
- {"afsrmtsys", 7009,},
- {"afsres", 7010,}, /* residency database for MR-AFS */
- {"afsremio", 7011,}, /* remote I/O interface for MR-AFS */
- {0, 0} /* insert new services before this spot */
+ {"afs", "afs3-fileserver", 7000,},
+ {"afscb", "afs3-callback", 7001,},
+ {"afsprot", "afs3-prserver", 7002,},
+ {"afsvldb", "afs3-vlserver", 7003,},
+ {"afskauth", "afs3-kaserver", 7004,},
+ {"afsvol", "afs3-volserver", 7005,},
+ {"afserror", "afs3-errors", 7006,},
+ {"afsnanny", "afs3-bos", 7007,},
+ {"afsupdate", "afs3-update", 7008,},
+ {"afsrmtsys", "afs3-rmtsys", 7009,},
+ {"afsres", NULL, 7010,},/* residency database for MR-AFS */
+ {"afsremio", NULL, 7011,}, /* remote I/O interface for MR-AFS */
+ {0, 0, 0} /* insert new services before this spot */
};
/* Prototypes */
-static afs_int32 afsconf_FindService(register const char *aname);
static int TrimLine(char *abuffer, int abufsize);
-#ifdef AFS_NT40_ENV
static int IsClientConfigDirectory(const char *path);
+#ifdef AFS_NT40_ENV
static int GetCellNT(struct afsconf_dir *adir);
#endif
static int afsconf_Check(register struct afsconf_dir *adir);
#endif /* AFS_SUN5_ENV && ! __sparcv9 */
/* return port number in network byte order in the low 16 bits of a long; return -1 if not found */
-static afs_int32
-afsconf_FindService(register const char *aname)
+afs_int32
+afsconf_FindService(const char *aname)
{
/* lookup a service name */
struct servent *ts;
- register struct afsconf_servPair *tsp;
+ struct afsconf_servPair *tsp;
+
+ if (aname == NULL || aname[0] == '\0')
+ return -1;
#if defined(AFS_OSF_ENV)
ts = getservbyname(aname, "");
#else
- ts = getservbyname(aname, NULL);
+ ts = (struct servent *) getservbyname(aname, NULL);
#endif
if (ts) {
/* we found it in /etc/services, so we use this value */
}
/* not found in /etc/services, see if it is one of ours */
- for (tsp = serviceTable;; tsp++) {
- if (tsp->name == NULL)
- return -1;
- if (!strcmp(tsp->name, aname))
+ for (tsp = serviceTable; tsp->port; tsp++) {
+ if ((tsp->name && (!strcmp(tsp->name, aname)))
+ || (tsp->ianaName && (!strcmp(tsp->ianaName, aname))))
return htons(tsp->port);
}
+ return -1;
+}
+
+const char *
+afsconf_FindIANAName(const char *aname)
+{
+ /* lookup a service name */
+ struct afsconf_servPair *tsp;
+
+ if (aname == NULL || aname[0] == '\0')
+ return NULL;
+
+ /* see if it is one of ours */
+ for (tsp = serviceTable; tsp->port; tsp++) {
+ if ((tsp->name && (!strcmp(tsp->name, aname)))
+ || (tsp->ianaName && (!strcmp(tsp->ianaName, aname))))
+ return tsp->ianaName;
+ }
+ return NULL;
}
static int
return 0;
}
-#ifdef AFS_NT40_ENV
/*
* IsClientConfigDirectory() -- determine if path matches well-known
* client configuration directory.
*/
+#ifdef AFS_NT40_ENV
+#define IS_SEP(x) ((x) == '\\' || (x) == '/')
+#else /* AFS_NT40_ENV */
+#define IS_SEP(x) ((x) == '/')
+#endif /* AFS_NT40_ENV */
static int
IsClientConfigDirectory(const char *path)
{
const char *cdir = AFSDIR_CLIENT_ETC_DIRPATH;
- int i;
+ int i, cc, pc;
for (i = 0; cdir[i] != '\0' && path[i] != '\0'; i++) {
- int cc = tolower(cdir[i]);
- int pc = tolower(path[i]);
+#ifdef AFS_NT40_ENV
+ cc = tolower(cdir[i]);
+ pc = tolower(path[i]);
if (cc == '\\') {
cc = '/';
if (pc == '\\') {
pc = '/';
}
- if (cc != pc) {
+#else /* AFS_NT40_ENV */
+ cc = cdir[i];
+ pc = path[i];
+#endif /* AFS_NT40_ENV */
+ if (cc != pc) {
return 0;
}
}
/* hit end of one or both; allow mismatch in existence of trailing slash */
if (cdir[i] != '\0') {
- if ((cdir[i] != '\\' && cdir[i] != '/') || (cdir[i + 1] != '\0')) {
+ if (!IS_SEP(cdir[i]) || (cdir[i + 1] != '\0')) {
return 0;
}
}
if (path[i] != '\0') {
- if ((path[i] != '\\' && path[i] != '/') || (path[i + 1] != '\0')) {
+ if (!IS_SEP(path[i]) || (path[i + 1] != '\0')) {
return 0;
}
}
return 1;
}
-#endif /* AFS_NT40_ENV */
static int
return GetCellUnix(adir);
}
}
+
+/* The following procedures and structs are used on Windows only
+ * to enumerate the Cell information distributed within the
+ * Windows registry. (See src/WINNT/afsd/cm_config.c)
+ */
+typedef struct _cm_enumCellRegistry {
+ afs_uint32 client; /* non-zero if client query */
+ struct afsconf_dir *adir;
+} cm_enumCellRegistry_t;
+
+static long
+cm_serverConfigProc(void *rockp, struct sockaddr_in *addrp,
+ char *hostNamep, unsigned short rank)
+{
+ struct afsconf_cell *cellInfop = (struct afsconf_cell *)rockp;
+
+ if (cellInfop->numServers == MAXHOSTSPERCELL)
+ return 0;
+
+ cellInfop->hostAddr[cellInfop->numServers] = *addrp;
+ strncpy(cellInfop->hostName[cellInfop->numServers], hostNamep, MAXHOSTCHARS);
+ cellInfop->hostName[cellInfop->numServers][MAXHOSTCHARS-1] = '\0';
+ cellInfop->numServers++;
+
+ return 0;
+}
+
+static long
+cm_enumCellRegistryProc(void *rockp, char * cellNamep)
+{
+ long code;
+ cm_enumCellRegistry_t *enump = (cm_enumCellRegistry_t *)rockp;
+ char linkedName[256] = "";
+ int timeout = 0;
+ struct afsconf_entry *newEntry;
+
+
+ newEntry = malloc(sizeof(struct afsconf_entry));
+ if (newEntry == NULL)
+ return ENOMEM;
+ newEntry->cellInfo.numServers = 0;
+
+ code = cm_SearchCellRegistry(enump->client, cellNamep, NULL, linkedName, cm_serverConfigProc, &newEntry->cellInfo);
+ if (code == CM_ERROR_FORCE_DNS_LOOKUP)
+ code = cm_SearchCellByDNS(cellNamep, NULL, &timeout, cm_serverConfigProc, &newEntry->cellInfo);
+
+ if (code == 0) {
+ strncpy(newEntry->cellInfo.name, cellNamep, MAXCELLCHARS);
+ newEntry->cellInfo.name[MAXCELLCHARS-1];
+ if (linkedName[0])
+ newEntry->cellInfo.linkedCell = strdup(linkedName);
+ else
+ newEntry->cellInfo.linkedCell = NULL;
+ newEntry->cellInfo.timeout = timeout;
+ newEntry->cellInfo.flags = 0;
+
+ newEntry->next = enump->adir->entries;
+ enump->adir->entries = newEntry;
+ } else {
+ free(newEntry);
+ }
+ return code;
+}
#endif /* AFS_NT40_ENV */
afs_int32 i;
char tbuffer[256], tbuf1[256];
struct stat tstat;
+#ifdef AFS_NT40_ENV
+ cm_enumCellRegistry_t enumCellRegistry = {0, 0};
+#endif /* AFS_NT40_ENV */
/* figure out the local cell name */
#ifdef AFS_NT40_ENV
i = GetCellNT(adir);
+ enumCellRegistry.adir = adir;
#else
i = GetCellUnix(adir);
#endif
if (IsClientConfigDirectory(adir->name)) {
/* NT client config dir */
char *p;
+
+ enumCellRegistry.client = 1;
+
if (!afssw_GetClientCellServDBDir(&p)) {
strcompose(tbuffer, sizeof(tbuffer), p, "/",
AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
if (!tf) {
return -1;
}
+
+ /* The CellServDB file is now open.
+ * The following code parses the contents of the
+ * file and creates a list with the first cell entry
+ * in the CellServDB file at the end of the list.
+ *
+ * No checking is performed for duplicates.
+ * The side effects of this process are that duplicate
+ * entries appended to the end of the CellServDB file
+ * take precedence and are found in a shorter period
+ * of time.
+ */
+
while (1) {
tp = fgets(tbuffer, sizeof(tbuffer), tf);
if (!tp)
return -1;
}
i = curEntry->cellInfo.numServers;
- if (cell && !strcmp(cell, curEntry->cellInfo.name))
- code =
- ParseHostLine(tbuffer, &curEntry->cellInfo.hostAddr[i],
- curEntry->cellInfo.hostName[i], &clones[i]);
- else
- code =
- ParseHostLine(tbuffer, &curEntry->cellInfo.hostAddr[i],
- curEntry->cellInfo.hostName[i], 0);
- if (code) {
- if (code == AFSCONF_SYNTAX) {
- for (bp = tbuffer; *bp != '\n'; bp++) { /* Take out the <cr> from the buffer */
- if (!*bp)
- break;
+ if (i < MAXHOSTSPERCELL) {
+ if (cell && !strcmp(cell, curEntry->cellInfo.name))
+ code =
+ ParseHostLine(tbuffer,
+ &curEntry->cellInfo.hostAddr[i],
+ curEntry->cellInfo.hostName[i],
+ &clones[i]);
+ else
+ code =
+ ParseHostLine(tbuffer,
+ &curEntry->cellInfo.hostAddr[i],
+ curEntry->cellInfo.hostName[i], 0);
+
+ if (code) {
+ if (code == AFSCONF_SYNTAX) {
+ for (bp = tbuffer; *bp != '\n'; bp++) { /* Take out the <cr> from the buffer */
+ if (!*bp)
+ break;
+ }
+ *bp = '\0';
+ fprintf(stderr,
+ "Can't properly parse host line \"%s\" in configuration file %s\n",
+ tbuffer, tbuf1);
}
- *bp = '\0';
- fprintf(stderr,
- "Can't properly parse host line \"%s\" in configuration file %s\n",
- tbuffer, tbuf1);
+ free(curEntry);
+ fclose(tf);
+ afsconf_CloseInternal(adir);
+ return -1;
}
- free(curEntry);
- fclose(tf);
- afsconf_CloseInternal(adir);
- return -1;
+ curEntry->cellInfo.numServers = ++i;
+ } else {
+ fprintf(stderr,
+ "Too many hosts for cell %s in configuration file %s\n",
+ curEntry->cellInfo.name, tbuf1);
}
- curEntry->cellInfo.numServers = ++i;
}
}
fclose(tf); /* close the file now */
adir->entries = curEntry;
}
+#ifdef AFS_NT40_ENV
+ /*
+ * Windows maintains a CellServDB list in the Registry
+ * that supercedes the contents of the CellServDB file.
+ * Prepending these entries to the head of the list
+ * is sufficient to enforce the precedence.
+ */
+ cm_EnumerateCellRegistry( enumCellRegistry.client,
+ cm_enumCellRegistryProc,
+ &enumCellRegistry);
+#endif /* AFS_NT40_ENV */
+
/* Read in the alias list */
strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLALIAS_FILE, NULL);
afsconf_GetAfsdbInfo(char *acellName, char *aservice,
struct afsconf_cell *acellInfo)
{
- register afs_int32 i;
- int tservice;
+ afs_int32 i;
+ int tservice = afsconf_FindService(aservice);
+ const char *ianaName = afsconf_FindIANAName(aservice);
struct afsconf_entry DNSce;
afs_int32 cellHostAddrs[AFSMAXCELLHOSTS];
char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
+ unsigned short ipRanks[AFSMAXCELLHOSTS];
+ unsigned short ports[AFSMAXCELLHOSTS];
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(acellName, cellHostAddrs, cellHostNames, &numServers,
+
+ 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 (rc < 0)
- return -1;
- if (numServers == 0)
+
+ /* 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 == 7002 || tservice == 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++) {
sizeof(long));
memcpy(acellInfo->hostName[i], cellHostNames[i], MAXHOSTCHARS);
acellInfo->hostAddr[i].sin_family = AF_INET;
-
- /* sin_port supplied by connection code */
+ 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);
- if (aservice) {
- LOCK_GLOBAL_MUTEX;
- tservice = afsconf_FindService(aservice);
- UNLOCK_GLOBAL_MUTEX;
- if (tservice < 0) {
- return AFSCONF_NOTFOUND; /* service not found */
- }
- for (i = 0; i < acellInfo->numServers; i++) {
- acellInfo->hostAddr[i].sin_port = tservice;
- }
- }
acellInfo->linkedCell = NULL; /* no linked cell */
acellInfo->flags = 0;
return 0;
}
}
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 (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 */
+
+ memset(&hostAddr, 0, sizeof(hostAddr));
+ memset(&hostName, 0, sizeof(hostName));
+
+ 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;
+ for (k=0, dup=0; !dup && k < numServers; k++) {
+ if (hostAddr[k].sin_addr.s_addr == *(u_long *)he->h_addr_list[i])
+ 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(long));
+ strcpy(hostName[numServers], acellInfo->hostName[j]);
+ foundAddr = 1;
+ numServers++;
+ }
+ }
+ if (!foundAddr) {
+ hostAddr[numServers] = acellInfo->hostAddr[j];
+ strcpy(hostName[numServers], acellInfo->hostName[j]);
+ numServers++;
+ }
+ }
+
+ for (i=0; i<numServers; i++) {
+ acellInfo->hostAddr[i] = hostAddr[i];
+ strcpy(acellInfo->hostName[i], hostName[i]);
+ }
+ acellInfo->numServers = numServers;
+ acellInfo->flags |= AFSCONF_CELL_FLAG_DNS_QUERIED;
+ }
UNLOCK_GLOBAL_MUTEX;
return 0;
} else {