00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef DBUS_SYSDEPS_H
00026 #define DBUS_SYSDEPS_H
00027
00028 #include <config.h>
00029
00030 #include <dbus/dbus-errors.h>
00031
00032
00033
00034
00035 #include <string.h>
00036 #include <stdarg.h>
00037
00038
00039
00040
00041
00042
00043 #ifdef HAVE_POLL
00044 #include <sys/poll.h>
00045 #endif
00046
00047 DBUS_BEGIN_DECLS
00048
00049 #ifdef DBUS_WIN
00050 #define _DBUS_PATH_SEPARATOR ";"
00051 #else
00052 #define _DBUS_PATH_SEPARATOR ":"
00053 #endif
00054
00055
00056
00058 typedef struct DBusString DBusString;
00059
00061 typedef struct DBusList DBusList;
00062
00064 typedef struct DBusCredentials DBusCredentials;
00065
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00082 #define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \
00083 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
00084 #define _DBUS_GNUC_NORETURN \
00085 __attribute__((__noreturn__))
00086 #else
00087 #define _DBUS_GNUC_PRINTF( format_idx, arg_idx )
00088 #define _DBUS_GNUC_NORETURN
00089 #endif
00090
00098 void _dbus_abort (void) _DBUS_GNUC_NORETURN;
00099
00100 const char* _dbus_getenv (const char *varname);
00101 dbus_bool_t _dbus_setenv (const char *varname,
00102 const char *value);
00103 dbus_bool_t _dbus_clearenv (void);
00104 char ** _dbus_get_environment (void);
00105
00107 typedef unsigned long dbus_pid_t;
00109 typedef unsigned long dbus_uid_t;
00111 typedef unsigned long dbus_gid_t;
00112
00114 #define DBUS_PID_UNSET ((dbus_pid_t) -1)
00115
00116 #define DBUS_UID_UNSET ((dbus_uid_t) -1)
00117
00118 #define DBUS_GID_UNSET ((dbus_gid_t) -1)
00119
00121 #define DBUS_PID_FORMAT "%lu"
00122
00123 #define DBUS_UID_FORMAT "%lu"
00124
00125 #define DBUS_GID_FORMAT "%lu"
00126
00127
00138 dbus_bool_t _dbus_open_tcp_socket (int *fd,
00139 DBusError *error);
00140 dbus_bool_t _dbus_close_socket (int fd,
00141 DBusError *error);
00142 int _dbus_read_socket (int fd,
00143 DBusString *buffer,
00144 int count);
00145 int _dbus_write_socket (int fd,
00146 const DBusString *buffer,
00147 int start,
00148 int len);
00149 int _dbus_write_socket_two (int fd,
00150 const DBusString *buffer1,
00151 int start1,
00152 int len1,
00153 const DBusString *buffer2,
00154 int start2,
00155 int len2);
00156 int _dbus_connect_tcp_socket (const char *host,
00157 const char *port,
00158 const char *family,
00159 DBusError *error);
00160 int _dbus_listen_tcp_socket (const char *host,
00161 const char *port,
00162 const char *family,
00163 DBusString *retport,
00164 int **fds_p,
00165 DBusError *error);
00166 int _dbus_accept (int listen_fd);
00167
00168
00169 dbus_bool_t _dbus_read_credentials_socket (int client_fd,
00170 DBusCredentials *credentials,
00171 DBusError *error);
00172 dbus_bool_t _dbus_send_credentials_socket (int server_fd,
00173 DBusError *error);
00174
00175 dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials,
00176 const DBusString *username);
00177 dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials);
00178 dbus_bool_t _dbus_append_user_from_current_process (DBusString *str);
00179
00180 dbus_bool_t _dbus_parse_unix_user_from_config (const DBusString *username,
00181 dbus_uid_t *uid_p);
00182 dbus_bool_t _dbus_parse_unix_group_from_config (const DBusString *groupname,
00183 dbus_gid_t *gid_p);
00184 dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid,
00185 dbus_gid_t **group_ids,
00186 int *n_group_ids);
00187 dbus_bool_t _dbus_unix_user_is_at_console (dbus_uid_t uid,
00188 DBusError *error);
00189 dbus_bool_t _dbus_unix_user_is_process_owner (dbus_uid_t uid);
00190 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid);
00191
00192 dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory,
00193 DBusCredentials *credentials);
00194
00198 typedef struct DBusAtomic DBusAtomic;
00199
00203 struct DBusAtomic
00204 {
00205 #ifdef DBUS_WIN
00206 volatile long value;
00207 #else
00208 volatile dbus_int32_t value;
00209 #endif
00210 };
00211
00212
00213
00214
00215
00216 #if DBUS_HAVE_ATOMIC_INT_COND
00217 # define DBUS_HAVE_ATOMIC_INT 1
00218 #else
00219 # undef DBUS_HAVE_ATOMIC_INT
00220 #endif
00221
00222 dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic);
00223 dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
00224
00225
00226
00227
00228 #ifdef _AIX
00229
00230 #define _DBUS_POLLIN 0x0001
00231
00232 #define _DBUS_POLLPRI 0x0004
00233
00234 #define _DBUS_POLLOUT 0x0002
00235
00236 #define _DBUS_POLLERR 0x4000
00237
00238 #define _DBUS_POLLHUP 0x2000
00239
00240 #define _DBUS_POLLNVAL 0x8000
00241 #else
00242
00243 #define _DBUS_POLLIN 0x0001
00244
00245 #define _DBUS_POLLPRI 0x0002
00246
00247 #define _DBUS_POLLOUT 0x0004
00248
00249 #define _DBUS_POLLERR 0x0008
00250
00251 #define _DBUS_POLLHUP 0x0010
00252
00253 #define _DBUS_POLLNVAL 0x0020
00254 #endif
00255
00259 typedef struct
00260 {
00261 int fd;
00262 short events;
00263 short revents;
00264 } DBusPollFD;
00265
00266 int _dbus_poll (DBusPollFD *fds,
00267 int n_fds,
00268 int timeout_milliseconds);
00269
00270 void _dbus_sleep_milliseconds (int milliseconds);
00271
00272 void _dbus_get_current_time (long *tv_sec,
00273 long *tv_usec);
00274
00278 dbus_bool_t _dbus_file_exists (const char *file);
00279 dbus_bool_t _dbus_file_get_contents (DBusString *str,
00280 const DBusString *filename,
00281 DBusError *error);
00282 dbus_bool_t _dbus_string_save_to_file (const DBusString *str,
00283 const DBusString *filename,
00284 DBusError *error);
00285
00286 dbus_bool_t _dbus_make_file_world_readable (const DBusString *filename,
00287 DBusError *error);
00288
00289 dbus_bool_t _dbus_create_file_exclusively (const DBusString *filename,
00290 DBusError *error);
00291 dbus_bool_t _dbus_delete_file (const DBusString *filename,
00292 DBusError *error);
00293 dbus_bool_t _dbus_create_directory (const DBusString *filename,
00294 DBusError *error);
00295 dbus_bool_t _dbus_delete_directory (const DBusString *filename,
00296 DBusError *error);
00297
00298 dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir,
00299 const DBusString *next_component);
00300 dbus_bool_t _dbus_string_get_dirname (const DBusString *filename,
00301 DBusString *dirname);
00302 dbus_bool_t _dbus_path_is_absolute (const DBusString *filename);
00303
00304 dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs);
00305 dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs);
00306
00307 dbus_bool_t _dbus_append_system_config_file (DBusString *str);
00308 dbus_bool_t _dbus_append_session_config_file (DBusString *str);
00309
00310 typedef struct {
00311 int fd_or_handle;
00312 } DBusPipe;
00313
00314 void _dbus_pipe_init (DBusPipe *pipe,
00315 int fd);
00316 void _dbus_pipe_init_stdout (DBusPipe *pipe);
00317 int _dbus_pipe_write (DBusPipe *pipe,
00318 const DBusString *buffer,
00319 int start,
00320 int len,
00321 DBusError *error);
00322 int _dbus_pipe_close (DBusPipe *pipe,
00323 DBusError *error);
00324 dbus_bool_t _dbus_pipe_is_valid (DBusPipe *pipe);
00325 void _dbus_pipe_invalidate (DBusPipe *pipe);
00326 dbus_bool_t _dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe);
00327
00328
00330 typedef struct DBusDirIter DBusDirIter;
00331
00332 DBusDirIter* _dbus_directory_open (const DBusString *filename,
00333 DBusError *error);
00334 dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter,
00335 DBusString *filename,
00336 DBusError *error);
00337 void _dbus_directory_close (DBusDirIter *iter);
00338
00339 dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir,
00340 DBusError *error);
00341
00342 void _dbus_fd_set_close_on_exec (int fd);
00343
00344 const char* _dbus_get_tmpdir (void);
00345
00349 void _dbus_generate_pseudorandom_bytes_buffer (char *buffer,
00350 int n_bytes);
00351 void _dbus_generate_random_bytes_buffer (char *buffer,
00352 int n_bytes);
00353 dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
00354 int n_bytes);
00355 dbus_bool_t _dbus_generate_random_ascii (DBusString *str,
00356 int n_bytes);
00357
00358 const char* _dbus_error_from_errno (int error_number);
00359
00360 void _dbus_set_errno_to_zero (void);
00361 dbus_bool_t _dbus_get_is_errno_nonzero (void);
00362 dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (void);
00363 dbus_bool_t _dbus_get_is_errno_enomem (void);
00364 dbus_bool_t _dbus_get_is_errno_eintr (void);
00365 const char* _dbus_strerror_from_errno (void);
00366
00367 void _dbus_disable_sigpipe (void);
00368
00369
00370 void _dbus_exit (int code) _DBUS_GNUC_NORETURN;
00371
00372 int _dbus_printf_string_upper_bound (const char *format,
00373 va_list args);
00374
00375
00379 typedef struct
00380 {
00381 unsigned long mode;
00382 unsigned long nlink;
00383 dbus_uid_t uid;
00384 dbus_gid_t gid;
00385 unsigned long size;
00386 unsigned long atime;
00387 unsigned long mtime;
00388 unsigned long ctime;
00389 } DBusStat;
00390
00391 dbus_bool_t _dbus_stat (const DBusString *filename,
00392 DBusStat *statbuf,
00393 DBusError *error);
00394 dbus_bool_t _dbus_full_duplex_pipe (int *fd1,
00395 int *fd2,
00396 dbus_bool_t blocking,
00397 DBusError *error);
00398
00399 void _dbus_print_backtrace (void);
00400
00401 dbus_bool_t _dbus_become_daemon (const DBusString *pidfile,
00402 DBusPipe *print_pid_pipe,
00403 DBusError *error,
00404 dbus_bool_t keep_umask);
00405
00406 dbus_bool_t _dbus_verify_daemon_user (const char *user);
00407 dbus_bool_t _dbus_change_to_daemon_user (const char *user,
00408 DBusError *error);
00409
00410 dbus_bool_t _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile,
00411 DBusPipe *print_pid_pipe,
00412 dbus_pid_t pid_to_write,
00413 DBusError *error);
00414
00415 dbus_bool_t _dbus_command_for_pid (unsigned long pid,
00416 DBusString *str,
00417 int max_len,
00418 DBusError *error);
00419
00421 typedef void (* DBusSignalHandler) (int sig);
00422
00423 void _dbus_set_signal_handler (int sig,
00424 DBusSignalHandler handler);
00425
00426 dbus_bool_t _dbus_user_at_console (const char *username,
00427 DBusError *error);
00428
00429 void _dbus_init_system_log (void);
00430 void _dbus_log_info (const char *msg, va_list args);
00431 void _dbus_log_security (const char *msg, va_list args);
00432
00433
00434
00435
00436 #if !defined (DBUS_VA_COPY)
00437 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
00438 # define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
00439 # elif defined (DBUS_VA_COPY_AS_ARRAY)
00440 # define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list))
00441 # else
00442 # define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2))
00443 # endif
00444 #endif
00445
00446
00451 #define _DBUS_BYTE_OF_PRIMITIVE(p, i) \
00452 (((const char*)&(p))[(i)])
00453
00458 #define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) \
00459 (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) && \
00460 _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) && \
00461 _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) && \
00462 _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) && \
00463 _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) && \
00464 _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) && \
00465 _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \
00466 _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7))
00467
00468 dbus_bool_t _dbus_get_autolaunch_address (DBusString *address,
00469 DBusError *error);
00470
00474 typedef union DBusGUID DBusGUID;
00475
00476 dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id,
00477 dbus_bool_t create_if_not_found,
00478 DBusError *error);
00479
00485 dbus_bool_t _dbus_threads_init_platform_specific (void);
00486
00487 dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs,
00488 const char *suffix,
00489 DBusList **dir_list);
00490
00491 unsigned long _dbus_pid_for_log (void);
00492
00493
00494
00495
00496
00497 dbus_pid_t _dbus_getpid (void);
00498
00499 void _dbus_flush_caches (void);
00500
00503 DBUS_END_DECLS
00504
00505 #endif