D-Bus 1.15.8
Data Structures | Macros | Typedefs | Enumerations | Functions

Internal system-dependent API available on UNIX and Windows. More...

Data Structures

struct  DBusSocket
 Socket interface. More...
 
struct  DBusAtomic
 An atomic integer safe to increment or decrement from multiple threads. More...
 
struct  DBusPollFD
 
struct  DBusStat
 Portable struct with stat() results. More...
 

Macros

#define DBUS_PID_UNSET   ((dbus_pid_t) -1)
 an invalid PID used to represent an uninitialized dbus_pid_t field More...
 
#define DBUS_UID_UNSET   ((dbus_uid_t) -1)
 an invalid UID used to represent an uninitialized dbus_uid_t field More...
 
#define DBUS_GID_UNSET   ((dbus_gid_t) -1)
 an invalid GID used to represent an uninitialized dbus_gid_t field More...
 
#define DBUS_PID_FORMAT   "%lu"
 an appropriate printf format for dbus_pid_t More...
 
#define DBUS_UID_FORMAT   "%lu"
 an appropriate printf format for dbus_uid_t More...
 
#define DBUS_GID_FORMAT   "%lu"
 an appropriate printf format for dbus_gid_t More...
 
#define DBUS_SOCKET_FORMAT   "d"
 
#define DBUS_SOCKET_INIT   { -1 }
 
#define DBUS_POLLABLE_FORMAT   "d"
 
#define _DBUS_POLLIN   0x0001
 There is data to read. More...
 
#define _DBUS_POLLPRI   0x0002
 There is urgent data to read. More...
 
#define _DBUS_POLLOUT   0x0004
 Writing now will not block. More...
 
#define _DBUS_POLLERR   0x0008
 Error condition. More...
 
#define _DBUS_POLLHUP   0x0010
 Hung up. More...
 
#define _DBUS_POLLNVAL   0x0020
 Invalid request: fd not open. More...
 
#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b)   (memcmp (&(a), &(b), sizeof (double)) == 0)
 On x86 there is an 80-bit FPU, and if you do "a == b" it may have a or b in an 80-bit register, thus failing to compare the two 64-bit doubles for bitwise equality. More...
 
#define DBUS_DEFAULT_MESSAGE_UNIX_FDS   16
 
#define _DBUS_MAX_SUN_PATH_LENGTH   99
 Maximum length of the path to a UNIX domain socket, sockaddr_un::sun_path member. More...
 

Typedefs

typedef unsigned long dbus_pid_t
 A process ID. More...
 
typedef unsigned long dbus_uid_t
 A user ID. More...
 
typedef unsigned long dbus_gid_t
 A group ID. More...
 
typedef struct DBusAtomic DBusAtomic
 Opaque type representing an atomically-modifiable integer that can be used from multiple threads. More...
 
typedef int DBusPollable
 
typedef struct DBusDirIter DBusDirIter
 Opaque type for reading a directory listing. More...
 
typedef union DBusGUID DBusGUID
 Type representing a universally unique ID. More...
 
typedef struct DBusRLimit DBusRLimit
 

Enumerations

enum  DBusCredentialsAddFlags { DBUS_CREDENTIALS_ADD_FLAGS_USER_DATABASE = (1 << 0) , DBUS_CREDENTIALS_ADD_FLAGS_NONE = 0 }
 
enum  DBusLogFlags { DBUS_LOG_FLAGS_STDERR = (1 << 0) , DBUS_LOG_FLAGS_SYSTEM_LOG = (1 << 1) }
 
enum  DBusSystemLogSeverity { DBUS_SYSTEM_LOG_INFO , DBUS_SYSTEM_LOG_WARNING , DBUS_SYSTEM_LOG_SECURITY , DBUS_SYSTEM_LOG_ERROR }
 

Functions

void _dbus_abort (void)
 Aborts the program with SIGABRT (dumping core). More...
 
const char * _dbus_getenv (const char *varname)
 Wrapper for getenv(). More...
 
dbus_bool_t _dbus_clearenv (void)
 Wrapper for clearenv(). More...
 
dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs, const char *suffix, DBusList **dir_list)
 Split paths into a list of char strings. More...
 
dbus_bool_t _dbus_check_setuid (void)
 NOTE: If you modify this function, please also consider making the corresponding change in GLib. More...
 
char ** _dbus_get_environment (void)
 Gets a NULL-terminated list of key=value pairs from the environment. More...
 
dbus_bool_t _dbus_set_socket_nonblocking (DBusSocket fd, DBusError *error)
 Sets a file descriptor to be nonblocking. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_close_socket (DBusSocket *fd, DBusError *error)
 Closes a socket and invalidates it. More...
 
DBUS_PRIVATE_EXPORT int _dbus_read_socket (DBusSocket fd, DBusString *buffer, int count)
 Like _dbus_read(), but only works on sockets so is available on Windows. More...
 
DBUS_PRIVATE_EXPORT int _dbus_write_socket (DBusSocket fd, const DBusString *buffer, int start, int len)
 Like _dbus_write(), but only supports sockets and is thus available on Windows. More...
 
int _dbus_write_socket_two (DBusSocket fd, const DBusString *buffer1, int start1, int len1, const DBusString *buffer2, int start2, int len2)
 Like _dbus_write_two() but only works on sockets and is thus available on Windows. More...
 
int _dbus_read_socket_with_unix_fds (DBusSocket fd, DBusString *buffer, int count, int *fds, unsigned int *n_fds)
 Like _dbus_read_socket() but also tries to read unix fds from the socket. More...
 
DBUS_PRIVATE_EXPORT int _dbus_write_socket_with_unix_fds (DBusSocket fd, const DBusString *buffer, int start, int len, const int *fds, int n_fds)
 
int _dbus_write_socket_with_unix_fds_two (DBusSocket fd, const DBusString *buffer1, int start1, int len1, const DBusString *buffer2, int start2, int len2, const int *fds, int n_fds)
 
DBusSocket _dbus_connect_tcp_socket (const char *host, const char *port, const char *family, DBusError *error)
 Creates a socket and connects to a socket at the given host and port. More...
 
DBusSocket _dbus_connect_tcp_socket_with_nonce (const char *host, const char *port, const char *family, const char *noncefile, DBusError *error)
 
int _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, const char **retfamily, DBusSocket **fds_p, DBusError *error)
 Creates a socket and binds it to the given path, then listens on the socket. More...
 
DBusSocket _dbus_accept (DBusSocket listen_fd)
 Accepts a connection on a listening socket. More...
 
dbus_bool_t _dbus_read_credentials_socket (DBusSocket client_fd, DBusCredentials *credentials, DBusError *error)
 Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if available. More...
 
dbus_bool_t _dbus_send_credentials_socket (DBusSocket server_fd, DBusError *error)
 Sends a single nul byte with our UNIX credentials as ancillary data. More...
 
dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, const DBusString *username, DBusCredentialsAddFlags flags, DBusError *error)
 Adds the credentials corresponding to the given username. More...
 
dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
 Adds the most important credentials of the current process (the uid and pid) to the passed-in credentials object. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_append_user_from_current_process (DBusString *str)
 Append to the string the identity we would like to have when we authenticate, on UNIX this is the current process UID and on Windows something else, probably a Windows SID string. More...
 
dbus_bool_t _dbus_parse_unix_user_from_config (const DBusString *username, dbus_uid_t *uid_p)
 Parse a UNIX user from the bus config file. More...
 
dbus_bool_t _dbus_parse_unix_group_from_config (const DBusString *groupname, dbus_gid_t *gid_p)
 Parse a UNIX group from the bus config file. More...
 
dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids, DBusError *error)
 Gets all groups corresponding to the given UNIX user ID. More...
 
dbus_bool_t _dbus_unix_user_is_at_console (dbus_uid_t uid, DBusError *error)
 Checks to see if the UNIX user ID is at the console. More...
 
dbus_bool_t _dbus_unix_user_is_process_owner (dbus_uid_t uid)
 Checks to see if the UNIX user ID matches the UID of the process. More...
 
dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid)
 Checks to see if the Windows user SID matches the owner of the process. More...
 
dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory, DBusCredentials *credentials)
 Appends the directory in which a keyring for the given credentials should be stored. More...
 
dbus_bool_t _dbus_daemon_unpublish_session_bus_address (void)
 Clear the platform-specific centralized location where the session bus address is published. More...
 
dbus_bool_t _dbus_socket_can_pass_unix_fd (DBusSocket fd)
 Checks whether file descriptors may be passed via the socket. More...
 
DBUS_PRIVATE_EXPORT dbus_pid_t _dbus_resolve_pid_fd (int pid_fd)
 Resolve the PID from the PID FD, if any. More...
 
DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic)
 Atomically increments an integer. More...
 
DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic)
 Atomically decrement an integer. More...
 
DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic)
 Atomically get the value of an integer. More...
 
DBUS_PRIVATE_EXPORT void _dbus_atomic_set_zero (DBusAtomic *atomic)
 Atomically set the value of an integer to 0. More...
 
DBUS_PRIVATE_EXPORT void _dbus_atomic_set_nonzero (DBusAtomic *atomic)
 Atomically set the value of an integer to something nonzero. More...
 
DBUS_PRIVATE_EXPORT int _dbus_poll (DBusPollFD *fds, int n_fds, int timeout_milliseconds)
 Wrapper for poll(). More...
 
DBUS_PRIVATE_EXPORT void _dbus_sleep_milliseconds (int milliseconds)
 Sleeps the given number of milliseconds. More...
 
DBUS_PRIVATE_EXPORT void _dbus_get_monotonic_time (long *tv_sec, long *tv_usec)
 Get current time, as in gettimeofday(). More...
 
