1.12 <GCredentials>

Class: <GCredentials>

It derives from <GObject>.

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. socket:get-credentials.

Some operating systems supports securely sending and receiving credentials over a Unix Domain Socket, see <GUnixCredentialsMessage>, unix-connection:send-credentials? and unix-connection: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 linux-ucred.

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

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

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

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

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

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

Procedures

Method: credentials:get-unix-pid self ⇒ %return
Method: get-unix-pid self ⇒ %return

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

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

self

Passed: a <GCredentials>.

A <GCredentials>

%return

Returned: a 32-bit integer.

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

Method: credentials:get-unix-user self ⇒ %return
Method: get-unix-user self ⇒ %return

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

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

As the signedness of uid_t is not specified by POSIX, it is recommended to check error for failure rather than trying to check the return value, particularly in language bindings.

self

Passed: a <GCredentials>.

A <GCredentials>

%return

Returned: an unsigned 32-bit integer.

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

Method: credentials:is-same-user? self other-credentials ⇒ %return
Method: is-same-user? self other-credentials ⇒ %return

Checks if self and other-credentials is the same user.

This operation can fail if <GCredentials> is not supported on the the OS.

self

Passed: a <GCredentials>.

A <GCredentials>.

other-credentials

Passed: a <GCredentials>.

A <GCredentials>.

%return

Returned: a boolean.

#t if self and other-credentials has the same user, #f otherwise or if error is set.

Procedure: credentials:new ⇒ %return

Creates a new <GCredentials> object with credentials matching the the current process.

%return

Returned: a <GCredentials>.

A <GCredentials>. Free with object:unref.

Method: credentials:set-native self native-type native
Method: set-native self native-type native

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 <GCredentials> support for the OS or if native-type isn’t supported by the OS.

self

Passed: a <GCredentials>.

A <GCredentials>.

native-type

Passed: a <GCredentialsType>, or one of its symbols.

The type of native credentials to set.

native

Passed: a foreign pointer, or a bytevector.

A pointer to native credentials.

Method: credentials:set-unix-user? self uid ⇒ %return
Method: set-unix-user? self uid ⇒ %return

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

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

self

Passed: a <GCredentials>.

A <GCredentials>.

uid

Passed: an unsigned 32-bit integer.

The UNIX user identifier to set.

%return

Returned: a boolean.

#t if uid was set, #f if error is set.

Method: credentials:to-string self ⇒ %return
Method: to-string self ⇒ %return

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.

self

Passed: a <GCredentials>.

A <GCredentials> object.

%return

Returned: a string.

A string that should be freed with byte-array:free.