summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-03-15 21:02:10 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-03-15 21:02:10 +0000
commit4fab456581899b539dfa38abbe09ffa5d335281f (patch)
tree70982219338e71c3fd83ca47983d1282384fd2c5 /sys/kern
parenta995e755d4518486473cf6405ba5e125b6eb050a (diff)
add sysctl_int_lower(). This can read, but can only write to a kernel
variable if the result is a lowering of the value; tested matthieu
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_sysctl.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 5cdfb1ae031..037afc29aed 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.138 2006/01/28 09:53:37 dlg Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.139 2006/03/15 21:02:09 deraadt Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -674,6 +674,26 @@ debug_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
#endif /* DEBUG */
/*
+ * Reads, or writes that lower the value
+ */
+int
+sysctl_int_lower(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int *valp)
+{
+ unsigned int oval = *valp, val = *valp;
+ int error;
+
+ if (newp == NULL)
+ return (sysctl_rdint(oldp, oldlenp, newp, *valp));
+
+ if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &val)))
+ return (error);
+ if (val > oval)
+ return (EPERM); /* do not allow raising */
+ *(unsigned int *)valp = val;
+ return (0);
+}
+
+/*
* Validate parameters and get old / set new parameters
* for an integer-valued sysctl function.
*/