Loading src/blogi.cpp +49 −0 Changes for src/blogi.cpp: 49 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3759,6 +3759,51 @@ static std::string stripConfigPrefix(const std::string &configPath) return configPath.substr(5); return configPath; } static void ensureConfigGroupWritable(const std::string &configPath) { const std::string path = stripConfigPrefix(configPath); if (path.empty()) return; struct group *grp = getgrnam("blogi"); if (!grp) { std::cerr << "Warning: group 'blogi' not found, cannot adjust config permissions." << std::endl; return; } std::filesystem::path fsPath(path); std::error_code ec; if (fsPath.has_parent_path()) { const std::string parent = fsPath.parent_path().string(); struct stat dirStat; if (stat(parent.c_str(), &dirStat) == 0) { mode_t dirMode = dirStat.st_mode | S_IRGRP | S_IWGRP | S_IXGRP | S_ISGID; if (chown(parent.c_str(), static_cast<uid_t>(-1), grp->gr_gid) != 0) std::cerr << "Warning: cannot set group on config directory '" << parent << "': " << strerror(errno) << std::endl; if (chmod(parent.c_str(), dirMode) != 0) std::cerr << "Warning: cannot chmod config directory '" << parent << "': " << strerror(errno) << std::endl; } } struct stat fileStat; if (stat(path.c_str(), &fileStat) == 0) { mode_t fileMode = fileStat.st_mode | S_IRGRP | S_IWGRP; if (chown(path.c_str(), static_cast<uid_t>(-1), grp->gr_gid) != 0) std::cerr << "Warning: cannot set group on config file '" << path << "': " << strerror(errno) << std::endl; if (chmod(path.c_str(), fileMode) != 0) std::cerr << "Warning: cannot chmod config file '" << path << "': " << strerror(errno) << std::endl; } else { std::cerr << "Warning: config file not found for permission adjustment: " << path << std::endl; } } #endif #ifndef Windows Loading Loading @@ -3809,10 +3854,14 @@ int main(int argc, char *argv[]) try { if (getuid() == 0) { if (!fground) { logFiles("/var/log/blogi/access.log",STDOUT_FILENO); logFiles("/var/log/blogi/error.log",STDERR_FILENO); } ensureConfigGroupWritable(config); } } catch (std::exception &e) { Loading Loading
src/blogi.cpp +49 −0 Changes for src/blogi.cpp: 49 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3759,6 +3759,51 @@ static std::string stripConfigPrefix(const std::string &configPath) return configPath.substr(5); return configPath; } static void ensureConfigGroupWritable(const std::string &configPath) { const std::string path = stripConfigPrefix(configPath); if (path.empty()) return; struct group *grp = getgrnam("blogi"); if (!grp) { std::cerr << "Warning: group 'blogi' not found, cannot adjust config permissions." << std::endl; return; } std::filesystem::path fsPath(path); std::error_code ec; if (fsPath.has_parent_path()) { const std::string parent = fsPath.parent_path().string(); struct stat dirStat; if (stat(parent.c_str(), &dirStat) == 0) { mode_t dirMode = dirStat.st_mode | S_IRGRP | S_IWGRP | S_IXGRP | S_ISGID; if (chown(parent.c_str(), static_cast<uid_t>(-1), grp->gr_gid) != 0) std::cerr << "Warning: cannot set group on config directory '" << parent << "': " << strerror(errno) << std::endl; if (chmod(parent.c_str(), dirMode) != 0) std::cerr << "Warning: cannot chmod config directory '" << parent << "': " << strerror(errno) << std::endl; } } struct stat fileStat; if (stat(path.c_str(), &fileStat) == 0) { mode_t fileMode = fileStat.st_mode | S_IRGRP | S_IWGRP; if (chown(path.c_str(), static_cast<uid_t>(-1), grp->gr_gid) != 0) std::cerr << "Warning: cannot set group on config file '" << path << "': " << strerror(errno) << std::endl; if (chmod(path.c_str(), fileMode) != 0) std::cerr << "Warning: cannot chmod config file '" << path << "': " << strerror(errno) << std::endl; } else { std::cerr << "Warning: config file not found for permission adjustment: " << path << std::endl; } } #endif #ifndef Windows Loading Loading @@ -3809,10 +3854,14 @@ int main(int argc, char *argv[]) try { if (getuid() == 0) { if (!fground) { logFiles("/var/log/blogi/access.log",STDOUT_FILENO); logFiles("/var/log/blogi/error.log",STDERR_FILENO); } ensureConfigGroupWritable(config); } } catch (std::exception &e) { Loading