DBUS_PRIVATE_EXPORT void _dbus_get_real_time (long *tv_sec, long *tv_usec)
 Get current time, as in gettimeofday(). More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_create_directory (const DBusString *filename, DBusError *error)
 directory interface More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_ensure_directory (const DBusString *filename, DBusError *error)
 Creates a directory; succeeds if the directory is created or already existed. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_delete_directory (const DBusString *filename, DBusError *error)
 Removes a directory; Directory must be empty. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir, const DBusString *next_component)
 Appends the given filename to the given directory. More...
 
dbus_bool_t _dbus_string_get_dirname (const DBusString *filename, DBusString *dirname)
 Get the directory name from a complete filename. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_path_is_absolute (const DBusString *filename)
 Checks whether the filename is an absolute path. More...
 
dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs)
 Returns the standard directories for a session bus to look for service activation files. More...
 
dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs)
 Returns the standard directories for a system bus to look for service activation files. More...
 
dbus_bool_t _dbus_set_up_transient_session_servicedirs (DBusList **dirs, DBusError *error)
 Returns the standard directories for a session bus to look for transient service activation files. More...
 
dbus_bool_t _dbus_get_system_config_file (DBusString *str)
 Get the absolute path of the system.conf file (there is no system bus on Windows so this can just return FALSE and print a warning or something) More...
 
dbus_bool_t _dbus_get_session_config_file (DBusString *str)
 Get the absolute path of the session.conf file. More...
 
DBusDirIter_dbus_directory_open (const DBusString *filename, DBusError *error)
 Open a directory to iterate over. More...
 
dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter, DBusString *filename, DBusError *error)
 Get next file in the directory. More...
 
void _dbus_directory_close (DBusDirIter *iter)
 Closes a directory iteration. More...
 
dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
 Checks to make sure the given directory is private to the user. More...
 
DBUS_PRIVATE_EXPORT const char * _dbus_get_tmpdir (void)
 Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order. More...
 
_DBUS_WARN_UNUSED_RESULT dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer, int n_bytes, DBusError *error)
 Random numbers. More...
 
dbus_bool_t _dbus_generate_random_bytes (DBusString *str, int n_bytes, DBusError *error)
 Generates the given number of securely random bytes, using the best mechanism we can come up with. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_generate_random_ascii (DBusString *str, int n_bytes, DBusError *error)
 Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII subset. More...
 
DBUS_PRIVATE_EXPORT const char * _dbus_error_from_errno (int error_number)
 Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name. More...
 
DBUS_PRIVATE_EXPORT const char * _dbus_error_from_system_errno (void)
 Converts the current system errno value into a DBusError name. More...
 
int _dbus_get_low_level_socket_errno (void)
 
int _dbus_save_socket_errno (void)
 
void _dbus_restore_socket_errno (int saved_errno)
 
void _dbus_set_errno_to_zero (void)
 Assign 0 to the global errno variable. More...
 
dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (int e)
 See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted) More...
 
dbus_bool_t _dbus_get_is_errno_enomem (int e)
 See if errno is ENOMEM. More...
 
dbus_bool_t _dbus_get_is_errno_eintr (int e)
 See if errno is EINTR. More...
 
dbus_bool_t _dbus_get_is_errno_epipe (int e)
 See if errno is EPIPE. More...
 
dbus_bool_t _dbus_get_is_errno_etoomanyrefs (int e)
 See if errno is ETOOMANYREFS. More...
 
DBUS_PRIVATE_EXPORT const char * _dbus_strerror_from_errno (void)
 Get error message from errno. More...
 
void _dbus_disable_sigpipe (void)
 signal (SIGPIPE, SIG_IGN); More...
 
DBUS_PRIVATE_EXPORT void _dbus_exit (int code) _DBUS_GNUC_NORETURN
 Exit the process, returning the given value. More...
 
DBUS_PRIVATE_EXPORT int _dbus_printf_string_upper_bound (const char *format, va_list args)
 Measure the length of the given format string and arguments, not including the terminating nul. More...
 
dbus_bool_t _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error)
 stat() wrapper. More...
 
DBusSocket _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...
 
DBusSocket _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...
 
DBusSocket _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...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_socketpair (DBusSocket *fd1, DBusSocket *fd2, dbus_bool_t blocking, DBusError *error)
 Creates pair of connect sockets (as in socketpair()). More...
 
DBUS_PRIVATE_EXPORT void _dbus_print_backtrace (void)
 On GNU libc systems, print a crude backtrace to stderr. More...
 
dbus_bool_t _dbus_become_daemon (const DBusString *pidfile, DBusPipe *print_pid_pipe, DBusError *error, dbus_bool_t keep_umask)
 Does the chdir, fork, setsid, etc. More...
 
dbus_bool_t _dbus_verify_daemon_user (const char *user)
 Verify that after the fork we can successfully change to this user. More...
 
dbus_bool_t _dbus_change_to_daemon_user (const char *user, DBusError *error)
 Changes the user and group the bus is running as. More...
 
dbus_bool_t _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, DBusPipe *print_pid_pipe, dbus_pid_t pid_to_write, DBusError *error)
 Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL). More...
 
dbus_bool_t _dbus_command_for_pid (unsigned long pid, DBusString *str, int max_len, DBusError *error)
 Get a printable string describing the command used to execute the process with pid. More...
 
DBUS_PRIVATE_EXPORT void _dbus_init_system_log (const char *tag, DBusLogFlags flags)
 Initialize the system log. More...
 
DBUS_PRIVATE_EXPORT void _dbus_log (DBusSystemLogSeverity severity, const char *msg,...)
 Log a message to the system log file (e.g. More...
 
DBUS_PRIVATE_EXPORT void _dbus_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
 Log a message to the system log file (e.g. More...
 
dbus_bool_t _dbus_get_autolaunch_address (const char *scope, DBusString *address, DBusError *error)
 Returns the address of a new session bus. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported, DBusString *address, DBusError *error)
 Determines the address of the session bus by querying a platform-specific method. More...
 
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id, dbus_bool_t create_if_not_found, DBusError *error)
 Reads the uuid of the machine we're running on from the dbus configuration. More...
 
dbus_bool_t _dbus_threads_init_platform_specific (void)
 Initialize threads as in dbus_threads_init_default(), appropriately for the platform. More...
 
void _dbus_threads_lock_platform_specific (void)
 Lock a static mutex used to protect _dbus_threads_init_platform_specific(). More...
 
void _dbus_threads_unlock_platform_specific (void)
 Undo _dbus_threads_lock_platform_specific(). More...
 
unsigned long _dbus_pid_for_log (void)
 The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not for other purposes. More...
 
DBUS_PRIVATE_EXPORT dbus_pid_t _dbus_getpid (void)
 Gets our process ID. More...
 
DBUS_PRIVATE_EXPORT dbus_uid_t _dbus_getuid (void)
 Gets our UID. More...
 
DBUS_PRIVATE_EXPORT void _dbus_flush_caches (void)
 Called when the bus daemon is signaled to reload its configuration; any caches should be nuked. More...
 
dbus_bool_t _dbus_replace_install_prefix (DBusString *path)
 Replace the DBUS_PREFIX in the given path, in-place, by the current D-Bus installation directory. More...
 
DBusRLimit * _dbus_rlimit_save_fd_limit (DBusError *error)
 
dbus_bool_t _dbus_rlimit_raise_fd_limit (DBusError *error)
 
dbus_bool_t _dbus_rlimit_restore_fd_limit (DBusRLimit *saved, DBusError *error)
 
void _dbus_rlimit_free (DBusRLimit *lim)
 
void _dbus_daemon_report_ready (void)
 Report to a service manager that the daemon calling this function is ready for use. More...
 
void _dbus_daemon_report_reloading (void)
 Report to a service manager that the daemon calling this function is reloading configuration. More...
 
void _dbus_daemon_report_reloaded (void)
 Report to a service manager that the daemon calling this function is reloading configuration. More...
 
void _dbus_daemon_report_stopping (void)
 Report to a service manager that the daemon calling this function is shutting down. More...
 
dbus_bool_t _dbus_inet_sockaddr_to_string (const void *sockaddr_pointer, size_t len, char *string, size_t string_len, const char **family_name, dbus_uint16_t *port, DBusError *error)
 
void _dbus_set_error_with_inet_sockaddr (DBusError *error, const void *sockaddr_pointer, size_t len, const char *description, int saved_errno)
 
void _dbus_combine_tcp_errors (DBusList **sources, const char *summary, const char *host, const char *port, DBusError *dest)
 

Detailed Description

Internal system-dependent API available on UNIX and Windows.

The system-dependent API has a dual purpose. First, it encapsulates all usage of operating system APIs for ease of auditing and to avoid cluttering the rest of the code with bizarre OS quirks and headers. Second, it abstracts different operating system APIs for portability.

Macro Definition Documentation

◆ _DBUS_DOUBLES_BITWISE_EQUAL

#define _DBUS_DOUBLES_BITWISE_EQUAL (   a,
 
)    (memcmp (&(a), &(b), sizeof (double)) == 0)

On x86 there is an 80-bit FPU, and if you do "a == b" it may have a or b in an 80-bit register, thus failing to compare the two 64-bit doubles for bitwise equality.

So this macro compares the two doubles bitwise.

Definition at line 653 of file dbus-sysdeps.h.

◆ _DBUS_MAX_SUN_PATH_LENGTH

#define _DBUS_MAX_SUN_PATH_LENGTH   99

Maximum length of the path to a UNIX domain socket, sockaddr_un::sun_path member.

POSIX requires that all systems support at least 100 bytes here, including the nul termination. We use 99 for the max value to allow for the nul.

We could probably also do sizeof (addr.sun_path) but this way we are the same on all platforms which is probably a good idea.

Definition at line 764 of file dbus-sysdeps.h.

◆ _DBUS_POLLERR

#define _DBUS_POLLERR   0x0008

