OpenDNSSEC-enforcer 2.1.10
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 "cmdhandler.h"
32#include "log.h"
33#include "str.h"
34#include "clientpipe.h"
36
38
39static const char *module_str = "zonelist_export_cmd";
40
41static void
42usage(int sockfd)
43{
44 client_printf(sockfd,
45 "zonelist export\n"
46 );
47}
48
49static void
50help(int sockfd)
51{
52 client_printf(sockfd,
53 "Export list of zones from the database to the zonelist.xml file.\n\n"
54 );
55}
56
57static int
58run(int sockfd, cmdhandler_ctx_type* context, const char *cmd)
59{
60 db_connection_t* dbconn = getconnectioncontext(context);
61 engine_type* engine = getglobalcontext(context);
62 (void)cmd;
63
64 if (!engine) {
65 return 1;
66 }
67 if (!engine->config) {
68 return 1;
69 }
70 if (!engine->config->zonelist_filename) {
71 return 1;
72 }
73 if (!dbconn) {
74 return 1;
75 }
76
77 ods_log_debug("[%s] %s command", module_str, zonelist_export_funcblock.cmdname);
78
79 if (zonelist_export(sockfd, dbconn, engine->config->zonelist_filename, 1) != ZONELIST_EXPORT_OK) {
80 ods_log_error("[%s] zonelist exported to %s failed", module_str, engine->config->zonelist_filename);
81 client_printf_err(sockfd, "Exported zonelist to %s failed!\n", engine->config->zonelist_filename);
82 return 1;
83 }
84
85 ods_log_info("[%s] zonelist exported to %s successfully", module_str, engine->config->zonelist_filename);
86 client_printf(sockfd, "Exported zonelist to %s successfully\n", engine->config->zonelist_filename);
87 return 0;
88}
89
90struct cmd_func_block zonelist_export_funcblock = {
91 "zonelist export", &usage, &help, NULL, &run
92};
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
engineconfig_type * config
Definition: engine.h:48
const char * zonelist_filename
Definition: cfg.h:57
int zonelist_export(int sockfd, db_connection_t *connection, const char *filename, int comment)
#define ZONELIST_EXPORT_OK
struct cmd_func_block zonelist_export_funcblock