set(CMAKE_SHARED_LIBRARY_PREFIX "")
# Needed for ASLR to work
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIE -Wno-error=shadow -Werror=missing-field-initializers")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIE -Wno-error=shadow -Werror=missing-field-initializers")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIE -Wno-error=shadow -Werror=missing-field-initializers -fconcepts")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIE -Wno-error=shadow -Werror=missing-field-initializers -fconcepts")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
add_subdirectory(common)
return out_str;
}
+int fs_helpers::copy_label(auto label, auto dest_path, auto type)
+{
+ if (type != SMACK_LABEL_TRANSMUTE)
+ return smack_lsetlabel(dest_path.data(), label.c_str(), type);
+
+ /* Setting TRANSMUTE attribute needs special attention:
+ * the only correct values are: NULL, "", "0" or "1" */
+ if (label == "TRUE")
+ return smack_lsetlabel(dest_path.data(), "1", type);
+
+ /* N.B. This is a bit tricky. Since TRANSMUTE attribute is inheritable,
+ * it is possible that it was set to TRUE while copying the files from
+ * /etc/skel, but originally it wasn't there in the source directory for
+ * some subdirectories/files. Therefore it must be removed explicitly. */
+ int ret = smack_lsetlabel(dest_path.data(), "0", type);
+ if (ret == -1 && errno == ENODATA) {
+ /* We tried to drop the label, but it already didn't exist,
+ * so the "error" is expected and not a problem. */
+ return 0;
+ }
+
+ return ret;
+}
+
void fs_helpers::copy_smack_attributes(std::string_view src_path, std::string_view dest_path)
{
static const enum smack_label_type label_types[] = {
for (const auto type : label_types) {
auto label = get_smack_label(src_path, type);
- int ret = 0;
-
- if (type == SMACK_LABEL_TRANSMUTE) {
- // N.B. Setting TRANSMUTE attribute needs special attention:
- // the only correct values are: NULL, "", "0" or "1".
- if (label == "TRUE")
- ret = smack_lsetlabel(dest_path.data(), "1", type);
- }
- else
- ret = smack_lsetlabel(dest_path.data(), label.c_str(), type);
- if (ret)
+ if (copy_label(label, dest_path, type))
throw std::runtime_error(
"Couldn't set SMACK attributes of destination directory: "s +
dest_path.data());
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);