Annotation of embedaddon/ntp/ntpd/cmd_args.c, revision 1.1.1.1
1.1 misho 1: /*
2: * cmd_args.c = command-line argument processing
3: */
4: #ifdef HAVE_CONFIG_H
5: # include <config.h>
6: #endif
7:
8: #include "ntpd.h"
9: #include "ntp_stdlib.h"
10: #include "ntp_cmdargs.h"
11:
12: #include "ntpd-opts.h"
13:
14: /*
15: * Definitions of things either imported from or exported to outside
16: */
17: extern char const *progname;
18: extern const char *specific_interface;
19:
20: #ifdef HAVE_NETINFO
21: extern int check_netinfo;
22: #endif
23:
24:
25: /*
26: * getCmdOpts - get command line options
27: */
28: void
29: getCmdOpts(
30: int argc,
31: char *argv[]
32: )
33: {
34: extern const char *config_file;
35: int errflg;
36: tOptions *myOptions = &ntpdOptions;
37:
38: /*
39: * Initialize, initialize
40: */
41: errflg = 0;
42:
43: if (ipv4_works && ipv6_works) {
44: if (HAVE_OPT( IPV4 ))
45: ipv6_works = 0;
46: else if (HAVE_OPT( IPV6 ))
47: ipv4_works = 0;
48: } else if (!ipv4_works && !ipv6_works) {
49: msyslog(LOG_ERR, "Neither IPv4 nor IPv6 networking detected, fatal.");
50: exit(1);
51: } else if (HAVE_OPT( IPV4 ) && !ipv4_works)
52: msyslog(LOG_WARNING, "-4/--ipv4 ignored, IPv4 networking not found.");
53: else if (HAVE_OPT( IPV6 ) && !ipv6_works)
54: msyslog(LOG_WARNING, "-6/--ipv6 ignored, IPv6 networking not found.");
55:
56: if (HAVE_OPT( AUTHREQ ))
57: proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
58: else if (HAVE_OPT( AUTHNOREQ ))
59: proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
60:
61: if (HAVE_OPT( BCASTSYNC ))
62: proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
63:
64: if (HAVE_OPT( CONFIGFILE )) {
65: config_file = OPT_ARG( CONFIGFILE );
66: #ifdef HAVE_NETINFO
67: check_netinfo = 0;
68: #endif
69: }
70:
71: if (HAVE_OPT( DRIFTFILE ))
72: stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ));
73:
74: if (HAVE_OPT( PANICGATE ))
75: allow_panic = TRUE;
76:
77: #ifdef HAVE_DROPROOT
78: if (HAVE_OPT( JAILDIR )) {
79: droproot = 1;
80: chrootdir = OPT_ARG( JAILDIR );
81: }
82: #endif
83:
84: if (HAVE_OPT( KEYFILE ))
85: getauthkeys(OPT_ARG( KEYFILE ));
86:
87: if (HAVE_OPT( PIDFILE ))
88: stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
89:
90: if (HAVE_OPT( QUIT ))
91: mode_ntpdate = TRUE;
92:
93: if (HAVE_OPT( PROPAGATIONDELAY ))
94: do {
95: double tmp;
96: const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
97:
98: if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
99: msyslog(LOG_ERR,
100: "command line broadcast delay value %s undecodable",
101: my_ntp_optarg);
102: } else {
103: proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
104: }
105: } while (0);
106:
107: if (HAVE_OPT( STATSDIR ))
108: stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
109:
110: if (HAVE_OPT( TRUSTEDKEY )) {
111: int ct = STACKCT_OPT( TRUSTEDKEY );
112: const char** pp = STACKLST_OPT( TRUSTEDKEY );
113:
114: do {
115: u_long tkey;
116: const char* p = *pp++;
117:
118: tkey = (int)atol(p);
119: if (tkey == 0 || tkey > NTP_MAXKEY) {
120: msyslog(LOG_ERR,
121: "command line trusted key %s is invalid",
122: p);
123: } else {
124: authtrust(tkey, 1);
125: }
126: } while (--ct > 0);
127: }
128:
129: #ifdef HAVE_DROPROOT
130: if (HAVE_OPT( USER )) {
131: droproot = 1;
132: user = estrdup(OPT_ARG( USER ));
133: group = rindex(user, ':');
134: if (group)
135: *group++ = '\0'; /* get rid of the ':' */
136: }
137: #endif
138:
139: if (HAVE_OPT( VAR )) {
140: int ct = STACKCT_OPT( VAR );
141: const char** pp = STACKLST_OPT( VAR );
142:
143: do {
144: const char* my_ntp_optarg = *pp++;
145:
146: set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
147: (u_short) (RW));
148: } while (--ct > 0);
149: }
150:
151: if (HAVE_OPT( DVAR )) {
152: int ct = STACKCT_OPT( DVAR );
153: const char** pp = STACKLST_OPT( DVAR );
154:
155: do {
156: const char* my_ntp_optarg = *pp++;
157:
158: set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
159: (u_short) (RW | DEF));
160: } while (--ct > 0);
161: }
162:
163: if (HAVE_OPT( SLEW )) {
164: clock_max = 600;
165: kern_enable = 0;
166: }
167: if (HAVE_OPT( UPDATEINTERVAL )) {
168: long val = OPT_VALUE_UPDATEINTERVAL;
169:
170: if (val >= 0)
171: interface_interval = val;
172: else {
173: fprintf(stderr,
174: "command line interface update interval %ld must not be negative\n",
175: val);
176: msyslog(LOG_ERR,
177: "command line interface update interval %ld must not be negative",
178: val);
179: errflg++;
180: }
181: }
182: #ifdef SIM
183:
184: /* SK:
185: * The simulator no longer takes any command line arguments. Hence,
186: * all the code that was here has been removed.
187: */
188:
189: #endif /* SIM */
190:
191: if (errflg || argc) {
192: if (argc)
193: fprintf(stderr, "argc after processing is <%d>\n", argc);
194: optionUsage(myOptions, 2);
195: }
196: return;
197: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>