jobextra/consolekit2/trust_runtime_admin_policy....

102 lines
3.0 KiB
Diff

diff -Nuar -uar a/src/ck-sysdeps-unix.c b/src/ck-sysdeps-unix.c
--- a/src/ck-sysdeps-unix.c 2019-03-19 21:50:30.000000000 +1100
+++ b/src/ck-sysdeps-unix.c 2019-07-19 00:54:37.011751960 +1100
@@ -403,11 +403,17 @@
create_rundir_base (guint uid)
{
const gchar *base;
-
+ struct stat st ;
TRACE ();
base = RUNDIR "/user";
-
+
+ if (stat(base,&st) == -1) {
+ g_warning ("unable to stat %s, reason was: %s",base,strerror(errno)) ;
+ errno = 0 ;
+ return FALSE ;
+ }
+ if (S_ISDIR(st.st_mode)) return TRUE ;
/* Create the base directory that we will own. */
if (g_mkdir_with_parents (base, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
g_warning ("Failed to create %s, reason was: %s", base, strerror(errno));
@@ -459,7 +465,7 @@
{
gchar *dest;
struct passwd *pwent;
-
+ struct stat st ;
TRACE ();
errno = 0;
@@ -476,33 +482,41 @@
}
dest = get_rundir (uid);
-
- /* Ensure any files from the last session are removed */
- if (g_file_test (dest, G_FILE_TEST_EXISTS) == TRUE) {
- remove_rundir (uid, dest);
- }
-
- /* Create the new directory */
- if (g_mkdir_with_parents (dest, S_IRWXU) != 0) {
- g_warning ("Failed to create XDG_RUNTIME_DIR, reason was: %s", strerror(errno));
- errno = 0;
- g_free (dest);
- return NULL;
- }
-
- g_debug ("setting uid %d, gid %d", uid, pwent->pw_gid);
-
- /* assign ownership to the user */
- if (chown (dest, uid, pwent->pw_gid) != 0) {
- g_warning ("Failed to chown XDG_RUNTIME_DIR, reason was: %s", strerror(errno));
- errno = 0;
- g_free (dest);
- return NULL;
- }
-
- /* attempt to make it a small tmpfs location */
- ck_make_tmpfs (uid, pwent->pw_gid, dest);
-
+ if (stat(dest,&st) == -1) {
+ g_warning ("unable to stat %s, reason was: %s",dest,strerror(errno)) ;
+ errno = 0 ;
+ return NULL ;
+ }
+ /** if administrator have already set rundir, we
+ * trust him */
+ if (!S_ISDIR(st.st_mode)) {
+ /* Ensure any files from the last session are removed */
+ if (g_file_test (dest, G_FILE_TEST_EXISTS) == TRUE) {
+ remove_rundir (uid, dest);
+ }
+
+ /* Create the new directory */
+ if (g_mkdir_with_parents (dest, S_IRWXU) != 0) {
+ g_warning ("Failed to create XDG_RUNTIME_DIR, reason was: %s", strerror(errno));
+ errno = 0;
+ g_free (dest);
+ return NULL;
+ }
+
+ g_debug ("setting uid %d, gid %d", uid, pwent->pw_gid);
+
+ /* assign ownership to the user */
+ if (chown (dest, uid, pwent->pw_gid) != 0) {
+ g_warning ("Failed to chown XDG_RUNTIME_DIR, reason was: %s", strerror(errno));
+ errno = 0;
+ g_free (dest);
+ return NULL;
+ }
+
+ /* attempt to make it a small tmpfs location */
+ ck_make_tmpfs (uid, pwent->pw_gid, dest);
+ }
+
return dest;
}