Internal system-dependent API
[D-Bus secret internal implementation details]

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  DBusStat
 Portable struct with stat() results. More...

Defines

#define DBUS_PID_UNSET   ((dbus_pid_t) -1)
 an invalid PID used to represent an uninitialized dbus_pid_t field
#define DBUS_UID_UNSET   ((dbus_uid_t) -1)
 an invalid UID used to represent an uninitialized dbus_uid_t field
#define DBUS_GID_UNSET   ((dbus_gid_t) -1)
 an invalid GID used to represent an uninitialized dbus_gid_t field
#define DBUS_PID_FORMAT   "%lu"
 an appropriate printf format for dbus_pid_t
#define DBUS_UID_FORMAT   "%lu"
 an appropriate printf format for dbus_uid_t
#define DBUS_GID_FORMAT   "%lu"
 an appropriate printf format for dbus_gid_t
#define DBUS_SOCKET_FORMAT   "d"
#define DBUS_SOCKET_INIT   { -1 }
#define DBUS_POLLABLE_FORMAT   "d"
#define _DBUS_POLLIN   POLLIN
 There is data to read.
#define _DBUS_POLLPRI   POLLPRI
 There is urgent data to read.
#define _DBUS_POLLOUT   POLLOUT
 Writing now will not block.
#define _DBUS_POLLERR   POLLERR
 Error condition.
#define _DBUS_POLLHUP   POLLHUP
 Hung up.
#define _DBUS_POLLNVAL   POLLNVAL
 Invalid request: fd not open.
#define _DBUS_BYTE_OF_PRIMITIVE(p, i)   (((const char*)&(p))[(i)])
 Casts a primitive C type to a byte array and then indexes a particular byte of the array.
#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b)
 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.
#define DBUS_DEFAULT_MESSAGE_UNIX_FDS   16

Typedefs

typedef unsigned long dbus_pid_t
 A process ID.
typedef unsigned long dbus_uid_t
 A user ID.
typedef unsigned long dbus_gid_t
 A group ID.
typedef DBusAtomic DBusAtomic
 Opaque type representing an atomically-modifiable integer that can be used from multiple threads.
typedef int DBusPollable
typedef pollfd DBusPollFD
 A portable struct pollfd wrapper, or an emulation of struct pollfd on platforms where poll() is missing or broken.
typedef DBusDirIter DBusDirIter
 Opaque type for reading a directory listing.
typedef void(*) DBusSignalHandler (int sig)
 A UNIX signal handler.
typedef DBusGUID DBusGUID
 Type representing a universally unique ID.
typedef DBusRLimit DBusRLimit

Enumerations

enum  DBusSystemLogSeverity { DBUS_SYSTEM_LOG_INFO, DBUS_SYSTEM_LOG_WARNING, DBUS_SYSTEM_LOG_SECURITY, DBUS_SYSTEM_LOG_FATAL }

Functions

void _dbus_abort (void)
 Aborts the program with SIGABRT (dumping core).
const char * _dbus_getenv (const char *varname)
 Wrapper for getenv().
dbus_bool_t _dbus_clearenv (void)
 Wrapper for clearenv().
dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs, const char *suffix, DBusList **dir_list)
 Split paths into a list of char strings.
dbus_bool_t _dbus_check_setuid (void)
 **NOTE**: If you modify this function, please also consider making the corresponding change in GLib.
char ** _dbus_get_environment (void)
 Gets a NULL-terminated list of key=value pairs from the environment.
dbus_bool_t _dbus_set_socket_nonblocking (DBusSocket fd, DBusError *error)
 Sets a file descriptor to be nonblocking.
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_close_socket (DBusSocket fd, DBusError *error)
 Closes a 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.
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.
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.
int _dbus_read_socket_with_unix_fds (DBusSocket fd, DBusString *buffer, int count, int *fds, int *n_fds)
 Like _dbus_read_socket() but also tries to read unix fds from the socket.
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.
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, DBusSocket **fds_p, DBusError *error)
 Creates a socket and binds it to the given path, then listens on the socket.
