From 5682f21557419aa00ba8387cac95fb1b9e28526c Mon Sep 17 00:00:00 2001 From: rwatson Date: Wed, 28 Nov 2001 21:22:05 +0000 Subject: o Cache req->td->td_proc->p_ucred->cr_prison in pr to improve readability. o Conditionalize only the SYSCTL definitions for the regression tree, not the variables itself, decreasing the number of #ifdef REGRESSIONs scattered in kern_mib.c, and making the code more readable. Sponsored by: DARPA, NAI Labs --- sys/kern/kern_mib.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'sys/kern/kern_mib.c') diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c index 9007922..37eaf55 100644 --- a/sys/kern/kern_mib.c +++ b/sys/kern/kern_mib.c @@ -154,14 +154,15 @@ char hostname[MAXHOSTNAMELEN]; static int sysctl_hostname(SYSCTL_HANDLER_ARGS) { + struct prison *pr; int error; - if (jailed(req->td->td_proc->p_ucred)) { + pr = req->td->td_proc->p_ucred->cr_prison; + if (pr != NULL) { if (!jail_set_hostname_allowed && req->newptr) return (EPERM); - error = sysctl_handle_string(oidp, - req->td->td_proc->p_ucred->cr_prison->pr_host, - sizeof req->td->td_proc->p_ucred->cr_prison->pr_host, req); + error = sysctl_handle_string(oidp, pr->pr_host, + sizeof pr->pr_host, req); } else error = sysctl_handle_string(oidp, hostname, sizeof hostname, req); @@ -172,9 +173,9 @@ SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_hostname, "A", "Hostname"); -#ifdef REGRESSION static int regression_securelevel_nonmonotonic = 0; +#ifdef REGRESSION SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW, ®ression_securelevel_nonmonotonic, 0, "securelevel may be lowered"); #endif @@ -205,17 +206,13 @@ sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS) * global level, and local level if any. */ if (pr != NULL) { -#ifdef REGRESSION - if (!regression_securelevel_nonmonotonic) -#endif - if (level < imax(securelevel, pr->pr_securelevel)) + if (!regression_securelevel_nonmonotonic && + (level < imax(securelevel, pr->pr_securelevel))) return (EPERM); pr->pr_securelevel = level; } else { -#ifdef REGRESSION - if (!regression_securelevel_nonmonotonic) -#endif - if (level < securelevel) + if (!regression_securelevel_nonmonotonic && + (level < securelevel)) return (EPERM); securelevel = level; } -- cgit v1.1