13 #include <sys/types.h> 19 #include <libxml/parser.h> 20 #include <libxml/tree.h> 21 #include <libxml/xpath.h> 22 #include <libxslt/transform.h> 23 #include <libxslt/variables.h> 24 #include <libxslt/xsltutils.h> 34 #define ACL_NS_PREFIX "http://clusterlabs.org/ns/pacemaker/access/" 35 #define ACL_NS_Q_PREFIX "pcmk-access-" 36 #define ACL_NS_Q_WRITABLE (const xmlChar *) ACL_NS_Q_PREFIX "writable" 37 #define ACL_NS_Q_READABLE (const xmlChar *) ACL_NS_Q_PREFIX "readable" 38 #define ACL_NS_Q_DENIED (const xmlChar *) ACL_NS_Q_PREFIX "denied" 40 static const xmlChar *NS_WRITABLE = (
const xmlChar *)
ACL_NS_PREFIX "writable";
41 static const xmlChar *NS_READABLE = (
const xmlChar *)
ACL_NS_PREFIX "readable";
42 static const xmlChar *NS_DENIED = (
const xmlChar *)
ACL_NS_PREFIX "denied";
56 pcmk__acl_mark_node_with_namespace(xmlNode *i_node,
const xmlChar *ns,
int *ret,
57 xmlNs **ns_recycle_writable,
58 xmlNs **ns_recycle_readable,
59 xmlNs **ns_recycle_denied)
61 if (ns == NS_WRITABLE)
63 if (*ns_recycle_writable == NULL)
65 *ns_recycle_writable = xmlNewNs(xmlDocGetRootElement(i_node->doc),
68 xmlSetNs(i_node, *ns_recycle_writable);
71 else if (ns == NS_READABLE)
73 if (*ns_recycle_readable == NULL)
75 *ns_recycle_readable = xmlNewNs(xmlDocGetRootElement(i_node->doc),
78 xmlSetNs(i_node, *ns_recycle_readable);
81 else if (ns == NS_DENIED)
83 if (*ns_recycle_denied == NULL)
85 *ns_recycle_denied = xmlNewNs(xmlDocGetRootElement(i_node->doc),
88 xmlSetNs(i_node, *ns_recycle_denied);
110 annotate_with_siblings(xmlNode *xml_modify)
113 static xmlNs *ns_recycle_writable = NULL,
114 *ns_recycle_readable = NULL,
115 *ns_recycle_denied = NULL;
116 static const xmlDoc *prev_doc = NULL;
118 xmlNode *i_node = NULL;
122 if (prev_doc == NULL || prev_doc != xml_modify->doc) {
123 prev_doc = xml_modify->doc;
124 ns_recycle_writable = ns_recycle_readable = ns_recycle_denied = NULL;
127 for (i_node = xml_modify; i_node != NULL; i_node = i_node->next) {
128 switch (i_node->type) {
129 case XML_ELEMENT_NODE:
139 pcmk__acl_mark_node_with_namespace(i_node, ns, &ret,
140 &ns_recycle_writable,
141 &ns_recycle_readable,
144 if (i_node->properties != NULL) {
149 ret |= annotate_with_siblings((xmlNodePtr)
152 if (i_node->children != NULL) {
153 ret |= annotate_with_siblings(i_node->children);
157 case XML_ATTRIBUTE_NODE:
160 (
const char *) i_node->name,
164 (
const char *) i_node->name,
170 pcmk__acl_mark_node_with_namespace(i_node, ns, &ret,
171 &ns_recycle_writable,
172 &ns_recycle_readable,
176 case XML_COMMENT_NODE:
179 (
const char *) i_node->name,
183 (
const char *) i_node->name,
189 pcmk__acl_mark_node_with_namespace(i_node, ns, &ret,
190 &ns_recycle_writable,
191 &ns_recycle_readable,
205 xmlDoc **acl_evaled_doc)
208 xmlNode *
target, *comment;
209 const char *validation;
212 CRM_CHECK(cib_doc != NULL,
return EINVAL);
213 CRM_CHECK(acl_evaled_doc != NULL,
return EINVAL);
216 if (strpbrk(cred,
"<>&") != NULL) {
241 ret = annotate_with_siblings(
target);
249 if (comment == NULL) {
253 xmlAddPrevSibling(xmlDocGetRootElement(
target->doc), comment);
254 *acl_evaled_doc =
target->doc;
264 xmlChar **doc_txt_ptr)
267 xsltStylesheet *xslt;
268 xsltTransformContext *xslt_ctxt;
271 static const char *params_namespace[] = {
275 "accessrendercfg:c-reset",
"",
276 "accessrender:extra-spacing",
"no",
279 }, *params_useansi[] = {
281 "accessrendercfg:c-writable",
"\x1b[32m",
282 "accessrendercfg:c-readable",
"\x1b[34m",
283 "accessrendercfg:c-denied",
"\x1b[31m",
284 "accessrendercfg:c-reset",
"\x1b[0m",
285 "accessrender:extra-spacing",
"no",
288 }, *params_noansi[] = {
289 "accessrendercfg:c-writable",
"vvv---[ WRITABLE ]---vvv",
290 "accessrendercfg:c-readable",
"vvv---[ READABLE ]---vvv",
291 "accessrendercfg:c-denied",
"vvv---[ ~DENIED~ ]---vvv",
292 "accessrendercfg:c-reset",
"",
293 "accessrender:extra-spacing",
"yes",
294 "accessrender:self-reproducing-prefix",
"",
299 xmlParserCtxtPtr parser_ctxt;
306 xmlChar *annotated_dump;
313 if (isatty(STDOUT_FILENO)) {
320 xmlDocDumpFormatMemory(annotated_doc, &annotated_dump, &dump_size, 1);
321 res = xmlReadDoc(annotated_dump,
"on-the-fly-access-render", NULL,
324 xmlFree(annotated_dump);
325 xmlFreeDoc(annotated_doc);
330 parser_ctxt = xmlNewParserCtxt();
335 xslt_doc = xmlCtxtReadFile(parser_ctxt, sfile, NULL, XML_PARSE_NONET);
337 xslt = xsltParseStylesheetDoc(xslt_doc);
339 crm_crit(
"Problem in parsing %s", sfile);
344 xmlFreeParserCtxt(parser_ctxt);
346 xslt_ctxt = xsltNewTransformContext(xslt, annotated_doc);
351 params = params_namespace;
354 params = params_noansi;
361 params = params_useansi;
365 xsltQuoteUserParams(xslt_ctxt, params);
367 res = xsltApplyStylesheetUser(xslt, annotated_doc, NULL,
368 NULL, NULL, xslt_ctxt);
370 xmlFreeDoc(annotated_doc);
371 annotated_doc = NULL;
372 xsltFreeTransformContext(xslt_ctxt);
376 char **param_i = (
char **) params;
379 }
while (*param_i++ != NULL);
387 int temp = xsltSaveResultToString(doc_txt_ptr, &doc_txt_len, res, xslt);
395 xsltFreeStylesheet(xslt);
#define CRM_CHECK(expr, failure_action)
#define crm_crit(fmt, args...)
#define ACL_NS_Q_READABLE
int get_schema_version(const char *name)
void pcmk__set_xml_doc_flag(xmlNode *xml, enum xml_private_flags flag)
xmlNode * copy_xml(xmlNode *src_node)
#define ACL_NS_Q_WRITABLE
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define PCMK__COMPAT_ACL_2_MIN_INCL
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
Wrappers for and extensions to libxml2.
#define XML_ATTR_VALIDATION
int pcmk__acl_evaled_render(xmlDoc *annotated_doc, enum pcmk__acl_render_how how, xmlChar **doc_txt_ptr)
const xmlChar * pcmkXmlStr
void pcmk__enable_acl(xmlNode *acl_source, xmlNode *target, const char *user)
bool pcmk__check_acl(xmlNode *xml, const char *name, enum xml_private_flags mode)
char * pcmk__xml_artefact_path(enum pcmk__xml_artefact_ns ns, const char *filespec)
bool pcmk_acl_required(const char *user)
Check whether ACLs are required for a given user.
int pcmk__acl_annotate_permissions(const char *cred, const xmlDoc *cib_doc, xmlDoc **acl_evaled_doc)
Annotate CIB with XML namespaces indicating ACL evaluation results.