OpenDNSSEC-enforcer 2.1.13
signconf_task.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
31#include "duration.h"
32#include "log.h"
33#include "file.h"
34
36
37static const char *module_str = "signconf_cmd";
38
39static time_t
40perform(task_type* task, char const *zonename, void *userdata, void *context)
41{
42 (void)userdata;
43 int ret;
44 char cmd[SYSTEM_MAXLEN];
45 db_connection_t* dbconn = (db_connection_t*) context;
46
47 ods_log_info("[%s] performing signconf for zone %s", module_str,
48 zonename);
49
50 /* exports all that have "needswriting set */
51 ret = signconf_export_zone(zonename, dbconn);
52 if (ret == SIGNCONF_EXPORT_NO_CHANGE) {
53 ods_log_info("[%s] signconf done, no change", module_str);
54 return schedule_SUCCESS;
55 }
56 if (ret != SIGNCONF_EXPORT_OK) {
57 ods_log_error("[%s] signconf failed", module_str);
58 /* YBS reschedule backoff? */
59 return schedule_SUCCESS;
60 }
61
62 ods_log_info("[%s] signconf done for zone %s, notifying signer",
63 module_str, zonename);
64
65 /* TODO: do this better, connect directly or use execve() */
66 if (snprintf(cmd, sizeof(cmd), "%s %s", SIGNER_CLI_UPDATE, zonename) >= (int)sizeof(cmd)
67 || system(cmd))
68 {
69 ods_log_error("[%s] unable to notify signer of signconf changes for zone %s!",
70 module_str, zonename);
71 }
72 return schedule_SUCCESS;
73}
74
75void
77 const char* zonename)
78{
79 task_type* task = task_create(strdup(zonename), TASK_CLASS_ENFORCER,
80 TASK_TYPE_SIGNCONF, perform, NULL, NULL, time_now());
81 (void) schedule_task(engine->taskq, task, 1, 0);
82}
83
84void
86 policy_t const *policy)
87{
88 zone_db_t const *zone;
89 zone_list_db_t *zonelist;
90
91 ods_log_assert(policy);
92
94 if (!zonelist) {
95 ods_log_error("[%s] Can't fetch zones for policy %s from database",
96 module_str, policy_name(policy));
97 return;
98 }
99 while ((zone = zone_list_db_next(zonelist))) {
100 signconf_task_flush_zone(engine, dbconn, zone_db_name(zone));
101 }
102 zone_list_db_free(zonelist);
103}
104
105void
107{
108 zone_list_db_t *zonelist;
109 zone_db_t const *zone;
110
111 zonelist = zone_list_db_new(dbconn);
112 if (!zonelist) {
113 ods_log_error("[%s] Can't fetch zones from database", module_str);
114 return;
115 }
116 if (zone_list_db_get(zonelist)) { /* fetch all */
117 ods_log_error("[%s] Can't fetch zones from database", module_str);
118 zone_list_db_free(zonelist);
119 return;
120 }
121 while ((zone = zone_list_db_next(zonelist))) {
122 signconf_task_flush_zone(engine, dbconn, zone_db_name(zone));
123 }
124 zone_list_db_free(zonelist);
125}
const char * policy_name(const policy_t *policy)
Definition policy.c:813
const db_value_t * policy_id(const policy_t *policy)
Definition policy.c:805
void signconf_task_flush_policy(engine_type *engine, db_connection_t *dbconn, policy_t const *policy)
void signconf_task_flush_zone(engine_type *engine, db_connection_t *dbconn, const char *zonename)
void signconf_task_flush_all(engine_type *engine, db_connection_t *dbconn)
int signconf_export_zone(char const *zonename, db_connection_t *dbconn)
#define SIGNCONF_EXPORT_NO_CHANGE
#define SIGNCONF_EXPORT_OK
schedule_type * taskq
Definition engine.h:60
const char * zone_db_name(const zone_db_t *zone)
Definition zone_db.c:782
zone_list_db_t * zone_list_db_new_get_by_policy_id(const db_connection_t *connection, const db_value_t *policy_id)
Definition zone_db.c:2524
zone_list_db_t * zone_list_db_new(const db_connection_t *connection)
Definition zone_db.c:1946
int zone_list_db_get(zone_list_db_t *zone_list)
Definition zone_db.c:2363
const zone_db_t * zone_list_db_next(zone_list_db_t *zone_list)
Definition zone_db.c:2603
void zone_list_db_free(zone_list_db_t *zone_list)
Definition zone_db.c:1989