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));
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);
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);
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);
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,
}
}
-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)
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;
}
}
-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);
#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);