debug: generate skel: Print my own creds sandbox/klewandowski/generate-skel3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 21 May 2025 09:18:34 +0000 (11:18 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 21 May 2025 09:19:14 +0000 (11:19 +0200)
Change-Id: I4960abf2e83ce00fe17f1047d148fabb06791bed

src/service/src/main_skel.cpp

index ecaab847c12fb1b37fcdc6a9ba1f5c8250d277fe..d17bce2317354e8d31c9108c60f2221d00b66bac 100644 (file)
@@ -26,6 +26,8 @@
 #undef LOG_TAG
 #define LOG_TAG "SESSIOND_REGENERATE_SKEL"
 #include <dlog.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #include "fs_helpers.hpp"
 #include "os_ops.hpp"
@@ -35,8 +37,24 @@ namespace fs = std::filesystem;
 
 constexpr auto TEMPLATE_IMAGE_SIZE_KB = 10240;
 
+void print_creds(void)
+{
+       int fd = open("/proc/self/attr/current", O_RDONLY);
+       char buf[3084] = {0, };
+       int r = read(fd, buf, sizeof(buf));
+       if (r >= sizeof(buf))
+               buf[sizeof(buf) - 1] = 0;
+       else if (r > 0)
+               buf[r] = 0;
+
+       LOGW("Starting with creds: uid: %d, euid: %d, gid: %d, egid: %d, label: %s", getuid(), geteuid(), getgid(), getegid(), buf);
+}
+
+
 int regenerate_skel()
 {
+       print_creds();
+
        try {
                fs::current_path("/opt/usr/home");
        } catch (const std::exception& ex) {