Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a30fccf
Refactor: libcrmcommon: Use a switch statement in is_mode_allowed()
nrwahl2 Dec 26, 2025
cf815b1
Doc: libcrmcommon: Clarify that pcmk__element_xpath() returns non-NULL
nrwahl2 Dec 26, 2025
012636b
Refactor: libcrmcommon: Use convenience helpers in implicitly_allowed()
nrwahl2 Dec 26, 2025
6e872c6
Refactor: libcrmcommon: Walk up the tree in implicitly_allowed()
nrwahl2 Dec 26, 2025
680e7f2
Refactor: libcrmcommon, libpe_status: Drop strncmp() calls
nrwahl2 Dec 26, 2025
53df26a
Refactor: libcrmcommon: Drop a redundant check in pcmk__xa_remove()
nrwahl2 Dec 26, 2025
ec009a7
Refactor: libcrmcommon: Check force arg sooner in pcmk__xa_remove()
nrwahl2 Dec 26, 2025
4b68578
Refactor: libcrmcommon: Functionize cases of new_private_data()
nrwahl2 Dec 26, 2025
6a37ef2
Refactor: libcrmcommon: New pcmk__xe_foreach{,_const}_attr()
nrwahl2 Dec 27, 2025
9b07fef
Refactor: libcrmcommon: pcmk__xe_foreach_attr() in new_private_data()
nrwahl2 Dec 26, 2025
35e75c9
Refactor: libcrmcommon: Clear flags in reset_xml_private_data()
nrwahl2 Dec 27, 2025
b20629c
Refactor: libcrmcommon: pcmk__xe_foreach_attr() in free_private_data()
nrwahl2 Dec 27, 2025
cea7ac8
Refactor: libcrmcommon: Use a for-loop in xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
659c1a9
Refactor: libcrmcommon: Unindent else block in xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
2a99e79
Refactor: libcrmcommon: Unindent a bit more of xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
9d269d6
Refactor: libcrmcommon: pcmk__xe_foreach_attr() in xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
7ba8a6f
Refactor: libcrmcommon: Drop redundant check from mark_attr_diff()
nrwahl2 Dec 27, 2025
6c6e518
Refactor: libcrmcommon: Drop redundant args from mark_attr_*() functions
nrwahl2 Dec 27, 2025
ec1359a
Refactor: libcrmcommon: Use for loop in mark_created_attrs()
nrwahl2 Dec 27, 2025
a5f814f
Refactor: libcrmcommon: Unindent most of for loop in mark_created_attrs
nrwahl2 Dec 27, 2025
ccec087
Refactor: libcrmcommon: pcmk__xe_foreach_attr() for mark_created_attrs()
nrwahl2 Dec 27, 2025
336a189
Refactor: libcrmcommon: New mark_attr_created()
nrwahl2 Dec 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/crm/common/xml_element_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ extern "C" {

const char *pcmk__xe_add_last_written(xmlNode *xe);

bool pcmk__xe_foreach_attr(xmlNode *xml, bool (*fn)(xmlAttr *, void *),
void *user_data);
bool pcmk__xe_foreach_const_attr(const xmlNode *xml,
bool (*fn)(const xmlAttr *, void *),
void *user_data);

xmlNode *pcmk__xe_first_child(const xmlNode *parent, const char *node_name,
const char *attr_n, const char *attr_v);

Expand Down
2 changes: 1 addition & 1 deletion include/crm/pengine/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pe_base_name_eq(const pcmk_resource_t *rsc, const char *id)
// Number of characters in rsc->id before any clone suffix
size_t base_len = pe_base_name_end(rsc->id) - rsc->id + 1;

return (strlen(id) == base_len) && !strncmp(id, rsc->id, base_len);
return (strlen(id) == base_len) && g_str_has_prefix(rsc->id, id);
}
return false;
}
Expand Down
63 changes: 31 additions & 32 deletions lib/common/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,30 +764,28 @@ is_mode_allowed(uint32_t flags, enum pcmk__xml_flags mode)
return false;
}

if (pcmk__is_set(flags, mode)) {
// The access we requested is explicitly allowed
return true;
}

