2001-08-29 14:35:15 +00:00
|
|
|
/*
|
|
|
|
* cmd_args.c = command-line argument processing
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ntpd.h"
|
|
|
|
#include "ntp_stdlib.h"
|
2014-12-20 22:52:39 +00:00
|
|
|
#include "ntp_config.h"
|
2001-08-29 14:35:15 +00:00
|
|
|
#include "ntp_cmdargs.h"
|
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
#include "ntpd-opts.h"
|
2004-07-20 15:01:56 +00:00
|
|
|
|
2001-08-29 14:35:15 +00:00
|
|
|
/*
|
|
|
|
* Definitions of things either imported from or exported to outside
|
|
|
|
*/
|
|
|
|
extern char const *progname;
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINFO
|
|
|
|
extern int check_netinfo;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-12-20 22:52:39 +00:00
|
|
|
* getCmdOpts - apply most command line options
|
|
|
|
*
|
|
|
|
* A few options are examined earlier in ntpd.c ntpdmain() and
|
|
|
|
* ports/winnt/ntpd/ntservice.c main().
|
2001-08-29 14:35:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2008-08-18 14:26:05 +00:00
|
|
|
getCmdOpts(
|
2014-12-20 22:52:39 +00:00
|
|
|
int argc,
|
|
|
|
char ** argv
|
2001-08-29 14:35:15 +00:00
|
|
|
)
|
|
|
|
{
|
2008-08-18 14:26:05 +00:00
|
|
|
extern const char *config_file;
|
2001-08-29 14:35:15 +00:00
|
|
|
int errflg;
|
|
|
|
|
|
|
|
/*
|
2008-08-18 14:26:05 +00:00
|
|
|
* Initialize, initialize
|
2001-08-29 14:35:15 +00:00
|
|
|
*/
|
|
|
|
errflg = 0;
|
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
if (ipv4_works && ipv6_works) {
|
|
|
|
if (HAVE_OPT( IPV4 ))
|
|
|
|
ipv6_works = 0;
|
|
|
|
else if (HAVE_OPT( IPV6 ))
|
|
|
|
ipv4_works = 0;
|
|
|
|
} else if (!ipv4_works && !ipv6_works) {
|
|
|
|
msyslog(LOG_ERR, "Neither IPv4 nor IPv6 networking detected, fatal.");
|
|
|
|
exit(1);
|
|
|
|
} else if (HAVE_OPT( IPV4 ) && !ipv4_works)
|
|
|
|
msyslog(LOG_WARNING, "-4/--ipv4 ignored, IPv4 networking not found.");
|
|
|
|
else if (HAVE_OPT( IPV6 ) && !ipv6_works)
|
|
|
|
msyslog(LOG_WARNING, "-6/--ipv6 ignored, IPv6 networking not found.");
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( AUTHREQ ))
|
|
|
|
proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
|
2013-12-04 21:33:17 +00:00
|
|
|
else if (HAVE_OPT( AUTHNOREQ ))
|
2008-08-18 14:26:05 +00:00
|
|
|
proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
|
|
|
|
|
|
|
|
if (HAVE_OPT( BCASTSYNC ))
|
|
|
|
proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
|
|
|
|
|
|
|
|
if (HAVE_OPT( CONFIGFILE )) {
|
|
|
|
config_file = OPT_ARG( CONFIGFILE );
|
|
|
|
#ifdef HAVE_NETINFO
|
|
|
|
check_netinfo = 0;
|
2001-08-29 14:35:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( DRIFTFILE ))
|
2020-03-04 13:59:29 +00:00
|
|
|
stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ), 0);
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
if (HAVE_OPT( PANICGATE ))
|
|
|
|
allow_panic = TRUE;
|
|
|
|
|
2015-04-10 01:26:02 +00:00
|
|
|
if (HAVE_OPT( FORCE_STEP_ONCE ))
|
|
|
|
force_step_once = TRUE;
|
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
#ifdef HAVE_DROPROOT
|
2013-12-04 21:33:17 +00:00
|
|
|
if (HAVE_OPT( JAILDIR )) {
|
|
|
|
droproot = 1;
|
|
|
|
chrootdir = OPT_ARG( JAILDIR );
|
2001-08-29 14:35:15 +00:00
|
|
|
}
|
2013-12-04 21:33:17 +00:00
|
|
|
#endif
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( KEYFILE ))
|
|
|
|
getauthkeys(OPT_ARG( KEYFILE ));
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( PIDFILE ))
|
2020-03-04 13:59:29 +00:00
|
|
|
stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ), 0);
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( QUIT ))
|
|
|
|
mode_ntpdate = TRUE;
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( PROPAGATIONDELAY ))
|
|
|
|
do {
|
|
|
|
double tmp;
|
|
|
|
const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
|
|
|
|
msyslog(LOG_ERR,
|
|
|
|
"command line broadcast delay value %s undecodable",
|
|
|
|
my_ntp_optarg);
|
|
|
|
} else {
|
|
|
|
proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (HAVE_OPT( STATSDIR ))
|
2020-03-04 13:59:29 +00:00
|
|
|
stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ), 0);
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
if (HAVE_OPT( TRUSTEDKEY )) {
|
2009-12-12 22:29:30 +00:00
|
|
|
int ct = STACKCT_OPT( TRUSTEDKEY );
|
|
|
|
const char** pp = STACKLST_OPT( TRUSTEDKEY );
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
u_long tkey;
|
|
|
|
const char* p = *pp++;
|
|
|
|
|
|
|
|
tkey = (int)atol(p);
|
|
|
|
if (tkey == 0 || tkey > NTP_MAXKEY) {
|
|
|
|
msyslog(LOG_ERR,
|
|
|
|
"command line trusted key %s is invalid",
|
|
|
|
p);
|
|
|
|
} else {
|
|
|
|
authtrust(tkey, 1);
|
|
|
|
}
|
|
|
|
} while (--ct > 0);
|
|
|
|
}
|
2001-08-29 14:35:15 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
#ifdef HAVE_DROPROOT
|
2013-12-04 21:33:17 +00:00
|
|
|
if (HAVE_OPT( USER )) {
|
2008-08-18 14:26:05 +00:00
|
|
|
droproot = 1;
|
2013-12-04 21:33:17 +00:00
|
|
|
user = estrdup(OPT_ARG( USER ));
|
2014-12-20 22:52:39 +00:00
|
|
|
group = strrchr(user, ':');
|
|
|
|
if (group != NULL) {
|
|
|
|
size_t len;
|
|
|
|
|
2009-12-12 22:29:30 +00:00
|
|
|
*group++ = '\0'; /* get rid of the ':' */
|
2014-12-20 22:52:39 +00:00
|
|
|
len = group - user;
|
|
|
|
group = estrdup(group);
|
|
|
|
user = erealloc(user, len);
|
|
|
|
}
|
2008-08-18 14:26:05 +00:00
|
|
|
}
|
2013-12-04 21:33:17 +00:00
|
|
|
#endif
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
if (HAVE_OPT( VAR )) {
|
2014-12-20 22:52:39 +00:00
|
|
|
int ct;
|
|
|
|
const char ** pp;
|
|
|
|
const char * v_assign;
|
2008-08-18 14:26:05 +00:00
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
ct = STACKCT_OPT( VAR );
|
|
|
|
pp = STACKLST_OPT( VAR );
|
2008-08-18 14:26:05 +00:00
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
do {
|
|
|
|
v_assign = *pp++;
|
|
|
|
set_sys_var(v_assign, strlen(v_assign) + 1, RW);
|
2008-08-18 14:26:05 +00:00
|
|
|
} while (--ct > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HAVE_OPT( DVAR )) {
|
2009-12-12 22:29:30 +00:00
|
|
|
int ct = STACKCT_OPT( DVAR );
|
|
|
|
const char** pp = STACKLST_OPT( DVAR );
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
const char* my_ntp_optarg = *pp++;
|
|
|
|
|
|
|
|
set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
|
|
|
|
(u_short) (RW | DEF));
|
|
|
|
} while (--ct > 0);
|
|
|
|
}
|
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
if (HAVE_OPT( SLEW ))
|
|
|
|
loop_config(LOOP_MAX, 600);
|
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (HAVE_OPT( UPDATEINTERVAL )) {
|
|
|
|
long val = OPT_VALUE_UPDATEINTERVAL;
|
2015-04-10 01:26:02 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (val >= 0)
|
|
|
|
interface_interval = val;
|
|
|
|
else {
|
2015-04-10 01:26:02 +00:00
|
|
|
fprintf(stderr,
|
2009-12-12 22:29:30 +00:00
|
|
|
"command line interface update interval %ld must not be negative\n",
|
|
|
|
val);
|
2015-04-10 01:26:02 +00:00
|
|
|
msyslog(LOG_ERR,
|
2009-12-12 22:29:30 +00:00
|
|
|
"command line interface update interval %ld must not be negative",
|
|
|
|
val);
|
2008-08-18 14:26:05 +00:00
|
|
|
errflg++;
|
|
|
|
}
|
|
|
|
}
|
2004-07-20 15:01:56 +00:00
|
|
|
|
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
/* save list of servers from cmd line for config_peers() use */
|
|
|
|
if (argc > 0) {
|
|
|
|
cmdline_server_count = argc;
|
|
|
|
cmdline_servers = argv;
|
2001-08-29 14:35:15 +00:00
|
|
|
}
|
2014-12-20 22:52:39 +00:00
|
|
|
|
|
|
|
/* display usage & exit with any option processing errors */
|
|
|
|
if (errflg)
|
|
|
|
optionUsage(&ntpdOptions, 2); /* does not return */
|
2001-08-29 14:35:15 +00:00
|
|
|
}
|