Fix logic for set Home directory's smack label 56/107056/3
authorYunmi Ha <yunmi.ha@samsung.com>
Mon, 26 Dec 2016 09:09:28 +0000 (18:09 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Mon, 2 Jan 2017 02:21:43 +0000 (11:21 +0900)
Home directory's smack should be different with skel folder.
After copy file attributes from skel folder,
set home directory's own smack label.
(This can be set using gumd.config)

Change-Id: Ie9532f3e011968d32a05947eeb4d3ab4987ec75f
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/common/gum-file.c

index abfc2d9..4491c72 100755 (executable)
 static gboolean
 _set_smack64_attr (
         const gchar *path,
-        const gchar *key)
+        const gchar *key,
+        gboolean transmute)
 {
 #if defined(HAVE_LSETXATTR)
     GumConfig *config = NULL;
@@ -134,6 +135,12 @@ _set_smack64_attr (
         g_object_unref (config);
         return FALSE;
     }
+
+    if (transmute &&
+        lsetxattr(path, XATTR_NAME_SMACKTRANSMUTE, "TRUE", strlen("TRUE"), 0) != 0) {
+        g_object_unref (config);
+        return FALSE;
+    }
     g_object_unref (config);
 #endif
     return TRUE;
@@ -257,7 +264,7 @@ gum_file_open_db_files (
     }
 
     if (!_set_smack64_attr (dup_file_path,
-            GUM_CONFIG_GENERAL_SMACK64_NEW_FILES)) {
+            GUM_CONFIG_GENERAL_SMACK64_NEW_FILES, FALSE)) {
         GUM_SET_ERROR (GUM_ERROR_FILE_ATTRIBUTE,
                  "Unable to set smack file attributes", error, retval, FALSE);
         goto _fail;
@@ -740,7 +747,7 @@ _copy_dir_recursively (
             gint mode = GUM_PERM & ~umask;
             g_mkdir_with_parents (dest_filepath, mode);
             stop = !_set_smack64_attr (dest_filepath,
-                    GUM_CONFIG_GENERAL_SMACK64_USER_FILES);
+                    GUM_CONFIG_GENERAL_SMACK64_USER_FILES, FALSE);
             if (!stop)
                 stop = !_copy_dir_recursively (src_filepath, dest_filepath, uid,
                     gid, umask, NULL);
@@ -756,7 +763,7 @@ _copy_dir_recursively (
                 goto _free_data;
             }
             stop = !_set_smack64_attr (dest_filepath,
-                    GUM_CONFIG_GENERAL_SMACK64_USER_FILES);
+                    GUM_CONFIG_GENERAL_SMACK64_USER_FILES, FALSE);
         }
         if (!stop) stop = !_copy_file_attributes (src_filepath, dest_filepath);
         if (!stop) stop = (lchown (dest_filepath, uid, gid) < 0);
@@ -823,15 +830,15 @@ gum_file_create_home_dir (
                     "Home directory creation failure", error, FALSE);
         }
 
-        if (!_set_smack64_attr (home_dir,
-                GUM_CONFIG_GENERAL_SMACK64_USER_FILES)) {
+        if (!_copy_file_attributes (skel_dir, home_dir)) {
             GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_ATTRIBUTE,
-                     "Unable to set smack64 home dir attr", error, FALSE);
+                    "Unable to get/set dir attributes", error, FALSE);
         }
 
-        if (!_copy_file_attributes (skel_dir, home_dir)) {
+        if (!_set_smack64_attr (home_dir,
+                GUM_CONFIG_GENERAL_SMACK64_USER_FILES, TRUE)) {
             GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_ATTRIBUTE,
-                    "Unable to get/set dir attributes", error, FALSE);
+                     "Unable to set smack64 home dir attr", error, FALSE);
         }
 
         /* when run in test mode, user may not exist */
@@ -846,9 +853,9 @@ gum_file_create_home_dir (
 
         retval = _copy_dir_recursively (skel_dir, home_dir, uid, gid, umask,
                 error);
-       }
+    }
 
-       return retval;
+    return retval;
 }
 
 /**