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:
parent
1661137341
commit
adb22920bc
@ -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;
|
} */ *uap = v;
|
||||||
struct timex ntv;
|
struct timex ntv;
|
||||||
int error = 0;
|
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 modes;
|
||||||
int s;
|
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
|
* Update selected clock variables. Note that there is no error
|
||||||
* change anything. Note that there is no error checking here on
|
* checking here on the assumption the superuser should know
|
||||||
* the assumption the superuser should know what it is doing.
|
* what it is doing.
|
||||||
*/
|
*/
|
||||||
modes = ntv.modes;
|
modes = ntv.modes;
|
||||||
if (modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)))
|
|
||||||
return (error);
|
|
||||||
|
|
||||||
s = splclock();
|
s = splclock();
|
||||||
if (modes & MOD_FREQUENCY)
|
if (modes & MOD_FREQUENCY)
|
||||||
#ifdef PPS_SYNC
|
#ifdef PPS_SYNC
|
||||||
|
@ -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.
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||||
@ -186,7 +186,6 @@ sys_clock_settime(p, v, retval)
|
|||||||
syscallarg(const struct timespec *) tp;
|
syscallarg(const struct timespec *) tp;
|
||||||
} */ *uap = v;
|
} */ *uap = v;
|
||||||
clockid_t clock_id;
|
clockid_t clock_id;
|
||||||
struct timeval atv;
|
|
||||||
struct timespec ats;
|
struct timespec ats;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
@ -194,14 +193,27 @@ sys_clock_settime(p, v, retval)
|
|||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
clock_id = SCARG(uap, clock_id);
|
clock_id = SCARG(uap, clock_id);
|
||||||
if (clock_id != CLOCK_REALTIME)
|
|
||||||
return (EINVAL);
|
|
||||||
|
|
||||||
if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0)
|
if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
TIMESPEC_TO_TIMEVAL(&atv,&ats);
|
return (clock_settime1(clock_id, &ats));
|
||||||
if ((error = settime(&atv)))
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 (error);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -344,26 +356,45 @@ sys_settimeofday(p, v, retval)
|
|||||||
} */ *uap = v;
|
} */ *uap = v;
|
||||||
struct timeval atv;
|
struct timeval atv;
|
||||||
struct timezone atz;
|
struct timezone atz;
|
||||||
|
struct timeval *tv = NULL;
|
||||||
|
struct timezone *tzp = NULL;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
/* Verify all parameters before changing time. */
|
/* Verify all parameters before changing time. */
|
||||||
if (SCARG(uap, tv) && (error = copyin(SCARG(uap, tv),
|
if (SCARG(uap, tv)) {
|
||||||
&atv, sizeof(atv))))
|
if ((error = copyin(SCARG(uap, tv), &atv, sizeof(atv))) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
|
tv = &atv;
|
||||||
|
}
|
||||||
/* XXX since we don't use tz, probably no point in doing copyin. */
|
/* XXX since we don't use tz, probably no point in doing copyin. */
|
||||||
if (SCARG(uap, tzp) && (error = copyin(SCARG(uap, tzp),
|
if (SCARG(uap, tzp)) {
|
||||||
&atz, sizeof(atz))))
|
if ((error = copyin(SCARG(uap, tzp), &atz, sizeof(atz))) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
if (SCARG(uap, tv))
|
tzp = &atz;
|
||||||
if ((error = settime(&atv)))
|
}
|
||||||
|
|
||||||
|
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);
|
return (error);
|
||||||
/*
|
/*
|
||||||
* NetBSD has no kernel notion of time zone, and only an
|
* NetBSD has no kernel notion of time zone, and only an
|
||||||
* obsolete program would try to set it, so we log a warning.
|
* 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 "
|
log(LOG_WARNING, "pid %d attempted to set the "
|
||||||
"(obsolete) kernel time zone\n", p->p_pid);
|
"(obsolete) kernel time zone\n", p->p_pid);
|
||||||
return (0);
|
return (0);
|
||||||
@ -385,8 +416,8 @@ sys_adjtime(p, v, retval)
|
|||||||
syscallarg(struct timeval *) olddelta;
|
syscallarg(struct timeval *) olddelta;
|
||||||
} */ *uap = v;
|
} */ *uap = v;
|
||||||
struct timeval atv;
|
struct timeval atv;
|
||||||
long ndelta, ntickdelta, odelta;
|
struct timeval *oatv = NULL;
|
||||||
int s, error;
|
int error;
|
||||||
|
|
||||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
||||||
return (error);
|
return (error);
|
||||||
@ -394,10 +425,25 @@ sys_adjtime(p, v, retval)
|
|||||||
error = copyin(SCARG(uap, delta), &atv, sizeof(struct timeval));
|
error = copyin(SCARG(uap, delta), &atv, sizeof(struct timeval));
|
||||||
if (error)
|
if (error)
|
||||||
return (error);
|
return (error);
|
||||||
if (SCARG(uap, olddelta) != NULL &&
|
|
||||||
uvm_useracc((caddr_t)SCARG(uap, olddelta), sizeof(struct timeval),
|
if (SCARG(uap, olddelta) != NULL) {
|
||||||
B_WRITE) == FALSE)
|
if (uvm_useracc((caddr_t)SCARG(uap, olddelta),
|
||||||
return (EFAULT);
|
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.
|
* 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
|
* hardclock(), tickdelta will become zero, lest the correction
|
||||||
* overshoot and start taking us away from the desired final time.
|
* 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)
|
if (ndelta > bigadj || ndelta < -bigadj)
|
||||||
ntickdelta = 10 * tickadj;
|
ntickdelta = 10 * tickadj;
|
||||||
else
|
else
|
||||||
@ -427,11 +473,10 @@ sys_adjtime(p, v, retval)
|
|||||||
tickdelta = ntickdelta;
|
tickdelta = ntickdelta;
|
||||||
splx(s);
|
splx(s);
|
||||||
|
|
||||||
if (SCARG(uap, olddelta)) {
|
if (olddelta) {
|
||||||
atv.tv_sec = odelta / 1000000;
|
delta->tv_sec = odelta / 1000000;
|
||||||
atv.tv_usec = odelta % 1000000;
|
delta->tv_usec = odelta % 1000000;
|
||||||
(void) copyout(&atv, SCARG(uap, olddelta),
|
(void) copyout(delta, olddelta, sizeof(struct timeval));
|
||||||
sizeof(struct timeval));
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -516,7 +561,8 @@ sys_setitimer(p, v, retval)
|
|||||||
if ((u_int)which > ITIMER_PROF)
|
if ((u_int)which > ITIMER_PROF)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
itvp = SCARG(uap, itv);
|
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);
|
return (error);
|
||||||
if (SCARG(uap, oitv) != NULL) {
|
if (SCARG(uap, oitv) != NULL) {
|
||||||
SCARG(&getargs, which) = which;
|
SCARG(&getargs, which) = which;
|
||||||
|
Loading…
Reference in New Issue
Block a user