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, xmlNs **ns_recycle_writable, xmlNs **ns_recycle_readable, xmlNs **ns_recycle_denied)
58 if (ns == NS_WRITABLE)
60 if (*ns_recycle_writable == NULL)
62 *ns_recycle_writable = xmlNewNs(xmlDocGetRootElement(i_node->doc),
65 xmlSetNs(i_node, *ns_recycle_writable);
68 else if (ns == NS_READABLE)
70 if (*ns_recycle_readable == NULL)
72 *ns_recycle_readable = xmlNewNs(xmlDocGetRootElement(i_node->doc),
75 xmlSetNs(i_node, *ns_recycle_readable);
78 else if (ns == NS_DENIED)
80 if (*ns_recycle_denied == NULL)
82 *ns_recycle_denied = xmlNewNs(xmlDocGetRootElement(i_node->doc),
85 xmlSetNs(i_node, *ns_recycle_denied);
105 pcmk__acl_annotate_permissions_recursive(xmlNode *xml_modify)
108 static xmlNs *ns_recycle_writable = NULL,
109 *ns_recycle_readable = NULL,
110 *ns_recycle_denied = NULL;
111 static const xmlDoc *prev_doc = NULL;
113 xmlNode *i_node = NULL;
117 if (prev_doc == NULL || prev_doc != xml_modify->doc) {
118 prev_doc = xml_modify->doc;
119 ns_recycle_writable = ns_recycle_readable = ns_recycle_denied = NULL;
122 for (i_node = xml_modify; i_node != NULL; i_node = i_node->next) {
123 switch (i_node->type) {
124 case XML_ELEMENT_NODE:
134 pcmk__acl_mark_node_with_namespace(i_node, ns, &ret, &ns_recycle_writable, &ns_recycle_readable, &ns_recycle_denied);
136 if (i_node->properties != NULL) {
140 ret |= pcmk__acl_annotate_permissions_recursive((xmlNodePtr) i_node->properties);
142 if (i_node->children != NULL) {
143 ret |= pcmk__acl_annotate_permissions_recursive(i_node->children);
146 case XML_ATTRIBUTE_NODE:
149 (
const char *) i_node->name,
153 (
const char *) i_node->name,
159 pcmk__acl_mark_node_with_namespace(i_node, ns, &ret, &ns_recycle_writable, &ns_recycle_readable, &ns_recycle_denied);
161 case XML_COMMENT_NODE:
175 pcmk__acl_mark_node_with_namespace(i_node, ns, &ret, &ns_recycle_writable, &ns_recycle_readable, &ns_recycle_denied);
187 xmlDoc **acl_evaled_doc)
190 xmlNode *
target, *comment;
191 const char *validation;
194 CRM_CHECK(cib_doc != NULL,
return EINVAL);
195 CRM_CHECK(acl_evaled_doc != NULL,
return EINVAL);
198 if (strpbrk(cred,
"<>&") != NULL) {
221 ret = pcmk__acl_annotate_permissions_recursive(
target);
227 if (comment == NULL) {
231 xmlAddPrevSibling(xmlDocGetRootElement(
target->doc), comment);
232 *acl_evaled_doc =
target->doc;
242 xmlChar **doc_txt_ptr)
245 xsltStylesheet *xslt;
246 xsltTransformContext *xslt_ctxt;
249 static const char *params_namespace[] = {
253 "accessrendercfg:c-reset",
"",
254 "accessrender:extra-spacing",
"no",
257 }, *params_useansi[] = {
259 "accessrendercfg:c-writable",
"\x1b[32m",
260 "accessrendercfg:c-readable",
"\x1b[34m",
261 "accessrendercfg:c-denied",
"\x1b[31m",
262 "accessrendercfg:c-reset",
"\x1b[0m",
263 "accessrender:extra-spacing",
"no",
266 }, *params_noansi[] = {
267 "accessrendercfg:c-writable",
"vvv---[ WRITABLE ]---vvv",
268 "accessrendercfg:c-readable",
"vvv---[ READABLE ]---vvv",
269 "accessrendercfg:c-denied",
"vvv---[ ~DENIED~ ]---vvv",
270 "accessrendercfg:c-reset",
"",
271 "accessrender:extra-spacing",
"yes",
272 "accessrender:self-reproducing-prefix",
"",
277 xmlParserCtxtPtr parser_ctxt;
284 xmlChar *annotated_dump;
287 xmlDocDumpFormatMemory(annotated_doc, &annotated_dump, &dump_size, 1);
288 res = xmlReadDoc(annotated_dump,
"on-the-fly-access-render", NULL,
291 xmlFree(annotated_dump);
292 xmlFreeDoc(annotated_doc);
297 parser_ctxt = xmlNewParserCtxt();
302 xslt_doc = xmlCtxtReadFile(parser_ctxt, sfile, NULL, XML_PARSE_NONET);
304 xslt = xsltParseStylesheetDoc(xslt_doc);
306 crm_crit(
"Problem in parsing %s", sfile);
311 xmlFreeParserCtxt(parser_ctxt);
313 xslt_ctxt = xsltNewTransformContext(xslt, annotated_doc);
317 params = params_noansi;
319 params = params_namespace;
321 params = params_useansi;
324 xsltQuoteUserParams(xslt_ctxt, params);
326 res = xsltApplyStylesheetUser(xslt, annotated_doc, NULL,
327 NULL, NULL, xslt_ctxt);
329 xmlFreeDoc(annotated_doc);
330 annotated_doc = NULL;
331 xsltFreeTransformContext(xslt_ctxt);
335 char **param_i = (
char **) params;
338 }
while (*param_i++ != NULL);
346 int temp = xsltSaveResultToString(doc_txt_ptr, &doc_txt_len, res, xslt);
354 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)
int pcmk__acl_annotate_permissions(const char *cred, xmlDoc *cib_doc, xmlDoc **acl_evaled_doc)
Mark CIB with namespace-encoded result of ACLs eval'd per credential.
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.