OpenDNSSEC-enforcer  2.0.3
zonelist_export_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
3  * Copyright (c) 2014 OpenDNSSEC AB (svb)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #include "daemon/engine.h"
30 #include "daemon/cmdhandler.h"
31 #include "log.h"
32 #include "str.h"
33 #include "clientpipe.h"
35 
37 
38 static const char *module_str = "zonelist_export_cmd";
39 
40 static void
41 usage(int sockfd)
42 {
43  client_printf(sockfd,
44  "zonelist export\n"
45  );
46 }
47 
48 static void
49 help(int sockfd)
50 {
51  client_printf(sockfd,
52  "Export list of zones from the database to the zonelist.xml file.\n\n"
53  );
54 }
55 
56 static int
57 handles(const char *cmd, ssize_t n)
58 {
59  return ods_check_command(cmd, n, zonelist_export_funcblock()->cmdname) ? 1 : 0;
60 }
61 
62 static int
63 run(int sockfd, engine_type* engine, const char *cmd, ssize_t n,
64  db_connection_t *dbconn)
65 {
66  (void)cmd; (void)n;
67 
68  if (!engine) {
69  return 1;
70  }
71  if (!engine->config) {
72  return 1;
73  }
74  if (!engine->config->zonelist_filename) {
75  return 1;
76  }
77  if (!dbconn) {
78  return 1;
79  }
80 
81  ods_log_debug("[%s] %s command", module_str, zonelist_export_funcblock()->cmdname);
82 
83  if (zonelist_export(sockfd, dbconn, engine->config->zonelist_filename, 1) != ZONELIST_EXPORT_OK) {
84  ods_log_error("[%s] zonelist exported to %s failed", module_str, engine->config->zonelist_filename);
85  client_printf_err(sockfd, "Exported zonelist to %s failed!\n", engine->config->zonelist_filename);
86  return 1;
87  }
88 
89  ods_log_info("[%s] zonelist exported to %s successfully", module_str, engine->config->zonelist_filename);
90  client_printf(sockfd, "Exported zonelist to %s successfully\n", engine->config->zonelist_filename);
91  /*
92  flush_enforce_task(engine, 1);
93  */
94  return 0;
95 }
96 
97 static struct cmd_func_block funcblock = {
98  "zonelist export", &usage, &help, &handles, &run
99 };
100 
101 struct cmd_func_block*
103 {
104  return &funcblock;
105 }
void(* help)(int sockfd)
Definition: cmdhandler.h:64
void ods_log_debug(const char *format,...)
Definition: log.c:41
struct cmd_func_block * zonelist_export_funcblock(void)
const char * zonelist_filename
Definition: cfg.h:57
void ods_log_info(const char *format,...)
Definition: log.c:55
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
Definition: cmdhandler.h:79
const char * cmdname
Definition: cmdhandler.h:59
void ods_log_error(const char *format,...)
Definition: log.c:69
void(* usage)(int sockfd)
Definition: cmdhandler.h:61
#define ZONELIST_EXPORT_OK
engineconfig_type * config
Definition: engine.h:53
int zonelist_export(int sockfd, db_connection_t *connection, const char *filename, int comment)
int(* handles)(const char *cmd, ssize_t n)
Definition: cmdhandler.h:67