Commit de89f1d1 authored by jan.koester's avatar jan.koester
Browse files

test

parent a5c51a9a
Loading
Loading
Loading
Loading
+39 −1
Changes for src/blogi.cpp: 39 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3023,6 +3023,44 @@ 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
@@ -3066,7 +3104,7 @@ int main(int argc, char* argv[]) {
        if(debug==0){
            // Running as root: set up logfiles, optionally daemonize, and
            // let HttpConD drop privileges to the blogi user afterwards.

            ensureConfigGroupWritable(config);
            logFiles("/var/log/blogi/access.log",STDOUT_FILENO);
            logFiles("/var/log/blogi/error.log",STDERR_FILENO);

+0 −26
Changes for src/conf.cpp: 0 added lines, 26 removed lines.
Original line number Diff line number Diff line
@@ -30,32 +30,6 @@
#include "conf.h"

blogi::Config::Config(const std::string &path) : confplus::Config(path), _ConfigPath(path){
    try {
        for(size_t i =0; i<getElements(getKey("/BLOGI/PLUGINDIR")); ++i){
           _PlgDir.push_back(getValue(getKey("/BLOGI/PLUGINDIR"),i));
        }
    } catch(...) {}

    try { _DBDriver=getValue(getKey("/BLOGI/DATABASE/DRIVER"),0); } catch(...) {}
    try { _DBConnection=getValue(getKey("/BLOGI/DATABASE/CONNECTION"),0); } catch(...) {}

    // Parse global database replicas
    try {
        auto *repKey = getKey("/BLOGI/DATABASE/REPLICAS");
        size_t repCount = getElements(repKey);
        for (size_t i = 0; i < repCount; ++i) {
            ReplicaConfig rc;
            std::string repBase = "/BLOGI/DATABASE/REPLICAS/" + std::to_string(i);
            try { rc.driver = getValue(getKey((repBase + "/DRIVER").c_str()), 0); } catch(...) { rc.driver = _DBDriver; }
            try { rc.connection = getValue(getKey((repBase + "/CONNECTION").c_str()), 0); } catch(...) { continue; }
            _DBReplicas.push_back(std::move(rc));
        }
    } catch(...) {}

    try { _AuthUrl=getValue(getKey("/BLOGI/AUTHDB/URL"),0); } catch(...) {}
    try { _ClientName=getValue(getKey("/BLOGI/AUTHDB/CLIENTNAME"),0); } catch(...) {}
    try { _ClientSecret=getValue(getKey("/BLOGI/AUTHDB/CLIENTSECRET"),0); } catch(...) {}

    // Parse multi-domain AUTHDB sources.
    // Preferred form is an indexed sequence: /BLOGI/AUTHDB/<i>/URL ... .
    // A legacy single-mapping form (/BLOGI/AUTHDB/URL) is still supported.