Commit 7041e6b1 authored by Daniel Salzman's avatar Daniel Salzman

knot1to2: update control section transformation

parent 68fe9aa7
This diff is collapsed.
......@@ -120,7 +120,7 @@ extern int cf_debug;
typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{
#line 361 "cf-parse.y" /* yacc.c:1909 */
#line 353 "cf-parse.y" /* yacc.c:1909 */
struct {
char *t;
......
......@@ -199,7 +199,6 @@ typedef enum {
ACL_XFR,
ACL_NTF,
ACL_UPD,
ACL_CTL
} acl_type_t;
static void acl_start(void *scanner, acl_type_t type)
......@@ -212,7 +211,6 @@ static void acl_start(void *scanner, acl_type_t type)
case ACL_XFR: extra->current_trie = extra->share->acl_xfer; break;
case ACL_NTF: extra->current_trie = extra->share->acl_notify; break;
case ACL_UPD: extra->current_trie = extra->share->acl_update; break;
case ACL_CTL: extra->current_trie = extra->share->acl_control; break;
}
}
......@@ -285,8 +283,7 @@ static bool is_acl(void *scanner, const char *str) {
return hattrie_tryget(extra->share->acl_xfer, str, strlen(str)) != NULL ||
hattrie_tryget(extra->share->acl_notify, str, strlen(str)) != NULL ||
hattrie_tryget(extra->share->acl_update, str, strlen(str)) != NULL ||
hattrie_tryget(extra->share->acl_control, str, strlen(str)) != NULL;
hattrie_tryget(extra->share->acl_update, str, strlen(str)) != NULL;
}
static bool have_acl(void *scanner) {
......@@ -294,8 +291,7 @@ static bool have_acl(void *scanner) {
return (hattrie_weight(extra->share->acl_xfer) +
hattrie_weight(extra->share->acl_notify) +
hattrie_weight(extra->share->acl_update) +
hattrie_weight(extra->share->acl_control)) > 0;
hattrie_weight(extra->share->acl_update)) > 0;
}
static char *acl_actions(void *scanner, const char *str) {
......@@ -318,10 +314,6 @@ static char *acl_actions(void *scanner, const char *str) {
strlcat(actions, _first ? "" : ", ", sizeof(actions)); _first = false;
strlcat(actions, "update", sizeof(actions));
}
if (hattrie_tryget(extra->share->acl_control, str, strlen(str)) != NULL) {
strlcat(actions, _first ? "" : ", ", sizeof(actions)); _first = false;
strlcat(actions, "control", sizeof(actions));
}
strlcat(actions, "]", sizeof(actions));
......@@ -761,24 +753,21 @@ ctl_listen_start:
;
ctl_allow_start:
ALLOW { f_name(scanner, R_CTL, C_ACL, false); acl_start(scanner, ACL_CTL); _str = "acl_"; }
ALLOW
;
control:
CONTROL '{' { f_section(scanner, R_CTL, S_CTL); _acl_run = R_CTL; }
| control ctl_listen_start '{' { f_name(scanner, R_CTL, C_LISTEN, false); _addr = NULL, _port = -1; }
interface '}' {
if (_addr == NULL) {
cf_error(scanner, "control.listen address not defined");
} else if (_port == -1) {
f_val(scanner, R_CTL, false, "%s\n", _addr);
} else {
f_val(scanner, R_CTL, false, "%s@%i\n", _addr, _port);
f_val(scanner, R_CTL, true, "knot.sock");
if (cf_get_extra(scanner)->run == S_CTL) {
cf_warning(scanner, "remote control over INET socket is no longer supported");
}
free(_addr);
}
| control ctl_listen_start TEXT ';' { f_quote(scanner, R_CTL, C_LISTEN, $3.t); free($3.t); }
| control ctl_allow_start zone_acl_list
| control ctl_allow_start TEXT ';' { free($3.t); }
;
conf: ';' | system '}' | interfaces '}' | keys '}' | remotes '}' | groups '}' | zones '}' | log '}' | control '}';
......
......@@ -70,7 +70,7 @@ static int convert(const char *file_out, const char *file_in)
"# the conversion cannot be perfect. It is important to do a review\n"
"# of this file (see the documentation).\n"
"# It is also possible to reformat the file via knotc, like:\n"
"# knotc -c ./this_file.conf export ./reformatted_file.conf\n"
"# knotc -c ./this_file.conf conf-export ./reformatted_file.conf\n"
);
share_t share = {
......@@ -80,13 +80,12 @@ static int convert(const char *file_out, const char *file_in)
.remotes = hattrie_create(),
.acl_xfer = hattrie_create(),
.acl_notify = hattrie_create(),
.acl_update = hattrie_create(),
.acl_control = hattrie_create(),
.acl_update = hattrie_create()
};
// Parse the input file multiple times to get some context.
int ret = 0;
for (int i = R_SYS; i <= R_LOG; i++) {
for (int i = R_SYS; i <= R_ZONE; i++) {
ret = run_parser(file_in, i, &share);
if (ret != 0) {
break;
......@@ -116,7 +115,6 @@ static int convert(const char *file_out, const char *file_in)
hattrie_free(share.acl_xfer);
hattrie_free(share.acl_notify);
hattrie_free(share.acl_update);
hattrie_free(share.acl_control);
fclose(out);
......
......@@ -19,34 +19,34 @@
typedef enum {
S_FIRST = 0,
S_SRV = S_FIRST,
S_CTL,
S_LOG,
S_KEY,
S_RMT,
S_ACL,
S_CTL,
S_DNSTAP,
S_SYNTH,
S_DNSPROXY,
S_ROSEDB,
S_TPL,
S_ZONE,
S_LOG,
S_LAST = S_LOG
S_LAST = S_ZONE
} section_t;
typedef enum {
R_SYS, // -> SERVER
R_IF, // -> SERVER
R_CTL, // -> CONTROL
R_LOG, // -> LOG
R_KEY, // -> KEY
R_RMT, // -> REMOTE
R_RMT_ACL, // -> ACL
R_CTL, // -> CONTROL
R_ZONEM1, // -> MOD_DNSTAP
R_ZONEM2, // -> MOD_SYNTRECORD
R_ZONEM3, // -> MOD_DNSPROXY
R_ZONEM4, // -> MOD_ROSEDB
R_ZONE_TPL, // -> TEMPLATE default
R_ZONE, // -> ZONE
R_LOG, // -> LOG
} run_t;
#define C_ACL "\x03""acl"
......@@ -113,17 +113,17 @@ inline static const char* section_name(section_t id)
{
switch (id) {
case S_SRV: return C_SRV;
case S_CTL: return C_CTL;
case S_LOG: return C_LOG;
case S_KEY: return C_KEY;
case S_ACL: return C_ACL;
case S_RMT: return C_RMT;
case S_CTL: return C_CTL;
case S_DNSTAP: return C_MOD_DNSTAP;
case S_SYNTH: return C_MOD_SYNTH_RECORD;
case S_DNSPROXY: return C_MOD_DNSPROXY;
case S_ROSEDB: return C_MOD_ROSEDB;
case S_TPL: return C_TPL;
case S_ZONE: return C_ZONE;
case S_LOG: return C_LOG;
default: return 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