D-Bus  1.9.2
Data Structures | Typedefs | Functions

Internal system-dependent API available on UNIX only. More...

Data Structures

struct  DBusUserInfo
 Information about a UNIX user. More...
 
struct  DBusGroupInfo
 Information about a UNIX group. More...
 

Typedefs

typedef struct DBusUserInfo DBusUserInfo
 Information about a UNIX user.
 
typedef struct DBusGroupInfo DBusGroupInfo
 Information about a UNIX group.
 

Functions

dbus_bool_t _dbus_close (int fd, DBusError *error)
 Closes a file descriptor. More...
 
int _dbus_dup (int fd, DBusError *error)
 Duplicates a file descriptor. More...
 
int _dbus_read (int fd, DBusString *buffer, int count)
 Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer. More...
 
int _dbus_write (int fd, const DBusString *buffer, int start, int len)
 Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for you. More...
 
int _dbus_write_two (int fd, const DBusString *buffer1, int start1, int len1, const DBusString *buffer2, int start2, int len2)
 Like _dbus_write() but will use writev() if possible to write both buffers in sequence. More...
 
int _dbus_connect_unix_socket (const char *path, dbus_bool_t abstract, DBusError *error)
 Creates a socket and connects it to the UNIX domain socket at the given path. More...
 
int _dbus_listen_unix_socket (const char *path, dbus_bool_t abstract, DBusError *error)
 Creates a socket and binds it to the given path, then listens on the socket. More...
 
int _dbus_connect_exec (const char *path, char *const argv[], DBusError *error)
 Creates a UNIX domain socket and connects it to the specified process to execute. More...
 
int _dbus_listen_systemd_sockets (int **fd, DBusError *error)
 Acquires one or more sockets passed in from systemd. More...
 
dbus_bool_t _dbus_read_credentials (int client_fd, DBusCredentials *credentials, DBusError *error)
 
dbus_bool_t _dbus_send_credentials (int server_fd, DBusError *error)
 
dbus_bool_t _dbus_lookup_launchd_socket (DBusString *socket_path, const char *launchd_env_var, DBusError *error)
 quries launchd for a specific env var which holds the socket path. More...
 
dbus_bool_t _dbus_user_info_fill (DBusUserInfo *info, const DBusString *username, DBusError *error)
 Gets user info for the given username. More...
 
dbus_bool_t _dbus_user_info_fill_uid (DBusUserInfo *info, dbus_uid_t uid, DBusError *error)
 Gets user info for the given user ID. More...
 
void _dbus_user_info_free (DBusUserInfo *info)
 Frees the members of info (but not info itself) More...
 
dbus_bool_t _dbus_group_info_fill (DBusGroupInfo *info, const DBusString *groupname, DBusError *error)
 Initializes the given DBusGroupInfo struct with information about the given group name. More...
 
dbus_bool_t _dbus_group_info_fill_gid (DBusGroupInfo *info, dbus_gid_t gid, DBusError *error)
 Initializes the given DBusGroupInfo struct with information about the given group ID. More...
 
void _dbus_group_info_free (DBusGroupInfo *info)
 Frees the members of info (but not info itself). More...
 
dbus_uid_t _dbus_getuid (void)
 Gets our UID. More...
 
dbus_uid_t _dbus_geteuid (void)
 Gets our effective UID. More...
 
dbus_bool_t _dbus_parse_uid (const DBusString *uid_str, dbus_uid_t *uid)
 Gets a UID from a UID string. More...
 
