From: Adam Michalski Date: Wed, 7 Sep 2022 16:08:39 +0000 (+0200) Subject: sessiond: Add privacy to the `fs_helpers` module X-Git-Tag: submit/tizen/20220913.195454~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca9eebe38d1f958dd5a79dba2151f8bf4c636658;p=platform%2Fcore%2Fsystem%2Fsessiond.git sessiond: Add privacy to the `fs_helpers` module Change-Id: Iebce977b981135a85bd22d61cddd016d39376aa4 --- diff --git a/src/service/src/fs_helpers.cpp b/src/service/src/fs_helpers.cpp index 2fa7a67..de2cf58 100644 --- a/src/service/src/fs_helpers.cpp +++ b/src/service/src/fs_helpers.cpp @@ -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(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(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); diff --git a/src/service/src/fs_helpers.hpp b/src/service/src/fs_helpers.hpp index b2a133f..6c2209d 100644 --- a/src/service/src/fs_helpers.hpp +++ b/src/service/src/fs_helpers.hpp @@ -6,18 +6,6 @@ #include #include -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);