]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: XTTYPE_STRING support
authorJan Engelhardt <jengelh@medozas.de>
Tue, 15 Feb 2011 21:09:21 +0000 (22:09 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Wed, 6 Apr 2011 11:12:55 +0000 (13:12 +0200)
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
include/xtables.h.in
xtoptions.c

index 3e596e0c130c95f8f7e243b9674934ed17125187..c3c8da9c3234eefa3066641d198244e78502dbd6 100644 (file)
@@ -49,12 +49,14 @@ struct in_addr;
  * %XTTYPE_NONE:       option takes no argument
  * %XTTYPE_UINT*:      standard integer
  * %XTTYPE_UINT*RC:    colon-separated range of standard integers
+ * %XTTYPE_STRING:     arbitrary string
  */
 enum xt_option_type {
        XTTYPE_NONE,
        XTTYPE_UINT8,
        XTTYPE_UINT32,
        XTTYPE_UINT32RC,
+       XTTYPE_STRING,
 };
 
 /**
index 03c629e06b9c42fff1c35a73f3b2770545047df5..631e7a3c35027e3de4ceeed7f36c68e7bb1a60d3 100644 (file)
@@ -163,16 +163,41 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
        }
 }
 
+static void xtopt_parse_string(struct xt_option_call *cb)
+{
+       const struct xt_option_entry *entry = cb->entry;
+       size_t z = strlen(cb->arg);
+       char *p;
+
+       if (entry->min != 0 && z < entry->min)
+               xt_params->exit_err(PARAMETER_PROBLEM,
+                       "Argument must have a minimum length of "
+                       "%u characters\n", entry->min);
+       if (entry->max != 0 && z > entry->max)
+               xt_params->exit_err(PARAMETER_PROBLEM,
+                       "Argument must have a maximum length of "
+                       "%u characters\n", entry->max);
+       if (!(entry->flags & XTOPT_PUT))
+               return;
+       if (z >= entry->size)
+               z = entry->size - 1;
+       p = XTOPT_MKPTR(cb);
+       strncpy(p, cb->arg, z);
+       p[z] = '\0';
+}
+
 static void (*const xtopt_subparse[])(struct xt_option_call *) = {
        [XTTYPE_UINT8]       = xtopt_parse_int,
        [XTTYPE_UINT32]      = xtopt_parse_int,
        [XTTYPE_UINT32RC]    = xtopt_parse_mint,
+       [XTTYPE_STRING]      = xtopt_parse_string,
 };
 
 static const size_t xtopt_psize[] = {
        [XTTYPE_UINT8]       = sizeof(uint8_t),
        [XTTYPE_UINT32]      = sizeof(uint32_t),
        [XTTYPE_UINT32RC]    = sizeof(uint32_t[2]),
+       [XTTYPE_STRING]      = -1,
 };
 
 /**