D-Bus 1.4.14
|
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 00002 /* dbus-sysdeps.h Wrappers around system/libc features (internal to D-Bus implementation) 00003 * 00004 * Copyright (C) 2002, 2003 Red Hat, Inc. 00005 * Copyright (C) 2003 CodeFactory AB 00006 * 00007 * Licensed under the Academic Free License version 2.1 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 */ 00024 00025 #ifndef DBUS_SYSDEPS_H 00026 #define DBUS_SYSDEPS_H 00027 00028 #include "config.h" 00029 00030 #ifdef HAVE_STDINT_H 00031 #include <stdint.h> 00032 #endif 00033 00034 #include <dbus/dbus-errors.h> 00035 #include <dbus/dbus-file.h> 00036 #include <dbus/dbus-string.h> 00037 00038 /* this is perhaps bogus, but strcmp() etc. are faster if we use the 00039 * stuff straight out of string.h, so have this here for now. 00040 */ 00041 #include <string.h> 00042 #include <stdarg.h> 00043 00044 /* AIX sys/poll.h does #define events reqevents, and other 00045 * wonderousness, so must include sys/poll before declaring 00046 * DBusPollFD 00047 */ 00048 #ifdef HAVE_POLL 00049 #include <sys/poll.h> 00050 #endif 00051 00052 #ifdef DBUS_WINCE 00053 /* Windows CE lacks some system functions (such as errno and clock). 00054 We bring them in here. */ 00055 #include "dbus-sysdeps-wince-glue.h" 00056 #endif 00057 00058 DBUS_BEGIN_DECLS 00059 00060 #ifdef DBUS_WIN 00061 #define _DBUS_PATH_SEPARATOR ";" 00062 #else 00063 #define _DBUS_PATH_SEPARATOR ":" 00064 #endif 00065 00066 /* Forward declarations */ 00067 00068 00070 typedef struct DBusList DBusList; 00071 00073 typedef struct DBusCredentials DBusCredentials; 00074 00076 typedef struct DBusPipe DBusPipe; 00077 00084 void _dbus_abort (void) _DBUS_GNUC_NORETURN; 00085 00086 dbus_bool_t _dbus_check_setuid (void); 00087 const char* _dbus_getenv (const char *varname); 00088 dbus_bool_t _dbus_setenv (const char *varname, 00089 const char *value); 00090 dbus_bool_t _dbus_clearenv (void); 00091 char ** _dbus_get_environment (void); 00092 00094 typedef unsigned long dbus_pid_t; 00096 typedef unsigned long dbus_uid_t; 00098 typedef unsigned long dbus_gid_t; 00099 00101 #define DBUS_PID_UNSET ((dbus_pid_t) -1) 00102 00103 #define DBUS_UID_UNSET ((dbus_uid_t) -1) 00104 00105 #define DBUS_GID_UNSET ((dbus_gid_t) -1) 00106 00108 #define DBUS_PID_FORMAT "%lu" 00109 00110 #define DBUS_UID_FORMAT "%lu" 00111 00112 #define DBUS_GID_FORMAT "%lu" 00113 00114 00125 dbus_bool_t _dbus_open_tcp_socket (int *fd, 00126 DBusError *error); 00127 dbus_bool_t _dbus_close_socket (int fd, 00128 DBusError *error); 00129 int _dbus_read_socket (int fd, 00130 DBusString *buffer, 00131 int count); 00132 int _dbus_write_socket (int fd, 00133 const DBusString *buffer, 00134 int start, 00135 int len); 00136 int _dbus_write_socket_two (int fd, 00137 const DBusString *buffer1, 00138 int start1, 00139 int len1, 00140 const DBusString *buffer2, 00141 int start2, 00142 int len2); 00143 00144 int _dbus_read_socket_with_unix_fds (int fd, 00145 DBusString *buffer, 00146 int count, 00147 int *fds, 00148 int *n_fds); 00149 int _dbus_write_socket_with_unix_fds (int fd, 00150 const DBusString *buffer, 00151 int start, 00152 int len, 00153 const int *fds, 00154 int n_fds); 00155 int _dbus_write_socket_with_unix_fds_two (int fd, 00156 const DBusString *buffer1, 00157 int start1, 00158 int len1, 00159 const DBusString *buffer2, 00160 int start2, 00161 int len2, 00162 const int *fds, 00163 int n_fds); 00164 00165 dbus_bool_t _dbus_socket_is_invalid (int fd); 00166 00167 int _dbus_connect_tcp_socket (const char *host, 00168 const char *port, 00169 const char *family, 00170 DBusError *error); 00171 int _dbus_connect_tcp_socket_with_nonce (const char *host, 00172 const char *port, 00173 const char *family, 00174 const char *noncefile, 00175 DBusError *error); 00176 int _dbus_listen_tcp_socket (const char *host, 00177 const char *port, 00178 const char *family, 00179 DBusString *retport, 00180 int **fds_p, 00181 DBusError *error); 00182 int _dbus_accept (int listen_fd); 00183 00184 00185 dbus_bool_t _dbus_read_credentials_socket (int client_fd, 00186 DBusCredentials *credentials, 00187 DBusError *error); 00188 dbus_bool_t _dbus_send_credentials_socket (int server_fd, 00189 DBusError *error); 00190 00191 dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, 00192 const DBusString *username); 00193 dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials); 00194 dbus_bool_t _dbus_append_user_from_current_process (DBusString *str); 00195 00196 dbus_bool_t _dbus_parse_unix_user_from_config (const DBusString *username, 00197 dbus_uid_t *uid_p); 00198 dbus_bool_t _dbus_parse_unix_group_from_config (const DBusString *groupname, 00199 dbus_gid_t *gid_p); 00200 dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, 00201 dbus_gid_t **group_ids, 00202 int *n_group_ids); 00203 dbus_bool_t _dbus_unix_user_is_at_console (dbus_uid_t uid, 00204 DBusError *error); 00205 dbus_bool_t _dbus_unix_user_is_process_owner (dbus_uid_t uid); 00206 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid); 00207 00208 dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory, 00209 DBusCredentials *credentials); 00210 00211 dbus_bool_t _dbus_daemon_is_session_bus_address_published (const char *scope); 00212 00213 dbus_bool_t _dbus_daemon_publish_session_bus_address (const char* address, const char* shm_name); 00214 00215 void _dbus_daemon_unpublish_session_bus_address (void); 00216 00217 dbus_bool_t _dbus_socket_can_pass_unix_fd(int fd); 00218 00222 typedef struct DBusAtomic DBusAtomic; 00223 00227 struct DBusAtomic 00228 { 00229 #ifdef DBUS_WIN 00230 volatile long value; 00231 #else 00232 volatile dbus_int32_t value; 00233 #endif 00234 }; 00235 00236 /* The value we get from autofoo is in the form of a cpp expression; 00237 * convert that to a conventional defined/undef switch. (We can't get 00238 * the conventional defined/undef because of multiarch builds only running 00239 * ./configure once, on Darwin.) */ 00240 #if DBUS_HAVE_ATOMIC_INT_COND 00241 # define DBUS_HAVE_ATOMIC_INT 1 00242 #else 00243 # undef DBUS_HAVE_ATOMIC_INT 00244 #endif 00245 00246 dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic); 00247 dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic); 00248 dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic); 00249 00250 00251 /* AIX uses different values for poll */ 00252 00253 #ifdef _AIX 00254 00255 #define _DBUS_POLLIN 0x0001 00256 00257 #define _DBUS_POLLPRI 0x0004 00258 00259 #define _DBUS_POLLOUT 0x0002 00260 00261 #define _DBUS_POLLERR 0x4000 00262 00263 #define _DBUS_POLLHUP 0x2000 00264 00265 #define _DBUS_POLLNVAL 0x8000 00266 #elif defined(__HAIKU__) 00267 00268 #define _DBUS_POLLIN 0x0001 00269 00270 #define _DBUS_POLLOUT 0x0002 00271 00272 #define _DBUS_POLLERR 0x0004 00273 00274 #define _DBUS_POLLPRI 0x0020 00275 00276 #define _DBUS_POLLHUP 0x0080 00277 00278 #define _DBUS_POLLNVAL 0x1000 00279 #else 00280 00281 #define _DBUS_POLLIN 0x0001 00282 00283 #define _DBUS_POLLPRI 0x0002 00284 00285 #define _DBUS_POLLOUT 0x0004 00286 00287 #define _DBUS_POLLERR 0x0008 00288 00289 #define _DBUS_POLLHUP 0x0010 00290 00291 #define _DBUS_POLLNVAL 0x0020 00292 #endif 00293 00297 typedef struct 00298 { 00299 int fd; 00300 short events; 00301 short revents; 00302 } DBusPollFD; 00303 00304 int _dbus_poll (DBusPollFD *fds, 00305 int n_fds, 00306 int timeout_milliseconds); 00307 00308 void _dbus_sleep_milliseconds (int milliseconds); 00309 00310 void _dbus_get_current_time (long *tv_sec, 00311 long *tv_usec); 00312 00316 dbus_bool_t _dbus_create_directory (const DBusString *filename, 00317 DBusError *error); 00318 dbus_bool_t _dbus_delete_directory (const DBusString *filename, 00319 DBusError *error); 00320 00321 dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir, 00322 const DBusString *next_component); 00323 dbus_bool_t _dbus_string_get_dirname (const DBusString *filename, 00324 DBusString *dirname); 00325 dbus_bool_t _dbus_path_is_absolute (const DBusString *filename); 00326 00327 dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs); 00328 dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs); 00329 00330 dbus_bool_t _dbus_append_system_config_file (DBusString *str); 00331 dbus_bool_t _dbus_append_session_config_file (DBusString *str); 00332 00334 typedef struct DBusDirIter DBusDirIter; 00335 00336 DBusDirIter* _dbus_directory_open (const DBusString *filename, 00337 DBusError *error); 00338 dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter, 00339 DBusString *filename, 00340 DBusError *error); 00341 void _dbus_directory_close (DBusDirIter *iter); 00342 00343 dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir, 00344 DBusError *error); 00345 00346 void _dbus_fd_set_close_on_exec (intptr_t fd); 00347 00348 const char* _dbus_get_tmpdir (void); 00349 00353 void _dbus_generate_pseudorandom_bytes_buffer (char *buffer, 00354 int n_bytes); 00355 void _dbus_generate_random_bytes_buffer (char *buffer, 00356 int n_bytes); 00357 dbus_bool_t _dbus_generate_random_bytes (DBusString *str, 00358 int n_bytes); 00359 dbus_bool_t _dbus_generate_random_ascii (DBusString *str, 00360 int n_bytes); 00361 00362 const char* _dbus_error_from_errno (int error_number); 00363 const char* _dbus_error_from_system_errno (void); 00364 00365 void _dbus_set_errno_to_zero (void); 00366 dbus_bool_t _dbus_get_is_errno_nonzero (void); 00367 dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (void); 00368 dbus_bool_t _dbus_get_is_errno_enomem (void); 00369 dbus_bool_t _dbus_get_is_errno_eintr (void); 00370 dbus_bool_t _dbus_get_is_errno_epipe (void); 00371 const char* _dbus_strerror_from_errno (void); 00372 00373 void _dbus_disable_sigpipe (void); 00374 00375 00376 void _dbus_exit (int code) _DBUS_GNUC_NORETURN; 00377 00378 int _dbus_printf_string_upper_bound (const char *format, 00379 va_list args); 00380 00381 00385 typedef struct 00386 { 00387 unsigned long mode; 00388 unsigned long nlink; 00389 dbus_uid_t uid; 00390 dbus_gid_t gid; 00391 unsigned long size; 00392 unsigned long atime; 00393 unsigned long mtime; 00394 unsigned long ctime; 00395 } DBusStat; 00396 00397 dbus_bool_t _dbus_stat (const DBusString *filename, 00398 DBusStat *statbuf, 00399 DBusError *error); 00400 dbus_bool_t _dbus_full_duplex_pipe (int *fd1, 00401 int *fd2, 00402 dbus_bool_t blocking, 00403 DBusError *error); 00404 00405 void _dbus_print_backtrace (void); 00406 00407 dbus_bool_t _dbus_become_daemon (const DBusString *pidfile, 00408 DBusPipe *print_pid_pipe, 00409 DBusError *error, 00410 dbus_bool_t keep_umask); 00411 00412 dbus_bool_t _dbus_verify_daemon_user (const char *user); 00413 dbus_bool_t _dbus_change_to_daemon_user (const char *user, 00414 DBusError *error); 00415 00416 dbus_bool_t _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, 00417 DBusPipe *print_pid_pipe, 00418 dbus_pid_t pid_to_write, 00419 DBusError *error); 00420 00421 dbus_bool_t _dbus_command_for_pid (unsigned long pid, 00422 DBusString *str, 00423 int max_len, 00424 DBusError *error); 00425 00427 typedef void (* DBusSignalHandler) (int sig); 00428 00429 void _dbus_set_signal_handler (int sig, 00430 DBusSignalHandler handler); 00431 00432 dbus_bool_t _dbus_user_at_console (const char *username, 00433 DBusError *error); 00434 00435 void _dbus_init_system_log (void); 00436 00437 typedef enum { 00438 DBUS_SYSTEM_LOG_INFO, 00439 DBUS_SYSTEM_LOG_SECURITY, 00440 DBUS_SYSTEM_LOG_FATAL 00441 } DBusSystemLogSeverity; 00442 00443 void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (2, 3); 00444 void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args); 00445 00446 /* Define DBUS_VA_COPY() to do the right thing for copying va_list variables. 00447 * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy. 00448 */ 00449 #if !defined (DBUS_VA_COPY) 00450 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) 00451 # define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) 00452 # elif defined (DBUS_VA_COPY_AS_ARRAY) 00453 # define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list)) 00454 # else /* va_list is a pointer */ 00455 # define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2)) 00456 # endif /* va_list is a pointer */ 00457 #endif /* !DBUS_VA_COPY */ 00458 00459 00464 #define _DBUS_BYTE_OF_PRIMITIVE(p, i) \ 00465 (((const char*)&(p))[(i)]) 00466 00471 #define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) \ 00472 (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) && \ 00473 _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) && \ 00474 _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) && \ 00475 _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) && \ 00476 _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) && \ 00477 _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) && \ 00478 _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \ 00479 _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7)) 00480 00481 dbus_bool_t _dbus_get_autolaunch_address (const char *scope, 00482 DBusString *address, 00483 DBusError *error); 00484 00485 dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported, 00486 DBusString *address, 00487 DBusError *error); 00488 00492 typedef union DBusGUID DBusGUID; 00493 00494 dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id, 00495 dbus_bool_t create_if_not_found, 00496 DBusError *error); 00497 00503 dbus_bool_t _dbus_threads_init_platform_specific (void); 00504 00505 dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs, 00506 const char *suffix, 00507 DBusList **dir_list); 00508 00509 unsigned long _dbus_pid_for_log (void); 00510 00511 /* FIXME move back to dbus-sysdeps-unix.h probably - 00512 * the PID file handling just needs a little more abstraction 00513 * in the bus daemon first. 00514 */ 00515 dbus_pid_t _dbus_getpid (void); 00516 00517 dbus_bool_t _dbus_change_to_daemon_user (const char *user, 00518 DBusError *error); 00519 00520 void _dbus_flush_caches (void); 00521 00522 void _dbus_request_file_descriptor_limit (unsigned int limit); 00523 00524 /* 00525 * replaces the term DBUS_PREFIX in configure_time_path by the 00526 * current dbus installation directory. On unix this function is a noop 00527 * 00528 * @param configure_time_path 00529 * @return real path 00530 */ 00531 const char * 00532 _dbus_replace_install_prefix (const char *configure_time_path); 00533 00536 DBUS_END_DECLS 00537 00538 00539 #ifdef DBUS_WIN 00540 #include "dbus-sysdeps-win.h" 00541 #endif 00542 00543 #endif /* DBUS_SYSDEPS_H */