sessiond: Add privacy to the `fs_helpers` module 13/281013/2
authorAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 7 Sep 2022 16:08:39 +0000 (18:08 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Thu, 8 Sep 2022 10:16:51 +0000 (12:16 +0200)
Change-Id: Iebce977b981135a85bd22d61cddd016d39376aa4

src/service/src/fs_helpers.cpp
src/service/src/fs_helpers.hpp

index 2fa7a6753308928349cad238bf849eeb25b3bfec..de2cf58223d413806c9f8602467b83f08d649541 100644 (file)
@@ -43,7 +43,7 @@
 namespace fs = std::filesystem;
 using namespace std::string_literals;
 
-std::string get_home_dir_by_user_id(const int uid)
+static std::string get_home_dir_by_user_id(const int uid)
 {
        auto max_buf_size = static_cast<ssize_t>(sysconf(_SC_GETPW_R_SIZE_MAX));
        std::runtime_error err("Couldn't get home directory for session_uid=" + std::to_string(uid));
@@ -64,7 +64,16 @@ std::string get_home_dir_by_user_id(const int uid)
        return std::string(pass_ptr->pw_dir);
 }
 
-void copy_ownership(std::string_view src_path, std::string_view dest_path)
+static void change_owner_and_group(std::string_view path, const int session_uid, const int group_id)
+{
+       if (lchown(path.data(), session_uid, group_id) == -1)
+               throw std::system_error(errno, std::system_category(),
+                       "Couldn't set owner/group of the `"s
+                       + path.data()
+                       + "` file/directory");
+}
+
+static void copy_ownership(std::string_view src_path, std::string_view dest_path)
 {
        struct stat info;
        int ret = lstat(src_path.data(), &info);
@@ -78,7 +87,7 @@ void copy_ownership(std::string_view src_path, std::string_view dest_path)
        change_owner_and_group(dest_path, info.st_uid, info.st_gid);
 }
 
-std::string get_smack_label(std::string_view src_path, smack_label_type type)
+static std::string get_smack_label(std::string_view src_path, smack_label_type type)
 {
        char *label_raw = nullptr;
        int ret = smack_lgetlabel(src_path.data(), &label_raw, type);
@@ -99,7 +108,7 @@ std::string get_smack_label(std::string_view src_path, smack_label_type type)
        return out_str;
 }
 
-int copy_label(auto label, auto dest_path, auto type)
+static int copy_label(auto label, auto dest_path, auto type)
 {
        if (type != SMACK_LABEL_TRANSMUTE)
                return smack_lsetlabel(dest_path.data(), label.c_str(), type);
@@ -123,7 +132,7 @@ int copy_label(auto label, auto dest_path, auto type)
        return ret;
 }
 
-void copy_smack_attributes(std::string_view src_path, std::string_view dest_path)
+static void copy_smack_attributes(std::string_view src_path, std::string_view dest_path)
 {
        static const enum smack_label_type label_types[] = {
                SMACK_LABEL_ACCESS,
@@ -140,7 +149,7 @@ void copy_smack_attributes(std::string_view src_path, std::string_view dest_path
        }
 }
 
-int get_gid_from_name(std::string_view group_name)
+static int get_gid_from_name(std::string_view group_name)
 {
        auto max_grp_buf_size = static_cast<ssize_t>(sysconf(_SC_GETGR_R_SIZE_MAX));
        if (max_grp_buf_size <= 0)
@@ -157,17 +166,8 @@ int get_gid_from_name(std::string_view group_name)
        return pass_grp_ptr->gr_gid;
 }
 
-void change_owner_and_group(std::string_view path, const int session_uid, const int group_id)
-{
-       if (lchown(path.data(), session_uid, group_id) == -1)
-               throw std::system_error(errno, std::system_category(),
-                       "Couldn't set owner/group of the `"s
-                       + path.data()
-                       + "` file/directory");
-}
-
 // Create `$HOME/subsession` directory if it doesn't exist
-void create_main_subdirectory(const int session_uid, std::string_view main_dir)
+static void create_main_subdirectory(const int session_uid, std::string_view main_dir)
 {
        if (fs::exists(main_dir))
                return;
@@ -311,7 +311,7 @@ void remove_user_subsession(const int session_uid, const std::string_view subses
        }
 }
 
-fs::path get_subsession_dir_by_uid(const int session_uid)
+static fs::path get_subsession_dir_by_uid(const int session_uid)
 {
        std::string home_dir = get_home_dir_by_user_id(session_uid);
 
index b2a133f1b41e99c085937750e061c3e8a2d302cd..6c2209d7ef96b8eac07ffb80ad48255e4e6f35d9 100644 (file)
@@ -6,18 +6,6 @@
 #include <string_view>
 #include <vector>
 
-namespace fs = std::filesystem;
-
-std::string get_home_dir_by_user_id(const int uid);
-int get_gid_from_name(std::string_view group_name);
-fs::path get_subsession_dir_by_uid(const int session_uid);
-
-void create_main_subdirectory(const int session_uid, std::string_view main_dir);
-void change_owner_and_group(std::string_view path, const int session_uid, const int group_id);
-void copy_ownership(std::string_view src_path, std::string_view dest_path);
-std::string get_smack_label(std::string_view src_path, smack_label_type type);
-int copy_label(auto label, auto dest_path, auto type);
-void copy_smack_attributes(std::string_view src_path, std::string_view dest_path);
 bool subsession_exists(const int session_uid, const std::string_view subsession_id);
 void add_user_subsession(const int session_uid, const std::string_view subsession_id);
 void remove_user_subsession(const int session_uid, const std::string_view subsession_id);