Commit 0b59d3e7 authored by Holger Macht's avatar Holger Macht Committed by David Zeuthen
Browse files

avoid reliance on DT_REG so we work on reiserfs as well



(with minor fixes from davidz for avoiding memory leaks)

Recently I wondered why PolicyKit (especially polkit-auth) does not work
on my system. While debugging, I noticed that the corresponding code works
in my home directory, but not in the root filesystem.

readdir() and its d_type are the culprits. Quoting the readdir manpage:

[...]
Other than Linux, the d_type field is available mainly only on BSD
systems.  This field makes it possible to avoid the expense of calling
stat() if further actions depend on the type of the file.
[...]

Filesystems may fill DT_UNKNOWN into this field, which reiserfs does, so
call stat instead, which always does the right thing.
Signed-off-by: Holger Macht's avatarHolger Macht <hmacht@suse.de>
parent fd51264a
...@@ -181,11 +181,22 @@ dump_auths_all (const char *root) ...@@ -181,11 +181,22 @@ dump_auths_all (const char *root)
char path[PATH_MAX]; char path[PATH_MAX];
static const char suffix[] = ".auths"; static const char suffix[] = ".auths";
struct passwd *pw; struct passwd *pw;
struct stat statbuf;
if (d->d_type != DT_REG) if (d->d_name == NULL)
continue; continue;
if (d->d_name == NULL) if (snprintf (path, sizeof (path), "%s/%s", root, d->d_name) >= (int) sizeof (path)) {
fprintf (stderr, "polkit-read-auth-helper: string was truncated (1)\n");
goto out;
}
if (stat (path, &statbuf) != 0) {
fprintf (stderr, "polkit-read-auth-helper: cannot stat %s: %m\n", path);
goto out;
}
if (!S_ISREG(statbuf.st_mode))
continue; continue;
filename = d->d_name; filename = d->d_name;
...@@ -230,11 +241,6 @@ dump_auths_all (const char *root) ...@@ -230,11 +241,6 @@ dump_auths_all (const char *root)
} }
uid = pw->pw_uid; uid = pw->pw_uid;
if (snprintf (path, sizeof (path), "%s/%s", root, filename) >= (int) sizeof (path)) {
fprintf (stderr, "polkit-read-auth-helper: string was truncated (1)\n");
goto out;
}
if (!dump_auths_from_file (path, uid)) if (!dump_auths_from_file (path, uid))
goto out; goto out;
} }
......
...@@ -100,6 +100,7 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions, ...@@ -100,6 +100,7 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
DIR *dir; DIR *dir;
struct dirent64 *d; struct dirent64 *d;
PolKitPolicyCache *pc; PolKitPolicyCache *pc;
struct stat statbuf;
dir = NULL; dir = NULL;
...@@ -127,18 +128,28 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions, ...@@ -127,18 +128,28 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
char *filename; char *filename;
static const char suffix[] = ".policy"; static const char suffix[] = ".policy";
if (d->d_type != DT_REG) path = kit_strdup_printf ("%s/%s", dirname, d->d_name);
if (path == NULL) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory");
goto out;
}
if (stat (path, &statbuf) != 0) {
polkit_error_set_error (error, POLKIT_ERROR_GENERAL_ERROR, "stat()");
kit_free (path);
goto out;
}
if (!S_ISREG (statbuf.st_mode)) {
kit_free (path);
continue; continue;
}
filename = d->d_name; filename = d->d_name;
name_len = strlen (filename); name_len = strlen (filename);
if (name_len < sizeof (suffix) || strcmp ((filename + name_len - sizeof (suffix) + 1), suffix) != 0) if (name_len < sizeof (suffix) || strcmp ((filename + name_len - sizeof (suffix) + 1), suffix) != 0) {
kit_free (path);
continue; continue;
path = kit_strdup_printf ("%s/%s", dirname, filename);
if (path == NULL) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory");
goto out;
} }
_pk_debug ("Loading %s", path); _pk_debug ("Loading %s", path);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment