mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zdev: Fix reporting of read-only sysfs attributes
Since commitd542138868("zdev: use libutil provided path functions") lszdev fails to correctly report most read-only sysfs attributes as such in its detailed information output (options -i or -ii). This is because the libutil function util_path_is_writable() is not equivalent to the former function file_writable(). util_path_is_writable() always returns true (the underlying function access() indicates the file is writable), if the path exists and the user is root, regardless of the path's effective access permissions. This is correct for most use cases, as root can effectively read/write any path regardless of its effective access permissions). util_path_is_writable() behaves exactly like Bash -w in this regard. The former function file_writable() examined the file's access permissions to check if one or more of user, group, and other have write permission. For lszdev it is irrelevant whether a file is effectively writable by the current user. Instead it needs to determine whether sysfs attributes access permissions contain write access in any form. If not it lists those sysfs attributes in a separate read-only section. Use the new function util_path_is_readonly_file(), which does explicitly check the file's effective read and write access permissions. It behaves similar to the former function file_writable(), except that it does test whether any of user, group, and other have read permission. Fixes:d542138868("zdev: use libutil provided path functions") Signed-off-by: Jens Remus <jremus@linux.ibm.com> Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* zdev - Modify and display the persistent configuration of devices
|
||||
*
|
||||
* Copyright IBM Corp. 2016, 2017
|
||||
* Copyright IBM Corp. 2016, 2019
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "lib/util_path.h"
|
||||
|
||||
@@ -521,7 +522,7 @@ void device_read_active_settings(struct device *dev, read_scope_t scope)
|
||||
s = setting_list_apply_actual(dev->active.settings, a, name,
|
||||
value);
|
||||
if (link || (scope == scope_all &&
|
||||
!util_path_is_writable(path)))
|
||||
util_path_is_readonly_file("%s", path)))
|
||||
s->readonly = 1;
|
||||
if (link)
|
||||
free(link);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "lib/util_path.h"
|
||||
@@ -259,7 +260,7 @@ bool module_set_params(const char *mod, struct setting_list *settings)
|
||||
struct setting *s;
|
||||
char *path;
|
||||
const char *value;
|
||||
bool result;
|
||||
bool readonly;
|
||||
exit_code_t rc;
|
||||
|
||||
/* First check if all modified settings can be applied this way. */
|
||||
@@ -277,9 +278,9 @@ bool module_set_params(const char *mod, struct setting_list *settings)
|
||||
return false;
|
||||
}
|
||||
path = path_get_sys_module_param(mod, s->name);
|
||||
result = util_path_is_writable(path);
|
||||
readonly = util_path_is_readonly_file("%s", path);
|
||||
free(path);
|
||||
if (!result) {
|
||||
if (readonly) {
|
||||
/* Sysfs file is not writable. */
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user