13 #include <sys/types.h> 19 #include <libxml/tree.h> 27 typedef struct xml_acl_s {
46 g_list_free_full(acls, free_acl);
68 if ((tag == NULL) && (ref == NULL) && (xpath == NULL)) {
70 crm_trace(
"Ignoring ACL <%s> element without selection criteria",
80 acl->xpath = g_strdup(xpath);
81 crm_trace(
"Unpacked ACL <%s> element using xpath: %s",
82 xml->name, acl->xpath);
85 GString *buf = g_string_sized_new(128);
87 if ((ref != NULL) && (attr != NULL)) {
90 ref,
"' and @", attr,
"]", NULL);
92 }
else if (ref != NULL) {
96 }
else if (attr != NULL) {
97 pcmk__g_strcat(buf,
"//", pcmk__s(tag,
"*"),
"[@", attr,
"]", NULL);
103 acl->xpath = buf->str;
105 g_string_free(buf, FALSE);
106 crm_trace(
"Unpacked ACL <%s> element as xpath: %s",
107 xml->name, acl->xpath);
110 return g_list_append(acls, acl);
126 parse_acl_entry(
const xmlNode *acl_top,
const xmlNode *acl_entry, GList *acls)
128 xmlNode *child = NULL;
130 for (child = pcmk__xe_first_child(acl_entry); child;
131 child = pcmk__xe_next(child)) {
132 const char *tag = (
const char *) child->name;
137 crm_trace(
"Unpacking ACL <%s> element of kind '%s'", tag, kind);
140 crm_trace(
"Unpacking ACL <%s> element", tag);
148 xmlNode *role = NULL;
150 for (role = pcmk__xe_first_child(acl_top); role;
151 role = pcmk__xe_next(role)) {
156 if (role_id && strcmp(ref_role, role_id) == 0) {
157 crm_trace(
"Unpacking referenced role '%s' in ACL <%s> element",
158 role_id, acl_entry->name);
159 acls = parse_acl_entry(acl_top, role, acls);
176 crm_warn(
"Ignoring unknown ACL %s '%s'",
177 (kind?
"kind" :
"element"), tag);
227 xmlXPathObjectPtr xpathObj = NULL;
230 crm_trace(
"Skipping ACLs for user '%s' because not enabled for this XML",
235 for (aIter = docpriv->
acls; aIter != NULL; aIter = aIter->next) {
236 int max = 0, lpc = 0;
240 max = numXpathResults(xpathObj);
242 for (lpc = 0; lpc < max; lpc++) {
245 nodepriv = match->_private;
252 crm_trace(
"Applying %s ACL to %s matched by %s",
253 acl_to_text(acl->mode),
path->str, acl->xpath);
254 g_string_free(
path, TRUE);
259 crm_trace(
"Applied %s ACL %s (%d match%s)",
260 acl_to_text(acl->mode), acl->xpath, max,
261 ((max == 1)?
"" :
"es"));
285 || (
target->doc->_private == NULL)) {
289 docpriv =
target->doc->_private;
291 crm_trace(
"Not unpacking ACLs because not required for user '%s'",
294 }
else if (docpriv->
acls == NULL) {
301 xmlNode *child = NULL;
303 for (child = pcmk__xe_first_child(acls); child;
304 child = pcmk__xe_next(child)) {
314 if (
id && strcmp(
id, user) == 0) {
315 crm_debug(
"Unpacking ACLs for user '%s'",
id);
316 docpriv->
acls = parse_acl_entry(acls, child, docpriv->
acls);
326 crm_debug(
"Unpacking ACLs for group '%s'",
id);
327 docpriv->
acls = parse_acl_entry(acls, child, docpriv->
acls);
357 }
else if (pcmk_all_flags_set(allowed, requested)) {
383 purge_xml_attributes(xmlNode *xml)
385 xmlNode *child = NULL;
386 xmlAttr *xIter = NULL;
387 bool readable_children =
false;
396 xIter = xml->properties;
397 while (xIter != NULL) {
398 xmlAttr *tmp = xIter;
399 const char *prop_name = (
const char *)xIter->name;
406 xmlUnsetProp(xml, tmp->name);
409 child = pcmk__xml_first_child(xml);
410 while ( child != NULL ) {
411 xmlNode *tmp = child;
413 child = pcmk__xml_next(child);
414 readable_children |= purge_xml_attributes(tmp);
417 if (!readable_children) {
420 return readable_children;
444 crm_trace(
"Not filtering XML because ACLs not required for user '%s'",
449 crm_trace(
"Filtering XML copy using user '%s' ACLs", user);
457 docpriv =
target->doc->_private;
458 for(aIter = docpriv->
acls; aIter != NULL &&
target; aIter = aIter->next) {
465 }
else if (acl->xpath) {
469 max = numXpathResults(xpathObj);
470 for(lpc = 0; lpc < max; lpc++) {
473 if (!purge_xml_attributes(match) && (match ==
target)) {
474 crm_trace(
"ACLs deny user '%s' access to entire XML document",
480 crm_trace(
"ACLs deny user '%s' access to %s (%d %s)",
481 user, acl->xpath, max,
487 if (!purge_xml_attributes(
target)) {
488 crm_trace(
"ACLs deny user '%s' access to entire XML document", user);
493 g_list_free_full(docpriv->
acls, free_acl);
494 docpriv->
acls = NULL;
497 crm_trace(
"User '%s' without ACLs denied access to entire XML document",
523 implicitly_allowed(
const xmlNode *xml)
525 GString *
path = NULL;
527 for (xmlAttr *prop = xml->properties; prop != NULL; prop = prop->next) {
528 if (strcmp((
const char *) prop->name,
XML_ATTR_ID) != 0) {
537 g_string_free(
path, TRUE);
541 g_string_free(
path, TRUE);
545 #define display_id(xml) (ID(xml)? ID(xml) : "<unset>") 568 if (implicitly_allowed(xml)) {
569 crm_trace(
"Creation of <%s> scaffolding with id=\"%s\"" 570 " is implicitly allowed",
574 crm_trace(
"ACLs allow creation of <%s> with id=\"%s\"",
577 }
else if (check_top) {
578 crm_trace(
"ACLs disallow creation of <%s> with id=\"%s\"",
584 crm_notice(
"ACLs would disallow creation of %s<%s> with id=\"%s\"",
585 ((xml == xmlDocGetRootElement(xml->doc))?
"root element " :
""),
590 for (xmlNode *cIter = pcmk__xml_first_child(xml); cIter != NULL; ) {
591 xmlNode *child = cIter;
592 cIter = pcmk__xml_next(cIter);
607 if (xml && xml->doc && xml->doc->_private){
638 if (xml && xml->doc && xml->doc->_private){
656 GString *xpath = NULL;
658 if (docpriv->
acls == NULL) {
667 qb_log_from_external_source(__func__, __FILE__,
668 "User '%s' without ACLs denied %s " 670 docpriv->
user, acl_to_text(mode),
671 (
const char *) xpath->str);
672 g_string_free(xpath, TRUE);
691 if (test_acl_mode(nodepriv->
flags, mode)) {
703 qb_log_from_external_source(__func__, __FILE__,
704 "%sACL denies user '%s' %s access " 706 (
parent != xml)?
"Parent ":
"",
707 docpriv->
user, acl_to_text(mode),
708 (
const char *) xpath->str);
709 g_string_free(xpath, TRUE);
723 qb_log_from_external_source(__func__, __FILE__,
724 "Default ACL denies user '%s' %s access to " 726 docpriv->
user, acl_to_text(mode),
727 (
const char *) xpath->str);
728 g_string_free(xpath, TRUE);
745 if (pcmk__str_empty(user)) {
746 crm_trace(
"ACLs not required because no user set");
750 crm_trace(
"ACLs not required for privileged user %s", user);
761 struct passwd *pwent = getpwuid(uid);
764 crm_perror(LOG_INFO,
"Cannot get user details for user ID %d", uid);
791 const char *peer_user)
793 static const char *effective_user = NULL;
794 const char *requested_user = NULL;
795 const char *user = NULL;
797 if (effective_user == NULL) {
799 if (effective_user == NULL) {
800 effective_user = strdup(
"#unprivileged");
801 CRM_CHECK(effective_user != NULL,
return NULL);
802 crm_err(
"Unable to determine effective user, assuming unprivileged for ACLs");
807 if (requested_user == NULL) {
816 if (!pcmk__is_privileged(effective_user)) {
820 user = effective_user;
822 }
else if (peer_user == NULL && requested_user == NULL) {
826 user = effective_user;
828 }
else if (peer_user == NULL) {
830 user = requested_user;
832 }
else if (!pcmk__is_privileged(peer_user)) {
838 }
else if (requested_user == NULL) {
844 user = requested_user;
856 return requested_user;
#define CRM_CHECK(expr, failure_action)
void xml_acl_disable(xmlNode *xml)
#define crm_notice(fmt, args...)
#define pcmk__if_tracing(if_action, else_action)
void pcmk__free_acls(GList *acls)
bool pcmk_acl_required(const char *user)
Check whether ACLs are required for a given user.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#define XML_ACL_TAG_WRITE
void pcmk__apply_creation_acl(xmlNode *xml, bool check_top)
G_GNUC_INTERNAL bool pcmk__is_user_in_group(const char *user, const char *group)
void pcmk__set_xml_doc_flag(xmlNode *xml, enum xml_private_flags flag)
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
xmlNode * copy_xml(xmlNode *src_node)
#define XML_ACL_ATTR_REFv1
#define XML_ACL_ATTR_KIND
char * pcmk__uid2username(uid_t uid)
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
Copy ACL-allowed portions of specified XML.
bool pcmk__check_acl(xmlNode *xml, const char *name, enum xml_private_flags mode)
#define crm_warn(fmt, args...)
void pcmk_free_xml_subtree(xmlNode *xml)
#define crm_debug(fmt, args...)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define XML_ACL_ATTR_XPATH
#define XML_ACL_TAG_PERMISSION
#define crm_trace(fmt, args...)
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
void pcmk__enable_acl(xmlNode *acl_source, xmlNode *target, const char *user)
#define XML_ACL_TAG_USERv1
void pcmk__str_update(char **str, const char *value)
Wrappers for and extensions to libxml2.
const char * pcmk__update_acl_user(xmlNode *request, const char *field, const char *peer_user)
#define XML_ACL_ATTR_ATTRIBUTE
void pcmk__unpack_acl(xmlNode *source, xmlNode *target, const char *user)
void free_xml(xmlNode *child)
bool xml_acl_denied(const xmlNode *xml)
Check whether or not an XML node is ACL-denied.
#define XML_ACL_ATTR_TAGv1
const xmlChar * pcmkXmlStr
#define XML_ACL_TAG_GROUP
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
pcmk__action_result_t result
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
#define pcmk__plural_alt(i, s1, s2)
#define XML_ACL_TAG_ROLE_REFv1
void pcmk__apply_acl(xmlNode *xml)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
bool xml_acl_enabled(const xmlNode *xml)
Check whether or not an XML node is ACL-enabled.
GString * pcmk__element_xpath(const xmlNode *xml)
#define XML_ACL_TAG_ROLE_REF
G_GNUC_INTERNAL bool pcmk__tracking_xml_changes(xmlNode *xml, bool lazy)
#define pcmk__set_xml_flags(xml_priv, flags_to_set)
#define pcmk__clear_xml_flags(xml_priv, flags_to_clear)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
struct xml_acl_s xml_acl_t