---
name: "sd_bus_creds_get_augmented_mask"
section: "3"
platform: "linux"
package: "libsystemd-dev"
version: "257.13-1~deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sd_bus_creds_new_from_pid"
---

# sd\_bus\_creds\_get\_augmented\_mask(3)

Retrieve credentials object for the specified PID

Part of [sd\_bus\_creds\_new\_from\_pid(3)](/sd_bus_creds_new_from_pid/3.md).

## NAME

sd\_bus\_creds\_new\_from\_pid, sd\_bus\_creds\_new\_from\_pidfd, sd\_bus\_creds\_get\_mask, sd\_bus\_creds\_get\_augmented\_mask, sd\_bus\_creds\_ref, sd\_bus\_creds\_unref, sd\_bus\_creds\_unrefp - Retrieve credentials object for the specified PID

## SYNOPSIS

```
#include <systemd/sd-bus.h>
```

**int sd\_bus\_creds\_new\_from\_pid(pid\_t** *pid***, uint64\_t** *creds\_mask***, sd\_bus\_creds \*\****ret***);**

**int sd\_bus\_creds\_new\_from\_pidfd(int** *pidfd***, uint64\_t** *creds\_mask***, sd\_bus\_creds \*\****ret***);**

**uint64\_t sd\_bus\_creds\_get\_mask(sd\_bus\_creds \****c***);**

**uint64\_t sd\_bus\_creds\_get\_augmented\_mask(sd\_bus\_creds \****c***);**

**sd\_bus\_creds \*sd\_bus\_creds\_ref(sd\_bus\_creds \****c***);**

**sd\_bus\_creds \*sd\_bus\_creds\_unref(sd\_bus\_creds \****c***);**

**void sd\_bus\_creds\_unrefp(sd\_bus\_creds \*\****c***);**

**SD\_BUS\_CREDS\_PID**, **SD\_BUS\_CREDS\_PPID**, **SD\_BUS\_CREDS\_TID**, **SD\_BUS\_CREDS\_UID**, **SD\_BUS\_CREDS\_EUID**, **SD\_BUS\_CREDS\_SUID**, **SD\_BUS\_CREDS\_FSUID**, **SD\_BUS\_CREDS\_GID**, **SD\_BUS\_CREDS\_EGID**, **SD\_BUS\_CREDS\_SGID**, **SD\_BUS\_CREDS\_FSGID**, **SD\_BUS\_CREDS\_SUPPLEMENTARY\_GIDS**, **SD\_BUS\_CREDS\_COMM**, **SD\_BUS\_CREDS\_TID\_COMM**, **SD\_BUS\_CREDS\_EXE**, **SD\_BUS\_CREDS\_CMDLINE**, **SD\_BUS\_CREDS\_CGROUP**, **SD\_BUS\_CREDS\_UNIT**, **SD\_BUS\_CREDS\_SLICE**, **SD\_BUS\_CREDS\_USER\_UNIT**, **SD\_BUS\_CREDS\_USER\_SLICE**, **SD\_BUS\_CREDS\_SESSION**, **SD\_BUS\_CREDS\_OWNER\_UID**, **SD\_BUS\_CREDS\_EFFECTIVE\_CAPS**, **SD\_BUS\_CREDS\_PERMITTED\_CAPS**, **SD\_BUS\_CREDS\_INHERITABLE\_CAPS**, **SD\_BUS\_CREDS\_BOUNDING\_CAPS**, **SD\_BUS\_CREDS\_SELINUX\_CONTEXT**, **SD\_BUS\_CREDS\_AUDIT\_SESSION\_ID**, **SD\_BUS\_CREDS\_AUDIT\_LOGIN\_UID**, **SD\_BUS\_CREDS\_TTY**, **SD\_BUS\_CREDS\_UNIQUE\_NAME**, **SD\_BUS\_CREDS\_WELL\_KNOWN\_NAMES**, **SD\_BUS\_CREDS\_DESCRIPTION**, **SD\_BUS\_CREDS\_PIDFD**, **SD\_BUS\_CREDS\_AUGMENT**, **\_SD\_BUS\_CREDS\_ALL**

## DESCRIPTION

