summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2002-12-07 03:37:24 +0000
committerKen Raeburn <raeburn@mit.edu>2002-12-07 03:37:24 +0000
commit34da169bae1a1ae416c73a6318298ffc30c65ebb (patch)
treefa2517d67cf509eb449a88bba5f7193cd16d7015 /src
parentaae8df84aade9b538efc6ac2db392b884cec9d1a (diff)
downloadkrb5-34da169bae1a1ae416c73a6318298ffc30c65ebb.tar.gz
krb5-34da169bae1a1ae416c73a6318298ffc30c65ebb.tar.xz
krb5-34da169bae1a1ae416c73a6318298ffc30c65ebb.zip
Checkpoint first step of merge.
Moved per-file data into a separate object from the profile handle. Dropped some old MacOS 9 code. * prof_int.h: Include Mac OS X versions of header files if appropriate. Only include prof_err.h if profile.h doesn't define ERROR_TABLE_BASE_prof. (struct _prf_data_t): Move most of contents of _prf_file_t here. Add reference count. (prf_data_t): New typedef. (struct _prf_file_t): Include an array of one _prf_data_t structure. * prof_file.c (profile_open_file): Fill in "data" field. Drop some old Mac specific code. (profile_flush_file_data): Renamed from profile_flush_file, now takes prf_data_t argument. (profile_flush_file_data): Likewise. (profile_free_file): Now calls profile_free_file_data. (profile_free_file_data): New function, with most of old profile_free_file code. * prof_init.c (profile_init_path): Removed old Mac version. (profile_ser_size, profile_ser_externalize): Get file data from new "data" field. * prof_set.c (rw_setup, profile_update_relation, profile_clear_relation, profile_rename_section, profile_add_relation): Likewise. * prof_tree.c (profile_node_iterator): Likewise. * test_profile.c (do_batchmode): Likewise. * prof_int.h (profile_flush_file): Now a macro. * prof_err.et (PROF_MAGIC_FILE_DATA): New error code value. ticket: 1237 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15037 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/profile/ChangeLog27
-rw-r--r--src/util/profile/prof_err.et3
-rw-r--r--src/util/profile/prof_file.c118
-rw-r--r--src/util/profile/prof_init.c25
-rw-r--r--src/util/profile/prof_int.h40
-rw-r--r--src/util/profile/prof_set.c20
-rw-r--r--src/util/profile/prof_tree.c6
-rw-r--r--src/util/profile/test_profile.c4
8 files changed, 142 insertions, 101 deletions
diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog
index 82463e310..cf7c5360f 100644
--- a/src/util/profile/ChangeLog
+++ b/src/util/profile/ChangeLog
@@ -1,5 +1,32 @@
2002-12-06 Ken Raeburn <raeburn@mit.edu>
+ * prof_int.h: Include Mac OS X versions of header files if
+ appropriate. Only include prof_err.h if profile.h doesn't define
+ ERROR_TABLE_BASE_prof.
+ (struct _prf_data_t): Move most of contents of _prf_file_t here.
+ Add reference count.
+ (prf_data_t): New typedef.
+ (struct _prf_file_t): Include an array of one _prf_data_t
+ structure.
+ * prof_file.c (profile_open_file): Fill in "data" field. Drop
+ some old Mac specific code.
+ (profile_flush_file_data): Renamed from profile_flush_file, now
+ takes prf_data_t argument.
+ (profile_flush_file_data): Likewise.
+ (profile_free_file): Now calls profile_free_file_data.
+ (profile_free_file_data): New function, with most of old
+ profile_free_file code.
+ * prof_init.c (profile_init_path): Removed old Mac version.
+ (profile_ser_size, profile_ser_externalize): Get file data from
+ new "data" field.
+ * prof_set.c (rw_setup, profile_update_relation,
+ profile_clear_relation, profile_rename_section,
+ profile_add_relation): Likewise.
+ * prof_tree.c (profile_node_iterator): Likewise.
+ * test_profile.c (do_batchmode): Likewise.
+ * prof_int.h (profile_flush_file): Now a macro.
+ * prof_err.et (PROF_MAGIC_FILE_DATA): New error code value.
+
* prof_get.c (conf_yes, conf_no): Entries now point to const.
(profile_parse_boolean): Updated type of 'p' correspondingly.
diff --git a/src/util/profile/prof_err.et b/src/util/profile/prof_err.et
index dc248f417..af7801ee0 100644
--- a/src/util/profile/prof_err.et
+++ b/src/util/profile/prof_err.et
@@ -60,4 +60,7 @@ error_code PROF_EXISTS, "Section already exists"
error_code PROF_BAD_BOOLEAN, "Invalid boolean value"
error_code PROF_BAD_INTEGER, "Invalid integer value"
+error_code PROF_MAGIC_FILE_DATA, "Bad magic value in profile_file_data_t"
+
+
end
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c
index 52fc5bbf7..4ffe7e138 100644
--- a/src/util/profile/prof_file.c
+++ b/src/util/profile/prof_file.c
@@ -74,34 +74,33 @@ errcode_t profile_open_file(filespec, ret_prof)
errcode_t retval;
char *home_env = 0;
unsigned int len;
+ prf_data_t data;
prf = malloc(sizeof(struct _prf_file_t));
if (!prf)
return ENOMEM;
memset(prf, 0, sizeof(struct _prf_file_t));
-
-#ifndef macintosh
+ data = prf->data;
+
len = strlen(filespec)+1;
if (filespec[0] == '~' && filespec[1] == '/') {
home_env = getenv("HOME");
if (home_env)
len += strlen(home_env);
}
- prf->filespec = malloc(len);
- if (!prf->filespec) {
+ data->filespec = malloc(len);
+ if (!data->filespec) {
free(prf);
return ENOMEM;
}
if (home_env) {
- strcpy(prf->filespec, home_env);
- strcat(prf->filespec, filespec+1);
+ strcpy(data->filespec, home_env);
+ strcat(data->filespec, filespec+1);
} else
- strcpy(prf->filespec, filespec);
- prf->magic = PROF_MAGIC_FILE;
-#else
- prf->filespec = filespec;
+ strcpy(data->filespec, filespec);
prf->magic = PROF_MAGIC_FILE;
-#endif
+ data->magic = PROF_MAGIC_FILE_DATA;
+ data->refcount = 1;
retval = profile_update_file(prf);
if (retval) {
@@ -113,8 +112,7 @@ errcode_t profile_open_file(filespec, ret_prof)
return 0;
}
-errcode_t profile_update_file(prf)
- prf_file_t prf;
+errcode_t profile_update_file_data(prf_data_t data)
{
errcode_t retval;
#ifdef HAVE_STAT
@@ -123,17 +121,17 @@ errcode_t profile_update_file(prf)
FILE *f;
#ifdef HAVE_STAT
- if (stat(prf->filespec, &st))
+ if (stat(data->filespec, &st))
return errno;
- if (st.st_mtime == prf->timestamp)
+ if (st.st_mtime == data->timestamp)
return 0;
- if (prf->root) {
- profile_free_node(prf->root);
- prf->root = 0;
+ if (data->root) {
+ profile_free_node(data->root);
+ data->root = 0;
}
- if (prf->comment) {
- free(prf->comment);
- prf->comment = 0;
+ if (data->comment) {
+ free(data->comment);
+ data->comment = 0;
}
#else
/*
@@ -141,14 +139,14 @@ errcode_t profile_update_file(prf)
* memory image is correct. That is, we won't reread the
* profile file if it changes.
*/
- if (prf->root)
+ if (data->root)
return 0;
#endif
errno = 0;
#ifdef PROFILE_USES_PATHS
- f = fopen(prf->filespec, "r");
+ f = fopen(data->filespec, "r");
#else
- f = FSp_fopen (&prf->filespec, "r");
+ f = FSp_fopen (&data->filespec, "r");
#endif
if (f == NULL) {
retval = errno;
@@ -156,16 +154,16 @@ errcode_t profile_update_file(prf)
retval = ENOENT;
return retval;
}
- prf->upd_serial++;
- prf->flags = 0;
- if (rw_access(prf->filespec))
- prf->flags |= PROFILE_FILE_RW;
- retval = profile_parse_file(f, &prf->root);
+ data->upd_serial++;
+ data->flags = 0;
+ if (rw_access(data->filespec))
+ data->flags |= PROFILE_FILE_RW;
+ retval = profile_parse_file(f, &data->root);
fclose(f);
if (retval)
return retval;
#ifdef HAVE_STAT
- prf->timestamp = st.st_mtime;
+ data->timestamp = st.st_mtime;
#endif
return 0;
}
@@ -188,33 +186,33 @@ OSErr GetMacOSTempFilespec (
#endif
-errcode_t profile_flush_file(prf)
- prf_file_t prf;
+errcode_t profile_flush_file_data(data)
+ prf_data_t data;
{
FILE *f;
profile_filespec_t new_file;
profile_filespec_t old_file;
errcode_t retval = 0;
- if (!prf || prf->magic != PROF_MAGIC_FILE)
- return PROF_MAGIC_FILE;
+ if (!data || data->magic != PROF_MAGIC_FILE_DATA)
+ return PROF_MAGIC_FILE_DATA;
- if ((prf->flags & PROFILE_FILE_DIRTY) == 0)
+ if ((data->flags & PROFILE_FILE_DIRTY) == 0)
return 0;
retval = ENOMEM;
#ifdef PROFILE_USES_PATHS
new_file = old_file = 0;
- new_file = malloc(strlen(prf->filespec) + 5);
+ new_file = malloc(strlen(data->filespec) + 5);
if (!new_file)
goto errout;
- old_file = malloc(strlen(prf->filespec) + 5);
+ old_file = malloc(strlen(data->filespec) + 5);
if (!old_file)
goto errout;
- sprintf(new_file, "%s.$$$", prf->filespec);
- sprintf(old_file, "%s.bak", prf->filespec);
+ sprintf(new_file, "%s.$$$", data->filespec);
+ sprintf(old_file, "%s.bak", data->filespec);
errno = 0;
@@ -222,7 +220,7 @@ errcode_t profile_flush_file(prf)
#else
/* On MacOS, we do this by writing to a new file and then atomically
swapping the files with a file system call */
- GetMacOSTempFilespec (&prf->filespec, &new_file);
+ GetMacOSTempFilespec (&data->filespec, &new_file);
f = FSp_fopen (&new_file, "w");
#endif
@@ -233,7 +231,7 @@ errcode_t profile_flush_file(prf)
goto errout;
}
- profile_write_tree_file(prf->root, f);
+ profile_write_tree_file(data->root, f);
if (fclose(f) != 0) {
retval = errno;
goto errout;
@@ -241,18 +239,18 @@ errcode_t profile_flush_file(prf)
#ifdef PROFILE_USES_PATHS
unlink(old_file);
- if (rename(prf->filespec, old_file)) {
+ if (rename(data->filespec, old_file)) {
retval = errno;
goto errout;
}
- if (rename(new_file, prf->filespec)) {
+ if (rename(new_file, data->filespec)) {
retval = errno;
- rename(old_file, prf->filespec); /* back out... */
+ rename(old_file, data->filespec); /* back out... */
goto errout;
}
#else
{
- OSErr err = FSpExchangeFiles (&prf->filespec, &new_file);
+ OSErr err = FSpExchangeFiles (&data->filespec, &new_file);
if (err != noErr) {
retval = ENFILE;
goto errout;
@@ -262,9 +260,9 @@ errcode_t profile_flush_file(prf)
#endif
- prf->flags = 0;
- if (rw_access(prf->filespec))
- prf->flags |= PROFILE_FILE_RW;
+ data->flags = 0;
+ if (rw_access(data->filespec))
+ data->flags |= PROFILE_FILE_RW;
retval = 0;
errout:
@@ -281,18 +279,22 @@ errout:
void profile_free_file(prf)
prf_file_t prf;
{
-#ifdef PROFILE_USES_PATHS
- if (prf->filespec)
- free(prf->filespec);
-#endif
- if (prf->root)
- profile_free_node(prf->root);
- if (prf->comment)
- free(prf->comment);
- prf->magic = 0;
+ profile_free_file_data(prf->data);
free(prf);
+}
- return;
+void profile_free_file_data(data)
+ prf_data_t data;
+{
+#ifdef PROFILE_USES_PATHS
+ if (data->filespec)
+ free(data->filespec);
+#endif
+ if (data->root)
+ profile_free_node(data->root);
+ if (data->comment)
+ free(data->comment);
+ data->magic = 0;
}
errcode_t profile_close_file(prf)
diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c
index f94833a7b..46ebf2dbd 100644
--- a/src/util/profile/prof_init.c
+++ b/src/util/profile/prof_init.c
@@ -73,10 +73,6 @@ profile_init(files, ret_profile)
return 0;
}
-#ifndef macintosh
-/*
- * On MacOS, profile_init_path is the same as profile_init
- */
errcode_t KRB5_CALLCONV
profile_init_path(filepath, ret_profile)
const_profile_filespec_list_t filepath;
@@ -128,15 +124,6 @@ profile_init_path(filepath, ret_profile)
return retval;
}
-#else
-errcode_t KRB5_CALLCONV
-profile_init_path(filelist, ret_profile)
- profile_filespec_list_t filelist;
- profile_t *ret_profile;
-{
- return profile_init (filelist, ret_profile);
-}
-#endif
errcode_t KRB5_CALLCONV
profile_flush(profile)
@@ -200,8 +187,8 @@ errcode_t profile_ser_size(unused, profile, sizep)
for (pfp = profile->first_file; pfp; pfp = pfp->next) {
required += sizeof(prof_int32);
#ifdef PROFILE_USES_PATHS
- if (pfp->filespec)
- required += strlen(pfp->filespec);
+ if (pfp->data->filespec)
+ required += strlen(pfp->data->filespec);
#else
required += sizeof (profile_filespec_t);
#endif
@@ -251,18 +238,18 @@ errcode_t profile_ser_externalize(unused, profile, bufpp, remainp)
pack_int32(fcount, &bp, &remain);
for (pfp = profile->first_file; pfp; pfp = pfp->next) {
#ifdef PROFILE_USES_PATHS
- slen = (pfp->filespec) ?
- (prof_int32) strlen(pfp->filespec) : 0;
+ slen = (pfp->data->filespec) ?
+ (prof_int32) strlen(pfp->data->filespec) : 0;
pack_int32(slen, &bp, &remain);
if (slen) {
- memcpy(bp, pfp->filespec, (size_t) slen);
+ memcpy(bp, pfp->data->filespec, (size_t) slen);
bp += slen;
remain -= (size_t) slen;
}
#else
slen = sizeof (FSSpec);
pack_int32(slen, &bp, &remain);
- memcpy (bp, &(pfp->filespec), (size_t) slen);
+ memcpy (bp, &(pfp->data->filespec), (size_t) slen);
bp += slen;
remain -= (size_t) slen;
#endif
diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h
index 3f120a7fa..00fd2847b 100644
--- a/src/util/profile/prof_int.h
+++ b/src/util/profile/prof_int.h
@@ -3,9 +3,19 @@
*/
#include <time.h>
+#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
+#include <TargetConditionals.h>
+#include <Kerberos/com_err.h>
+#include <Kerberos/FullPOSIXPath.h>
+#include <CoreServices/CoreServices.h>
+#else
#include "com_err.h"
-#include "prof_err.h"
+#endif
+
#include "profile.h"
+#ifndef ERROR_TABLE_BASE_prof
+#include "prof_err.h"
+#endif
#if defined(_WIN32)
#define SIZEOF_INT 4
@@ -24,14 +34,23 @@ typedef long prf_magic_t;
* This is the structure which stores the profile information for a
* particular configuration file.
*/
-struct _prf_file_t {
+struct _prf_data_t {
prf_magic_t magic;
char *comment;
profile_filespec_t filespec;
struct profile_node *root;
- time_t timestamp;
- int flags;
- int upd_serial;
+ time_t timestamp; /* time tree was last updated from file */
+ int flags; /* r/w, dirty */
+ int upd_serial; /* incremented when data changes */
+ int refcount; /* prf_file_t references */
+ struct _prf_data_t *next;
+};
+
+typedef struct _prf_data_t *prf_data_t;
+
+struct _prf_file_t {
+ prf_magic_t magic;
+ struct _prf_data_t data[1];
struct _prf_file_t *next;
};
@@ -162,14 +181,17 @@ errcode_t profile_rename_node
errcode_t profile_open_file
(const_profile_filespec_t file, prf_file_t *ret_prof);
-errcode_t profile_update_file
- (prf_file_t profile);
+#define profile_update_file(P) profile_update_file_data((P)->data)
+errcode_t profile_update_file_data
+ (prf_data_t profile);
-errcode_t profile_flush_file
- (prf_file_t profile);
+#define profile_flush_file(P) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data((P)->data) : PROF_MAGIC_FILE)
+errcode_t profile_flush_file_data
+ (prf_data_t data);
void profile_free_file
(prf_file_t profile);
+void profile_free_file_data (prf_data_t data);
errcode_t profile_close_file
(prf_file_t profile);
diff --git a/src/util/profile/prof_set.c b/src/util/profile/prof_set.c
index 1f2b16d81..4c6ccb29d 100644
--- a/src/util/profile/prof_set.c
+++ b/src/util/profile/prof_set.c
@@ -33,11 +33,11 @@ static errcode_t rw_setup(profile)
return PROF_MAGIC_PROFILE;
file = profile->first_file;
- if (!(file->flags & PROFILE_FILE_RW))
+ if (!(file->data->flags & PROFILE_FILE_RW))
return PROF_READ_ONLY;
/* Don't update the file if we've already made modifications */
- if (file->flags & PROFILE_FILE_DIRTY)
+ if (file->data->flags & PROFILE_FILE_DIRTY)
return 0;
retval = profile_update_file(file);
@@ -73,7 +73,7 @@ profile_update_relation(profile, names, old_value, new_value)
if (!old_value || !*old_value)
return PROF_EINVAL;
- section = profile->first_file->root;
+ section = profile->first_file->data->root;
for (cpp = names; cpp[1]; cpp++) {
state = 0;
retval = profile_find_node(section, *cpp, 0, 1,
@@ -94,7 +94,7 @@ profile_update_relation(profile, names, old_value, new_value)
if (retval)
return retval;
- profile->first_file->flags |= PROFILE_FILE_DIRTY;
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
return 0;
}
@@ -121,7 +121,7 @@ profile_clear_relation(profile, names)
if (names == 0 || names[0] == 0 || names[1] == 0)
return PROF_BAD_NAMESET;
- section = profile->first_file->root;
+ section = profile->first_file->data->root;
for (cpp = names; cpp[1]; cpp++) {
state = 0;
retval = profile_find_node(section, *cpp, 0, 1,
@@ -140,7 +140,7 @@ profile_clear_relation(profile, names)
return retval;
} while (state);
- profile->first_file->flags |= PROFILE_FILE_DIRTY;
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
return 0;
}
@@ -169,7 +169,7 @@ profile_rename_section(profile, names, new_name)
if (names == 0 || names[0] == 0 || names[1] == 0)
return PROF_BAD_NAMESET;
- section = profile->first_file->root;
+ section = profile->first_file->data->root;
for (cpp = names; cpp[1]; cpp++) {
state = 0;
retval = profile_find_node(section, *cpp, 0, 1,
@@ -190,7 +190,7 @@ profile_rename_section(profile, names, new_name)
if (retval)
return retval;
- profile->first_file->flags |= PROFILE_FILE_DIRTY;
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
return 0;
}
@@ -222,7 +222,7 @@ profile_add_relation(profile, names, new_value)
if (names == 0 || names[0] == 0 || names[1] == 0)
return PROF_BAD_NAMESET;
- section = profile->first_file->root;
+ section = profile->first_file->data->root;
for (cpp = names; cpp[1]; cpp++) {
state = 0;
retval = profile_find_node(section, *cpp, 0, 1,
@@ -245,7 +245,7 @@ profile_add_relation(profile, names, new_value)
if (retval)
return retval;
- profile->first_file->flags |= PROFILE_FILE_DIRTY;
+ profile->first_file->data->flags |= PROFILE_FILE_DIRTY;
return 0;
}
diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c
index be76db328..41e71ffb8 100644
--- a/src/util/profile/prof_tree.c
+++ b/src/util/profile/prof_tree.c
@@ -481,7 +481,7 @@ errcode_t profile_node_iterator(iter_p, ret_node, ret_name, ret_value)
* If the file has changed, then the node pointer is invalid,
* so we'll have search the file again looking for it.
*/
- if (iter->node && (iter->file->upd_serial != iter->file_serial)) {
+ if (iter->node && (iter->file->data->upd_serial != iter->file_serial)) {
iter->flags &= ~PROFILE_ITER_FINAL_SEEN;
skip_num = iter->num;
iter->node = 0;
@@ -510,12 +510,12 @@ get_new_file:
return retval;
}
}
- iter->file_serial = iter->file->upd_serial;
+ iter->file_serial = iter->file->data->upd_serial;
/*
* Find the section to list if we are a LIST_SECTION,
* or find the containing section if not.
*/
- section = iter->file->root;
+ section = iter->file->data->root;
for (cpp = iter->names; cpp[iter->done_idx]; cpp++) {
for (p=section->first_child; p; p = p->next)
if (!strcmp(p->name, *cpp) && !p->value)
diff --git a/src/util/profile/test_profile.c b/src/util/profile/test_profile.c
index df4867d74..8a97dd2f7 100644
--- a/src/util/profile/test_profile.c
+++ b/src/util/profile/test_profile.c
@@ -61,7 +61,7 @@ static void do_batchmode(profile)
print_status = PRINT_VALUES;
} else if (!strcmp(cmd, "dump")) {
retval = profile_write_tree_file
- (profile->first_file->root, stdout);
+ (profile->first_file->data->root, stdout);
} else if (!strcmp(cmd, "clear")) {
retval = profile_clear_relation(profile, names);
} else if (!strcmp(cmd, "update")) {
@@ -69,7 +69,7 @@ static void do_batchmode(profile)
*names, *(names+1));
} else if (!strcmp(cmd, "verify")) {
retval = profile_verify_node
- (profile->first_file->root);
+ (profile->first_file->data->root);
} else if (!strcmp(cmd, "rename_section")) {
retval = profile_rename_section(profile, names+1,
*names);