|
|
4728c8 |
---
|
|
|
4728c8 |
libmultipath/parser.c | 154 ++++++++++++++++++++++++++++++++++++++++----------
|
|
|
4728c8 |
1 file changed, 126 insertions(+), 28 deletions(-)
|
|
|
4728c8 |
|
|
|
4728c8 |
Index: multipath-tools-130222/libmultipath/parser.c
|
|
|
4728c8 |
===================================================================
|
|
|
4728c8 |
--- multipath-tools-130222.orig/libmultipath/parser.c
|
|
|
4728c8 |
+++ multipath-tools-130222/libmultipath/parser.c
|
|
|
4728c8 |
@@ -395,36 +395,57 @@ set_value(vector strvec)
|
|
|
4728c8 |
char *alloc = NULL;
|
|
|
4728c8 |
char *tmp;
|
|
|
4728c8 |
|
|
|
4728c8 |
- if (!str)
|
|
|
4728c8 |
+ if (!str) {
|
|
|
4728c8 |
+ condlog(0, "option '%s' missing value",
|
|
|
4728c8 |
+ (char *)VECTOR_SLOT(strvec, 0));
|
|
|
4728c8 |
return NULL;
|
|
|
4728c8 |
-
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
size = strlen(str);
|
|
|
4728c8 |
- if (size == 0)
|
|
|
4728c8 |
+ if (size == 0) {
|
|
|
4728c8 |
+ condlog(0, "option '%s' has empty value",
|
|
|
4728c8 |
+ (char *)VECTOR_SLOT(strvec, 0));
|
|
|
4728c8 |
return NULL;
|
|
|
4728c8 |
-
|
|
|
4728c8 |
- if (*str == '"') {
|
|
|
4728c8 |
- for (i = 2; i < VECTOR_SIZE(strvec); i++) {
|
|
|
4728c8 |
- str = VECTOR_SLOT(strvec, i);
|
|
|
4728c8 |
- len += strlen(str);
|
|
|
4728c8 |
- if (!alloc)
|
|
|
4728c8 |
- alloc =
|
|
|
4728c8 |
- (char *) MALLOC(sizeof (char *) *
|
|
|
4728c8 |
- (len + 1));
|
|
|
4728c8 |
- else {
|
|
|
4728c8 |
- alloc =
|
|
|
4728c8 |
- REALLOC(alloc, sizeof (char *) * (len + 1));
|
|
|
4728c8 |
- tmp = VECTOR_SLOT(strvec, i-1);
|
|
|
4728c8 |
- if (alloc && *str != '"' && *tmp != '"')
|
|
|
4728c8 |
- strncat(alloc, " ", 1);
|
|
|
4728c8 |
- }
|
|
|
4728c8 |
-
|
|
|
4728c8 |
- if (alloc && i != VECTOR_SIZE(strvec)-1)
|
|
|
4728c8 |
- strncat(alloc, str, strlen(str));
|
|
|
4728c8 |
- }
|
|
|
4728c8 |
- } else {
|
|
|
4728c8 |
- alloc = MALLOC(sizeof (char *) * (size + 1));
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*str != '"') {
|
|
|
4728c8 |
+ alloc = MALLOC(sizeof (char) * (size + 1));
|
|
|
4728c8 |
if (alloc)
|
|
|
4728c8 |
memcpy(alloc, str, size);
|
|
|
4728c8 |
+ else
|
|
|
4728c8 |
+ condlog(0, "can't allocate memeory for option '%s'",
|
|
|
4728c8 |
+ (char *)VECTOR_SLOT(strvec, 0));
|
|
|
4728c8 |
+ return alloc;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ /* Even empty quotes counts as a value (An empty string) */
|
|
|
4728c8 |
+ alloc = (char *) MALLOC(sizeof (char));
|
|
|
4728c8 |
+ if (!alloc) {
|
|
|
4728c8 |
+ condlog(0, "can't allocate memeory for option '%s'",
|
|
|
4728c8 |
+ (char *)VECTOR_SLOT(strvec, 0));
|
|
|
4728c8 |
+ return NULL;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ for (i = 2; i < VECTOR_SIZE(strvec); i++) {
|
|
|
4728c8 |
+ str = VECTOR_SLOT(strvec, i);
|
|
|
4728c8 |
+ if (!str) {
|
|
|
4728c8 |
+ free(alloc);
|
|
|
4728c8 |
+ condlog(0, "parse error for option '%s'",
|
|
|
4728c8 |
+ (char *)VECTOR_SLOT(strvec, 0));
|
|
|
4728c8 |
+ return NULL;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*str == '"')
|
|
|
4728c8 |
+ break;
|
|
|
4728c8 |
+ tmp = alloc;
|
|
|
4728c8 |
+ /* The first +1 is for the NULL byte. The rest are for the
|
|
|
4728c8 |
+ * spaces between words */
|
|
|
4728c8 |
+ len += strlen(str) + 1;
|
|
|
4728c8 |
+ alloc = REALLOC(alloc, sizeof (char) * len);
|
|
|
4728c8 |
+ if (!alloc) {
|
|
|
4728c8 |
+ FREE(tmp);
|
|
|
4728c8 |
+ condlog(0, "can't allocate memeory for option '%s'",
|
|
|
4728c8 |
+ (char *)VECTOR_SLOT(strvec, 0));
|
|
|
4728c8 |
+ return NULL;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*alloc != '\0')
|
|
|
4728c8 |
+ strncat(alloc, " ", 1);
|
|
|
4728c8 |
+ strncat(alloc, str, strlen(str));
|
|
|
4728c8 |
}
|
|
|
4728c8 |
return alloc;
|
|
|
4728c8 |
}
|
|
|
4728c8 |
@@ -465,6 +486,74 @@ void free_uniques(vector uniques)
|
|
|
4728c8 |
}
|
|
|
4728c8 |
|
|
|
4728c8 |
int
|
|
|
4728c8 |
+is_sublevel_keyword(char *str)
|
|
|
4728c8 |
+{
|
|
|
4728c8 |
+ return (strcmp(str, "defaults") == 0 || strcmp(str, "blacklist") == 0 ||
|
|
|
4728c8 |
+ strcmp(str, "blacklist_exceptions") == 0 ||
|
|
|
4728c8 |
+ strcmp(str, "devices") == 0 || strcmp(str, "devices") == 0 ||
|
|
|
4728c8 |
+ strcmp(str, "device") == 0 || strcmp(str, "multipaths") == 0 ||
|
|
|
4728c8 |
+ strcmp(str, "multipath") == 0);
|
|
|
4728c8 |
+}
|
|
|
4728c8 |
+
|
|
|
4728c8 |
+int
|
|
|
4728c8 |
+validate_config_strvec(vector strvec)
|
|
|
4728c8 |
+{
|
|
|
4728c8 |
+ char *str;
|
|
|
4728c8 |
+ int i;
|
|
|
4728c8 |
+
|
|
|
4728c8 |
+ str = VECTOR_SLOT(strvec, 0);
|
|
|
4728c8 |
+ if (str == NULL) {
|
|
|
4728c8 |
+ condlog(0, "can't parse option on line %d of config file",
|
|
|
4728c8 |
+ line_nr);
|
|
|
4728c8 |
+ return -1;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*str == '}') {
|
|
|
4728c8 |
+ if (VECTOR_SIZE(strvec) > 1)
|
|
|
4728c8 |
+ condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 1), line_nr);
|
|
|
4728c8 |
+ return 0;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*str == '{') {
|
|
|
4728c8 |
+ condlog(0, "invalid keyword '%s' on line %d of config file", str, line_nr);
|
|
|
4728c8 |
+ return -1;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (is_sublevel_keyword(str)) {
|
|
|
4728c8 |
+ str = VECTOR_SLOT(strvec, 1);
|
|
|
4728c8 |
+ if (str == NULL)
|
|
|
4728c8 |
+ condlog(0, "missing '{' on line %d of config file", line_nr);
|
|
|
4728c8 |
+ else if (*str != '{')
|
|
|
4728c8 |
+ condlog(0, "expecting '{' on line %d of config file. found '%s'", line_nr, str);
|
|
|
4728c8 |
+ else if (VECTOR_SIZE(strvec) > 2)
|
|
|
4728c8 |
+ condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 2), line_nr);
|
|
|
4728c8 |
+ return 0;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ str = VECTOR_SLOT(strvec, 1);
|
|
|
4728c8 |
+ if (str == NULL) {
|
|
|
4728c8 |
+ condlog(0, "missing value for option '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 0), line_nr);
|
|
|
4728c8 |
+ return -1;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*str != '"') {
|
|
|
4728c8 |
+ if (VECTOR_SIZE(strvec) > 2)
|
|
|
4728c8 |
+ condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, 2), line_nr);
|
|
|
4728c8 |
+ return 0;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ for (i = 2; i < VECTOR_SIZE(strvec); i++) {
|
|
|
4728c8 |
+ str = VECTOR_SLOT(strvec, i);
|
|
|
4728c8 |
+ if (str == NULL) {
|
|
|
4728c8 |
+ condlog(0, "can't parse value on line %d of config file", line_nr);
|
|
|
4728c8 |
+ return -1;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ if (*str == '"') {
|
|
|
4728c8 |
+ if (VECTOR_SIZE(strvec) > i + 1)
|
|
|
4728c8 |
+ condlog(0, "ignoring extra data starting with '%s' on line %d of config file", (char *)VECTOR_SLOT(strvec, (i + 1)), line_nr);
|
|
|
4728c8 |
+ return 0;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ condlog(0, "missing closing quotes on line %d of config file",
|
|
|
4728c8 |
+ line_nr);
|
|
|
4728c8 |
+ return 0;
|
|
|
4728c8 |
+}
|
|
|
4728c8 |
+
|
|
|
4728c8 |
+int
|
|
|
4728c8 |
process_stream(vector keywords)
|
|
|
4728c8 |
{
|
|
|
4728c8 |
int i;
|
|
|
4728c8 |
@@ -494,11 +583,20 @@ process_stream(vector keywords)
|
|
|
4728c8 |
if (!strvec)
|
|
|
4728c8 |
continue;
|
|
|
4728c8 |
|
|
|
4728c8 |
+ if (validate_config_strvec(strvec) != 0) {
|
|
|
4728c8 |
+ free_strvec(strvec);
|
|
|
4728c8 |
+ continue;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+
|
|
|
4728c8 |
str = VECTOR_SLOT(strvec, 0);
|
|
|
4728c8 |
|
|
|
4728c8 |
- if (!strcmp(str, EOB) && kw_level > 0) {
|
|
|
4728c8 |
- free_strvec(strvec);
|
|
|
4728c8 |
- break;
|
|
|
4728c8 |
+ if (!strcmp(str, EOB)) {
|
|
|
4728c8 |
+ if (kw_level > 0) {
|
|
|
4728c8 |
+ free_strvec(strvec);
|
|
|
4728c8 |
+ break;
|
|
|
4728c8 |
+ }
|
|
|
4728c8 |
+ condlog(0, "unmatched '%s' at line %d of config file",
|
|
|
4728c8 |
+ EOB, line_nr);
|
|
|
4728c8 |
}
|
|
|
4728c8 |
|
|
|
4728c8 |
for (i = 0; i < VECTOR_SIZE(keywords); i++) {
|