diff options
| author | Theodore Tso <tytso@mit.edu> | 1998-11-03 22:49:25 +0000 |
|---|---|---|
| committer | Theodore Tso <tytso@mit.edu> | 1998-11-03 22:49:25 +0000 |
| commit | a77feae4293dbdba211ca39a275da85e7c3b655f (patch) | |
| tree | e5d2dd560fe394343167007cc7e9c7bb04c240e1 /src/util/profile/prof_init.c | |
| parent | 186666be751244e0382e41cc175b5eb9e888b34d (diff) | |
| download | krb5-a77feae4293dbdba211ca39a275da85e7c3b655f.tar.gz krb5-a77feae4293dbdba211ca39a275da85e7c3b655f.tar.xz krb5-a77feae4293dbdba211ca39a275da85e7c3b655f.zip | |
Makefile.in: Added prof_get.c to the list of files to be compiled
profile.hin: Added declarations for profile_free_list(),
profile_get_relation_names(), and profile_get_subsection_names().
(These are new public interfaces to the profile library.)
prof_int.h: Removed the profile_section_t structure, which was used
only by the now-defunct prof_section.c file. Added the internal
interfaces for the new public interfaces. Removed unused declarations
which were never implemented(profile_get, profile_update).
prof_init.c: Moved all of the profile querying functions
(profile_get_values(), profile_get_value(), etc.) to prof_get.c. In
the process, removed the really bletcherous (and badly implemented)
profile_get_first_values(), which did nothing like what the named
implied. Also added to prof_get.c new functions
profile_get_subsection_names() and profile_get_relation_names().
(profile_ser_internalize): Rewrote error handling to be clearer, and
removed a bug where memory was not freed correctly in an error case.
(profile_init): If a list of pathnames is passed in, profile_init will
now try to open all of them, now that we've defined query fallback
semantics in prof_get.c
prof_parse.c: Fix lint warning.
prof_tree.c (profile_find_node_relation,
profile_find_node_subsection): Allow the returned value or subsection
field to be NULL (in case the caller isn't interested in getting the
returned value or subsection, and only cares about getting the name).
(profile_delete_node_relation, profile_delete_interior_node_relation):
Removed these functions and replaced it with profile_remove_node(),
which takes a boolean argument section_flag.
(profile_find_node_name): Removed this function. (This was a
Cygnus/Fusion special used by the now removed
profile_find_first_values() function.)
test_profile.c: Added commands to test the new
profile_get_subsection_names() and profile_get_relation_names()
interfaces.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11011 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile/prof_init.c')
| -rw-r--r-- | src/util/profile/prof_init.c | 381 |
1 files changed, 56 insertions, 325 deletions
diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c index f69fa0bb7..cbf2bc2ad 100644 --- a/src/util/profile/prof_init.c +++ b/src/util/profile/prof_init.c @@ -30,7 +30,7 @@ errcode_t profile_init(filenames, ret_profile) const char **fn; profile_t profile; prf_file_t new_file, last = 0; - errcode_t retval; + errcode_t retval = 0; initialize_prof_error_table(); @@ -55,9 +55,6 @@ errcode_t profile_init(filenames, ret_profile) else profile->first_file = new_file; last = new_file; - /* since we actually got something, don't loop again */ - /* (at least until we understand what multiple files mean) */ - break; } /* if the last file was missing, they all were, so report such */ if (retval == ENOENT) { @@ -131,274 +128,9 @@ void profile_release(profile) free(profile); } -struct string_list { - char **list; - int num; - int max; -}; - -static errcode_t init_list(list) - struct string_list *list; -{ - list->num = 0; - list->max = 10; - list->list = malloc(list->max * sizeof(char *)); - if (list->list == 0) - return ENOMEM; - list->list[0] = 0; - return 0; -} - -static void free_list(list) - struct string_list *list; -{ - char **cp; - - for (cp = list->list; *cp; cp++) - free(*cp); - free(list->list); - list->num = list->max = 0; - list->list = 0; -} - -static errcode_t add_to_list(list, str) - struct string_list *list; - const char *str; -{ - char *newstr; - - if (list->num+1 >= list->max) { - list->max += 5; - list->list = realloc(list->list, list->max * sizeof(char *)); - if (list->list == 0) - return ENOMEM; - } - newstr = malloc(strlen(str)+1); - if (newstr == 0) - return ENOMEM; - strcpy(newstr, str); - - list->list[list->num++] = newstr; - list->list[list->num] = 0; - return 0; -} - /* - * XXX this version only works to get values from the first file. - * To do more than that means we have to implement some "interesting" - * code to do the section searching. + * Here begins the profile serialization functions. */ -KRB5_DLLIMP errcode_t KRB5_CALLCONV -profile_get_values(profile, names, ret_values) - profile_t profile; - const char **names; - char ***ret_values; -{ - prf_file_t file; - errcode_t retval; - struct profile_node *section; - void *state; - char *value; - struct string_list values; - const char **cpp; - - if (profile == 0) - return PROF_NO_PROFILE; - - if (names == 0 || names[0] == 0 || names[1] == 0) - return PROF_BAD_NAMESET; - - init_list(&values); - - file = profile->first_file; - retval = profile_update_file(file); - if (retval) - goto cleanup; - - section = file->root; - - for (cpp = names; cpp[1]; cpp++) { - state = 0; - retval = profile_find_node_subsection(section, *cpp, - &state, 0, §ion); - if (retval) - goto cleanup; - } - - state = 0; - do { - retval = profile_find_node_relation(section, *cpp, &state, 0, &value); - if (retval) - goto cleanup; - add_to_list(&values, value); - } while (state); - - *ret_values = values.list; - return 0; -cleanup: - free_list(&values); - return retval; -} - -/* - * XXX this version only works to get values from the first file. - * To do more than that means we have to implement some "interesting" - * code to do the section searching. - */ -errcode_t profile_get_first_values(profile, names, ret_values) - profile_t profile; - const char **names; - char ***ret_values; -{ - prf_file_t file; - errcode_t retval; - struct profile_node *section; - void *state; - char *value; - struct string_list values; - char *secname; - - if (profile == 0) - return PROF_NO_PROFILE; - - if (names == 0 || names[0] == 0) - return PROF_BAD_NAMESET; - - init_list(&values); - - file = profile->first_file; - retval = profile_update_file(file); - if (retval) - goto cleanup; - - section = file->root; - - state = 0; - retval = profile_find_node_subsection(section, *names, &state, &secname, §ion); - - do { - retval = profile_find_node_name(section, &state, &value); - if (retval) - goto cleanup; - add_to_list(&values, value); - } while (state); - - *ret_values = values.list; - return 0; -cleanup: - free_list(&values); - return retval; -} - -/* - * XXX this version only works to get values from the first file. - */ -static errcode_t profile_get_value(profile, names, ret_value) - profile_t profile; - const char **names; - char **ret_value; -{ - prf_file_t file; - errcode_t retval; - struct profile_node *section; - void *state; - char *value; - const char **cpp; - - if (names == 0 || names[0] == 0 || names[1] == 0) - return PROF_BAD_NAMESET; - - file = profile->first_file; - retval = profile_update_file(file); - if (retval) - goto cleanup; - - section = file->root; - - for (cpp = names; cpp[1]; cpp++) { - state = 0; - retval = profile_find_node_subsection(section, *cpp, - &state, 0, §ion); - if (retval) - goto cleanup; - } - - state = 0; - retval = profile_find_node_relation(section, *cpp, &state, 0, &value); - if (retval) - goto cleanup; - - *ret_value = value; - return 0; -cleanup: - return retval; -} - -errcode_t profile_get_string(profile, name, subname, subsubname, - def_val, ret_string) - profile_t profile; - const char *name, *subname, *subsubname; - const char *def_val; - char **ret_string; -{ - const char *value; - errcode_t retval; - const char *names[4]; - - if (profile) { - names[0] = name; - names[1] = subname; - names[2] = subsubname; - names[3] = 0; - retval = profile_get_value(profile, names, &value); - if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) - value = def_val; - else if (retval) - return retval; - } else - value = def_val; - - if (value) { - *ret_string = malloc(strlen(value)+1); - if (*ret_string == 0) - return ENOMEM; - strcpy(*ret_string, value); - } else - *ret_string = 0; - return 0; -} - -errcode_t profile_get_integer(profile, name, subname, subsubname, - def_val, ret_int) - profile_t profile; - const char *name, *subname, *subsubname; - int def_val; - int *ret_int; -{ - char *value; - errcode_t retval; - const char *names[4]; - - if (profile == 0) { - *ret_int = def_val; - return 0; - } - - names[0] = name; - names[1] = subname; - names[2] = subsubname; - names[3] = 0; - retval = profile_get_value(profile, names, &value); - if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) { - *ret_int = def_val; - return 0; - } else if (retval) - return retval; - - *ret_int = atoi(value); - return 0; -} - errcode_t profile_ser_size(unused, profile, sizep) const char *unused; profile_t profile; @@ -407,14 +139,6 @@ errcode_t profile_ser_size(unused, profile, sizep) size_t required; prf_file_t pfp; - /* - * ARGH - We want to avoid having to include k5-int.h. We ASSuME that - * krb5_int32 is 4 bytes in length. - * - * krb5_int32 for header - * krb5_int32 for number of files. - * krb5_int32 for trailer - */ required = 3*sizeof(prof_int32); for (pfp = profile->first_file; pfp; pfp = pfp->next) { required += sizeof(prof_int32); @@ -502,63 +226,70 @@ static int unpack_int32(intp, bufpp, remainp) } errcode_t profile_ser_internalize(unused, profilep, bufpp, remainp) - const char *unused; - profile_t *profilep; - unsigned char **bufpp; - size_t *remainp; + const char *unused; + profile_t *profilep; + unsigned char **bufpp; + size_t *remainp; { - errcode_t retval; - unsigned char *bp; - size_t remain; - int i; - prof_int32 fcount, tmp; - char **flist; - - bp = *bufpp; - remain = *remainp; - retval = EINVAL; - - if (remain >= 12) - (void) unpack_int32(&tmp, &bp, &remain); - else - tmp = 0; - if (tmp == PROF_MAGIC_PROFILE) { + errcode_t retval; + unsigned char *bp; + size_t remain; + int i; + prof_int32 fcount, tmp; + char **flist = 0; + + bp = *bufpp; + remain = *remainp; + + if (remain >= 12) + (void) unpack_int32(&tmp, &bp, &remain); + else + tmp = 0; + + if (tmp != PROF_MAGIC_PROFILE) { + retval = EINVAL; + goto cleanup; + } + (void) unpack_int32(&fcount, &bp, &remain); retval = ENOMEM; - if (!fcount || - (flist = (char **) malloc(sizeof(char *) * (fcount + 1)))) { - memset(flist, 0, sizeof(char *) * (fcount+1)); - for (i=0; i<fcount; i++) { + + flist = (char **) malloc(sizeof(char *) * (fcount + 1)); + if (!flist) + goto cleanup; + + memset(flist, 0, sizeof(char *) * (fcount+1)); + for (i=0; i<fcount; i++) { if (!unpack_int32(&tmp, &bp, &remain)) { - if ((flist[i] = (char *) malloc((size_t) (tmp+1)))) { + flist[i] = (char *) malloc((size_t) (tmp+1)); + if (!flist[i]) + goto cleanup; memcpy(flist[i], bp, (size_t) tmp); flist[i][tmp] = '\0'; bp += tmp; remain -= (size_t) tmp; - } - else - break; } - else - break; - } - if ((i == fcount) && - !unpack_int32(&tmp, &bp, &remain) && - (tmp == PROF_MAGIC_PROFILE)) - retval = profile_init((const char **)flist, profilep); + } - if (!retval) { - *bufpp = bp; - *remainp = remain; - } + if (unpack_int32(&tmp, &bp, &remain) || + (tmp != PROF_MAGIC_PROFILE)) { + retval = EINVAL; + goto cleanup; + } - for (i=0; i<fcount; i++) { - if (flist[i]) - free(flist[i]); - } - free(flist); + if ((retval = profile_init((const char **)flist, profilep))) + goto cleanup; + + *bufpp = bp; + *remainp = remain; + +cleanup: + if (flist) { + for (i=0; i<fcount; i++) { + if (flist[i]) + free(flist[i]); + } + free(flist); } - } - return(retval); + return(retval); } - |
