Skip to content

Commit

Permalink
add "pedantic" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Feb 25, 2019
1 parent 13073ce commit a760983
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions raddb/mods-available/isc_dhcp
Expand Up @@ -43,4 +43,31 @@ isc_dhcp {
# debug:: For developers, we print out what we're parsing.
#
debug = true

#
# pedantic:: Be harsh or forgiving about what we parse
#
# The `isc_dhcp` module implements only a small subset of the
# ISC DHCP configuration file commands. However, the module
# *parses* just about everything that is allowable in the ISC
# DHCP configuration.
#
# The goal here is to allow an easy migration from ISC DHCP
# to FreeRADIUS, by just copying over "dhcpd.conf".
# FreeRADIUS will at least start, instead of complaining
# about everything.
#
# If `pedantic = true`, then the module will fail with an
# error when it sees a command it knows it can't implement.
# The module will also issue warnings for commands which are
# ignored (e.g. OMAPI ones, "listen on port X", and similar).
# The module will also issue warnings for commands which
# should be implemented at some point.
#
# If a command does not produce any errors or warnings, it is
# implemented and supported.
#
# The default is `pedantic = false`
#
# pedantic = true
}
30 changes: 30 additions & 0 deletions src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c
Expand Up @@ -67,6 +67,7 @@ typedef struct {
char const *name;
char const *filename;
bool debug;
bool pedantic;
rlm_isc_dhcp_info_t *head;
} rlm_isc_dhcp_t;

Expand All @@ -76,6 +77,7 @@ typedef struct {
static const CONF_PARSER module_config[] = {
{ FR_CONF_OFFSET("filename", FR_TYPE_FILE_INPUT | FR_TYPE_REQUIRED | FR_TYPE_NOT_EMPTY, rlm_isc_dhcp_t, filename) },
{ FR_CONF_OFFSET("debug", FR_TYPE_BOOL, rlm_isc_dhcp_t, debug) },
{ FR_CONF_OFFSET("pedantic", FR_TYPE_BOOL, rlm_isc_dhcp_t, pedantic) },
CONF_PARSER_TERMINATOR
};

Expand Down Expand Up @@ -1301,6 +1303,34 @@ static int match_keyword(rlm_isc_dhcp_info_t *parent, rlm_isc_dhcp_tokenizer_t *
return parse_options(parent, state);
}

/*
* Print out more warnings / errors in pedantic mode.
*/
if (state->inst->pedantic && !tokens[half].parse) {
if (tokens[half].type == ISC_INVALID) {
ERROR("Command '%.*s' is not supported.",
state->token_len, state->token);
return -1;
}

/*
* Print out WARNING messages only in debug mode.
* We don't need to spam the main log file every
* time the server starts.
*/
if (rad_debug_lvl) {
if (tokens[half].type == ISC_NOOP) {
WARN("Command '%.*s' is not yet implemented.",
state->token_len, state->token);
}

if (tokens[half].type == ISC_IGNORE) {
WARN("Ignoring command '%.*s'. It is not relevant.",
state->token_len, state->token);
}
}
}

semicolon = YES_SEMICOLON; /* default to always requiring this */

DDEBUG("... TOKEN %.*s ", state->token_len, state->token);
Expand Down

0 comments on commit a760983

Please sign in to comment.