blob: c59edbbb277e114a77ea42db4ece59d981337261 [file] [log] [blame]
Brad Bishop00ab2372019-10-14 11:06:18 -04001From 0000000000000000000000000000000000000000 Mon Sep 17
200:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Mon, 6 Nov
32017 21:39:28 -0600 Subject: [PATCH] RH: warn on invalid regex instead of
4failing
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005
6multipath.conf used to allow "*" as a match everything regular expression,
7instead of requiring ".*". Instead of erroring when the old style
8regular expressions are used, it should print a warning and convert
9them.
10
11Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Brad Bishop19323692019-04-05 15:28:33 -040012
13Upstream-Status: Pending
14
Brad Bishop00ab2372019-10-14 11:06:18 -040015update this patch to 0.8.2
Brad Bishop19323692019-04-05 15:28:33 -040016
17Signed-off-by: Changqing Li <changqing.li@windriver.com>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080018---
Brad Bishop19323692019-04-05 15:28:33 -040019 libmultipath/dict.c | 29 ++++++++++++++++++++++-------
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080020 libmultipath/parser.c | 13 +++++++++++++
Brad Bishopc342db32019-05-15 21:57:59 -040021 libmultipath/parser.h | 1 +
22 3 files changed, 36 insertions(+), 7 deletions(-)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080023
24diff --git a/libmultipath/dict.c b/libmultipath/dict.c
Brad Bishop00ab2372019-10-14 11:06:18 -040025index c6eba0f..05ed3d8 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080026--- a/libmultipath/dict.c
27+++ b/libmultipath/dict.c
Brad Bishop19323692019-04-05 15:28:33 -040028@@ -59,6 +59,21 @@ set_str(vector strvec, void *ptr)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029 }
30
31 static int
32+set_regex(vector strvec, void *ptr)
33+{
Brad Bishop19323692019-04-05 15:28:33 -040034+ char **str_ptr = (char **)ptr;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080035+
Brad Bishop19323692019-04-05 15:28:33 -040036+ if (*str_ptr)
37+ FREE(*str_ptr);
38+ *str_ptr = set_regex_value(strvec);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039+
Brad Bishop19323692019-04-05 15:28:33 -040040+ if (!*str_ptr)
41+ return 1;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042+
Brad Bishop19323692019-04-05 15:28:33 -040043+ return 0;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044+}
45+
46+static int
47 set_yes_no(vector strvec, void *ptr)
48 {
49 char * buff;
Brad Bishop00ab2372019-10-14 11:06:18 -040050@@ -1415,8 +1430,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \
Brad Bishop19323692019-04-05 15:28:33 -040051 \
52 if (!conf->option) \
53 return 1; \
54- \
55- buff = set_value(strvec); \
56+ \
57+ buff = set_regex_value(strvec); \
58 if (!buff) \
59 return 1; \
60 \
Brad Bishop00ab2372019-10-14 11:06:18 -040061@@ -1432,7 +1447,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080062 if (!conf->option) \
63 return 1; \
64 \
65- buff = set_value(strvec); \
66+ buff = set_regex_value(strvec); \
67 if (!buff) \
68 return 1; \
69 \
Brad Bishop00ab2372019-10-14 11:06:18 -040070@@ -1535,16 +1550,16 @@ device_handler(struct config *conf, vector strvec)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080071 return 0;
72 }
73
74-declare_hw_handler(vendor, set_str)
75+declare_hw_handler(vendor, set_regex)
76 declare_hw_snprint(vendor, print_str)
77
78-declare_hw_handler(product, set_str)
79+declare_hw_handler(product, set_regex)
80 declare_hw_snprint(product, print_str)
81
82-declare_hw_handler(revision, set_str)
83+declare_hw_handler(revision, set_regex)
84 declare_hw_snprint(revision, print_str)
85
86-declare_hw_handler(bl_product, set_str)
87+declare_hw_handler(bl_product, set_regex)
88 declare_hw_snprint(bl_product, print_str)
89
90 declare_hw_handler(hwhandler, set_str)
91diff --git a/libmultipath/parser.c b/libmultipath/parser.c
Brad Bishop00ab2372019-10-14 11:06:18 -040092index e00c5ff..6ca5842 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080093--- a/libmultipath/parser.c
94+++ b/libmultipath/parser.c
Brad Bishop00ab2372019-10-14 11:06:18 -040095@@ -382,6 +382,19 @@ oom:
96 return NULL;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080097 }
98
99+void *
100+set_regex_value(vector strvec)
101+{
Brad Bishop19323692019-04-05 15:28:33 -0400102+ char *buff = set_value(strvec);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800103+
Brad Bishop19323692019-04-05 15:28:33 -0400104+ if (buff && strcmp("*", buff) == 0) {
105+ condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\"");
106+ FREE(buff);
107+ return strdup(".*");
108+ }
109+ return buff;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800110+}
111+
112 /* non-recursive configuration stream handler */
113 static int kw_level = 0;
114
115diff --git a/libmultipath/parser.h b/libmultipath/parser.h
Brad Bishopc342db32019-05-15 21:57:59 -0400116index 62906e9..b791705 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800117--- a/libmultipath/parser.h
118+++ b/libmultipath/parser.h
Brad Bishopc342db32019-05-15 21:57:59 -0400119@@ -77,6 +77,7 @@ extern void dump_keywords(vector keydump, int level);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800120 extern void free_keywords(vector keywords);
121 extern vector alloc_strvec(char *string);
Brad Bishopc342db32019-05-15 21:57:59 -0400122 extern void *set_value(vector strvec);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800123+extern void *set_regex_value(vector strvec);
124 extern int process_file(struct config *conf, char *conf_file);
125 extern struct keyword * find_keyword(vector keywords, vector v, char * name);
126 int snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw,
Brad Bishop00ab2372019-10-14 11:06:18 -0400127--
1282.7.4
129