SD_BUS_QU...NDER_CREDS(3)
π sd_bus_query_sender_creds, sd_bus_query_sender_privilege β query bus message sender credentials/privileges
okay so bestie, grab your iced coffee π because we're diving into the sd_bus_query_sender_creds family β that's sd_bus_query_sender_creds and sd_bus_query_sender_privilege, both living their best life in the sd_bus_query_sender_creds section of the systemd manuals. yes, the header repeats the name like three times, that's just how manpages are. iconic behavior honestly π
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_query_sender_creds(sd_bus_message *m, uint64_t mask,
sd_bus_creds **creds);
sd_bus_error* sd_bus_query_sender_privilege(sd_bus_message *m,
int capability);
πΈ DESCRIPTION πΈ
π«Ά sd_bus_query_sender_creds()
so this one returns the credentials of the message m, okay? and the mask parameter? that's a little combo of SD_BUS_CREDS_* flags that tells everyone which credential info the caller is actually interested in. wanna see the full list of possible flags? go peek at sd_bus_creds_new_from_pid(3), it's all there π
now the way this works is lowkey a little detective story:
- first, it checks if the requested credentials are already attached to the message itself. easy, no notes π
- if not, but the message contains the pid of the sender and the caller specified the
SD_BUS_CREDS_AUGMENTflag, the function tries to figure out the missing credentials via other means (starting from the pid). main character detective energy fr fr π - if the PID is not available but the message has a sender, this function calls
sd_bus_get_name_creds(3)to get the requested credentials. - if the message has no sender (this is the direct-connection girlies), this function calls
sd_bus_get_owner_creds(3)to get the requested credentials.
on success, the requested credentials are stored in creds. and the ownership of that credentials object in creds is transferred to the caller β so you gotta free it by calling sd_bus_creds_unref(3). don't ghost it, clean up after yourself π§Ήβ¨
π¦ sd_bus_query_sender_privilege()
this one checks if the message m has the requested privileges. here's the tea:
- if
capabilityis a non-negative integer, it checks if the message has the capability with the same value. seecapabilities(7)for a list of capabilities π - if
capabilityis a negative integer, it returns whether the sender of the message runs as the same user as the receiver of the message, or whether the sender of the message runs as root and the receiver of the message does not run as root. root girlies stay winning π
on success and if the message has the requested privileges, this function returns a positive integer (slay). if the message does not have the requested privileges, it returns zero. no cap. π«‘
β RETURN VALUE β
on success, these functions return a non-negative integer. on failure, they return a negative errno-style error code. the duality of life π
π Errors
returned errors may indicate the following problems, bestie β write these down:
-EINVALβ the messagemor an output parameter isNULL.
added in version 246.
-ENOTCONNβ the bus ofmis not connected.
added in version 246.
-ECHILDβ the bus ofmwas created in a different process, library or module instance. rude, honestly π
added in version 246.
-EPERMβ the messagemis not sealed.
added in version 246.
π NOTES π
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file. build system besties, that one's for you π οΈ
all functions listed here are thread-agnostic, and only a single thread may operate on a given object at any given time. different threads may access the same object at different times, and multiple independent objects may be used from different threads in parallel. sharing is caring but also read the rules π
β οΈ heads up babes: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. that means the code calling the functions described here must not callsetenv(3)from a parallel thread. it's recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. do with that information what you will, but like, please do it correctly π
π HISTORY π
sd_bus_query_sender_creds() and sd_bus_query_sender_privilege() were added in version 246. glow-up era β¨
π SEE ALSO π
systemd(1), sd-bus(3), sd_bus_creds_new_from_pid(3), sd_bus_get_name_creds(3), sd_bus_get_owner_creds(3), sd_bus_creds_unref(3), capabilities(7)
okay that's the whole page, bestie, you ate that ππ this little number is from systemd 261.3, dated the systemd 261.3 era, and if you ever forget, just remember: this manual page itself is literally called SD_BUS_QU...NDER_CREDS(3) β the abbreviated icon it is ππ¦ periodt πΈ
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms