Commit 13889bfe authored by Daniel Salzman's avatar Daniel Salzman

confio: unify return codes from conf_get if invalid ID

parent bd7dcde3
......@@ -187,6 +187,7 @@ conf_val_t conf_zone_get_txn(
C_ZONE + 1, C_TPL + 1, knot_strerror(val.code));
// FALLTHROUGH
case KNOT_ENOENT:
case KNOT_YP_EINVAL_ID:
// Use the default template.
conf_db_get(conf, txn, C_TPL, key1_name, CONF_DEFAULT_ID + 1,
CONF_DEFAULT_ID[0], &val);
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -667,6 +667,9 @@ int conf_db_get(
// Set the key0 code.
out.code = db_code(conf, txn, KEY0_ROOT, key0, DB_GET, &k[KEY0_POS]);
if (out.code != KNOT_EOK) {
if (id_len > 0) {
out.code = KNOT_YP_EINVAL_ID;
}
goto get_error;
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -547,7 +547,7 @@ static void test_conf_io_unset(void)
ok(conf_io_unset("zone", "file", ZONE1, "name") ==
KNOT_EOK, "unset zone file");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_FILE, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
// Multi group, single bad value, all ids.
ok(conf_io_unset("zone", "comment", NULL, "other") ==
......@@ -567,9 +567,9 @@ static void test_conf_io_unset(void)
ok(conf_io_unset("zone", "comment", NULL, "abc") ==
KNOT_EOK, "unset some zones comment");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone2);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone3);
ok(val.code == KNOT_EOK, "check entry");
......@@ -581,11 +581,11 @@ static void test_conf_io_unset(void)
ok(conf_io_unset("zone", "comment", NULL, NULL) ==
KNOT_EOK, "unset all zones comment");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone2);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone3);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
// Restart transaction.
conf_io_abort(false);
......@@ -595,9 +595,9 @@ static void test_conf_io_unset(void)
ok(conf_io_unset("zone", NULL, ZONE1, NULL) ==
KNOT_EOK, "unset zone items");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_FILE, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone2);
ok(val.code == KNOT_EOK, "check entry");
......@@ -609,11 +609,11 @@ static void test_conf_io_unset(void)
ok(conf_io_unset("zone", NULL, NULL, NULL) ==
KNOT_EOK, "unset zone items");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_FILE, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone2);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
// Restart transaction.
conf_io_abort(false);
......@@ -627,11 +627,11 @@ static void test_conf_io_unset(void)
val = conf_get_txn(conf(), conf()->io.txn, C_SERVER, C_LISTEN);
ok(val.code == KNOT_ENOENT, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_FILE, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone1);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
val = conf_zone_get_txn(conf(), conf()->io.txn, C_COMMENT, zone2);
ok(val.code == KNOT_ENOENT, "check entry");
ok(val.code == KNOT_YP_EINVAL_ID, "check entry");
knot_dname_free(&zone1, NULL);
knot_dname_free(&zone2, NULL);
......
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