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++) {
245 static struct qb_log_callsite *trace_cs = NULL;
248 nodepriv = match->_private;
255 if (trace_cs == NULL) {
256 trace_cs = qb_log_callsite_get(__func__, __FILE__,
"apply_acl",
261 crm_trace(
"Applying %s ACL to %s matched by %s",
262 acl_to_text(acl->mode), (
const char *)
path->str,
264 g_string_free(
path, TRUE);
267 crm_trace(
"Applied %s ACL %s (%d match%s)",
268 acl_to_text(acl->mode), acl->xpath, max,
269 ((max == 1)?
"" :
"es"));
293 || (
target->doc->_private == NULL)) {
297 docpriv =
target->doc->_private;
299 crm_trace(
"Not unpacking ACLs because not required for user '%s'",
302 }
else if (docpriv->
acls == NULL) {
309 xmlNode *child = NULL;
311 for (child = pcmk__xe_first_child(acls); child;
312 child = pcmk__xe_next(child)) {
313 const char *tag = crm_element_name(child);
323 if (
id && strcmp(
id, user) == 0) {
324 crm_debug(
"Unpacking ACLs for user '%s'",
id);
325 docpriv->
acls = parse_acl_entry(acls, child, docpriv->
acls);
335 crm_debug(
"Unpacking ACLs for group '%s'",
id);
336 docpriv->
acls = parse_acl_entry(acls, child, docpriv->
acls);
366 }
else if (pcmk_all_flags_set(allowed, requested)) {
392 purge_xml_attributes(xmlNode *xml)
394 xmlNode *child = NULL;
395 xmlAttr *xIter = NULL;
396 bool readable_children =
false;
400 crm_trace(
"%s[@id=%s] is readable", crm_element_name(xml),
ID(xml));
404 xIter = xml->properties;
405 while (xIter != NULL) {
406 xmlAttr *tmp = xIter;
407 const char *prop_name = (
const char *)xIter->name;
414 xmlUnsetProp(xml, tmp->name);
417 child = pcmk__xml_first_child(xml);
418 while ( child != NULL ) {
419 xmlNode *tmp = child;
421 child = pcmk__xml_next(child);
422 readable_children |= purge_xml_attributes(tmp);
425 if (!readable_children) {
428 return readable_children;
452 crm_trace(
"Not filtering XML because ACLs not required for user '%s'",
457 crm_trace(
"Filtering XML copy using user '%s' ACLs", user);
465 docpriv =
target->doc->_private;
466 for(aIter = docpriv->
acls; aIter != NULL &&
target; aIter = aIter->next) {
473 }
else if (acl->xpath) {
477 max = numXpathResults(xpathObj);
478 for(lpc = 0; lpc < max; lpc++) {
481 if (!purge_xml_attributes(match) && (match ==
target)) {
482 crm_trace(
"ACLs deny user '%s' access to entire XML document",
488 crm_trace(
"ACLs deny user '%s' access to %s (%d %s)",
489 user, acl->xpath, max,
495 if (!purge_xml_attributes(
target)) {
496 crm_trace(
"ACLs deny user '%s' access to entire XML document", user);
501 g_list_free_full(docpriv->
acls, free_acl);
502 docpriv->
acls = NULL;
505 crm_trace(
"User '%s' without ACLs denied access to entire XML document",
531 implicitly_allowed(
const xmlNode *xml)
533 GString *
path = NULL;
535 for (xmlAttr *prop = xml->properties; prop != NULL; prop = prop->next) {
536 if (strcmp((
const char *) prop->name,
XML_ATTR_ID) != 0) {
545 g_string_free(
path, TRUE);
549 g_string_free(
path, TRUE);
553 #define display_id(xml) (ID(xml)? ID(xml) : "<unset>") 576 if (implicitly_allowed(xml)) {
577 crm_trace(
"Creation of <%s> scaffolding with id=\"%s\"" 578 " is implicitly allowed",
582 crm_trace(
"ACLs allow creation of <%s> with id=\"%s\"",
585 }
else if (check_top) {
586 crm_trace(
"ACLs disallow creation of <%s> with id=\"%s\"",
592 crm_notice(
"ACLs would disallow creation of %s<%s> with id=\"%s\" ",
593 ((xml == xmlDocGetRootElement(xml->doc))?
"root element " :
""),
598 for (xmlNode *cIter = pcmk__xml_first_child(xml); cIter != NULL; ) {
599 xmlNode *child = cIter;
600 cIter = pcmk__xml_next(cIter);
615 if (xml && xml->doc && xml->doc->_private){
646 if (xml && xml->doc && xml->doc->_private){
664 GString *xpath = NULL;
666 if (docpriv->
acls == NULL) {
675 qb_log_from_external_source(__func__, __FILE__,
676 "User '%s' without ACLs denied %s " 678 docpriv->
user, acl_to_text(mode),
679 (
const char *) xpath->str);
680 g_string_free(xpath, TRUE);
699 if (test_acl_mode(nodepriv->
flags, mode)) {
711 qb_log_from_external_source(__func__, __FILE__,
712 "%sACL denies user '%s' %s access " 714 (
parent != xml)?
"Parent ":
"",
715 docpriv->
user, acl_to_text(mode),
716 (
const char *) xpath->str);
717 g_string_free(xpath, TRUE);
731 qb_log_from_external_source(__func__, __FILE__,
732 "Default ACL denies user '%s' %s access to " 734 docpriv->
user, acl_to_text(mode),
735 (
const char *) xpath->str);
736 g_string_free(xpath, TRUE);
753 if (pcmk__str_empty(user)) {
754 crm_trace(
"ACLs not required because no user set");
758 crm_trace(
"ACLs not required for privileged user %s", user);
768 struct passwd *pwent = getpwuid(uid);
771 crm_perror(LOG_INFO,
"Cannot get user details for user ID %d", uid);
774 return strdup(pwent->pw_name);
797 const char *peer_user)
799 static const char *effective_user = NULL;
800 const char *requested_user = NULL;
801 const char *user = NULL;
803 if (effective_user == NULL) {
805 if (effective_user == NULL) {
806 effective_user = strdup(
"#unprivileged");
807 CRM_CHECK(effective_user != NULL,
return NULL);
808 crm_err(
"Unable to determine effective user, assuming unprivileged for ACLs");
813 if (requested_user == NULL) {
822 if (!pcmk__is_privileged(effective_user)) {
826 user = effective_user;
828 }
else if (peer_user == NULL && requested_user == NULL) {
832 user = effective_user;
834 }
else if (peer_user == NULL) {
836 user = requested_user;
838 }
else if (!pcmk__is_privileged(peer_user)) {
844 }
else if (requested_user == NULL) {
850 user = requested_user;
862 return requested_user;
#define CRM_CHECK(expr, failure_action)
void xml_acl_disable(xmlNode *xml)
#define crm_notice(fmt, args...)
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
#define pcmk__log_else(level, else_action)
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
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
#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