PolicyKit: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Tue Feb 26 13:07:11 PST 2008


 src/polkit-dbus/polkit-read-auth-helper.c |   20 +++++++++++++-------
 src/polkit/polkit-policy-cache.c          |   25 ++++++++++++++++++-------
 2 files changed, 31 insertions(+), 14 deletions(-)

New commits:
commit 0b59d3e7d4b282da308b362dc440b007b9ecedbf
Author: Holger Macht <hmacht at suse.de>
Date:   Tue Feb 26 16:05:23 2008 -0500

    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 <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..0d6c2fc 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,18 +128,28 @@ _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()");
+                        kit_free (path);
+                        goto out;
+                }
+                
+                if (!S_ISREG (statbuf.st_mode)) {
+                        kit_free (path);
                         continue;
+                }
 
                 filename = d->d_name;
                 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;
-
-                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);


More information about the hal-commit mailing list