Loading data/admin.html +24 −0 Changes for data/admin.html: 24 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -533,6 +533,30 @@ function createDomainForm() { html += '<tr><td></td><td><input type="button" value="Save" onclick="submitCreateDomain()"></td></tr>'; html += '</table></form>'; setContent(html); suggestDomainValues(); } /* the name from the DC host name, the file from the name; both stay as they * are once typed in */ function suggestDomainValues() { var nameEl = document.getElementById("cd_name"); var optEl = document.getElementById("cd_options"); var dir = "/var/lib/fenrirds", optEdited = false; function suggestFile() { if (!optEl || optEdited) return; var name = nameEl.value.trim().toLowerCase().replace(/[^a-z0-9._-]/g, "-"); optEl.value = name ? dir + "/" + name + ".db" : ""; } nameEl.oninput = suggestFile; if (optEl) optEl.oninput = function() { optEdited = optEl.value !== ""; if (!optEdited) suggestFile(); }; ajaxGet("/settings/admin/api/getconfig", function(err, data) { if (err || !data) return; if (data.statedir) dir = data.statedir; var host = (data.values && data.values["DNS/HOSTNAME"]) || ""; var dot = host.indexOf("."); if (!nameEl.value && dot > 0) nameEl.value = host.substring(dot + 1); suggestFile(); }); } function submitCreateDomain() { Loading data/serverconfig.js +24 −8 Changes for data/serverconfig.js: 24 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ var ServerConfig = (function() { var SECTIONS = [ { title: "Web interface", fields: [ { key: "BIND", label: "Bind address", hint: "0.0.0.0 = all interfaces" }, { key: "PORT", label: "Port", type: "number" }, { key: "PORT", label: "Port", type: "number", def: "9090" }, { key: "MAXCONN", label: "Max. connections", type: "number" }, { key: "SSL/CERT", label: "TLS certificate", hint: "optional, a file below the config directory" }, { key: "SSL/KEY", label: "TLS key", hint: "optional, a file below the config directory" } Loading @@ -25,14 +25,27 @@ var ServerConfig = (function() { ]}, { title: "Service ports", fields: [ { key: "KDC/BIND", label: "Kerberos bind" }, { key: "KDC/PORT", label: "Kerberos port", type: "number" }, { key: "KDC/PORT", label: "Kerberos port", type: "number", def: "88" }, { key: "AD/BIND", label: "LDAP bind" }, { key: "AD/PORT", label: "LDAP port", type: "number" }, { key: "AD/PORT", label: "LDAP port", type: "number", def: "389" }, { key: "AD/MAXCONN", label: "LDAP max. connections", type: "number" }, { key: "DNS/BIND", label: "DNS bind" }, { key: "DNS/PORT", label: "DNS port", type: "number" }, { key: "DNS/PORT", label: "DNS port", type: "number", def: "53" }, { key: "SMB/BIND", label: "SMB bind" }, { key: "SMB/PORT", label: "SMB port", type: "number" } { key: "SMB/PORT", label: "SMB port", type: "number", def: "445" }, { key: "OIDC/BIND", label: "OIDC bind" }, { key: "OIDC/PORT", label: "OIDC port", type: "number", def: "9443" }, { key: "RADIUS/BIND", label: "RADIUS bind" }, { key: "RADIUS/AUTHPORT", label: "RADIUS auth port", type: "number", def: "1812" }, { key: "RADIUS/ACCTPORT", label: "RADIUS accounting port", type: "number", def: "1813" } ]}, { title: "Fixed ports", fields: [ { label: "LDAPS", type: "fixed", value: "636/tcp", hint: "with a TLS certificate" }, { label: "Global Catalog", type: "fixed", value: "3268/tcp" }, { label: "Global Catalog TLS", type: "fixed", value: "3269/tcp", hint: "with a TLS certificate" }, { label: "Kerberos password change", type: "fixed", value: "464/tcp+udp" }, { label: "RPC endpoint mapper", type: "fixed", value: "135/tcp" }, { label: "RPC", type: "fixed", value: "49152/tcp" } ]}, { title: "Replication", fields: [ { key: "REPLICATION/ROLE", label: "Role", type: "select", options: ["none", "master", "slave"] }, Loading @@ -49,7 +62,7 @@ var ServerConfig = (function() { { key: "CLUSTER/ENABLE", label: "Enabled", type: "bool", hint: "needs TLS (certificate and key above)" }, { key: "CLUSTER/BIND", label: "Bind address" }, { key: "CLUSTER/PORT", label: "Port", type: "number" }, { key: "CLUSTER/PORT", label: "Port", type: "number", def: "4433" }, { key: "CLUSTER/AUTH_NAME", label: "Auth name" }, { key: "CLUSTER/AUTH_KEY", label: "Auth key", type: "secret" }, { key: "CLUSTER/DATA_BLOCKS", label: "Data blocks", type: "number" }, Loading @@ -74,6 +87,9 @@ var ServerConfig = (function() { } function fieldHtml(f, values, secrets) { if (f.type === "fixed") return '<tr><td>' + esc(f.label) + '</td><td>' + esc(f.value) + (f.hint ? '<br><small>' + esc(f.hint) + '</small>' : '') + '</td></tr>'; var id = fid(f.key), v = values[f.key], input; if (f.type === "select") { input = '<select id="' + id + '" onchange="ServerConfig.updateRole()">'; Loading @@ -92,7 +108,7 @@ var ServerConfig = (function() { + (isSet ? ' placeholder="unchanged"' : '') + '>'; } else { input = '<input type="' + (f.type === "number" ? 'number' : 'text') + '" id="' + id + '" value="' + esc(v) + '">'; + '" value="' + esc(v) + '"' + (f.def ? ' placeholder="' + esc(f.def) + '"' : '') + '>'; } return '<tr' + (f.role ? ' class="srvcfg-role" data-role="' + f.role + '"' : '') + '>' + '<td><label for="' + id + '">' + esc(f.label) + '</label></td>' Loading Loading @@ -130,7 +146,7 @@ var ServerConfig = (function() { for (var s = 0; s < SECTIONS.length; s++) { for (var i = 0; i < SECTIONS[s].fields.length; i++) { var f = SECTIONS[s].fields[i]; if (f.role && f.role !== r) continue; if (f.type === "fixed" || (f.role && f.role !== r)) continue; var el = document.getElementById(fid(f.key)); if (!el) continue; if (f.type === "bool") Loading src/confhelper.cpp +55 −2 Changes for src/confhelper.cpp: 55 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -53,6 +53,8 @@ #include <sys/wait.h> #include <sys/time.h> #include <arpa/inet.h> #include <ifaddrs.h> #include <net/if.h> #ifdef __linux__ #include <sys/prctl.h> #endif Loading Loading @@ -101,6 +103,11 @@ namespace fenrirds::confhelper { { "DNS/ALLOW_UPDATE", UpdatePolicy, false }, { "SMB/BIND", Ip, false }, { "SMB/PORT", Port, false }, { "OIDC/BIND", Ip, false }, { "OIDC/PORT", Port, false }, { "RADIUS/BIND", Ip, false }, { "RADIUS/AUTHPORT", Port, false }, { "RADIUS/ACCTPORT", Port, false }, { "REPLICATION/ROLE", Role, false }, { "REPLICATION/NAME", Token, false }, { "REPLICATION/KEY", Secret, false }, Loading Loading @@ -133,6 +140,8 @@ namespace fenrirds::confhelper { " CLUSTER:\n" " ENABLE: \"false\"\n" " PATH: \"" STATEPATH "/cluster\"\n" " BIND: \"0.0.0.0\"\n" " PORT: 4433\n" " SSLVERIFY: \"false\"\n" " KDC:\n" " BIND: \"0.0.0.0\"\n" Loading @@ -141,6 +150,19 @@ namespace fenrirds::confhelper { " BIND: \"0.0.0.0\"\n" " PORT: 389\n" " MAXCONN: 1024\n" " DNS:\n" " BIND: \"0.0.0.0\"\n" " PORT: 53\n" " SMB:\n" " BIND: \"0.0.0.0\"\n" " PORT: 445\n" " OIDC:\n" " BIND: \"0.0.0.0\"\n" " PORT: 9443\n" " RADIUS:\n" " BIND: \"0.0.0.0\"\n" " AUTHPORT: 1812\n" " ACCTPORT: 1813\n" " REPLICATION:\n" " ROLE: \"none\"\n" " SSLVERIFY: \"false\"\n"; Loading Loading @@ -252,6 +274,33 @@ namespace fenrirds::confhelper { return s.substr(b, e - b + 1); } /* the default bind address of a new config: the first interface that * is up, not loopback and not link-local; all of them if there is none */ std::string firstAddress() { std::string addr = "0.0.0.0"; #ifndef _WIN32 struct ifaddrs *list = nullptr; if (getifaddrs(&list) != 0) return addr; for (struct ifaddrs *i = list; i; i = i->ifa_next) { if (!i->ifa_addr || i->ifa_addr->sa_family != AF_INET || !(i->ifa_flags & IFF_UP) || !(i->ifa_flags & IFF_RUNNING) || (i->ifa_flags & IFF_LOOPBACK)) continue; auto *sin = reinterpret_cast<struct sockaddr_in *>(i->ifa_addr); if ((ntohl(sin->sin_addr.s_addr) & 0xFFFF0000) == 0xA9FE0000) continue; char buf[INET_ADDRSTRLEN]; if (inet_ntop(AF_INET, &sin->sin_addr, buf, sizeof(buf))) { addr = buf; break; } } freeifaddrs(list); #endif return addr; } class ConfFile { public: explicit ConfFile(const std::string &spec) : _spec(spec) { Loading Loading @@ -364,8 +413,11 @@ namespace fenrirds::confhelper { int fd = mkstemp(tmpl); if (fd < 0) throw std::runtime_error(std::string("mkstemp: ") + strerror(errno)); size_t len = strlen(TEMPLATE); bool ok = ::write(fd, TEMPLATE, len) == (ssize_t)len; std::string text = TEMPLATE; const std::string any = "0.0.0.0", addr = firstAddress(); for (size_t at = 0; (at = text.find(any, at)) != std::string::npos; at += addr.size()) text.replace(at, any.size(), addr); bool ok = ::write(fd, text.data(), text.size()) == (ssize_t)text.size(); ::close(fd); if (!ok) { ::unlink(tmpl); Loading Loading @@ -426,6 +478,7 @@ namespace fenrirds::confhelper { json_object_object_add(jres, "ok", json_object_new_boolean(true)); json_object_object_add(jres, "exists", json_object_new_boolean(cf.exists())); json_object_object_add(jres, "path", json_object_new_string(specPath(spec).c_str())); json_object_object_add(jres, "statedir", json_object_new_string(STATEPATH)); json_object_object_add(jres, "values", jvals); json_object_object_add(jres, "secrets", jsec); return jres; Loading src/fenrirds.cpp +24 −25 Changes for src/fenrirds.cpp: 24 added lines, 25 removed lines. Original line number Diff line number Diff line Loading @@ -1454,33 +1454,32 @@ int main(int argc,char *argv[]){ if (getuid() == 0) { struct passwd *pw = getpwnam("fenrirds"); 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)) { if (chown(entry.path().c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << entry.path() << " failed: " << strerror(errno) << std::endl; } if (chown(parentDir.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << parentDir << " failed: " << strerror(errno) << std::endl; } } 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)) { if (chown(entry.path().c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << entry.path() << " failed: " << strerror(errno) << std::endl; } if (chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << ccfg.store_path << " failed: " << strerror(errno) << std::endl; } } /* lchown: these directories are the unprivileged user's, a * link in them must not hand it the target at the next start */ auto ownFile = [pw](const fs::path &p) { if (lchown(p.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << p << " failed: " << strerror(errno) << std::endl; }; auto ownTree = [&ownFile](const fs::path &dir) { if (dir.empty() || !fs::is_directory(dir)) return; for (auto &entry : fs::recursive_directory_iterator(dir)) ownFile(entry.path()); ownFile(dir); }; /* Chown data files created while running as root (e.g. blocks.bin). * The state directory also when ADMINDB is elsewhere: domains are * stored there, and a bind mount brings the owner of the host. A * domain's own path comes from the web admin and is left alone. */ std::error_code ec; fs::create_directories(STATEPATH, ec); ownTree(STATEPATH); if (!backendPath.empty()) ownTree(fs::path(backendPath).parent_path()); if (clusterEnabled) ownTree(ccfg.store_path); if (!rcfg.domain_path.empty()) { if (chown(rcfg.domain_path.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << rcfg.domain_path << " failed: " << strerror(errno) << std::endl; ownFile(rcfg.domain_path); } } } Loading Loading
data/admin.html +24 −0 Changes for data/admin.html: 24 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -533,6 +533,30 @@ function createDomainForm() { html += '<tr><td></td><td><input type="button" value="Save" onclick="submitCreateDomain()"></td></tr>'; html += '</table></form>'; setContent(html); suggestDomainValues(); } /* the name from the DC host name, the file from the name; both stay as they * are once typed in */ function suggestDomainValues() { var nameEl = document.getElementById("cd_name"); var optEl = document.getElementById("cd_options"); var dir = "/var/lib/fenrirds", optEdited = false; function suggestFile() { if (!optEl || optEdited) return; var name = nameEl.value.trim().toLowerCase().replace(/[^a-z0-9._-]/g, "-"); optEl.value = name ? dir + "/" + name + ".db" : ""; } nameEl.oninput = suggestFile; if (optEl) optEl.oninput = function() { optEdited = optEl.value !== ""; if (!optEdited) suggestFile(); }; ajaxGet("/settings/admin/api/getconfig", function(err, data) { if (err || !data) return; if (data.statedir) dir = data.statedir; var host = (data.values && data.values["DNS/HOSTNAME"]) || ""; var dot = host.indexOf("."); if (!nameEl.value && dot > 0) nameEl.value = host.substring(dot + 1); suggestFile(); }); } function submitCreateDomain() { Loading
data/serverconfig.js +24 −8 Changes for data/serverconfig.js: 24 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ var ServerConfig = (function() { var SECTIONS = [ { title: "Web interface", fields: [ { key: "BIND", label: "Bind address", hint: "0.0.0.0 = all interfaces" }, { key: "PORT", label: "Port", type: "number" }, { key: "PORT", label: "Port", type: "number", def: "9090" }, { key: "MAXCONN", label: "Max. connections", type: "number" }, { key: "SSL/CERT", label: "TLS certificate", hint: "optional, a file below the config directory" }, { key: "SSL/KEY", label: "TLS key", hint: "optional, a file below the config directory" } Loading @@ -25,14 +25,27 @@ var ServerConfig = (function() { ]}, { title: "Service ports", fields: [ { key: "KDC/BIND", label: "Kerberos bind" }, { key: "KDC/PORT", label: "Kerberos port", type: "number" }, { key: "KDC/PORT", label: "Kerberos port", type: "number", def: "88" }, { key: "AD/BIND", label: "LDAP bind" }, { key: "AD/PORT", label: "LDAP port", type: "number" }, { key: "AD/PORT", label: "LDAP port", type: "number", def: "389" }, { key: "AD/MAXCONN", label: "LDAP max. connections", type: "number" }, { key: "DNS/BIND", label: "DNS bind" }, { key: "DNS/PORT", label: "DNS port", type: "number" }, { key: "DNS/PORT", label: "DNS port", type: "number", def: "53" }, { key: "SMB/BIND", label: "SMB bind" }, { key: "SMB/PORT", label: "SMB port", type: "number" } { key: "SMB/PORT", label: "SMB port", type: "number", def: "445" }, { key: "OIDC/BIND", label: "OIDC bind" }, { key: "OIDC/PORT", label: "OIDC port", type: "number", def: "9443" }, { key: "RADIUS/BIND", label: "RADIUS bind" }, { key: "RADIUS/AUTHPORT", label: "RADIUS auth port", type: "number", def: "1812" }, { key: "RADIUS/ACCTPORT", label: "RADIUS accounting port", type: "number", def: "1813" } ]}, { title: "Fixed ports", fields: [ { label: "LDAPS", type: "fixed", value: "636/tcp", hint: "with a TLS certificate" }, { label: "Global Catalog", type: "fixed", value: "3268/tcp" }, { label: "Global Catalog TLS", type: "fixed", value: "3269/tcp", hint: "with a TLS certificate" }, { label: "Kerberos password change", type: "fixed", value: "464/tcp+udp" }, { label: "RPC endpoint mapper", type: "fixed", value: "135/tcp" }, { label: "RPC", type: "fixed", value: "49152/tcp" } ]}, { title: "Replication", fields: [ { key: "REPLICATION/ROLE", label: "Role", type: "select", options: ["none", "master", "slave"] }, Loading @@ -49,7 +62,7 @@ var ServerConfig = (function() { { key: "CLUSTER/ENABLE", label: "Enabled", type: "bool", hint: "needs TLS (certificate and key above)" }, { key: "CLUSTER/BIND", label: "Bind address" }, { key: "CLUSTER/PORT", label: "Port", type: "number" }, { key: "CLUSTER/PORT", label: "Port", type: "number", def: "4433" }, { key: "CLUSTER/AUTH_NAME", label: "Auth name" }, { key: "CLUSTER/AUTH_KEY", label: "Auth key", type: "secret" }, { key: "CLUSTER/DATA_BLOCKS", label: "Data blocks", type: "number" }, Loading @@ -74,6 +87,9 @@ var ServerConfig = (function() { } function fieldHtml(f, values, secrets) { if (f.type === "fixed") return '<tr><td>' + esc(f.label) + '</td><td>' + esc(f.value) + (f.hint ? '<br><small>' + esc(f.hint) + '</small>' : '') + '</td></tr>'; var id = fid(f.key), v = values[f.key], input; if (f.type === "select") { input = '<select id="' + id + '" onchange="ServerConfig.updateRole()">'; Loading @@ -92,7 +108,7 @@ var ServerConfig = (function() { + (isSet ? ' placeholder="unchanged"' : '') + '>'; } else { input = '<input type="' + (f.type === "number" ? 'number' : 'text') + '" id="' + id + '" value="' + esc(v) + '">'; + '" value="' + esc(v) + '"' + (f.def ? ' placeholder="' + esc(f.def) + '"' : '') + '>'; } return '<tr' + (f.role ? ' class="srvcfg-role" data-role="' + f.role + '"' : '') + '>' + '<td><label for="' + id + '">' + esc(f.label) + '</label></td>' Loading Loading @@ -130,7 +146,7 @@ var ServerConfig = (function() { for (var s = 0; s < SECTIONS.length; s++) { for (var i = 0; i < SECTIONS[s].fields.length; i++) { var f = SECTIONS[s].fields[i]; if (f.role && f.role !== r) continue; if (f.type === "fixed" || (f.role && f.role !== r)) continue; var el = document.getElementById(fid(f.key)); if (!el) continue; if (f.type === "bool") Loading
src/confhelper.cpp +55 −2 Changes for src/confhelper.cpp: 55 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -53,6 +53,8 @@ #include <sys/wait.h> #include <sys/time.h> #include <arpa/inet.h> #include <ifaddrs.h> #include <net/if.h> #ifdef __linux__ #include <sys/prctl.h> #endif Loading Loading @@ -101,6 +103,11 @@ namespace fenrirds::confhelper { { "DNS/ALLOW_UPDATE", UpdatePolicy, false }, { "SMB/BIND", Ip, false }, { "SMB/PORT", Port, false }, { "OIDC/BIND", Ip, false }, { "OIDC/PORT", Port, false }, { "RADIUS/BIND", Ip, false }, { "RADIUS/AUTHPORT", Port, false }, { "RADIUS/ACCTPORT", Port, false }, { "REPLICATION/ROLE", Role, false }, { "REPLICATION/NAME", Token, false }, { "REPLICATION/KEY", Secret, false }, Loading Loading @@ -133,6 +140,8 @@ namespace fenrirds::confhelper { " CLUSTER:\n" " ENABLE: \"false\"\n" " PATH: \"" STATEPATH "/cluster\"\n" " BIND: \"0.0.0.0\"\n" " PORT: 4433\n" " SSLVERIFY: \"false\"\n" " KDC:\n" " BIND: \"0.0.0.0\"\n" Loading @@ -141,6 +150,19 @@ namespace fenrirds::confhelper { " BIND: \"0.0.0.0\"\n" " PORT: 389\n" " MAXCONN: 1024\n" " DNS:\n" " BIND: \"0.0.0.0\"\n" " PORT: 53\n" " SMB:\n" " BIND: \"0.0.0.0\"\n" " PORT: 445\n" " OIDC:\n" " BIND: \"0.0.0.0\"\n" " PORT: 9443\n" " RADIUS:\n" " BIND: \"0.0.0.0\"\n" " AUTHPORT: 1812\n" " ACCTPORT: 1813\n" " REPLICATION:\n" " ROLE: \"none\"\n" " SSLVERIFY: \"false\"\n"; Loading Loading @@ -252,6 +274,33 @@ namespace fenrirds::confhelper { return s.substr(b, e - b + 1); } /* the default bind address of a new config: the first interface that * is up, not loopback and not link-local; all of them if there is none */ std::string firstAddress() { std::string addr = "0.0.0.0"; #ifndef _WIN32 struct ifaddrs *list = nullptr; if (getifaddrs(&list) != 0) return addr; for (struct ifaddrs *i = list; i; i = i->ifa_next) { if (!i->ifa_addr || i->ifa_addr->sa_family != AF_INET || !(i->ifa_flags & IFF_UP) || !(i->ifa_flags & IFF_RUNNING) || (i->ifa_flags & IFF_LOOPBACK)) continue; auto *sin = reinterpret_cast<struct sockaddr_in *>(i->ifa_addr); if ((ntohl(sin->sin_addr.s_addr) & 0xFFFF0000) == 0xA9FE0000) continue; char buf[INET_ADDRSTRLEN]; if (inet_ntop(AF_INET, &sin->sin_addr, buf, sizeof(buf))) { addr = buf; break; } } freeifaddrs(list); #endif return addr; } class ConfFile { public: explicit ConfFile(const std::string &spec) : _spec(spec) { Loading Loading @@ -364,8 +413,11 @@ namespace fenrirds::confhelper { int fd = mkstemp(tmpl); if (fd < 0) throw std::runtime_error(std::string("mkstemp: ") + strerror(errno)); size_t len = strlen(TEMPLATE); bool ok = ::write(fd, TEMPLATE, len) == (ssize_t)len; std::string text = TEMPLATE; const std::string any = "0.0.0.0", addr = firstAddress(); for (size_t at = 0; (at = text.find(any, at)) != std::string::npos; at += addr.size()) text.replace(at, any.size(), addr); bool ok = ::write(fd, text.data(), text.size()) == (ssize_t)text.size(); ::close(fd); if (!ok) { ::unlink(tmpl); Loading Loading @@ -426,6 +478,7 @@ namespace fenrirds::confhelper { json_object_object_add(jres, "ok", json_object_new_boolean(true)); json_object_object_add(jres, "exists", json_object_new_boolean(cf.exists())); json_object_object_add(jres, "path", json_object_new_string(specPath(spec).c_str())); json_object_object_add(jres, "statedir", json_object_new_string(STATEPATH)); json_object_object_add(jres, "values", jvals); json_object_object_add(jres, "secrets", jsec); return jres; Loading
src/fenrirds.cpp +24 −25 Changes for src/fenrirds.cpp: 24 added lines, 25 removed lines. Original line number Diff line number Diff line Loading @@ -1454,33 +1454,32 @@ int main(int argc,char *argv[]){ if (getuid() == 0) { struct passwd *pw = getpwnam("fenrirds"); 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)) { if (chown(entry.path().c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << entry.path() << " failed: " << strerror(errno) << std::endl; } if (chown(parentDir.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << parentDir << " failed: " << strerror(errno) << std::endl; } } 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)) { if (chown(entry.path().c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << entry.path() << " failed: " << strerror(errno) << std::endl; } if (chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << ccfg.store_path << " failed: " << strerror(errno) << std::endl; } } /* lchown: these directories are the unprivileged user's, a * link in them must not hand it the target at the next start */ auto ownFile = [pw](const fs::path &p) { if (lchown(p.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << p << " failed: " << strerror(errno) << std::endl; }; auto ownTree = [&ownFile](const fs::path &dir) { if (dir.empty() || !fs::is_directory(dir)) return; for (auto &entry : fs::recursive_directory_iterator(dir)) ownFile(entry.path()); ownFile(dir); }; /* Chown data files created while running as root (e.g. blocks.bin). * The state directory also when ADMINDB is elsewhere: domains are * stored there, and a bind mount brings the owner of the host. A * domain's own path comes from the web admin and is left alone. */ std::error_code ec; fs::create_directories(STATEPATH, ec); ownTree(STATEPATH); if (!backendPath.empty()) ownTree(fs::path(backendPath).parent_path()); if (clusterEnabled) ownTree(ccfg.store_path); if (!rcfg.domain_path.empty()) { if (chown(rcfg.domain_path.c_str(), pw->pw_uid, pw->pw_gid) != 0) std::cerr << "chown " << rcfg.domain_path << " failed: " << strerror(errno) << std::endl; ownFile(rcfg.domain_path); } } } Loading