Commit d35387de authored by Daniel Salzman's avatar Daniel Salzman

conf: ignore trailing non-root zone name dot in %s formatter

parent a2742f94
......@@ -491,14 +491,15 @@ A path to the zone file. Non absolute path is relative to
\fI\%storage\fP\&. It is also possible to use the following formatters:
.INDENT 0.0
.IP \(bu 2
\fI%s\fP \- means the current zone name in the textual representation (beware of special
characters which are escaped or encoded in the \eDDD form). Each zone name is
terminated with a dot character!
\fB%s\fP \- means the current zone name in the textual representation (beware
of special characters which are escaped or encoded in the \eDDD form where
DDD is corresponding decimal ASCII code). The zone name doesn\(aqt include the
terminating dot, except for the root zone.
.IP \(bu 2
\fI%%\fP \- means the \fI%\fP character
\fB%%\fP \- means the \fB%\fP character
.UNINDENT
.sp
Default: \fI\%storage\fP/\fB%s\fPzone
Default: \fI\%storage\fP/\fB%s\fP\&.zone
.SS storage
.sp
A data directory for storing zone files, journal files and timers database.
......
......@@ -584,14 +584,15 @@ file
----
A path to the zone file. Non absolute path is relative to
:ref:`storage<zone_storage>`. It is also possible to use the following formatters:
:ref:`storage<zone_storage>`. It is also possible to use the following formatters:
- `%s` - means the current zone name in the textual representation (beware of special
characters which are escaped or encoded in the \\DDD form). Each zone name is
terminated with a dot character!
- `%%` - means the `%` character
- ``%s`` - means the current zone name in the textual representation (beware
of special characters which are escaped or encoded in the \\DDD form where
DDD is corresponding decimal ASCII code). The zone name doesn't include the
terminating dot, except for the root zone.
- ``%%`` - means the ``%`` character
Default: :ref:`storage<zone_storage>`/``%s``\ zone
Default: :ref:`storage<zone_storage>`/``%s``\ .zone
.. _zone_storage:
......
......@@ -649,11 +649,18 @@ static char* get_filename(
}
// Replace possible slashes with underscores.
for (char *ch = buff; *ch != '\0'; ch++) {
char *ch;
for (ch = buff; *ch != '\0'; ch++) {
if (*ch == '/') {
*ch = '_';
}
}
// Remove trailing dot if not root zone.
if (ch - buff > 1) {
*(--ch) = '\0';
}
break;
case '\0':
CONF_LOG_ZONE(LOG_WARNING, zone, "ignoring missing "
......@@ -699,7 +706,7 @@ char* conf_zonefile_txn(
// Use default zonefile name pattern if not specified.
if (file == NULL) {
file = "%szone";
file = "%s.zone";
}
return get_filename(conf, txn, zone, file);
......@@ -714,7 +721,7 @@ char* conf_journalfile_txn(
return NULL;
}
return get_filename(conf, txn, zone, "%sdb");
return get_filename(conf, txn, zone, "%s.db");
}
size_t conf_udp_threads_txn(
......
......@@ -20,6 +20,7 @@
#define ZONE1 "0/25.2.0.192.in-addr.arpa."
#define ZONE2 "."
#define ZONE3 "x."
static void test_conf_zonefile(void)
{
......@@ -30,6 +31,8 @@ static void test_conf_zonefile(void)
ok(zone1 != NULL, "create dname "ZONE1);
knot_dname_t *zone2 = knot_dname_from_str_alloc(ZONE2);
ok(zone2 != NULL, "create dname "ZONE2);
knot_dname_t *zone3 = knot_dname_from_str_alloc(ZONE3);
ok(zone3 != NULL, "create dname "ZONE3);
const char *conf_str =
"template:\n"
......@@ -38,9 +41,10 @@ static void test_conf_zonefile(void)
"\n"
"zone:\n"
" - domain: "ZONE1"\n"
" file: dir/a%%b/%ssuffix/%a\n"
"zone:\n"
" file: dir/a%%b/%s.suffix/%a\n"
" - domain: "ZONE2"\n"
" file: /%s\n"
" - domain: "ZONE3"\n"
" file: /%s\n";
ret = test_conf(conf_str, NULL);
......@@ -64,9 +68,19 @@ static void test_conf_zonefile(void)
free(file);
}
// Absolute path without formatters.
file = conf_zonefile(conf(), zone3);
ok(file != NULL, "Get zonefile path for "ZONE3);
if (file != NULL) {
ok(strcmp(file, "/x") == 0,
"Zonefile path compare for "ZONE3);
free(file);
}
conf_free(conf(), false);
knot_dname_free(&zone1, NULL);
knot_dname_free(&zone2, NULL);
knot_dname_free(&zone3, NULL);
}
int main(int argc, char *argv[])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment