Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / ntpd / cmd_args.c
blob17b357b4fe43e0e0265de4043e1746f5c7502239
1 /* $NetBSD$ */
3 /*
4 * cmd_args.c = command-line argument processing
5 */
6 #ifdef HAVE_CONFIG_H
7 # include <config.h>
8 #endif
10 #include "ntpd.h"
11 #include "ntp_stdlib.h"
12 #include "ntp_cmdargs.h"
14 #include "ntpd-opts.h"
17 * Definitions of things either imported from or exported to outside
19 extern char const *progname;
20 extern const char *specific_interface;
21 extern short default_ai_family;
23 #ifdef HAVE_NETINFO
24 extern int check_netinfo;
25 #endif
29 * getCmdOpts - get command line options
31 void
32 getCmdOpts(
33 int argc,
34 char *argv[]
37 extern const char *config_file;
38 int errflg;
39 tOptions *myOptions = &ntpdOptions;
42 * Initialize, initialize
44 errflg = 0;
46 if (HAVE_OPT( IPV4 ))
47 default_ai_family = AF_INET;
48 else if (HAVE_OPT( IPV6 ))
49 default_ai_family = AF_INET6;
51 if (HAVE_OPT( AUTHREQ ))
52 proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
53 else if (HAVE_OPT( AUTHNOREQ ))
54 proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
56 if (HAVE_OPT( BCASTSYNC ))
57 proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
59 if (HAVE_OPT( CONFIGFILE )) {
60 config_file = OPT_ARG( CONFIGFILE );
61 #ifdef HAVE_NETINFO
62 check_netinfo = 0;
63 #endif
66 if (HAVE_OPT( DRIFTFILE ))
67 stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ));
69 if (HAVE_OPT( PANICGATE ))
70 allow_panic = TRUE;
72 #ifdef HAVE_DROPROOT
73 if (HAVE_OPT( JAILDIR )) {
74 droproot = 1;
75 chrootdir = OPT_ARG( JAILDIR );
77 #endif
79 if (HAVE_OPT( KEYFILE ))
80 getauthkeys(OPT_ARG( KEYFILE ));
82 if (HAVE_OPT( PIDFILE ))
83 stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
85 if (HAVE_OPT( QUIT ))
86 mode_ntpdate = TRUE;
88 if (HAVE_OPT( PROPAGATIONDELAY ))
89 do {
90 double tmp;
91 const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
93 if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
94 msyslog(LOG_ERR,
95 "command line broadcast delay value %s undecodable",
96 my_ntp_optarg);
97 } else {
98 proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
100 } while (0);
102 if (HAVE_OPT( STATSDIR ))
103 stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
105 if (HAVE_OPT( TRUSTEDKEY )) {
106 int ct = STACKCT_OPT( TRUSTEDKEY );
107 const char** pp = STACKLST_OPT( TRUSTEDKEY );
109 do {
110 u_long tkey;
111 const char* p = *pp++;
113 tkey = (int)atol(p);
114 if (tkey == 0 || tkey > NTP_MAXKEY) {
115 msyslog(LOG_ERR,
116 "command line trusted key %s is invalid",
118 } else {
119 authtrust(tkey, 1);
121 } while (--ct > 0);
124 #ifdef HAVE_DROPROOT
125 if (HAVE_OPT( USER )) {
126 droproot = 1;
127 user = estrdup(OPT_ARG( USER ));
128 group = rindex(user, ':');
129 if (group)
130 *group++ = '\0'; /* get rid of the ':' */
132 #endif
134 if (HAVE_OPT( VAR )) {
135 int ct = STACKCT_OPT( VAR );
136 const char** pp = STACKLST_OPT( VAR );
138 do {
139 const char* my_ntp_optarg = *pp++;
141 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
142 (u_short) (RW));
143 } while (--ct > 0);
146 if (HAVE_OPT( DVAR )) {
147 int ct = STACKCT_OPT( DVAR );
148 const char** pp = STACKLST_OPT( DVAR );
150 do {
151 const char* my_ntp_optarg = *pp++;
153 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
154 (u_short) (RW | DEF));
155 } while (--ct > 0);
158 if (HAVE_OPT( SLEW )) {
159 clock_max = 600;
160 kern_enable = 0;
162 if (HAVE_OPT( UPDATEINTERVAL )) {
163 long val = OPT_VALUE_UPDATEINTERVAL;
165 if (val >= 0)
166 interface_interval = val;
167 else {
168 fprintf(stderr,
169 "command line interface update interval %ld must not be negative\n",
170 val);
171 msyslog(LOG_ERR,
172 "command line interface update interval %ld must not be negative",
173 val);
174 errflg++;
177 #ifdef SIM
179 /* SK:
180 * The simulator no longer takes any command line arguments. Hence,
181 * all the code that was here has been removed.
184 #endif /* SIM */
186 if (errflg || argc) {
187 if (argc)
188 fprintf(stderr, "argc after processing is <%d>\n", argc);
189 optionUsage(myOptions, 2);
191 return;