|
|
adddbf |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
adddbf |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
adddbf |
Date: Wed, 29 Sep 2021 12:56:04 -0500
|
|
|
adddbf |
Subject: [PATCH] libmultipath: improve checks for set_str
|
|
|
adddbf |
|
|
|
adddbf |
multipath always requires absolute pathnames, so make sure all file and
|
|
|
adddbf |
directory names start with a slash. Also check that the directories
|
|
|
adddbf |
exist. Finally, some strings, like the alias, will be used in paths.
|
|
|
adddbf |
These must not contain the slash character '/', since it is a forbidden
|
|
|
adddbf |
character in file/directory names. This patch adds seperate handlers for
|
|
|
adddbf |
these three cases. If a config line is invalid, these handlers retain
|
|
|
adddbf |
the existing config string, if any.
|
|
|
adddbf |
|
|
|
adddbf |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
adddbf |
---
|
|
|
adddbf |
libmultipath/dict.c | 89 +++++++++++++++++++++++++++++++++++++++------
|
|
|
adddbf |
1 file changed, 78 insertions(+), 11 deletions(-)
|
|
|
adddbf |
|
|
|
adddbf |
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
|
|
|
adddbf |
index 686f4d5c..d547d898 100644
|
|
|
adddbf |
--- a/libmultipath/dict.c
|
|
|
adddbf |
+++ b/libmultipath/dict.c
|
|
|
adddbf |
@@ -5,6 +5,8 @@
|
|
|
adddbf |
* Copyright (c) 2005 Kiyoshi Ueda, NEC
|
|
|
adddbf |
*/
|
|
|
adddbf |
#include <sys/types.h>
|
|
|
adddbf |
+#include <sys/stat.h>
|
|
|
adddbf |
+#include <unistd.h>
|
|
|
adddbf |
#include <pwd.h>
|
|
|
adddbf |
#include <string.h>
|
|
|
adddbf |
#include "checkers.h"
|
|
|
adddbf |
@@ -121,7 +123,72 @@ set_regex(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
adddbf |
|
|
|
adddbf |
if (!*str_ptr)
|
|
|
adddbf |
return 1;
|
|
|
adddbf |
+ return 0;
|
|
|
adddbf |
+}
|
|
|
adddbf |
|
|
|
adddbf |
+static int
|
|
|
adddbf |
+set_dir(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
adddbf |
+{
|
|
|
adddbf |
+ char **str_ptr = (char **)ptr;
|
|
|
adddbf |
+ char *old_str = *str_ptr;
|
|
|
adddbf |
+ struct stat sb;
|
|
|
adddbf |
+
|
|
|
adddbf |
+ *str_ptr = set_value(strvec);
|
|
|
adddbf |
+ if (!*str_ptr) {
|
|
|
adddbf |
+ free(old_str);
|
|
|
adddbf |
+ return 1;
|
|
|
adddbf |
+ }
|
|
|
adddbf |
+ if ((*str_ptr)[0] != '/'){
|
|
|
adddbf |
+ condlog(1, "%s line %d, %s is not an absolute directory path. Ignoring", file, line_nr, *str_ptr);
|
|
|
adddbf |
+ *str_ptr = old_str;
|
|
|
adddbf |
+ } else {
|
|
|
adddbf |
+ if (stat(*str_ptr, &sb) == 0 && S_ISDIR(sb.st_mode))
|
|
|
adddbf |
+ free(old_str);
|
|
|
adddbf |
+ else {
|
|
|
adddbf |
+ condlog(1, "%s line %d, %s is not an existing directory. Ignoring", file, line_nr, *str_ptr);
|
|
|
adddbf |
+ *str_ptr = old_str;
|
|
|
adddbf |
+ }
|
|
|
adddbf |
+ }
|
|
|
adddbf |
+ return 0;
|
|
|
adddbf |
+}
|
|
|
adddbf |
+
|
|
|
adddbf |
+static int
|
|
|
adddbf |
+set_path(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
adddbf |
+{
|
|
|
adddbf |
+ char **str_ptr = (char **)ptr;
|
|
|
adddbf |
+ char *old_str = *str_ptr;
|
|
|
adddbf |
+
|
|
|
adddbf |
+ *str_ptr = set_value(strvec);
|
|
|
adddbf |
+ if (!*str_ptr) {
|
|
|
adddbf |
+ free(old_str);
|
|
|
adddbf |
+ return 1;
|
|
|
adddbf |
+ }
|
|
|
adddbf |
+ if ((*str_ptr)[0] != '/'){
|
|
|
adddbf |
+ condlog(1, "%s line %d, %s is not an absolute path. Ignoring",
|
|
|
adddbf |
+ file, line_nr, *str_ptr);
|
|
|
adddbf |
+ *str_ptr = old_str;
|
|
|
adddbf |
+ } else
|
|
|
adddbf |
+ free(old_str);
|
|
|
adddbf |
+ return 0;
|
|
|
adddbf |
+}
|
|
|
adddbf |
+
|
|
|
adddbf |
+static int
|
|
|
adddbf |
+set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
adddbf |
+{
|
|
|
adddbf |
+ char **str_ptr = (char **)ptr;
|
|
|
adddbf |
+ char *old_str = *str_ptr;
|
|
|
adddbf |
+
|
|
|
adddbf |
+ *str_ptr = set_value(strvec);
|
|
|
adddbf |
+ if (!*str_ptr) {
|
|
|
adddbf |
+ free(old_str);
|
|
|
adddbf |
+ return 1;
|
|
|
adddbf |
+ }
|
|
|
adddbf |
+ if (strchr(*str_ptr, '/')) {
|
|
|
adddbf |
+ condlog(1, "%s line %d, %s cannot contain a slash. Ignoring",
|
|
|
adddbf |
+ file, line_nr, *str_ptr);
|
|
|
adddbf |
+ *str_ptr = old_str;
|
|
|
adddbf |
+ } else
|
|
|
adddbf |
+ free(old_str);
|
|
|
adddbf |
return 0;
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
@@ -400,19 +467,19 @@ declare_def_snprint(checkint, print_int)
|
|
|
adddbf |
declare_def_handler(max_checkint, set_uint)
|
|
|
adddbf |
declare_def_snprint(max_checkint, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_range_handler(verbosity, 0, MAX_VERBOSITY)
|
|
|
adddbf |
+declare_def_range_handler(verbosity, 0, 4)
|
|
|
adddbf |
declare_def_snprint(verbosity, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(reassign_maps, set_yes_no)
|
|
|
adddbf |
declare_def_snprint(reassign_maps, print_yes_no)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(multipath_dir, set_str)
|
|
|
adddbf |
+declare_def_handler(multipath_dir, set_dir)
|
|
|
adddbf |
declare_def_snprint(multipath_dir, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
static int def_partition_delim_handler(struct config *conf, vector strvec,
|
|
|
adddbf |
const char *file, int line_nr)
|
|
|
adddbf |
{
|
|
|
adddbf |
- int rc = set_str(strvec, &conf->partition_delim, file, line_nr);
|
|
|
adddbf |
+ int rc = set_str_noslash(strvec, &conf->partition_delim, file, line_nr);
|
|
|
adddbf |
|
|
|
adddbf |
if (rc != 0)
|
|
|
adddbf |
return rc;
|
|
|
adddbf |
@@ -545,11 +612,11 @@ declare_hw_snprint(prio_name, print_str)
|
|
|
adddbf |
declare_mp_handler(prio_name, set_str)
|
|
|
adddbf |
declare_mp_snprint(prio_name, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(alias_prefix, set_str)
|
|
|
adddbf |
+declare_def_handler(alias_prefix, set_str_noslash)
|
|
|
adddbf |
declare_def_snprint_defstr(alias_prefix, print_str, DEFAULT_ALIAS_PREFIX)
|
|
|
adddbf |
-declare_ovr_handler(alias_prefix, set_str)
|
|
|
adddbf |
+declare_ovr_handler(alias_prefix, set_str_noslash)
|
|
|
adddbf |
declare_ovr_snprint(alias_prefix, print_str)
|
|
|
adddbf |
-declare_hw_handler(alias_prefix, set_str)
|
|
|
adddbf |
+declare_hw_handler(alias_prefix, set_str_noslash)
|
|
|
adddbf |
declare_hw_snprint(alias_prefix, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(prio_args, set_str)
|
|
|
adddbf |
@@ -633,13 +700,13 @@ declare_hw_snprint(user_friendly_names, print_yes_no_undef)
|
|
|
adddbf |
declare_mp_handler(user_friendly_names, set_yes_no_undef)
|
|
|
adddbf |
declare_mp_snprint(user_friendly_names, print_yes_no_undef)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(bindings_file, set_str)
|
|
|
adddbf |
+declare_def_handler(bindings_file, set_path)
|
|
|
adddbf |
declare_def_snprint(bindings_file, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(wwids_file, set_str)
|
|
|
adddbf |
+declare_def_handler(wwids_file, set_path)
|
|
|
adddbf |
declare_def_snprint(wwids_file, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(prkeys_file, set_str)
|
|
|
adddbf |
+declare_def_handler(prkeys_file, set_path)
|
|
|
adddbf |
declare_def_snprint(prkeys_file, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(retain_hwhandler, set_yes_no_undef)
|
|
|
adddbf |
@@ -738,7 +805,7 @@ def_config_dir_handler(struct config *conf, vector strvec, const char *file,
|
|
|
adddbf |
/* this is only valid in the main config file */
|
|
|
adddbf |
if (conf->processed_main_config)
|
|
|
adddbf |
return 0;
|
|
|
adddbf |
- return set_str(strvec, &conf->config_dir, file, line_nr);
|
|
|
adddbf |
+ return set_path(strvec, &conf->config_dir, file, line_nr);
|
|
|
adddbf |
}
|
|
|
adddbf |
declare_def_snprint(config_dir, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
@@ -1781,7 +1848,7 @@ multipath_handler(struct config *conf, vector strvec, const char *file,
|
|
|
adddbf |
declare_mp_handler(wwid, set_str)
|
|
|
adddbf |
declare_mp_snprint(wwid, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_mp_handler(alias, set_str)
|
|
|
adddbf |
+declare_mp_handler(alias, set_str_noslash)
|
|
|
adddbf |
declare_mp_snprint(alias, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
/*
|