summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkn <kn@cvs.openbsd.org>2019-01-02 23:08:01 +0000
committerkn <kn@cvs.openbsd.org>2019-01-02 23:08:01 +0000
commit43310863b1b4ff17f9f983b320f24df1624e49e4 (patch)
treefcd6455c9ea165d603cd81648a76702607fe68ce
parent7029f90ab0c3240b31be5448e1970eb1db0f9910 (diff)
Error out on missing table command, zap internal wrapper function
Table name and table command require each other as reflected in the synopsis [-t table -T command [address ...]], so print usage and exit if only one of them is given. By moving the inter-dependence check right after option parsing is done, we can bail out even before opening pf(4) and drop the internal wrapper pfctl_command_tables() as unneeded indirection with now duplicate checks. OK sashan
-rw-r--r--sbin/pfctl/pfctl.c7
-rw-r--r--sbin/pfctl/pfctl.h4
-rw-r--r--sbin/pfctl/pfctl_table.c13
3 files changed, 8 insertions, 16 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index c8199fa61ba..78f939e76a9 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.361 2018/12/27 16:33:44 kn Exp $ */
+/* $OpenBSD: pfctl.c,v 1.362 2019/01/02 23:08:00 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -2482,6 +2482,9 @@ main(int argc, char *argv[])
}
}
+ if (tblcmdopt == NULL ^ tableopt == NULL)
+ usage();
+
if (tblcmdopt != NULL) {
argc -= optind;
argv += optind;
@@ -2661,7 +2664,7 @@ main(int argc, char *argv[])
pfctl_kill_src_nodes(dev, ifaceopt, opts);
if (tblcmdopt != NULL) {
- error = pfctl_command_tables(argc, argv, tableopt,
+ error = pfctl_table(argc, argv, tableopt,
tblcmdopt, rulesopt, anchorname, opts);
rulesopt = NULL;
}
diff --git a/sbin/pfctl/pfctl.h b/sbin/pfctl/pfctl.h
index dc36c6cbfe6..776c106d28b 100644
--- a/sbin/pfctl/pfctl.h
+++ b/sbin/pfctl/pfctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.h,v 1.58 2019/01/02 22:59:54 kn Exp $ */
+/* $OpenBSD: pfctl.h,v 1.59 2019/01/02 23:08:00 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -77,7 +77,7 @@ int pfi_clr_istats(const char *, int *, int);
void pfctl_print_title(char *);
void pfctl_clear_tables(const char *, int);
void pfctl_show_tables(const char *, int);
-int pfctl_command_tables(int, char *[], char *, const char *, char *,
+int pfctl_table(int, char *[], char *, const char *, char *,
const char *, int);
void warn_namespace_collision(const char *);
void pfctl_show_ifaces(const char *, int);
diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c
index 05ed48006ab..7adad9da627 100644
--- a/sbin/pfctl/pfctl_table.c
+++ b/sbin/pfctl/pfctl_table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl_table.c,v 1.78 2018/10/15 21:15:35 kn Exp $ */
+/* $OpenBSD: pfctl_table.c,v 1.79 2019/01/02 23:08:00 kn Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@@ -54,8 +54,6 @@
#include "pfctl.h"
extern void usage(void);
-static int pfctl_table(int, char *[], char *, const char *, char *,
- const char *, int);
static void print_table(struct pfr_table *, int, int);
static void print_tstats(struct pfr_tstats *, int);
static int load_addr(struct pfr_buffer *, int, char *[], char *, int, int);
@@ -117,15 +115,6 @@ pfctl_show_tables(const char *anchor, int opts)
}
int
-pfctl_command_tables(int argc, char *argv[], char *tname,
- const char *command, char *file, const char *anchor, int opts)
-{
- if (tname == NULL || command == NULL)
- usage();
- return pfctl_table(argc, argv, tname, command, file, anchor, opts);
-}
-
-int
pfctl_table(int argc, char *argv[], char *tname, const char *command,
char *file, const char *anchor, int opts)
{