Credentials

Added in version 2.26.

class Credentials(**properties: Any)

Superclasses: Object

The GCredentials type is a reference-counted wrapper for native credentials.

The information in GCredentials is typically used for identifying, authenticating and authorizing other processes.

Some operating systems supports looking up the credentials of the remote peer of a communication endpoint - see e.g. get_credentials.

Some operating systems supports securely sending and receiving credentials over a Unix Domain Socket, see UnixCredentialsMessage, send_credentials and receive_credentials for details.

On Linux, the native credential type is a struct ucred - see the `unix(7) man page <man:unix(7>`_) for details. This corresponds to G_CREDENTIALS_TYPE_LINUX_UCRED.

On Apple operating systems (including iOS, tvOS, and macOS), the native credential type is a struct xucred. This corresponds to G_CREDENTIALS_TYPE_APPLE_XUCRED.

On FreeBSD, Debian GNU/kFreeBSD, and GNU/Hurd, the native credential type is a struct cmsgcred. This corresponds to G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED.

On NetBSD, the native credential type is a struct unpcbid. This corresponds to G_CREDENTIALS_TYPE_NETBSD_UNPCBID.

On OpenBSD, the native credential type is a struct sockpeercred. This corresponds to G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED.

On Solaris (including OpenSolaris and its derivatives), the native credential type is a ucred_t. This corresponds to G_CREDENTIALS_TYPE_SOLARIS_UCRED.

Since GLib 2.72, on Windows, the native credentials may contain the PID of a process. This corresponds to G_CREDENTIALS_TYPE_WIN32_PID.

Constructors

class Credentials
classmethod new() Credentials

Creates a new Credentials object with credentials matching the the current process.

Added in version 2.26.

Methods

class Credentials
get_unix_pid() int

Tries to get the UNIX process identifier from credentials. This method is only available on UNIX platforms.

This operation can fail if Credentials is not supported on the OS or if the native credentials type does not contain information about the UNIX process ID.

Added in version 2.36.

get_unix_user() int

Tries to get the UNIX user identifier from credentials. This method is only available on UNIX platforms.

This operation can fail if Credentials is not supported on the OS or if the native credentials type does not contain information about the UNIX user.

Added in version 2.26.

is_same_user(other_credentials: Credentials) bool

Checks if credentials and other_credentials is the same user.

This operation can fail if Credentials is not supported on the the OS.

Added in version 2.26.

Parameters:

other_credentials – A Credentials.

set_native(native_type: CredentialsType, native: None) None

Copies the native credentials of type native_type from native into credentials.

It is a programming error (which will cause a warning to be logged) to use this method if there is no Credentials support for the OS or if native_type isn’t supported by the OS.

Added in version 2.26.

Parameters:
  • native_type – The type of native credentials to set.

  • native – A pointer to native credentials.

set_unix_user(uid: int) bool

Tries to set the UNIX user identifier on credentials. This method is only available on UNIX platforms.

This operation can fail if Credentials is not supported on the OS or if the native credentials type does not contain information about the UNIX user. It can also fail if the OS does not allow the use of “spoofed” credentials.

Added in version 2.26.

Parameters:

uid – The UNIX user identifier to set.

to_string() str

Creates a human-readable textual representation of credentials that can be used in logging and debug messages. The format of the returned string may change in future GLib release.

Added in version 2.26.