https://fedorahosted.org/sssd/ticket/1792 https://fedorahosted.org/sssd/ticket/1793
-- Thank you, Dmitri Pal Sr. Engineering Manager for IdM portfolio Red Hat Inc. ------------------------------- Looking to carve out IT costs? www.redhat.com/carveoutcosts/
From dcef150b5edaf5f854155e112bdc7e495cf4786d Mon Sep 17 00:00:00 2001 From: Dmitri Pal <[email protected]> Date: Sat, 26 Jan 2013 16:47:56 -0500 Subject: [PATCH 1/2] [INI] Check is the stats we collected This patch corrects a problem related to stats being accessed and evaluated without being initialized. --- ini/ini_config_priv.h | 2 ++ ini/ini_fileobj.c | 13 +++++++++++++ ini/ini_parse_ut.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-) diff --git a/ini/ini_config_priv.h b/ini/ini_config_priv.h index 31cee84cf4815dab2378c06af1878cb82c913585..89ad8a9d58a2b38232eb5285b15bc2bf443c5103 100644 --- a/ini/ini_config_priv.h +++ b/ini/ini_config_priv.h @@ -69,6 +69,8 @@ struct ini_cfgfile { /**********************/ /* File stats */ struct stat file_stats; + /* Were stats read ? */ + int stats_read; }; /* Parsing error */ diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c index 677383c9de12263cbf51fbace11ff7c878a175fc..7d2011a5edfc51359b2f569ad5fe2bbbc9009ea8 100644 --- a/ini/ini_fileobj.c +++ b/ini/ini_fileobj.c @@ -76,6 +76,8 @@ static int common_file_init(struct ini_cfgfile *file_ctx) return error; } + file_ctx->stats_read = 0; + /* Collect stats */ if (file_ctx->metadata_flags & INI_META_STATS) { errno = 0; @@ -85,6 +87,7 @@ static int common_file_init(struct ini_cfgfile *file_ctx) TRACE_ERROR_NUMBER("Failed to get file stats.", error); return error; } + file_ctx->stats_read = 1; } else memset(&(file_ctx->file_stats), 0, sizeof(struct stat)); @@ -231,7 +234,11 @@ int ini_config_access_check(struct ini_cfgfile *file_ctx, if ((file_ctx == NULL) || (flags == 0)) { TRACE_ERROR_NUMBER("Invalid parameter.", EINVAL); return EINVAL; + } + if (file_ctx->stats_read == 0) { + TRACE_ERROR_NUMBER("Stats were not collected.", EINVAL); + return EINVAL; } /* Check mode */ @@ -304,6 +311,12 @@ int ini_config_changed(struct ini_cfgfile *file_ctx1, return EINVAL; } + if ((file_ctx1->stats_read == 0) || + (file_ctx2->stats_read == 0)) { + TRACE_ERROR_NUMBER("Stats were not collected.", EINVAL); + return EINVAL; + } + *changed = 0; /* Unfortunately the time is not granular enough diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c index 002fdd599d2a71165e3bfd5555062538abef8653..c5e91663dbfa1f492539c51622c081c057b84b1b 100644 --- a/ini/ini_parse_ut.c +++ b/ini/ini_parse_ut.c @@ -1085,6 +1085,36 @@ int startup_test(void) return error; } + /* Open config file not collecting stats */ + error = ini_config_file_open(outfile, + 0, + &file_ctx); + if (error) { + printf("Failed to open file %s for reading. Error %d.\n", + outfile, error); + return error; + } + + /* We will check just permissions here. */ + error = ini_config_access_check(file_ctx, + INI_ACCESS_CHECK_MODE, /* add uid & gui flags + * in real case + */ + 0, /* <- will be real uid in real case */ + 0, /* <- will be real gid in real case */ + 0440, /* Checking for r--r----- */ + 0); + /* This check is expected to fail since + * we did not collect stats + */ + ini_config_file_destroy(file_ctx); + + if (!error) { + printf("Expected error got success!\n"); + return EACCES; + } + + /* Open config file */ error = ini_config_file_open(outfile, INI_META_STATS, -- 1.7.1
From 777bdd3176b23981c8569bfabc208e6c000eb97e Mon Sep 17 00:00:00 2001 From: Dmitri Pal <[email protected]> Date: Sat, 26 Jan 2013 20:07:48 -0500 Subject: [PATCH 2/2] [INI] Expose collected stat data Added a new top level interface funtion and a unit test for it. --- ini/ini_configobj.h | 14 ++++++++++++++ ini/ini_fileobj.c | 14 ++++++++++++++ ini/ini_parse_ut.c | 17 +++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-) diff --git a/ini/ini_configobj.h b/ini/ini_configobj.h index 16f6499862ddb5f933baaedce75b6baac32c3eaf..ac85ba7e015c2912f550f54b199d74ddb2bf495f 100644 --- a/ini/ini_configobj.h +++ b/ini/ini_configobj.h @@ -587,6 +587,20 @@ void ini_config_print_errors(FILE *file, char **error_list); */ const char *ini_config_get_filename(struct ini_cfgfile *file_ctx); +/** + * @brief Get pointer to collected stat data + * + * Returns the pointer to the internal stat structure. + * If stat data was not collected when the file was open + * function would return NULL. + * + * @param[in] file_ctx Configuration file object. + * + * @return Pointer to the stat structure. + */ +const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx); + + /** * @brief Print file context diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c index 7d2011a5edfc51359b2f569ad5fe2bbbc9009ea8..7ac9dc6558900cb0429f524462b8a2ba0cb585a4 100644 --- a/ini/ini_fileobj.c +++ b/ini/ini_fileobj.c @@ -215,6 +215,20 @@ const char *ini_config_get_filename(struct ini_cfgfile *file_ctx) return ret; } +/* Get pointer to stat structure */ +const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx) +{ + const struct stat *ret; + TRACE_FLOW_ENTRY(); + + if (file_ctx->stats_read) ret = &(file_ctx->file_stats); + else ret = NULL; + + TRACE_FLOW_EXIT(); + return ret; +} + + /* Check access */ int ini_config_access_check(struct ini_cfgfile *file_ctx, uint32_t flags, diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c index c5e91663dbfa1f492539c51622c081c057b84b1b..32c59e7a3a36a5b719620ae42cf070154d4eb416 100644 --- a/ini/ini_parse_ut.c +++ b/ini/ini_parse_ut.c @@ -1057,6 +1057,7 @@ int startup_test(void) char command[PATH_MAX * 3]; char *srcdir = NULL; char *builddir; + const struct stat *file_stat; INIOUT(printf("<==== Startup test ====>\n")); @@ -1095,6 +1096,12 @@ int startup_test(void) return error; } + file_stat = ini_config_get_stat(file_ctx); + if (file_stat) { + printf("Expected NULL got not NULL!\n"); + return EINVAL; + } + /* We will check just permissions here. */ error = ini_config_access_check(file_ctx, INI_ACCESS_CHECK_MODE, /* add uid & gui flags @@ -1125,6 +1132,16 @@ int startup_test(void) return error; } + /* Get stats */ + file_stat = ini_config_get_stat(file_ctx); + if (!file_stat) { + printf("Expected not NULL got NULL!\n"); + return EINVAL; + } + + INIOUT(printf("File was modified at: %d seconds since Jan 1 1970.\n", + (int)(file_stat->st_mtime))); + /* We will check just permissions here. */ error = ini_config_access_check(file_ctx, INI_ACCESS_CHECK_MODE, /* add uid & gui flags -- 1.7.1
_______________________________________________ sssd-devel mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
