[PATCH] PolicyKit: Make PolicyKit work on reiserfs
Holger Macht
hmacht at suse.de
Sat Jan 26 03:22:43 PST 2008
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 <hmacht at suse.de>
---
diff --git a/src/polkit-dbus/polkit-read-auth-helper.c b/src/polkit-dbus/polkit-read-auth-helper.c
index 9948d1d..25505ca 100644
--- a/src/polkit-dbus/polkit-read-auth-helper.c
+++ b/src/polkit-dbus/polkit-read-auth-helper.c
@@ -181,11 +181,22 @@ dump_auths_all (const char *root)
char path[PATH_MAX];
static const char suffix[] = ".auths";
struct passwd *pw;
+ struct stat statbuf;
- if (d->d_type != DT_REG)
+ if (d->d_name == NULL)
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;
filename = d->d_name;
@@ -230,11 +241,6 @@ dump_auths_all (const char *root)
}
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))
goto out;
}
diff --git a/src/polkit/polkit-policy-cache.c b/src/polkit/polkit-policy-cache.c
index 6a80909..3641c8a 100644
--- a/src/polkit/polkit-policy-cache.c
+++ b/src/polkit/polkit-policy-cache.c
@@ -100,6 +100,7 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
DIR *dir;
struct dirent64 *d;
PolKitPolicyCache *pc;
+ struct stat statbuf;
dir = NULL;
@@ -127,7 +128,18 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
char *filename;
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()");
+ goto out;
+ }
+
+ if (!S_ISREG (statbuf.st_mode))
continue;
filename = d->d_name;
@@ -135,12 +147,6 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
if (name_len < sizeof (suffix) || strcmp ((filename + name_len - sizeof (suffix) + 1), suffix) != 0)
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_error = NULL;
pf = polkit_policy_file_new (path, load_descriptions, &pk_error);
More information about the hal
mailing list