privops: add support for privileged ntp_adjtime()
This commit is contained in:
parent
d5bc4e92e6
commit
3cb0351aff
2 changed files with 73 additions and 2 deletions
69
privops.c
69
privops.c
|
@ -34,8 +34,9 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define OP_ADJUSTTIME 1024
|
#define OP_ADJUSTTIME 1024
|
||||||
#define OP_SETTIME 1025
|
#define OP_ADJUSTTIMEX 1025
|
||||||
#define OP_BINDSOCKET 1026
|
#define OP_SETTIME 1026
|
||||||
|
#define OP_BINDSOCKET 1027
|
||||||
#define OP_QUIT 1099
|
#define OP_QUIT 1099
|
||||||
|
|
||||||
union sockaddr_in46 {
|
union sockaddr_in46 {
|
||||||
|
@ -52,6 +53,12 @@ typedef struct {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
} ReqAdjustTime;
|
} ReqAdjustTime;
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
typedef struct {
|
||||||
|
struct timex tmx;
|
||||||
|
} ReqAdjustTimex;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
} ReqSetTime;
|
} ReqSetTime;
|
||||||
|
@ -66,6 +73,9 @@ typedef struct {
|
||||||
int op;
|
int op;
|
||||||
union {
|
union {
|
||||||
ReqAdjustTime adjust_time;
|
ReqAdjustTime adjust_time;
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
ReqAdjustTimex adjust_timex;
|
||||||
|
#endif
|
||||||
ReqSetTime set_time;
|
ReqSetTime set_time;
|
||||||
ReqBindSocket bind_socket;
|
ReqBindSocket bind_socket;
|
||||||
} data;
|
} data;
|
||||||
|
@ -77,6 +87,12 @@ typedef struct {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
} ResAdjustTime;
|
} ResAdjustTime;
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
typedef struct {
|
||||||
|
struct timex tmx;
|
||||||
|
} ResAdjustTimex;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char msg[256];
|
char msg[256];
|
||||||
} ResFatalMsg;
|
} ResFatalMsg;
|
||||||
|
@ -88,6 +104,9 @@ typedef struct {
|
||||||
union {
|
union {
|
||||||
ResFatalMsg fatal_msg;
|
ResFatalMsg fatal_msg;
|
||||||
ResAdjustTime adjust_time;
|
ResAdjustTime adjust_time;
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
ResAdjustTimex adjust_timex;
|
||||||
|
#endif
|
||||||
} data;
|
} data;
|
||||||
} PrvResponse;
|
} PrvResponse;
|
||||||
|
|
||||||
|
@ -185,6 +204,21 @@ do_adjust_time(const ReqAdjustTime *req, PrvResponse *res)
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
|
/* HELPER - perform ntp_adjtime() */
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
static void
|
||||||
|
do_adjust_timex(const ReqAdjustTimex *req, PrvResponse *res)
|
||||||
|
{
|
||||||
|
res->data.adjust_timex.tmx = req->tmx;
|
||||||
|
res->rc = ntp_adjtime(&res->data.adjust_timex.tmx);
|
||||||
|
if (res->rc < 0)
|
||||||
|
res->res_errno = errno;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
|
||||||
/* HELPER - perform settimeofday() */
|
/* HELPER - perform settimeofday() */
|
||||||
|
|
||||||
#ifdef PRIVOPS_SETTIME
|
#ifdef PRIVOPS_SETTIME
|
||||||
|
@ -255,6 +289,11 @@ helper_main(int fd)
|
||||||
do_adjust_time(&req.data.adjust_time, &res);
|
do_adjust_time(&req.data.adjust_time, &res);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
case OP_ADJUSTTIMEX:
|
||||||
|
do_adjust_timex(&req.data.adjust_timex, &res);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#ifdef PRIVOPS_SETTIME
|
#ifdef PRIVOPS_SETTIME
|
||||||
case OP_SETTIME:
|
case OP_SETTIME:
|
||||||
do_set_time(&req.data.set_time, &res);
|
do_set_time(&req.data.set_time, &res);
|
||||||
|
@ -417,6 +456,32 @@ PRV_AdjustTime(const struct timeval *delta, struct timeval *olddelta)
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
|
/* DAEMON - request ntp_adjtime() */
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
int
|
||||||
|
PRV_AdjustTimex(struct timex *tmx)
|
||||||
|
{
|
||||||
|
PrvRequest req;
|
||||||
|
PrvResponse res;
|
||||||
|
|
||||||
|
if (!have_helper())
|
||||||
|
return ntp_adjtime(tmx);
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof (req));
|
||||||
|
req.op = OP_ADJUSTTIMEX;
|
||||||
|
req.data.adjust_timex.tmx = *tmx;
|
||||||
|
|
||||||
|
submit_request(&req, &res);
|
||||||
|
|
||||||
|
*tmx = res.data.adjust_timex.tmx;
|
||||||
|
|
||||||
|
return res.rc;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
|
||||||
/* DAEMON - request settimeofday() */
|
/* DAEMON - request settimeofday() */
|
||||||
|
|
||||||
#ifdef PRIVOPS_SETTIME
|
#ifdef PRIVOPS_SETTIME
|
||||||
|
|
|
@ -34,6 +34,12 @@ int PRV_AdjustTime(const struct timeval *delta, struct timeval *olddelta);
|
||||||
#define PRV_AdjustTime adjtime
|
#define PRV_AdjustTime adjtime
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_ADJUSTTIMEX
|
||||||
|
int PRV_AdjustTimex(struct timex *txc);
|
||||||
|
#else
|
||||||
|
#define PRV_AdjustTimex ntp_adjtime
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PRIVOPS_SETTIME
|
#ifdef PRIVOPS_SETTIME
|
||||||
int PRV_SetTime(const struct timeval *tp, const struct timezone *tzp);
|
int PRV_SetTime(const struct timeval *tp, const struct timezone *tzp);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue