]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
configure: add option to set default user
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Apr 2014 14:28:44 +0000 (16:28 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Apr 2014 14:30:06 +0000 (16:30 +0200)
The default user is root by default, which disables root dropping by
default. The user directive or the -u option can still be used to set
the user.

chrony.texi.in
chronyd.8.in
conf.c
configure
main.c

index 18fbf41b94911f757b9a70b16aa75aef87c5444a..583d5ed6289c639281f6a005c8a8a453920e1be3 100644 (file)
@@ -1028,8 +1028,9 @@ to work well, it relies on @code{chronyd} having been able to determine
 accurate statistics for the difference between the real time clock and
 system clock last time the computer was on.
 @item -u <user>
-When this option is used, chronyd will drop root privileges to the specified
-user.  So far, it works only on Linux when compiled with capabilities support.
+This option sets the name of the user to which will @code{chronyd} switch to
+drop root privileges if compiled with Linux capabilities support (default
+@code{@DEFAULT_USER@}).
 @item -q
 When run in this mode, @code{chronyd} will set the system clock once
 and exit.  It will not detach from the terminal.
@@ -2958,10 +2959,11 @@ be set to run 0.183ppm faster than it would be without the compensation, etc.
 @node user directive
 @subsection user
 The @code{user} directive sets the name of the user to which will
-@code{chronyd} drop root privileges after the initialisation. So far, it works
-only on Linux when compiled with capabilities support.
+@code{chronyd} switch on initialisation to drop root privileges.
+So far, it works only on Linux when compiled with capabilities support.
+Setting the name to root will disable it.
 
-By default, root privileges are not dropped.
+The default value is @code{@DEFAULT_USER@}.
 @c }}}
 @c }}}
 @c {{{ S:Running chronyc
index 245388ace621af77aab9382f79e509bacd2f1c91..39a762369f32465ec17b29b59ec30c8ed34aa8bc 100644 (file)
@@ -103,8 +103,9 @@ between the real time clock and system clock last time the
 computer was on.
 .TP
 \fB\-u\fR \fIuser\fR
-When this option is used, chronyd will drop root privileges to the specified
-user.  So far, it works only on Linux when compiled with capabilities support.
+This option sets the name of the user to which will \fBchronyd\fR switch to
+drop root privileges if compiled with Linux capabilities support (default
+\fB@DEFAULT_USER@\fR).
 .TP
 .B \-q
 When run in this mode, chronyd will set the system clock once
diff --git a/conf.c b/conf.c
index 649e4b1cce21bd79ad206737caa806439bedc5b1..3a176e11afa7a286b6acb66f7b5c0bff59be4c90 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -203,7 +203,7 @@ static int lock_memory = 0;
 static char *leapsec_tz = NULL;
 
 /* Name of the user to which will be dropped root privileges. */
-static char *user = NULL;
+static char *user = DEFAULT_USER;
 
 typedef struct {
   NTP_Source_Type type;
index 971e7e44d051381a94d79fc77316716aab757ca6..6bbe1e9038679f097436529c019ee5a1e143802a 100755 (executable)
--- a/configure
+++ b/configure
@@ -113,6 +113,7 @@ For better control, use the options below.
   --disable-rtc          Don't include RTC even on Linux
   --disable-linuxcaps    Disable Linux capabilities support
   --disable-forcednsretry Don't retry on permanent DNS error
+  --with-user=USER       Specify default chronyd user [root]
   --with-sendmail=PATH   Path to sendmail binary [/usr/lib/sendmail]
   --enable-debug         Enable debugging support
 
@@ -191,6 +192,7 @@ feat_pps=1
 try_setsched=0
 try_lockmem=0
 feat_forcednsretry=1
+default_user="root"
 mail_program="/usr/lib/sendmail"
 
 for option
@@ -268,6 +270,9 @@ do
     --disable-forcednsretry)
       feat_forcednsretry=0
     ;;
+    --with-user=* )
+      default_user=`echo $option | sed -e 's/^.*=//;'`
+    ;;
     --with-sendmail=* )
       mail_program=`echo $option | sed -e 's/^.*=//;'`
     ;;
@@ -618,6 +623,7 @@ fi
 
 add_def DEBUG $debug
 add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
+add_def DEFAULT_USER "\"$default_user\""
 add_def MAIL_PROGRAM "\"$mail_program\""
 
 if [ -f version.txt ]; then
@@ -649,7 +655,8 @@ do
           s%@MANDIR@%${MANDIR}%;\
           s%@INFODIR@%${INFODIR}%;\
           s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
-          s%@CHRONYVARDIR@%${CHRONYVARDIR}%;"\
+          s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
+          s%@DEFAULT_USER@%${default_user}%;"\
           < ${f}.in > $f
 done
 
diff --git a/main.c b/main.c
index 77d8d2dd27b3473b87dd2f6452640c792bf5f7a8..e8daf33d4addac38f20f298e0815cdd61dc83b8a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -466,7 +466,7 @@ int main
   if (!user) {
     user = CNF_GetUser();
   }
-  if (user) {
+  if (user && strcmp(user, "root")) {
     SYS_DropRoot(user);
   }