Split root-only time-related system calls so that we have an upper part, that

checks root privs, and a lower part that does the actual job. The lower part
will be called by the upcoming clockctl driver. Approved by Christos
Also fixed a few cosmetic things
This commit is contained in:
manu 2001-09-16 06:50:06 +00:00
parent 1661137341
commit adb22920bc
2 changed files with 96 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_ntptime.c,v 1.13 2000/08/07 18:10:21 bjh21 Exp $ */
/* $NetBSD: kern_ntptime.c,v 1.14 2001/09/16 06:50:06 manu Exp $ */
/******************************************************************************
* *
@ -201,22 +201,33 @@ sys_ntp_adjtime(p, v, retval)
} */ *uap = v;
struct timex ntv;
int error = 0;
if ((error = copyin((caddr_t)SCARG(uap, tp), (caddr_t)&ntv,
sizeof(ntv))) != 0)
return (error);
if (ntv.modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
return (ntp_adjtime1(&ntv, retval));
}
int
ntp_adjtime1(struct timex *, register_t*)
struct timex *ntv;
register_t *retval;
{
int error = 0;
int modes;
int s;
if ((error = copyin((caddr_t)SCARG(uap, tp), (caddr_t)&ntv,
sizeof(ntv))))
return (error);
/*
* Update selected clock variables - only the superuser can
* change anything. Note that there is no error checking here on
* the assumption the superuser should know what it is doing.
* Update selected clock variables. Note that there is no error
* checking here on the assumption the superuser should know
* what it is doing.
*/
modes = ntv.modes;
if (modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)))
return (error);
s = splclock();
if (modes & MOD_FREQUENCY)
#ifdef PPS_SYNC

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_time.c,v 1.55 2001/06/11 07:07:12 tron Exp $ */
/* $NetBSD: kern_time.c,v 1.56 2001/09/16 06:50:06 manu Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -186,7 +186,6 @@ sys_clock_settime(p, v, retval)
syscallarg(const struct timespec *) tp;
} */ *uap = v;
clockid_t clock_id;
struct timeval atv;
struct timespec ats;
int error;
@ -194,14 +193,27 @@ sys_clock_settime(p, v, retval)
return (error);
clock_id = SCARG(uap, clock_id);
if (clock_id != CLOCK_REALTIME)
return (EINVAL);
if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0)
return (error);
TIMESPEC_TO_TIMEVAL(&atv,&ats);
if ((error = settime(&atv)))
return (clock_settime1(clock_id, &ats));
}
int
clock_settime1(clock_id, ats)
clockid_t clock_id;
struct timespec *ats;
{
struct timeval atv;
int error;
if (clock_id != CLOCK_REALTIME)
return (EINVAL);
TIMESPEC_TO_TIMEVAL(&atv, ats);
if ((error = settime(&atv)) != 0)
return (error);
return 0;
@ -344,26 +356,45 @@ sys_settimeofday(p, v, retval)
} */ *uap = v;
struct timeval atv;
struct timezone atz;
struct timeval *tv = NULL;
struct timezone *tzp = NULL;
int error;
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
/* Verify all parameters before changing time. */
if (SCARG(uap, tv) && (error = copyin(SCARG(uap, tv),
&atv, sizeof(atv))))
return (error);
if (SCARG(uap, tv)) {
if ((error = copyin(SCARG(uap, tv), &atv, sizeof(atv))) != 0)
return (error);
tv = &atv;
}
/* XXX since we don't use tz, probably no point in doing copyin. */
if (SCARG(uap, tzp) && (error = copyin(SCARG(uap, tzp),
&atz, sizeof(atz))))
return (error);
if (SCARG(uap, tv))
if ((error = settime(&atv)))
if (SCARG(uap, tzp)) {
if ((error = copyin(SCARG(uap, tzp), &atz, sizeof(atz))) != 0)
return (error);
tzp = &atz;
}
return settimeofday1(tv, tzp, p);
}
int
settimeofday1(tv, tzp, p)
struct timeval *tv;
struct timezone *tzp;
struct proc *p;
{
int error;
if (tv)
if ((error = settime(tv)) != 0)
return (error);
/*
* NetBSD has no kernel notion of time zone, and only an
* obsolete program would try to set it, so we log a warning.
*/
if (SCARG(uap, tzp))
if (tzp)
log(LOG_WARNING, "pid %d attempted to set the "
"(obsolete) kernel time zone\n", p->p_pid);
return (0);
@ -385,8 +416,8 @@ sys_adjtime(p, v, retval)
syscallarg(struct timeval *) olddelta;
} */ *uap = v;
struct timeval atv;
long ndelta, ntickdelta, odelta;
int s, error;
struct timeval *oatv = NULL;
int error;
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
@ -394,10 +425,25 @@ sys_adjtime(p, v, retval)
error = copyin(SCARG(uap, delta), &atv, sizeof(struct timeval));
if (error)
return (error);
if (SCARG(uap, olddelta) != NULL &&
uvm_useracc((caddr_t)SCARG(uap, olddelta), sizeof(struct timeval),
B_WRITE) == FALSE)
return (EFAULT);
if (SCARG(uap, olddelta) != NULL) {
if (uvm_useracc((caddr_t)SCARG(uap, olddelta),
sizeof(struct timeval), B_WRITE) == FALSE)
return (EFAULT);
oatv = SCARG(uap, olddelta);
}
return adjtime1(&atv, oatv, p);
}
int
adjtime1(delta, olddelta, p)
struct timeval *delta;
struct timeval *olddelta;
struct proc *p;
{
long ndelta, ntickdelta, odelta;
int s;
/*
* Compute the total correction and the rate at which to apply it.
@ -406,7 +452,7 @@ sys_adjtime(p, v, retval)
* hardclock(), tickdelta will become zero, lest the correction
* overshoot and start taking us away from the desired final time.
*/
ndelta = atv.tv_sec * 1000000 + atv.tv_usec;
ndelta = delta->tv_sec * 1000000 + delta->tv_usec;
if (ndelta > bigadj || ndelta < -bigadj)
ntickdelta = 10 * tickadj;
else
@ -427,11 +473,10 @@ sys_adjtime(p, v, retval)
tickdelta = ntickdelta;
splx(s);
if (SCARG(uap, olddelta)) {
atv.tv_sec = odelta / 1000000;
atv.tv_usec = odelta % 1000000;
(void) copyout(&atv, SCARG(uap, olddelta),
sizeof(struct timeval));
if (olddelta) {
delta->tv_sec = odelta / 1000000;
delta->tv_usec = odelta % 1000000;
(void) copyout(delta, olddelta, sizeof(struct timeval));
}
return (0);
}
@ -516,7 +561,8 @@ sys_setitimer(p, v, retval)
if ((u_int)which > ITIMER_PROF)
return (EINVAL);
itvp = SCARG(uap, itv);
if (itvp && (error = copyin(itvp, &aitv, sizeof(struct itimerval))))
if (itvp &&
(error = copyin(itvp, &aitv, sizeof(struct itimerval)) != 0))
return (error);
if (SCARG(uap, oitv) != NULL) {
SCARG(&getargs, which) = which;