Gio.Credentials

g GObject.Object GObject.Object Gio.Credentials Gio.Credentials GObject.Object->Gio.Credentials

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

get_unix_pid ()

get_unix_user ()

is_same_user (other_credentials)

set_native (native_type, native)

set_unix_user (uid)

to_string ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gio.Credentials(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Gio.CredentialsClass

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. [method`Gio`.Socket.get_credentials].

Some operating systems supports securely sending and receiving credentials over a Unix Domain Socket, see [class`Gio`.UnixCredentialsMessage], [method`Gio`.UnixConnection.send_credentials] and [method`Gio`.UnixConnection.receive_credentials] for details.

On Linux, the native credential type is a struct ucred - see the unix(7) man page) 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.

New in version 2.26.

classmethod new()[source]
Returns:

A Gio.Credentials. Free with GObject.Object.unref().

Return type:

Gio.Credentials

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

New in version 2.26.

get_unix_pid()[source]
Raises:

GLib.Error

Returns:

The UNIX process ID, or -1 if error is set.

Return type:

int

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

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

New in version 2.36.

get_unix_user()[source]
Raises:

GLib.Error

Returns:

The UNIX user identifier or -1 if error is set.

Return type:

int

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

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

New in version 2.26.

is_same_user(other_credentials)[source]
Parameters:

other_credentials (Gio.Credentials) – A Gio.Credentials.

Raises:

GLib.Error

Returns:

True if self and other_credentials has the same user, False otherwise or if error is set.

Return type:

bool

Checks if self and other_credentials is the same user.

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

New in version 2.26.

set_native(native_type, native)[source]
Parameters:
  • native_type (Gio.CredentialsType) – The type of native credentials to set.

  • native (object) – A pointer to native credentials.

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

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

New in version 2.26.

set_unix_user(uid)[source]
Parameters:

uid (int) – The UNIX user identifier to set.

Raises:

GLib.Error

Returns:

True if uid was set, False if error is set.

Return type:

bool

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

This operation can fail if Gio.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.

New in version 2.26.

to_string()[source]
Returns:

A string that should be freed with GLib.free().

Return type:

str

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

New in version 2.26.