DBusSocket _dbus_accept (DBusSocket listen_fd)
 Accepts a connection on a listening socket.
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.
dbus_bool_t _dbus_send_credentials_socket (DBusSocket server_fd, DBusError *error)
 Sends a single nul byte with our UNIX credentials as ancillary data.
dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, const DBusString *username)
 Adds the credentials corresponding to the given username.
dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
 Adds the credentials of the current process to the passed-in credentials object.
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.
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.
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.
dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
 Gets all groups corresponding to the given UNIX user ID.
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.
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.
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.
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.
dbus_bool_t _dbus_daemon_is_session_bus_address_published (const char *scope)
dbus_bool_t _dbus_daemon_publish_session_bus_address (const char *address, const char *shm_name)
void _dbus_daemon_unpublish_session_bus_address (void)
dbus_bool_t _dbus_socket_can_pass_unix_fd (DBusSocket fd)
 Checks whether file descriptors may be passed via the socket.
DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic)
 Atomically increments an integer.
DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic)
 Atomically decrement an integer.
DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic)
 Atomically get the value of an integer.
DBUS_PRIVATE_EXPORT int _dbus_poll (DBusPollFD *fds, int n_fds, int timeout_milliseconds)
 Wrapper for poll().
DBUS_PRIVATE_EXPORT void _dbus_sleep_milliseconds (int milliseconds)
 Sleeps the given number of milliseconds.
DBUS_PRIVATE_EXPORT void _dbus_get_monotonic_time (long *tv_sec, long *tv_usec)
 Get current time, as in gettimeofday().
DBUS_PRIVATE_EXPORT void _dbus_get_real_time (long *tv_sec, long *tv_usec)
 Get current time, as in gettimeofday().
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_create_directory (const DBusString *filename, DBusError *error)
 directory interface
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_delete_directory (const DBusString *filename, DBusError *error)
 Removes a directory; Directory must be empty.
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.
dbus_bool_t _dbus_string_get_dirname (const DBusString *filename, DBusString *dirname)
 Get the directory name from a complete filename.
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_path_is_absolute (const DBusString *filename)
 Checks whether the filename is an absolute path.
dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs)
 Returns the standard directories for a session bus to look for service activation files.
dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs)
 Returns the standard directories for a system bus to look for service activation files.
dbus_bool_t _dbus_append_system_config_file (DBusString *str)
 Append 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).
dbus_bool_t _dbus_append_session_config_file (DBusString *str)
 Append the absolute path of the session.conf file.
DBusDirIter_dbus_directory_open (const DBusString *filename, DBusError *error)
 Open a directory to iterate over.
dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter, DBusString *filename, DBusError *error)
 Get next file in the directory.
void _dbus_directory_close (DBusDirIter *iter)
 Closes a directory iteration.
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.
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.
_DBUS_GNUC_WARN_UNUSED_RESULT
dbus_bool_t 
_dbus_generate_random_bytes_buffer (char *buffer, int n_bytes, DBusError *error)
 Random numbers.
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.
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.
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.
DBUS_PRIVATE_EXPORT const
char * 
_dbus_error_from_system_errno (void)
 Converts the current system errno value into a DBusError name.
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.
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).
dbus_bool_t _dbus_get_is_errno_enomem (int e)
 See if errno is ENOMEM.
dbus_bool_t _dbus_get_is_errno_eintr (int e)
 See if errno is EINTR.
dbus_bool_t _dbus_get_is_errno_epipe (int e)
 See if errno is EPIPE.
dbus_bool_t _dbus_get_is_errno_etoomanyrefs (int e)
 See if errno is ETOOMANYREFS.
DBUS_PRIVATE_EXPORT const
char * 
_dbus_strerror_from_errno (void)
 Get error message from errno.
void _dbus_disable_sigpipe (void)
 signal (SIGPIPE, SIG_IGN);
DBUS_PRIVATE_EXPORT void _dbus_exit (int code) _DBUS_GNUC_NORETURN
 Exit the process, returning the given value.
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.
dbus_bool_t _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error)
 stat() wrapper.
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()).
void _dbus_print_backtrace (void)
 On GNU libc systems, print a crude backtrace to stderr.
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.
dbus_bool_t _dbus_verify_daemon_user (const char *user)
 Verify that after the fork we can successfully change to this user.
