/* ================================================== */
void
-CNF_Initialise(int r)
+CNF_Initialise(int r, int client_only)
{
restarted = r;
dumpdir = Strdup("");
logdir = Strdup("");
- bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
- pidfile = Strdup(DEFAULT_PID_FILE);
rtc_device = Strdup(DEFAULT_RTC_DEVICE);
hwclock_file = Strdup(DEFAULT_HWCLOCK_FILE);
user = Strdup(DEFAULT_USER);
+
+ if (client_only) {
+ cmd_port = ntp_port = 0;
+ bind_cmd_path = Strdup("");
+ pidfile = Strdup("");
+ } else {
+ bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
+ pidfile = Strdup(DEFAULT_PID_FILE);
+ }
}
/* ================================================== */
#include "addressing.h"
#include "reference.h"
-extern void CNF_Initialise(int restarted);
+extern void CNF_Initialise(int restarted, int client_only);
extern void CNF_Finalise(void);
extern char *CNF_GetRtcDevice(void);
will not detach from the terminal.
*-Q*::
-This option is similar to *-q*, but it will only print the offset without any
-corrections of the clock.
+This option is similar to the *-q* option, except it only prints the offset
+without making any corrections of the clock and it allows *chronyd* to be
+started without root privileges.
*-r*::
This option will try to reload and then delete files containing sample
delete_pidfile(void)
{
const char *pidfile = CNF_GetPidFile();
+
+ if (!pidfile[0])
+ return;
+
/* Don't care if this fails, there's not a lot we can do */
unlink(pidfile);
}
const char *pidfile = CNF_GetPidFile();
FILE *out;
+ if (!pidfile[0])
+ return;
+
out = fopen(pidfile, "w");
if (!out) {
LOG_FATAL("Could not open %s : %s", pidfile, strerror(errno));
char *user = NULL, *log_file = NULL;
struct passwd *pw;
int opt, debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
- int do_init_rtc = 0, restarted = 0, timeout = 0;
+ int do_init_rtc = 0, restarted = 0, client_only = 0, timeout = 0;
int scfilter_level = 0, lock_memory = 0, sched_priority = 0;
int clock_control = 1, system_log = 1;
int config_args = 0;
case 'Q':
ref_mode = opt == 'q' ? REF_ModeUpdateOnce : REF_ModePrintOnce;
nofork = 1;
+ client_only = 1;
+ clock_control = 0;
system_log = 0;
break;
case 'r':
}
}
- if (getuid() != 0) {
+ if (getuid() && !client_only)
LOG_FATAL("Not superuser");
- }
/* Turn into a daemon */
if (!nofork) {
DNS_SetAddressFamily(address_family);
- CNF_Initialise(restarted);
+ CNF_Initialise(restarted, client_only);
/* Parse the config file or the remaining command line arguments */
config_args = argc - optind;
/* Create all directories before dropping root */
CNF_CreateDirs(pw->pw_uid, pw->pw_gid);
- /* Drop root privileges if the user has non-zero uid or gid */
- if (pw->pw_uid || pw->pw_gid)
+ /* Drop root privileges if the specified user has a non-zero UID */
+ if (!geteuid() && (pw->pw_uid || pw->pw_gid))
SYS_DropRoot(pw->pw_uid, pw->pw_gid);
REF_Initialise();
"cmdratelimit interval 3 burst 4 leak 3",
};
- CNF_Initialise(0);
+ CNF_Initialise(0, 0);
for (i = 0; i < sizeof conf / sizeof conf[0]; i++)
CNF_ParseLine(NULL, i + 1, conf[i]);
"keyfile "KEYFILE
};
- CNF_Initialise(0);
+ CNF_Initialise(0, 0);
for (i = 0; i < sizeof conf / sizeof conf[0]; i++)
CNF_ParseLine(NULL, i + 1, conf[i]);
CPS_NTP_Source source;
NTP_Remote_Address remote_addr;
- CNF_Initialise(0);
+ CNF_Initialise(0, 0);
for (i = 0; i < sizeof conf / sizeof conf[0]; i++)
CNF_ParseLine(NULL, i + 1, conf[i]);
memset(¶ms, 0, sizeof (params));
- CNF_Initialise(0);
+ CNF_Initialise(0, 0);
CNF_ParseLine(NULL, 1, conf);
LCL_Initialise();
double offset, freq, wander;
char conf[] = "smoothtime 300 0.01";
- CNF_Initialise(0);
+ CNF_Initialise(0, 0);
CNF_ParseLine(NULL, 1, conf);
LCL_Initialise();
double offset, delay, disp;
struct timespec ts;
- CNF_Initialise(0);
+ CNF_Initialise(0, 0);
LCL_Initialise();
TST_RegisterDummyDrivers();
SCH_Initialise();