32#include "cmdhandler.h"
37#include "clientpipe.h"
38#include "longgetopt.h"
50static const char *module_str =
"zone_add_cmd";
57 " --zone <zone> aka -z\n"
58 " [--policy <policy>] aka -p\n"
59 " [--signerconf <path>] aka -s\n"
60 " [--in-type <type>] aka -j\n"
63 " [--input <path>] aka -i\n"
64 " [--out-type <type>] aka -q\n"
65 " [--output <path>] aka -o\n"
74 "Add a new zone to the enforcer database.\n"
76 "zone name of the zone\n"
77 "policy name of the policy, if not set the default policy is used\n"
78 "signerconf specify a location for signer configuration file, default is /var/lib/opendnssec/signconf/\n"
79 "in-type specify the type of input, should be DNS or File, default is File \n"
80 "input specify a location for the unsigned zone, this location is set in conf.xml, default for File Adapter is /var/lib/opendnssec/unsigned/ and for DNS Adapter is /etc/opendnssec/addns.xml \n"
81 "out-type specify the type of output, should be DNS or File, default is File\n"
82 "output specify a location for the signed zone, this location is set in conf.xml, default path for File Adapter is /var/lib/opendnssec/signed/ and for DNS Adapter is /etc/opendnssec/addns.xml \n"
83 "xml update the zonelist.xml file\n\n"
88run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
90 int sockfd = context->sockfd;
91 struct longgetopt optctx;
92 const char *zone_name = NULL;
94 const char *signconf = NULL;
95 const char *input = NULL;
96 const char *output = NULL;
97 const char *input_type = NULL;
98 const char *output_type = NULL;
105 int long_index = 0, opt = 0;
109 static struct option long_options[] = {
110 {
"zone", required_argument, 0,
'z'},
111 {
"policy", required_argument, 0,
'p'},
112 {
"signerconf", required_argument, 0,
's'},
113 {
"input", required_argument, 0,
'i'},
114 {
"output", required_argument, 0,
'o'},
115 {
"in-type", required_argument, 0,
'j'},
116 {
"out-type", required_argument, 0,
'q'},
117 {
"xml", no_argument, 0,
'u'},
118 {
"suspend", no_argument, 0,
'n'},
122 for(opt = longgetopt(argc, argv,
"z:p:s:i:o:j:q:un", long_options, &long_index, &optctx); opt != -1;
123 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
126 zone_name = optctx.optarg;
132 signconf = optctx.optarg;
135 input = optctx.optarg;
138 output = optctx.optarg;
141 input_type = optctx.optarg;
144 output_type = optctx.optarg;
153 client_printf_err(sockfd,
"unknown arguments\n");
154 ods_log_error(
"[%s] unknown arguments for zone add command", module_str);
160 client_printf_err(sockfd,
"expected option --zone <zone>\n");
165 client_printf_err(sockfd,
"Unable to add zone, zone already exists!\n");
171 client_printf_err(sockfd,
"Unable to find policy %s needed for adding the zone!\n", (
policy_name ?
policy_name :
"default"));
176 client_printf_err(sockfd,
"Unable to add zone, memory allocation problem!\n");
179 client_printf_err(sockfd,
"Unable to add zone, failed to set zone name!\n");
182 client_printf_err(sockfd,
"Unable to add zone, failed to set policy!\n");
185 if (!strcasecmp(input_type,
"DNS"))
187 else if (!strcasecmp(input_type,
"File"))
190 client_printf_err(sockfd,
"Unable to add zone, %s is not a valid input type! in_type must be File or DNS.\n", input_type);
194 client_printf_err(sockfd,
"Unable to add zone, failed to set input type!\n");
198 if (input[0] ==
'/') {
200 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
204 if (input_type && !strcasecmp(input_type,
"DNS")) {
205 if (snprintf(path,
sizeof(path),
"%s/%s", OPENDNSSEC_CONFIG_DIR, input) >= (
int)
sizeof(path)
208 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
212 if (snprintf(path,
sizeof(path),
"%s/unsigned/%s", OPENDNSSEC_STATE_DIR, input) >= (
int)
sizeof(path)
215 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
221 if (input_type && !strcasecmp(input_type,
"DNS")) {
222 if (snprintf(path,
sizeof(path),
"%s/addns.xml", OPENDNSSEC_CONFIG_DIR) >= (
int)
sizeof(path)
225 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
229 if (snprintf(path,
sizeof(path),
"%s/unsigned/%s", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
232 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
238 client_printf_err(sockfd,
"WARNING: The input file %s for zone %s does not currently exist. The zone will be added to the database anyway. \n",
zone_db_input_adapter_uri(zone), zone_name);
239 ods_log_warning(
"[%s] WARNING: The input file %s for zone %s does not currently exist. The zone will be added to the database anyway.", module_str,
zone_db_input_adapter_uri(zone), zone_name);
242 client_printf_err(sockfd,
"WARNING: Read access to input file %s for zone %s denied! \n ",
zone_db_input_adapter_uri(zone), zone_name);
243 ods_log_warning(
"[%s] WARNING: Read access to input file %s for zone %s denied! ", module_str,
zone_db_input_adapter_uri(zone), zone_name);
247 if (!strcasecmp(output_type,
"DNS"))
249 else if (!strcasecmp(output_type,
"File"))
250 output_type =
"File";
252 client_printf_err(sockfd,
"Unable to add zone, %s is not a valid output type! out_type must be File or DNS.\n", output_type);
256 client_printf_err(sockfd,
"Unable to add zone, failed to set output type!\n");
260 if (output[0] ==
'/') {
262 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
266 if (output_type && !strcasecmp(output_type,
"DNS")) {
267 if (snprintf(path,
sizeof(path),
"%s/%s", OPENDNSSEC_CONFIG_DIR, output) >= (
int)
sizeof(path)
270 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
274 if (snprintf(path,
sizeof(path),
"%s/signed/%s", OPENDNSSEC_STATE_DIR, output) >= (
int)
sizeof(path)
277 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
283 if(output_type && !strcasecmp(output_type,
"DNS")) {
284 if (snprintf(path,
sizeof(path),
"%s/addns.xml", OPENDNSSEC_CONFIG_DIR) >= (
int)
sizeof(path)
287 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
291 if (snprintf(path,
sizeof(path),
"%s/signed/%s", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
294 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
300 if (output_type && !strcasecmp(output_type,
"DNS")) {
302 client_printf_err(sockfd,
"WARNING: The output file %s for zone %s does not currently exist. The zone will be added to the database anyway. \n",
zone_db_output_adapter_uri(zone), zone_name);
303 ods_log_warning(
"[%s] WARNING: The output file %s for zone %s does not currently exist. The zone will be added to the database anyway.", module_str,
zone_db_output_adapter_uri(zone), zone_name);
306 client_printf_err(sockfd,
"WARNING: Read access to output file %s for zone %s denied! \n ",
zone_db_output_adapter_uri(zone), zone_name);
307 ods_log_warning(
"[%s] WARNING: Read access to output file %s for zone %s denied! ", module_str,
zone_db_output_adapter_uri(zone), zone_name);
312 if (signconf[0] ==
'/') {
314 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
318 if (snprintf(path,
sizeof(path),
"%s/signconf/%s", OPENDNSSEC_STATE_DIR, signconf) >= (
int)
sizeof(path)
321 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
326 if (snprintf(path,
sizeof(path),
"%s/signconf/%s.xml", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
329 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
334 ods_log_error(
"[%s] Cannot suspend zone %s, database error!", module_str, zone_name);
335 client_printf_err(sockfd,
"Cannot suspend zone %s, database error!\n", zone_name);
340 client_printf_err(sockfd,
"Unable to add zone, database error!\n");
345 ods_log_info(
"[%s] zone %s added [policy: %s]", module_str, zone_name, (
policy_name ?
policy_name :
"default"));
346 client_printf(sockfd,
"Zone %s added successfully\n", zone_name);
360 if (snprintf(path,
sizeof(path),
"%s/%s", engine->
config->
working_dir, OPENDNSSEC_ENFORCER_ZONELIST) >= (
int)
sizeof(path)
363 ods_log_error(
"[%s] internal zonelist update failed", module_str);
364 client_printf_err(sockfd,
"Unable to update the internal zonelist %s, updates will not reach the Signer!\n", path);
368 ods_log_info(
"[%s] internal zonelist updated successfully", module_str);
377 ods_log_debug(
"[%s] Flushing enforce task", module_str);
389 "zone add", &usage, &help, NULL, NULL, &run, NULL
task_type * enforce_task(engine_type *engine, char const *owner)
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
int hsm_key_factory_generate_policy(engine_type *engine, const db_connection_t *connection, const policy_t *policy, time_t duration)
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)
const char * policy_name(const policy_t *policy)
const db_value_t * policy_id(const policy_t *policy)
void policy_free(policy_t *policy)
engineconfig_type * config
const char * zonelist_filename
struct cmd_func_block zone_add_funcblock
int zone_db_set_input_adapter_type(zone_db_t *zone, const char *input_adapter_type_text)
void zone_db_free(zone_db_t *zone)
int zone_db_set_output_adapter_type(zone_db_t *zone, const char *output_adapter_type_text)
int zone_db_set_policy_id(zone_db_t *zone, const db_value_t *policy_id)
int zone_db_create(zone_db_t *zone)
const char * zone_db_input_adapter_uri(const zone_db_t *zone)
int zone_db_set_signconf_path(zone_db_t *zone, const char *signconf_path_text)
zone_db_t * zone_db_new(const db_connection_t *connection)
int zone_db_set_output_adapter_uri(zone_db_t *zone, const char *output_adapter_uri_text)
int zone_db_set_name(zone_db_t *zone, const char *name_text)
const char * zone_db_output_adapter_uri(const zone_db_t *zone)
zone_db_t * zone_db_new_get_by_name(const db_connection_t *connection, const char *name)
int zone_db_set_next_change(zone_db_t *zone, int next_change)
int zone_db_set_input_adapter_uri(zone_db_t *zone, const char *input_adapter_uri_text)
int zonelist_update_add(int sockfd, const char *filename, const zone_db_t *zone, int comment)
#define ZONELIST_UPDATE_OK