dbus_bool_t _dbus_change_to_daemon_user (const char *user, DBusError *error)
 Changes the user and group the bus is running as.
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).
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.
void _dbus_set_signal_handler (int sig, DBusSignalHandler handler)
 Installs a UNIX signal handler.
dbus_bool_t _dbus_user_at_console (const char *username, DBusError *error)
 Checks if user is at the console.
void _dbus_init_system_log (dbus_bool_t is_daemon)
void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg,...)
 Log a message to the system log file (e.g.
void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
 Log a message to the system log file (e.g.
dbus_bool_t _dbus_get_autolaunch_address (const char *scope, DBusString *address, DBusError *error)
 Returns the address of a new session bus.
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.
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.
dbus_bool_t _dbus_threads_init_platform_specific (void)
 Initialize threads as in dbus_threads_init_default(), appropriately for the platform.
void _dbus_threads_lock_platform_specific (void)
 Lock a static mutex used to protect _dbus_threads_init_platform_specific().
void _dbus_threads_unlock_platform_specific (void)
 Undo _dbus_threads_lock_platform_specific().
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.
DBUS_PRIVATE_EXPORT dbus_pid_t _dbus_getpid (void)
 Gets our process ID.
DBUS_PRIVATE_EXPORT dbus_uid_t _dbus_getuid (void)
 Gets our UID.
DBUS_PRIVATE_EXPORT void _dbus_flush_caches (void)
 Called when the bus daemon is signaled to reload its configuration; any caches should be nuked.
const char * _dbus_replace_install_prefix (const char *configure_time_path)
DBusRLimit_dbus_rlimit_save_fd_limit (DBusError *error)
dbus_bool_t _dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired, DBusError *error)
dbus_bool_t _dbus_rlimit_restore_fd_limit (DBusRLimit *saved, DBusError *error)
void _dbus_rlimit_free (DBusRLimit *lim)

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.


Define Documentation

#define _DBUS_DOUBLES_BITWISE_EQUAL ( a,
 ) 

Value:

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 589 of file dbus-sysdeps.h.


Typedef Documentation

typedef union DBusGUID DBusGUID

Type representing a universally unique ID.

Todo:
rename to UUID instead of GUID

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


Function Documentation

DBusSocket _dbus_accept ( DBusSocket  listen_fd  ) 

Accepts a connection on a listening socket.

Handles EINTR for you.

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

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

References _dbus_fd_set_close_on_exec(), and DBusSocket::fd.

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:
directory string to append directory to
credentials credentials the directory should be for
Returns:
FALSE on no memory

Definition at line 4151 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_init(), _dbus_string_init_const(), _dbus_string_set_length(), _dbus_warn(), DBUS_UID_UNSET, FALSE, NULL, and TRUE.

dbus_bool_t _dbus_append_session_config_file ( DBusString str  ) 

Append the absolute path of the session.conf file.

Parameters:
str the string to append to
Returns:
FALSE if no memory

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

References _dbus_string_append().

dbus_bool_t _dbus_append_system_config_file ( DBusString str  ) 

Append 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:
str the string to append to
Returns:
FALSE if no memory

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

References _dbus_string_append().

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:
str the string to append to
Returns:
FALSE on no memory
Todo:
to which class belongs this

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

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

DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_dec ( DBusAtomic atomic  ) 

Atomically decrement an integer.

Parameters:
atomic pointer to the integer to decrement
Returns:
the value before decrementing

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

References DBusAtomic::value.

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:
atomic pointer to the integer to get
Returns:
the value at this moment

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

References DBusAtomic::value.

DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_inc ( DBusAtomic atomic  ) 

Atomically increments an integer.

Parameters:
atomic pointer to the integer to increment
Returns:
the value before incrementing

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