Error condition.

Definition at line 450 of file dbus-sysdeps.h.

◆ _DBUS_POLLHUP

#define _DBUS_POLLHUP   0x0010

Hung up.

Definition at line 452 of file dbus-sysdeps.h.

◆ _DBUS_POLLIN

#define _DBUS_POLLIN   0x0001

There is data to read.

Definition at line 444 of file dbus-sysdeps.h.

◆ _DBUS_POLLNVAL

#define _DBUS_POLLNVAL   0x0020

Invalid request: fd not open.

Definition at line 454 of file dbus-sysdeps.h.

◆ _DBUS_POLLOUT

#define _DBUS_POLLOUT   0x0004

Writing now will not block.

Definition at line 448 of file dbus-sysdeps.h.

◆ _DBUS_POLLPRI

#define _DBUS_POLLPRI   0x0002

There is urgent data to read.

Definition at line 446 of file dbus-sysdeps.h.

◆ DBUS_DEFAULT_MESSAGE_UNIX_FDS

#define DBUS_DEFAULT_MESSAGE_UNIX_FDS   16

Definition at line 719 of file dbus-sysdeps.h.

◆ DBUS_GID_FORMAT

#define DBUS_GID_FORMAT   "%lu"

an appropriate printf format for dbus_gid_t

Definition at line 157 of file dbus-sysdeps.h.

◆ DBUS_GID_UNSET

#define DBUS_GID_UNSET   ((dbus_gid_t) -1)

an invalid GID used to represent an uninitialized dbus_gid_t field

Definition at line 150 of file dbus-sysdeps.h.

◆ DBUS_PID_FORMAT

#define DBUS_PID_FORMAT   "%lu"

an appropriate printf format for dbus_pid_t

Definition at line 153 of file dbus-sysdeps.h.

◆ DBUS_PID_UNSET

#define DBUS_PID_UNSET   ((dbus_pid_t) -1)

an invalid PID used to represent an uninitialized dbus_pid_t field

Definition at line 146 of file dbus-sysdeps.h.

◆ DBUS_POLLABLE_FORMAT

#define DBUS_POLLABLE_FORMAT   "d"

Definition at line 393 of file dbus-sysdeps.h.

◆ DBUS_SOCKET_FORMAT

#define DBUS_SOCKET_FORMAT   "d"

Definition at line 186 of file dbus-sysdeps.h.

◆ DBUS_SOCKET_INIT

#define DBUS_SOCKET_INIT   { -1 }

Definition at line 187 of file dbus-sysdeps.h.

◆ DBUS_UID_FORMAT

#define DBUS_UID_FORMAT   "%lu"

an appropriate printf format for dbus_uid_t

Definition at line 155 of file dbus-sysdeps.h.

◆ DBUS_UID_UNSET

#define DBUS_UID_UNSET   ((dbus_uid_t) -1)

an invalid UID used to represent an uninitialized dbus_uid_t field

Definition at line 148 of file dbus-sysdeps.h.

Typedef Documentation

◆ dbus_gid_t

typedef unsigned long dbus_gid_t

A group ID.

Definition at line 143 of file dbus-sysdeps.h.

◆ dbus_pid_t

typedef unsigned long dbus_pid_t

A process ID.

Definition at line 139 of file dbus-sysdeps.h.

◆ dbus_uid_t

typedef unsigned long dbus_uid_t

A user ID.

Definition at line 141 of file dbus-sysdeps.h.

◆ DBusAtomic

typedef struct DBusAtomic DBusAtomic

Opaque type representing an atomically-modifiable integer that can be used from multiple threads.

Definition at line 334 of file dbus-sysdeps.h.

◆ DBusDirIter

typedef struct DBusDirIter DBusDirIter

Opaque type for reading a directory listing.

Definition at line 503 of file dbus-sysdeps.h.

◆ DBusGUID

typedef union DBusGUID DBusGUID

Type representing a universally unique ID.

Definition at line 667 of file dbus-sysdeps.h.

◆ DBusPollable

typedef int DBusPollable

Definition at line 392 of file dbus-sysdeps.h.

◆ DBusRLimit

typedef struct DBusRLimit DBusRLimit

Definition at line 721 of file dbus-sysdeps.h.

Enumeration Type Documentation

◆ DBusCredentialsAddFlags

enum DBusCredentialsAddFlags

Definition at line 284 of file dbus-sysdeps.h.

◆ DBusLogFlags

enum DBusLogFlags

Definition at line 623 of file dbus-sysdeps.h.

◆ DBusSystemLogSeverity

enum DBusSystemLogSeverity

Definition at line 632 of file dbus-sysdeps.h.

Function Documentation

◆ _dbus_abort()

DBUS_PRIVATE_EXPORT void _dbus_abort ( void  )

Aborts the program with SIGABRT (dumping core).

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

Referenced by _dbus_get_tmpdir(), _dbus_real_assert(), _dbus_real_assert_not_reached(), dbus_malloc(), dbus_malloc0(), and dbus_realloc().

◆ _dbus_accept()

DBusSocket _dbus_accept ( DBusSocket  listen_fd)

Accepts a connection on a listening socket.

Handles EINTR for you.

This will enable FD_CLOEXEC for the returned socket.

Parameters
listen_fdthe listen file descriptor
Returns
the connection fd of the client, or -1 on error

Handles EINTR for you.

Parameters
listen_fdthe listen file descriptor
Returns
the connection fd of the client, or -1 on error

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

References _dbus_fd_set_close_on_exec(), and NULL.

◆ _dbus_append_keyring_directory_for_credentials()

dbus_bool_t _dbus_append_keyring_directory_for_credentials ( DBusString directory,
DBusCredentials credentials 
)

Appends the directory in which a keyring for the given credentials should be stored.

The credentials should have either a Windows or UNIX user in them. The directory should be an absolute path.

On UNIX the directory is ~/.dbus-keyrings while on Windows it should probably be something else, since the dotfile convention is not normal on Windows.

Parameters
directorystring to append directory to
credentialscredentials the directory should be for
Returns
FALSE on no memory

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

References _dbus_assert, _dbus_concat_dir_and_file(), _dbus_credentials_are_anonymous(), _dbus_credentials_get_unix_uid(), _dbus_getenv(), _dbus_homedir_from_uid(), _dbus_string_append(), _dbus_string_copy(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_get_length(), _dbus_string_init(), _dbus_string_init_const(), _dbus_string_set_length(), _dbus_warn(), DBUS_UID_UNSET, FALSE, NULL, and TRUE.

Referenced by _dbus_keyring_new_for_credentials().

◆ _dbus_append_user_from_current_process()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_append_user_from_current_process ( DBusString str)

Append to the string the identity we would like to have when we authenticate, on UNIX this is the current process UID and on Windows something else, probably a Windows SID string.

No escaping is required, that is done in dbus-auth.c. The username here need not be anything human-readable, it can be the machine-readable form i.e. a user id.

Parameters
strthe string to append to
Returns
FALSE on no memory

No escaping is required, that is done in dbus-auth.c. The username here need not be anything human-readable, it can be the machine-readable form i.e. a user id.

Parameters
strthe string to append to
Returns
FALSE on no memory

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

References _dbus_geteuid(), _dbus_getpid(), _dbus_string_append(), _dbus_string_append_uint(), FALSE, and NULL.

◆ _dbus_atomic_dec()

DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_dec ( DBusAtomic atomic)

Atomically decrement an integer.

Parameters
atomicpointer to the integer to decrement
Returns
the value before decrementing

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

References DBusAtomic::value.

Referenced by _dbus_babysitter_unref(), _dbus_connection_unref_unlocked(), _dbus_pending_call_unref_and_unlock(), _dbus_server_unref_unlocked(), dbus_connection_unref(), dbus_free(), dbus_message_unref(), dbus_pending_call_unref(), dbus_server_ref(), and dbus_server_unref().

◆ _dbus_atomic_get()

DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_get ( DBusAtomic atomic)

Atomically get the value of an integer.

It may change at any time thereafter, so this is mostly only useful for assertions.

Parameters
atomicpointer to the integer to get
Returns
the value at this moment

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

References DBusAtomic::value.

Referenced by _dbus_connection_close_if_only_one_ref().

◆ _dbus_atomic_inc()

DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_inc ( DBusAtomic atomic)

◆ _dbus_atomic_set_nonzero()

DBUS_PRIVATE_EXPORT void _dbus_atomic_set_nonzero ( DBusAtomic atomic)

Atomically set the value of an integer to something nonzero.

Parameters
atomicpointer to the integer to set

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

References DBusAtomic::value.

Referenced by dbus_connection_set_change_sigpipe().

◆ _dbus_atomic_set_zero()

DBUS_PRIVATE_EXPORT void _dbus_atomic_set_zero ( DBusAtomic atomic)

Atomically set the value of an integer to 0.

Parameters
atomicpointer to the integer to set

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

References DBusAtomic::value.

◆ _dbus_become_daemon()

dbus_bool_t _dbus_become_daemon ( const DBusString pidfile,
DBusPipe print_pid_pipe,
DBusError error,
dbus_bool_t  keep_umask 
)

Does the chdir, fork, setsid, etc.

to become a daemon process.

Parameters
pidfileNULL, or pidfile to create
print_pid_pipepipe to print daemon's pid to, or -1 for none
errorreturn location for errors
keep_umaskTRUE to keep the original umask
Returns
FALSE on failure

to become a daemon process.

Parameters
pidfileNULL, or pidfile to create
print_pid_pipefile descriptor to print daemon's pid to, or -1 for none
errorreturn location for errors
keep_umaskTRUE to keep the original umask
Returns
FALSE on failure

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

References _dbus_error_from_errno(), DBUS_ERROR_FAILED, DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), and FALSE.

◆ _dbus_change_to_daemon_user()

