#include <grp.h>
#include <pwd.h>
#include <sys/smack.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
return std::string(pass_ptr->pw_dir);
}
+void fs_helpers::copy_ownership(std::string_view src_path, std::string_view dest_path)
+{
+ struct stat info;
+ int ret = stat(src_path.data(), &info);
+
+ if (ret)
+ throw std::system_error(errno, std::system_category(),
+ std::string("Couldn't stat `")
+ + src_path.data()
+ + "` file/directory");
+
+ if (chown(dest_path.data(), info.st_uid, info.st_gid) == -1)
+ throw std::system_error(errno, std::system_category(),
+ std::string("Couldn't set owner/group of the `")
+ + dest_path.data()
+ + "` file/directory");
+}
+
void fs_helpers::copy_smack_attributes(const std::string &src_path, const std::string &dest_path)
{
static const enum smack_label_type label_types[] = {
| fs::copy_options::copy_symlinks
);
- // Copy SMACK attributes for `apps_rw/*` subdirectories
+ // Copy ownership and SMACK attributes for `apps_rw/*` subdirectories & files
for (auto const& entry : fs::recursive_directory_iterator(source_dir)) {
std::string s_path = entry.path();
tmp_path.erase(0, source_dir_len);
std::string d_path = apps_rw_tmp_dir + tmp_path;
+ copy_ownership(s_path, d_path);
copy_smack_attributes(s_path, d_path);
}
// Last but not least - the `apps_rw` directory itself
+ copy_ownership(source_dir, apps_rw_tmp_dir);
copy_smack_attributes(source_dir, apps_rw_tmp_dir);
// Copy + rename so that the replacement is atomic
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 copy_ownership(std::string_view src_path, std::string_view dest_path);
void copy_smack_attributes(const std::string &src_path, const std::string &dest_path);
void add_user_subsession(const int session_uid, const int subsession_id);
void remove_user_subsession(const int session_uid, const int subsession_id);