References DBusAtomic::value.

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:
pidfile NULL, or pidfile to create
print_pid_pipe file descriptor to print daemon's pid to, or -1 for none
error return location for errors
keep_umask TRUE to keep the original umask
Returns:
FALSE on failure

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

References _dbus_assert_not_reached, _dbus_error_from_errno(), _dbus_getenv(), _dbus_write_pid_to_file_and_pipe(), DBUS_ERROR_FAILED, DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), FALSE, DBusError::message, NULL, and TRUE.

dbus_bool_t _dbus_change_to_daemon_user ( const char *  user,
DBusError error 
)

Changes the user and group the bus is running as.

Parameters:
user the user to become
error return location for errors
Returns:
FALSE on failure

Definition at line 332 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_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:
dir the name of the directory
error error return
Returns:
FALSE on failure

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

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

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

References FALSE, and TRUE.

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_clearenv ( void   ) 

Wrapper for clearenv().

Returns:
TRUE on success.

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

References FALSE, NULL, and TRUE.

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_close_socket ( DBusSocket  fd,
DBusError error 
)

Closes a socket.

Parameters:
fd the file descriptor
error error object
Returns:
FALSE if error set

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

References _dbus_close(), _dbus_error_from_errno(), _dbus_strerror_from_errno(), dbus_set_error(), FALSE, DBusSocket::fd, and TRUE.

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:
pid Process id
str Append command to this string
max_len Maximum length of returned command
error return location for errors
Returns:
FALSE on error

Definition at line 1208 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_init(), dbus_set_error(), FALSE, NULL, and TRUE.

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.

Todo:
it might be cute to collapse multiple '/' such as "foo//" concat "//bar"
Parameters:
dir the directory name
next_component the filename
Returns:
TRUE on success

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

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

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.

Parameters:
host the host name to connect to
port the port to connect to
family the address family to listen on, NULL for all
error return location for error code
Returns:
connection file descriptor or -1 on error

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

References _dbus_connect_tcp_socket_with_nonce(), and NULL.

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_create_directory ( const DBusString filename,
DBusError error 
)

directory interface

Parameters:
filename directory filename
error initialized error object
Returns:
TRUE on success

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

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

dbus_bool_t _dbus_credentials_add_from_current_process ( DBusCredentials credentials  ) 

Adds the credentials of the current process to the passed-in credentials object.

Parameters:
credentials credentials 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 2621 of file dbus-sysdeps-unix.c.

References _dbus_credentials_add_pid(), _dbus_credentials_add_unix_uid(), _dbus_credentials_add_windows_sid(), _dbus_geteuid(), _dbus_getpid(), FALSE, and TRUE.

dbus_bool_t _dbus_credentials_add_from_user ( DBusCredentials credentials,
const DBusString username 
)

Adds the credentials corresponding to the given username.

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.

Todo:
this is broken because it treats OOM and parse error the same way. Needs a DBusError.
Parameters:
credentials credentials to fill in
username the username
Returns:
TRUE if the username existed and we got some credentials

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

References _dbus_credentials_add_unix_uid(), _dbus_credentials_add_windows_sid(), _dbus_user_database_get_system(), _dbus_user_database_get_username(), _dbus_user_database_lock_system(), _dbus_user_database_unlock_system(), FALSE, NULL, TRUE, and DBusUserInfo::uid.

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_delete_directory ( const DBusString filename,
DBusError error 
)

Removes a directory; Directory must be empty.

Parameters:
filename directory filename
error initialized error object
Returns:
TRUE on success

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

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

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.

Parameters:
iter the iterator
filename string to be set to the next file in the dir
error return location for error
Returns:
TRUE if filename was filled in with a new filename

Definition at line 802 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, DBusDirIter::fileinfo, DBusDirIter::finished, DBusDirIter::handle, DBusDirIter::offset, and TRUE.

DBusDirIter* _dbus_directory_open ( const DBusString filename,
DBusError error 
)

Open a directory to iterate over.

Parameters:
filename the directory name
error exception return object or NULL
Returns:
new iterator, or NULL on error

