From: Mike Yuan Date: Tue, 19 Dec 2023 08:20:08 +0000 (+0800) Subject: networkctl-config-file: check for masked config before editing/showing X-Git-Tag: v256-rc1~1449^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ce6a0960f8243fed662d28f82db1c31c9e8994a;p=thirdparty%2Fsystemd.git networkctl-config-file: check for masked config before editing/showing --- diff --git a/src/network/networkctl-config-file.c b/src/network/networkctl-config-file.c index 46e5e8f3e78..b212358cfaa 100644 --- a/src/network/networkctl-config-file.c +++ b/src/network/networkctl-config-file.c @@ -29,7 +29,12 @@ typedef enum ReloadFlags { RELOAD_UDEVD = 1 << 1, } ReloadFlags; -static int get_config_files_by_name(const char *name, char **ret_path, char ***ret_dropins) { +static int get_config_files_by_name( + const char *name, + bool allow_masked, + char **ret_path, + char ***ret_dropins) { + _cleanup_free_ char *path = NULL; int r; @@ -45,6 +50,16 @@ static int get_config_files_by_name(const char *name, char **ret_path, char ***r r = RET_NERRNO(access(p, F_OK)); if (r >= 0) { + if (!allow_masked) { + r = null_or_empty_path(p); + if (r < 0) + return log_debug_errno(r, + "Failed to check if network config '%s' is masked: %m", + name); + if (r > 0) + return -ERFKILL; + } + path = TAKE_PTR(p); break; } @@ -425,7 +440,9 @@ int verb_edit(int argc, char *argv[], void *userdata) { else return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid network config name '%s'.", *name); - r = get_config_files_by_name(*name, &path, &dropins); + r = get_config_files_by_name(*name, /* allow_masked = */ false, &path, &dropins); + if (r == -ERFKILL) + return log_error_errno(r, "Network config '%s' is masked.", *name); if (r == -ENOENT) { if (arg_drop_in) return log_error_errno(r, "Cannot find network config '%s'.", *name); @@ -474,11 +491,15 @@ int verb_cat(int argc, char *argv[], void *userdata) { if (r < 0) return RET_GATHER(ret, r); } else { - r = get_config_files_by_name(*name, &path, &dropins); + r = get_config_files_by_name(*name, /* allow_masked = */ false, &path, &dropins); if (r == -ENOENT) { RET_GATHER(ret, log_error_errno(r, "Cannot find network config file '%s'.", *name)); continue; } + if (r == -ERFKILL) { + RET_GATHER(ret, log_debug_errno(r, "Network config '%s' is masked, ignoring.", *name)); + continue; + } if (r < 0) { log_error_errno(r, "Failed to get the path of network config '%s': %m", *name); return RET_GATHER(ret, r);