33 #include "clientpipe.h"
39 #include <libxml/parser.h>
40 #include <libxml/tree.h>
49 xmlNodePtr root = NULL;
59 char* dirname, *dirlast;
68 if (access(filename, W_OK)) {
69 if (errno == ENOENT) {
70 if ((dirname = strdup(filename))) {
71 if ((dirlast = strrchr(dirname,
'/'))) {
73 if (access(dirname, W_OK)) {
74 client_printf_err(sockfd,
"Write access to directory denied: %s\n", strerror(errno));
83 client_printf_err(sockfd,
"Write access to file denied: %s\n", strerror(errno));
88 if (!(doc = xmlNewDoc((xmlChar*)
"1.0"))
89 || !(root = xmlNewNode(NULL, (xmlChar*)
"ZoneList")))
91 client_printf_err(sockfd,
"Unable to create XML elements, memory allocation error!\n");
99 node = xmlNewComment((xmlChar*)
101 "********* Important changes to zonelist.xml in 2.0 ***************\n"
103 "In 2.0, the zonelist.xml file is no longer automatically updated when zones\n"
104 "are added or deleted via the command line by using the 'ods-enforcer zone add'\n"
105 "command. However, in 2.0 it is possible to force an update of the zonelist.xml\n"
106 "file by using the new 'xml' flag. This is in contrast to the behaviour in 1.4\n"
107 "where zonelist.xml was always updated, unless the 'no-xml' flag was used. \n"
109 xmlNodeAddContent(node, (xmlChar*)
110 "As a result in 2.0 the contents of the enforcer database should be considered\n"
111 "the 'master' for the list of currently configured zones, not the zonelist.xml\n"
112 "file as the file can easily become out of sync with the database.\n"
114 xmlNodeAddContent(node, (xmlChar*)
115 "The contents of the database can be listed using:\n"
116 " ods-enforcer zone list\n"
117 "and exported using the command\n"
118 " ods-enforcer zonelist export\n"
119 "The contents of the database can still be updated in bulk from the zonelist.xml\n"
120 "file by using the command:\n"
121 " ods-enforcer zonelist import (or ods-enforcer update zonelist)\n\n"
123 xmlAddChild(root, node);
125 xmlDocSetRootElement(doc, root);
133 client_printf_err(sockfd,
"Unable to get list of zones, database error!\n");
137 client_printf_err(sockfd,
"Unable to get list of zones, memory allocation error!\n");
158 client_printf_err(sockfd,
"Unable to get policy, database error!\n");
165 if (!(node = xmlNewChild(root, NULL, (xmlChar*)
"Zone", NULL))
166 || !xmlNewProp(node, (xmlChar*)
"name", (xmlChar*)
zone_db_name(zone))
169 || !(node2 = xmlNewChild(node, NULL, (xmlChar*)
"Adapters", NULL))
170 || !(node3 = xmlNewChild(node2, NULL, (xmlChar*)
"Input", NULL))
173 || !(node3 = xmlNewChild(node2, NULL, (xmlChar*)
"Output", NULL))
177 client_printf_err(sockfd,
"Unable to create XML elements for zone %s!\n",
zone_db_name(zone));
186 if (snprintf(path,
sizeof(path),
"%s.new", filename) >= (
int)
sizeof(path)) {
187 client_printf_err(sockfd,
"Unable to write zonelist, memory allocation error!\n");
192 if (xmlSaveFormatFileEnc(path, doc,
"UTF-8", 1) == -1) {
193 client_printf_err(sockfd,
"Unable to write zonelist, LibXML error!\n");
200 client_printf_err(sockfd,
"Unable to validate the exported zonelist XML!\n");
205 if (rename(path, filename)) {
206 client_printf_err(sockfd,
"Unable to write zonelist, rename failed!\n");
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
int check_zonelist(const char *zonelist, int verbose, char **policy_names, int policy_count)
const char * policy_name(const policy_t *policy)
const db_value_t * policy_id(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 zone_db_t * zone_list_db_next(zone_list_db_t *zone_list)
const char * zone_db_output_adapter_type(const zone_db_t *zone)
int zone_list_db_get(zone_list_db_t *zone_list)
const char * zone_db_input_adapter_type(const zone_db_t *zone)
zone_list_db_t * zone_list_db_new(const db_connection_t *connection)
const char * zone_db_input_adapter_uri(const zone_db_t *zone)
void zone_list_db_free(zone_list_db_t *zone_list)
const db_value_t * zone_db_policy_id(const zone_db_t *zone)
int zonelist_export(int sockfd, db_connection_t *connection, const char *filename, int comment)
#define ZONELIST_EXPORT_ERR_DATABASE
#define ZONELIST_EXPORT_OK
#define ZONELIST_EXPORT_ERR_ARGS
#define ZONELIST_EXPORT_ERR_XML
#define ZONELIST_EXPORT_ERR_MEMORY
#define ZONELIST_EXPORT_ERR_FILE