Definition at line 754 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_init_from_string(), DBusDirIter::d, DBUS_ERROR_NO_MEMORY, dbus_free(), dbus_new0, dbus_set_error(), FALSE, DBusDirIter::fileinfo, DBusDirIter::finished, DBusDirIter::handle, NULL, DBusDirIter::offset, and TRUE.

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.

Todo:
should cover more errnos, specifically those from open().
Parameters:
error_number the errno.
Returns:
an error name

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

References DBUS_ERROR_ACCESS_DENIED, DBUS_ERROR_ADDRESS_IN_USE, DBUS_ERROR_FAILED, DBUS_ERROR_FILE_EXISTS, DBUS_ERROR_FILE_NOT_FOUND, DBUS_ERROR_LIMITS_EXCEEDED, DBUS_ERROR_NO_MEMORY, DBUS_ERROR_NO_NETWORK, DBUS_ERROR_NO_SERVER, DBUS_ERROR_NOT_SUPPORTED, and DBUS_ERROR_TIMEOUT.

Referenced by _dbus_append_address_from_socket(), _dbus_become_daemon(), _dbus_change_to_daemon_user(), _dbus_check_dir_is_private_to_user(), _dbus_close(), _dbus_close_socket(), _dbus_command_for_pid(), _dbus_connect_exec(), _dbus_connect_tcp_socket_with_nonce(), _dbus_connect_unix_socket(), _dbus_directory_get_next_file(), _dbus_directory_open(), _dbus_dup(), _dbus_error_from_system_errno(), _dbus_file_get_contents(), _dbus_generate_random_bytes(), _dbus_is_console_user(), _dbus_listen_systemd_sockets(), _dbus_listen_tcp_socket(), _dbus_listen_unix_socket(), _dbus_read_credentials_socket(), _dbus_rlimit_raise_fd_limit_if_privileged(), _dbus_rlimit_restore_fd_limit(), _dbus_rlimit_save_fd_limit(), _dbus_send_credentials_socket(), _dbus_set_socket_nonblocking(), _dbus_socketpair(), _dbus_stat(), and _dbus_string_save_to_file().

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

References _dbus_error_from_errno().

DBUS_PRIVATE_EXPORT void _dbus_exit ( int  code  ) 

Exit the process, returning the given value.

Parameters:
code the exit code

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

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

References _dbus_user_database_flush_system().

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:
str the string
n_bytes the number of random ASCII bytes to append to string
error location to store reason for failure
Returns:
TRUE on success, FALSE if no memory or other failure

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

References _dbus_assert, _dbus_generate_random_bytes(), _dbus_string_validate_ascii(), FALSE, and TRUE.

Referenced by _dbus_server_listen_platform_specific(), and _dbus_string_save_to_file().

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:
str the string
n_bytes the number of random bytes to append to string
error location to store reason for failure
Returns:
TRUE on success

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

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

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

Random numbers.

Parameters:
buffer an allocated buffer
n_bytes the number of bytes in buffer to write to
error location to store reason for failure
Returns:
TRUE on success

Definition at line 516 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_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:
scope scope of autolaunch (Windows only)
address a DBusString where the address can be stored
error a DBusError to store the error in case of failure
Returns:
TRUE on success, FALSE if an error happened

Definition at line 3740 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_free(), _dbus_string_init(), DBUS_ERROR_FAILED, DBUS_ERROR_NOT_SUPPORTED, dbus_set_error_const(), FALSE, NULL, and TRUE.

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 49 of file dbus-sysdeps-util.c.

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

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

dbus_bool_t _dbus_get_is_errno_eintr ( int  e  ) 

See if errno is EINTR.

Returns:
TRUE if e == EINTR

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

dbus_bool_t _dbus_get_is_errno_enomem ( int  e  ) 

See if errno is ENOMEM.

Returns:
TRUE if e == ENOMEM

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

dbus_bool_t _dbus_get_is_errno_epipe ( int  e  ) 

See if errno is EPIPE.

Returns:
TRUE if errno == EPIPE

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

dbus_bool_t _dbus_get_is_errno_etoomanyrefs ( int  e  ) 

See if errno is ETOOMANYREFS.

