summaryrefslogtreecommitdiff
path: root/sbin/pfctl
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-12-31 16:48:37 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-12-31 16:48:37 +0000
commita77104479538bd5b4f0275cd44fa48804ecd8693 (patch)
treec3c5a915fa89ba07bbdba9fa4b97a6c53e55879e /sbin/pfctl
parent239003eb7b76de04fffd98deff247d096960c0ac (diff)
only open device for writing if we gonna modify anything
Diffstat (limited to 'sbin/pfctl')
-rw-r--r--sbin/pfctl/pfctl.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index 3f242510653..55280ef9ca4 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.48 2001/12/10 18:08:12 dhartmei Exp $ */
+/* $OpenBSD: pfctl.c,v 1.49 2001/12/31 16:48:36 mickey Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -678,6 +678,7 @@ main(int argc, char *argv[])
int error = 0;
int dev = -1;
int ch;
+ int mode = O_RDONLY;
if (argc < 2)
usage();
@@ -686,36 +687,44 @@ main(int argc, char *argv[])
switch (ch) {
case 'd':
opts |= PF_OPT_DISABLE;
+ mode = O_RDWR;
break;
case 'e':
opts |= PF_OPT_ENABLE;
+ mode = O_RDWR;
break;
case 'q':
opts |= PF_OPT_QUIET;
break;
case 'F':
clearopt = optarg;
+ mode = O_RDWR;
break;
case 'l':
logopt = optarg;
+ mode = O_RDWR;
break;
case 'n':
opts |= PF_OPT_NOACTION;
break;
case 'N':
natopt = optarg;
+ mode = O_RDWR;
break;
case 'O':
hintopt = optarg;
+ mode = O_RDWR;
break;
case 'R':
rulesopt = optarg;
+ mode = O_RDWR;
break;
case 's':
showopt = optarg;
break;
case 't':
timeoutopt = optarg;
+ mode = O_RDWR;
break;
case 'v':
opts |= PF_OPT_VERBOSE;
@@ -736,8 +745,10 @@ main(int argc, char *argv[])
/* NOTREACHED */
}
+ if (opts & PF_OPT_NOACTION)
+ mode = O_RDONLY;
if ((opts & PF_OPT_NOACTION) == 0) {
- dev = open("/dev/pf", O_RDWR);
+ dev = open("/dev/pf", mode);
if (dev == -1)
err(1, "open(\"/dev/pf\")");
} else {