From ba3b73f0d3aae8188ff0b75d0839c841352f7760 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 1 Mar 2011 20:11:01 +0100 Subject: libxt_AUDIT: use guided option parser Signed-off-by: Jan Engelhardt --- extensions/libxt_AUDIT.c | 66 ++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) (limited to 'extensions/libxt_AUDIT.c') diff --git a/extensions/libxt_AUDIT.c b/extensions/libxt_AUDIT.c index a6ab37f9..86a61cbe 100644 --- a/extensions/libxt_AUDIT.c +++ b/extensions/libxt_AUDIT.c @@ -5,16 +5,15 @@ * * This program is distributed under the terms of GNU GPL v2, 1991 */ - -#include #include #include -#include -#include - #include #include +enum { + O_AUDIT_TYPE = 0, +}; + static void audit_help(void) { printf( @@ -22,46 +21,26 @@ static void audit_help(void) " --type TYPE Action type to be recorded.\n"); } -static const struct option audit_opts[] = { - {.name = "type", .has_arg = true, .val = 't'}, - XT_GETOPT_TABLEEND, +static const struct xt_option_entry audit_opts[] = { + {.name = "type", .id = O_AUDIT_TYPE, .type = XTTYPE_STRING, + .flags = XTOPT_MAND}, + XTOPT_TABLEEND, }; -static int audit_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_target **target) -{ - struct xt_audit_info *einfo - = (struct xt_audit_info *)(*target)->data; - - switch (c) { - case 't': - if (!strcasecmp(optarg, "accept")) - einfo->type = XT_AUDIT_TYPE_ACCEPT; - else if (!strcasecmp(optarg, "drop")) - einfo->type = XT_AUDIT_TYPE_DROP; - else if (!strcasecmp(optarg, "reject")) - einfo->type = XT_AUDIT_TYPE_REJECT; - else - xtables_error(PARAMETER_PROBLEM, - "Bad action type value `%s'", optarg); - - if (*flags) - xtables_error(PARAMETER_PROBLEM, - "AUDIT: Can't specify --type twice"); - *flags = 1; - break; - default: - return 0; - } - - return 1; -} - -static void audit_final_check(unsigned int flags) +static void audit_parse(struct xt_option_call *cb) { - if (!flags) + struct xt_audit_info *einfo = cb->data; + + xtables_option_parse(cb); + if (strcasecmp(cb->arg, "accept") == 0) + einfo->type = XT_AUDIT_TYPE_ACCEPT; + else if (strcasecmp(cb->arg, "drop") == 0) + einfo->type = XT_AUDIT_TYPE_DROP; + else if (strcasecmp(cb->arg, "reject") == 0) + einfo->type = XT_AUDIT_TYPE_REJECT; + else xtables_error(PARAMETER_PROBLEM, - "AUDIT target: Parameter --type is required"); + "Bad action type value \"%s\"", cb->arg); } static void audit_print(const void *ip, const struct xt_entry_target *target, @@ -110,11 +89,10 @@ static struct xtables_target audit_tg_reg = { .size = XT_ALIGN(sizeof(struct xt_audit_info)), .userspacesize = XT_ALIGN(sizeof(struct xt_audit_info)), .help = audit_help, - .parse = audit_parse, - .final_check = audit_final_check, .print = audit_print, .save = audit_save, - .extra_opts = audit_opts, + .x6_parse = audit_parse, + .x6_options = audit_opts, }; void _init(void) -- cgit v1.2.3