diff options
author | Jeffrey Hutzelman <jhutz@cmu.edu> | 2013-01-04 18:05:28 -0500 |
---|---|---|
committer | Jeffrey Hutzelman <jhutz@cmu.edu> | 2013-02-17 22:34:40 -0500 |
commit | 959c68d69e1887cb119f82bf0d64409936696fc0 (patch) | |
tree | 3eb25f2d03c58ea4774322ac00e85045a469ad59 /server | |
parent | 3923d414d0408e2f33dff220c5964b36e28565ba (diff) |
Support calling realm_init() more than once
This makes realm_init() augment the existing other-realm array instead
of replacing it wholesale, which makes it safe to call more than once.
During the first call in which the realm.list file exists and contains at
least one realm, the otherrealms array will be initialized with entries
for all configured realms. During subsequent calls, any new realms will
be added, growing the array as necessary. For now, entries for existing
realms are not updated in any way.
Diffstat (limited to 'server')
-rw-r--r-- | server/realm.c | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/server/realm.c b/server/realm.c index 6b84e05..d4eeff6 100644 --- a/server/realm.c +++ b/server/realm.c @@ -3,9 +3,10 @@ Unacked *rlm_nacklist = NULL; /* not acked list for realm-realm packets */ -ZRealm **otherrealms; /* points to an array of the known +ZRealm **otherrealms = NULL; /* points to an array of the known servers */ int nrealms = 0; /* number of other realms */ +int n_realm_slots = 0; /* size of malloc'd otherrealms */ /* * External Routines: @@ -514,7 +515,7 @@ realm_init(void) ZRealm_server *srvr; ZRealmname *rlmnames; ZRealm *rlm; - int ii, jj; + int ii, jj, nrlmnames; struct hostent *hp; char realm_list_file[128]; char rlmprinc[MAX_PRINCIPAL_SIZE]; @@ -523,27 +524,53 @@ realm_init(void) rlmnames = get_realm_lists(realm_list_file); if (!rlmnames) { zdbug((LOG_DEBUG, "No other realms")); - nrealms = 0; + /* should we nuke all existing server records? */ return; } - for (nrealms = 0; rlmnames[nrealms].name; nrealms++); + for (nrlmnames = 0; rlmnames[nrlmnames].name; nrlmnames++); - otherrealms = (ZRealm **)malloc(nrealms * sizeof(ZRealm *)); + /* + * This happens only when we first start up. Otherwise, otherrealms + * is grown as needed. + */ if (!otherrealms) { - syslog(LOG_CRIT, "malloc failed in realm_init"); - abort(); + otherrealms = (ZRealm **)malloc(nrlmnames * sizeof(ZRealm *)); + if (!otherrealms) { + syslog(LOG_CRIT, "malloc failed in realm_init"); + abort(); + } + memset(otherrealms, 0, (nrlmnames * sizeof(ZRealm *))); + n_realm_slots = nrlmnames; } - memset(otherrealms, 0, (nrealms * sizeof(ZRealm *))); - for (ii = 0; ii < nrealms; ii++) { + for (ii = 0; ii < nrlmnames; ii++) { + rlm = realm_get_realm_by_name_string(rlmnames[ii].name); + if (rlm) { + // XXX update existing realm + free(rlmnames[ii].servers); + continue; + } + + if (nrealms >= n_realm_slots) { + otherrealms = realloc(otherrealms, + n_realm_slots * 2 * sizeof(ZRealm *)); + if (!otherrealms) { + syslog(LOG_CRIT, "realloc failed in realm_init"); + abort(); + } + memset(otherrealms + n_realm_slots, 0, + n_realm_slots * sizeof(ZRealm *)); + n_realm_slots *= 2; + } + rlm = (ZRealm *) malloc(sizeof(ZRealm)); if (!rlm) { syslog(LOG_CRIT, "malloc failed in realm_init"); abort(); } memset(rlm, 0, sizeof(ZRealm)); - otherrealms[ii] = rlm; + otherrealms[nrealms++] = rlm; rlm->namestr = rlmnames[ii].name; rlm->name = rlm->namestr->string; |