void _dbus_close_all (void)
 Closes all file descriptors except the first three (i.e. More...
 
dbus_bool_t _dbus_append_address_from_socket (int fd, DBusString *address, DBusError *error)
 Read the address from the socket and append it to the string. More...
 
void _dbus_fd_set_close_on_exec (int fd)
 Sets the file descriptor to be close on exec. More...
 

Detailed Description

Internal system-dependent API available on UNIX only.

Function Documentation

dbus_bool_t _dbus_append_address_from_socket ( int  fd,
DBusString address,
DBusError error 
)

Read the address from the socket and append it to the string.

Parameters
fdthe socket
address
errorreturn location for error code

Definition at line 4180 of file dbus-sysdeps-unix.c.

References _dbus_address_append_escaped(), _dbus_error_from_errno(), _dbus_string_append(), _dbus_string_append_printf(), _dbus_string_init_const(), dbus_set_error(), FALSE, and TRUE.

Referenced by _dbus_server_listen_platform_specific().

dbus_bool_t _dbus_close ( int  fd,
DBusError error 
)
void _dbus_close_all ( void  )

Closes all file descriptors except the first three (i.e.

stdin, stdout, stderr).

Definition at line 4057 of file dbus-sysdeps-unix.c.

References NULL.

Referenced by _dbus_connect_exec().

int _dbus_connect_exec ( const char *  path,
char *const  argv[],
DBusError error 
)

Creates a UNIX domain socket and connects it to the specified process to execute.

This will set FD_CLOEXEC for the socket returned.

Parameters
paththe path to the executable
argvthe argument list for the process to execute. argv[0] typically is identical to the path of the executable
errorreturn location for error code
Returns
connection file descriptor or -1 on error

Definition at line 929 of file dbus-sysdeps-unix.c.

References _dbus_close_all(), _dbus_error_from_errno(), _dbus_fd_set_close_on_exec(), and dbus_set_error().

int _dbus_connect_unix_socket ( const char *  path,
dbus_bool_t  abstract,
DBusError error 
)

Creates a socket and connects it to the UNIX domain socket at the given path.

The connection fd is returned, and is set up as nonblocking.

Uses abstract sockets instead of filesystem-linked sockets if requested (it's possible only on Linux; see "man 7 unix" on Linux). On non-Linux abstract socket usage always fails.

This will set FD_CLOEXEC for the socket returned.

Parameters
paththe path to UNIX domain socket
abstractTRUE to use abstract namespace
errorreturn location for error code
Returns
connection file descriptor or -1 on error

Definition at line 833 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _DBUS_ZERO, DBUS_ERROR_BAD_ADDRESS, DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), and NULL.

Referenced by _dbus_transport_new_for_domain_socket().

int _dbus_dup ( int  fd,
DBusError error 
)

Duplicates a file descriptor.

Makes sure the fd returned is >= 3 (i.e. avoids stdin/stdout/stderr). Sets O_CLOEXEC.

Parameters
fdthe file descriptor to duplicate
erroraddress of error location.
Returns
duplicated file descriptor

Definition at line 3053 of file dbus-sysdeps-unix.c.

References _dbus_error_from_errno(), _dbus_fd_set_close_on_exec(), and dbus_set_error().

Referenced by _dbus_message_iter_get_args_valist(), dbus_message_copy(), dbus_message_iter_append_basic(), and dbus_message_iter_get_basic().

void _dbus_fd_set_close_on_exec ( int  fd)

Sets the file descriptor to be close on exec.

Should be called for all file descriptors in D-Bus code.

Parameters
fdthe file descriptor

Definition at line 3003 of file dbus-sysdeps-unix.c.

Referenced by _dbus_accept(), _dbus_connect_exec(), _dbus_dup(), _dbus_full_duplex_pipe(), _dbus_read_socket_with_unix_fds(), and _dbus_server_new_for_launchd().

dbus_uid_t _dbus_geteuid ( void  )

Gets our effective UID.

Returns
process effective UID

Definition at line 2489 of file dbus-sysdeps-unix.c.

Referenced by _dbus_append_user_from_current_process(), _dbus_credentials_add_from_current_process(), and _dbus_unix_user_is_process_owner().

dbus_uid_t _dbus_getuid ( void  )

Gets our UID.

Returns
process UID

Definition at line 2480 of file dbus-sysdeps-unix.c.

dbus_bool_t _dbus_group_info_fill ( DBusGroupInfo info,
const DBusString groupname,
DBusError error 
)

Initializes the given DBusGroupInfo struct with information about the given group name.

Parameters
infothe group info struct
groupnamename of group
errorthe error return
Returns
FALSE if error is set

Definition at line 997 of file dbus-sysdeps-util-unix.c.

References DBUS_GID_UNSET.

Referenced by _dbus_user_database_lookup_group().

dbus_bool_t _dbus_group_info_fill_gid ( DBusGroupInfo info,
dbus_gid_t  gid,
DBusError error 
)

Initializes the given DBusGroupInfo struct with information about the given group ID.

Parameters
infothe group info struct
gidgroup ID
errorthe error return
Returns
FALSE if error is set

Definition at line 1016 of file dbus-sysdeps-util-unix.c.

References NULL.

Referenced by _dbus_user_database_lookup_group().

void _dbus_group_info_free ( DBusGroupInfo info)

Frees the members of info (but not info itself).

Parameters
infothe group info

Definition at line 89 of file dbus-userdb.c.

References dbus_free(), and DBusGroupInfo::groupname.

Referenced by _dbus_group_info_free_allocated().

int _dbus_listen_systemd_sockets ( int **  fds,
DBusError error 
)

Acquires one or more sockets passed in from systemd.

The sockets are set to be nonblocking.

This will set FD_CLOEXEC for the sockets returned.

Parameters
fdsthe file descriptors
errorreturn location for errors
Returns
the number of file descriptors

Definition at line 1162 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), DBUS_ERROR_BAD_ADDRESS, DBUS_ERROR_NO_MEMORY, DBUS_ERROR_NOT_SUPPORTED, dbus_free(), dbus_new, dbus_set_error(), dbus_set_error_const(), NULL, and TRUE.

Referenced by _dbus_server_listen_platform_specific().

int _dbus_listen_unix_socket ( const char *  path,
dbus_bool_t  abstract,
DBusError error 
)

Creates a socket and binds it to the given path, then listens on the socket.

The socket is set to be nonblocking.

