mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 19:25:07 -05:00
Linux capabilities support
Attached is a patch adding a linux capabilities support to chronyd. It adds -u option which can be used to specify the user which chronyd should switch to.
This commit is contained in:
committed by
Richard P. Curnow
parent
8336f14680
commit
be42b4eeea
52
sys_linux.c
52
sys_linux.c
@@ -39,6 +39,14 @@
|
||||
#include <assert.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifdef FEAT_LINUXCAPS
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/capability.h>
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
#include "localp.h"
|
||||
#include "sys_linux.h"
|
||||
#include "sched.h"
|
||||
@@ -831,6 +839,50 @@ SYS_Linux_GetKernelVersion(int *major, int *minor, int *patchlevel)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
#ifdef FEAT_LINUXCAPS
|
||||
void
|
||||
SYS_Linux_DropRoot(char *user)
|
||||
{
|
||||
struct passwd *pw;
|
||||
cap_t cap;
|
||||
|
||||
if (user == NULL)
|
||||
return;
|
||||
|
||||
if ((pw = getpwnam(user)) == NULL) {
|
||||
LOG_FATAL(LOGF_SysLinux, "getpwnam(%s) failed", user);
|
||||
}
|
||||
|
||||
if (prctl(PR_SET_KEEPCAPS, 1)) {
|
||||
LOG_FATAL(LOGF_SysLinux, "prcap() failed");
|
||||
}
|
||||
|
||||
if (setgroups(0, NULL)) {
|
||||
LOG_FATAL(LOGF_SysLinux, "setgroups() failed");
|
||||
}
|
||||
|
||||
if (setgid(pw->pw_gid)) {
|
||||
LOG_FATAL(LOGF_SysLinux, "setgid(%d) failed", pw->pw_gid);
|
||||
}
|
||||
|
||||
if (setuid(pw->pw_uid)) {
|
||||
LOG_FATAL(LOGF_SysLinux, "setuid(%d) failed", pw->pw_uid);
|
||||
}
|
||||
|
||||
if ((cap = cap_from_text("cap_sys_time=ep")) == NULL) {
|
||||
LOG_FATAL(LOGF_SysLinux, "cap_from_text() failed");
|
||||
}
|
||||
|
||||
if (cap_set_proc(cap)) {
|
||||
LOG_FATAL(LOGF_SysLinux, "cap_set_proc() failed");
|
||||
}
|
||||
|
||||
LOG(LOGS_INFO, LOGF_SysLinux, "Privileges dropped to user %s", user);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
#endif /* LINUX */
|
||||
|
||||
/* vim:ts=8
|
||||
|
||||
Reference in New Issue
Block a user