OpenDNSSEC-enforcer  2.0.3
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 
30 #include "signconf/signconf.h"
31 #include "duration.h"
32 #include "log.h"
33 #include "file.h"
34 
35 #include "signconf/signconf_task.h"
36 
37 static const char *module_str = "signconf_cmd";
38 
39 int perform_signconf(int sockfd, const db_connection_t* dbconn, int force) {
40  int ret;
41  char cmd[SYSTEM_MAXLEN];
42 
43  ods_log_info("[%s] performing signconf for all zones", module_str);
44  ret = signconf_export_all(sockfd, dbconn, force);
45  if (ret == SIGNCONF_EXPORT_NO_CHANGE) {
46  ods_log_info("[%s] signconf done, no change", module_str);
47  return 0;
48  }
49  if (ret != SIGNCONF_EXPORT_OK) {
50  ods_log_error("[%s] signconf failed", module_str);
51  return 1;
52  }
53 
54  ods_log_info("[%s] signconf done, notifying signer", module_str);
55  /* TODO: do this better, connect directly or use execve() */
56  if (snprintf(cmd, sizeof(cmd), "%s --all", SIGNER_CLI_UPDATE) >= (int)sizeof(cmd)
57  || system(cmd))
58  {
59  ods_log_error("[%s] unable to notify signer of signconf changes!", module_str);
60  return 1;
61  }
62 
63  return 0;
64 }
65 
66 
67 static task_type* signconf_task_perform(task_type* task) {
68  perform_signconf(-1, task->dbconn, 0);
69  task_cleanup(task);
70  return NULL;
71 }
72 
73 task_type* signconf_task(const db_connection_t* dbconn, const char* what, const char* who) {
74  task_id what_id = task_register(what, "signconf_task_perform", signconf_task_perform);
75  return task_create(what_id, time_now(), who, what, (void*)dbconn, NULL);
76 }
#define SIGNCONF_EXPORT_OK
Definition: signconf.h:40
void ods_log_info(const char *format,...)
Definition: log.c:55
int perform_signconf(int sockfd, const db_connection_t *dbconn, int force)
Definition: signconf_task.c:39
void ods_log_error(const char *format,...)
Definition: log.c:69
enum task_id_enum task_id
Definition: task.h:53
void task_cleanup(task_type *task)
Definition: task.c:147
db_connection_t * dbconn
Definition: task.h:71
task_type * signconf_task(const db_connection_t *dbconn, const char *what, const char *who)
Definition: signconf_task.c:73
#define SIGNCONF_EXPORT_NO_CHANGE
Definition: signconf.h:64
int signconf_export_all(int sockfd, const db_connection_t *connection, int force)
Definition: signconf.c:56
task_id task_register(const char *short_name, const char *long_name, how_type how)
Definition: task.c:82
task_type * task_create(task_id what_id, time_t when, const char *who, const char *what, void *context, how_type clean_context)
Definition: task.c:110