Skip to content
Draft
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
b7ab6c5
Refactor: libcrmcommon: Use a switch statement in is_mode_allowed()
nrwahl2 Dec 26, 2025
7b72b09
Doc: libcrmcommon: Clarify that pcmk__element_xpath() returns non-NULL
nrwahl2 Dec 26, 2025
8bcdbf7
Refactor: libcrmcommon: Use convenience helpers in implicitly_allowed()
nrwahl2 Dec 26, 2025
2bfcd7f
Refactor: libcrmcommon: Walk up the tree in implicitly_allowed()
nrwahl2 Dec 26, 2025
9fa78e1
Refactor: libcrmcommon, libpe_status: Drop strncmp() calls
nrwahl2 Dec 26, 2025
8efa3d1
Refactor: libcrmcommon: Drop a redundant check in pcmk__xa_remove()
nrwahl2 Dec 26, 2025
82c66d8
Refactor: libcrmcommon: Check force arg sooner in pcmk__xa_remove()
nrwahl2 Dec 26, 2025
c0b44c2
Refactor: libcrmcommon: Functionize cases of new_private_data()
nrwahl2 Dec 26, 2025
a02321d
Refactor: libcrmcommon: New pcmk__xe_foreach{,_const}_attr()
nrwahl2 Dec 27, 2025
604008a
Refactor: libcrmcommon: pcmk__xe_foreach_attr() in new_private_data()
nrwahl2 Dec 26, 2025
d31a7f1
Refactor: libcrmcommon: Clear flags in reset_xml_private_data()
nrwahl2 Dec 27, 2025
bc31f24
Refactor: libcrmcommon: pcmk__xe_foreach_attr() in free_private_data()
nrwahl2 Dec 27, 2025
a936f4a
Refactor: libcrmcommon: Use a for-loop in xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
d5b2a56
Refactor: libcrmcommon: Unindent else block in xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
3767f3f
Refactor: libcrmcommon: Unindent a bit more of xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
32661fe
Refactor: libcrmcommon: pcmk__xe_foreach_attr() in xml_diff_old_attrs()
nrwahl2 Dec 27, 2025
4dc2dd1
Refactor: libcrmcommon: Drop redundant check from mark_attr_diff()
nrwahl2 Dec 27, 2025
d4205d9
Refactor: libcrmcommon: Drop redundant args from mark_attr_*() functions
nrwahl2 Dec 27, 2025
5d5d632
Refactor: libcrmcommon: Use for loop in mark_created_attrs()
nrwahl2 Dec 27, 2025
309bc02
Refactor: libcrmcommon: Unindent most of for loop in mark_created_attrs
nrwahl2 Dec 27, 2025
7a12db8
Refactor: libcrmcommon: pcmk__xe_foreach_attr() for mark_created_attrs()
nrwahl2 Dec 27, 2025
a6e1de5
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