diff options
Diffstat (limited to 'extensions/libxt_owner.c')
-rw-r--r-- | extensions/libxt_owner.c | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/extensions/libxt_owner.c b/extensions/libxt_owner.c index 4cd173e3..bf26f35c 100644 --- a/extensions/libxt_owner.c +++ b/extensions/libxt_owner.c @@ -19,6 +19,11 @@ #include <linux/netfilter_ipv4/ipt_owner.h> #include <linux/netfilter_ipv6/ip6t_owner.h> +/* + * Note: "UINT32_MAX - 1" is used in the code because -1 is a reserved + * UID/GID value anyway. + */ + enum { FLAG_UID_OWNER = 1 << 0, FLAG_GID_OWNER = 1 << 1, @@ -107,11 +112,11 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags, switch (c) { case 'u': - param_act(P_ONLY_ONCE, "owner", "--uid-owner", *flags & FLAG_UID_OWNER); + xtables_param_act(XTF_ONLY_ONCE, "owner", "--uid-owner", *flags & FLAG_UID_OWNER); if ((pwd = getpwnam(optarg)) != NULL) id = pwd->pw_uid; - else if (!strtonum(optarg, NULL, &id, 0, ~(uid_t)0)) - param_act(P_BAD_VALUE, "owner", "--uid-owner", optarg); + else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--uid-owner", optarg); if (invert) info->invert |= IPT_OWNER_UID; info->match |= IPT_OWNER_UID; @@ -120,11 +125,11 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags, return true; case 'g': - param_act(P_ONLY_ONCE, "owner", "--gid-owner", *flags & FLAG_GID_OWNER); + xtables_param_act(XTF_ONLY_ONCE, "owner", "--gid-owner", *flags & FLAG_GID_OWNER); if ((grp = getgrnam(optarg)) != NULL) id = grp->gr_gid; - else if (!strtonum(optarg, NULL, &id, 0, ~(gid_t)0)) - param_act(P_BAD_VALUE, "owner", "--gid-owner", optarg); + else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--gid-owner", optarg); if (invert) info->invert |= IPT_OWNER_GID; info->match |= IPT_OWNER_GID; @@ -133,9 +138,9 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags, return true; case 'p': - param_act(P_ONLY_ONCE, "owner", "--pid-owner", *flags & FLAG_PID_OWNER); - if (!strtonum(optarg, NULL, &id, 0, INT_MAX)) - param_act(P_BAD_VALUE, "owner", "--pid-owner", optarg); + xtables_param_act(XTF_ONLY_ONCE, "owner", "--pid-owner", *flags & FLAG_PID_OWNER); + if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--pid-owner", optarg); if (invert) info->invert |= IPT_OWNER_PID; info->match |= IPT_OWNER_PID; @@ -144,9 +149,9 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags, return true; case 's': - param_act(P_ONLY_ONCE, "owner", "--sid-owner", *flags & FLAG_SID_OWNER); - if (!strtonum(optarg, NULL, &id, 0, INT_MAX)) - param_act(P_BAD_VALUE, "owner", "--sid-value", optarg); + xtables_param_act(XTF_ONLY_ONCE, "owner", "--sid-owner", *flags & FLAG_SID_OWNER); + if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--sid-value", optarg); if (invert) info->invert |= IPT_OWNER_SID; info->match |= IPT_OWNER_SID; @@ -156,7 +161,7 @@ owner_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags, #ifdef IPT_OWNER_COMM case 'c': - param_act(P_ONLY_ONCE, "owner", "--cmd-owner", *flags & FLAG_COMM); + xtables_param_act(XTF_ONLY_ONCE, "owner", "--cmd-owner", *flags & FLAG_COMM); if (strlen(optarg) > sizeof(info->comm)) exit_error(PARAMETER_PROBLEM, "owner match: command " "\"%s\" too long, max. %zu characters", @@ -186,12 +191,12 @@ owner_mt6_parse_v0(int c, char **argv, int invert, unsigned int *flags, switch (c) { case 'u': - param_act(P_ONLY_ONCE, "owner", "--uid-owner", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--uid-owner", *flags & FLAG_UID_OWNER); if ((pwd = getpwnam(optarg)) != NULL) id = pwd->pw_uid; - else if (!strtonum(optarg, NULL, &id, 0, ~(uid_t)0)) - param_act(P_BAD_VALUE, "owner", "--uid-owner", optarg); + else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--uid-owner", optarg); if (invert) info->invert |= IP6T_OWNER_UID; info->match |= IP6T_OWNER_UID; @@ -200,12 +205,12 @@ owner_mt6_parse_v0(int c, char **argv, int invert, unsigned int *flags, return true; case 'g': - param_act(P_ONLY_ONCE, "owner", "--gid-owner", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--gid-owner", *flags & FLAG_GID_OWNER); if ((grp = getgrnam(optarg)) != NULL) id = grp->gr_gid; - else if (!strtonum(optarg, NULL, &id, 0, ~(gid_t)0)) - param_act(P_BAD_VALUE, "owner", "--gid-owner", optarg); + else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--gid-owner", optarg); if (invert) info->invert |= IP6T_OWNER_GID; info->match |= IP6T_OWNER_GID; @@ -214,10 +219,10 @@ owner_mt6_parse_v0(int c, char **argv, int invert, unsigned int *flags, return true; case 'p': - param_act(P_ONLY_ONCE, "owner", "--pid-owner", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--pid-owner", *flags & FLAG_PID_OWNER); - if (!strtonum(optarg, NULL, &id, 0, INT_MAX)) - param_act(P_BAD_VALUE, "owner", "--pid-owner", optarg); + if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--pid-owner", optarg); if (invert) info->invert |= IP6T_OWNER_PID; info->match |= IP6T_OWNER_PID; @@ -226,10 +231,10 @@ owner_mt6_parse_v0(int c, char **argv, int invert, unsigned int *flags, return true; case 's': - param_act(P_ONLY_ONCE, "owner", "--sid-owner", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--sid-owner", *flags & FLAG_SID_OWNER); - if (!strtonum(optarg, NULL, &id, 0, INT_MAX)) - param_act(P_BAD_VALUE, "owner", "--sid-owner", optarg); + if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX)) + xtables_param_act(XTF_BAD_VALUE, "owner", "--sid-owner", optarg); if (invert) info->invert |= IP6T_OWNER_SID; info->match |= IP6T_OWNER_SID; @@ -245,15 +250,15 @@ static void owner_parse_range(const char *s, unsigned int *from, { char *end; - /* 4294967295 is reserved, so subtract one from ~0 */ - if (!strtonum(s, &end, from, 0, (~(uid_t)0) - 1)) - param_act(P_BAD_VALUE, "owner", opt, s); + /* -1 is reversed, so the max is one less than that. */ + if (!xtables_strtoui(s, &end, from, 0, UINT32_MAX - 1)) + xtables_param_act(XTF_BAD_VALUE, "owner", opt, s); *to = *from; if (*end == '-' || *end == ':') - if (!strtonum(end + 1, &end, to, 0, (~(uid_t)0) - 1)) - param_act(P_BAD_VALUE, "owner", opt, s); + if (!xtables_strtoui(end + 1, &end, to, 0, UINT32_MAX - 1)) + xtables_param_act(XTF_BAD_VALUE, "owner", opt, s); if (*end != '\0') - param_act(P_BAD_VALUE, "owner", opt, s); + xtables_param_act(XTF_BAD_VALUE, "owner", opt, s); } static int owner_mt_parse(int c, char **argv, int invert, unsigned int *flags, @@ -266,7 +271,7 @@ static int owner_mt_parse(int c, char **argv, int invert, unsigned int *flags, switch (c) { case 'u': - param_act(P_ONLY_ONCE, "owner", "--uid-owner", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--uid-owner", *flags & FLAG_UID_OWNER); if ((pwd = getpwnam(optarg)) != NULL) from = to = pwd->pw_uid; @@ -281,7 +286,7 @@ static int owner_mt_parse(int c, char **argv, int invert, unsigned int *flags, return true; case 'g': - param_act(P_ONLY_ONCE, "owner", "--gid-owner", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--gid-owner", *flags & FLAG_GID_OWNER); if ((grp = getgrnam(optarg)) != NULL) from = to = grp->gr_gid; @@ -296,7 +301,7 @@ static int owner_mt_parse(int c, char **argv, int invert, unsigned int *flags, return true; case 'k': - param_act(P_ONLY_ONCE, "owner", "--socket-exists", + xtables_param_act(XTF_ONLY_ONCE, "owner", "--socket-exists", *flags & FLAG_SOCKET_EXISTS); if (invert) info->invert |= XT_OWNER_SOCKET; |