dbus_bool_t _dbus_change_to_daemon_user ( const char *  user,
DBusError error 
)

Changes the user and group the bus is running as.

Parameters
userthe user to become
errorreturn location for errors
Returns
FALSE on failure

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

References _dbus_error_from_errno(), _dbus_get_user_id_and_primary_group(), _dbus_string_init_const(), _dbus_warn(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

◆ _dbus_check_dir_is_private_to_user()

dbus_bool_t _dbus_check_dir_is_private_to_user ( DBusString dir,
DBusError error 
)

Checks to make sure the given directory is private to the user.

Parameters
dirthe name of the directory
errorerror return
Returns
FALSE on failure

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

References _dbus_error_from_errno(), _dbus_string_get_const_data(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

◆ _dbus_check_setuid()

dbus_bool_t _dbus_check_setuid ( void  )

NOTE: If you modify this function, please also consider making the corresponding change in GLib.

See glib/gutils.c:g_check_setuid().

Returns TRUE if the current process was executed as setuid (or an equivalent __libc_enable_secure is available). See: http://osdir.com/ml/linux.lfs.hardened/2007-04/msg00032.html

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

References FALSE, and TRUE.

Referenced by _dbus_get_autolaunch_address(), _dbus_getenv(), _dbus_keyring_new_for_credentials(), _dbus_lookup_launchd_socket(), and _dbus_threads_init_platform_specific().

◆ _dbus_clearenv()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_clearenv ( void  )

Wrapper for clearenv().

Returns
TRUE on success.

Definition at line 213 of file dbus-sysdeps.c.

References FALSE, NULL, and TRUE.

◆ _dbus_close_socket()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_close_socket ( DBusSocket fd,
DBusError error 
)

Closes a socket and invalidates it.

Should not be used on non-socket file descriptors or handles.

If an error is detected, this function returns FALSE and sets the error, but the socket is still closed and invalidated. Callers can use the error in a diagnostic message, but should not retry closing the socket.

Parameters
fdthe socket
errorreturn location for an error
Returns
FALSE if error is set
Parameters
fdthe file descriptor
errorerror object
Returns
FALSE if error set

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

References _dbus_assert, _dbus_close(), _dbus_error_from_errno(), _dbus_strerror_from_errno(), dbus_set_error(), and NULL.

Referenced by _dbus_server_listen_platform_specific(), and _dbus_server_new_for_tcp_socket().

◆ _dbus_combine_tcp_errors()

void _dbus_combine_tcp_errors ( DBusList **  sources,
const char *  summary,
const char *  host,
const char *  port,
DBusError dest 
)

Definition at line 913 of file dbus-sysdeps.c.

◆ _dbus_command_for_pid()

dbus_bool_t _dbus_command_for_pid ( unsigned long  pid,
DBusString str,
int  max_len,
DBusError error 
)

Get a printable string describing the command used to execute the process with pid.

This string should only be used for informative purposes such as logging; it may not be trusted.

The command is guaranteed to be printable ASCII and no longer than max_len.

Parameters
pidProcess id
strAppend command to this string
max_lenMaximum length of returned command
errorreturn location for errors
Returns
FALSE on error

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

References _dbus_close(), _dbus_error_from_errno(), _dbus_read(), _dbus_string_append_printf(), _dbus_string_copy(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_get_length(), _dbus_string_init(), DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), FALSE, NULL, and TRUE.

◆ _dbus_concat_dir_and_file()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_concat_dir_and_file ( DBusString dir,
const DBusString next_component 
)

Appends the given filename to the given directory.

Parameters
dirthe directory name
next_componentthe filename
Returns
TRUE on success
Parameters
dirthe directory name
next_componentthe filename
Returns
TRUE on success

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

References _dbus_string_append_byte(), _dbus_string_copy(), _dbus_string_get_byte(), _dbus_string_get_length(), _dbus_string_shorten(), FALSE, and TRUE.

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_get_standard_session_servicedirs(), _dbus_server_listen_unix_socket(), and _dbus_split_paths_and_append().

◆ _dbus_connect_exec()

DBusSocket _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
a valid socket on success or an invalid socket on error

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

◆ _dbus_connect_tcp_socket()

DBusSocket _dbus_connect_tcp_socket ( const char *  host,
const char *  port,
const char *  family,
DBusError error 
)

Creates a socket and connects to a socket at the given host and port.

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

This will set FD_CLOEXEC for the socket returned

Parameters
hostthe host name to connect to
portthe port to connect to
familythe address family to listen on, NULL for all
errorreturn location for error code
Returns
connection file descriptor or -1 on error

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

Parameters
hostthe host name to connect to
portthe port to connect to
familythe address family to listen on, NULL for all
errorreturn location for error code
Returns
connection file descriptor or -1 on error

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

◆ _dbus_connect_tcp_socket_with_nonce()

DBusSocket _dbus_connect_tcp_socket_with_nonce ( const char *  host,
const char *  port,
const char *  family,
const char *  noncefile,
DBusError error 
)

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

◆ _dbus_connect_unix_socket()

DBusSocket _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
a valid socket on success or an invalid socket on error

The socket is returned, and is set up as nonblocking.

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
a valid socket on success or an invalid socket on error

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

◆ _dbus_create_directory()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_create_directory ( const DBusString filename,
DBusError error 
)

directory interface

directory interface

Unlike _dbus_ensure_directory(), this only succeeds if the directory is genuinely newly-created.

Parameters
filenamedirectory filename
errorinitialized error object
Returns
TRUE on success

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

References _dbus_strerror_from_errno(), _dbus_string_get_const_data(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

◆ _dbus_credentials_add_from_current_process()

dbus_bool_t _dbus_credentials_add_from_current_process ( DBusCredentials credentials)

Adds the most important credentials of the current process (the uid and pid) to the passed-in credentials object.

The group vector is not included because it is rarely needed. The Linux security label is not included because it is rarely needed, it requires reading /proc, and the LSM API doesn't actually guarantee that the string seen in /proc is comparable to the strings found in SO_PEERSEC results.

Parameters
credentialscredentials to add to
Returns
FALSE if no memory; does not properly roll back on failure, so only some credentials may have been added

Adds the most important credentials of the current process (the uid and pid) to the passed-in credentials object.

Parameters
credentialscredentials to add to
Returns
FALSE if no memory; does not properly roll back on failure, so only some credentials may have been added

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

References _dbus_credentials_add_pid(), _dbus_credentials_add_windows_sid(), _dbus_getpid(), FALSE, NULL, and TRUE.

Referenced by _dbus_credentials_new_from_current_process(), and _dbus_keyring_new_for_credentials().

◆ _dbus_credentials_add_from_user()

dbus_bool_t _dbus_credentials_add_from_user ( DBusCredentials credentials,
const DBusString username,
DBusCredentialsAddFlags  flags,
DBusError error 
)

Adds the credentials corresponding to the given username.

Parameters
credentialscredentials to fill in
usernamethe username
Returns
TRUE if the username existed and we got some credentials

Used among other purposes to parses a desired identity provided from a client in the auth protocol. On UNIX this means parsing a UID, on Windows probably parsing an SID string.

Parameters
credentialscredentials to fill in
usernamethe username
Returns
TRUE if the username existed and we got some credentials

Definition at line 2314 of file dbus-sysdeps-win.c.

References _dbus_credentials_add_windows_sid(), _dbus_is_a_number(), _dbus_string_get_const_data(), DBUS_UID_UNSET, FALSE, and TRUE.

◆ _dbus_daemon_report_ready()

void _dbus_daemon_report_ready ( void  )

Report to a service manager that the daemon calling this function is ready for use.

This is currently only implemented for systemd.

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

Referenced by _dbus_daemon_report_reloaded().

◆ _dbus_daemon_report_reloaded()

void _dbus_daemon_report_reloaded ( void  )

Report to a service manager that the daemon calling this function is reloading configuration.

This is currently only implemented for systemd.

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

References _dbus_daemon_report_ready().

◆ _dbus_daemon_report_reloading()

void _dbus_daemon_report_reloading ( void  )

Report to a service manager that the daemon calling this function is reloading configuration.

This is currently only implemented for systemd.

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

◆ _dbus_daemon_report_stopping()

void _dbus_daemon_report_stopping ( void  )

Report to a service manager that the daemon calling this function is shutting down.

This is currently only implemented for systemd.

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

◆ _dbus_daemon_unpublish_session_bus_address()

dbus_bool_t _dbus_daemon_unpublish_session_bus_address ( void  )

Clear the platform-specific centralized location where the session bus address is published.

This must only be called if DBusServer::published_address is TRUE, which is be the case if and only if platform-specific code has published the address centrally.

On Windows, this is implemented by closing a global shared memory segment.

On Unix, the session bus address is not published in a centralized location by libdbus, so this function does nothing. The closest equivalent on Unix is that the session bus address is published by the dbus-launch tool, and unpublished automatically when the dbus-launch tool exits.

Returns
NULL in case of error

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

References FALSE, NULL, and TRUE.

◆ _dbus_delete_directory()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_delete_directory ( const DBusString filename,
DBusError error 
)

Removes a directory; Directory must be empty.

Parameters
filenamedirectory filename
errorinitialized error object
Returns
TRUE on success

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

References _dbus_string_get_const_data(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, and TRUE.

◆ _dbus_directory_close()

void _dbus_directory_close ( DBusDirIter iter)

Closes a directory iteration.

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

References DBusDirIter::d, and dbus_free().

◆ _dbus_directory_get_next_file()

dbus_bool_t _dbus_directory_get_next_file ( DBusDirIter iter,
DBusString filename,
DBusError error 
)

Get next file in the directory.

Will not return "." or ".." on UNIX. If an error occurs, the contents of "filename" are undefined. The error is never set if the function succeeds.

This function is not re-entrant, and not necessarily thread-safe. Only use it for test code or single-threaded utilities.

Parameters
iterthe iterator
filenamestring to be set to the next file in the dir
errorreturn location for error
Returns
TRUE if filename was filled in with a new filename

Will not return "." or ".." on UNIX. If an error occurs, the contents of "filename" are undefined. The error is never set if the function succeeds.

Parameters
iterthe iterator
filenamestring to be set to the next file in the dir
errorreturn location for error
Returns
TRUE if filename was filled in with a new filename

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

References _dbus_error_from_errno(), _dbus_string_append(), _dbus_string_set_length(), DBusDirIter::d, DBUS_ERROR_NO_MEMORY, dbus_set_error(), FALSE, and TRUE.

◆ _dbus_directory_open()

DBusDirIter * _dbus_directory_open ( const DBusString filename,
DBusError error 
)

Open a directory to iterate over.

Parameters
filenamethe directory name
errorexception return object or NULL
Returns
new iterator, or NULL on error

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

References _dbus_error_from_errno(), _dbus_string_append(), _dbus_string_ends_with_c_str(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_init_from_string(), DBusDirIter::d, DBUS_ERROR_NO_MEMORY, dbus_free(), dbus_new0, dbus_set_error(), FALSE, NULL, and TRUE.

◆ _dbus_disable_sigpipe()

void _dbus_disable_sigpipe ( void  )

signal (SIGPIPE, SIG_IGN);

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

◆ _dbus_ensure_directory()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_ensure_directory ( const DBusString filename,
DBusError error 
)

Creates a directory; succeeds if the directory is created or already existed.

Parameters
filenamedirectory filename
errorinitialized error object
Returns
TRUE on success

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

References _dbus_strerror_from_errno(), _dbus_string_get_const_data(), DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

◆ _dbus_error_from_errno()

DBUS_PRIVATE_EXPORT const char * _dbus_error_from_errno ( int  error_number)

◆ _dbus_error_from_system_errno()

DBUS_PRIVATE_EXPORT const char * _dbus_error_from_system_errno ( void  )

Converts the current system errno value into a DBusError name.

Returns
an error name

Definition at line 693 of file dbus-sysdeps.c.

References _dbus_error_from_errno().

◆ _dbus_exit()

DBUS_PRIVATE_EXPORT void _dbus_exit ( int  code)

Exit the process, returning the given value.

Parameters
codethe exit code

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

◆ _dbus_flush_caches()

DBUS_PRIVATE_EXPORT void _dbus_flush_caches ( void  )

Called when the bus daemon is signaled to reload its configuration; any caches should be nuked.

Of course any caches that need explicit reload are probably broken, but c'est la vie.

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

References _dbus_user_database_flush_system().

◆ _dbus_generate_random_ascii()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_generate_random_ascii ( DBusString str,
int  n_bytes,
DBusError error 
)

Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII subset.

Parameters
strthe string
n_bytesthe number of random ASCII bytes to append to string
errorlocation to store reason for failure
Returns
TRUE on success, FALSE if no memory or other failure

Definition at line 561 of file dbus-sysdeps.c.

References _dbus_assert, _dbus_generate_random_bytes(), _dbus_string_get_byte(), _dbus_string_get_length(), _dbus_string_set_byte(), _dbus_string_validate_ascii(), FALSE, and TRUE.

Referenced by _dbus_string_save_to_file().

◆ _dbus_generate_random_bytes()

dbus_bool_t _dbus_generate_random_bytes ( DBusString str,
int  n_bytes,
DBusError error 
)

Generates the given number of securely random bytes, using the best mechanism we can come up with.

Parameters
strthe string
n_bytesthe number of random bytes to append to string
errorlocation to store reason for failure
Returns
TRUE on success, FALSE on error

Generates the given number of securely random bytes, using the best mechanism we can come up with.

Parameters
strthe string
n_bytesthe number of random bytes to append to string
errorlocation to store reason for failure
Returns
TRUE on success

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

References _dbus_close(), _dbus_error_from_errno(), _dbus_read(), _dbus_string_get_data_len(), _dbus_string_get_length(), _dbus_string_lengthen(), _dbus_string_set_length(), DBUS_ERROR_IO_ERROR, dbus_set_error(), FALSE, NULL, and TRUE.

Referenced by _dbus_generate_random_ascii(), and _dbus_generate_random_bytes_buffer().

◆ _dbus_generate_random_bytes_buffer()

_DBUS_WARN_UNUSED_RESULT dbus_bool_t _dbus_generate_random_bytes_buffer ( char *  buffer,
int  n_bytes,
DBusError error 
)

Random numbers.

Random numbers.

Parameters
bufferan allocated buffer
n_bytesthe number of bytes in buffer to write to
errorlocation to store reason for failure
Returns
TRUE on success

Definition at line 527 of file dbus-sysdeps.c.

References _dbus_generate_random_bytes(), _dbus_string_copy_to_buffer(), _dbus_string_free(), _dbus_string_init(), FALSE, and TRUE.

Referenced by _dbus_generate_uuid().

◆ _dbus_get_autolaunch_address()

dbus_bool_t _dbus_get_autolaunch_address ( const char *  scope,
DBusString address,
DBusError error 
)

Returns the address of a new session bus.

If successful, returns TRUE and appends the address to address. If a failure happens, returns FALSE and sets an error in error.

Parameters
scopescope of autolaunch (Windows only)
addressa DBusString where the address can be stored
errora DBusError to store the error in case of failure
Returns
TRUE on success, FALSE if an error happened

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

References _dbus_assert, _dbus_check_setuid(), _dbus_get_local_machine_uuid_encoded(), _dbus_getenv(), _DBUS_N_ELEMENTS, _dbus_string_append_printf(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_get_data(), _dbus_string_get_length(), _dbus_string_init(), DBUS_ERROR_FAILED, DBUS_ERROR_NO_MEMORY, DBUS_ERROR_NOT_SUPPORTED, DBUS_ERROR_SPAWN_CHILD_EXITED, DBUS_ERROR_TIMEOUT, dbus_set_error(), dbus_set_error_const(), FALSE, NULL, and TRUE.

◆ _dbus_get_environment()

char ** _dbus_get_environment ( void  )

Gets a NULL-terminated list of key=value pairs from the environment.

Use dbus_free_string_array to free it.

Returns
the environment or NULL on OOM

Definition at line 55 of file dbus-sysdeps-util.c.

References _dbus_assert, _dbus_strdup(), dbus_free_string_array(), dbus_new0, and NULL.

◆ _dbus_get_is_errno_eagain_or_ewouldblock()

dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock ( int  e)

See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted)

Returns
TRUE if e == EAGAIN or e == EWOULDBLOCK

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

◆ _dbus_get_is_errno_eintr()

dbus_bool_t _dbus_get_is_errno_eintr ( int  e)

See if errno is EINTR.

Returns
TRUE if e == EINTR

Definition at line 726 of file dbus-sysdeps.c.

◆ _dbus_get_is_errno_enomem()

dbus_bool_t _dbus_get_is_errno_enomem ( int  e)

See if errno is ENOMEM.

Returns
TRUE if e == ENOMEM

Definition at line 716 of file dbus-sysdeps.c.

◆ _dbus_get_is_errno_epipe()

dbus_bool_t _dbus_get_is_errno_epipe ( int  e)

See if errno is EPIPE.

Returns
TRUE if errno == EPIPE

Definition at line 736 of file dbus-sysdeps.c.

◆ _dbus_get_is_errno_etoomanyrefs()

dbus_bool_t _dbus_get_is_errno_etoomanyrefs ( int  e)

See if errno is ETOOMANYREFS.

Returns
TRUE if errno == ETOOMANYREFS

Definition at line 746 of file dbus-sysdeps.c.

References FALSE.

◆ _dbus_get_low_level_socket_errno()

int _dbus_get_low_level_socket_errno ( void  )

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

◆ _dbus_get_monotonic_time()

DBUS_PRIVATE_EXPORT void _dbus_get_monotonic_time ( long *  tv_sec,
long *  tv_usec 
)

Get current time, as in gettimeofday().

Use the monotonic clock if available, to avoid problems when the system time changes.

Parameters
tv_secreturn location for number of seconds
tv_usecreturn location for number of microseconds

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

References _dbus_get_real_time(), and NULL.

◆ _dbus_get_real_time()

DBUS_PRIVATE_EXPORT void _dbus_get_real_time ( long *  tv_sec,
long *  tv_usec 
)

Get current time, as in gettimeofday().

Never uses the monotonic clock.

Parameters
tv_secreturn location for number of seconds
tv_usecreturn location for number of microseconds

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

References DBUS_INT64_CONSTANT, dbus_uint64_t, and NULL.

Referenced by _dbus_generate_uuid(), and _dbus_get_monotonic_time().

◆ _dbus_get_session_config_file()

dbus_bool_t _dbus_get_session_config_file ( DBusString str)

Get the absolute path of the session.conf file.

Parameters
strthe string to append to, which must be empty on entry
Returns
FALSE if no memory

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

References _dbus_assert, _dbus_string_append(), and _dbus_string_get_length().

◆ _dbus_get_standard_session_servicedirs()

dbus_bool_t _dbus_get_standard_session_servicedirs ( DBusList **  dirs)

Returns the standard directories for a session bus to look for service activation files.

On UNIX this should be the standard xdg freedesktop.org data directories:

XDG_DATA_HOME=${XDG_DATA_HOME-$HOME/.local/share} XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}

and

DBUS_DATADIR

Parameters
dirsthe directory list we are returning
Returns
FALSE on OOM

On Windows this should be data directories:

CommonProgramFiles%/dbus

and

relocated DBUS_DATADIR

Parameters
dirsthe directory list we are returning
Returns
FALSE on OOM

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

References _dbus_concat_dir_and_file(), _dbus_getenv(), _dbus_homedir_from_current_process(), _dbus_replace_install_prefix(), _dbus_split_paths_and_append(), _dbus_string_append(), _dbus_string_free(), _dbus_string_get_const_data(), _dbus_string_init(), _dbus_string_init_const(), FALSE, NULL, and TRUE.

◆ _dbus_get_standard_system_servicedirs()

dbus_bool_t _dbus_get_standard_system_servicedirs ( DBusList **  dirs)

Returns the standard directories for a system bus to look for service activation files.

On UNIX this should be the standard xdg freedesktop.org data directories:

XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}

and

DBUS_DATADIR

On Windows there is no system bus and this function can return nothing.

Parameters
dirsthe directory list we are returning
Returns
FALSE on OOM

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

References _dbus_split_paths_and_append(), _dbus_string_init_const(), NULL, and TRUE.

◆ _dbus_get_system_config_file()

dbus_bool_t _dbus_get_system_config_file ( DBusString str)

Get the absolute path of the system.conf file (there is no system bus on Windows so this can just return FALSE and print a warning or something)

Parameters
strthe string to append to, which must be empty on entry
Returns
FALSE if no memory

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

References _dbus_assert, _dbus_string_append(), and _dbus_string_get_length().

◆ _dbus_get_tmpdir()

DBUS_PRIVATE_EXPORT const char * _dbus_get_tmpdir ( void  )

Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.

If none of those are set "/tmp" is returned

Returns
location of temp directory, or NULL if no memory for locking

Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.

Returns
location of temp directory, or NULL if no memory for locking

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

References _dbus_abort(), _dbus_assert, _DBUS_LOCK, _DBUS_UNLOCK, _dbus_warn(), and NULL.

◆ _dbus_getenv()

DBUS_PRIVATE_EXPORT const char * _dbus_getenv ( const char *  varname)

Wrapper for getenv().

Parameters
varnamename of environment variable
Returns
value of environment variable or NULL if unset

Definition at line 197 of file dbus-sysdeps.c.

References _dbus_check_setuid(), and NULL.

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_get_autolaunch_address(), _dbus_get_standard_session_servicedirs(), _dbus_homedir_from_uid(), _dbus_server_listen_unix_socket(), _dbus_server_new_for_launchd(), and _dbus_set_up_transient_session_servicedirs().

◆ _dbus_getpid()

DBUS_PRIVATE_EXPORT dbus_pid_t _dbus_getpid ( void  )

Gets our process ID.

Returns
process ID

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

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

◆ _dbus_getuid()

DBUS_PRIVATE_EXPORT dbus_uid_t _dbus_getuid ( void  )

Gets our UID.

Returns
process UID

Gets our UID.

Returns
on Windows, just DBUS_UID_UNSET

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

References DBUS_UID_UNSET.

Referenced by _dbus_homedir_from_uid().

◆ _dbus_inet_sockaddr_to_string()

dbus_bool_t _dbus_inet_sockaddr_to_string ( const void *  sockaddr_pointer,
size_t  len,
char *  string,
size_t  string_len,
const char **  family_name,
dbus_uint16_t port,
DBusError error 
)

Definition at line 798 of file dbus-sysdeps.c.

◆ _dbus_init_system_log()

DBUS_PRIVATE_EXPORT void _dbus_init_system_log ( const char *  tag,
DBusLogFlags  flags 
)

Initialize the system log.

The "tag" is not copied, and must remain valid for the entire lifetime of the process or until _dbus_init_system_log() is called again. In practice it will normally be a constant.

On platforms that do not support a system log, the #DBUS_LOG_FLAGS_SYSTEM_LOG flag is treated as equivalent to #DBUS_LOG_FLAGS_STDERR.

Parameters
tagthe name of the executable (syslog tag)
modewhether to log to stderr, the system log or both

The "tag" is not copied, and must remain valid for the entire lifetime of the process or until _dbus_init_system_log() is called again. In practice it will normally be a constant.

Parameters
tagthe name of the executable (syslog tag)
modewhether to log to stderr, the system log or both

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

References _dbus_assert.

◆ _dbus_listen_tcp_socket()

int _dbus_listen_tcp_socket ( const char *  host,
const char *  port,
const char *  family,
DBusString retport,
const char **  retfamily,
DBusSocket **  fds_p,
DBusError error 
)

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

The socket is set to be nonblocking. In case of port=0 a random free port is used and returned in the port parameter. If inaddr_any is specified, the hostname is ignored.

This will set FD_CLOEXEC for the socket returned

Parameters
hostthe host name to listen on
portthe port to listen on, if zero a free port will be used
familythe address family to listen on, NULL for all
retportstring to return the actual port listened on
retfamilystring to return the actual family listened on
fds_plocation to store returned file descriptors
errorreturn location for errors
Returns
the number of listening file descriptors or -1 on error

The socket is set to be nonblocking. In case of port=0 a random free port is used and returned in the port parameter. If inaddr_any is specified, the hostname is ignored.

Parameters
hostthe host name to listen on
portthe port to listen on, if zero a free port will be used
familythe address family to listen on, NULL for all
retportstring to return the actual port listened on
retfamilystring to return the actual family listened on
fds_plocation to store returned file descriptors
errorreturn location for errors
Returns
the number of listening file descriptors or -1 on error

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

References _dbus_close(), _dbus_error_from_errno(), _dbus_warn(), _DBUS_ZERO, DBUS_ERROR_BAD_ADDRESS, dbus_error_init(), DBUS_ERROR_INVALID_ARGS, dbus_new0, dbus_set_error(), FALSE, and NULL.

Referenced by _dbus_server_new_for_tcp_socket().

◆ _dbus_listen_unix_socket()

DBusSocket _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
a valid socket on success or an invalid socket on error

The socket is set to be nonblocking.

Abstract socket usage always fails.

This will set CLOEXEC for the socket returned

Parameters
paththe socket name
abstractTRUE to use abstract namespace
errorreturn location for errors
Returns
a valid socket on success or an invalid socket on error

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

Referenced by _dbus_server_new_for_domain_socket().

◆ _dbus_log()

DBUS_PRIVATE_EXPORT void _dbus_log ( DBusSystemLogSeverity  severity,
const char *  msg,
  ... 
)

Log a message to the system log file (e.g.

syslog on Unix) and/or stderr.

Parameters
severitya severity value
msga printf-style format string

Definition at line 772 of file dbus-sysdeps.c.

References _dbus_logv().

◆ _dbus_logv()

DBUS_PRIVATE_EXPORT void _dbus_logv ( DBusSystemLogSeverity  severity,
const char *  msg,
va_list  args 
)

Log a message to the system log file (e.g.

syslog on Unix) and/or stderr.

Parameters
severitya severity value
msga printf-style format string
argsarguments for the format string

syslog on Unix).

Parameters
severitya severity value
msga printf-style format string
argsarguments for the format string

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

Referenced by _dbus_log().

◆ _dbus_lookup_session_address()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_lookup_session_address ( dbus_bool_t supported,
DBusString address,
DBusError error 
)

Determines the address of the session bus by querying a platform-specific method.

The first parameter will be a boolean specifying whether or not a dynamic session lookup is supported on this platform.

If supported is TRUE and the return value is TRUE, the address will be appended to address. If a failure happens, returns FALSE and sets an error in error.

If supported is FALSE, ignore the return value.

Parameters
supportedreturns whether this method is supported
addressa DBusString where the address can be stored
errora DBusError to store the error in case of failure
Returns
TRUE on success, FALSE if an error happened

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

References FALSE, and TRUE.

◆ _dbus_parse_unix_group_from_config()

dbus_bool_t _dbus_parse_unix_group_from_config ( const DBusString groupname,
dbus_gid_t gid_p 
)

Parse a UNIX group from the bus config file.

On Windows, this should simply always fail (just return FALSE).

Parameters
groupnamethe groupname text
gid_pplace to return the gid
Returns
TRUE on success

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

References _dbus_get_group_id(), and FALSE.

◆ _dbus_parse_unix_user_from_config()

dbus_bool_t _dbus_parse_unix_user_from_config ( const DBusString username,
dbus_uid_t uid_p 
)

Parse a UNIX user from the bus config file.

On Windows, this should simply always fail (just return FALSE).

Parameters
usernamethe username text
uid_pplace to return the uid
Returns
TRUE on success

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

References _dbus_get_user_id(), and FALSE.

◆ _dbus_path_is_absolute()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_path_is_absolute ( const DBusString filename)

Checks whether the filename is an absolute path.

Parameters
filenamethe filename
Returns
TRUE if an absolute path

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

References _dbus_string_get_byte(), _dbus_string_get_length(), and FALSE.

◆ _dbus_pid_for_log()

unsigned long _dbus_pid_for_log ( void  )

The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not for other purposes.

Returns
process ID to put in log messages

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

References _dbus_getpid().

◆ _dbus_poll()

DBUS_PRIVATE_EXPORT int _dbus_poll ( DBusPollFD fds,
int  n_fds,
int  timeout_milliseconds 
)

Wrapper for poll().

Parameters
fdsthe file descriptors to poll
n_fdsnumber of descriptors in the array
timeout_millisecondstimeout or -1 for infinite
Returns
numbers of fds with revents, or <0 on error

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

References _DBUS_POLLERR, _DBUS_POLLIN, _DBUS_POLLOUT, DBusPollFD::events, DBusPollFD::fd, NULL, and DBusPollFD::revents.

◆ _dbus_print_backtrace()

DBUS_PRIVATE_EXPORT void _dbus_print_backtrace ( void  )

On GNU libc systems, print a crude backtrace to stderr.

On other systems, print "no backtrace support" and block for possible gdb attachment if an appropriate environment variable is set.

Definition at line 204 of file dbus-backtrace-win.c.

◆ _dbus_printf_string_upper_bound()

DBUS_PRIVATE_EXPORT int _dbus_printf_string_upper_bound ( const char *  format,
va_list  args 
)

Measure the length of the given format string and arguments, not including the terminating nul.

Parameters
formata printf-style format string
argsarguments for the format string
Returns
length of the given format string and args, or -1 if no memory

Measure the length of the given format string and arguments, not including the terminating nul.

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

References dbus_free(), dbus_malloc(), and NULL.

Referenced by _dbus_string_append_printf_valist().

◆ _dbus_read_credentials_socket()

dbus_bool_t _dbus_read_credentials_socket ( DBusSocket  handle,
DBusCredentials credentials,
DBusError error 
)

Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if available.

Clears the credentials object, then adds pid/uid if available, so any previous credentials stored in the object are lost.

DBusServer makes the security assumption that the credentials returned by this method are the credentials that were active at the time the socket was opened. Do not add APIs to this method that would break that assumption.

In particular, it is incorrect to use any API of the form "get the process ID at the other end of the connection, then determine its uid, gid, or other credentials from the pid" (e.g. looking in /proc on Linux). If we did that, we would be vulnerable to several attacks. A malicious process could queue up the rest of the authentication handshake and a malicious message that it should not be allowed to send, then race with the DBusServer to exec() a more privileged (e.g. setuid) binary that would have been allowed to send that message; or it could exit, and arrange for enough setuid processes to be started that its pid would be recycled for one of those processes with high probability; or it could fd-pass the connection to a more privileged process.

Return value indicates whether a byte was read, not whether we got valid credentials. On some systems, such as Linux, reading/writing the byte isn't actually required, but we do it anyway just to avoid multiple codepaths.

Fails if no byte is available, so you must select() first.

The point of the byte is that on some systems we have to use sendmsg()/recvmsg() to transmit credentials.

Parameters
client_fdthe client file descriptor
credentialsobject to add client credentials to
errorlocation to store error code
Returns
TRUE on success

Fills in pid/uid/gid with -1 if no credentials are available. Return value indicates whether a byte was read, not whether we got valid credentials. On some systems, such as Linux, reading/writing the byte isn't actually required, but we do it anyway just to avoid multiple codepaths.

Fails if no byte is available, so you must select() first.

The point of the byte is that on some systems we have to use sendmsg()/recvmsg() to transmit credentials.

Parameters
handlethe client file descriptor
credentialsstruct to fill with credentials of client
errorlocation to store error code
Returns
TRUE on success

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

References _dbus_credentials_add_pid(), _dbus_credentials_add_windows_sid(), _dbus_read_socket(), _dbus_string_free(), _dbus_string_init(), dbus_error_is_set(), FALSE, NULL, and TRUE.

◆ _dbus_read_local_machine_uuid()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_read_local_machine_uuid ( DBusGUID machine_id,
dbus_bool_t  create_if_not_found,
DBusError error 
)

Reads the uuid of the machine we're running on from the dbus configuration.

Optionally try to create it (only root can do this usually).

On UNIX, reads a file that gets created by dbus-uuidgen in a post-install script. On Windows, if there's a standard machine uuid we could just use that, but I can't find one with the right properties (the hardware profile guid can change without rebooting I believe). If there's no standard one we might want to use the registry instead of a file for this, and I'm not sure how we'd ensure the uuid gets created.

Parameters
machine_idguid to init with the machine's uuid
create_if_not_foundtry to create the uuid if it doesn't exist
errorthe error return
Returns
FALSE if the error is set

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

References _dbus_generate_uuid(), _dbus_read_uuid_file(), _dbus_string_init_const(), _dbus_write_uuid_file(), DBusGUID::as_uint32s, dbus_error_free(), DBUS_ERROR_INIT, DBUS_ERROR_NO_MEMORY, dbus_set_error(), FALSE, DBusError::message, DBusError::name, NULL, and TRUE.

Referenced by _dbus_get_uuid().

◆ _dbus_read_socket()

DBUS_PRIVATE_EXPORT int _dbus_read_socket ( DBusSocket  fd,
DBusString buffer,
int  count 
)

Like _dbus_read(), but only works on sockets so is available on Windows.

Parameters
fdthe socket
bufferstring to append data to
countmax amount of data to read
Returns
number of bytes appended to the string

Like _dbus_read(), but only works on sockets so is available on Windows.

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_socket() handles EINTR for you. _dbus_read_socket() can return ENOMEM, even though regular UNIX read doesn't.

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 338 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_read(), _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_read_credentials_socket(), and _dbus_read_socket_with_unix_fds().

◆ _dbus_read_socket_with_unix_fds()

int _dbus_read_socket_with_unix_fds ( DBusSocket  fd,
DBusString buffer,
int  count,
int *  fds,
unsigned int *  n_fds 
)

Like _dbus_read_socket() but also tries to read unix fds from the socket.

When there are more fds to read than space in the array passed this function will fail with ENOSPC.

Parameters
fdthe socket
bufferstring to append data to
countmax amount of data to read
fdsarray to place read file descriptors in
n_fdson input space in fds array, on output how many fds actually got read
Returns
number of bytes appended to string

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

References _dbus_assert, _dbus_read_socket(), _dbus_string_get_data_len(), _dbus_string_get_length(), _dbus_string_lengthen(), _dbus_string_set_length(), _DBUS_ZERO, DBUS_MAXIMUM_MESSAGE_UNIX_FDS, and FALSE.

◆ _dbus_replace_install_prefix()

dbus_bool_t _dbus_replace_install_prefix ( DBusString path)

Replace the DBUS_PREFIX in the given path, in-place, by the current D-Bus installation directory.

On Unix this function does nothing, successfully.

Parameters
pathpath to edit
Returns
FALSE on OOM

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

References _dbus_string_free(), _dbus_string_get_byte(), _dbus_string_get_length(), _dbus_string_init(), _dbus_string_replace_len(), _dbus_string_set_byte(), _dbus_string_starts_with_c_str(), FALSE, and TRUE.

Referenced by _dbus_get_standard_session_servicedirs().

◆ _dbus_resolve_pid_fd()

DBUS_PRIVATE_EXPORT dbus_pid_t _dbus_resolve_pid_fd ( int  pid_fd)

Resolve the PID from the PID FD, if any.

This allows us to avoid PID reuse attacks. Returns DBUS_PID_UNSET if the PID could not be resolved. Note that this requires being able to read /proc/self/fdinfo/<FD>, which is created as 600 and owned by the original UID that the process started as. So it cannot work when the start as root and drop privileges mechanism is in use (the systemd unit no longer does this, but third-party init-scripts might).

Parameters
pid_fdthe PID FD
Returns
the resolved PID if found, DBUS_PID_UNSET otherwise

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

References _dbus_file_get_contents(), _dbus_string_append_printf(), _dbus_string_find(), _dbus_string_free(), _dbus_string_get_byte(), _dbus_string_init(), _dbus_string_parse_uint(), dbus_error_free(), DBUS_ERROR_INIT, DBUS_PID_UNSET, DBusError::message, DBusError::name, and NULL.

Referenced by _dbus_credentials_get_pid().

◆ _dbus_restore_socket_errno()

void _dbus_restore_socket_errno ( int  saved_errno)

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

◆ _dbus_rlimit_free()

void _dbus_rlimit_free ( DBusRLimit *  lim)

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

◆ _dbus_rlimit_raise_fd_limit()

dbus_bool_t _dbus_rlimit_raise_fd_limit ( DBusError error)

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

◆ _dbus_rlimit_restore_fd_limit()

dbus_bool_t _dbus_rlimit_restore_fd_limit ( DBusRLimit *  saved,
DBusError error 
)

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

◆ _dbus_rlimit_save_fd_limit()

DBusRLimit * _dbus_rlimit_save_fd_limit ( DBusError error)

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

◆ _dbus_save_socket_errno()

int _dbus_save_socket_errno ( void  )

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

◆ _dbus_send_credentials_socket()

dbus_bool_t _dbus_send_credentials_socket ( DBusSocket  server_fd,
DBusError error 
)

Sends a single nul byte with our UNIX credentials as ancillary data.

Returns TRUE if the data was successfully written. On systems that don't support sending credentials, just writes a byte, doesn't send any credentials. On some systems, such as Linux, reading/writing the byte isn't actually required, but we do it anyway just to avoid multiple codepaths.

Fails if no byte can be written, so you must select() first.

The point of the byte is that on some systems we have to use sendmsg()/recvmsg() to transmit credentials.

Parameters
server_fdfile descriptor for connection to server
errorreturn location for error code
Returns
TRUE if the byte was sent

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

References _dbus_assert, _dbus_error_from_errno(), _dbus_strerror_from_errno(), _dbus_string_init_const_len(), _dbus_write_socket(), DBUS_ERROR_IO_ERROR, dbus_set_error(), FALSE, and TRUE.

◆ _dbus_set_errno_to_zero()

void _dbus_set_errno_to_zero ( void  )

Assign 0 to the global errno variable.

Definition at line 702 of file dbus-sysdeps.c.

Referenced by _dbus_string_parse_int(), and _dbus_string_parse_uint().

◆ _dbus_set_error_with_inet_sockaddr()

void _dbus_set_error_with_inet_sockaddr ( DBusError error,
const void *  sockaddr_pointer,
size_t  len,
const char *  description,
int  saved_errno 
)

Definition at line 885 of file dbus-sysdeps.c.

◆ _dbus_set_socket_nonblocking()

dbus_bool_t _dbus_set_socket_nonblocking ( DBusSocket  handle,
DBusError error 
)

Sets a file descriptor to be nonblocking.

Parameters
fdthe file descriptor.
erroraddress of error location.
Returns
TRUE on success.
Parameters
handlethe file descriptor.
erroraddress of error location.
Returns
TRUE on success.

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

References _dbus_error_from_errno(), _dbus_strerror_from_errno(), dbus_set_error(), FALSE, and TRUE.

◆ _dbus_set_up_transient_session_servicedirs()

dbus_bool_t _dbus_set_up_transient_session_servicedirs ( DBusList **  dirs,
DBusError error 
)

Returns the standard directories for a session bus to look for transient service activation files.

Parameters
dirsthe directory list we are returning
Returns
FALSE on error

On Windows, there are none.

Parameters
dirsthe directory list we are returning
Returns
TRUE

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

References _dbus_getenv(), _dbus_list_append(), _dbus_string_append(), _dbus_string_append_printf(), _dbus_string_free(), _dbus_string_init(), _dbus_string_steal_data(), dbus_free(), FALSE, NULL, and TRUE.

◆ _dbus_sleep_milliseconds()

DBUS_PRIVATE_EXPORT void _dbus_sleep_milliseconds ( int  milliseconds)

Sleeps the given number of milliseconds.

Parameters
millisecondsnumber of milliseconds

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

◆ _dbus_socket_can_pass_unix_fd()

dbus_bool_t _dbus_socket_can_pass_unix_fd ( DBusSocket  fd)

Checks whether file descriptors may be passed via the socket.

Parameters
fdthe socket
Returns
TRUE when fd passing over this socket is supported

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

References _DBUS_ZERO, and FALSE.

◆ _dbus_socketpair()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_socketpair ( DBusSocket fd1,
DBusSocket fd2,
dbus_bool_t  blocking,
DBusError error 
)

Creates pair of connect sockets (as in socketpair()).

Sets both ends of the pair nonblocking.

Marks both file descriptors as close-on-exec

Parameters
fd1return location for one end
fd2return location for the other end
blockingTRUE if pair should be blocking
errorerror return
Returns
FALSE on failure (if error is set)

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

References _dbus_close(), _dbus_error_from_errno(), _dbus_fd_set_close_on_exec(), _dbus_strerror_from_errno(), _dbus_warn(), _DBUS_ZERO, DBUS_ERROR_FAILED, dbus_set_error(), FALSE, NULL, and TRUE.

◆ _dbus_split_paths_and_append()

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_split_paths_and_append ( DBusString dirs,
const char *  suffix,
DBusList **  dir_list 
)

Split paths into a list of char strings.

Parameters
dirsstring with pathes
suffixstring concated to each path in dirs
dir_listcontains a list of splitted pathes return TRUE is pathes could be splittes,FALSE in oom case

Definition at line 238 of file dbus-sysdeps.c.

References _dbus_concat_dir_and_file(), _dbus_list_append(), _dbus_list_clear_full(), _dbus_string_chop_white(), _dbus_string_copy_data(), _dbus_string_copy_len(), _dbus_string_find(), _dbus_string_free(), _dbus_string_get_length(), _dbus_string_init(), _dbus_string_init_const(), dbus_free(), FALSE, and TRUE.

Referenced by _dbus_get_standard_session_servicedirs(), and _dbus_get_standard_system_servicedirs().

◆ _dbus_stat()

dbus_bool_t _dbus_stat ( const DBusString filename,
DBusStat statbuf,
DBusError error 
)

stat() wrapper.

Parameters
filenamethe filename to stat
statbufthe stat info to fill in
errorreturn location for error
Returns
FALSE if error was set

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

References _dbus_error_from_errno(), _dbus_string_get_const_data(), DBusStat::atime, DBusStat::ctime, DBUS_GID_UNSET, DBUS_INT64_CONSTANT, dbus_int64_t, dbus_set_error(), DBUS_UID_UNSET, FALSE, DBusStat::gid, DBusStat::mode, DBusStat::mtime, DBusStat::nlink, NULL, DBusStat::size, TRUE, and DBusStat::uid.

Referenced by _dbus_is_console_user().

◆ _dbus_strerror_from_errno()

DBUS_PRIVATE_EXPORT const char * _dbus_strerror_from_errno ( void  )

◆ _dbus_string_get_dirname()

dbus_bool_t _dbus_string_get_dirname ( const DBusString filename,
DBusString dirname 
)

Get the directory name from a complete filename.

Parameters
filenamethe filename
dirnamestring to append directory name to
Returns
FALSE if no memory

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

References _dbus_assert, _dbus_string_append(), _dbus_string_copy_len(), _dbus_string_find_byte_backward(), _dbus_string_get_byte(), _dbus_string_get_length(), and NULL.

◆ _dbus_threads_init_platform_specific()

dbus_bool_t _dbus_threads_init_platform_specific ( void  )

Initialize threads as in dbus_threads_init_default(), appropriately for the platform.

Returns
FALSE if no memory

Definition at line 281 of file dbus-sysdeps-pthread.c.

References _dbus_check_setuid(), FALSE, and TRUE.

Referenced by dbus_threads_init().

◆ _dbus_threads_lock_platform_specific()

void _dbus_threads_lock_platform_specific ( void  )

Lock a static mutex used to protect _dbus_threads_init_platform_specific().

Definition at line 296 of file dbus-sysdeps-pthread.c.

References _dbus_assert.

Referenced by dbus_threads_init().

◆ _dbus_threads_unlock_platform_specific()

void _dbus_threads_unlock_platform_specific ( void  )

Undo _dbus_threads_lock_platform_specific().

Definition at line 302 of file dbus-sysdeps-pthread.c.

References _dbus_assert.

Referenced by dbus_threads_init().

◆ _dbus_unix_groups_from_uid()

dbus_bool_t _dbus_unix_groups_from_uid ( dbus_uid_t  uid,
dbus_gid_t **  group_ids,
int *  n_group_ids,
DBusError error 
)

Gets all groups corresponding to the given UNIX user ID.

On UNIX, just calls _dbus_groups_from_uid(). On Windows, should always fail since we don't know any UNIX groups.

Parameters
uidthe UID
group_idsreturn location for array of group IDs
n_group_idsreturn location for length of returned array
errorerror location
Returns
TRUE if the UID existed and we got some credentials

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

References _dbus_groups_from_uid().

◆ _dbus_unix_user_is_at_console()

dbus_bool_t _dbus_unix_user_is_at_console ( dbus_uid_t  uid,
DBusError error 
)

Checks to see if the UNIX user ID is at the console.

Should always fail on Windows (set the error to DBUS_ERROR_NOT_SUPPORTED).

Parameters
uidUID of person to check
errorreturn location for errors
Returns
TRUE if the UID is the same as the console user and there are no errors

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

References _dbus_is_console_user().

◆ _dbus_unix_user_is_process_owner()

dbus_bool_t _dbus_unix_user_is_process_owner ( dbus_uid_t  uid)

Checks to see if the UNIX user ID matches the UID of the process.

Should always return FALSE on Windows.

Parameters
uidthe UNIX user ID
Returns
TRUE if this uid owns the process.

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

References _dbus_geteuid(), and FALSE.

◆ _dbus_verify_daemon_user()

dbus_bool_t _dbus_verify_daemon_user ( const char *  user)

Verify that after the fork we can successfully change to this user.

Parameters
userthe username given in the daemon configuration
Returns
TRUE if username is valid

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

References _dbus_get_user_id_and_primary_group(), _dbus_string_init_const(), NULL, and TRUE.

◆ _dbus_windows_user_is_process_owner()

dbus_bool_t _dbus_windows_user_is_process_owner ( const char *  windows_sid)

Checks to see if the Windows user SID matches the owner of the process.

Should always return FALSE on UNIX.

Parameters
windows_sidthe Windows user SID
Returns
TRUE if this user owns the process.

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

References FALSE, and TRUE.

◆ _dbus_write_pid_to_file_and_pipe()

dbus_bool_t _dbus_write_pid_to_file_and_pipe ( const DBusString pidfile,
DBusPipe print_pid_pipe,
dbus_pid_t  pid_to_write,
DBusError error 
)

Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL).

Does nothing if pidfile and print_pid_pipe are both NULL.

Parameters
pidfilethe file to write to or NULL
print_pid_pipethe pipe to write to or NULL
pid_to_writethe pid to write out
errorerror on failure
Returns
FALSE if error is set

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

References _dbus_string_get_const_data().

◆ _dbus_write_socket()

DBUS_PRIVATE_EXPORT int _dbus_write_socket ( DBusSocket  fd,
const DBusString buffer,
int  start,
int  len 
)

Like _dbus_write(), but only supports sockets and is thus available on Windows.

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

Like _dbus_write(), but only supports sockets and is thus available on Windows.

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 356 of file dbus-sysdeps-unix.c.

References _dbus_strerror_from_errno(), _dbus_string_get_const_data_len(), _dbus_verbose_bytes_of_string(), and _dbus_write().

Referenced by _dbus_send_credentials_socket().

◆ _dbus_write_socket_two()

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

Like _dbus_write_two() but only works on sockets and is thus available on Windows.

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

Like _dbus_write_two() but only works on sockets and is thus available on Windows.

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 694 of file dbus-sysdeps-unix.c.

References _dbus_assert, _dbus_strerror_from_errno(), _dbus_string_get_const_data_len(), _dbus_write_two(), _DBUS_ZERO, and NULL.

◆ _dbus_write_socket_with_unix_fds()

DBUS_PRIVATE_EXPORT int _dbus_write_socket_with_unix_fds ( DBusSocket  fd,
const DBusString buffer,
int  start,
int  len,
const int *  fds,
int  n_fds 
)

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

◆ _dbus_write_socket_with_unix_fds_two()

int _dbus_write_socket_with_unix_fds_two ( DBusSocket  fd,
const DBusString buffer1,
int  start1,
int  len1,
const DBusString buffer2,
int  start2,
int  len2,
const int *  fds,
int  n_fds 
)

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