33 #include "clientpipe.h"
37 #include <libxml/parser.h>
38 #include <libxml/tree.h>
44 static int zonelist_update(
int add,
int sockfd,
const char* filename,
const zone_db_t* zone,
int comment) {
63 if (!access(filename, F_OK)) {
64 if (access(filename, R_OK|W_OK)) {
65 client_printf_err(sockfd,
"Read and/or write access to file denied!\n");
73 client_printf_err(sockfd,
"Unable to read XML, validation error!\n");
77 xmlKeepBlanksDefault(0);
78 if (!(doc = xmlParseFile(filename))) {
79 client_printf_err(sockfd,
"Unable to read XML, parse error!\n");
83 if (!(root = xmlDocGetRootElement(doc))) {
84 client_printf_err(sockfd,
"Unable to get root XML element!\n");
90 if (!(doc = xmlNewDoc((xmlChar*)
"1.0"))
91 || !(root = xmlNewNode(NULL, (xmlChar*)
"ZoneList")))
93 client_printf_err(sockfd,
"Unable to create XML elements, memory allocation error!\n");
101 node = xmlNewComment((xmlChar*)
103 "********* Important changes to zonelist.xml in 2.0 ***************\n"
105 "In 2.0, the zonelist.xml file is no longer automatically updated when zones\n"
106 "are added or deleted via the command line by using the 'ods-enforcer zone add'\n"
107 "command. However, in 2.0 it is possible to force an update of the zonelist.xml\n"
108 "file by using the new 'xml' flag. This is in contrast to the behaviour in 1.4\n"
109 "where zonelist.xml was always updated, unless the 'no-xml' flag was used. \n"
111 xmlNodeAddContent(node, (xmlChar*)
112 "As a result in 2.0 the contents of the enforcer database should be considered\n"
113 "the 'master' for the list of currently configured zones, not the zonelist.xml\n"
114 "file as the file can easily become out of sync with the database.\n"
116 xmlNodeAddContent(node, (xmlChar*)
117 "The contents of the database can be listed using:\n"
118 " ods-enforcer zone list\n"
119 "and exported using the command\n"
120 " ods-enforcer zonelist export\n"
121 "The contents of the database can still be updated in bulk from the zonelist.xml\n"
122 "file by using the command:\n"
123 " ods-enforcer zonelist import (or ods-enforcer update zonelist)\n\n"
125 xmlAddChild(root, node);
127 xmlDocSetRootElement(doc, root);
130 for (; root; root = root->next) {
131 if (root->type != XML_ELEMENT_NODE) {
135 if (!strcmp((
char*)root->name,
"ZoneList")) {
136 for (node = root->children; node; node = node->next) {
137 if (node->type != XML_ELEMENT_NODE) {
140 if (strcmp((
char*)node->name,
"Zone")) {
144 if (!(name = xmlGetProp(node, (
const xmlChar*)
"name"))) {
145 client_printf_err(sockfd,
"Unable to XML property, memory allocation error!\n");
164 client_printf_err(sockfd,
"Unable to update XML, entry already exists!\n");
168 if (!add && !found) {
176 || !(node = xmlNewChild(root, NULL, (xmlChar*)
"Zone", NULL))
177 || !xmlNewProp(node, (xmlChar*)
"name", (xmlChar*)
zone_db_name(zone))
180 || !(node2 = xmlNewChild(node, NULL, (xmlChar*)
"Adapters", NULL))
181 || !(node3 = xmlNewChild(node2, NULL, (xmlChar*)
"Input", NULL))
184 || !(node3 = xmlNewChild(node2, NULL, (xmlChar*)
"Output", NULL))
188 client_printf_err(sockfd,
"Unable to create new XML element, memory allocation or internal error!\n");
199 if (snprintf(path,
sizeof(path),
"%s.update", filename) >= (
int)
sizeof(path)) {
200 client_printf_err(sockfd,
"Unable to write updated XML, path to long!\n");
205 if (xmlSaveFormatFileEnc(path, doc,
"UTF-8", 1) == -1) {
206 client_printf_err(sockfd,
"Unable to write updated XML, unknown error!\n");
214 client_printf_err(sockfd,
"Validating updated XML failed!\n");
219 if (rename(path, filename)) {
220 client_printf_err(sockfd,
"Unable to write updated XML, rename failed!\n");
229 return zonelist_update(1, sockfd, filename, zone, comment);
233 return zonelist_update(0, sockfd, filename, zone, comment);
int check_zonelist(const char *zonelist, int verbose, char **policy_names, int policy_count)
const char * policy_name(const policy_t *policy)
void policy_free(policy_t *policy)
const char * zone_db_output_adapter_uri(const zone_db_t *zone)
const char * zone_db_name(const zone_db_t *zone)
const char * zone_db_signconf_path(const zone_db_t *zone)
policy_t * zone_db_get_policy(const zone_db_t *zone)
const char * zone_db_output_adapter_type(const zone_db_t *zone)
const char * zone_db_input_adapter_type(const zone_db_t *zone)
const char * zone_db_input_adapter_uri(const zone_db_t *zone)
int zonelist_update_add(int sockfd, const char *filename, const zone_db_t *zone, int comment)
int zonelist_update_delete(int sockfd, const char *filename, const zone_db_t *zone, int comment)
#define ZONELIST_UPDATE_ERR_ARGS
#define ZONELIST_UPDATE_OK
#define ZONELIST_UPDATE_ERR_MEMORY
#define ZONELIST_UPDATE_ERR_FILE
#define ZONELIST_UPDATE_ERR_XML