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",
71 crm_element_name(xml));
80 acl->xpath = strdup(xpath);
82 crm_trace(
"Unpacked ACL <%s> element using xpath: %s",
83 crm_element_name(xml), acl->xpath);
86 GString *buf = g_string_sized_new(128);
88 if ((ref != NULL) && (attr != NULL)) {
91 ref,
"' and @", attr,
"]", NULL);
93 }
else if (ref != NULL) {
97 }
else if (attr != NULL) {
98 pcmk__g_strcat(buf,
"//", pcmk__s(tag,
"*"),
"[@", attr,
"]", NULL);
104 acl->xpath = strdup((
const char *) buf->str);
107 g_string_free(buf, TRUE);
108 crm_trace(
"Unpacked ACL <%s> element as xpath: %s",
109 crm_element_name(xml), acl->xpath);
112 return g_list_append(acls, acl);
128 parse_acl_entry(
const xmlNode *acl_top,
const xmlNode *acl_entry, GList *acls)
130 xmlNode *child = NULL;
132 for (child = pcmk__xe_first_child(acl_entry); child;
133 child = pcmk__xe_next(child)) {
134 const char *tag = crm_element_name(child);
139 crm_trace(
"Unpacking ACL <%s> element of kind '%s'", tag, kind);
142 crm_trace(
"Unpacking ACL <%s> element", tag);
150 xmlNode *role = NULL;
152 for (role = pcmk__xe_first_child(acl_top); role;
153 role = pcmk__xe_next(role)) {
158 if (role_id && strcmp(ref_role, role_id) == 0) {
159 crm_trace(
"Unpacking referenced role '%s' in ACL <%s> element",
160 role_id, crm_element_name(acl_entry));
161 acls = parse_acl_entry(acl_top, role, acls);
178 crm_warn(
"Ignoring unknown ACL %s '%s'",
179 (kind?
"kind" :
"element"), tag);
229 xmlXPathObjectPtr xpathObj = NULL;
232 crm_trace(
"Skipping ACLs for user '%s' because not enabled for this XML",
237 for (aIter = docpriv->
acls; aIter != NULL; aIter = aIter->next) {
238 int max = 0, lpc = 0;
242 max = numXpathResults(xpathObj);
244 for (lpc = 0; lpc < max; lpc++) {
247 nodepriv = match->_private;
254 crm_trace(
"Applying %s ACL to %s matched by %s",
255 acl_to_text(acl->mode),
path->str, acl->xpath);
256 g_string_free(
path, TRUE);
261 crm_trace(
"Applied %s ACL %s (%d match%s)",
262 acl_to_text(acl->mode), acl->xpath, max,
263 ((max == 1)?
"" :
"es"));
287 || (
target->doc->_private == NULL)) {
291 docpriv =
target->doc->_private;
293 crm_trace(
"Not unpacking ACLs because not required for user '%s'",
296 }
else if (docpriv->
acls == NULL) {
303 xmlNode *child = NULL;
305 for (child = pcmk__xe_first_child(acls); child;
306 child = pcmk__xe_next(child)) {
307 const char *tag = crm_element_name(child);
317 if (
id && strcmp(
id, user) == 0) {
318 crm_debug(
"Unpacking ACLs for user '%s'",
id);
319 docpriv->
acls = parse_acl_entry(acls, child, docpriv->
acls);
329 crm_debug(
"Unpacking ACLs for group '%s'",
id);
330 docpriv->
acls = parse_acl_entry(acls, child, docpriv->
acls);
360 }
else if (pcmk_all_flags_set(allowed, requested)) {
386 purge_xml_attributes(xmlNode *xml)
388 xmlNode *child = NULL;
389 xmlAttr *xIter = NULL;
390 bool readable_children =
false;
395 crm_element_name(xml),
ID(xml));
399 xIter = xml->properties;
400 while (xIter != NULL) {
401 xmlAttr *tmp = xIter;
402 const char *prop_name = (
const char *)xIter->name;
409 xmlUnsetProp(xml, tmp->name);
412 child = pcmk__xml_first_child(xml);
413 while ( child != NULL ) {
414 xmlNode *tmp = child;
416 child = pcmk__xml_next(child);
417 readable_children |= purge_xml_attributes(tmp);
420 if (!readable_children) {
423 return readable_children;
447 crm_trace(
"Not filtering XML because ACLs not required for user '%s'",
452 crm_trace(
"Filtering XML copy using user '%s' ACLs", user);
460 docpriv =
target->doc->_private;
461 for(aIter = docpriv->
acls; aIter != NULL &&
target; aIter = aIter->next) {
468 }
else if (acl->xpath) {
472 max = numXpathResults(xpathObj);
473 for(lpc = 0; lpc < max; lpc++) {
476 if (!purge_xml_attributes(match) && (match ==
target)) {
477 crm_trace(
"ACLs deny user '%s' access to entire XML document",
483 crm_trace(
"ACLs deny user '%s' access to %s (%d %s)",
484 user, acl->xpath, max,
490 if (!purge_xml_attributes(
target)) {
491 crm_trace(
"ACLs deny user '%s' access to entire XML document", user);
496 g_list_free_full(docpriv->
acls, free_acl);
497 docpriv->
acls = NULL;
500 crm_trace(
"User '%s' without ACLs denied access to entire XML document",
526 implicitly_allowed(
const xmlNode *xml)
528 GString *
path = NULL;
530 for (xmlAttr *prop = xml->properties; prop != NULL; prop = prop->next) {
531 if (strcmp((
const char *) prop->name,
XML_ATTR_ID) != 0) {
540 g_string_free(
path, TRUE);
544 g_string_free(
path, TRUE);
548 #define display_id(xml) (ID(xml)? ID(xml) : "<unset>") 571 if (implicitly_allowed(xml)) {
572 crm_trace(
"Creation of <%s> scaffolding with id=\"%s\"" 573 " is implicitly allowed",
577 crm_trace(
"ACLs allow creation of <%s> with id=\"%s\"",
580 }
else if (check_top) {
581 crm_trace(
"ACLs disallow creation of <%s> with id=\"%s\"",
587 crm_notice(
"ACLs would disallow creation of %s<%s> with id=\"%s\"",
588 ((xml == xmlDocGetRootElement(xml->doc))?
"root element " :
""),
593 for (xmlNode *cIter = pcmk__xml_first_child(xml); cIter != NULL; ) {
594 xmlNode *child = cIter;
595 cIter = pcmk__xml_next(cIter);
610 if (xml && xml->doc && xml->doc->_private){
641 if (xml && xml->doc && xml->doc->_private){
659 GString *xpath = NULL;
661 if (docpriv->
acls == NULL) {
670 qb_log_from_external_source(__func__, __FILE__,
671 "User '%s' without ACLs denied %s " 673 docpriv->
user, acl_to_text(mode),
674 (
const char *) xpath->str);
675 g_string_free(xpath, TRUE);
694 if (test_acl_mode(nodepriv->
flags, mode)) {
706 qb_log_from_external_source(__func__, __FILE__,
707 "%sACL denies user '%s' %s access " 709 (
parent != xml)?
"Parent ":
"",
710 docpriv->
user, acl_to_text(mode),
711 (
const char *) xpath->str);
712 g_string_free(xpath, TRUE);
726 qb_log_from_external_source(__func__, __FILE__,
727 "Default ACL denies user '%s' %s access to " 729 docpriv->
user, acl_to_text(mode),
730 (
const char *) xpath->str);
731 g_string_free(xpath, TRUE);
748 if (pcmk__str_empty(user)) {
749 crm_trace(
"ACLs not required because no user set");
753 crm_trace(
"ACLs not required for privileged user %s", user);
764 struct passwd *pwent = getpwuid(uid);
767 crm_perror(LOG_INFO,
"Cannot get user details for user ID %d", uid);
794 const char *peer_user)
796 static const char *effective_user = NULL;
797 const char *requested_user = NULL;
798 const char *user = NULL;
800 if (effective_user == NULL) {
802 if (effective_user == NULL) {
803 effective_user = strdup(
"#unprivileged");
804 CRM_CHECK(effective_user != NULL,
return NULL);
805 crm_err(
"Unable to determine effective user, assuming unprivileged for ACLs");
810 if (requested_user == NULL) {
819 if (!pcmk__is_privileged(effective_user)) {
823 user = effective_user;
825 }
else if (peer_user == NULL && requested_user == NULL) {
829 user = effective_user;
831 }
else if (peer_user == NULL) {
833 user = requested_user;
835 }
else if (!pcmk__is_privileged(peer_user)) {
841 }
else if (requested_user == NULL) {
847 user = requested_user;
859 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
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...)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
#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