Commit 83bc0e42 authored by jan.koester's avatar jan.koester
Browse files

test

parent d2d44bcc
Loading
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <mutex>
#include <shared_mutex>
#include <fstream>
#include <filesystem>
#include <thread>
#include <map>
#include <memory>
@@ -756,6 +757,26 @@ int main(int argc,char *argv[]){
        if (getuid() == 0) {
            struct passwd *pw = getpwnam("authdb");
            if (pw) {
                /* Chown data files created while running as root (e.g. blocks.bin) */
                if (!backendPath.empty()) {
                    namespace fs = std::filesystem;
                    fs::path parentDir = fs::path(backendPath).parent_path();
                    if (fs::is_directory(parentDir)) {
                        for (auto &entry : fs::recursive_directory_iterator(parentDir)) {
                            chown(entry.path().c_str(), pw->pw_uid, pw->pw_gid);
                        }
                        chown(parentDir.c_str(), pw->pw_uid, pw->pw_gid);
                    }
                }
                if (clusterEnabled && !ccfg.store_path.empty()) {
                    namespace fs = std::filesystem;
                    if (fs::is_directory(ccfg.store_path)) {
                        for (auto &entry : fs::recursive_directory_iterator(ccfg.store_path)) {
                            chown(entry.path().c_str(), pw->pw_uid, pw->pw_gid);
                        }
                        chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid);
                    }
                }
                if (setgid(pw->pw_gid) != 0) {
                    std::cerr << "setgid failed" << std::endl;
                    return 1;