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