}
}
+void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB, const fs::path& contents_path)
+{
+ const auto child_pid = OS::throwing_fork();
+ if (child_pid == 0) {
+ const auto mkfs = "/usr/sbin/mkfs.ext2"sv;
+
+ /* Would ideally be std::format instead of this ugly stack,
+ * but some important downstream forks use obsolete gcc. */
+ std::string owner_arg = "root_owner=";
+ owner_arg += std::to_string(uid);
+ owner_arg += ":";
+ owner_arg += std::to_string(gid);
+
+ std::string size_arg = std::to_string(size_kB);
+
+ execl
+ ( mkfs.data(), mkfs.data() /* argv[0] convention */
+ , "-E", owner_arg.c_str()
+ , "-m", "0"
+ , "-d", contents_path.c_str()
+ , image_path.c_str()
+ , size_arg.c_str()
+ , (char *) NULL
+ );
+
+ _exit(1);
+ } else {
+ OS::throw_if_child_failed(child_pid, "mkfs.ext2 failed!");
+ }
+}
+
+
void do_mount(const fs::path& image_path, const fs::path& mount_path)
{
/* Don't just call mount() since there's some extra steps involved
bool switch_user_subsession(const int session_uid, const std::string_view prev_subsession, const std::string_view next_subsession);
std::vector<std::string> get_user_list(const int session_uid);
void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB);
+void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB, const fs::path& contents_path);
void do_mount(const fs::path& image_path, const fs::path& mount_path);
void do_umount(const fs::path& path);
void umount_and_remove (const fs::path& path);
dlog
capi-system-info
libxml-2.0
+ libsmack
pkgmgr-info
)
TARGET_COMPILE_OPTIONS(libsessiond-update-skelimg PUBLIC -fPIC ${deps_CFLAGS})
TARGET_LINK_LIBRARIES(libsessiond-update-skelimg PRIVATE ${deps_LDFLAGS})
-ADD_EXECUTABLE(sessiond-update-skelimg helper.cpp)
+ADD_EXECUTABLE(sessiond-update-skelimg helper.cpp ../service/src/os_ops.cpp ../service/src/fs_helpers.cpp ../service/src/dir_backend_fixed_size.cpp ../service/src/dir_backend_regular_dir.cpp)
+INCLUDE_DIRECTORIES(../library/include ../common/include)
+TARGET_COMPILE_FEATURES(sessiond-update-skelimg PUBLIC cxx_std_20)
TARGET_COMPILE_OPTIONS(sessiond-update-skelimg PUBLIC -fPIC -fPIE ${deps_CFLAGS})
TARGET_INCLUDE_DIRECTORIES(sessiond-update-skelimg PRIVATE ../service/src)
TARGET_LINK_LIBRARIES(sessiond-update-skelimg PRIVATE ${deps_LDFLAGS})
+#include <filesystem>
+#include <iostream>
+
#include "fs_helpers.hpp"
+#include "os_ops.hpp"
+
+namespace fs = std::filesystem;
+
+using namespace std;
+
+int main(int argc, char **argv) {
+
+ int r = 0;
+
+ try {
+ fs::current_path("/opt/usr/home");
+ } catch (std::exception& ex) {
+ std::cerr << "Unable to chdir to HOME. Can not continue" << std::endl;
+ }
+
+ for (auto const& entry : fs::directory_iterator(".")) {
+ if (!fs::is_directory(entry.status()))
+ continue;
+
+ const auto &username = entry.path().filename();
+
+ fs::path skel_path = ".etc-skel-";
+ skel_path += username;
+ skel_path += ".img";
+ fs::path skel_tmp_path = skel_path;
+ skel_tmp_path += ".tmp";
+
+ const int username_uid = OS::get_uid_from_name(username.string());
+ const int system_share_gid = OS::get_gid_from_name(system_share_group);
+
+ try {
+ do_mkfs(skel_tmp_path, username_uid, system_share_gid, 10000, "/etc/skel");
+ fs::rename(skel_tmp_path, skel_path);
+ } catch (const std::exception& ex) {
+ std::cerr << "Caught exception " << ex.what() << std::endl;
+ r = 1;
+ }
+ }
-int main(int argc, char **argv)
-{
- return 0;
+ return r;
}