summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorGravatar Jeffrey Hutzelman <jhutz@cmu.edu>2012-11-25 05:32:19 -0500
committerGravatar Jeffrey Hutzelman <jhutz@cmu.edu>2013-02-17 22:34:40 -0500
commitc62bf1b7533ad07647828b82ad1600200378f492 (patch)
treef69ff605d67170885a78983907e57ae7e8e5ae82 /server
parent6452eb4960a542328615730b6a11d24a1281a457 (diff)
Return _ZRealm_server from get_realm_lists()
Instead of returning an array of server hostname strings for each realm, get_realm_lists() now returns an array of struct _ZRealm_server for each realm. This allows it to return additional per-server information found in the realm.list file, such as the nosend flag, and simplifies creation of the final per-realm server list. This change will make it easier to use interned strings for server names, which will eventually enable efficient processing of updates to server configuration when the realm.list file is reloaded.
Diffstat (limited to 'server')
-rw-r--r--server/realm.c74
-rw-r--r--server/zserver.h3
2 files changed, 27 insertions, 50 deletions
diff --git a/server/realm.c b/server/realm.c
index 431893e..2b906a9 100644
--- a/server/realm.c
+++ b/server/realm.c
@@ -213,16 +213,16 @@ get_realm_lists(char *file)
rlm = &rlm_list[ii];
if (rlm->nused +1 >= rlm->nservers) {
/* make more space */
- rlm->servers = (char **)realloc((char *)rlm->servers,
- (unsigned)rlm->nservers * 2 *
- sizeof(char *));
+ rlm->servers = (struct _ZRealm_server *)
+ realloc((char *)rlm->servers,
+ (unsigned)rlm->nservers * 2 *
+ sizeof(struct _ZRealm_server));
if (!rlm->servers) {
syslog(LOG_CRIT, "get_realm_lists realloc");
abort();
}
rlm->nservers *= 2;
}
- rlm->servers[rlm->nused++] = strsave(server);
} else {
/* new realm */
if (nused + 1 >= ntotal) {
@@ -240,13 +240,21 @@ get_realm_lists(char *file)
strcpy(rlm->name, realm);
rlm->nused = 0;
rlm->nservers = 16;
- rlm->servers = (char **)malloc(rlm->nservers * sizeof(char *));
+ rlm->servers = (struct _ZRealm_server *)
+ malloc(rlm->nservers * sizeof(struct _ZRealm_server));
if (!rlm->servers) {
syslog(LOG_CRIT, "get_realm_lists malloc");
abort();
}
- rlm->servers[rlm->nused++] = strsave(server);
}
+ memset(&rlm->servers[rlm->nused], 0, sizeof(struct _ZRealm_server));
+ if (*server == '/') {
+ rlm->servers[rlm->nused].name = strsave(server + 1);
+ rlm->servers[rlm->nused].dontsend = 1;
+ } else {
+ rlm->servers[rlm->nused].name = strsave(server);
+ }
+ rlm->nused++;
}
if (nused + 1 >= ntotal) {
rlm_list = (ZRealmname *)realloc((char *)rlm_list,
@@ -494,9 +502,7 @@ realm_init(void)
ZRealm_server *srvr;
ZRealmname *rlmnames;
ZRealm *rlm;
- int ii, jj, found;
- struct in_addr *addresses;
- char *nosend;
+ int ii, jj;
struct hostent *hp;
char realm_list_file[128];
char rlmprinc[MAX_PRINCIPAL_SIZE];
@@ -521,50 +527,23 @@ realm_init(void)
for (ii = 0; ii < nrealms; ii++) {
rlm = &otherrealms[ii];
strcpy(rlm->name, rlmnames[ii].name);
- nosend = malloc(rlmnames[ii].nused * sizeof(char));
-
- addresses = (struct in_addr *)malloc(rlmnames[ii].nused *
- sizeof(struct in_addr));
- if (!addresses || !nosend) {
- syslog(LOG_CRIT, "malloc failed in realm_init");
- abort();
- }
/* convert names to addresses */
- found = 0;
- for (jj = 0; jj < rlmnames[ii].nused; jj++) {
- if (*rlmnames[ii].servers[jj] == '/')
- nosend[found] = 1;
- else
- nosend[found] = 0;
-
- hp = gethostbyname((rlmnames[ii].servers[jj])+nosend[found]);
+ rlm->count = rlmnames[ii].nused;
+ rlm->srvrs = rlmnames[ii].servers;
+ for (srvr = rlm->srvrs, jj = 0; jj < rlm->count; jj++, srvr++) {
+ hp = gethostbyname(srvr->name);
if (hp) {
- memmove(&addresses[found], hp->h_addr,
+ memmove(&srvr->addr.sin_addr, hp->h_addr,
sizeof(struct in_addr));
- found++;
+ /* use the server port */
+ srvr->addr.sin_port = srv_addr.sin_port;
+ srvr->addr.sin_family = AF_INET;
+ srvr->usable = 1;
} else
- syslog(LOG_WARNING, "hostname failed, %s",
- rlmnames[ii].servers[jj]);
- /* free the hostname */
- free(rlmnames[ii].servers[jj]);
- }
- rlm->count = found;
- rlm->srvrs = (ZRealm_server *)malloc(found * sizeof(ZRealm_server));
- if (!rlm->srvrs) {
- syslog(LOG_CRIT, "malloc failed in realm_init");
- abort();
+ syslog(LOG_WARNING, "hostname failed, %s", srvr->name);
}
- memset(rlm->srvrs, 0, (found * sizeof(ZRealm_server)));
- for (srvr = rlm->srvrs, jj = 0; jj < rlm->count; jj++, srvr++) {
- srvr->addr.sin_addr = addresses[jj];
- /* use the server port */
- srvr->addr.sin_port = srv_addr.sin_port;
- srvr->addr.sin_family = AF_INET;
- srvr->usable = 1;
- srvr->dontsend = nosend[jj];
- }
client = (Client *) malloc(sizeof(Client));
if (!client) {
syslog(LOG_CRIT, "malloc failed in realm_init");
@@ -598,9 +577,6 @@ realm_init(void)
/* Assume the best */
rlm->state = REALM_TARDY;
rlm->have_tkt = 1;
- free(rlmnames[ii].servers);
- free(addresses);
- free(nosend);
}
free(rlmnames);
}
diff --git a/server/zserver.h b/server/zserver.h
index b61cc06..bb1f722 100644
--- a/server/zserver.h
+++ b/server/zserver.h
@@ -112,6 +112,7 @@ struct _Destlist {
};
struct _ZRealm_server {
+ char *name; /* server's hostname */
struct sockaddr_in addr; /* server's address */
unsigned int usable :1; /* set once entry is usable */
unsigned int dontsend :1; /* private server, do not send */
@@ -132,7 +133,7 @@ struct _ZRealm {
struct _ZRealmname {
char name[REALM_SZ];
- char **servers;
+ struct _ZRealm_server *servers;
int nused;
int nservers;
};