summaryrefslogtreecommitdiffstats
path: root/ini/ini_config.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-04-02 20:08:14 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-04-14 12:15:54 -0400
commitf9a7b9fa00fbc57bf86ec4381f78ae0d9c12354a (patch)
treefce33201159cf23b4fca68a2546e700c8796b6b3 /ini/ini_config.c
parent3941ba7fb37ddebf8406da2a53337a659c6cb505 (diff)
downloadding-libs2-f9a7b9fa00fbc57bf86ec4381f78ae0d9c12354a.tar.gz
ding-libs2-f9a7b9fa00fbc57bf86ec4381f78ae0d9c12354a.tar.xz
ding-libs2-f9a7b9fa00fbc57bf86ec4381f78ae0d9c12354a.zip
Acess control and config change checks
1) Fixed the issue that metadata was saved as numbers. Was supposed to be saved as strings. 2) Added two functions. One is to check permissions on the config file. Another to check if the file has changed and thus the cinfiguration needs to be reread. 3) Added unit test will sample code and comments how to use the functions. 4) Added doxygen description in the comments. 5) Fixed couple typos and ommisions here and there. [INI] Fixing crash detected on 64-bit system This patch corrects original code to be more on the safe side and check parameters before using. Instead of dereferencing metadata it is now passed as reference to the next level. It is not used there yet so no other new changes needed so far. [INI] Addressing review comments [INI] Addressing comments.
Diffstat (limited to 'ini/ini_config.c')
-rw-r--r--ini/ini_config.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/ini/ini_config.c b/ini/ini_config.c
index 66d2c03..1c8e4ae 100644
--- a/ini/ini_config.c
+++ b/ini/ini_config.c
@@ -87,6 +87,8 @@
#define MAX_VALUE PATH_MAX
#define BUFFER_SIZE MAX_KEY + MAX_VALUE + 3
+/* Beffer length used for int to string conversions */
+#define CONVERSION_BUFFER 80
/*============================================================*/
/* The following classes moved here from the public header
@@ -583,7 +585,7 @@ static int config_with_metadata(const char *application,
int error_level,
struct collection_item **error_list,
uint32_t metaflags,
- struct collection_item *metadata)
+ struct collection_item **metadata)
{
int error;
int created = 0;
@@ -667,8 +669,8 @@ int config_from_fd_with_metadata(const char *application,
int save_error = 0;
int fd = -1;
FILE *config_file = NULL;
- int can_free = 0;
char abs_name[PATH_MAX + 1];
+ char buff[CONVERSION_BUFFER];
TRACE_FLOW_STRING("config_from_fd_with_metadata", "Entry");
@@ -703,10 +705,12 @@ int config_from_fd_with_metadata(const char *application,
if (save_error) {
/* Record the result of the open file operation in metadata */
- error = col_add_int_property(*metadata,
+ snprintf(buff, CONVERSION_BUFFER, "%d", file_error);
+ error = col_add_str_property(*metadata,
INI_META_SEC_ERROR,
INI_META_KEY_READ_ERROR,
- file_error);
+ buff,
+ 0);
if (error) {
/* Something is really wrong if we failed here */
TRACE_ERROR_NUMBER("Failed to save file open error", error);
@@ -731,15 +735,17 @@ int config_from_fd_with_metadata(const char *application,
}
- /* Collect meta data before actually parsing the file */
- error = collect_metadata(metaflags,
- metadata,
- config_file,
- abs_name);
- if(error) {
- TRACE_ERROR_NUMBER("Failed to collect metadata", error);
- fclose(config_file);
- return error;
+ if (metadata) {
+ /* Collect meta data before actually parsing the file */
+ error = collect_metadata(metaflags,
+ metadata,
+ config_file,
+ abs_name);
+ if(error) {
+ TRACE_ERROR_NUMBER("Failed to collect metadata", error);
+ fclose(config_file);
+ return error;
+ }
}
if (!(metaflags & INI_META_ACTION_NOPARSE)) {
@@ -751,7 +757,7 @@ int config_from_fd_with_metadata(const char *application,
error_level,
error_list,
metaflags,
- *metadata);
+ metadata);
}
/* We opened the file we close it */
@@ -1529,7 +1535,7 @@ static unsigned long long get_ullong_config_value(struct collection_item *item,
char *endptr;
unsigned long long val = 0;
- TRACE_FLOW_STRING("get_long_config_value", "Entry");
+ TRACE_FLOW_STRING("get_ullong_config_value", "Entry");
/* Do we have the item ? */
if ((item == NULL) ||
@@ -1561,7 +1567,7 @@ static unsigned long long get_ullong_config_value(struct collection_item *item,
return def;
}
- TRACE_FLOW_NUMBER("get_long_config_value returning", (long)val);
+ TRACE_FLOW_NUMBER("get_ullong_config_value returning", (long)val);
return val;
}