1 diff -wpruN --no-dereference '--exclude=*.orig' a~/configure a/configure
2 --- a~/configure 1970-01-01 00:00:00
3 +++ a/configure 1970-01-01 00:00:00
4 @@ -208,6 +208,11 @@ get_features () {
7 OPERATINGSYSTEM=`uname -s`
8 +if [ "$OPERATINGSYSTEM" = "SunOS" ]; then
10 + [ -n "$KERNEL" ] && OPERATINGSYSTEM="$KERNEL"
16 @@ -472,7 +477,7 @@ case $OPERATINGSYSTEM in
18 echo "Configuring for macOS (" $SYSTEM "macOS version" $VERSION ")"
22 EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o sys_posix.o"
23 LIBS="$LIBS -lsocket -lnsl -lkvm -lelf -lresolv"
25 @@ -488,6 +493,21 @@ case $OPERATINGSYSTEM in
27 echo "Configuring for illumos (" $SYSTEM "SunOS version" $VERSION ")"
30 + EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o sys_posix.o"
31 + LIBS="$LIBS -lsocket -lnsl -lresolv"
35 + # These are needed to have msg_control in struct msghdr
36 + add_def _XOPEN_SOURCE 600
37 + add_def __EXTENSIONS__ 1
38 + if [ $feat_droproot = "1" ]; then
39 + add_def FEAT_PRIVDROP
40 + priv_ops="ADJUSTTIMEX SETTIME BINDSOCKET"
42 + echo "Configuring for illumos (" $SYSTEM "version" $VERSION ")"
45 echo "error: $SYSTEM is not supported (yet?)"
47 diff -wpruN --no-dereference '--exclude=*.orig' a~/privops.c a/privops.c
48 --- a~/privops.c 1970-01-01 00:00:00
49 +++ a/privops.c 1970-01-01 00:00:00
57 #define OP_ADJUSTTIME 1024
58 @@ -667,6 +668,8 @@ PRV_StartHelper(void)
59 /* ignore signals, the process will exit on OP_QUIT request */
60 UTI_SetQuitSignalsHandler(SIG_IGN, 1);
62 + SYS_DropRoot(0, 0, SYS_PRIV_HELPER);
64 helper_main(sock_fd2);
67 diff -wpruN --no-dereference '--exclude=*.orig' a~/sys.h a/sys.h
68 --- a~/sys.h 1970-01-01 00:00:00
69 +++ a/sys.h 1970-01-01 00:00:00
70 @@ -38,6 +38,7 @@ extern void SYS_Finalise(void);
77 /* Switch to the specified user and group in given context */
78 diff -wpruN --no-dereference '--exclude=*.orig' a~/sys_solaris.c a/sys_solaris.c
79 --- a~/sys_solaris.c 1970-01-01 00:00:00
80 +++ a/sys_solaris.c 1970-01-01 00:00:00
82 #include "sys_timex.h"
88 -/* ================================================== */
91 -set_dosynctodr(int on_off)
93 - struct nlist nl[] = { {"dosynctodr"}, {NULL} };
96 - kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL);
98 - LOG_FATAL("Could not open kvm");
100 - if (kvm_nlist(kt, nl) < 0 || !nl[0].n_value)
101 - LOG_FATAL("Could not get dosynctodr address");
103 - if (kvm_kwrite(kt, nl[0].n_value, &on_off, sizeof (on_off)) < 0)
104 - LOG_FATAL("Could not write to dosynctodr");
108 +#include "logging.h"
110 /* ================================================== */
113 SYS_Solaris_Initialise(void)
115 - /* The kernel keeps the system clock and hardware clock synchronised to each
116 - other. The dosynctodr variable needs to be set to zero to prevent the
117 - the system clock from following the hardware clock when the system clock
118 - is not adjusted by adjtime() or ntp_adjtime(modes=MOD_OFFSET). */
121 /* The kernel allows the frequency to be set in the full range off int32_t */
122 SYS_Timex_InitialiseWithFunctions(32500, 1.0 / 100, NULL, NULL, NULL,
123 0.0, 0.0, NULL, NULL);
124 @@ -85,11 +57,75 @@ SYS_Solaris_Finalise(void)
125 /* ================================================== */
132 SYS_Solaris_DropRoot(uid_t uid, gid_t gid, SYS_ProcessContext context)
134 + priv_set_t *privs, *basicprivs;
137 + setpflags(PRIV_DEBUG, 1);
140 + privs = priv_allocset();
141 + basicprivs = priv_allocset();
143 + if (privs == NULL || basicprivs == NULL)
144 + LOG_FATAL("Failed to allocate privilege sets");
146 + if (getppriv(PRIV_PERMITTED, privs) != 0)
147 + LOG_FATAL("Failed to retrieve current privileges");
149 + priv_basicset(basicprivs);
150 + priv_intersect(basicprivs, privs);
152 + if (context == SYS_PRIV_HELPER) {
153 + /* for OP_BINDSOCKET */
154 + priv_addset(privs, PRIV_NET_PRIVADDR);
155 + /* for OP_SETTIME and OP_ADJUSTTIMEX */
156 + priv_addset(privs, PRIV_SYS_TIME);
158 + priv_delset(privs, PRIV_FILE_LINK_ANY);
159 + priv_delset(privs, PRIV_FILE_READ);
160 + priv_delset(privs, PRIV_FILE_WRITE);
161 + priv_delset(privs, PRIV_NET_ACCESS);
162 + priv_delset(privs, PRIV_PROC_FORK);
163 + priv_delset(privs, PRIV_PROC_EXEC);
164 + priv_delset(privs, PRIV_PROC_SECFLAGS);
165 + priv_delset(privs, PRIV_PROC_INFO);
166 + priv_delset(privs, PRIV_PROC_SESSION);
170 + double mail_threshold;
173 if (context == SYS_MAIN_PROCESS)
176 UTI_DropRoot(uid, gid);
178 + priv_delset(privs, PRIV_FILE_LINK_ANY);
179 + priv_delset(privs, PRIV_PROC_INFO);
180 + priv_delset(privs, PRIV_PROC_SESSION);
182 + CNF_GetMailOnChange(&mail_enabled, &mail_threshold, &mail_user);
183 + if (!mail_enabled) {
184 + priv_delset(privs, PRIV_PROC_FORK);
185 + priv_delset(privs, PRIV_PROC_EXEC);
189 + if (setppriv(PRIV_SET, PRIV_PERMITTED, privs) != 0)
190 + LOG_FATAL("Failed to reduce permitted privileges");
191 + if (setppriv(PRIV_SET, PRIV_INHERITABLE, privs) != 0)
192 + LOG_FATAL("Failed to reduce inheritable privileges");
193 + if (setppriv(PRIV_SET, PRIV_LIMIT, privs) != 0)
194 + LOG_FATAL("Failed to reduce limit privileges");
196 + priv_freeset(privs);
197 + priv_freeset(basicprivs);