32 #include "cmdhandler.h"
37 #include "clientpipe.h"
46 static const char *module_str =
"zone_set_policy_cmd";
53 " --zone <zone> aka -z\n"
54 " --policy <policy> aka -p\n"
65 "Change the policy of an existing zone in the enforcer database.\n"
67 "zone name of the zone\n"
68 "policy name of the new policy\n"
69 "xml update the zonelist.xml file\n\n"
78 client_printf_err(sockfd,
"Unable to update zone, database error!\n");
82 client_printf_err(sockfd,
"Policy same as before, not updating.\n");
87 client_printf_err(sockfd,
"Unable to update zone, database error!\n");
92 client_printf(sockfd,
"Failed to update zone in database.\n");
101 run(
int sockfd, cmdhandler_ctx_type* context,
char *cmd)
104 const char* argv[
NARGV];
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'},
124 argc = ods_str_explode(cmd,
NARGV, argv);
126 client_printf_err(sockfd,
"too many arguments\n");
127 ods_log_error(
"[%s] too many arguments for %s command",
133 while ((opt = getopt_long(argc, (
char*
const*)argv,
"z:p:u", long_options, &long_index)) != -1) {
145 client_printf_err(sockfd,
"unknown arguments\n");
146 ods_log_error(
"[%s] unknown arguments for %s command",
153 client_printf_err(sockfd,
"expected option --zone <zone>\n");
159 client_printf_err(sockfd,
"expected option --policy <policy>\n");
167 free((
void*)zone_name);
169 client_printf_err(sockfd,
"Unable to update zone, zone does not exist!\n");
177 client_printf_err(sockfd,
"Unable to update zone, policy does not exist!\n");
183 ret = set_zone_policy(sockfd, dbconn, zone,
policy);
199 if (snprintf(path,
sizeof(path),
"%s/%s", engine->
config->
working_dir, OPENDNSSEC_ENFORCER_ZONELIST) >= (
int)
sizeof(path)
202 ods_log_error(
"[%s] internal zonelist update failed", module_str);
203 client_printf_err(sockfd,
"Unable to update the internal zonelist %s, updates will not reach the Signer!\n", path);
206 ods_log_info(
"[%s] internal zonelist updated successfully", module_str);
213 "zone set-policy", &usage, &help, NULL, &run
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)
const char * policy_name(const policy_t *policy)
const db_value_t * policy_id(const policy_t *policy)
void policy_free(policy_t *policy)
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)
engineconfig_type * config
const char * zonelist_filename
void zone_db_free(zone_db_t *zone)
const char * zone_db_name(const zone_db_t *zone)
int zone_db_set_policy_id(zone_db_t *zone, const db_value_t *policy_id)
int zone_db_update(zone_db_t *zone)
const db_value_t * zone_db_policy_id(const 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