Returns:
TRUE if errno == ETOOMANYREFS

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

References FALSE.

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_sec return location for number of seconds
tv_usec return location for number of microseconds

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

References _dbus_get_real_time(), and NULL.

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_sec return location for number of seconds
tv_usec return location for number of microseconds

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

References DBUS_INT64_CONSTANT, dbus_uint64_t, and NULL.

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 Windows this should be data directories:

CommonProgramFiles/dbus

and

relocated DBUS_DATADIR

Parameters:
dirs the directory list we are returning
Returns:
FALSE on OOM

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

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

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:
dirs the directory list we are returning
Returns:
FALSE on OOM

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

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

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

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

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

DBUS_PRIVATE_EXPORT const char * _dbus_getenv ( const char *  varname  ) 

Wrapper for getenv().

Parameters:
varname name of environment variable
Returns:
value of environment variable or NULL if unset

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

References _dbus_check_setuid(), and NULL.

Referenced by _dbus_abort(), _dbus_append_keyring_directory_for_credentials(), _dbus_become_daemon(), _dbus_get_autolaunch_address(), _dbus_get_standard_session_servicedirs(), _dbus_lookup_user_bus(), _dbus_server_listen_platform_specific(), and _dbus_server_new_for_launchd().

DBUS_PRIVATE_EXPORT dbus_pid_t _dbus_getpid ( void   ) 

Gets our process ID.

Returns:
process ID

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

DBUS_PRIVATE_EXPORT dbus_uid_t _dbus_getuid ( void   ) 

Gets our UID.

Returns:
on Windows, just DBUS_UID_UNSET

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

References DBUS_UID_UNSET.

