policy_ext.c
Go to the documentation of this file.
/*
* Copyright (c) 2014 Jerry Lundström <lundstrom.jerry@gmail.com>
* Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
* Copyright (c) 2014 OpenDNSSEC AB (svb)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "policy.h"
#include "db_error.h"
#include "duration.h"
#include "log.h"
#include <string.h>
static int __xmlNode2policy(policy_t* policy, xmlNodePtr policy_node, int* updated) {
xmlNodePtr node;
xmlNodePtr node2;
xmlNodePtr node3;
xmlNodePtr node4;
xmlChar* xml_text = NULL;
duration_type* duration = NULL;
int check_if_updated = 0;
int update_this = 1;
int denial_optout = 0;
int keys_shared = 0;
int signatures_max_zone_ttl = 0;
int keys_purge = 0;
int denial_ttl = 0;
unsigned int passthrough = 0;
if (!policy) {
return DB_ERROR_UNKNOWN;
}
if (!policy_node) {
return DB_ERROR_UNKNOWN;
}
/*
* If updated is set we will check if the content is changed and set the
* integer pointed by updated to non-zero.
*/
if (updated) {
*updated = 0;
check_if_updated = 1;
}
if (!(xml_text = xmlGetProp(policy_node, (xmlChar*)"name"))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] policy %s", (char*)xml_text);
if (check_if_updated) {
update_this = 0;
if (!policy_name(policy)) {
*updated = 1;
update_this = 1;
}
else if (strcmp(policy_name(policy), (char*)xml_text)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_name(policy, (char*)xml_text)) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
for (node = policy_node->children; node; node = node->next) {
if (node->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node->name, "Description")) {
if (!(xml_text = xmlNodeGetContent(node))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] description %s", (char*)xml_text);
if (check_if_updated) {
update_this = 0;
if (!policy_description(policy)) {
*updated = 1;
update_this = 1;
}
else if (strcmp(policy_description(policy), (char*)xml_text)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_description(policy, (char*)xml_text)) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
}
else if (!strcmp((char*)node->name, "Passthrough")) {
passthrough = 1;
}
else if (!strcmp((char*)node->name, "Signatures")) {
for (node2 = node->children; node2; node2 = node2->next) {
if (node2->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node2->name, "Resign")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature resign %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_resign(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_resign(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "Refresh")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature refresh %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_refresh(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_refresh(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "Validity")) {
for (node3 = node2->children; node3; node3 = node3->next) {
if (node3->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node3->name, "Default")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature validity default %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_validity_default(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_validity_default(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "Denial")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature validity denial %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_validity_denial(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_validity_denial(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "Keyset")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature validity keyset %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_validity_keyset(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_validity_keyset(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node3->name);
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node2->name, "Jitter")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature jitter %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_jitter(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_jitter(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "InceptionOffset")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature inception offset %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_inception_offset(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_inception_offset(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "MaxZoneTTL")) {
signatures_max_zone_ttl = 1;
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] signature max zone ttl %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_signatures_max_zone_ttl(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_signatures_max_zone_ttl(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node2->name);
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node->name, "Denial")) {
for (node2 = node->children; node2; node2 = node2->next) {
if (node2->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node2->name, "NSEC")) {
ods_log_deeebug("[policy_*_from_xml] denial nsec");
if (check_if_updated) {
update_this = 0;
if (policy_denial_type(policy) != POLICY_DENIAL_TYPE_NSEC) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_type(policy, POLICY_DENIAL_TYPE_NSEC)) {
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node2->name, "NSEC3")) {
ods_log_deeebug("[policy_*_from_xml] denial nsec3");
if (check_if_updated) {
update_this = 0;
if (policy_denial_type(policy) != POLICY_DENIAL_TYPE_NSEC3) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_type(policy, POLICY_DENIAL_TYPE_NSEC3)) {
return DB_ERROR_UNKNOWN;
}
}
for (node3 = node2->children; node3; node3 = node3->next) {
if (node3->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node3->name, "TTL")) {
denial_ttl = 1;
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] denial ttl %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (policy_denial_ttl(policy) != duration2time(duration)) {
if (policy_set_denial_ttl(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
if (check_if_updated) *updated = 1;
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "OptOut")) {
denial_optout = 1;
ods_log_deeebug("[policy_*_from_xml] denial optout");
if (check_if_updated) {
update_this = 0;
if (!policy_denial_optout(policy)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_optout(policy, 1)) {
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node3->name, "Resalt")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] denial resalt %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_denial_resalt(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_resalt(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "Hash")) {
for (node4 = node3->children; node4; node4 = node4->next) {
if (node4->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node4->name, "Algorithm")) {
if (!(xml_text = xmlNodeGetContent(node4))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] denial algorithm %s", (char*)xml_text);
if (check_if_updated) {
update_this = 0;
if (policy_denial_algorithm(policy) != (unsigned int)atoi((char*)xml_text)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_algorithm(policy, (unsigned int)atoi((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
}
else if (!strcmp((char*)node4->name, "Iterations")) {
if (!(xml_text = xmlNodeGetContent(node4))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] denial iterations %s", (char*)xml_text);
if (check_if_updated) {
update_this = 0;
if (policy_denial_iterations(policy) != (unsigned int)atoi((char*)xml_text)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_iterations(policy, (unsigned int)atoi((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
}
else if (!strcmp((char*)node4->name, "Salt")) {
if (!(xml_text = xmlGetProp(node4, (xmlChar*)"length"))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] denial salt length %s", (char*)xml_text);
if (check_if_updated) {
update_this = 0;
if (policy_denial_salt_length(policy) != (unsigned int)atoi((char*)xml_text)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_salt_length(policy, (unsigned int)atoi((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node4->name);
return DB_ERROR_UNKNOWN;
}
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node3->name);
return DB_ERROR_UNKNOWN;
}
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node2->name);
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node->name, "Keys")) {
for (node2 = node->children; node2; node2 = node2->next) {
if (node2->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node2->name, "TTL")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] keys ttl %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_keys_ttl(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_ttl(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "RetireSafety")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] keys retire safety %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_keys_retire_safety(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_retire_safety(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "PublishSafety")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] keys publish safety %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_keys_publish_safety(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_publish_safety(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "ShareKeys")) {
keys_shared = 1;
ods_log_deeebug("[policy_*_from_xml] keys shared keys");
if (check_if_updated) {
update_this = 0;
if (!policy_keys_shared(policy)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_shared(policy, 1)) {
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node2->name, "Purge")) {
keys_purge = 1;
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] keys purge %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_keys_purge_after(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_purge_after(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "KSK")) {
continue;
}
else if (!strcmp((char*)node2->name, "ZSK")) {
continue;
}
else if (!strcmp((char*)node2->name, "CSK")) {
continue;
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node2->name);
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node->name, "Zone")) {
for (node2 = node->children; node2; node2 = node2->next) {
if (node2->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node2->name, "PropagationDelay")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] zone propagation delay %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_zone_propagation_delay(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_zone_propagation_delay(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "SOA")) {
for (node3 = node2->children; node3; node3 = node3->next) {
if (node3->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node3->name, "TTL")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] zone soa ttl %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_zone_soa_ttl(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_zone_soa_ttl(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "Minimum")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] zone soa minimum %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_zone_soa_minimum(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_zone_soa_minimum(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "Serial")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] zone soa serial %s", (char*)xml_text);
if (check_if_updated) {
update_this = 0;
if (strcmp(policy_zone_soa_serial_text(policy), (char*)xml_text)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_zone_soa_serial_text(policy, (char*)xml_text)) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node3->name);
return DB_ERROR_UNKNOWN;
}
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node2->name);
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node->name, "Parent")) {
for (node2 = node->children; node2; node2 = node2->next) {
if (node2->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node2->name, "RegistrationDelay")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] parent registration delay %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_parent_registration_delay(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_parent_registration_delay(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "PropagationDelay")) {
if (!(xml_text = xmlNodeGetContent(node2))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] parent propagation delay %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_parent_propagation_delay(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_parent_propagation_delay(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node2->name, "SOA")) {
for (node3 = node2->children; node3; node3 = node3->next) {
if (node3->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node3->name, "TTL")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] parent soa ttl %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_parent_soa_ttl(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_parent_soa_ttl(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else if (!strcmp((char*)node3->name, "Minimum")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] parent soa minimum %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_parent_soa_minimum(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_parent_soa_minimum(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node3->name);
return DB_ERROR_UNKNOWN;
}
}
}
else if (!strcmp((char*)node2->name, "DS")) {
for (node3 = node2->children; node3; node3 = node3->next) {
if (node3->type != XML_ELEMENT_NODE) {
continue;
}
if (!strcmp((char*)node3->name, "TTL")) {
if (!(xml_text = xmlNodeGetContent(node3))) {
return DB_ERROR_UNKNOWN;
}
ods_log_deeebug("[policy_*_from_xml] parent ds ttl %s", (char*)xml_text);
if (!(duration = duration_create_from_string((char*)xml_text))) {
if (xml_text) {
xmlFree(xml_text);
}
return DB_ERROR_UNKNOWN;
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
if (check_if_updated) {
update_this = 0;
if (policy_parent_ds_ttl(policy) != duration2time(duration)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_parent_ds_ttl(policy, duration2time(duration))) {
duration_cleanup(duration);
return DB_ERROR_UNKNOWN;
}
}
duration_cleanup(duration);
duration = NULL;
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node3->name);
return DB_ERROR_UNKNOWN;
}
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node2->name);
return DB_ERROR_UNKNOWN;
}
}
}
else {
ods_log_deeebug("[policy_*_from_xml] unknown %s", (char*)node->name);
return DB_ERROR_UNKNOWN;
}
}
if (xml_text) {
xmlFree(xml_text);
xml_text = NULL;
}
duration_cleanup(duration);
duration = NULL;
/*
* If we did not find these XML elements we need to disable them
*/
if (!denial_optout) {
ods_log_deeebug("[policy_*_from_xml] - denial optout");
if (check_if_updated) {
update_this = 0;
if (policy_denial_optout(policy)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_denial_optout(policy, 0)) {
return DB_ERROR_UNKNOWN;
}
}
}
if (!keys_shared) {
ods_log_deeebug("[policy_*_from_xml] - keys shared keys");
if (check_if_updated) {
update_this = 0;
if (policy_keys_shared(policy)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_shared(policy, 0)) {
return DB_ERROR_UNKNOWN;
}
}
}
if (!signatures_max_zone_ttl) {
ods_log_deeebug("[policy_*_from_xml] - signatures max zone ttl");
if (policy_signatures_max_zone_ttl(policy) != 86400)
{
if (policy_set_signatures_max_zone_ttl(policy, 86400)) {
return DB_ERROR_UNKNOWN;
}
if (check_if_updated) *updated = 1;
}
}
if (!keys_purge) {
ods_log_deeebug("[policy_*_from_xml] - keys purge");
if (check_if_updated) {
update_this = 0;
if (policy_keys_purge_after(policy)) {
*updated = 1;
update_this = 1;
}
}
if (update_this) {
if (policy_set_keys_purge_after(policy, 0)) {
return DB_ERROR_UNKNOWN;
}
}
}
if (!denial_ttl) {
ods_log_deeebug("[policy_*_from_xml] - denial ttl");
update_this = 0;
if (policy_denial_ttl(policy)) {
/* it was not mentioned in kasp. set it to 0 */
update_this = 1;
}
if (update_this) {
if (policy_set_denial_ttl(policy, 0)) {
return DB_ERROR_UNKNOWN;
}
if (check_if_updated) *updated = 1;
}
}
/* Check if passtrough has toggled */
if (passthrough != policy_passthrough(policy)) {
ods_log_deeebug("[policy_*_from_xml] - passthrough set to %d",
passthrough);
if (check_if_updated)
*updated = 1;
if (policy_set_passthrough(policy, passthrough)) {
return DB_ERROR_UNKNOWN;
}
}
return DB_OK;
}
int policy_create_from_xml(policy_t* policy, xmlNodePtr policy_node) {
if (!policy) {
return DB_ERROR_UNKNOWN;
}
if (!policy_node) {
return DB_ERROR_UNKNOWN;
}
return __xmlNode2policy(policy, policy_node, NULL);
}
int policy_update_from_xml(policy_t* policy, xmlNodePtr policy_node, int* updated) {
if (!policy) {
return DB_ERROR_UNKNOWN;
}
if (!policy_node) {
return DB_ERROR_UNKNOWN;
}
if (!updated) {
return DB_ERROR_UNKNOWN;
}
return __xmlNode2policy(policy, policy_node, updated);
}
policy_key_list_t* policy_get_policy_keys(const policy_t* policy) {
if (!policy) {
return NULL;
}
if (!policy->dbo) {
return NULL;
}
if (db_value_not_empty(&(policy->id))) {
return NULL;
}
return policy_key_list_new_get_by_policy_id(db_object_connection(policy->dbo),
&(policy->id));
}
db_error.h
DB_ERROR_UNKNOWN
#define DB_ERROR_UNKNOWN
Definition db_error.h:40
DB_OK
#define DB_OK
Definition db_error.h:36
db_object_connection
const db_connection_t * db_object_connection(const db_object_t *object)
Definition db_object.c:320
db_value_not_empty
int db_value_not_empty(const db_value_t *value)
Definition db_value.c:347
policy_denial_salt_length
unsigned int policy_denial_salt_length(const policy_t *policy)
Definition policy.c:941
policy_set_name
int policy_set_name(policy_t *policy, const char *name_text)
Definition policy.c:1142
policy_zone_propagation_delay
unsigned int policy_zone_propagation_delay(const policy_t *policy)
Definition policy.c:1005
policy_denial_iterations
unsigned int policy_denial_iterations(const policy_t *policy)
Definition policy.c:933
policy_set_parent_ds_ttl
int policy_set_parent_ds_ttl(policy_t *policy, unsigned int parent_ds_ttl)
Definition policy.c:1500
policy_set_denial_type
int policy_set_denial_type(policy_t *policy, policy_denial_type_t denial_type)
Definition policy.c:1266
policy_set_denial_ttl
int policy_set_denial_ttl(policy_t *policy, unsigned int denial_ttl)
Definition policy.c:1289
policy_denial_optout
unsigned int policy_denial_optout(const policy_t *policy)
Definition policy.c:901
policy_parent_soa_minimum
unsigned int policy_parent_soa_minimum(const policy_t *policy)
Definition policy.c:1077
policy_set_signatures_resign
int policy_set_signatures_resign(policy_t *policy, unsigned int signatures_resign)
Definition policy.c:1186
policy_signatures_validity_denial
unsigned int policy_signatures_validity_denial(const policy_t *policy)
Definition policy.c:869
policy_keys_purge_after
unsigned int policy_keys_purge_after(const policy_t *policy)
Definition policy.c:997
policy_set_denial_iterations
int policy_set_denial_iterations(policy_t *policy, unsigned int denial_iterations)
Definition policy.c:1323
policy_parent_ds_ttl
unsigned int policy_parent_ds_ttl(const policy_t *policy)
Definition policy.c:1061
policy_signatures_resign
unsigned int policy_signatures_resign(const policy_t *policy)
Definition policy.c:829
policy_set_parent_soa_minimum
int policy_set_parent_soa_minimum(policy_t *policy, unsigned int parent_soa_minimum)
Definition policy.c:1520
policy_set_signatures_inception_offset
int policy_set_signatures_inception_offset(policy_t *policy, unsigned int signatures_inception_offset)
Definition policy.c:1216
policy_set_zone_propagation_delay
int policy_set_zone_propagation_delay(policy_t *policy, unsigned int zone_propagation_delay)
Definition policy.c:1433
policy_keys_ttl
unsigned int policy_keys_ttl(const policy_t *policy)
Definition policy.c:965
policy_parent_propagation_delay
unsigned int policy_parent_propagation_delay(const policy_t *policy)
Definition policy.c:1053
policy_set_keys_purge_after
int policy_set_keys_purge_after(policy_t *policy, unsigned int keys_purge_after)
Definition policy.c:1423
policy_zone_soa_ttl
unsigned int policy_zone_soa_ttl(const policy_t *policy)
Definition policy.c:1013
policy_zone_soa_minimum
unsigned int policy_zone_soa_minimum(const policy_t *policy)
Definition policy.c:1021
policy_passthrough
unsigned int policy_passthrough(const policy_t *policy)
Definition policy.c:1085
policy_signatures_refresh
unsigned int policy_signatures_refresh(const policy_t *policy)
Definition policy.c:837
policy_denial_ttl
unsigned int policy_denial_ttl(const policy_t *policy)
Definition policy.c:909
policy_signatures_max_zone_ttl
unsigned int policy_signatures_max_zone_ttl(const policy_t *policy)
Definition policy.c:885
policy_set_parent_soa_ttl
int policy_set_parent_soa_ttl(policy_t *policy, unsigned int parent_soa_ttl)
Definition policy.c:1510
policy_name
const char * policy_name(const policy_t *policy)
Definition policy.c:813
policy_set_denial_resalt
int policy_set_denial_resalt(policy_t *policy, unsigned int denial_resalt)
Definition policy.c:1299
policy_keys_shared
unsigned int policy_keys_shared(const policy_t *policy)
Definition policy.c:989
policy_set_denial_algorithm
int policy_set_denial_algorithm(policy_t *policy, unsigned int denial_algorithm)
Definition policy.c:1309
policy_set_parent_registration_delay
int policy_set_parent_registration_delay(policy_t *policy, unsigned int parent_registration_delay)
Definition policy.c:1480
policy_set_zone_soa_serial_text
int policy_set_zone_soa_serial_text(policy_t *policy, const char *zone_soa_serial)
Definition policy.c:1463
policy_signatures_jitter
unsigned int policy_signatures_jitter(const policy_t *policy)
Definition policy.c:845
policy_parent_registration_delay
unsigned int policy_parent_registration_delay(const policy_t *policy)
Definition policy.c:1045
policy_set_parent_propagation_delay
int policy_set_parent_propagation_delay(policy_t *policy, unsigned int parent_propagation_delay)
Definition policy.c:1490
policy_set_denial_optout
int policy_set_denial_optout(policy_t *policy, unsigned int denial_optout)
Definition policy.c:1279
policy_signatures_inception_offset
unsigned int policy_signatures_inception_offset(const policy_t *policy)
Definition policy.c:853
policy_set_signatures_max_zone_ttl
int policy_set_signatures_max_zone_ttl(policy_t *policy, unsigned int signatures_max_zone_ttl)
Definition policy.c:1256
policy_set_signatures_jitter
int policy_set_signatures_jitter(policy_t *policy, unsigned int signatures_jitter)
Definition policy.c:1206
policy_set_description
int policy_set_description(policy_t *policy, const char *description_text)
Definition policy.c:1164
policy_set_keys_shared
int policy_set_keys_shared(policy_t *policy, unsigned int keys_shared)
Definition policy.c:1413
policy_parent_soa_ttl
unsigned int policy_parent_soa_ttl(const policy_t *policy)
Definition policy.c:1069
policy_set_denial_salt_length
int policy_set_denial_salt_length(policy_t *policy, unsigned int denial_salt_length)
Definition policy.c:1337
policy_zone_soa_serial_text
const char * policy_zone_soa_serial_text(const policy_t *policy)
Definition policy.c:1029
policy_set_signatures_validity_keyset
int policy_set_signatures_validity_keyset(policy_t *policy, unsigned int signatures_validity_keyset)
Definition policy.c:1246
policy_set_signatures_validity_default
int policy_set_signatures_validity_default(policy_t *policy, unsigned int signatures_validity_default)
Definition policy.c:1226
policy_denial_algorithm
unsigned int policy_denial_algorithm(const policy_t *policy)
Definition policy.c:925
policy_signatures_validity_default
unsigned int policy_signatures_validity_default(const policy_t *policy)
Definition policy.c:861
policy_set_signatures_refresh
int policy_set_signatures_refresh(policy_t *policy, unsigned int signatures_refresh)
Definition policy.c:1196
policy_set_keys_ttl
int policy_set_keys_ttl(policy_t *policy, unsigned int keys_ttl)
Definition policy.c:1383
policy_description
const char * policy_description(const policy_t *policy)
Definition policy.c:821
policy_set_signatures_validity_denial
int policy_set_signatures_validity_denial(policy_t *policy, unsigned int signatures_validity_denial)
Definition policy.c:1236
policy_set_passthrough
int policy_set_passthrough(policy_t *policy, unsigned int passthrough)
Definition policy.c:1530
policy_denial_resalt
unsigned int policy_denial_resalt(const policy_t *policy)
Definition policy.c:917
policy_keys_publish_safety
unsigned int policy_keys_publish_safety(const policy_t *policy)
Definition policy.c:981
policy_set_zone_soa_minimum
int policy_set_zone_soa_minimum(policy_t *policy, unsigned int zone_soa_minimum)
Definition policy.c:1453
policy_set_keys_publish_safety
int policy_set_keys_publish_safety(policy_t *policy, unsigned int keys_publish_safety)
Definition policy.c:1403
policy_keys_retire_safety
unsigned int policy_keys_retire_safety(const policy_t *policy)
Definition policy.c:973
policy_set_keys_retire_safety
int policy_set_keys_retire_safety(policy_t *policy, unsigned int keys_retire_safety)
Definition policy.c:1393
policy_signatures_validity_keyset
unsigned int policy_signatures_validity_keyset(const policy_t *policy)
Definition policy.c:877
policy_set_zone_soa_ttl
int policy_set_zone_soa_ttl(policy_t *policy, unsigned int zone_soa_ttl)
Definition policy.c:1443
policy.h
policy_t
struct policy policy_t
Definition policy.h:37
policy_denial_type
policy_denial_type
Definition policy.h:40
POLICY_DENIAL_TYPE_NSEC
@ POLICY_DENIAL_TYPE_NSEC
Definition policy.h:42
POLICY_DENIAL_TYPE_NSEC3
@ POLICY_DENIAL_TYPE_NSEC3
Definition policy.h:43
policy_get_policy_keys
policy_key_list_t * policy_get_policy_keys(const policy_t *policy)
Definition policy_ext.c:1241
policy_update_from_xml
int policy_update_from_xml(policy_t *policy, xmlNodePtr policy_node, int *updated)
Definition policy_ext.c:1227
policy_create_from_xml
int policy_create_from_xml(policy_t *policy, xmlNodePtr policy_node)
Definition policy_ext.c:1216
policy_key_list_new_get_by_policy_id
policy_key_list_t * policy_key_list_new_get_by_policy_id(const db_connection_t *connection, const db_value_t *policy_id)
Definition policy_key.c:1299
policy_key_list_t
struct policy_key_list policy_key_list_t
Definition policy_key.h:38
policy
Definition policy.h:60
policy::id
db_value_t id
Definition policy.h:62
policy::dbo
db_object_t * dbo
Definition policy.h:61