Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / ntpd / cmd_args.c
blobdcede19374e38d957b330e83c20f49d60566fbae
1 /* $NetBSD: cmd_args.c,v 1.6 2008/08/23 09:10:31 kardel Exp $ */
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 #ifdef SIM
15 # include "ntpsim.h"
16 # include "ntpdsim-opts.h"
17 # define OPTSTRUCT ntpdsimOptions
18 #else
19 # include "ntpd-opts.h"
20 # define OPTSTRUCT ntpdOptions
21 #endif /* SIM */
24 * Definitions of things either imported from or exported to outside
26 extern char const *progname;
27 extern const char *specific_interface;
28 extern short default_ai_family;
30 #ifdef HAVE_NETINFO
31 extern int check_netinfo;
32 #endif
36 * getCmdOpts - get command line options
38 void
39 getCmdOpts(
40 int argc,
41 char *argv[]
44 extern const char *config_file;
45 int errflg;
46 tOptions *myOptions = &OPTSTRUCT;
49 * Initialize, initialize
51 errflg = 0;
53 switch (WHICH_IDX_IPV4) {
54 case INDEX_OPT_IPV4:
55 default_ai_family = AF_INET;
56 break;
57 case INDEX_OPT_IPV6:
58 default_ai_family = AF_INET6;
59 break;
60 default:
61 /* ai_fam_templ = ai_fam_default; */
62 break;
65 if (HAVE_OPT( AUTHREQ ))
66 proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
68 if (HAVE_OPT( AUTHNOREQ ))
69 proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
71 if (HAVE_OPT( BCASTSYNC ))
72 proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
74 if (HAVE_OPT( CONFIGFILE )) {
75 config_file = OPT_ARG( CONFIGFILE );
76 #ifdef HAVE_NETINFO
77 check_netinfo = 0;
78 #endif
81 if (HAVE_OPT( DRIFTFILE ))
82 stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ));
84 if (HAVE_OPT( PANICGATE ))
85 allow_panic = TRUE;
87 if (HAVE_OPT( JAILDIR )) {
88 #ifdef HAVE_DROPROOT
89 droproot = 1;
90 chrootdir = (char *)OPT_ARG( JAILDIR );
91 #else
92 fprintf(stderr,
93 "command line -i option (jaildir) is not supported by this binary"
94 # ifndef SYS_WINNT
95 ",\n" "can not drop root privileges. See configure options\n"
96 "--enable-clockctl and --enable-linuxcaps.\n");
97 # else
98 ".\n");
99 # endif
100 msyslog(LOG_ERR,
101 "command line -i option (jaildir) is not supported by this binary.");
102 errflg++;
103 #endif
106 if (HAVE_OPT( KEYFILE ))
107 getauthkeys(OPT_ARG( KEYFILE ));
109 if (HAVE_OPT( PIDFILE ))
110 stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
112 if (HAVE_OPT( QUIT ))
113 mode_ntpdate = TRUE;
115 if (HAVE_OPT( PROPAGATIONDELAY ))
116 do {
117 double tmp;
118 const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
120 if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
121 msyslog(LOG_ERR,
122 "command line broadcast delay value %s undecodable",
123 my_ntp_optarg);
124 } else {
125 proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
127 } while (0);
129 if (HAVE_OPT( STATSDIR ))
130 stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
132 if (HAVE_OPT( TRUSTEDKEY )) {
133 int ct = STACKCT_OPT( TRUSTEDKEY );
134 const char** pp = STACKLST_OPT( TRUSTEDKEY );
136 do {
137 u_long tkey;
138 const char* p = *pp++;
140 tkey = (int)atol(p);
141 if (tkey == 0 || tkey > NTP_MAXKEY) {
142 msyslog(LOG_ERR,
143 "command line trusted key %s is invalid",
145 } else {
146 authtrust(tkey, 1);
148 } while (--ct > 0);
151 if (HAVE_OPT( USER )) {
152 #ifdef HAVE_DROPROOT
153 char *ntp_optarg = (char *)OPT_ARG( USER );
155 droproot = 1;
156 user = emalloc(strlen(ntp_optarg) + 1);
157 (void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
158 group = rindex(user, ':');
159 if (group)
160 *group++ = '\0'; /* get rid of the ':' */
161 #else
162 fprintf(stderr,
163 "command line -u/--user option is not supported by this binary"
164 # ifndef SYS_WINNT
165 ",\n" "can not drop root privileges. See configure options\n"
166 "--enable-clockctl and --enable-linuxcaps.\n");
167 # else
168 ".\n");
169 # endif
170 msyslog(LOG_ERR,
171 "command line -u/--user option is not supported by this binary.");
172 errflg++;
173 #endif
176 if (HAVE_OPT( VAR )) {
177 int ct = STACKCT_OPT( VAR );
178 const char** pp = STACKLST_OPT( VAR );
180 do {
181 const char* my_ntp_optarg = *pp++;
183 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
184 (u_short) (RW));
185 } while (--ct > 0);
188 if (HAVE_OPT( DVAR )) {
189 int ct = STACKCT_OPT( DVAR );
190 const char** pp = STACKLST_OPT( DVAR );
192 do {
193 const char* my_ntp_optarg = *pp++;
195 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
196 (u_short) (RW | DEF));
197 } while (--ct > 0);
200 if (HAVE_OPT( SLEW ))
201 clock_max = 600;
203 if (HAVE_OPT( UPDATEINTERVAL )) {
204 long val = OPT_VALUE_UPDATEINTERVAL;
206 if (val >= 0)
207 interface_interval = val;
208 else {
209 fprintf(stderr,
210 "command line interface update interval %ld must not be negative\n",
211 val);
212 msyslog(LOG_ERR,
213 "command line interface update interval %ld must not be negative",
214 val);
215 errflg++;
218 #ifdef SIM
219 if (HAVE_OPT( SIMBROADCASTDELAY ))
220 sscanf(OPT_ARG( SIMBROADCASTDELAY ), "%lf", &ntp_node.bdly);
222 if (HAVE_OPT( PHASENOISE ))
223 sscanf(OPT_ARG( PHASENOISE ), "%lf", &ntp_node.snse);
225 if (HAVE_OPT( SIMSLEW ))
226 sscanf(OPT_ARG( SIMSLEW ), "%lf", &ntp_node.slew);
228 if (HAVE_OPT( SERVERTIME ))
229 sscanf(OPT_ARG( SERVERTIME ), "%lf", &ntp_node.clk_time);
231 if (HAVE_OPT( ENDSIMTIME ))
232 sscanf(OPT_ARG( ENDSIMTIME ), "%lf", &ntp_node.sim_time);
234 if (HAVE_OPT( FREQERR ))
235 sscanf(OPT_ARG( FREQERR ), "%lf", &ntp_node.ferr);
237 if (HAVE_OPT( WALKNOISE ))
238 sscanf(OPT_ARG( WALKNOISE ), "%lf", &ntp_node.fnse);
240 if (HAVE_OPT( NDELAY ))
241 sscanf(OPT_ARG( NDELAY ), "%lf", &ntp_node.ndly);
243 if (HAVE_OPT( PDELAY ))
244 sscanf(OPT_ARG( PDELAY ), "%lf", &ntp_node.pdly);
246 #endif /* SIM */
248 if (errflg || argc) {
249 if (argc)
250 fprintf(stderr, "argc after processing is <%d>\n", argc);
251 optionUsage(myOptions, 2);
253 return;