Uses abstract sockets instead of filesystem-linked sockets if requested (it's possible only on Linux; see "man 7 unix" on Linux). On non-Linux abstract socket usage always fails.

This will set FD_CLOEXEC for the socket returned

Parameters
paththe socket name
abstractTRUE to use abstract namespace
errorreturn location for errors
Returns
the listening file descriptor or -1 on error

Definition at line 1035 of file dbus-sysdeps-unix.c.

References _dbus_close(), _dbus_error_from_errno(), _dbus_warn(), _DBUS_ZERO, DBUS_ERROR_BAD_ADDRESS, DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), and NULL.

Referenced by _dbus_server_new_for_domain_socket().

dbus_bool_t _dbus_lookup_launchd_socket ( DBusString socket_path,
const char *  launchd_env_var,
DBusError error 
)

quries launchd for a specific env var which holds the socket path.

Parameters
socket_pathappend the socket path to this DBusString
launchd_env_varthe env var to look up
errora DBusError to store the error in case of failure
Returns
the value of the env var

Definition at line 3731 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_check_setuid(), _DBUS_N_ELEMENTS, _dbus_string_get_length(), _dbus_string_shorten(), DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), dbus_set_error_const(), FALSE, NULL, and TRUE.

Referenced by _dbus_transport_open_platform_specific().

dbus_bool_t _dbus_parse_uid ( const DBusString uid_str,
dbus_uid_t uid 
)

Gets a UID from a UID string.

Parameters
uid_strthe UID in string form
uidUID to fill in
Returns
TRUE if successfully filled in UID

Definition at line 2514 of file dbus-sysdeps-unix.c.

References _dbus_string_get_length(), _dbus_string_parse_int(), FALSE, and TRUE.

int _dbus_read ( int  fd,
DBusString buffer,
int  count 
)

Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer.

It appends up to the given count, and returns the same value and same errno as read(). The only exception is that _dbus_read() handles EINTR for you. Also, _dbus_read() can return ENOMEM, even though regular UNIX read doesn't.

Unlike _dbus_read_socket(), _dbus_read() is not available on Windows.

Parameters
fdthe file descriptor to read from
bufferthe buffer to append data to
countthe amount of data to read
Returns
the number of bytes read or -1

Definition at line 628 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_string_get_data_len(), _dbus_string_get_length(), _dbus_string_lengthen(), _dbus_string_set_length(), and _dbus_verbose_bytes_of_string().

Referenced by _dbus_command_for_pid(), _dbus_file_get_contents(), _dbus_generate_random_bytes(), and _dbus_read_socket().

dbus_bool_t _dbus_user_info_fill ( DBusUserInfo info,
const DBusString username,
DBusError error 
)

Gets user info for the given username.

Parameters
infouser info object to initialize
usernamethe username
errorerror return
Returns
TRUE on success

Definition at line 2397 of file dbus-sysdeps-unix.c.

References DBUS_UID_UNSET.

Referenced by _dbus_user_database_lookup().

dbus_bool_t _dbus_user_info_fill_uid ( DBusUserInfo info,
dbus_uid_t  uid,
DBusError error 
)

Gets user info for the given user ID.

Parameters
infouser info object to initialize
uidthe user ID
errorerror return
Returns
TRUE on success

Definition at line 2414 of file dbus-sysdeps-unix.c.

References NULL.

Referenced by _dbus_user_database_lookup().

void _dbus_user_info_free ( DBusUserInfo info)

Frees the members of info (but not info itself)

Parameters
infothe user info struct

Definition at line 76 of file dbus-userdb.c.

References dbus_free(), DBusUserInfo::group_ids, DBusUserInfo::homedir, and DBusUserInfo::username.

Referenced by _dbus_user_info_free_allocated().

int _dbus_write ( int  fd,
const DBusString buffer,
int  start,
int  len 
)

Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for you.

Parameters
fdthe file descriptor to write
bufferthe buffer to write data from
startthe first byte in the buffer to write
lenthe number of bytes to try to write
Returns
the number of bytes written or -1 on error

Definition at line 688 of file dbus-sysdeps-unix.c.

References _dbus_string_get_const_data_len(), and _dbus_verbose_bytes_of_string().

Referenced by _dbus_string_save_to_file(), _dbus_write_socket(), and _dbus_write_two().

int _dbus_write_two ( int  fd,
const DBusString buffer1,
int  start1,
int  len1,
const DBusString buffer2,
int  start2,
int  len2 
)

Like _dbus_write() but will use writev() if possible to write both buffers in sequence.

The return value is the number of bytes written in the first buffer, plus the number written in the second. If the first buffer is written successfully and an error occurs writing the second, the number of bytes in the first is returned (i.e. the error is ignored), on systems that don't have writev. Handles EINTR for you. The second buffer may be NULL.

Parameters
fdthe file descriptor
buffer1first buffer
start1first byte to write in first buffer
len1number of bytes to write from first buffer
buffer2second buffer, or NULL
start2first byte to write in second buffer
len2number of bytes to write in second buffer
Returns
total bytes written from both buffers, or -1 on error

Definition at line 734 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_string_get_const_data_len(), _dbus_write(), and NULL.

Referenced by _dbus_write_socket_two().