From 6b52199a905e7aca46c19f4fabcd71006c2a6dbb Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 01:50:33 -0700 Subject: [PATCH 01/12] Refactor: libcrmcommon: Drop pcmk__new_unauth_client() key argument Both callers pass NULL. Signed-off-by: Reid Wahl --- daemons/based/based_remote.c | 2 +- daemons/execd/remoted_tls.c | 2 +- include/crm/common/ipc_internal.h | 2 +- lib/common/ipc_server.c | 11 +++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/daemons/based/based_remote.c b/daemons/based/based_remote.c index 7695ea8947b..cc57962d249 100644 --- a/daemons/based/based_remote.c +++ b/daemons/based/based_remote.c @@ -586,7 +586,7 @@ cib_remote_listen(void *user_data) return 0; } - new_client = pcmk__new_unauth_client(NULL); + new_client = pcmk__new_unauth_client(); new_client->remote = pcmk__assert_alloc(1, sizeof(pcmk__remote_t)); if (is_tls) { diff --git a/daemons/execd/remoted_tls.c b/daemons/execd/remoted_tls.c index af28efc657c..5892b2b7cf5 100644 --- a/daemons/execd/remoted_tls.c +++ b/daemons/execd/remoted_tls.c @@ -230,7 +230,7 @@ lrmd_remote_listen(void *data) return TRUE; } - new_client = pcmk__new_unauth_client(NULL); + new_client = pcmk__new_unauth_client(); new_client->remote = pcmk__assert_alloc(1, sizeof(pcmk__remote_t)); pcmk__set_client_flags(new_client, pcmk__client_tls); new_client->remote->tls_session = session; diff --git a/include/crm/common/ipc_internal.h b/include/crm/common/ipc_internal.h index b48a702993a..969c14d4a77 100644 --- a/include/crm/common/ipc_internal.h +++ b/include/crm/common/ipc_internal.h @@ -209,7 +209,7 @@ pcmk__client_t *pcmk__find_client_by_id(const char *id); const char *pcmk__client_name(const pcmk__client_t *c); const char *pcmk__client_type_str(uint64_t client_type); -pcmk__client_t *pcmk__new_unauth_client(void *key); +pcmk__client_t *pcmk__new_unauth_client(void); pcmk__client_t *pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid); void pcmk__free_client(pcmk__client_t *c); void pcmk__drop_all_clients(qb_ipcs_service_t *s); diff --git a/lib/common/ipc_server.c b/lib/common/ipc_server.c index ec92392918f..93a9cb36c4b 100644 --- a/lib/common/ipc_server.c +++ b/lib/common/ipc_server.c @@ -227,16 +227,15 @@ client_from_connection(qb_ipcs_connection_t *c, void *key, uid_t uid_client) } /*! - * \brief Allocate a new pcmk__client_t object and generate its ID - * - * \param[in] key What to use as connections hash table key (NULL to use ID) + * \internal + * \brief Create and initialize a \c pcmk__client_t object * - * \return Pointer to new pcmk__client_t (asserts on failure) + * \return Newly allocated client object (guaranteed not to be \c NULL) */ pcmk__client_t * -pcmk__new_unauth_client(void *key) +pcmk__new_unauth_client(void) { - return client_from_connection(NULL, key, 0); + return client_from_connection(NULL, NULL, 0); } pcmk__client_t * From bc07937671e88aca2b33b296b49b854c06c90ace Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 01:56:56 -0700 Subject: [PATCH 02/12] Refactor: libcrmcommon: Drop client_from_connection() key argument Both callers pass NULL. Also do light cleanup. Signed-off-by: Reid Wahl --- lib/common/ipc_server.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/common/ipc_server.c b/lib/common/ipc_server.c index 93a9cb36c4b..4c4c16d9cd0 100644 --- a/lib/common/ipc_server.c +++ b/lib/common/ipc_server.c @@ -183,46 +183,38 @@ pcmk__drop_all_clients(qb_ipcs_service_t *service) * \brief Allocate a new pcmk__client_t object based on an IPC connection * * \param[in] c IPC connection (NULL to allocate generic client) - * \param[in] key Connection table key (NULL to use sane default) * \param[in] uid_client UID corresponding to c (ignored if c is NULL) * * \return Pointer to new pcmk__client_t (guaranteed not to be \c NULL) */ static pcmk__client_t * -client_from_connection(qb_ipcs_connection_t *c, void *key, uid_t uid_client) +client_from_connection(qb_ipcs_connection_t *c, uid_t uid_client) { pcmk__client_t *client = pcmk__assert_alloc(1, sizeof(pcmk__client_t)); + client->id = pcmk__generate_uuid(); + if (c != NULL) { client->user = pcmk__uid2username(uid_client); + if (client->user == NULL) { client->user = pcmk__str_copy("#unprivileged"); pcmk__err("Unable to enforce ACLs for user ID %d, assuming " - "unprivileged", - uid_client); + "unprivileged", uid_client); } client->ipcs = c; pcmk__set_client_flags(client, pcmk__client_ipc); client->pid = pcmk__client_pid(c); - - if (key == NULL) { - key = c; - } - } - - client->id = pcmk__generate_uuid(); - - if (key == NULL) { - key = client->id; } if (client_connections == NULL) { - pcmk__trace("Creating IPC client table"); client_connections = g_hash_table_new(g_direct_hash, g_direct_equal); } - g_hash_table_insert(client_connections, key, client); + g_hash_table_insert(client_connections, + ((c != NULL)? (void *) c : (void *) client->id), + client); return client; } @@ -235,7 +227,7 @@ client_from_connection(qb_ipcs_connection_t *c, void *key, uid_t uid_client) pcmk__client_t * pcmk__new_unauth_client(void) { - return client_from_connection(NULL, NULL, 0); + return client_from_connection(NULL, 0); } pcmk__client_t * @@ -266,7 +258,7 @@ pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client, gid_t gid_client) } /* TODO: Do our own auth checking, return NULL if unauthorized */ - client = client_from_connection(c, NULL, uid_client); + client = client_from_connection(c, uid_client); if ((uid_client == 0) || (uid_client == uid_cluster)) { /* Remember when a connection came from root or hacluster */ From d3c5d18aec40730f36eede9d09b819c3dbe88f44 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 02:07:40 -0700 Subject: [PATCH 03/12] Refactor: libcrmcommon: Drop pcmk__new_client() gid_client argument It has been unused except for logging since 5d71e650 in 2016. Signed-off-by: Reid Wahl --- daemons/attrd/attrd_ipc.c | 4 ++-- daemons/based/based_ipc.c | 4 ++-- daemons/controld/controld_control.c | 2 +- daemons/execd/execd_ipc.c | 4 ++-- daemons/execd/remoted_proxy.c | 2 +- daemons/fenced/fenced_ipc.c | 4 ++-- daemons/pacemakerd/pcmkd_ipc.c | 4 ++-- daemons/schedulerd/schedulerd_ipc.c | 4 ++-- include/crm/common/ipc_internal.h | 2 +- lib/common/ipc_server.c | 6 +++--- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/daemons/attrd/attrd_ipc.c b/daemons/attrd/attrd_ipc.c index 3b0113ccac1..73e10b5b090 100644 --- a/daemons/attrd/attrd_ipc.c +++ b/daemons/attrd/attrd_ipc.c @@ -484,7 +484,7 @@ attrd_client_update(pcmk__request_t *request) * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id + * \param[in] gid Ignored * * \return pcmk_ok on success, -errno otherwise */ @@ -498,7 +498,7 @@ attrd_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) return -ECONNREFUSED; } - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return pcmk_ok; diff --git a/daemons/based/based_ipc.c b/daemons/based/based_ipc.c index 9e32dfdbd5f..ca7cb0d53b0 100644 --- a/daemons/based/based_ipc.c +++ b/daemons/based/based_ipc.c @@ -37,7 +37,7 @@ static qb_ipcs_service_t *ipcs_rw = NULL; * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id + * \param[in] gid Ignored * * \return 0 on success, \c -errno otherwise */ @@ -51,7 +51,7 @@ based_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) } pcmk__trace("New client connection %p", c); - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return 0; diff --git a/daemons/controld/controld_control.c b/daemons/controld/controld_control.c index 0f916edf63b..21c81d50957 100644 --- a/daemons/controld/controld_control.c +++ b/daemons/controld/controld_control.c @@ -305,7 +305,7 @@ static int32_t accept_controller_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { pcmk__trace("Accepting new IPC client connection"); - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return 0; diff --git a/daemons/execd/execd_ipc.c b/daemons/execd/execd_ipc.c index c8821f51c9e..65f519e7297 100644 --- a/daemons/execd/execd_ipc.c +++ b/daemons/execd/execd_ipc.c @@ -33,7 +33,7 @@ static qb_ipcs_service_t *ipcs = NULL; * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id + * \param[in] gid Ignored * * \return 0 on success, -errno otherwise */ @@ -41,7 +41,7 @@ static int32_t execd_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { pcmk__trace("New client connection %p", c); - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return 0; diff --git a/daemons/execd/remoted_proxy.c b/daemons/execd/remoted_proxy.c index bc3c9a98838..bf0c4e3bb8c 100644 --- a/daemons/execd/remoted_proxy.c +++ b/daemons/execd/remoted_proxy.c @@ -91,7 +91,7 @@ ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid, const char *ipc_ /* This new client is a local IPC client on a Pacemaker Remote controlled * node, needing to access cluster node IPC services. */ - client = pcmk__new_client(c, uid, gid); + client = pcmk__new_client(c, uid); if (client == NULL) { return -ENOMEM; } diff --git a/daemons/fenced/fenced_ipc.c b/daemons/fenced/fenced_ipc.c index 34be2dd2b45..233bbd2509e 100644 --- a/daemons/fenced/fenced_ipc.c +++ b/daemons/fenced/fenced_ipc.c @@ -57,7 +57,7 @@ handle_ipc_reply(pcmk__client_t *client, xmlNode *request) * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id + * \param[in] gid Ignored * * \return 0 on success, -errno otherwise */ @@ -71,7 +71,7 @@ fenced_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) return -ECONNREFUSED; } - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return 0; diff --git a/daemons/pacemakerd/pcmkd_ipc.c b/daemons/pacemakerd/pcmkd_ipc.c index 41d823261c9..ed1f378abce 100644 --- a/daemons/pacemakerd/pcmkd_ipc.c +++ b/daemons/pacemakerd/pcmkd_ipc.c @@ -32,7 +32,7 @@ static qb_ipcs_service_t *ipcs = NULL; * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id + * \param[in] gid Ignored * * \return 0 on success, -errno otherwise */ @@ -40,7 +40,7 @@ static int32_t pacemakerd_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { pcmk__trace("New client connection %p", c); - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return 0; diff --git a/daemons/schedulerd/schedulerd_ipc.c b/daemons/schedulerd/schedulerd_ipc.c index 102f4049329..72ee12bbd0e 100644 --- a/daemons/schedulerd/schedulerd_ipc.c +++ b/daemons/schedulerd/schedulerd_ipc.c @@ -31,7 +31,7 @@ static qb_ipcs_service_t *ipcs = NULL; * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id + * \param[in] gid Ignored * * \return 0 on success, -errno otherwise */ @@ -39,7 +39,7 @@ static int32_t schedulerd_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { pcmk__trace("New client connection %p", c); - if (pcmk__new_client(c, uid, gid) == NULL) { + if (pcmk__new_client(c, uid) == NULL) { return -ENOMEM; } return 0; diff --git a/include/crm/common/ipc_internal.h b/include/crm/common/ipc_internal.h index 969c14d4a77..37323e1d410 100644 --- a/include/crm/common/ipc_internal.h +++ b/include/crm/common/ipc_internal.h @@ -210,7 +210,7 @@ const char *pcmk__client_name(const pcmk__client_t *c); const char *pcmk__client_type_str(uint64_t client_type); pcmk__client_t *pcmk__new_unauth_client(void); -pcmk__client_t *pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid); +pcmk__client_t *pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid); void pcmk__free_client(pcmk__client_t *c); void pcmk__drop_all_clients(qb_ipcs_service_t *s); void pcmk__set_client_queue_max(pcmk__client_t *client, const char *qmax); diff --git a/lib/common/ipc_server.c b/lib/common/ipc_server.c index 4c4c16d9cd0..de5983f9f10 100644 --- a/lib/common/ipc_server.c +++ b/lib/common/ipc_server.c @@ -231,7 +231,7 @@ pcmk__new_unauth_client(void) } pcmk__client_t * -pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client, gid_t gid_client) +pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client) { gid_t uid_cluster = 0; gid_t gid_cluster = 0; @@ -265,8 +265,8 @@ pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client, gid_t gid_client) pcmk__set_client_flags(client, pcmk__client_privileged); } - pcmk__debug("New IPC client %s for PID %u with uid %d and gid %d", - client->id, client->pid, uid_client, gid_client); + pcmk__debug("New IPC client %s for PID %u with uid %d", client->id, + client->pid, uid_client); return client; } From a602843093688f56ff103a480cca890704696a7b Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 02:10:18 -0700 Subject: [PATCH 04/12] Refactor: remoted: Drop ipc_proxy_accept() gid argument It's used only for logging. Signed-off-by: Reid Wahl --- daemons/execd/remoted_proxy.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/daemons/execd/remoted_proxy.c b/daemons/execd/remoted_proxy.c index bf0c4e3bb8c..149d4a86a34 100644 --- a/daemons/execd/remoted_proxy.c +++ b/daemons/execd/remoted_proxy.c @@ -69,22 +69,20 @@ ipc_proxy_get_provider(void) * * \param[in,out] c New connection * \param[in] uid Client user id - * \param[in] gid Client group id * \param[in] ipc_channel Name of IPC server to proxy * * \return 0 on success, -errno on error */ static int32_t -ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid, const char *ipc_channel) +ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, const char *ipc_channel) { pcmk__client_t *client = NULL; pcmk__client_t *ipc_proxy = ipc_proxy_get_provider(); xmlNode *msg = NULL; if (ipc_proxy == NULL) { - pcmk__warn("Cannot proxy IPC connection from uid %d gid %d to %s " - "because not connected to cluster", - uid, gid, ipc_channel); + pcmk__warn("Cannot proxy IPC connection from uid %d to %s because not " + "connected to cluster", uid, ipc_channel); return -EREMOTEIO; } @@ -115,28 +113,27 @@ ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid, const char *ipc_ pcmk__xe_set(msg, PCMK__XA_LRMD_IPC_SESSION, client->id); lrmd_server_send_notify(ipc_proxy, msg); pcmk__xml_free(msg); - pcmk__debug("Accepted IPC proxy connection (session ID %s) from uid %d " - "gid %d on channel %s", - client->id, uid, gid, ipc_channel); + pcmk__debug("Accepted IPC proxy connection (session ID %s) from uid %d on " + "channel %s", client->id, uid, ipc_channel); return 0; } static int32_t crmd_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { - return ipc_proxy_accept(c, uid, gid, CRM_SYSTEM_CRMD); + return ipc_proxy_accept(c, uid, CRM_SYSTEM_CRMD); } static int32_t attrd_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { - return ipc_proxy_accept(c, uid, gid, PCMK__VALUE_ATTRD); + return ipc_proxy_accept(c, uid, PCMK__VALUE_ATTRD); } static int32_t fencer_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { - return ipc_proxy_accept(c, uid, gid, "stonith-ng"); + return ipc_proxy_accept(c, uid, "stonith-ng"); } static int32_t @@ -148,13 +145,13 @@ pacemakerd_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) static int32_t cib_proxy_accept_rw(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { - return ipc_proxy_accept(c, uid, gid, PCMK__SERVER_BASED_RW); + return ipc_proxy_accept(c, uid, PCMK__SERVER_BASED_RW); } static int32_t cib_proxy_accept_ro(qb_ipcs_connection_t *c, uid_t uid, gid_t gid) { - return ipc_proxy_accept(c, uid, gid, PCMK__SERVER_BASED_RO); + return ipc_proxy_accept(c, uid, PCMK__SERVER_BASED_RO); } int From d746ccb35f548edb5df4854b451df69acf89dfe0 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 02:12:33 -0700 Subject: [PATCH 05/12] Low: libcrmcommon: Use uid_t for uid_cluster in pcmk__new_client() This bug was introduced by commit ae780515 in 2017. Signed-off-by: Reid Wahl --- lib/common/ipc_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/ipc_server.c b/lib/common/ipc_server.c index de5983f9f10..45c7a48be0a 100644 --- a/lib/common/ipc_server.c +++ b/lib/common/ipc_server.c @@ -233,7 +233,7 @@ pcmk__new_unauth_client(void) pcmk__client_t * pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client) { - gid_t uid_cluster = 0; + uid_t uid_cluster = 0; gid_t gid_cluster = 0; pcmk__client_t *client = NULL; From 1466db206360d79c9f292f5fade1e255546ef10e Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 02:16:52 -0700 Subject: [PATCH 06/12] Log: execd, libcrmcommon: Cast correctly for some pid_t and uid_t values Signed-off-by: Reid Wahl --- daemons/execd/remoted_proxy.c | 12 ++++++------ lib/common/ipc_server.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/daemons/execd/remoted_proxy.c b/daemons/execd/remoted_proxy.c index 149d4a86a34..b659133baff 100644 --- a/daemons/execd/remoted_proxy.c +++ b/daemons/execd/remoted_proxy.c @@ -81,8 +81,8 @@ ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, const char *ipc_channel) xmlNode *msg = NULL; if (ipc_proxy == NULL) { - pcmk__warn("Cannot proxy IPC connection from uid %d to %s because not " - "connected to cluster", uid, ipc_channel); + pcmk__warn("Cannot proxy IPC connection from uid %lld to %s because " + "not connected to cluster", (long long) uid, ipc_channel); return -EREMOTEIO; } @@ -97,8 +97,8 @@ ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, const char *ipc_channel) /* This ipc client is bound to a single ipc provider. If the * provider goes away, this client is disconnected */ client->userdata = pcmk__str_copy(ipc_proxy->id); - client->name = pcmk__assert_asprintf("proxy-%s-%d-%.8s", ipc_channel, - client->pid, client->id); + client->name = pcmk__assert_asprintf("proxy-%s-%lld-%.8s", ipc_channel, + (long long) client->pid, client->id); /* Allow remote executor to distinguish between proxied local clients and * actual executor API clients @@ -113,8 +113,8 @@ ipc_proxy_accept(qb_ipcs_connection_t *c, uid_t uid, const char *ipc_channel) pcmk__xe_set(msg, PCMK__XA_LRMD_IPC_SESSION, client->id); lrmd_server_send_notify(ipc_proxy, msg); pcmk__xml_free(msg); - pcmk__debug("Accepted IPC proxy connection (session ID %s) from uid %d on " - "channel %s", client->id, uid, ipc_channel); + pcmk__debug("Accepted IPC proxy connection (session ID %s) from uid %lld " + "on channel %s", client->id, (long long) uid, ipc_channel); return 0; } diff --git a/lib/common/ipc_server.c b/lib/common/ipc_server.c index 45c7a48be0a..ec2b98281ea 100644 --- a/lib/common/ipc_server.c +++ b/lib/common/ipc_server.c @@ -251,8 +251,8 @@ pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client) } if (uid_client != 0) { - pcmk__trace("Giving group %u access to new IPC connection", - gid_cluster); + pcmk__trace("Giving group %lld access to new IPC connection", + (long long) gid_cluster); /* Passing -1 to chown(2) means don't change */ qb_ipcs_connection_auth_set(c, -1, gid_cluster, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); } @@ -265,8 +265,8 @@ pcmk__new_client(qb_ipcs_connection_t *c, uid_t uid_client) pcmk__set_client_flags(client, pcmk__client_privileged); } - pcmk__debug("New IPC client %s for PID %u with uid %d", client->id, - client->pid, uid_client); + pcmk__debug("New IPC client %s for PID %lld with uid %lld", client->id, + (long long) client->pid, (long long) uid_client); return client; } From 88e88ab37f5f27534b66620bb0fa76cbf2356e65 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 11:05:12 -0700 Subject: [PATCH 07/12] Refactor: libcrmcommon: Drop is_ipc_provider_expected() forward decl Signed-off-by: Reid Wahl --- lib/common/ipc_client.c | 239 ++++++++++++++++++++-------------------- 1 file changed, 118 insertions(+), 121 deletions(-) diff --git a/lib/common/ipc_client.c b/lib/common/ipc_client.c index 530bd69ac8a..a2b68c6d51b 100644 --- a/lib/common/ipc_client.c +++ b/lib/common/ipc_client.c @@ -40,10 +40,6 @@ #include "crmcommon_private.h" -static int is_ipc_provider_expected(qb_ipcc_connection_t *qb_ipc, int sock, - uid_t refuid, gid_t refgid, pid_t *gotpid, - uid_t *gotuid, gid_t *gotgid); - /*! * \brief Create a new object for using Pacemaker daemon IPC * @@ -946,6 +942,124 @@ crm_ipc_new(const char *name, size_t max_size) return client; } +/*! + * \internal + * \brief Ensure an IPC provider has expected user or group + * + * \param[in] qb_ipc libqb client connection if available + * \param[in] sock Connected Unix socket for IPC + * \param[in] refuid Expected user ID + * \param[in] refgid Expected group ID + * \param[out] gotpid If not NULL, where to store provider's actual process ID + * (or 1 on platforms where ID is not available) + * \param[out] gotuid If not NULL, where to store provider's actual user ID + * \param[out] gotgid If not NULL, where to store provider's actual group ID + * + * \return Standard Pacemaker return code + * \note An actual user ID of 0 (root) will always be considered authorized, + * regardless of the expected values provided. The caller can use the + * output arguments to be stricter than this function. + */ +static int +is_ipc_provider_expected(qb_ipcc_connection_t *qb_ipc, int sock, + uid_t refuid, gid_t refgid, + pid_t *gotpid, uid_t *gotuid, gid_t *gotgid) +{ + int rc = EOPNOTSUPP; + pid_t found_pid = 0; + uid_t found_uid = 0; + gid_t found_gid = 0; + +#ifdef HAVE_QB_IPCC_AUTH_GET + if (qb_ipc != NULL) { + rc = qb_ipcc_auth_get(qb_ipc, &found_pid, &found_uid, &found_gid); + rc = -rc; // libqb returns 0 or -errno + if (rc == pcmk_rc_ok) { + goto found; + } + } +#endif + +#ifdef HAVE_UCRED + { + struct ucred ucred; + socklen_t ucred_len = sizeof(ucred); + + if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &ucred, &ucred_len) < 0) { + rc = errno; + } else if (ucred_len != sizeof(ucred)) { + rc = EOPNOTSUPP; + } else { + found_pid = ucred.pid; + found_uid = ucred.uid; + found_gid = ucred.gid; + goto found; + } + } +#endif + +#ifdef HAVE_SOCKPEERCRED + { + struct sockpeercred sockpeercred; + socklen_t sockpeercred_len = sizeof(sockpeercred); + + if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, + &sockpeercred, &sockpeercred_len) < 0) { + rc = errno; + } else if (sockpeercred_len != sizeof(sockpeercred)) { + rc = EOPNOTSUPP; + } else { + found_pid = sockpeercred.pid; + found_uid = sockpeercred.uid; + found_gid = sockpeercred.gid; + goto found; + } + } +#endif + +#ifdef HAVE_GETPEEREID // For example, FreeBSD + if (getpeereid(sock, &found_uid, &found_gid) < 0) { + rc = errno; + } else { + found_pid = PCMK__SPECIAL_PID; + goto found; + } +#endif + +#ifdef HAVE_GETPEERUCRED + { + ucred_t *ucred = NULL; + + if (getpeerucred(sock, &ucred) < 0) { + rc = errno; + } else { + found_pid = ucred_getpid(ucred); + found_uid = ucred_geteuid(ucred); + found_gid = ucred_getegid(ucred); + ucred_free(ucred); + goto found; + } + } +#endif + + return rc; // If we get here, nothing succeeded + +found: + if (gotpid != NULL) { + *gotpid = found_pid; + } + if (gotuid != NULL) { + *gotuid = found_uid; + } + if (gotgid != NULL) { + *gotgid = found_gid; + } + if ((found_uid != 0) && (found_uid != refuid) && (found_gid != refgid)) { + return pcmk_rc_ipc_unauthorized; + } + return pcmk_rc_ok; +} + /*! * \internal * \brief Connect a generic (not daemon-specific) IPC object @@ -1586,123 +1700,6 @@ crm_ipc_send(crm_ipc_t *client, const xmlNode *message, return rc; } -/*! - * \brief Ensure an IPC provider has expected user or group - * - * \param[in] qb_ipc libqb client connection if available - * \param[in] sock Connected Unix socket for IPC - * \param[in] refuid Expected user ID - * \param[in] refgid Expected group ID - * \param[out] gotpid If not NULL, where to store provider's actual process ID - * (or 1 on platforms where ID is not available) - * \param[out] gotuid If not NULL, where to store provider's actual user ID - * \param[out] gotgid If not NULL, where to store provider's actual group ID - * - * \return Standard Pacemaker return code - * \note An actual user ID of 0 (root) will always be considered authorized, - * regardless of the expected values provided. The caller can use the - * output arguments to be stricter than this function. - */ -static int -is_ipc_provider_expected(qb_ipcc_connection_t *qb_ipc, int sock, - uid_t refuid, gid_t refgid, - pid_t *gotpid, uid_t *gotuid, gid_t *gotgid) -{ - int rc = EOPNOTSUPP; - pid_t found_pid = 0; - uid_t found_uid = 0; - gid_t found_gid = 0; - -#ifdef HAVE_QB_IPCC_AUTH_GET - if (qb_ipc != NULL) { - rc = qb_ipcc_auth_get(qb_ipc, &found_pid, &found_uid, &found_gid); - rc = -rc; // libqb returns 0 or -errno - if (rc == pcmk_rc_ok) { - goto found; - } - } -#endif - -#ifdef HAVE_UCRED - { - struct ucred ucred; - socklen_t ucred_len = sizeof(ucred); - - if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &ucred, &ucred_len) < 0) { - rc = errno; - } else if (ucred_len != sizeof(ucred)) { - rc = EOPNOTSUPP; - } else { - found_pid = ucred.pid; - found_uid = ucred.uid; - found_gid = ucred.gid; - goto found; - } - } -#endif - -#ifdef HAVE_SOCKPEERCRED - { - struct sockpeercred sockpeercred; - socklen_t sockpeercred_len = sizeof(sockpeercred); - - if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, - &sockpeercred, &sockpeercred_len) < 0) { - rc = errno; - } else if (sockpeercred_len != sizeof(sockpeercred)) { - rc = EOPNOTSUPP; - } else { - found_pid = sockpeercred.pid; - found_uid = sockpeercred.uid; - found_gid = sockpeercred.gid; - goto found; - } - } -#endif - -#ifdef HAVE_GETPEEREID // For example, FreeBSD - if (getpeereid(sock, &found_uid, &found_gid) < 0) { - rc = errno; - } else { - found_pid = PCMK__SPECIAL_PID; - goto found; - } -#endif - -#ifdef HAVE_GETPEERUCRED - { - ucred_t *ucred = NULL; - - if (getpeerucred(sock, &ucred) < 0) { - rc = errno; - } else { - found_pid = ucred_getpid(ucred); - found_uid = ucred_geteuid(ucred); - found_gid = ucred_getegid(ucred); - ucred_free(ucred); - goto found; - } - } -#endif - - return rc; // If we get here, nothing succeeded - -found: - if (gotpid != NULL) { - *gotpid = found_pid; - } - if (gotuid != NULL) { - *gotuid = found_uid; - } - if (gotgid != NULL) { - *gotgid = found_gid; - } - if ((found_uid != 0) && (found_uid != refuid) && (found_gid != refgid)) { - return pcmk_rc_ipc_unauthorized; - } - return pcmk_rc_ok; -} - int crm_ipc_is_authentic_process(int sock, uid_t refuid, gid_t refgid, pid_t *gotpid, uid_t *gotuid, gid_t *gotgid) From a47b4f631f27f97ce15ad2d260cd5057f2808fac Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 11:27:43 -0700 Subject: [PATCH 08/12] Refactor: pacemakerd: Rename cluster_connect_cfg() and return bool Also initialize variables. Signed-off-by: Reid Wahl --- daemons/pacemakerd/pacemakerd.c | 2 +- daemons/pacemakerd/pcmkd_corosync.c | 20 +++++++++++--------- daemons/pacemakerd/pcmkd_corosync.h | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c index 932a2721b17..d78536d8e89 100644 --- a/daemons/pacemakerd/pacemakerd.c +++ b/daemons/pacemakerd/pacemakerd.c @@ -436,7 +436,7 @@ main(int argc, char **argv) #if SUPPORT_COROSYNC /* Allows us to block shutdown */ - if (!cluster_connect_cfg()) { + if (!pacemakerd_corosync_connect_cfg()) { exit_code = CRM_EX_PROTOCOL; goto done; } diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c index e085789d0cc..f8238cef76c 100644 --- a/daemons/pacemakerd/pcmkd_corosync.c +++ b/daemons/pacemakerd/pcmkd_corosync.c @@ -95,7 +95,7 @@ close_cfg(void) static gboolean cluster_reconnect_cb(void *data) { - if (cluster_connect_cfg()) { + if (pacemakerd_corosync_connect_cfg()) { g_clear_pointer(&reconnect_timer, mainloop_timer_del); pcmk__notice("Cluster reconnect succeeded"); pacemakerd_read_config(); @@ -146,15 +146,17 @@ cluster_disconnect_cfg(void) } \ } while(counter < max) -gboolean -cluster_connect_cfg(void) +bool +pacemakerd_corosync_connect_cfg(void) { - cs_error_t rc; - int fd = -1, retries = 0, rv; + cs_error_t rc = CS_OK; + int fd = -1; + int retries = 0; + int rv = 0; uid_t found_uid = 0; gid_t found_gid = 0; pid_t found_pid = 0; - uint32_t nodeid; + uint32_t nodeid = 0; static struct mainloop_fd_callbacks cfg_fd_callbacks = { .dispatch = pcmk_cfg_dispatch, @@ -166,7 +168,7 @@ cluster_connect_cfg(void) if (rc != CS_OK) { pcmk__crit("Could not connect to Corosync CFG: %s " QB_XS " rc=%d", pcmk_rc_str(pcmk__corosync2rc(rc)), rc); - return FALSE; + return false; } rc = corosync_cfg_fd_get(cfg_handle, &fd); @@ -211,11 +213,11 @@ cluster_connect_cfg(void) #endif mainloop_add_fd("corosync-cfg", G_PRIORITY_DEFAULT, fd, &cfg_handle, &cfg_fd_callbacks); - return TRUE; + return true; bail: corosync_cfg_finalize(cfg_handle); - return FALSE; + return false; } void diff --git a/daemons/pacemakerd/pcmkd_corosync.h b/daemons/pacemakerd/pcmkd_corosync.h index bad71022ab6..46fba132c5e 100644 --- a/daemons/pacemakerd/pcmkd_corosync.h +++ b/daemons/pacemakerd/pcmkd_corosync.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2025 the Pacemaker project contributors + * Copyright 2010-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -11,7 +11,7 @@ #include -gboolean cluster_connect_cfg(void); +bool pacemakerd_corosync_connect_cfg(void); void cluster_disconnect_cfg(void); gboolean pacemakerd_read_config(void); bool pcmkd_corosync_connected(void); From 8d2eccc1a2f9a5990bcf74887a0cb26a88de27f2 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 11:33:00 -0700 Subject: [PATCH 09/12] Refactor: libcrmcommon: Use pcmk_rc_ok in crm_ipc_is_authentic_process() Signed-off-by: Reid Wahl --- lib/common/ipc_client.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/common/ipc_client.c b/lib/common/ipc_client.c index a2b68c6d51b..caeee77353e 100644 --- a/lib/common/ipc_client.c +++ b/lib/common/ipc_client.c @@ -1704,19 +1704,20 @@ int crm_ipc_is_authentic_process(int sock, uid_t refuid, gid_t refgid, pid_t *gotpid, uid_t *gotuid, gid_t *gotgid) { - int ret = is_ipc_provider_expected(NULL, sock, refuid, refgid, - gotpid, gotuid, gotgid); + int rc = is_ipc_provider_expected(NULL, sock, refuid, refgid, gotpid, + gotuid, gotgid); - /* The old function had some very odd return codes*/ - if (ret == 0) { - return 1; - } + // Strange return codes for public API backward compatibility + switch (rc) { + case pcmk_rc_ok: + return 1; - if (ret == pcmk_rc_ipc_unauthorized) { - return 0; - } + case pcmk_rc_ipc_unauthorized: + return 0; - return pcmk_rc2legacy(ret); + default: + return pcmk_rc2legacy(rc); + } } int From 5bb3fcf91f5d464b866fbf8f0a19a3ead7837732 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 11:41:40 -0700 Subject: [PATCH 10/12] Refactor: pacemakerd: Rename pacemakerd_read_config() and return bool Also initialize variables. Signed-off-by: Reid Wahl --- daemons/pacemakerd/pacemakerd.c | 2 +- daemons/pacemakerd/pcmkd_corosync.c | 22 +++++++++++----------- daemons/pacemakerd/pcmkd_corosync.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c index d78536d8e89..93a3be15d2c 100644 --- a/daemons/pacemakerd/pacemakerd.c +++ b/daemons/pacemakerd/pacemakerd.c @@ -411,7 +411,7 @@ main(int argc, char **argv) } #if SUPPORT_COROSYNC - if (pacemakerd_read_config() == FALSE) { + if (!pacemakerd_corosync_read_config()) { crm_exit(CRM_EX_UNAVAILABLE); } #endif diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c index f8238cef76c..d8e37759cf8 100644 --- a/daemons/pacemakerd/pcmkd_corosync.c +++ b/daemons/pacemakerd/pcmkd_corosync.c @@ -98,7 +98,7 @@ cluster_reconnect_cb(void *data) if (pacemakerd_corosync_connect_cfg()) { g_clear_pointer(&reconnect_timer, mainloop_timer_del); pcmk__notice("Cluster reconnect succeeded"); - pacemakerd_read_config(); + pacemakerd_corosync_read_config(); restart_cluster_subdaemons(); return G_SOURCE_REMOVE; } else { @@ -277,18 +277,18 @@ get_config_opt(uint64_t unused, cmap_handle_t object_handle, const char *key, ch return rc; } -gboolean -pacemakerd_read_config(void) +bool +pacemakerd_corosync_read_config(void) { cs_error_t rc = CS_OK; int retries = 0; - cmap_handle_t local_handle; + cmap_handle_t local_handle = 0; uint64_t config = 0; int fd = -1; uid_t found_uid = 0; gid_t found_gid = 0; pid_t found_pid = 0; - int rv; + int rv = 0; enum pcmk_cluster_layer cluster_layer = pcmk_cluster_layer_unknown; const char *cluster_layer_s = NULL; @@ -311,7 +311,7 @@ pacemakerd_read_config(void) if (rc != CS_OK) { pcmk__crit("Could not connect to Corosync CMAP: %s " QB_XS " rc=%d", pcmk_rc_str(pcmk__corosync2rc(rc)), rc); - return FALSE; + return false; } rc = cmap_fd_get(local_handle, &fd); @@ -319,7 +319,7 @@ pacemakerd_read_config(void) pcmk__crit("Could not get Corosync CMAP descriptor: %s " QB_XS " rc=%d", pcmk_rc_str(pcmk__corosync2rc(rc)), rc); cmap_finalize(local_handle); - return FALSE; + return false; } /* CMAP provider run as root (in given user namespace, anyway)? */ @@ -330,12 +330,12 @@ pacemakerd_read_config(void) (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); cmap_finalize(local_handle); - return FALSE; + return false; } else if (rv < 0) { pcmk__crit("Could not authenticate Corosync CMAP provider: %s " QB_XS " rc=%d", strerror(-rv), -rv); cmap_finalize(local_handle); - return FALSE; + return false; } cluster_layer = pcmk_get_cluster_layer(); @@ -345,7 +345,7 @@ pacemakerd_read_config(void) pcmk__crit("Expected Corosync cluster layer but detected %s " QB_XS " cluster_layer=%d", cluster_layer_s, cluster_layer); - return FALSE; + return false; } pcmk__info("Reading configuration for %s cluster layer", cluster_layer_s); @@ -393,5 +393,5 @@ pacemakerd_read_config(void) } cmap_finalize(local_handle); - return TRUE; + return true; } diff --git a/daemons/pacemakerd/pcmkd_corosync.h b/daemons/pacemakerd/pcmkd_corosync.h index 46fba132c5e..fb484308e93 100644 --- a/daemons/pacemakerd/pcmkd_corosync.h +++ b/daemons/pacemakerd/pcmkd_corosync.h @@ -13,6 +13,6 @@ bool pacemakerd_corosync_connect_cfg(void); void cluster_disconnect_cfg(void); -gboolean pacemakerd_read_config(void); +bool pacemakerd_corosync_read_config(void); bool pcmkd_corosync_connected(void); void pcmkd_shutdown_corosync(void); From 934585b13a64aa038a9c69dc9e19a925de195a8a Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 11:44:18 -0700 Subject: [PATCH 11/12] Refactor: various: Clean up crm_ipc_is_authentic_process() calls Signed-off-by: Reid Wahl --- daemons/pacemakerd/pcmkd_corosync.c | 24 +++++++---- lib/cluster/corosync.c | 66 +++++++++++++++++++---------- lib/cluster/cpg.c | 22 ++++++---- 3 files changed, 73 insertions(+), 39 deletions(-) diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c index d8e37759cf8..2bef6898040 100644 --- a/daemons/pacemakerd/pcmkd_corosync.c +++ b/daemons/pacemakerd/pcmkd_corosync.c @@ -179,16 +179,20 @@ pacemakerd_corosync_connect_cfg(void) } /* CFG provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__crit("Rejecting Corosync CFG provider because process %lld " "is running as uid %lld gid %lld, not root", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); goto bail; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__crit("Could not authenticate Corosync CFG provider: %s " - QB_XS " rc=%d", strerror(-rv), -rv); + QB_XS " rc=%d", pcmk_strerror(rv), rv); goto bail; } @@ -323,17 +327,21 @@ pacemakerd_corosync_read_config(void) } /* CMAP provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__crit("Rejecting Corosync CMAP provider because process %lld " "is running as uid %lld gid %lld, not root", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); cmap_finalize(local_handle); return false; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__crit("Could not authenticate Corosync CMAP provider: %s " - QB_XS " rc=%d", strerror(-rv), -rv); + QB_XS " rc=%d", pcmk_strerror(rv), rv); cmap_finalize(local_handle); return false; } diff --git a/lib/cluster/corosync.c b/lib/cluster/corosync.c index 5b1c9136745..bbcdf89b57c 100644 --- a/lib/cluster/corosync.c +++ b/lib/cluster/corosync.c @@ -112,10 +112,6 @@ pcmk__corosync_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid) char *name = NULL; cmap_handle_t local_handle = 0; int fd = -1; - uid_t found_uid = 0; - gid_t found_gid = 0; - pid_t found_pid = 0; - int rv; if (nodeid == 0) { nodeid = pcmk__cpg_local_nodeid(0); @@ -144,6 +140,11 @@ pcmk__corosync_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid) } if (cmap_handle == 0) { + pid_t found_pid = 0; + uid_t found_uid = 0; + gid_t found_gid = 0; + int rv = 0; + cmap_handle = local_handle; rc = cmap_fd_get(cmap_handle, &fd); @@ -154,16 +155,20 @@ pcmk__corosync_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid) } /* CMAP provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__err("CMAP provider is not authentic: process %lld " "(uid: %lld, gid: %lld)", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); goto bail; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__err("Could not verify authenticity of CMAP provider: %s (%d)", - strerror(-rv), -rv); + pcmk_strerror(rv), rv); goto bail; } } @@ -409,17 +414,21 @@ pcmk__corosync_quorum_connect(gboolean (*dispatch)(unsigned long long, } /* Quorum provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__err("Quorum provider is not authentic: process %lld " "(uid: %lld, gid: %lld)", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); rc = CS_ERR_ACCESS; goto bail; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__err("Could not verify authenticity of Quorum provider: %s (%d)", - strerror(-rv), -rv); + pcmk_strerror(rv), rv); rc = CS_ERR_ACCESS; goto bail; } @@ -604,16 +613,20 @@ pcmk__corosync_add_nodes(xmlNode *xml_parent) } /* CMAP provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__err("CMAP provider is not authentic: process %lld " "(uid: %lld, gid: %lld)", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); goto bail; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__err("Could not verify authenticity of CMAP provider: %s (%d)", - strerror(-rv), -rv); + pcmk_strerror(rv), rv); goto bail; } @@ -708,16 +721,20 @@ pcmk__corosync_cluster_name(void) } /* CMAP provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__err("CMAP provider is not authentic: process %lld " "(uid: %lld, gid: %lld)", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); goto bail; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__err("Could not verify authenticity of CMAP provider: %s (%d)", - strerror(-rv), -rv); + pcmk_strerror(rv), rv); goto bail; } @@ -789,8 +806,9 @@ pcmk__corosync_has_nodelist(void) } // Check whether CMAP connection is authentic (i.e. provided by root) - rc = crm_ipc_is_authentic_process(fd, (uid_t) 0, (gid_t) 0, - &found_pid, &found_uid, &found_gid); + rc = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + if (rc == 0) { pcmk__warn("Assuming Corosync does not have node list: CMAP provider " "is inauthentic " @@ -798,7 +816,9 @@ pcmk__corosync_has_nodelist(void) (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); goto bail; - } else if (rc < 0) { + } + + if (rc < 0) { pcmk__warn("Assuming Corosync does not have node list: Could not " "verify CMAP authenticity (%s) " QB_XS " rc=%d", pcmk_strerror(rc), rc); diff --git a/lib/cluster/cpg.c b/lib/cluster/cpg.c index ad314112ac6..ffb810cf4d9 100644 --- a/lib/cluster/cpg.c +++ b/lib/cluster/cpg.c @@ -139,18 +139,20 @@ pcmk__cpg_local_nodeid(cpg_handle_t handle) } // CPG provider run as root (at least in given user namespace)? - rv = crm_ipc_is_authentic_process(fd, (uid_t) 0, (gid_t) 0, &found_pid, - &found_uid, &found_gid); + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + if (rv == 0) { pcmk__err("CPG provider is not authentic: process %lld " "(uid: %lld, gid: %lld)", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); goto bail; + } - } else if (rv < 0) { + if (rv < 0) { pcmk__err("Could not verify authenticity of CPG provider: %s (%d)", - strerror(-rv), -rv); + pcmk_strerror(rv), rv); goto bail; } } @@ -834,17 +836,21 @@ pcmk__cpg_connect(pcmk_cluster_t *cluster) } /* CPG provider run as root (in given user namespace, anyway)? */ - if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid, - &found_uid, &found_gid))) { + rv = crm_ipc_is_authentic_process(fd, 0, 0, &found_pid, &found_uid, + &found_gid); + + if (rv == 0) { pcmk__err("CPG provider is not authentic: process %lld " "(uid: %lld, gid: %lld)", (long long) PCMK__SPECIAL_PID_AS_0(found_pid), (long long) found_uid, (long long) found_gid); rc = CS_ERR_ACCESS; goto bail; - } else if (rv < 0) { + } + + if (rv < 0) { pcmk__err("Could not verify authenticity of CPG provider: %s (%d)", - strerror(-rv), -rv); + pcmk_strerror(rv), rv); rc = CS_ERR_ACCESS; goto bail; } From ccdf7ffb94f4ae4e53a09933101a4a0622aad193 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 10 Aug 2026 11:46:05 -0700 Subject: [PATCH 12/12] Refactor: pacemakerd: Clean up cluster_reconnect_cb() Signed-off-by: Reid Wahl --- daemons/pacemakerd/pcmkd_corosync.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c index 2bef6898040..2c6473d18cf 100644 --- a/daemons/pacemakerd/pcmkd_corosync.c +++ b/daemons/pacemakerd/pcmkd_corosync.c @@ -95,23 +95,21 @@ close_cfg(void) static gboolean cluster_reconnect_cb(void *data) { - if (pacemakerd_corosync_connect_cfg()) { - g_clear_pointer(&reconnect_timer, mainloop_timer_del); - pcmk__notice("Cluster reconnect succeeded"); - pacemakerd_corosync_read_config(); - restart_cluster_subdaemons(); - return G_SOURCE_REMOVE; - } else { + if (!pacemakerd_corosync_connect_cfg()) { + /* In theory this will continue forever. In practice the CIB connection + * from attrd will timeout and shut down Pacemaker when it gets bored. + */ pcmk__info("Cluster reconnect failed (connection will be reattempted " "once per second)"); + return G_SOURCE_CONTINUE; } - /* - * In theory this will continue forever. In practice the CIB connection from - * attrd will timeout and shut down Pacemaker when it gets bored. - */ - return G_SOURCE_CONTINUE; -} + g_clear_pointer(&reconnect_timer, mainloop_timer_del); + pcmk__notice("Cluster reconnect succeeded"); + pacemakerd_corosync_read_config(); + restart_cluster_subdaemons(); + return G_SOURCE_REMOVE; +} static void cfg_connection_destroy(void *user_data)