From 1a9b4e34127b273f8fb42a14eccf7067ce8e627e Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Thu, 5 Jun 2014 15:33:02 +0200 Subject: [PATCH] client: require directory in --ifconfig compat:/dir (bnc#881544) --- client/redhat/compat-redhat.c | 32 ++++++++++++-------------------- client/suse/compat-suse.c | 22 +++++++++++----------- man/wicked.8.in | 6 ++---- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/client/redhat/compat-redhat.c b/client/redhat/compat-redhat.c index ec6f0006e..2a7b1a372 100644 --- a/client/redhat/compat-redhat.c +++ b/client/redhat/compat-redhat.c @@ -60,15 +60,15 @@ __ni_redhat_get_interfaces(const char *root, const char *path, ni_compat_netdev_ ni_string_array_t files = NI_STRING_ARRAY_INIT; ni_bool_t success = FALSE; char *pathname = NULL; + const char *_path = _PATH_NETCONFIG_DIR; - if (ni_string_empty(path)) - path = _PATH_NETCONFIG_DIR; + if (!ni_string_empty(path)) + _path = path; if (ni_string_empty(root)) - ni_string_dup(&pathname, path); + ni_string_dup(&pathname, _path); else - ni_string_printf(&pathname, "%s%s", root, path); - + ni_string_printf(&pathname, "%s%s", root, _path); if (ni_isdir(pathname)) { unsigned int i; @@ -93,24 +93,16 @@ __ni_redhat_get_interfaces(const char *root, const char *path, ni_compat_netdev_ } } else if (ni_file_exists(pathname)) { - ni_compat_netdev_t *compat; - const char *filename = ni_basename(pathname); - const char *ifname = filename + sizeof("ifcfg-")-1; - - if (strncmp("ifcfg-", filename, sizeof("ifcfg-")-1)) { - ni_error("File does not have ifcfg-prefix: %s", pathname); - goto done; - } - - if (!(compat = __ni_redhat_read_interface(pathname, ifname, result))) - goto done; - - ni_compat_netdev_client_info_set(compat->dev, pathname); - } else { - ni_error("File or directory does not exist: %s", pathname); + ni_error("Cannot use '%s' to read redhat ifcfg files -- not a directory", + pathname); + goto done; + } else + if (!ni_string_empty(path)) { + ni_error("Configuration directory '%s' does not exist", pathname); goto done; } + success = TRUE; done: ni_string_free(&pathname); diff --git a/client/suse/compat-suse.c b/client/suse/compat-suse.c index e53641bf8..017554748 100644 --- a/client/suse/compat-suse.c +++ b/client/suse/compat-suse.c @@ -220,22 +220,17 @@ __ni_suse_get_ifconfig(const char *root, const char *path, ni_compat_ifconfig_t ni_string_array_t files = NI_STRING_ARRAY_INIT; ni_bool_t success = FALSE; char *pathname = NULL; - const char *base; + const char *_path = __NI_SUSE_SYSCONFIG_NETWORK_DIR; unsigned int i; - if (ni_string_empty(path)) - path = __NI_SUSE_SYSCONFIG_NETWORK_DIR; + if (!ni_string_empty(path)) + _path = path; if (ni_string_empty(root)) - ni_string_dup(&pathname, path); + ni_string_dup(&pathname, _path); else - ni_string_printf(&pathname, "%s%s", root, path); + ni_string_printf(&pathname, "%s%s", root, _path); - if (ni_isreg(pathname)) { - if ((base = ni_dirname(pathname))) - ni_string_dup(&pathname, base); - path = ni_dirname(pathname); - } if (ni_isdir(pathname)) { if (!__ni_suse_read_globals(root, pathname)) goto done; @@ -273,7 +268,12 @@ __ni_suse_get_ifconfig(const char *root, const char *path, ni_compat_ifconfig_t } } else if (ni_file_exists(pathname)) { - ni_error("Cannot use '%s' to read suse ifcfg files", pathname); + ni_error("Cannot use '%s' to read suse ifcfg files -- not a directory", + pathname); + goto done; + } else + if (!ni_string_empty(path)) { + ni_error("Configuration directory '%s' does not exist", pathname); goto done; } diff --git a/man/wicked.8.in b/man/wicked.8.in index d34f215fb..5f116b254 100644 --- a/man/wicked.8.in +++ b/man/wicked.8.in @@ -187,10 +187,8 @@ If the file name starts with the string \fBcompat:\fP, \fBwicked\fP is instructed to load the interface configuration from files in the old-style "ifcfg" syntax, as described by the \fBifcfg\fP(5) manual page. The string following the \fBcompat:\fP prefix is interpreted as a -path name. If this path name refers to a directory, -\fBwicked\fP will scan it for files with names matching \fBifcfg-*\fP. -If the path name refers to a regular file, it will parse this file, assuming -it is an ifcfg file. +directory name where \fBwicked\fP will scan for files with names matching +\fBifcfg-*\fP and related files, like \fBroutes\fP and \fBifroute-*\fP. .IP The special name \fBfirmware:\fP can be used to obtain the interface definition(s) from firmware services like iBFT.