Skip to content

Commit

Permalink
Merge pull request #1570 from jrha/validate-ntpd-interface
Browse files Browse the repository at this point in the history
ncm-ntpd: Validate interface match option
  • Loading branch information
jrha authored Jan 3, 2023
2 parents eb8d00f + 8422f6f commit ac8cc61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ncm-ntpd/src/main/pan/components/ntpd/schema.pan
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ type ntpd_system_options = {
}
type ntpd_interface_options = {
"action" : choice("listen", "ignore", "drop")
"match" : string
"match" : string_trimmed with {
match(SELF, '^(all|ipv4|ipv6|wildcard)$')
|| is_ip(SELF)
|| is_ipv4_netmask_pair(SELF)
|| is_ipv6_network_block(SELF)
|| path_exists(format('/system/network/interfaces/%s', SELF));
}
};

# logging configuration
Expand All @@ -110,15 +116,11 @@ function valid_ntpd_logconfig_list = {
foreach (idx; configkeyword; ARGV[0]) {
# all keywords can be prefixed with +-=
if (!match(configkeyword, '^(\=|\-|\+)\w+')) {
error("invalid logconfig value "
+ to_string(ARGV[0])
+ " all configkeywords must precede by +,-, or =");
error("invalid logconfig value %s all configkeywords must precede by +,-, or =", ARGV[0]);
};
configkeyword = substr("configkeyword", 1);
if (!match(configkeyword, '^(all)?(clock|peer|sys|sync)?(status|events|statistics)?')) {
error("invalid logconfig value "
+ to_string(ARGV[0])
+ " failed to match regex '" + match_logkw + "'");
error("invalid logconfig value %s failed to match regex '%s'", ARGV[0], match_logkw);
};
};
true;
Expand Down
2 changes: 2 additions & 0 deletions ncm-ntpd/src/test/resources/interface.pan
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ object template interface;

include 'only_timeservers_base';

'/system/network/interfaces/eth0' = dict();

prefix "/software/components/ntpd";

'interface' = append(dict('action', 'listen', 'match', 'eth0'));
Expand Down

0 comments on commit ac8cc61

Please sign in to comment.