blob: a23e1673934e024f99f583c4da173c94e0205caa [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Benjamin Marzinski <bmarzins@redhat.com>
3Date: Mon, 6 Nov 2017 21:39:28 -0600
4Subject: [PATCH] RH: warn on invalid regex instead of failing
5
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>
12---
13 libmultipath/dict.c | 27 +++++++++++++++++++++------
14 libmultipath/parser.c | 13 +++++++++++++
15 libmultipath/parser.h | 1 +
16 3 files changed, 35 insertions(+), 6 deletions(-)
17
18diff --git a/libmultipath/dict.c b/libmultipath/dict.c
19index 7ad0f5a..ab808d6 100644
20--- a/libmultipath/dict.c
21+++ b/libmultipath/dict.c
22@@ -55,6 +55,21 @@ set_str(vector strvec, void *ptr)
23 }
24
25 static int
26+set_regex(vector strvec, void *ptr)
27+{
28+ char **str_ptr = (char **)ptr;
29+
30+ if (*str_ptr)
31+ FREE(*str_ptr);
32+ *str_ptr = set_regex_value(strvec);
33+
34+ if (!*str_ptr)
35+ return 1;
36+
37+ return 0;
38+}
39+
40+static int
41 set_yes_no(vector strvec, void *ptr)
42 {
43 char * buff;
44@@ -1271,7 +1286,7 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \
45 if (!conf->option) \
46 return 1; \
47 \
48- buff = set_value(strvec); \
49+ buff = set_regex_value(strvec); \
50 if (!buff) \
51 return 1; \
52 \
53@@ -1287,7 +1302,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
54 if (!conf->option) \
55 return 1; \
56 \
57- buff = set_value(strvec); \
58+ buff = set_regex_value(strvec); \
59 if (!buff) \
60 return 1; \
61 \
62@@ -1388,16 +1403,16 @@ device_handler(struct config *conf, vector strvec)
63 return 0;
64 }
65
66-declare_hw_handler(vendor, set_str)
67+declare_hw_handler(vendor, set_regex)
68 declare_hw_snprint(vendor, print_str)
69
70-declare_hw_handler(product, set_str)
71+declare_hw_handler(product, set_regex)
72 declare_hw_snprint(product, print_str)
73
74-declare_hw_handler(revision, set_str)
75+declare_hw_handler(revision, set_regex)
76 declare_hw_snprint(revision, print_str)
77
78-declare_hw_handler(bl_product, set_str)
79+declare_hw_handler(bl_product, set_regex)
80 declare_hw_snprint(bl_product, print_str)
81
82 declare_hw_handler(hwhandler, set_str)
83diff --git a/libmultipath/parser.c b/libmultipath/parser.c
84index b8b7e0d..34b4ad2 100644
85--- a/libmultipath/parser.c
86+++ b/libmultipath/parser.c
87@@ -380,6 +380,19 @@ set_value(vector strvec)
88 return alloc;
89 }
90
91+void *
92+set_regex_value(vector strvec)
93+{
94+ char *buff = set_value(strvec);
95+
96+ if (buff && strcmp("*", buff) == 0) {
97+ condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\"");
98+ FREE(buff);
99+ return strdup(".*");
100+ }
101+ return buff;
102+}
103+
104 /* non-recursive configuration stream handler */
105 static int kw_level = 0;
106
107diff --git a/libmultipath/parser.h b/libmultipath/parser.h
108index 62906e9..b791705 100644
109--- a/libmultipath/parser.h
110+++ b/libmultipath/parser.h
111@@ -77,6 +77,7 @@ extern void dump_keywords(vector keydump, int level);
112 extern void free_keywords(vector keywords);
113 extern vector alloc_strvec(char *string);
114 extern void *set_value(vector strvec);
115+extern void *set_regex_value(vector strvec);
116 extern int process_file(struct config *conf, char *conf_file);
117 extern struct keyword * find_keyword(vector keywords, vector v, char * name);
118 int snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw,
119--
1202.7.4
121