summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2016-09-14 18:13:00 +0200
committerAndreas Schneider <asn@cryptomilk.org>2017-01-06 12:28:19 +0100
commit7eeb2edc5060b03efa7166017e5b2a36af5b7f75 (patch)
tree0c08572fd1fdd6c8e0ee9954fbc0d719565e3d78 /lib
parent235aa6754471122bd5791614953eeea6d86e2a5e (diff)
downloadsamba-7eeb2edc5060b03efa7166017e5b2a36af5b7f75.tar.gz
lib/util: add pm_process_with_flags to allow parsing ini files with empty values
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/params.c25
-rw-r--r--lib/util/samba_util.h6
-rw-r--r--lib/util/tini.c25
-rw-r--r--lib/util/tini.h1
-rw-r--r--lib/util/tiniparser.c1
5 files changed, 51 insertions, 7 deletions
diff --git a/lib/util/params.c b/lib/util/params.c
index 5ec4fd23dbb..c5c252613d3 100644
--- a/lib/util/params.c
+++ b/lib/util/params.c
@@ -96,7 +96,30 @@ bool pm_process(const char *filename,
return false;
}
- ret = tini_parse(f, sfunc, pfunc, private_data);
+ ret = tini_parse(f, false, sfunc, pfunc, private_data);
+
+ fclose(f);
+
+ return ret;
+}
+
+
+bool pm_process_with_flags(const char *filename,
+ bool allow_empty_values,
+ bool (*sfunc)(const char *section, void *private_data),
+ bool (*pfunc)(const char *name, const char *value,
+ void *private_data),
+ void *private_data)
+{
+ FILE *f;
+ bool ret;
+
+ f = fopen(filename, "r");
+ if (f == NULL) {
+ return false;
+ }
+
+ ret = tini_parse(f, allow_empty_values, sfunc, pfunc, private_data);
fclose(f);
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 897e0f5923d..c19e246bcd4 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -609,6 +609,12 @@ bool pm_process( const char *fileName,
bool (*sfunc)(const char *, void *),
bool (*pfunc)(const char *, const char *, void *),
void *userdata);
+bool pm_process_with_flags(const char *filename,
+ bool allow_empty_values,
+ bool (*sfunc)(const char *section, void *private_data),
+ bool (*pfunc)(const char *name, const char *value,
+ void *private_data),
+ void *private_data);
void print_asc(int level, const uint8_t *buf,int len);
void print_asc_cb(const uint8_t *buf, int len,
diff --git a/lib/util/tini.c b/lib/util/tini.c
index 3bfc2d6511f..36d7a4522ce 100644
--- a/lib/util/tini.c
+++ b/lib/util/tini.c
@@ -227,19 +227,27 @@ static char *trim_one_space(char *buf)
}
static bool parse_param(char *buf,
+ bool allow_empty_value,
bool (*pfunc)(const char *name, const char *value,
void *private_data),
void *private_data)
{
char *equals;
- char *name, *value;
+ char *name;
+ const char *value;
size_t len;
+ bool no_value = false;
equals = strchr(buf, '=');
- if (equals == NULL) {
- return true;
+ if (equals != NULL) {
+ *equals = '\0';
+ } else {
+ if (allow_empty_value) {
+ no_value = true;
+ } else {
+ return true;
+ }
}
- *equals = '\0';
name = trim_one_space(buf);
len = strlen(buf);
@@ -247,12 +255,17 @@ static bool parse_param(char *buf,
return false;
}
- value = trim_one_space(equals+1);
+ if (no_value) {
+ value = "";
+ } else {
+ value = trim_one_space(equals+1);
+ }
return pfunc(name, value, private_data);
}
bool tini_parse(FILE *f,
+ bool allow_empty_value,
bool (*sfunc)(const char *section, void *private_data),
bool (*pfunc)(const char *name, const char *value,
void *private_data),
@@ -293,7 +306,7 @@ bool tini_parse(FILE *f,
ok = parse_section(buf, sfunc, private_data);
break;
default:
- ok = parse_param(buf, pfunc, private_data);
+ ok = parse_param(buf, allow_empty_value, pfunc, private_data);
break;
}
diff --git a/lib/util/tini.h b/lib/util/tini.h
index 02cc1acbd1e..36fc08082a1 100644
--- a/lib/util/tini.h
+++ b/lib/util/tini.h
@@ -38,6 +38,7 @@
#include <stdio.h>
bool tini_parse(FILE *f,
+ bool allow_empty_value,
bool (*sfunc)(const char *section, void *private_data),
bool (*pfunc)(const char *name, const char *value,
void *private_data),
diff --git a/lib/util/tiniparser.c b/lib/util/tiniparser.c
index 7c106162f01..c3ab4e7f806 100644
--- a/lib/util/tiniparser.c
+++ b/lib/util/tiniparser.c
@@ -339,6 +339,7 @@ struct tiniparser_dictionary *tiniparser_load(const char *filename)
d->section_list = NULL;
ret = tini_parse(fp,
+ false,
section_parser,
value_parser,
d);