int _dbus_listen_tcp_socket ( const char *  host,
const char *  port,
const char *  family,
DBusString retport,
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.

Parameters:
host the host name to listen on
port the port to listen on, if zero a free port will be used
family the address family to listen on, NULL for all
retport string to return the actual port listened on
fds_p location to store returned file descriptors
error return location for errors
Returns:
the number of listening file descriptors or -1 on error

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

References _dbus_close(), _dbus_error_from_errno(), _dbus_set_socket_nonblocking(), _dbus_strerror_from_errno(), _dbus_string_append(), _dbus_warn(), _DBUS_ZERO, DBUS_ERROR_BAD_ADDRESS, DBUS_ERROR_INVALID_ARGS, DBUS_ERROR_NO_MEMORY, dbus_free(), dbus_realloc(), dbus_set_error(), DBUS_SOCKET_INIT, DBusSocket::fd, and NULL.

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:
supported returns whether this method is supported
address a DBusString where the address can be stored
error a DBusError to store the error in case of failure
Returns:
TRUE on success, FALSE if an error happened

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

References _dbus_lookup_user_bus(), FALSE, and TRUE.

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:
groupname the groupname text
gid_p place to return the gid
Returns:
TRUE on success

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

References _dbus_get_group_id(), and FALSE.

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:
username the username text
uid_p place to return the uid
Returns:
TRUE on success

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

References _dbus_get_user_id(), and FALSE.

DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_path_is_absolute ( const DBusString filename  ) 

Checks whether the filename is an absolute path.

Parameters:
filename the filename
Returns:
TRUE if an absolute path

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

References FALSE.

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

References _dbus_getpid().

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

Wrapper for poll().

Parameters:
fds the file descriptors to poll
n_fds number of descriptors in the array
timeout_milliseconds timeout or -1 for infinite
Returns:
numbers of fds with revents, or <0 on error

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

References _dbus_assert_not_reached, _DBUS_POLLERR, _DBUS_POLLIN, _DBUS_POLLOUT, _dbus_strerror_from_errno(), FALSE, and NULL.

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

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:
format a printf-style format string
args arguments for the format string
Returns:
length of the given format string and args, or -1 if no memory

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

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

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.

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:
handle the client file descriptor
credentials struct to fill with credentials of client
error location to store error code
Returns:
TRUE on success

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

References _dbus_credentials_add_adt_audit_data(), _dbus_credentials_add_pid(), _dbus_credentials_add_unix_uid(), _dbus_credentials_add_windows_sid(), _dbus_credentials_clear(), _dbus_error_from_errno(), _dbus_read_socket(), _dbus_string_free(), _dbus_string_init(), _DBUS_ZERO, DBUS_ERROR_FAILED, DBUS_PID_FORMAT, DBUS_PID_UNSET, dbus_set_error(), DBUS_UID_FORMAT, DBUS_UID_UNSET, FALSE, DBusSocket::fd, NULL, and TRUE.

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_id guid to init with the machine's uuid
create_if_not_found try to create the uuid if it doesn't exist
error the error return
Returns:
FALSE if the error is set

Definition at line 3854 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_NO_MEMORY, dbus_set_error(), FALSE, NULL, and TRUE.

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.

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:
fd the file descriptor to read from
buffer the buffer to append data to
count the amount of data to read
Returns:
the number of bytes read or -1

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

References _dbus_assert, _dbus_read(), _dbus_string_get_data_len(), _dbus_string_lengthen(), _dbus_string_set_length(), _dbus_verbose_bytes_of_string(), and DBusSocket::fd.

int _dbus_read_socket_with_unix_fds ( DBusSocket  fd,
DBusString buffer,
int  count,
int *  fds,
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:
fd the socket
buffer string to append data to
count max amount of data to read
fds array to place read file descriptors in
n_fds on input space in fds array, on output how many fds actually got read
Returns:
number of bytes appended to string

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

References _dbus_assert, _dbus_fd_set_close_on_exec(), _dbus_read_socket(), _dbus_string_get_data_len(), _dbus_string_lengthen(), _dbus_string_set_length(), _dbus_verbose_bytes_of_string(), _DBUS_ZERO, FALSE, DBusSocket::fd, and TRUE.

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_fd file descriptor for connection to server
error return location for error code
Returns:
TRUE if the byte was sent

Definition at line 2199 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, DBusSocket::fd, and TRUE.

void _dbus_set_signal_handler ( int  sig,
DBusSignalHandler  handler 
)

Installs a UNIX signal handler.

Parameters:
sig the signal to handle
handler the handler

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

References NULL.

dbus_bool_t _dbus_set_socket_nonblocking ( DBusSocket  handle,
DBusError error 
)

Sets a file descriptor to be nonblocking.

Parameters:
handle the file descriptor.
error address of error location.
Returns:
TRUE on success.

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

References _dbus_error_from_errno(), _dbus_strerror_from_errno(), dbus_set_error(), FALSE, DBusSocket::fd, and TRUE.

DBUS_PRIVATE_EXPORT void _dbus_sleep_milliseconds ( int  milliseconds  ) 

Sleeps the given number of milliseconds.

Parameters:
milliseconds number of milliseconds

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

dbus_bool_t _dbus_socket_can_pass_unix_fd ( DBusSocket  fd  ) 

Checks whether file descriptors may be passed via the socket.

Parameters:
fd the socket
Returns:
TRUE when fd passing over this socket is supported

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

References _DBUS_ZERO, FALSE, and DBusSocket::fd.

Referenced by _dbus_transport_new_for_socket().

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:
fd1 return location for one end
fd2 return location for the other end
blocking TRUE if pair should be blocking
error error return
Returns:
FALSE on failure (if error is set)

Definition at line 3341 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, DBusSocket::fd, NULL, and TRUE.

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:
dirs string with pathes
suffix string concated to each path in dirs
dir_list contains a list of splitted pathes return TRUE is pathes could be splittes,FALSE in oom case

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

References _dbus_concat_dir_and_file(), _dbus_list_append(), _dbus_list_clear(), _dbus_list_foreach(), _dbus_string_chop_white(), _dbus_string_copy_data(), _dbus_string_copy_len(), _dbus_string_find(), _dbus_string_free(), _dbus_string_init(), _dbus_string_init_const(), dbus_free(), FALSE, NULL, and TRUE.

Referenced by _dbus_get_standard_session_servicedirs(), and _dbus_get_standard_system_servicedirs().

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

stat() wrapper.

Parameters:
filename the filename to stat
statbuf the stat info to fill in
error return location for error
Returns:
FALSE if error was set

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

References _dbus_error_from_errno(), 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.

DBUS_PRIVATE_EXPORT const char* _dbus_strerror_from_errno ( void   ) 

Get error message from errno.

Returns:
_dbus_strerror(errno)

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

Referenced by _dbus_close_socket(), _dbus_connect_tcp_socket_with_nonce(), _dbus_create_directory(), _dbus_delete_file(), _dbus_listen_tcp_socket(), _dbus_poll(), _dbus_send_credentials_socket(), _dbus_set_socket_nonblocking(), _dbus_socketpair(), _dbus_write_socket(), and _dbus_write_socket_two().

dbus_bool_t _dbus_string_get_dirname ( const DBusString filename,
DBusString dirname 
)

Get the directory name from a complete filename.

Parameters:
filename the filename
dirname string to append directory name to
Returns:
FALSE if no memory

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

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

void _dbus_system_log ( DBusSystemLogSeverity  severity,
const char *  msg,
  ... 
)

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

syslog on Unix).

Parameters:
severity a severity value
msg a printf-style format string

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

References _dbus_system_logv().

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

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

syslog on Unix).