if ((mode == pcmk__xf_acl_read)
&& pcmk__is_set(flags, pcmk__xf_acl_write)) {
switch (mode) {
case pcmk__xf_acl_read:
// Write access provides read access
return pcmk__any_flags_set(flags,
pcmk__xf_acl_read|pcmk__xf_acl_write);

// Write access provides read access
return true;
}
case pcmk__xf_acl_write:
return pcmk__is_set(flags, pcmk__xf_acl_write);

if ((mode == pcmk__xf_acl_create)
&& pcmk__any_flags_set(flags, pcmk__xf_acl_write|pcmk__xf_created)) {
case pcmk__xf_acl_create:
/* Write access provides create access.
*
* @TODO Why does the \c pcmk__xf_created flag provide create
* access? This was introduced by commit e2ed85fe.
*/
return pcmk__any_flags_set(flags,
pcmk__xf_acl_write|pcmk__xf_created);

/* Write access provides create access.
*
* @TODO Why does the \c pcmk__xf_created flag provide create access?
* This was introduced by commit e2ed85fe.
*/
return true;
default:
// Invalid mode
return false;
}

return false;
}

/*!
Expand Down Expand Up @@ -951,28 +949,29 @@ xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml,
*
* \param[in] xml XML element to check
*
* \return true if XML element is implicitly allowed, false otherwise
* \return \c true if XML element is implicitly allowed, or \c false otherwise
*/
static bool
implicitly_allowed(const xmlNode *xml)
implicitly_allowed(xmlNode *xml)
{
GString *path = NULL;
for (xmlAttr *attr = pcmk__xe_first_attr(xml); attr != NULL;
attr = attr->next) {

for (xmlAttr *prop = xml->properties; prop != NULL; prop = prop->next) {
if (strcmp((const char *) prop->name, PCMK_XA_ID) != 0) {
if (attr_is_not_id(attr, NULL)) {
return false;
}
}

path = pcmk__element_xpath(xml);
pcmk__assert(path != NULL);

if (strstr((const char *) path->str, "/" PCMK_XE_ACLS "/") != NULL) {
g_string_free(path, TRUE);
return false;
/* Creation is not implicitly allowed for a descendant of PCMK_XE_ACLS, but
* it may be for PCMK_XE_ACLS itself. Start checking at xml->parent and walk
* up the tree.
*/
for (xml = xml->parent; xml != NULL; xml = xml->parent) {
if (pcmk__xe_is(xml, PCMK_XE_ACLS)) {
return false;
}
}

g_string_free(path, TRUE);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/common/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ match_before(const char *key, size_t position, const char **matches)
const size_t possible = position - match_len - 1;

if ((key[possible] == '_')
&& (strncmp(key + possible + 1, matches[i], match_len) == 0)) {
&& g_str_has_prefix(key + possible + 1, matches[i])) {

return possible;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/common/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ pcmk__xa_filterable(const char *name)
static bool
should_filter_for_digest(xmlAttrPtr a, void *user_data)
{
if (strncmp((const char *) a->name, CRM_META "_",
sizeof(CRM_META " ") - 1) == 0) {
if (g_str_has_prefix((const char *) a->name, CRM_META "_")) {
return true;
}

return pcmk__str_any_of((const char *) a->name,
PCMK_XA_ID,
PCMK_XA_CRM_FEATURE_SET,
Expand Down
5 changes: 3 additions & 2 deletions lib/common/ipc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,9 @@ pcmk__ipc_is_authentic_process_active(const char *name, uid_t refuid,
}

rc = pcmk_rc_ok;
if ((found_uid != refuid || found_gid != refgid)
&& strncmp(last_asked_name, name, sizeof(last_asked_name))) {
if (((found_uid != refuid) || (found_gid != refgid))
&& !pcmk__str_eq(name, last_asked_name, pcmk__str_none)) {

if ((found_uid == 0) && (refuid != 0)) {
pcmk__warn("Daemon (IPC %s) runs as root, whereas the expected "
"credentials are %lld:%lld, hazard of violating the "
Expand Down
Loading