32 #include "cmdhandler.h" 37 #include "clientpipe.h" 49 static const char *module_str =
"zone_add_cmd";
56 " --zone <zone> aka -z\n" 57 " [--policy <policy>] aka -p\n" 58 " [--signerconf <path>] aka -s\n" 59 " [--in-type <type>] aka -j\n" 62 " [--input <path>] aka -i\n" 63 " [--out-type <type>] aka -q\n" 64 " [--output <path>] aka -o\n" 73 "Add a new zone to the enforcer database.\n" 75 "zone name of the zone\n" 76 "policy name of the policy, if not set the default policy is used\n" 77 "signerconf specify a location for signer configuration file, default is /var/lib/opendnssec/signconf/\n" 78 "in-type specify the type of input, should be DNS or File, default is File \n" 79 "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" 80 "out-type specify the type of output, should be DNS or File, default is File\n" 81 "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" 82 "xml update the zonelist.xml file\n\n" 87 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
91 const char* argv[
NARGV];
93 const char *zone_name = NULL;
95 const char *signconf = NULL;
96 const char *input = NULL;
97 const char *output = NULL;
98 const char *input_type = NULL;
99 const char *output_type = NULL;
106 int long_index = 0, opt = 0;
110 static struct option long_options[] = {
111 {
"zone", required_argument, 0,
'z'},
112 {
"policy", required_argument, 0,
'p'},
113 {
"signerconf", required_argument, 0,
's'},
114 {
"input", required_argument, 0,
'i'},
115 {
"output", required_argument, 0,
'o'},
116 {
"in-type", required_argument, 0,
'j'},
117 {
"out-type", required_argument, 0,
'q'},
118 {
"xml", no_argument, 0,
'u'},
119 {
"suspend", no_argument, 0,
'n'},
125 if (!(buf = strdup(cmd))) {
126 client_printf_err(sockfd,
"memory error\n");
129 argc = ods_str_explode(buf,
NARGV, argv);
131 client_printf_err(sockfd,
"too many arguments\n");
132 ods_log_error(
"[%s] too many arguments for %s command",
139 while ((opt = getopt_long(argc, (
char*
const*)argv,
"z:p:s:i:o:j:q:un", long_options, &long_index)) != -1) {
145 policy_name = optarg;
160 output_type = optarg;
169 client_printf_err(sockfd,
"unknown arguments\n");
170 ods_log_error(
"[%s] unknown arguments for %s command",
178 client_printf_err(sockfd,
"expected option --zone <zone>\n");
184 client_printf_err(sockfd,
"Unable to add zone, zone already exists!\n");
191 client_printf_err(sockfd,
"Unable to find policy %s needed for adding the zone!\n", (policy_name ? policy_name :
"default"));
197 client_printf_err(sockfd,
"Unable to add zone, memory allocation problem!\n");
200 client_printf_err(sockfd,
"Unable to add zone, failed to set zone name!\n");
203 client_printf_err(sockfd,
"Unable to add zone, failed to set policy!\n");
206 if (!strcasecmp(input_type,
"DNS"))
208 else if (!strcasecmp(input_type,
"File"))
211 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);
215 client_printf_err(sockfd,
"Unable to add zone, failed to set input type!\n");
219 if (input[0] ==
'/') {
221 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
225 if (input_type && !strcasecmp(input_type,
"DNS")) {
226 if (snprintf(path,
sizeof(path),
"%s/%s", OPENDNSSEC_CONFIG_DIR, input) >= (
int)
sizeof(path)
229 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
233 if (snprintf(path,
sizeof(path),
"%s/unsigned/%s", OPENDNSSEC_STATE_DIR, input) >= (
int)
sizeof(path)
236 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
242 if (input_type && !strcasecmp(input_type,
"DNS")) {
243 if (snprintf(path,
sizeof(path),
"%s/addns.xml", OPENDNSSEC_CONFIG_DIR) >= (
int)
sizeof(path)
246 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
250 if (snprintf(path,
sizeof(path),
"%s/unsigned/%s", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
253 client_printf_err(sockfd,
"Unable to add zone, failed to set input!\n");
259 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);
260 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);
263 client_printf_err(sockfd,
"WARNING: Read access to input file %s for zone %s denied! \n ",
zone_db_input_adapter_uri(zone), zone_name);
264 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);
268 if (!strcasecmp(output_type,
"DNS"))
270 else if (!strcasecmp(output_type,
"File"))
271 output_type =
"File";
273 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);
277 client_printf_err(sockfd,
"Unable to add zone, failed to set output type!\n");
281 if (output[0] ==
'/') {
283 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
287 if (output_type && !strcasecmp(output_type,
"DNS")) {
288 if (snprintf(path,
sizeof(path),
"%s/%s", OPENDNSSEC_CONFIG_DIR, output) >= (
int)
sizeof(path)
291 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
295 if (snprintf(path,
sizeof(path),
"%s/signed/%s", OPENDNSSEC_STATE_DIR, output) >= (
int)
sizeof(path)
298 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
304 if(output_type && !strcasecmp(output_type,
"DNS")) {
305 if (snprintf(path,
sizeof(path),
"%s/addns.xml", OPENDNSSEC_CONFIG_DIR) >= (
int)
sizeof(path)
308 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
312 if (snprintf(path,
sizeof(path),
"%s/signed/%s", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
315 client_printf_err(sockfd,
"Unable to add zone, failed to set output!\n");
321 if (output_type && !strcasecmp(output_type,
"DNS")) {
323 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);
324 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);
327 client_printf_err(sockfd,
"WARNING: Read access to output file %s for zone %s denied! \n ",
zone_db_output_adapter_uri(zone), zone_name);
328 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);
333 if (signconf[0] ==
'/') {
335 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
339 if (snprintf(path,
sizeof(path),
"%s/signconf/%s", OPENDNSSEC_STATE_DIR, signconf) >= (
int)
sizeof(path)
342 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
347 if (snprintf(path,
sizeof(path),
"%s/signconf/%s.xml", OPENDNSSEC_STATE_DIR, zone_name) >= (
int)
sizeof(path)
350 client_printf_err(sockfd,
"Unable to add zone, failed to set signconf!\n");
355 ods_log_error(
"[%s] Cannot suspend zone %s, database error!", module_str, zone_name);
356 client_printf_err(sockfd,
"Cannot suspend zone %s, database error!\n", zone_name);
361 client_printf_err(sockfd,
"Unable to add zone, database error!\n");
367 ods_log_info(
"[%s] zone %s added [policy: %s]", module_str, zone_name, (policy_name ? policy_name :
"default"));
368 client_printf(sockfd,
"Zone %s added successfully\n", zone_name);
383 if (snprintf(path,
sizeof(path),
"%s/%s", engine->
config->
working_dir, OPENDNSSEC_ENFORCER_ZONELIST) >= (
int)
sizeof(path)
386 ods_log_error(
"[%s] internal zonelist update failed", module_str);
387 client_printf_err(sockfd,
"Unable to update the internal zonelist %s, updates will not reach the Signer!\n", path);
391 ods_log_info(
"[%s] internal zonelist updated successfully", module_str);
400 ods_log_debug(
"[%s] Flushing enforce task", module_str);
412 "zone add", &usage, &help, NULL, &run
zone_db_t * zone_db_new_get_by_name(const db_connection_t *connection, const char *name)
void zone_db_free(zone_db_t *zone)
task_type * enforce_task(engine_type *engine, char const *owner)
struct cmd_func_block zone_add_funcblock
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)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
int zone_db_set_policy_id(zone_db_t *zone, const db_value_t *policy_id)
int zone_db_set_signconf_path(zone_db_t *zone, const char *signconf_path_text)
int zone_db_set_input_adapter_uri(zone_db_t *zone, const char *input_adapter_uri_text)
db_connection_t * getconnectioncontext(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)
int zone_db_create(zone_db_t *zone)
engineconfig_type * config
void policy_free(policy_t *policy)
const char * zone_db_input_adapter_uri(const zone_db_t *zone)
int zone_db_set_output_adapter_uri(zone_db_t *zone, const char *output_adapter_uri_text)
int zone_db_set_input_adapter_type(zone_db_t *zone, const char *input_adapter_type_text)
int zone_db_set_name(zone_db_t *zone, const char *name_text)
int zone_db_set_next_change(zone_db_t *zone, int next_change)
int zonelist_update_add(int sockfd, const char *filename, const zone_db_t *zone, int comment)
const char * zone_db_output_adapter_uri(const zone_db_t *zone)
int zone_db_set_output_adapter_type(zone_db_t *zone, const char *output_adapter_type_text)
const db_value_t * policy_id(const policy_t *policy)
zone_db_t * zone_db_new(const db_connection_t *connection)