32#include "cmdhandler.h"
37#include "clientpipe.h"
38#include "longgetopt.h"
47static const char *module_str =
"zone_set_policy_cmd";
54 " --zone <zone> aka -z\n"
55 " --policy <policy> aka -p\n"
66 "Change the policy of an existing zone in the enforcer database.\n"
68 "zone name of the zone\n"
69 "policy name of the new policy\n"
70 "xml update the zonelist.xml file\n\n"
79 client_printf_err(sockfd,
"Unable to update zone, database error!\n");
83 client_printf_err(sockfd,
"Policy same as before, not updating.\n");
88 client_printf_err(sockfd,
"Unable to update zone, database error!\n");
93 client_printf(sockfd,
"Failed to update zone in database.\n");
102run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
104 int sockfd = context->sockfd;
105 struct longgetopt optctx;
106 const char *zone_name = NULL;
109 int long_index = 0, opt = 0;
115 static struct option long_options[] = {
116 {
"zone", required_argument, 0,
'z'},
117 {
"policy", required_argument, 0,
'p'},
118 {
"xml", no_argument, 0,
'u'},
122 for(opt = longgetopt(argc, argv,
"z:p:u", long_options, &long_index, &optctx); opt != -1;
123 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
126 zone_name = optctx.optarg;
135 client_printf_err(sockfd,
"unknown arguments\n");
136 ods_log_error(
"[%s] unknown arguments for zone set-policy command", module_str);
142 client_printf_err(sockfd,
"expected option --zone <zone>\n");
148 client_printf_err(sockfd,
"expected option --policy <policy>\n");
156 client_printf_err(sockfd,
"Unable to update zone, zone does not exist!\n");
164 client_printf_err(sockfd,
"Unable to update zone, policy does not exist!\n");
170 ret = set_zone_policy(sockfd, dbconn, zone,
policy);
186 if (snprintf(path,
sizeof(path),
"%s/%s", engine->
config->
working_dir, OPENDNSSEC_ENFORCER_ZONELIST) >= (
int)
sizeof(path)
189 ods_log_error(
"[%s] internal zonelist update failed", module_str);
190 client_printf_err(sockfd,
"Unable to update the internal zonelist %s, updates will not reach the Signer!\n", path);
193 ods_log_info(
"[%s] internal zonelist updated successfully", module_str);
200 "zone set-policy", &usage, &help, NULL, NULL, &run, NULL
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
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
void zone_db_free(zone_db_t *zone)
const db_value_t * zone_db_policy_id(const zone_db_t *zone)
int zone_db_set_policy_id(zone_db_t *zone, const db_value_t *policy_id)
const char * zone_db_name(const zone_db_t *zone)
int zone_db_update(zone_db_t *zone)
zone_db_t * zone_db_new_get_by_name(const db_connection_t *connection, const char *name)
struct cmd_func_block zone_set_policy_funcblock
int zonelist_export(int sockfd, db_connection_t *connection, const char *filename, int comment)
#define ZONELIST_EXPORT_OK