void copy_ownership(std::string_view src_path, std::string_view dest_path)
{
struct stat info;
- int ret = stat(src_path.data(), &info);
+ int ret = lstat(src_path.data(), &info);
if (ret)
throw std::system_error(errno, std::system_category(),
{
try {
std::string home_dir = get_home_dir_by_user_id(session_uid);
- std::string main_dir = std::move(home_dir) + "/" + main_dir_name.data();
+ std::string main_dir = home_dir + "/" + main_dir_name.data();
create_main_subdirectory(session_uid, main_dir);
| fs::copy_options::copy_symlinks
);
- // Copy SMACK attributes for `apps_rw/*` subdirectories & files
- // but set [user]:[group] to `session_uid`:users
- int users_gid = get_gid_from_name("users");
-
+ /* Copy SMACK attributes for `apps_rw/*` subdirectories & files
+ * but set [user]:[group] to the corresponding homedir's
+ * `apps_rw/*` subdirectory permissions */
for (auto const& entry : fs::recursive_directory_iterator(source_dir)) {
std::string s_path = entry.path();
std::string tmp_path = s_path;
tmp_path.erase(0, source_dir_len);
+
+ std::string u_path = home_dir + "/apps_rw" + tmp_path;
std::string d_path = apps_rw_dir + std::move(tmp_path);
- change_owner_and_group(d_path, session_uid, users_gid);
+ copy_ownership(u_path, d_path);
copy_smack_attributes(s_path, d_path);
}