36 #include "clientpipe.h" 47 static const char *module_str =
"zone_add_cmd";
54 " --zone <zone> aka -z\n" 55 " [--policy <policy>] aka -p\n" 56 " [--signerconf <path>] aka -s\n" 57 " [--in-type <type>] aka -j\n" 60 " [--input <path>] aka -i\n" 61 " [--out-type <type>] aka -q\n" 62 " [--output <path>] aka -o\n" 64 " [--suspend] aka -n\n" 72 "Add a new zone to the enforcer database.\n" 74 "zone name of the zone\n" 75 "policy name of the policy, if not set the default policy is used\n" 76 "signerconf specify a location for signer configuration file, default is /var/opendnssec/signconf/\n" 77 "in-type specify the type of input, should be DNS or File, default is File \n" 78 "input specify a location for the unsigned zone, this location is set in conf.xml, default for File Adapter is /var/opendnssec/unsigned/ and for DNS Adapter is /etc/opendnssec/addns.xml \n" 79 "out-type specify the type of output, should be DNS or File, default is File\n" 80 "output specify a location for the signed zone, this location is set in conf.xml, default path for File Adapter is /var/opendnssec/signed/ and for DNS Adapter is /etc/opendnssec/addns.xml \n" 81 "xml update the zonelist.xml file\n" 82 "suspend suspend this zone until running enforce command\n\n" 87 handles(
const char *cmd, ssize_t n)
101 const char *signconf = NULL;
102 const char *input = NULL;
103 const char *output = NULL;
104 const char *input_type = NULL;
105 const char *output_type = NULL;
117 if (!(buf = strdup(cmd))) {
118 client_printf_err(sockfd,
"memory error\n");
122 argc = ods_str_explode(buf, 18, argv);
124 client_printf_err(sockfd,
"too many arguments\n");
129 ods_find_arg_and_param(&argc, argv,
"zone",
"z", &zone_name);
130 ods_find_arg_and_param(&argc, argv,
"policy",
"p", &policy_name);
131 ods_find_arg_and_param(&argc, argv,
"signerconf",
"s", &signconf);
132 ods_find_arg_and_param(&argc, argv,
"input",
"i", &input);
133 ods_find_arg_and_param(&argc, argv,
"output",
"o", &output);
134 ods_find_arg_and_param(&argc, argv,
"in-type",
"j", &input_type);
135 ods_find_arg_and_param(&argc, argv,
"out-type",
"q", &output_type);
136 write_xml = ods_find_arg(&argc, argv,
"xml",
"u") > -1 ? 1 : 0;
137 suspend = ods_find_arg(&argc, argv,
"suspend",
"n") > -1 ? 1 : 0;
140 client_printf_err(sockfd,
"unknown arguments\n");
145 client_printf_err(sockfd,
"expected option --zone <zone>\n");
151 client_printf_err(sockfd,
"Unable to add zone, zone already exists!\n");
158 client_printf_err(sockfd,
"Unable to find policy %s needed for adding the zone!\n", (policy_name ? policy_name :
"default"));
164 client_printf_err(sockfd,
"Unable to add zone, memory allocation problem!\n");
167 client_printf_err(sockfd,
"Unable to add zone, failed to set zone name!\n");
170 client_printf_err(sockfd,
"Unable to add zone, failed to set policy!\n");
173 if (!strcasecmp(input_type,
"DNS"))
175 else if (!strcasecmp(input_type,
"File"))
178 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);
182 client_printf_err(sockfd,
"Unable to add zone, failed to set input type!\n");
186 if (input[0] ==
'/') {
188 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
192 if (input_type && !strcasecmp(input_type,
"DNS")) {
193 if (snprintf(path,
sizeof(path),
"%s/%s", OPENDNSSEC_CONFIG_DIR, input) >= (
int)
sizeof(path)
196 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
200 if (snprintf(path,
sizeof(path),
"%s/unsigned/%s", OPENDNSSEC_STATE_DIR, input) >= (
int)
sizeof(path)
203 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
209 if (input_type && !strcasecmp(input_type,
"DNS")) {
210 if (snprintf(path,
sizeof(path),
"%s/addns.xml", OPENDNSSEC_CONFIG_DIR) >= (
int)
sizeof(path)
213 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
217 if (snprintf(path,
sizeof(path),
"%s/unsigned/%s", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
220 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
226 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_input_adapter_uri(zone), zone_name);
227 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_input_adapter_uri(zone), zone_name);
230 client_printf_err(sockfd,
"WARNING: Read access to input file %s for zone %s denied! \n ",
zone_input_adapter_uri(zone), zone_name);
235 if (!strcasecmp(output_type,
"DNS"))
237 else if (!strcasecmp(output_type,
"File"))
238 output_type =
"File";
240 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);
244 client_printf_err(sockfd,
"Unable to add zone, failed to set output type!\n");
248 if (output[0] ==
'/') {
250 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
254 if (output_type && !strcasecmp(output_type,
"DNS")) {
255 if (snprintf(path,
sizeof(path),
"%s/%s", OPENDNSSEC_CONFIG_DIR, output) >= (
int)
sizeof(path)
258 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
262 if (snprintf(path,
sizeof(path),
"%s/signed/%s", OPENDNSSEC_STATE_DIR, output) >= (
int)
sizeof(path)
265 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
271 if(output_type && !strcasecmp(output_type,
"DNS")) {
272 if (snprintf(path,
sizeof(path),
"%s/addns.xml", OPENDNSSEC_CONFIG_DIR) >= (
int)
sizeof(path)
275 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
279 if (snprintf(path,
sizeof(path),
"%s/signed/%s", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
282 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
288 if (output_type && !strcasecmp(output_type,
"DNS")) {
290 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_output_adapter_uri(zone), zone_name);
291 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_output_adapter_uri(zone), zone_name);
294 client_printf_err(sockfd,
"WARNING: Read access to output file %s for zone %s denied! \n ",
zone_output_adapter_uri(zone), zone_name);
300 if (signconf[0] ==
'/') {
302 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
306 if (snprintf(path,
sizeof(path),
"%s/signconf/%s", OPENDNSSEC_STATE_DIR, signconf) >= (
int)
sizeof(path)
309 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
314 char signedfile[257] =
"";
315 strncat (strncat (signedfile, zone_name, strlen (zone_name)),
".xml", 4);
316 if (snprintf(path,
sizeof(path),
"%s/signconf/%s", OPENDNSSEC_STATE_DIR, signedfile) >= (
int)
sizeof(path)
319 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
324 ods_log_error(
"[%s] Cannot suspend zone %s, database error!", module_str, zone_name);
325 client_printf_err(sockfd,
"Cannot suspend zone %s, database error!\n", zone_name);
330 client_printf_err(sockfd,
"Unable to add zone, database error!\n");
336 ods_log_info(
"[%s] zone %s added [policy: %s]", module_str, zone_name, (policy_name ? policy_name :
"default"));
337 client_printf(sockfd,
"Zone %s added successfully\n", zone_name);
352 if (snprintf(path,
sizeof(path),
"%s/%s", engine->
config->
working_dir, OPENDNSSEC_ENFORCER_ZONELIST) >= (
int)
sizeof(path)
355 ods_log_error(
"[%s] internal zonelist update failed", module_str);
356 client_printf_err(sockfd,
"Unable to update the internal zonelist %s, updates will not reach the Signer!\n", path);
360 ods_log_info(
"[%s] internal zonelist updated successfully", module_str);
const char * zone_output_adapter_uri(const zone_t *zone)
void ods_log_debug(const char *format,...)
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)
#define ZONELIST_UPDATE_OK
const char * zonelist_filename
const char * policy_name(const policy_t *policy)
int zone_set_signconf_path(zone_t *zone, const char *signconf_path_text)
void hsm_key_factory_generate_policy(engine_type *engine, const db_connection_t *connection, const policy_t *policy, time_t duration)
void ods_log_info(const char *format,...)
int zone_set_output_adapter_uri(zone_t *zone, const char *output_adapter_uri_text)
int zone_set_policy_id(zone_t *zone, const db_value_t *policy_id)
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
int zone_set_input_adapter_uri(zone_t *zone, const char *input_adapter_uri_text)
void ods_log_error(const char *format,...)
int zonelist_update_add(int sockfd, const char *filename, const zone_t *zone, int comment)
void zone_free(zone_t *zone)
void(* usage)(int sockfd)
engineconfig_type * config
void policy_free(policy_t *policy)
zone_t * zone_new(const db_connection_t *connection)
int zone_set_name(zone_t *zone, const char *name_text)
int zone_set_next_change(zone_t *zone, int next_change)
struct cmd_func_block * zone_add_funcblock(void)
zone_t * zone_new_get_by_name(const db_connection_t *connection, const char *name)
const char * zone_name(const zone_t *zone)
int zone_set_output_adapter_type(zone_t *zone, const char *output_adapter_type_text)
int(* handles)(const char *cmd, ssize_t n)
const char * zone_input_adapter_uri(const zone_t *zone)
const db_value_t * policy_id(const policy_t *policy)
int zone_create(zone_t *zone)
void ods_log_warning(const char *format,...)
int flush_enforce_task(engine_type *engine, bool enforce_all)
int zone_set_input_adapter_type(zone_t *zone, const char *input_adapter_type_text)