OpenDNSSEC-enforcer  2.0.2
enforce_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Surfnet
3  * Copyright (c) 2011 .SE (The Internet Infrastructure Foundation).
4  * Copyright (c) 2011 OpenDNSSEC AB (svb)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #include "config.h"
31 
32 #include "daemon/cmdhandler.h"
33 #include "daemon/engine.h"
34 #include "enforcer/enforce_task.h"
35 #include "file.h"
36 #include "log.h"
37 #include "str.h"
38 #include "clientpipe.h"
39 
40 #include "enforcer/enforce_cmd.h"
41 
42 static const char *module_str = "enforce_cmd";
43 
48 static void
49 usage(int sockfd)
50 {
51  client_printf(sockfd,
52  "enforce\n"
53  );
54 }
55 
56 static void
57 help(int sockfd)
58 {
59  client_printf(sockfd,
60  "Force the enforcer to run once for every zone.\n\n"
61  );
62 }
63 
64 static int
65 handles(const char *cmd, ssize_t n)
66 {
67  return ods_check_command(cmd, n, enforce_funcblock()->cmdname)?1:0;
68 }
69 
70 static void
71 reschedule_enforce(task_type *task, time_t t_when, const char *z_when)
72 {
73  ods_log_assert(task->who);
74  task->who = strdup(z_when);
75  task->when = t_when;
76  task->backoff = 0;
77 }
78 
83 static int
84 run(int sockfd, engine_type* engine, const char *cmd, ssize_t n,
85  db_connection_t *dbconn)
86 {
87  time_t t_next;
88  task_type *task;
89  (void)cmd; (void)n;
90  ods_log_debug("[%s] %s command", module_str, enforce_funcblock()->cmdname);
91 
92  task = enforce_task(engine, 1);
93 
94  t_next = perform_enforce_lock(sockfd, engine, 1, task, dbconn);
95  if (t_next == -1) {
96  task_cleanup(task);
97  } else {
98  reschedule_enforce(task, t_next, "next zone");
99  schedule_task(engine->taskq, task); /* TODO unchecked error */
100  }
101  return 0;
102 }
103 
104 static struct cmd_func_block funcblock = {
105  "enforce", &usage, &help, &handles, &run
106 };
107 
108 struct cmd_func_block*
110 {
111  return &funcblock;
112 }
void(* help)(int sockfd)
Definition: cmdhandler.h:64
void ods_log_debug(const char *format,...)
Definition: log.c:41
time_t when
Definition: task.h:63
char * who
Definition: task.h:66
time_t perform_enforce_lock(int sockfd, engine_type *engine, int bForceUpdate, task_type *task, db_connection_t *dbconn)
Definition: enforce_task.c:262
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
Definition: cmdhandler.h:79
time_t backoff
Definition: task.h:64
ods_status schedule_task(schedule_type *schedule, task_type *task)
Definition: schedule.c:401
struct cmd_func_block * enforce_funcblock(void)
Definition: enforce_cmd.c:109
void(* usage)(int sockfd)
Definition: cmdhandler.h:61
task_type * enforce_task(engine_type *engine, bool all)
Definition: enforce_task.c:305
void task_cleanup(task_type *task)
Definition: task.c:147
schedule_type * taskq
Definition: engine.h:55
int(* handles)(const char *cmd, ssize_t n)
Definition: cmdhandler.h:67