**sd\_bus\_creds\_new\_from\_pid()** creates a new credentials object and fills it with information about the process *pid*. The pointer to this object will be stored in the *ret* pointer. Note that credential objects may also be created and retrieved via [**sd\_bus\_get\_name\_creds**(3)](/sd_bus_get_name_creds/3.md), [**sd\_bus\_get\_owner\_creds**(3)](/sd_bus_get_owner_creds/3.md) and [**sd\_bus\_message\_get\_creds**(3)](/sd_bus_message_get_creds/3.md).

**sd\_bus\_creds\_new\_from\_pidfd()** is identical to **sd\_bus\_creds\_new\_from\_pid()**, but takes a PID file descriptor rather than a numeric PID as reference to the process. See [**pidfd\_open**(2)](/pidfd_open/2.md).

The information that will be stored is determined by *creds\_mask*. It may contain a subset of ORed constants **SD\_BUS\_CREDS\_PID**, **SD\_BUS\_CREDS\_PPID**, **SD\_BUS\_CREDS\_TID**, **SD\_BUS\_CREDS\_UID**, **SD\_BUS\_CREDS\_EUID**, **SD\_BUS\_CREDS\_SUID**, **SD\_BUS\_CREDS\_FSUID**, **SD\_BUS\_CREDS\_GID**, **SD\_BUS\_CREDS\_EGID**, **SD\_BUS\_CREDS\_SGID**, **SD\_BUS\_CREDS\_FSGID**, **SD\_BUS\_CREDS\_SUPPLEMENTARY\_GIDS**, **SD\_BUS\_CREDS\_COMM**, **SD\_BUS\_CREDS\_TID\_COMM**, **SD\_BUS\_CREDS\_EXE**, **SD\_BUS\_CREDS\_CMDLINE**, **SD\_BUS\_CREDS\_CGROUP**, **SD\_BUS\_CREDS\_UNIT**, **SD\_BUS\_CREDS\_SLICE**, **SD\_BUS\_CREDS\_USER\_UNIT**, **SD\_BUS\_CREDS\_USER\_SLICE**, **SD\_BUS\_CREDS\_SESSION**, **SD\_BUS\_CREDS\_OWNER\_UID**, **SD\_BUS\_CREDS\_EFFECTIVE\_CAPS**, **SD\_BUS\_CREDS\_PERMITTED\_CAPS**, **SD\_BUS\_CREDS\_INHERITABLE\_CAPS**, **SD\_BUS\_CREDS\_BOUNDING\_CAPS**, **SD\_BUS\_CREDS\_SELINUX\_CONTEXT**, **SD\_BUS\_CREDS\_AUDIT\_SESSION\_ID**, **SD\_BUS\_CREDS\_AUDIT\_LOGIN\_UID**, **SD\_BUS\_CREDS\_TTY**, **SD\_BUS\_CREDS\_UNIQUE\_NAME**, **SD\_BUS\_CREDS\_WELL\_KNOWN\_NAMES**, **SD\_BUS\_CREDS\_DESCRIPTION**, and **SD\_BUS\_CREDS\_PIDFD**. Use the special value **\_SD\_BUS\_CREDS\_ALL** to request all supported fields. The **SD\_BUS\_CREDS\_AUGMENT** constant may not be ORed into the mask for invocations of **sd\_bus\_creds\_new\_from\_pid()** or **sd\_bus\_creds\_new\_from\_pidfd()**.

Fields can be retrieved from the credentials object using [**sd\_bus\_creds\_get\_pid**(3)](/sd_bus_creds_get_pid/3.md) and other functions which correspond directly to the constants listed above.

A mask of fields which were actually successfully retrieved can be retrieved with **sd\_bus\_creds\_get\_mask()**. If the credentials object was created with **sd\_bus\_creds\_new\_from\_pid()** or **sd\_bus\_creds\_new\_from\_pidfd()**, this will be a subset of fields requested in *creds\_mask*.

