Loading src/authdb.cpp +26 −11 Changes for src/authdb.cpp: 26 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ #include <grp.h> #include <sys/stat.h> #include <fcntl.h> #include <ftw.h> #endif namespace authdb { Loading Loading @@ -549,17 +550,6 @@ int main(int argc,char *argv[]){ } } /* Pre-create store directory with authdb ownership before cluster.init() creates files as root */ #ifndef _WIN32 if (!ccfg.store_path.empty() && getuid() == 0) { mkdir(ccfg.store_path.c_str(), 0755); struct passwd *pw = getpwnam("authdb"); if (pw) chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid); } #endif cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; Loading Loading @@ -592,6 +582,31 @@ int main(int argc,char *argv[]){ #ifndef _WIN32 if (getuid() == 0) { struct passwd *pw = getpwnam("authdb"); /* Recursively chown paths that were created as root */ if (pw) { auto chown_recursive = [](const char *path, uid_t uid, gid_t gid) { static uid_t s_uid; static gid_t s_gid; s_uid = uid; s_gid = gid; nftw(path, [](const char *fpath, const struct stat *, int, struct FTW *) -> int { chown(fpath, s_uid, s_gid); return 0; }, 64, FTW_PHYS); }; if (clusterEnabled) { auto *sp = config.getKey("/AUTHDB/CLUSTER/PATH"); if (sp) chown_recursive(config.getValue(sp, 0).c_str(), pw->pw_uid, pw->pw_gid); } auto *ap = config.getKey("/AUTHDB/ADMINDB/PATH"); if (ap) { const char *adminPath = config.getValue(ap, 0).c_str(); chown(adminPath, pw->pw_uid, pw->pw_gid); } } if (pw) { if (setgid(pw->pw_gid) != 0) { std::cerr << "setgid failed" << std::endl; Loading test/docker/Dockerfile +0 −1 Changes for test/docker/Dockerfile: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -56,5 +56,4 @@ COPY --from=build /usr/local/share/authdb /usr/local/share/authdb # Ports: 9090 = HTTP API, 4433 = cluster QUIC EXPOSE 9090 4433 USER authdb CMD ["authdb", "-f", "true", "-c", "yaml:///etc/authdb/config.yaml"] Loading
src/authdb.cpp +26 −11 Changes for src/authdb.cpp: 26 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ #include <grp.h> #include <sys/stat.h> #include <fcntl.h> #include <ftw.h> #endif namespace authdb { Loading Loading @@ -549,17 +550,6 @@ int main(int argc,char *argv[]){ } } /* Pre-create store directory with authdb ownership before cluster.init() creates files as root */ #ifndef _WIN32 if (!ccfg.store_path.empty() && getuid() == 0) { mkdir(ccfg.store_path.c_str(), 0755); struct passwd *pw = getpwnam("authdb"); if (pw) chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid); } #endif cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; Loading Loading @@ -592,6 +582,31 @@ int main(int argc,char *argv[]){ #ifndef _WIN32 if (getuid() == 0) { struct passwd *pw = getpwnam("authdb"); /* Recursively chown paths that were created as root */ if (pw) { auto chown_recursive = [](const char *path, uid_t uid, gid_t gid) { static uid_t s_uid; static gid_t s_gid; s_uid = uid; s_gid = gid; nftw(path, [](const char *fpath, const struct stat *, int, struct FTW *) -> int { chown(fpath, s_uid, s_gid); return 0; }, 64, FTW_PHYS); }; if (clusterEnabled) { auto *sp = config.getKey("/AUTHDB/CLUSTER/PATH"); if (sp) chown_recursive(config.getValue(sp, 0).c_str(), pw->pw_uid, pw->pw_gid); } auto *ap = config.getKey("/AUTHDB/ADMINDB/PATH"); if (ap) { const char *adminPath = config.getValue(ap, 0).c_str(); chown(adminPath, pw->pw_uid, pw->pw_gid); } } if (pw) { if (setgid(pw->pw_gid) != 0) { std::cerr << "setgid failed" << std::endl; Loading
test/docker/Dockerfile +0 −1 Changes for test/docker/Dockerfile: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -56,5 +56,4 @@ COPY --from=build /usr/local/share/authdb /usr/local/share/authdb # Ports: 9090 = HTTP API, 4433 = cluster QUIC EXPOSE 9090 4433 USER authdb CMD ["authdb", "-f", "true", "-c", "yaml:///etc/authdb/config.yaml"]