Parameters:
severity a severity value
msg a printf-style format string
args arguments for the format string
If the FATAL severity is given, this function will terminate the program with an error code.

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

References _dbus_getpid(), and DBUS_PID_FORMAT.

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 278 of file dbus-sysdeps-pthread.c.

References _dbus_check_setuid(), FALSE, and TRUE.

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

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:
uid the UID
group_ids return location for array of group IDs
n_group_ids return location for length of returned array
Returns:
TRUE if the UID existed and we got some credentials

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

References _dbus_groups_from_uid(), and FALSE.

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:
uid UID of person to check
error return location for errors
Returns:
TRUE if the UID is the same as the console user and there are no errors

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

References _dbus_is_console_user(), DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), and FALSE.

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:
uid the UNIX user ID
Returns:
TRUE if this uid owns the process.

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

References _dbus_geteuid(), and FALSE.

dbus_bool_t _dbus_user_at_console ( const char *  username,
DBusError error 
)

Checks if user is at the console.

Parameters:
username user to check
error return location for errors
Returns:
TRUE is the user is at the consolei and there are no errors

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

References _dbus_concat_dir_and_file(), _dbus_file_exists(), _dbus_string_append(), _dbus_string_free(), _dbus_string_init(), _dbus_string_init_const(), and FALSE.

Referenced by _dbus_is_console_user().

dbus_bool_t _dbus_verify_daemon_user ( const char *  user  ) 

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

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

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

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

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_sid the Windows user SID
Returns:
TRUE if this user owns the process.

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

References FALSE, and TRUE.

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:
pidfile the file to write to or NULL
print_pid_pipe the pipe to write to or NULL
pid_to_write the pid to write out
error error on failure
Returns:
FALSE if error is set

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

References _dbus_string_append(), _dbus_string_append_int(), _dbus_string_free(), _dbus_string_init(), DBUS_ERROR_FAILED, dbus_error_is_set(), dbus_set_error(), FALSE, NULL, and TRUE.

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:
fd the file descriptor to write
buffer the buffer to write data from
start the first byte in the buffer to write
len the number of bytes to try to write
Returns:
the number of bytes written or -1 on error

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

References _dbus_strerror_from_errno(), _dbus_verbose_bytes_of_string(), _dbus_write(), and DBusSocket::fd.

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.

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:
fd the file descriptor
buffer1 first buffer
start1 first byte to write in first buffer
len1 number of bytes to write from first buffer
buffer2 second buffer, or NULL
start2 first byte to write in second buffer
len2 number of bytes to write in second buffer
Returns:
total bytes written from both buffers, or -1 on error

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

References _dbus_assert, _dbus_strerror_from_errno(), _dbus_write_two(), _DBUS_ZERO, DBusSocket::fd, and NULL.


Generated on 13 Sep 2016 for D-Bus by  doxygen 1.4.7