Similar to **sd\_bus\_creds\_get\_mask()**, the function **sd\_bus\_creds\_get\_augmented\_mask()** returns a bitmask of field constants. The mask indicates which credential fields have been retrieved in a non-atomic fashion. For credential objects created via **sd\_bus\_creds\_new\_from\_pid()** or **sd\_bus\_creds\_new\_from\_pidfd()**, this mask will be identical to the mask returned by **sd\_bus\_creds\_get\_mask()**. However, for credential objects retrieved via **sd\_bus\_get\_name\_creds()**, this mask will be set for the credential fields that could not be determined atomically at peer connection time, and which were later added by reading augmenting credential data from /proc/. Similarly, for credential objects retrieved via **sd\_bus\_get\_owner\_creds()**, the mask is set for the fields that could not be determined atomically at bus creation time, but have been augmented. Similarly, for credential objects retrieved via **sd\_bus\_message\_get\_creds()**, the mask is set for the fields that could not be determined atomically at message sending time, but have been augmented. The mask returned by **sd\_bus\_creds\_get\_augmented\_mask()** is always a subset of (or identical to) the mask returned by **sd\_bus\_creds\_get\_mask()** for the same object. The latter call hence returns all credential fields available in the credential object, the former then marks the subset of those that have been augmented. Note that augmented fields are unsuitable for authorization decisions, as they may be retrieved at different times, thus being subject to races. Hence, augmented fields should be used exclusively for informational purposes.

**sd\_bus\_creds\_ref()** creates a new reference to the credentials object *c*. This object will not be destroyed until **sd\_bus\_creds\_unref()** has been called as many times plus once more. Once the reference count has dropped to zero, *c* cannot be used anymore, so further calls to **sd\_bus\_creds\_ref(c)** or **sd\_bus\_creds\_unref(c)** are illegal.

**sd\_bus\_creds\_unref()** destroys a reference to *c*.

**sd\_bus\_creds\_unrefp()** is similar to **sd\_bus\_creds\_unref()** but takes a pointer to a pointer to an **sd\_bus\_creds** object. This call is useful in conjunction with GCC's and LLVM's **Clean-up Variable Attribute**\[1\]. Note that this function is defined as inline function.

**sd\_bus\_creds\_ref()**, **sd\_bus\_creds\_unref()** and **sd\_bus\_creds\_unrefp()** execute no operation if the passed in bus credentials object is **NULL**.

## RETURN VALUE

On success, **sd\_bus\_creds\_new\_from\_pid()** and **sd\_bus\_creds\_new\_from\_pidfd()** return 0 or a positive integer. On failure, they return a negative errno-style error code.

**sd\_bus\_creds\_get\_mask()** returns the mask of successfully acquired fields.

**sd\_bus\_creds\_get\_augmented\_mask()** returns the mask of fields that have been augmented from data in /proc/, and are thus not suitable for authorization decisions.

**sd\_bus\_creds\_ref()** always returns the argument.

**sd\_bus\_creds\_unref()** always returns **NULL**.

## REFERENCE OWNERSHIP

The functions **sd\_bus\_creds\_new\_from\_pid()** and **sd\_bus\_creds\_new\_from\_pidfd()** create a new object and the caller owns the sole reference. When not needed anymore, this reference should be destroyed with [**sd\_bus\_creds\_unref**(3)](/sd_bus_creds_unref/3.md).

### Errors

Returned errors may indicate the following problems:

**-ESRCH**

Specified *pid* could not be found.

**-EINVAL**

Specified parameter is invalid (**NULL** in case of output parameters).

**-ENOMEM**

Memory allocation failed.

**-EOPNOTSUPP**

One of the requested fields is unknown to the local system.

## NOTES

Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

The code described here uses [**getenv**(3)](/getenv/3.md), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/setenv/3.md) from a parallel thread. It is recommended to only do calls to **setenv()** from an early phase of the program when no other threads have been started.

## HISTORY

**sd\_bus\_creds\_new\_from\_pid()**, **sd\_bus\_creds\_get\_mask()**, **sd\_bus\_creds\_ref()**, **sd\_bus\_creds\_unref()**, and **sd\_bus\_creds\_get\_augmented\_mask()** were added in version 221.

**sd\_bus\_creds\_unrefp()** was added in version 229.

**sd\_bus\_creds\_new\_from\_pidfd()** was added in version 256.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-bus**(3)](/sd-bus/3.md), [**sd\_bus\_creds\_get\_pid**(3)](/sd_bus_creds_get_pid/3.md), [**sd\_bus\_get\_name\_creds**(3)](/sd_bus_get_name_creds/3.md), [**sd\_bus\_get\_owner\_creds**(3)](/sd_bus_get_owner_creds/3.md), [**sd\_bus\_message\_get\_creds**(3)](/sd_bus_message_get_creds/3.md)

## NOTES

- 1\.

  Clean-up Variable Attribute

  https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
