krb5 commit: Add support for directories in profile paths
Greg Hudson
ghudson at mit.edu
Wed Jul 15 16:25:58 EDT 2015
https://github.com/krb5/krb5/commit/13bfcda8de68c6347d0ce15f5dcdca25f782b6b3
commit 13bfcda8de68c6347d0ce15f5dcdca25f782b6b3
Author: Roland Mainz <rmainz at redhat.com>
Date: Tue Oct 21 12:06:42 2014 -0400
Add support for directories in profile paths
If a profile path component is a directory, process files in the
directory as we would for an "includedir" directive.
[ghudson at mit.edu: don't change default profile path; simplify
profile_process_directory using prior commit; only check stat bits,
not final character of pathname; misc style changes; commit message]
ticket: 8030 (new)
src/util/profile/prof_file.c | 29 +++++++++++++++++++----------
src/util/profile/prof_int.h | 3 +++
src/util/profile/prof_parse.c | 19 +++++++++++++++++++
3 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c
index 5611233..08c0dd0 100644
--- a/src/util/profile/prof_file.c
+++ b/src/util/profile/prof_file.c
@@ -307,6 +307,7 @@ errcode_t profile_update_file_data_locked(prf_data_t data, char **ret_modspec)
time_t now;
#endif
FILE *f;
+ int isdir = 0;
#ifdef HAVE_STAT
now = time(0);
@@ -345,19 +346,27 @@ errcode_t profile_update_file_data_locked(prf_data_t data, char **ret_modspec)
return 0;
}
#endif
- errno = 0;
- f = fopen(data->filespec, "r");
- if (f == NULL) {
- retval = errno;
- if (retval == 0)
- retval = ENOENT;
- return retval;
+
+#ifdef HAVE_STAT
+ isdir = S_ISDIR(st.st_mode);
+#endif
+ if (!isdir) {
+ errno = 0;
+ f = fopen(data->filespec, "r");
+ if (f == NULL)
+ return (errno != 0) ? errno : ENOENT;
+ set_cloexec_file(f);
}
- set_cloexec_file(f);
+
data->upd_serial++;
data->flags &= PROFILE_FILE_SHARED; /* FIXME same as '=' operator */
- retval = profile_parse_file(f, &data->root, ret_modspec);
- fclose(f);
+
+ if (isdir) {
+ retval = profile_process_directory(data->filespec, &data->root);
+ } else {
+ retval = profile_parse_file(f, &data->root, ret_modspec);
+ (void)fclose(f);
+ }
if (retval) {
return retval;
}
diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h
index 38ea59a..73f7fad 100644
--- a/src/util/profile/prof_int.h
+++ b/src/util/profile/prof_int.h
@@ -123,6 +123,9 @@ struct _profile_t {
errcode_t profile_parse_file
(FILE *f, struct profile_node **root, char **ret_modspec);
+errcode_t profile_process_directory
+ (const char *dirname, struct profile_node **root);
+
errcode_t profile_write_tree_file
(struct profile_node *root, FILE *dstfile);
diff --git a/src/util/profile/prof_parse.c b/src/util/profile/prof_parse.c
index 07605be..1c2a270 100644
--- a/src/util/profile/prof_parse.c
+++ b/src/util/profile/prof_parse.c
@@ -451,6 +451,25 @@ errcode_t profile_parse_file(FILE *f, struct profile_node **root,
return 0;
}
+errcode_t profile_process_directory(const char *dirname,
+ struct profile_node **root)
+{
+ errcode_t retval;
+ struct profile_node *node;
+
+ *root = NULL;
+ retval = profile_create_node("(root)", 0, &node);
+ if (retval)
+ return retval;
+ retval = parse_include_dir(dirname, node);
+ if (retval) {
+ profile_free_node(node);
+ return retval;
+ }
+ *root = node;
+ return 0;
+}
+
/*
* Return TRUE if the string begins or ends with whitespace
*/
More information about the cvs-krb5
mailing list