From: Remi Gacogne Date: Mon, 18 Jan 2021 16:55:24 +0000 (+0100) Subject: dnsdist: Handle syslog facility as string, document the numerical one X-Git-Tag: dnsdist-1.6.0-alpha1~27^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9989%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Handle syslog facility as string, document the numerical one --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 2413496505..6b3b9bcda4 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1984,13 +1984,69 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) g_secPollInterval = newInterval; }); - luaCtx.writeFunction("setSyslogFacility", [](int facility) { + luaCtx.writeFunction("setSyslogFacility", [](boost::variant facility) { setLuaSideEffect(); if (g_configurationDone) { g_outputBuffer="setSyslogFacility cannot be used at runtime!\n"; return; } - setSyslogFacility(facility); + if (facility.type() == typeid(std::string)) { + static std::map const facilities = { + { "local0", LOG_LOCAL0 }, + { "log_local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "log_local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "log_local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "log_local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "log_local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "log_local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "log_local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { "log_local7", LOG_LOCAL7 }, + /* most of these likely make very little sense + for dnsdist, but why not? */ + { "kern", LOG_KERN }, + { "log_kern", LOG_KERN }, + { "user", LOG_USER }, + { "log_user", LOG_USER }, + { "mail", LOG_MAIL }, + { "log_mail", LOG_MAIL }, + { "daemon", LOG_DAEMON }, + { "log_daemon", LOG_DAEMON }, + { "auth", LOG_AUTH }, + { "log_auth", LOG_AUTH }, + { "syslog", LOG_SYSLOG }, + { "log_syslog", LOG_SYSLOG }, + { "lpr", LOG_LPR }, + { "log_lpr", LOG_LPR }, + { "news", LOG_NEWS }, + { "log_news", LOG_NEWS }, + { "uucp", LOG_UUCP }, + { "log_uucp", LOG_UUCP }, + { "cron", LOG_CRON }, + { "log_cron", LOG_CRON }, + { "authpriv", LOG_AUTHPRIV }, + { "log_authpriv", LOG_AUTHPRIV }, + { "ftp", LOG_FTP }, + { "log_ftp", LOG_FTP } + }; + auto facilityStr = boost::get(facility); + toLowerInPlace(facilityStr); + auto it = facilities.find(facilityStr); + if (it == facilities.end()) { + g_outputBuffer="Unknown facility '" + facilityStr + "' passed to setSyslogFacility()!\n"; + return; + } + setSyslogFacility(it->second); + } + else { + setSyslogFacility(boost::get(facility)); + } }); luaCtx.writeFunction("addDOHLocal", [client](const std::string& addr, boost::optional>>> certFiles, boost::optional>>> keyFiles, boost::optional > > > urls, boost::optional vars) { diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index f12aa69d7f..71efff311c 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -53,9 +53,12 @@ Global configuration .. versionadded:: 1.4.0 + .. versionchanged:: 1.6.0 + ``facility`` can now be a string. + Set the syslog logging facility to ``facility``. - :param int facility: The new facility as a numeric value. Defaults to LOG_DAEMON. + :param int or str facility: The new facility as a numeric value (raw value as defined in syslog.h), or as a case-insensitive string ("LOCAL0", or "daemon", for example). Defaults to LOG_DAEMON. Listen Sockets ~~~~~~~~~~~~~~