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