OpenDNSSEC-signer 2.1.13
signercommands.c
Go to the documentation of this file.
1#include "config.h"
2
3#include "file.h"
4#include "str.h"
5#include "locks.h"
6#include "log.h"
7#include "status.h"
8#include "util.h"
9#include "longgetopt.h"
10#include "daemon/engine.h"
11#include "cmdhandler.h"
12#include "signercommands.h"
13#include "clientpipe.h"
14
15static char const * cmdh_str = "cmdhandler";
16
17static const char*
18cmdargument(const char* cmd, const char* matchValue, const char* defaultValue)
19{
20 const char* s = cmd;
21 if (!s)
22 return defaultValue;
23 while(*s && !isspace(*s))
24 ++s;
25 while(*s && isspace(*s))
26 ++s;
27 if(matchValue) {
28 if (!strcmp(s,matchValue))
29 return s;
30 else
31 return defaultValue;
32 } else if(*s) {
33 return s;
34 } else {
35 return defaultValue;
36 }
37}
38
43static int
44cmdhandler_handle_cmd_help(cmdhandler_ctx_type* context, char *cmd)
45{
46 int sockfd = context->sockfd;
47 char buf[ODS_SE_MAXLINE];
48
49 (void) snprintf(buf, ODS_SE_MAXLINE,
50 "Commands:\n"
51 "zones Show the currently known zones.\n"
52 "sign <zone> [--serial <nr>] Read zone and schedule for immediate "
53 "(re-)sign.\n"
54 " If a serial is given, that serial is used "
55 "in the output zone.\n"
56 "sign --all Read all zones and schedule all for "
57 "immediate (re-)sign.\n"
58 );
59 client_printf(sockfd, "%s", buf);
60
61 (void) snprintf(buf, ODS_SE_MAXLINE,
62 "clear <zone> Delete the internal storage of this "
63 "zone.\n"
64 " All signatures will be regenerated "
65 "on the next re-sign.\n"
66 "queue Show the current task queue.\n"
67 "flush Execute all scheduled tasks "
68 "immediately.\n"
69 );
70 client_printf(sockfd, "%s", buf);
71
72 (void) snprintf(buf, ODS_SE_MAXLINE,
73 "update <zone> Update this zone signer "
74 "configurations.\n"
75 "update [--all] Update zone list and all signer "
76 "configurations.\n"
77 "retransfer <zone> Retransfer the zone from the master.\n"
78 "start Start the engine.\n"
79 "running Check if the engine is running.\n"
80 "reload Reload the engine.\n"
81 "stop Stop the engine.\n"
82 "verbosity <nr> Set verbosity.\n"
83 );
84 client_printf(sockfd, "%s", buf);
85 return 0;
86}
87
88
93static int
94cmdhandler_handle_cmd_zones(cmdhandler_ctx_type* context, char *cmd)
95{
96 int sockfd = context->sockfd;
97 engine_type* engine;
98 char buf[ODS_SE_MAXLINE];
99 size_t i;
100 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
101 zone_type* zone = NULL;
102 engine = getglobalcontext(context);
103 if (!engine->zonelist || !engine->zonelist->zones) {
104 (void)snprintf(buf, ODS_SE_MAXLINE, "There are no zones configured\n");
105 client_printf(sockfd, "%s", buf);
106 return 0;
107 }
108 /* how many zones */
109 pthread_mutex_lock(&engine->zonelist->zl_lock);
110 (void)snprintf(buf, ODS_SE_MAXLINE, "There are %i zones configured\n",
111 (int) engine->zonelist->zones->count);
112 client_printf(sockfd, "%s", buf);
113 /* list zones */
114 node = ldns_rbtree_first(engine->zonelist->zones);
115 while (node && node != LDNS_RBTREE_NULL) {
116 zone = (zone_type*) node->data;
117 for (i=0; i < ODS_SE_MAXLINE; i++) {
118 buf[i] = 0;
119 }
120 (void)snprintf(buf, ODS_SE_MAXLINE, "- %s\n", zone->name);
121 client_printf(sockfd, "%s", buf);
122 node = ldns_rbtree_next(node);
123 }
124 pthread_mutex_unlock(&engine->zonelist->zl_lock);
125 return 0;
126}
127
128
133static int
134cmdhandler_handle_cmd_update(cmdhandler_ctx_type* context, char *cmd)
135{
136 int sockfd = context->sockfd;
137 engine_type* engine;
138 char buf[ODS_SE_MAXLINE];
139 zone_type* zone = NULL;
140 ods_status zl_changed = ODS_STATUS_OK;
141 engine = getglobalcontext(context);
142 ods_log_assert(engine);
143 ods_log_assert(engine->taskq);
144 if (cmdargument(cmd, "--all", NULL)) {
145 pthread_mutex_lock(&engine->zonelist->zl_lock);
146 zl_changed = zonelist_update(engine->zonelist,
147 engine->config->zonelist_filename);
148 if (zl_changed == ODS_STATUS_UNCHANGED) {
149 (void)snprintf(buf, ODS_SE_MAXLINE, "Zone list has not changed."
150 " Signer configurations updated.\n");
151 client_printf(sockfd, "%s", buf);
152 } else if (zl_changed == ODS_STATUS_OK) {
153 (void)snprintf(buf, ODS_SE_MAXLINE, "Zone list updated: %i "
154 "removed, %i added, %i updated.\n",
155 engine->zonelist->just_removed,
156 engine->zonelist->just_added,
157 engine->zonelist->just_updated);
158 client_printf(sockfd, "%s", buf);
159 } else {
160 pthread_mutex_unlock(&engine->zonelist->zl_lock);
161 (void)snprintf(buf, ODS_SE_MAXLINE, "Zone list has errors.\n");
162 client_printf(sockfd, "%s", buf);
163 }
164 if (zl_changed == ODS_STATUS_OK ||
165 zl_changed == ODS_STATUS_UNCHANGED) {
166 engine->zonelist->just_removed = 0;
167 engine->zonelist->just_added = 0;
168 engine->zonelist->just_updated = 0;
169 pthread_mutex_unlock(&engine->zonelist->zl_lock);
174 engine_update_zones(engine, ODS_STATUS_OK);
175 }
176 } else {
177 /* look up zone */
178 pthread_mutex_lock(&engine->zonelist->zl_lock);
179 zone = zonelist_lookup_zone_by_name(engine->zonelist, cmdargument(cmd, NULL, ""),
180 LDNS_RR_CLASS_IN);
181 /* If this zone is just added, don't update (it might not have a
182 * task yet) */
183 if (zone && zone->zl_status == ZONE_ZL_ADDED) {
184 zone = NULL;
185 }
186 pthread_mutex_unlock(&engine->zonelist->zl_lock);
187
188 if (!zone) {
189 (void)snprintf(buf, ODS_SE_MAXLINE, "Error: Zone %s not found.\n",
190 cmdargument(cmd, NULL, ""));
191 client_printf(sockfd, "%s", buf);
192 /* update all */
193 cmdhandler_handle_cmd_update(context, "update --all");
194 return 1;
195 }
196
197 pthread_mutex_lock(&zone->zone_lock);
198 schedule_scheduletask(engine->taskq, TASK_FORCESIGNCONF, zone->name, zone, &zone->zone_lock, schedule_PROMPTLY);
199 pthread_mutex_unlock(&zone->zone_lock);
200
201 (void)snprintf(buf, ODS_SE_MAXLINE, "Zone %s config being updated.\n",
202 cmdargument(cmd, NULL, ""));
203 client_printf(sockfd, "%s", buf);
204 ods_log_verbose("[%s] zone %s scheduled for immediate update signconf",
205 cmdh_str, cmdargument(cmd, NULL, ""));
206 engine_wakeup_workers(engine);
207 }
208 return 0;
209}
210
211
216static int
217cmdhandler_handle_cmd_retransfer(cmdhandler_ctx_type* context, char *cmd)
218{
219 int sockfd = context->sockfd;
220 engine_type* engine;
221 char buf[ODS_SE_MAXLINE];
222 zone_type* zone = NULL;
223 engine = getglobalcontext(context);
224 ods_log_assert(engine->taskq);
225 /* look up zone */
226 pthread_mutex_lock(&engine->zonelist->zl_lock);
227 zone = zonelist_lookup_zone_by_name(engine->zonelist, cmdargument(cmd, NULL, ""),
228 LDNS_RR_CLASS_IN);
229 /* If this zone is just added, don't retransfer (it might not have a
230 * task yet) */
231 if (zone && zone->zl_status == ZONE_ZL_ADDED) {
232 zone = NULL;
233 }
234 pthread_mutex_unlock(&engine->zonelist->zl_lock);
235
236 if (!zone) {
237 (void)snprintf(buf, ODS_SE_MAXLINE, "Error: Zone %s not found.\n",
238 cmdargument(cmd, NULL, ""));
239 client_printf(sockfd, "%s", buf);
240 } else if (zone->adinbound->type != ADAPTER_DNS) {
241 (void)snprintf(buf, ODS_SE_MAXLINE,
242 "Error: Zone %s not configured to use DNS input adapter.\n",
243 cmdargument(cmd, NULL, ""));
244 client_printf(sockfd, "%s", buf);
245 } else {
246 zone->xfrd->serial_retransfer = 1;
248 ods_log_debug("[%s] forward a notify", cmdh_str);
250 (uint8_t*) ODS_SE_NOTIFY_CMD, strlen(ODS_SE_NOTIFY_CMD));
251 (void)snprintf(buf, ODS_SE_MAXLINE, "Zone %s being re-transfered.\n", cmdargument(cmd, NULL, ""));
252 client_printf(sockfd, "%s", buf);
253 ods_log_verbose("[%s] zone %s being re-transfered", cmdh_str, cmdargument(cmd, NULL, ""));
254 }
255 return 0;
256}
257
258
259static uint32_t
260max(uint32_t a, uint32_t b)
261{
262 return (a<b?b:a);
263}
264
265static ods_status
266forceread(engine_type* engine, zone_type *zone, int force_serial, uint32_t serial, int sockfd)
267{
268 pthread_mutex_lock(&zone->zone_lock);
269 if (force_serial) {
270 ods_log_assert(zone->db);
271 if (!util_serial_gt(serial, max(zone->db->outserial,
272 zone->db->inbserial))) {
273 pthread_mutex_unlock(&zone->zone_lock);
274 client_printf(sockfd, "Error: Unable to enforce serial %u for zone %s.\n", serial, zone->name);
275 return 1;
276 }
277 zone->db->altserial = serial;
278 zone->db->force_serial = 1;
279 }
280 schedule_scheduletask(engine->taskq, TASK_FORCEREAD, zone->name, zone, &zone->zone_lock, schedule_IMMEDIATELY);
281 pthread_mutex_unlock(&zone->zone_lock);
282 return 0;
283}
284
285static struct option signoptions[] = {
286 { "all", 0, NULL, 'a' },
287 { "zone", 1, NULL, 'z' },
288 { "serial", 1, NULL, 's' },
289 { "time", 1, NULL, 't' },
290 { NULL, 0, NULL, 0 }
291};
292
293int
294getlong(char* s, char** endptr, long *result)
295{
296 char *end;
297 while(isspace(*s))
298 ++s;
299 errno = 0;
300 *result = strtol(s, &end, 0);
301 if(errno == ERANGE) {
302 *endptr = NULL;
303 return -1;
304 }
305 if(end) {
306 if(s == end) {
307 if(endptr)
308 *endptr = end;
309 return -1;
310 }
311 while(isspace(*end))
312 ++end;
313 if(endptr) {
314 *endptr = end;
315 return 0;
316 } else if(*end)
317 return -1;
318 else
319 return 0;
320 } else {
321 *endptr = end;
322 return -1;
323 }
324}
325
326static int
327cmdhandler_handle_cmd_sign(cmdhandler_ctx_type* context, int argc, char* argv[])
328{
329 engine_type* engine;
330 struct longgetopt optctx;
331 int allzones = 0;
332 int longindex;
333 char* zonename = NULL;
334 zone_type *zone;
335 int force_serial = 0;
336 long serial = 0;
337 char* signtime = NULL;
338 int opt;
339
340 engine = getglobalcontext(context);
341 /* Skip the "sign" command itself, then parse options */
342 ++argv;
343 --argc;
344 for(opt = longgetopt(argc, argv, "az:s:t:", signoptions, &longindex, &optctx); opt != -1;
345 opt = longgetopt(argc, argv, NULL, signoptions, &longindex, &optctx)) {
346 switch(opt) {
347 case 'a':
348 allzones = 1;
349 break;
350 case 'z':
351 zonename = optctx.optarg;
352 break;
353 case 's':
354 getlong(optctx.optarg, NULL, &serial);
355 force_serial = 1;
356 break;
357 case 't':
358 signtime = optctx.optarg;
359 break;
360 default:
361 client_printf_err(context->sockfd, "unknown arguments\n");
362 return -1;
363 }
364 }
365 if(optctx.optind < argc)
366 zonename = argv[optctx.optind];
367 if(!allzones && (zonename == NULL || *zonename == '\0')) {
368 client_printf_err(context->sockfd, "No zone name provided to zone sign command.\n");
369 return -1;
370 }
371 if(allzones) {
372 pthread_mutex_lock(&engine->zonelist->zl_lock);
373 ldns_rbnode_t* node;
374 for (node = ldns_rbtree_first(engine->zonelist->zones); node != LDNS_RBTREE_NULL && node != NULL; node = ldns_rbtree_next(node)) {
375 zone = (zone_type*)node->data;
376 forceread(engine, zone, 0, 0, context->sockfd);
377 }
378 pthread_mutex_unlock(&engine->zonelist->zl_lock);
379 engine_wakeup_workers(engine);
380 client_printf(context->sockfd, "All zones scheduled for immediate re-sign.\n");
381 } else {
382 pthread_mutex_lock(&engine->zonelist->zl_lock);
383 zone = zonelist_lookup_zone_by_name(engine->zonelist, zonename, LDNS_RR_CLASS_IN);
384 /* If this zone is just added, don't update (it might not have a task
385 * yet).
386 */
387 if (zone && zone->zl_status == ZONE_ZL_ADDED) {
388 zone = NULL;
389 }
390 pthread_mutex_unlock(&engine->zonelist->zl_lock);
391
392 if (!zone) {
393 client_printf(context->sockfd, "Error: Zone %s not found.\n", zonename);
394 return 1;
395 }
396
397 forceread(engine, zone, force_serial, serial, context->sockfd);
398 engine_wakeup_workers(engine);
399 client_printf(context->sockfd, "Zone %s scheduled for immediate re-sign.\n", zonename);
400 ods_log_verbose("zone %s scheduled for immediate re-sign", zonename);
401 }
402 return 0;
403}
404
409static void
410unlink_backup_file(const char* filename, const char* extension)
411{
412 char* tmpname = ods_build_path(filename, extension, 0, 1);
413 if (tmpname) {
414 ods_log_debug("[%s] unlink file %s", cmdh_str, tmpname);
415 unlink(tmpname);
416 free((void*)tmpname);
417 }
418}
419
424static int
425cmdhandler_handle_cmd_clear(cmdhandler_ctx_type* context, char *cmd)
426{
427 int sockfd = context->sockfd;
428 engine_type* engine;
429 char buf[ODS_SE_MAXLINE];
430 zone_type* zone = NULL;
431 uint32_t inbserial = 0;
432 uint32_t intserial = 0;
433 uint32_t outserial = 0;
434 engine = getglobalcontext(context);
435 unlink_backup_file(cmdargument(cmd, NULL, ""), ".inbound");
436 unlink_backup_file(cmdargument(cmd, NULL, ""), ".backup");
437 unlink_backup_file(cmdargument(cmd, NULL, ""), ".axfr");
438 unlink_backup_file(cmdargument(cmd, NULL, ""), ".ixfr");
439 pthread_mutex_lock(&engine->zonelist->zl_lock);
440 zone = zonelist_lookup_zone_by_name(engine->zonelist, cmdargument(cmd, NULL, ""),
441 LDNS_RR_CLASS_IN);
442 pthread_mutex_unlock(&engine->zonelist->zl_lock);
443 if (zone) {
444 pthread_mutex_lock(&zone->zone_lock);
445 inbserial = zone->db->inbserial;
446 intserial = zone->db->intserial;
447 outserial = zone->db->outserial;
448 namedb_cleanup(zone->db);
449 ixfr_cleanup(zone->ixfr);
451
452 zone->db = namedb_create((void*)zone);
453 zone->ixfr = ixfr_create();
454 zone->signconf = signconf_create();
455
456 if (!zone->signconf || !zone->ixfr || !zone->db) {
457 ods_fatal_exit("[%s] unable to clear zone %s: failed to recreate"
458 "signconf, ixfr of db structure (out of memory?)", cmdh_str, cmdargument(cmd, NULL, ""));
459 return 1;
460 }
461 /* restore serial management */
462 zone->db->inbserial = inbserial;
463 zone->db->intserial = intserial;
464 zone->db->outserial = outserial;
465 zone->db->have_serial = 1;
466
467 /* If a zone does not have a task we probably never read a signconf
468 * for it. Skip reschedule step */
469 schedule_scheduletask(engine->taskq, TASK_FORCESIGNCONF, zone->name, zone, &zone->zone_lock, schedule_IMMEDIATELY);
470 pthread_mutex_unlock(&zone->zone_lock);
471
472 (void)snprintf(buf, ODS_SE_MAXLINE, "Internal zone information about "
473 "%s cleared", cmdargument(cmd, NULL, ""));
474 ods_log_info("[%s] internal zone information about %s cleared",
475 cmdh_str, cmdargument(cmd, NULL, ""));
476 } else {
477 (void)snprintf(buf, ODS_SE_MAXLINE, "Cannot clear zone %s, zone not "
478 "found", cmdargument(cmd, NULL, ""));
479 ods_log_warning("[%s] cannot clear zone %s, zone not found",
480 cmdh_str, cmdargument(cmd, NULL, ""));
481 }
482 client_printf(sockfd, "%s", buf);
483 return 0;
484}
485
486
491static int
492cmdhandler_handle_cmd_queue(cmdhandler_ctx_type* context, char *cmd)
493{
494 int sockfd = context->sockfd;
495 engine_type* engine;
496 char* strtime = NULL;
497 char buf[ODS_SE_MAXLINE];
498 char* taskdesc;
499 size_t i = 0;
500 time_t now = 0;
501 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
502 task_type* task = NULL;
503 engine = getglobalcontext(context);
504 if (!engine->taskq || !engine->taskq->tasks) {
505 (void)snprintf(buf, ODS_SE_MAXLINE, "There are no tasks scheduled.\n");
506 client_printf(sockfd, "%s", buf);
507 return 0;
508 }
509 /* current time */
510 now = time_now();
511 strtime = ctime(&now);
512 (void)snprintf(buf, ODS_SE_MAXLINE, "It is now %s",
513 strtime?strtime:"(null)");
514 client_printf(sockfd, "%s", buf);
515 /* current work */
516 pthread_mutex_lock(&engine->taskq->schedule_lock);
517 /* how many tasks */
518 (void)snprintf(buf, ODS_SE_MAXLINE, "\nThere are %i tasks scheduled.\n",
519 (int) engine->taskq->tasks->count);
520 client_printf(sockfd, "%s", buf);
521 /* list tasks */
522 node = ldns_rbtree_first(engine->taskq->tasks);
523 while (node && node != LDNS_RBTREE_NULL) {
524 task = (task_type*) node->data;
525 for (i=0; i < ODS_SE_MAXLINE; i++) {
526 buf[i] = 0;
527 }
528 taskdesc = schedule_describetask(task);
529 client_printf(sockfd, "%s", taskdesc);
530 free(taskdesc);
531 node = ldns_rbtree_next(node);
532 }
533 pthread_mutex_unlock(&engine->taskq->schedule_lock);
534 return 0;
535}
536
537
542static int
543cmdhandler_handle_cmd_flush(cmdhandler_ctx_type* context, char *cmd)
544{
545 int sockfd = context->sockfd;
546 engine_type* engine;
547 char buf[ODS_SE_MAXLINE];
548 engine = getglobalcontext(context);
549 ods_log_assert(engine->taskq);
550 schedule_flush(engine->taskq);
551 engine_wakeup_workers(engine);
552 (void)snprintf(buf, ODS_SE_MAXLINE, "All tasks scheduled immediately.\n");
553 client_printf(sockfd, "%s", buf);
554 ods_log_verbose("[%s] all tasks scheduled immediately", cmdh_str);
555 return 0;
556}
557
558
563static int
564cmdhandler_handle_cmd_reload(cmdhandler_ctx_type* context, char *cmd)
565{
566 int sockfd = context->sockfd;
567 engine_type* engine;
568 char buf[ODS_SE_MAXLINE];
569 engine = getglobalcontext(context);
570 ods_log_error("signer instructed to reload due to explicit command");
571 engine->need_to_reload = 1;
572 pthread_mutex_lock(&engine->signal_lock);
573 pthread_cond_signal(&engine->signal_cond);
574 pthread_mutex_unlock(&engine->signal_lock);
575 (void)snprintf(buf, ODS_SE_MAXLINE, "Reloading engine.\n");
576 client_printf(sockfd, "%s", buf);
577 return 0;
578}
579
580
585static int
586cmdhandler_handle_cmd_stop(cmdhandler_ctx_type* context, char *cmd)
587{
588 int sockfd = context->sockfd;
589 engine_type* engine;
590 char buf[ODS_SE_MAXLINE];
591 engine = getglobalcontext(context);
592 engine->need_to_exit = 1;
593 pthread_mutex_lock(&engine->signal_lock);
594 pthread_cond_signal(&engine->signal_cond);
595 pthread_mutex_unlock(&engine->signal_lock);
596 (void)snprintf(buf, ODS_SE_MAXLINE, ODS_SE_STOP_RESPONSE);
597 client_printf(sockfd, "%s", buf);
598 return 0;
599}
600
601
606static int
607cmdhandler_handle_cmd_start(cmdhandler_ctx_type* context, char *cmd)
608{
609 int sockfd = context->sockfd;
610 char buf[ODS_SE_MAXLINE];
611 (void)snprintf(buf, ODS_SE_MAXLINE, "Engine already running.\n");
612 client_printf(sockfd, "%s", buf);
613 return 0;
614}
615
616
621static int
622cmdhandler_handle_cmd_running(cmdhandler_ctx_type* context, char *cmd)
623{
624 int sockfd = context->sockfd;
625 char buf[ODS_SE_MAXLINE];
626 (void)snprintf(buf, ODS_SE_MAXLINE, "Engine running.\n");
627 client_printf(sockfd, "%s", buf);
628 return 0;
629}
630
631
636static int
637cmdhandler_handle_cmd_verbosity(cmdhandler_ctx_type* context, char *cmd)
638{
639 int sockfd = context->sockfd;
640 char buf[ODS_SE_MAXLINE];
641 int val;
642 val = atoi(cmdargument(cmd, NULL, "1"));
643 ods_log_setverbosity(val);
644 (void)snprintf(buf, ODS_SE_MAXLINE, "Verbosity level set to %i.\n", val);
645 client_printf(sockfd, "%s", buf);
646 return 0;
647}
648
649
654static void
655cmdhandler_handle_cmd_error(int sockfd, cmdhandler_ctx_type* context, char* str)
656{
657 char buf[ODS_SE_MAXLINE];
658 (void)snprintf(buf, ODS_SE_MAXLINE, "Error: %s.\n", str?str:"(null)");
659 client_printf(sockfd, "%s", buf);
660}
661
662
667static int
668cmdhandler_handle_cmd_timeleap(cmdhandler_ctx_type* context, char *cmd)
669{
670 int sockfd = context->sockfd;
671 struct tm strtime_struct;
672 char strtime[64]; /* at least 26 according to docs plus a long integer */
673 time_t now = time_now();
674 time_t time_leap = 0;
675 time_t next_leap = 0;
676 struct tm tm;
677 int taskcount;
678 engine_type* engine = getglobalcontext(context);
679
680 /* skip "time" and "leap" */
681 while(isspace(*cmd)) ++cmd;
682 cmd = &cmd[4];
683 while(isspace(*cmd)) ++cmd;
684 cmd = &cmd[4];
685 while(isspace(*cmd)) ++cmd;
686
687 if (strptime(cmd, "%Y-%m-%d-%H:%M:%S", &tm)) {
688 tm.tm_isdst = -1;
689 time_leap = mktime(&tm);
690 client_printf(sockfd, "Using %s parameter value as time to leap to\n", cmd);
691 } else {
692 client_printf_err(sockfd, "Time leap: Error - could not convert '%s' to a time. Format is YYYY-MM-DD-HH:MM:SS \n", cmd);
693 return -1;
694 }
695 if (!engine->taskq || !engine->taskq->tasks) {
696 client_printf(sockfd, "There are no tasks scheduled.\n");
697 return 1;
698 }
699 schedule_info(engine->taskq, &next_leap, NULL, &taskcount);
700 now = time_now();
701 strftime(strtime, sizeof (strtime), "%c", localtime_r(&now, &strtime_struct));
702 client_printf(sockfd, "There are %i tasks scheduled.\nIt is now %s (%ld seconds since epoch)\n", taskcount, strtime, (long) now);
703 set_time_now(time_leap);
704 strftime(strtime, sizeof (strtime), "%c", localtime_r(&time_leap, &strtime_struct));
705 client_printf(sockfd, "Leaping to time %s (%ld seconds since epoch)\n", (strtime[0] ? strtime : "(null)"), (long) time_leap);
706 ods_log_info("Time leap: Leaping to time %s\n", strtime);
707 client_printf(sockfd, "Waking up workers\n");
708 engine_wakeup_workers(engine);
709 return 0;
710}
711
712struct cmd_func_block helpCmdDef = { "help", NULL, NULL, NULL, &cmdhandler_handle_cmd_help, NULL };
713struct cmd_func_block zonesCmdDef = { "zones", NULL, NULL, NULL, &cmdhandler_handle_cmd_zones, NULL };
714struct cmd_func_block signCmdDef = { "sign", NULL, NULL, NULL, NULL, &cmdhandler_handle_cmd_sign };
715struct cmd_func_block clearCmdDef = { "clear", NULL, NULL, NULL, &cmdhandler_handle_cmd_clear, NULL };
716struct cmd_func_block queueCmdDef = { "queue", NULL, NULL, NULL, &cmdhandler_handle_cmd_queue, NULL };
717struct cmd_func_block flushCmdDef = { "flush", NULL, NULL, NULL, &cmdhandler_handle_cmd_flush, NULL };
718struct cmd_func_block updateCmdDef = { "update", NULL, NULL, NULL, &cmdhandler_handle_cmd_update, NULL };
719struct cmd_func_block stopCmdDef = { "stop", NULL, NULL, NULL, &cmdhandler_handle_cmd_stop, NULL };
720struct cmd_func_block startCmdDef = { "start", NULL, NULL, NULL, &cmdhandler_handle_cmd_start, NULL };
721struct cmd_func_block reloadCmdDef = { "reload", NULL, NULL, NULL, &cmdhandler_handle_cmd_reload, NULL };
722struct cmd_func_block retransferCmdDef = { "retransfer", NULL, NULL, NULL, &cmdhandler_handle_cmd_retransfer, NULL };
723struct cmd_func_block runningCmdDef = { "running", NULL, NULL, NULL, &cmdhandler_handle_cmd_running, NULL };
724struct cmd_func_block verbosityCmdDef = { "verbosity", NULL, NULL, NULL, &cmdhandler_handle_cmd_verbosity, NULL };
725struct cmd_func_block timeleapCmdDef = { "time leap", NULL, NULL, NULL, &cmdhandler_handle_cmd_timeleap, NULL };
726
727struct cmd_func_block* signcommands[] = {
728 &helpCmdDef,
730 &signCmdDef,
735 &stopCmdDef,
742 NULL
743};
744struct cmd_func_block** signercommands = signcommands;
745
747getglobalcontext(cmdhandler_ctx_type* context)
748{
749 return (engine_type*) context->globalcontext;
750}
@ ADAPTER_DNS
Definition adapter.h:42
void dnshandler_fwd_notify(dnshandler_type *dnshandler, uint8_t *pkt, size_t len)
Definition dnshandler.c:231
#define ODS_SE_NOTIFY_CMD
Definition dnshandler.h:48
void engine_wakeup_workers(engine_type *engine)
Definition engine.c:291
void engine_update_zones(engine_type *engine, ods_status zl_changed)
Definition engine.c:617
void ixfr_cleanup(ixfr_type *ixfr)
Definition ixfr.c:277
ixfr_type * ixfr_create()
Definition ixfr.c:91
namedb_type * namedb_create(void *zone)
Definition namedb.c:121
void namedb_cleanup(namedb_type *db)
Definition namedb.c:1131
void signconf_cleanup(signconf_type *sc)
Definition signconf.c:470
signconf_type * signconf_create(void)
Definition signconf.c:47
struct cmd_func_block zonesCmdDef
struct cmd_func_block verbosityCmdDef
struct cmd_func_block startCmdDef
struct cmd_func_block signCmdDef
struct cmd_func_block retransferCmdDef
struct cmd_func_block * signcommands[]
struct cmd_func_block flushCmdDef
int getlong(char *s, char **endptr, long *result)
struct cmd_func_block timeleapCmdDef
struct cmd_func_block clearCmdDef
struct cmd_func_block reloadCmdDef
struct cmd_func_block queueCmdDef
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
struct cmd_func_block helpCmdDef
struct cmd_func_block ** signercommands
struct cmd_func_block stopCmdDef
struct cmd_func_block runningCmdDef
struct cmd_func_block updateCmdDef
adapter_mode type
Definition adapter.h:58
zonelist_type * zonelist
Definition engine.h:69
schedule_type * taskq
Definition engine.h:54
pthread_mutex_t signal_lock
Definition engine.h:67
pthread_cond_t signal_cond
Definition engine.h:66
int need_to_reload
Definition engine.h:63
int need_to_exit
Definition engine.h:62
dnshandler_type * dnshandler
Definition engine.h:70
engineconfig_type * config
Definition engine.h:52
const char * zonelist_filename
Definition cfg.h:49
unsigned have_serial
Definition namedb.h:60
uint32_t intserial
Definition namedb.h:54
uint32_t inbserial
Definition namedb.h:53
uint32_t altserial
Definition namedb.h:56
unsigned force_serial
Definition namedb.h:59
uint32_t outserial
Definition namedb.h:55
uint8_t serial_retransfer
Definition xfrd.h:119
signconf_type * signconf
Definition zone.h:77
namedb_type * db
Definition zone.h:79
adapter_type * adinbound
Definition zone.h:74
ixfr_type * ixfr
Definition zone.h:80
zone_zl_status zl_status
Definition zone.h:72
xfrd_type * xfrd
Definition zone.h:82
const char * name
Definition zone.h:69
pthread_mutex_t zone_lock
Definition zone.h:86
pthread_mutex_t zl_lock
Definition zonelist.h:50
ldns_rbtree_t * zones
Definition zonelist.h:45
void xfrd_set_timer_now(xfrd_type *xfrd)
Definition xfrd.c:454
@ ZONE_ZL_ADDED
Definition zone.h:35
ods_status zonelist_update(zonelist_type *zl, const char *zlfile)
Definition zonelist.c:342
zone_type * zonelist_lookup_zone_by_name(zonelist_type *zonelist, const char *name, ldns_rr_class klass)
Definition zonelist.c:157