]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3992] Fix syslog:facility parsing
authorThomas Markwalder <tmark@isc.org>
Thu, 3 Jul 2025 15:31:58 +0000 (11:31 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 10 Jul 2025 11:11:43 +0000 (07:11 -0400)
Backports #3921 to v2_6.

modified:   ChangeLog
modified:   src/lib/process/log_parser.cc
modified:   src/lib/process/tests/log_parser_unittests.cc

ChangeLog
src/lib/process/log_parser.cc
src/lib/process/tests/log_parser_unittests.cc

index 9ecca73e9aa3eabf908c0f365a4ea275098cf0bb..73f4938b7b68faef565933e1552cdaf0b8e21f56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2269.  [bug]           tmark
+       Corrected an issue in logging configuration when
+       parsing "syslog:<facility name>".
+       (Gitlab #3992, #3921)
+
 2268.  [bug]           razvan
        Fix error handling when detecting a global reservation for the
        client and global reservatons are explicitly disabled in the
index f052730cfc0a93b82b81dc0319809cb9282e5242..a43842032839651d5414f3cf9191b51955535aef 100644 (file)
@@ -174,7 +174,8 @@ void LogConfigParser::parseOutputOptions(std::vector<LoggingDestination>& destin
         auto output_str = output->stringValue();
         if ((output_str == "stdout") ||
             (output_str == "stderr") ||
-            (output_str == "syslog")) {
+            (output_str == "syslog") ||
+            (output_str.find("syslog:") == 0)) {
             dest.output_ = output_str;
         } else {
             try {
index b833ed9642b91dbfcbbf6570556b802f598fa772..87eef1a5993721170711b8e29448862f840a772e 100644 (file)
@@ -632,6 +632,82 @@ TEST_F(LoggingTest, maxsize) {
     testMaxSize(1000000LL * std::numeric_limits<int32_t>::max(), 1000000LL * std::numeric_limits<int32_t>::max());
 }
 
+// Verifies syslog destination
+TEST_F(LoggingTest, syslogDestination) {
+    // Note the backslash must be doubled in the pattern definition.
+    const char* config_txt =
+    "{ \"loggers\": ["
+    "    {"
+    "        \"name\": \"kea\","
+    "        \"output-options\": ["
+    "            {"
+    "                \"output\": \"syslog\""
+    "            }"
+    "        ],"
+    "        \"severity\": \"INFO\""
+    "    }"
+    "]}";
+
+    ConfigPtr storage(new ConfigBase());
+
+    LogConfigParser parser(storage);
+
+    // We need to parse properly formed JSON and then extract
+    // "loggers" element from it. For some reason fromJSON is
+    // throwing at opening square bracket
+    ConstElementPtr config = Element::fromJSON(config_txt);
+    config = config->get("loggers");
+
+    EXPECT_NO_THROW(parser.parseConfiguration(config));
+
+    ASSERT_EQ(1, storage->getLoggingInfo().size());
+
+    EXPECT_EQ("kea", storage->getLoggingInfo()[0].name_);
+    EXPECT_EQ(isc::log::INFO, storage->getLoggingInfo()[0].severity_);
+
+    ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size());
+    // The destination output should NOT include the validated path.
+    EXPECT_EQ("syslog" , storage->getLoggingInfo()[0].destinations_[0].output_);
+}
+
+// Verifies syslog destination
+TEST_F(LoggingTest, syslogPlusFacility) {
+    // Note the backslash must be doubled in the pattern definition.
+    const char* config_txt =
+    "{ \"loggers\": ["
+    "    {"
+    "        \"name\": \"kea\","
+    "        \"output-options\": ["
+    "            {"
+    "                \"output\": \"syslog:daemon\""
+    "            }"
+    "        ],"
+    "        \"severity\": \"INFO\""
+    "    }"
+    "]}";
+
+    ConfigPtr storage(new ConfigBase());
+
+    LogConfigParser parser(storage);
+
+    // We need to parse properly formed JSON and then extract
+    // "loggers" element from it. For some reason fromJSON is
+    // throwing at opening square bracket
+    ConstElementPtr config = Element::fromJSON(config_txt);
+    config = config->get("loggers");
+
+    EXPECT_NO_THROW(parser.parseConfiguration(config));
+
+    ASSERT_EQ(1, storage->getLoggingInfo().size());
+
+    EXPECT_EQ("kea", storage->getLoggingInfo()[0].name_);
+    EXPECT_EQ(isc::log::INFO, storage->getLoggingInfo()[0].severity_);
+
+    ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size());
+    // The destination output should NOT include the validated path.
+    EXPECT_EQ("syslog:daemon" , storage->getLoggingInfo()[0].destinations_[0].output_);
+}
+
 /// @todo Add tests for malformed logging configuration
 
 /// @todo There is no easy way to test applyConfiguration() and defaultLogging().