rc = TRUE if the request passes the ACL check */ rc = FALSE if the permission is denied */
| 129 | /* rc = TRUE if the request passes the ACL check */ |
| 130 | /* rc = FALSE if the permission is denied */ |
| 131 | gboolean |
| 132 | acl_check_diff(xmlNode * request, xmlNode * current_cib, xmlNode * result_cib, xmlNode * diff) |
| 133 | { |
| 134 | const char *user = NULL; |
| 135 | xmlNode *xml_acls = NULL; |
| 136 | GListPtr user_acl = NULL; |
| 137 | xmlNode *orig_diff = NULL; |
| 138 | xmlNode *diff_child = NULL; |
| 139 | int rc = FALSE; |
| 140 | |
| 141 | if (req_by_privileged(request)) { |
| 142 | return TRUE; |
| 143 | } |
| 144 | |
| 145 | if (diff == NULL) { |
| 146 | return TRUE; |
| 147 | } |
| 148 | |
| 149 | if (current_cib == NULL) { |
| 150 | return FALSE; |
| 151 | } |
| 152 | |
| 153 | xml_acls = get_object_root(XML_CIB_TAG_ACLS, current_cib); |
| 154 | if (xml_acls == NULL) { |
| 155 | crm_warn("Ordinary users cannot access the CIB without any defined ACLs: '%s'", user); |
| 156 | return FALSE; |
| 157 | } |
| 158 | |
| 159 | user = crm_element_value(request, F_CIB_USER); |
| 160 | unpack_user_acl(xml_acls, user, &user_acl); |
| 161 | |
| 162 | orig_diff = diff_xml_object_orig(current_cib, result_cib, FALSE, diff); |
| 163 | |
| 164 | for (diff_child = __xml_first_child(orig_diff); diff_child; diff_child = __xml_next(diff_child)) { |
| 165 | const char *tag = crm_element_name(diff_child); |
| 166 | GListPtr parsed_acl = NULL; |
| 167 | xmlNode *diff_cib = NULL; |
| 168 | |
| 169 | crm_debug("Preparing ACL checking on '%s'", tag); |
| 170 | |
| 171 | if (crm_str_eq(tag, XML_TAG_DIFF_REMOVED, TRUE)) { |
| 172 | crm_debug("Parsing any xpaths under the ACL according to the current CIB"); |
| 173 | parse_acl_xpath(current_cib, user_acl, &parsed_acl); |
| 174 | } else if (crm_str_eq(tag, XML_TAG_DIFF_ADDED, TRUE)) { |
| 175 | crm_debug("Parsing any xpaths under the ACL according to the result CIB"); |
| 176 | parse_acl_xpath(result_cib, user_acl, &parsed_acl); |
| 177 | } else { |
| 178 | continue; |
| 179 | } |
| 180 | |
| 181 | for (diff_cib = __xml_first_child(diff_child); diff_cib; diff_cib = __xml_next(diff_cib)) { |
| 182 | GHashTable *xml_perms = NULL; |
| 183 | |
| 184 | gen_xml_perms(diff_cib, parsed_acl, &xml_perms); |
| 185 | rc = acl_check_diff_xml(diff_cib, xml_perms); |
| 186 | g_hash_table_destroy(xml_perms); |
| 187 | |
| 188 | if (rc == FALSE) { |
no test coverage detected