diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -43,6 +43,8 @@ ensure_directory (const char *path, gint mode, GError **error) { + GStatBuf stat_buffer = { 0 }; + if (g_mkdir_with_parents (path, mode) < 0) { g_set_error (error, G_FILE_ERROR, @@ -52,15 +54,28 @@ ensure_directory (const char *path, return FALSE; } - if (g_chmod (path, mode) < 0) { + g_chmod (path, mode); + + if (g_stat (path, &stat_buffer) < 0) { + g_clear_error (error); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), - "Failed to change permissions of directory %s: %m", + "Failed to validate permissions of directory %s: %m", path); return FALSE; } + if ((stat_buffer.st_mode & ~S_IFMT) != mode) { + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + "Directory %s has wrong mode %o; it should be %o", + path, stat_buffer.st_mode, mode); + return FALSE; + } + return TRUE; } @@ -78,12 +93,19 @@ ensure_file_permissions (const char *dir_path, return FALSE; while ((filename = g_dir_read_name (dir)) != NULL) { + GStatBuf stat_buffer = { 0 }; + gchar *file_path = g_build_filename (dir_path, filename, NULL); g_debug ("Changing permission of %s to %04o", file_path, file_mode); - if (g_chmod (file_path, file_mode) < 0) + g_chmod (file_path, file_mode); + + if (g_stat (file_path, &stat_buffer) < 0) errsv = errno; + if ((stat_buffer.st_mode & ~S_IFMT) != file_mode) + errsv = EACCES; + g_free (file_path); } @@ -125,7 +147,6 @@ on_bus_acquired (GDBusConnection *connection, g_main_loop_quit (loop); return; } - openlog ("accounts-daemon", LOG_PID, LOG_DAEMON); syslog (LOG_INFO, "started daemon version %s", VERSION); closelog (); |