Crashpad
Static Public Member Functions | Static Public Attributes | List of all members
crashpad::UnixCredentialSocket Class Reference

Utilities for communicating over SO_PASSCRED enabled AF_UNIX sockets. More...

#include "util/linux/socket.h"

Static Public Member Functions

static bool CreateCredentialSocketpair (ScopedFileHandle *s1, ScopedFileHandle *s2)
 Creates an AF_UNIX family socket pair with SO_PASSCRED set on each socket. More...
 
static int SendMsg (int fd, const void *buf, size_t buf_size, const int *fds=nullptr, size_t fd_count=0)
 Wraps sendmsg() to send a message with file descriptors. More...
 
static bool RecvMsg (int fd, void *buf, size_t buf_size, ucred *creds, std::vector< ScopedFileHandle > *fds=nullptr)
 Wraps recvmsg() to receive a message with file descriptors and credentials. More...
 

Static Public Attributes

static const size_t kMaxSendRecvMsgFDs = 4
 The maximum number of file descriptors that may be sent/received with SendMsg() or RecvMsg().
 

Detailed Description

Utilities for communicating over SO_PASSCRED enabled AF_UNIX sockets.

Member Function Documentation

◆ CreateCredentialSocketpair()

bool crashpad::UnixCredentialSocket::CreateCredentialSocketpair ( ScopedFileHandle s1,
ScopedFileHandle s2 
)
static

Creates an AF_UNIX family socket pair with SO_PASSCRED set on each socket.

Parameters
[out]s1One end of the connected pair.
[out]s2The other end of the connected pair.
Returns
true on success. Otherwise, false with a message logged.

◆ RecvMsg()

bool crashpad::UnixCredentialSocket::RecvMsg ( int  fd,
void *  buf,
size_t  buf_size,
ucred *  creds,
std::vector< ScopedFileHandle > *  fds = nullptr 
)
static

Wraps recvmsg() to receive a message with file descriptors and credentials.

This function is intended to be used with AF_UNIX family sockets. Up to kMaxSendRecvMsgFDs file descriptors may be received (via SCM_RIGHTS). The socket must have SO_PASSCRED set.

Parameters
[in]fdThe file descriptor to receive the message on.
[out]bufThe buffer to fill with the message.
[in]buf_sizeThe size of the message.
[out]credsThe credentials of the sender.
[out]fdsThe recieved file descriptors. Optional. If nullptr, all received file descriptors will be closed.
Returns
true on success. Otherwise, false, with a message logged. No message will be logged if the message was detected to be an EOF condition triggered by all clients disconnecting. This case is indistinguishable from misuses of this interface that haven't set SO_PASSCRED on fd.

◆ SendMsg()

int crashpad::UnixCredentialSocket::SendMsg ( int  fd,
const void *  buf,
size_t  buf_size,
const int *  fds = nullptr,
size_t  fd_count = 0 
)
static

Wraps sendmsg() to send a message with file descriptors.

This function is intended for use with AF_UNIX family sockets and passes file descriptors with SCM_RIGHTS.

This function may be used in a compromised context.

Parameters
[in]fdThe file descriptor to write the message to.
[in]bufThe buffer containing the message.
[in]buf_sizeThe size of the message.
[in]fdsAn array of at most kMaxSendRecvMsgFDs file descriptors. Optional.
[in]fd_countThe number of file descriptors in fds. Required only if fds was set.
Returns
0 on success or an error code on failure.

The documentation for this class was generated from the following files: