Commit 443807e5 authored by Daniel Salzman's avatar Daniel Salzman

Merge branch 'long_index_in_conf' into 'master'

conf: enabled indexes up to 255 in filename pattern

See merge request !676
parents 7c052747 75b286ea
......@@ -769,7 +769,7 @@ A data directory for storing zone files, journal database, and timers database.
\fIDefault:\fP \fB${localstatedir}/lib/knot\fP (configured with \fB\-\-with\-storage=path\fP)
.SS file
.sp
A path to the zone file. Non absolute path is relative to
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
......@@ -783,14 +783,21 @@ one) are considered. If the character is not available, the formatter has no eff
(see \fB%s\fP). The index is counted from 0 from the right (0 ~ TLD).
If the label is not available, the formatter has no effect.
.IP \(bu 2
\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 (the result for the root zone is the empty string!).
\fB%s\fP – means the current zone name in the textual representation.
The zone name doesn\(aqt include the terminating dot (the result for the root
zone is the empty string!).
.IP \(bu 2
\fB%%\fP – means the \fB%\fP character
.UNINDENT
.sp
\fBWARNING:\fP
.INDENT 0.0
.INDENT 3.5
Beware of special characters which are escaped or encoded in the \eDDD form
where DDD is corresponding decimal ASCII code.
.UNINDENT
.UNINDENT
.sp
\fIDefault:\fP \fI\%storage\fP/\fB%s\fP\&.zone
.SS master
.sp
......@@ -961,7 +968,7 @@ value can be used for the default policy settings.
\fIRequired\fP
.SS kasp\-db
.sp
A KASP database path. Non absolute path is relative to
A KASP database path. Non\-absolute path is relative to
\fI\%storage\fP\&.
.sp
\fIDefault:\fP \fI\%storage\fP/keys
......
......@@ -905,7 +905,7 @@ A data directory for storing zone files, journal database, and timers database.
file
----
A path to the zone file. Non absolute path is relative to
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:
- ``%c[``\ *N*\ ``]`` or ``%c[``\ *N*\ ``-``\ *M*\ ``]`` – means the *N*\ th
......@@ -916,12 +916,15 @@ A path to the zone file. Non absolute path is relative to
- ``%l[``\ *N*\ ``]`` – means the *N*\ th label of the textual zone name
(see ``%s``). The index is counted from 0 from the right (0 ~ TLD).
If the label is not available, the formatter has no effect.
- ``%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 (the result for the root zone is the empty string!).
- ``%s`` – means the current zone name in the textual representation.
The zone name doesn't include the terminating dot (the result for the root
zone is the empty string!).
- ``%%`` – means the ``%`` character
.. WARNING::
Beware of special characters which are escaped or encoded in the \\DDD form
where DDD is corresponding decimal ASCII code.
*Default:* :ref:`storage<zone_storage>`/``%s``\ .zone
.. _zone_master:
......@@ -1111,7 +1114,7 @@ value can be used for the default policy settings.
kasp-db
-------
A KASP database path. Non absolute path is relative to
A KASP database path. Non-absolute path is relative to
:ref:`storage<zone_storage>`.
*Default:* :ref:`storage<zone_storage>`/keys
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -17,6 +17,7 @@
#include <assert.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include "knot/conf/base.h"
#include "knot/conf/confdb.h"
......@@ -782,48 +783,34 @@ void conf_free_mod_id(
static int get_index(
const char **start,
const char *end,
uint8_t *index1,
uint8_t *index2)
unsigned *index1,
unsigned *index2)
{
const char *pos = *start;
uint8_t i1, i2;
// At least [n] must fit into.
if (end - pos < 3 || pos[0] != '[') {
char c, *p;
if (sscanf(*start, "[%u%c", index1, &c) != 2) {
return KNOT_EINVAL;
}
// Check for the variant [n] or [m-n].
switch (pos[2]) {
case ']':
i1 = pos[1] - '0';
i2 = i1;
if (i1 > 9) {
return KNOT_EINVAL;
}
*start += 3;
break;
switch (c) {
case '-':
if (index2 == NULL || end - pos < 5 || pos[4] != ']') {
p = strchr(*start, '-') + 1;
if (end - p < 2 || index2 == NULL ||
sscanf(p, "%u%c", index2, &c) != 2 || c != ']') {
return KNOT_EINVAL;
}
i1 = pos[1] - '0';
i2 = pos[3] - '0';
if (i1 > 9 || i2 > 9 || i1 > i2) {
return KNOT_EINVAL;
break;
case ']':
if (index2 != NULL) {
*index2 = *index1;
}
*start += 5;
break;
default:
return KNOT_EINVAL;
}
*index1 = i1;
if (index2 != NULL) {
*index2 = i2;
}
return KNOT_EOK;
*start = strchr(*start, ']') + 1;
return ((*index1 < 256 && (index2 == NULL || *index2 < 256)
&& end - *start >= 0 && (index2 == NULL || *index2 >= *index1))
? KNOT_EOK : KNOT_EINVAL);
}
static void replace_slashes(
......@@ -849,8 +836,8 @@ static int str_char(
const knot_dname_t *zone,
char *buff,
size_t buff_len,
uint8_t index1,
uint8_t index2)
unsigned index1,
unsigned index2)
{
if (knot_dname_to_str(buff, zone, buff_len) == NULL) {
return KNOT_EINVAL;
......@@ -901,7 +888,7 @@ static int str_label(
const knot_dname_t *zone,
char *buff,
size_t buff_len,
uint8_t right_index)
unsigned right_index)
{
int labels = knot_dname_labels(zone, NULL);
......@@ -919,11 +906,11 @@ static int str_label(
// Compute the index from the left.
assert(labels > right_index);
uint8_t index = labels - right_index - 1;
unsigned index = labels - right_index - 1;
// Create a dname from the single label.
int prefix = (index > 0) ? knot_dname_prefixlen(zone, index, NULL) : 0;
uint8_t label_len = *(zone + prefix);
unsigned label_len = *(zone + prefix);
memcpy(label, zone + prefix, 1 + label_len);
label[1 + label_len] = '\0';
......@@ -968,7 +955,7 @@ static char* get_filename(
name = pos + 2;
char buff[512] = "";
uint8_t idx1, idx2;
unsigned idx1, idx2;
bool failed = false;
const char type = *(pos + 1);
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -63,16 +63,20 @@ static void test_get_filename(void)
check_name(zone, "/%c[3]", "/.");
check_name(zone, "/%c[8]", "/g");
check_name(zone, "/%c[9]", "/.");
check_name(zone, "/%c[10]", "/");
check_name(zone, "/%c[255]", "/");
check_name(zone, "/%c[0-1]", "/ab");
check_name(zone, "/%c[1-1]", "/b");
check_name(zone, "/%c[1-3]", "/bc.");
check_name(zone, "/%c[1-4]", "/bc.d");
check_name(zone, "/%c[254-255]", "/");
check_name_err(zone, "/%c");
check_name_err(zone, "/%cx");
check_name_err(zone, "/%c[a]");
check_name_err(zone, "/%c[:]");
check_name_err(zone, "/%c[/]");
check_name_err(zone, "/%c[10]");
check_name_err(zone, "/%c[-1]");
check_name_err(zone, "/%c[256]");
check_name_err(zone, "/%c[");
check_name_err(zone, "/%c[1");
check_name_err(zone, "/%c[1-");
......@@ -95,8 +99,11 @@ static void test_get_filename(void)
check_name(zone, "/%l[1]", "/def");
check_name(zone, "/%l[2]", "/abc");
check_name(zone, "/%l[3]", "/");
check_name(zone, "/%l[255]", "/");
check_name(zone, "/%l[0]-%l[1]-%l[2]", "/gh-def-abc");
check_name_err(zone, "/%l[0-1]");
check_name_err(zone, "/%l[-1]");
check_name_err(zone, "/%l[256]");
zone = ".";
check_name(zone, "/%l[0]", "/");
......
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