Commit 901363a3 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Merge branch '189-fix-tsig-dump-keyfile-name-generation-issues-v9_11' into 'v9_11'

[v9_11] Fix TSIG dump keyfile name generation issues

See merge request !192
parents ec32538c cf559815
Pipeline #1218 passed with stages
in 6 minutes and 38 seconds
......@@ -13,8 +13,10 @@
#include <config.h>
#include <limits.h>
#ifdef HAVE_LMDB
#include <lmdb.h>
#include <lmdb.h>
#endif
#include <isc/file.h>
......@@ -346,28 +348,28 @@ destroy(dns_view_t *view) {
if (view->dynamickeys != NULL) {
isc_result_t result;
char template[20];
char keyfile[20];
char template[PATH_MAX];
char keyfile[PATH_MAX];
FILE *fp = NULL;
int n;
n = snprintf(keyfile, sizeof(keyfile), "%s.tsigkeys",
view->name);
if (n > 0 && (size_t)n < sizeof(keyfile)) {
result = isc_file_mktemplate(keyfile, template,
sizeof(template));
if (result == ISC_R_SUCCESS)
(void)isc_file_openuniqueprivate(template, &fp);
result = isc_file_mktemplate(NULL, template, sizeof(template));
if (result == ISC_R_SUCCESS) {
(void)isc_file_openuniqueprivate(template, &fp);
}
if (fp == NULL)
if (fp == NULL) {
dns_tsigkeyring_detach(&view->dynamickeys);
else {
result = dns_tsigkeyring_dumpanddetach(
&view->dynamickeys, fp);
} else {
result = dns_tsigkeyring_dumpanddetach
(&view->dynamickeys, fp);
if (result == ISC_R_SUCCESS) {
if (fclose(fp) == 0)
result = isc_file_rename(template,
keyfile);
if (fclose(fp) == 0) {
result = isc_file_sanitize
(NULL, view->name, "tsigkeys",
keyfile, sizeof(keyfile));
if (result == ISC_R_SUCCESS)
result = isc_file_rename
(template, keyfile);
}
if (result != ISC_R_SUCCESS)
(void)remove(template);
} else {
......@@ -912,15 +914,15 @@ dns_view_getdynamickeyring(dns_view_t *view, dns_tsig_keyring_t **ringp) {
void
dns_view_restorekeyring(dns_view_t *view) {
FILE *fp;
char keyfile[20];
int n;
char keyfile[PATH_MAX];
isc_result_t result;
REQUIRE(DNS_VIEW_VALID(view));
if (view->dynamickeys != NULL) {
n = snprintf(keyfile, sizeof(keyfile), "%s.tsigkeys",
view->name);
if (n > 0 && (size_t)n < sizeof(keyfile)) {
result = isc_file_sanitize(NULL, view->name, "tsigkeys",
keyfile, sizeof(keyfile));
if (result == ISC_R_SUCCESS) {
fp = fopen(keyfile, "r");
if (fp != NULL) {
dns_keyring_restore(view->dynamickeys, fp);
......
......@@ -80,11 +80,57 @@ ATF_TC_BODY(isc_file_sanitize, tc) {
unlink(F(SHA));
}
ATF_TC(isc_file_template);
ATF_TC_HEAD(isc_file_template, tc) {
atf_tc_set_md_var(tc, "descr", "file template");
}
ATF_TC_BODY(isc_file_template, tc) {
isc_result_t result;
char buf[1024];
ATF_CHECK(chdir(TESTS) != -1);
result = isc_file_template("/absolute/path", "file-XXXXXXXX",
buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "/absolute/file-XXXXXXXX");
result = isc_file_template("relative/path", "file-XXXXXXXX",
buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "relative/file-XXXXXXXX");
result = isc_file_template("/trailing/slash/", "file-XXXXXXXX",
buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "/trailing/slash/file-XXXXXXXX");
result = isc_file_template("relative/trailing/slash/", "file-XXXXXXXX",
buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "relative/trailing/slash/file-XXXXXXXX");
result = isc_file_template("/", "file-XXXXXXXX", buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "/file-XXXXXXXX");
result = isc_file_template("noslash", "file-XXXXXXXX",
buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "file-XXXXXXXX");
result = isc_file_template(NULL, "file-XXXXXXXX", buf, sizeof(buf));
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_STREQ(buf, "file-XXXXXXXX");
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_file_sanitize);
ATF_TP_ADD_TC(tp, isc_file_template);
return (atf_no_error());
}
......@@ -224,10 +224,12 @@ isc_file_template(const char *path, const char *templet, char *buf,
{
const char *s;
REQUIRE(path != NULL);
REQUIRE(templet != NULL);
REQUIRE(buf != NULL);
if (path == NULL)
path = "";
s = strrchr(templet, '/');
if (s != NULL)
templet = s + 1;
......
......@@ -323,10 +323,12 @@ isc_file_template(const char *path, const char *templet, char *buf,
{
char *s;
REQUIRE(path != NULL);
REQUIRE(templet != NULL);
REQUIRE(buf != NULL);
if (path == NULL)
path = "";
s = strrchr(templet, '\\');
if (s != NULL)
templet = s + 1;
......
......@@ -24,6 +24,10 @@
*** Network.
***/
#ifndef PATH_MAX
#define PATH_MAX _MAX_PATH
#endif
#define ISC_PLATFORM_HAVEIPV6
#if _MSC_VER > 1200
#define ISC_PLATFORM_HAVEIN6PKTINFO
......
Supports Markdown
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