1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Miroslav Lichvar 2014-2016
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 Function replacements needed when optional features are disabled.
25
26 */
27
28 #include "config.h"
29
30 #include "clientlog.h"
31 #include "cmac.h"
32 #include "cmdmon.h"
33 #include "keys.h"
34 #include "logging.h"
35 #include "manual.h"
36 #include "memory.h"
37 #include "nameserv.h"
38 #include "nameserv_async.h"
39 #include "ntp_core.h"
40 #include "ntp_io.h"
41 #include "ntp_sources.h"
42 #include "ntp_signd.h"
43 #include "nts_ke_client.h"
44 #include "nts_ke_server.h"
45 #include "nts_ntp_client.h"
46 #include "nts_ntp_server.h"
47 #include "privops.h"
48 #include "refclock.h"
49 #include "sched.h"
50 #include "util.h"
51
52 #if defined(FEAT_NTP) && !defined(FEAT_ASYNCDNS)
53
54 /* This is a blocking implementation used when asynchronous resolving is not available */
55
56 struct DNS_Async_Instance {
57 const char *name;
58 DNS_NameResolveHandler handler;
59 void *arg;
60 int pipe[2];
61 };
62
63 static void
resolve_name(int fd,int event,void * anything)64 resolve_name(int fd, int event, void *anything)
65 {
66 struct DNS_Async_Instance *inst;
67 IPAddr addrs[DNS_MAX_ADDRESSES];
68 DNS_Status status;
69 int i;
70
71 inst = (struct DNS_Async_Instance *)anything;
72
73 SCH_RemoveFileHandler(inst->pipe[0]);
74 close(inst->pipe[0]);
75 close(inst->pipe[1]);
76
77 status = PRV_Name2IPAddress(inst->name, addrs, DNS_MAX_ADDRESSES);
78
79 for (i = 0; status == DNS_Success && i < DNS_MAX_ADDRESSES &&
80 addrs[i].family != IPADDR_UNSPEC; i++)
81 ;
82
83 (inst->handler)(status, i, addrs, inst->arg);
84
85 Free(inst);
86 }
87
88 void
DNS_Name2IPAddressAsync(const char * name,DNS_NameResolveHandler handler,void * anything)89 DNS_Name2IPAddressAsync(const char *name, DNS_NameResolveHandler handler, void *anything)
90 {
91 struct DNS_Async_Instance *inst;
92
93 inst = MallocNew(struct DNS_Async_Instance);
94 inst->name = name;
95 inst->handler = handler;
96 inst->arg = anything;
97
98 if (pipe(inst->pipe))
99 LOG_FATAL("pipe() failed");
100
101 UTI_FdSetCloexec(inst->pipe[0]);
102 UTI_FdSetCloexec(inst->pipe[1]);
103
104 SCH_AddFileHandler(inst->pipe[0], SCH_FILE_INPUT, resolve_name, inst);
105
106 if (write(inst->pipe[1], "", 1) < 0)
107 ;
108 }
109
110 #endif /* !FEAT_ASYNCDNS */
111
112 #ifndef FEAT_CMDMON
113
114 void
CAM_Initialise(void)115 CAM_Initialise(void)
116 {
117 }
118
119 void
CAM_Finalise(void)120 CAM_Finalise(void)
121 {
122 }
123
124 void
CAM_OpenUnixSocket(void)125 CAM_OpenUnixSocket(void)
126 {
127 }
128
129 int
CAM_AddAccessRestriction(IPAddr * ip_addr,int subnet_bits,int allow,int all)130 CAM_AddAccessRestriction(IPAddr *ip_addr, int subnet_bits, int allow, int all)
131 {
132 return 1;
133 }
134
135 void
MNL_Initialise(void)136 MNL_Initialise(void)
137 {
138 }
139
140 void
MNL_Finalise(void)141 MNL_Finalise(void)
142 {
143 }
144
145 #endif /* !FEAT_CMDMON */
146
147 #ifndef FEAT_NTP
148
149 void
NCR_AddBroadcastDestination(NTP_Remote_Address * addr,int interval)150 NCR_AddBroadcastDestination(NTP_Remote_Address *addr, int interval)
151 {
152 }
153
154 void
NCR_Initialise(void)155 NCR_Initialise(void)
156 {
157 }
158
159 void
NCR_Finalise(void)160 NCR_Finalise(void)
161 {
162 }
163
164 int
NCR_AddAccessRestriction(IPAddr * ip_addr,int subnet_bits,int allow,int all)165 NCR_AddAccessRestriction(IPAddr *ip_addr, int subnet_bits, int allow, int all)
166 {
167 return 1;
168 }
169
170 int
NCR_CheckAccessRestriction(IPAddr * ip_addr)171 NCR_CheckAccessRestriction(IPAddr *ip_addr)
172 {
173 return 0;
174 }
175
176 void
NIO_Initialise(void)177 NIO_Initialise(void)
178 {
179 }
180
181 void
NIO_Finalise(void)182 NIO_Finalise(void)
183 {
184 }
185
186 void
NSR_Initialise(void)187 NSR_Initialise(void)
188 {
189 }
190
191 void
NSR_Finalise(void)192 NSR_Finalise(void)
193 {
194 }
195
196 NSR_Status
NSR_AddSource(NTP_Remote_Address * remote_addr,NTP_Source_Type type,SourceParameters * params,uint32_t * conf_id)197 NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
198 SourceParameters *params, uint32_t *conf_id)
199 {
200 return NSR_TooManySources;
201 }
202
203 NSR_Status
NSR_AddSourceByName(char * name,int port,int pool,NTP_Source_Type type,SourceParameters * params,uint32_t * conf_id)204 NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
205 SourceParameters *params, uint32_t *conf_id)
206 {
207 return NSR_TooManySources;
208 }
209
210 NSR_Status
NSR_RemoveSource(IPAddr * address)211 NSR_RemoveSource(IPAddr *address)
212 {
213 return NSR_NoSuchSource;
214 }
215
216 void
NSR_RemoveSourcesById(uint32_t conf_id)217 NSR_RemoveSourcesById(uint32_t conf_id)
218 {
219 }
220
221 void
NSR_RemoveAllSources(void)222 NSR_RemoveAllSources(void)
223 {
224 }
225
226 void
NSR_HandleBadSource(IPAddr * address)227 NSR_HandleBadSource(IPAddr *address)
228 {
229 }
230
231 void
NSR_RefreshAddresses(void)232 NSR_RefreshAddresses(void)
233 {
234 }
235
236 char *
NSR_GetName(IPAddr * address)237 NSR_GetName(IPAddr *address)
238 {
239 return NULL;
240 }
241
242 void
NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler)243 NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler)
244 {
245 if (handler)
246 (handler)();
247 }
248
249 void
NSR_ResolveSources(void)250 NSR_ResolveSources(void)
251 {
252 }
253
NSR_StartSources(void)254 void NSR_StartSources(void)
255 {
256 }
257
NSR_AutoStartSources(void)258 void NSR_AutoStartSources(void)
259 {
260 }
261
262 int
NSR_InitiateSampleBurst(int n_good_samples,int n_total_samples,IPAddr * mask,IPAddr * address)263 NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples,
264 IPAddr *mask, IPAddr *address)
265 {
266 return 0;
267 }
268
269 uint32_t
NSR_GetLocalRefid(IPAddr * address)270 NSR_GetLocalRefid(IPAddr *address)
271 {
272 return 0;
273 }
274
275 int
NSR_SetConnectivity(IPAddr * mask,IPAddr * address,SRC_Connectivity connectivity)276 NSR_SetConnectivity(IPAddr *mask, IPAddr *address, SRC_Connectivity connectivity)
277 {
278 return 0;
279 }
280
281 int
NSR_ModifyMinpoll(IPAddr * address,int new_minpoll)282 NSR_ModifyMinpoll(IPAddr *address, int new_minpoll)
283 {
284 return 0;
285 }
286
287 int
NSR_ModifyMaxpoll(IPAddr * address,int new_maxpoll)288 NSR_ModifyMaxpoll(IPAddr *address, int new_maxpoll)
289 {
290 return 0;
291 }
292
293 int
NSR_ModifyMaxdelay(IPAddr * address,double new_max_delay)294 NSR_ModifyMaxdelay(IPAddr *address, double new_max_delay)
295 {
296 return 0;
297 }
298
299 int
NSR_ModifyMaxdelayratio(IPAddr * address,double new_max_delay_ratio)300 NSR_ModifyMaxdelayratio(IPAddr *address, double new_max_delay_ratio)
301 {
302 return 0;
303 }
304
305 int
NSR_ModifyMaxdelaydevratio(IPAddr * address,double new_max_delay_dev_ratio)306 NSR_ModifyMaxdelaydevratio(IPAddr *address, double new_max_delay_dev_ratio)
307 {
308 return 0;
309 }
310
311 int
NSR_ModifyMinstratum(IPAddr * address,int new_min_stratum)312 NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum)
313 {
314 return 0;
315 }
316
317 int
NSR_ModifyPolltarget(IPAddr * address,int new_poll_target)318 NSR_ModifyPolltarget(IPAddr *address, int new_poll_target)
319 {
320 return 0;
321 }
322
323 void
NSR_ReportSource(RPT_SourceReport * report,struct timespec * now)324 NSR_ReportSource(RPT_SourceReport *report, struct timespec *now)
325 {
326 memset(report, 0, sizeof (*report));
327 }
328
329 int
NSR_GetAuthReport(IPAddr * address,RPT_AuthReport * report)330 NSR_GetAuthReport(IPAddr *address, RPT_AuthReport *report)
331 {
332 return 0;
333 }
334
335 int
NSR_GetNTPReport(RPT_NTPReport * report)336 NSR_GetNTPReport(RPT_NTPReport *report)
337 {
338 return 0;
339 }
340
341 void
NSR_GetActivityReport(RPT_ActivityReport * report)342 NSR_GetActivityReport(RPT_ActivityReport *report)
343 {
344 memset(report, 0, sizeof (*report));
345 }
346
347 void
NSR_DumpAuthData(void)348 NSR_DumpAuthData(void)
349 {
350 }
351
352 #ifndef FEAT_CMDMON
353
354 void
CLG_Initialise(void)355 CLG_Initialise(void)
356 {
357 }
358
359 void
CLG_Finalise(void)360 CLG_Finalise(void)
361 {
362 }
363
364 void
DNS_SetAddressFamily(int family)365 DNS_SetAddressFamily(int family)
366 {
367 }
368
369 DNS_Status
DNS_Name2IPAddress(const char * name,IPAddr * ip_addrs,int max_addrs)370 DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
371 {
372 return DNS_Failure;
373 }
374
375 void
KEY_Initialise(void)376 KEY_Initialise(void)
377 {
378 }
379
380 void
KEY_Finalise(void)381 KEY_Finalise(void)
382 {
383 }
384
385 #endif /* !FEAT_CMDMON */
386 #endif /* !FEAT_NTP */
387
388 #ifndef FEAT_REFCLOCK
389 void
RCL_Initialise(void)390 RCL_Initialise(void)
391 {
392 }
393
394 void
RCL_Finalise(void)395 RCL_Finalise(void)
396 {
397 }
398
399 int
RCL_AddRefclock(RefclockParameters * params)400 RCL_AddRefclock(RefclockParameters *params)
401 {
402 return 0;
403 }
404
405 void
RCL_StartRefclocks(void)406 RCL_StartRefclocks(void)
407 {
408 }
409
410 void
RCL_ReportSource(RPT_SourceReport * report,struct timespec * now)411 RCL_ReportSource(RPT_SourceReport *report, struct timespec *now)
412 {
413 memset(report, 0, sizeof (*report));
414 }
415
416 #endif /* !FEAT_REFCLOCK */
417
418 #ifndef FEAT_SIGND
419
420 void
NSD_Initialise(void)421 NSD_Initialise(void)
422 {
423 }
424
425 void
NSD_Finalise(void)426 NSD_Finalise(void)
427 {
428 }
429
430 int
NSD_SignAndSendPacket(uint32_t key_id,NTP_Packet * packet,NTP_PacketInfo * info,NTP_Remote_Address * remote_addr,NTP_Local_Address * local_addr)431 NSD_SignAndSendPacket(uint32_t key_id, NTP_Packet *packet, NTP_PacketInfo *info,
432 NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr)
433 {
434 return 0;
435 }
436
437 #endif /* !FEAT_SIGND */
438
439 #ifndef HAVE_CMAC
440
441 int
CMC_GetKeyLength(CMC_Algorithm algorithm)442 CMC_GetKeyLength(CMC_Algorithm algorithm)
443 {
444 return 0;
445 }
446
447 CMC_Instance
CMC_CreateInstance(CMC_Algorithm algorithm,const unsigned char * key,int length)448 CMC_CreateInstance(CMC_Algorithm algorithm, const unsigned char *key, int length)
449 {
450 return NULL;
451 }
452
453 int
CMC_Hash(CMC_Instance inst,const void * in,int in_len,unsigned char * out,int out_len)454 CMC_Hash(CMC_Instance inst, const void *in, int in_len, unsigned char *out, int out_len)
455 {
456 return 0;
457 }
458
459 void
CMC_DestroyInstance(CMC_Instance inst)460 CMC_DestroyInstance(CMC_Instance inst)
461 {
462 }
463
464 #endif /* !HAVE_CMAC */
465
466 #ifndef FEAT_NTS
467
468 void
NNS_Initialise(void)469 NNS_Initialise(void)
470 {
471 }
472
473 void
NNS_Finalise(void)474 NNS_Finalise(void)
475 {
476 }
477
478 int
NNS_CheckRequestAuth(NTP_Packet * packet,NTP_PacketInfo * info,uint32_t * kod)479 NNS_CheckRequestAuth(NTP_Packet *packet, NTP_PacketInfo *info, uint32_t *kod)
480 {
481 *kod = 0;
482 return 0;
483 }
484
485 int
NNS_GenerateResponseAuth(NTP_Packet * request,NTP_PacketInfo * req_info,NTP_Packet * response,NTP_PacketInfo * res_info,uint32_t kod)486 NNS_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *req_info,
487 NTP_Packet *response, NTP_PacketInfo *res_info,
488 uint32_t kod)
489 {
490 return 0;
491 }
492
493 NNC_Instance
NNC_CreateInstance(IPSockAddr * nts_address,const char * name,uint32_t cert_set,uint16_t ntp_port)494 NNC_CreateInstance(IPSockAddr *nts_address, const char *name, uint32_t cert_set,
495 uint16_t ntp_port)
496 {
497 return NULL;
498 }
499
500 void
NNC_DestroyInstance(NNC_Instance inst)501 NNC_DestroyInstance(NNC_Instance inst)
502 {
503 }
504
505 int
NNC_PrepareForAuth(NNC_Instance inst)506 NNC_PrepareForAuth(NNC_Instance inst)
507 {
508 return 1;
509 }
510
511 int
NNC_GenerateRequestAuth(NNC_Instance inst,NTP_Packet * packet,NTP_PacketInfo * info)512 NNC_GenerateRequestAuth(NNC_Instance inst, NTP_Packet *packet, NTP_PacketInfo *info)
513 {
514 static int logged = 0;
515
516 LOG(logged ? LOGS_DEBUG : LOGS_WARN, "Missing NTS support");
517 logged = 1;
518 return 0;
519 }
520
521 int
NNC_CheckResponseAuth(NNC_Instance inst,NTP_Packet * packet,NTP_PacketInfo * info)522 NNC_CheckResponseAuth(NNC_Instance inst, NTP_Packet *packet, NTP_PacketInfo *info)
523 {
524 return 0;
525 }
526
527 void
NNC_ChangeAddress(NNC_Instance inst,IPAddr * address)528 NNC_ChangeAddress(NNC_Instance inst, IPAddr *address)
529 {
530 }
531
532 void
NNC_DumpData(NNC_Instance inst)533 NNC_DumpData(NNC_Instance inst)
534 {
535 }
536
537 void
NNC_GetReport(NNC_Instance inst,RPT_AuthReport * report)538 NNC_GetReport(NNC_Instance inst, RPT_AuthReport *report)
539 {
540 }
541
542 void
NKS_PreInitialise(uid_t uid,gid_t gid,int scfilter_level)543 NKS_PreInitialise(uid_t uid, gid_t gid, int scfilter_level)
544 {
545 }
546
547 void
NKS_Initialise(void)548 NKS_Initialise(void)
549 {
550 }
551
552 void
NKS_Finalise(void)553 NKS_Finalise(void)
554 {
555 }
556
557 void
NKS_DumpKeys(void)558 NKS_DumpKeys(void)
559 {
560 }
561
562 void
NKS_ReloadKeys(void)563 NKS_ReloadKeys(void)
564 {
565 }
566
567 #endif /* !FEAT_NTS */
568