D-Bus 1.4.20
|
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 #ifdef HAVE_INTTYPES_H 00035 #include <inttypes.h> 00036 #endif 00037 00038 #include <dbus/dbus-errors.h> 00039 #include <dbus/dbus-file.h> 00040 #include <dbus/dbus-string.h> 00041 00042 /* this is perhaps bogus, but strcmp() etc. are faster if we use the 00043 * stuff straight out of string.h, so have this here for now. 00044 */ 00045 #include <string.h> 00046 #include <stdarg.h> 00047 00048 /* AIX sys/poll.h does #define events reqevents, and other 00049 * wonderousness, so must include sys/poll before declaring 00050 * DBusPollFD 00051 */ 00052 #ifdef HAVE_POLL 00053 #include <sys/poll.h> 00054 #endif 00055 00056 #ifdef DBUS_WINCE 00057 /* Windows CE lacks some system functions (such as errno and clock). 00058 We bring them in here. */ 00059 #include "dbus-sysdeps-wince-glue.h" 00060 #endif 00061 00062 DBUS_BEGIN_DECLS 00063 00064 #ifdef DBUS_WIN 00065 #define _DBUS_PATH_SEPARATOR ";" 00066 #else 00067 #define _DBUS_PATH_SEPARATOR ":" 00068 #endif 00069 00070 /* Forward declarations */ 00071 00072 00074 typedef struct DBusList DBusList; 00075 00077 typedef struct DBusCredentials DBusCredentials; 00078 00080 typedef struct DBusPipe DBusPipe; 00081 00088 void _dbus_abort (void) _DBUS_GNUC_NORETURN; 00089 00090 const char* _dbus_getenv (const char *varname); 00091 dbus_bool_t _dbus_setenv (const char *varname, 00092 const char *value); 00093 dbus_bool_t _dbus_clearenv (void); 00094 char ** _dbus_get_environment (void); 00095 00097 typedef unsigned long dbus_pid_t; 00099 typedef unsigned long dbus_uid_t; 00101 typedef unsigned long dbus_gid_t; 00102 00104 #define DBUS_PID_UNSET ((dbus_pid_t) -1) 00105 00106 #define DBUS_UID_UNSET ((dbus_uid_t) -1) 00107 00108 #define DBUS_GID_UNSET ((dbus_gid_t) -1) 00109 00111 #define DBUS_PID_FORMAT "%lu" 00112 00113 #define DBUS_UID_FORMAT "%lu" 00114 00115 #define DBUS_GID_FORMAT "%lu" 00116 00117 00128 dbus_bool_t _dbus_open_tcp_socket (int *fd, 00129 DBusError *error); 00130 dbus_bool_t _dbus_close_socket (int fd, 00131 DBusError *error); 00132 int _dbus_read_socket (int fd, 00133 DBusString *buffer, 00134 int count); 00135 int _dbus_write_socket (int fd, 00136 const DBusString *buffer, 00137 int start, 00138 int len); 00139 int _dbus_write_socket_two (int fd, 00140 const DBusString *buffer1, 00141 int start1, 00142 int len1, 00143 const DBusString *buffer2, 00144 int start2, 00145 int len2); 00146 00147 int _dbus_read_socket_with_unix_fds (int fd, 00148 DBusString *buffer, 00149 int count, 00150 int *fds, 00151 int *n_fds); 00152 int _dbus_write_socket_with_unix_fds (int fd, 00153 const DBusString *buffer, 00154 int start, 00155 int len, 00156 const int *fds, 00157 int n_fds); 00158 int _dbus_write_socket_with_unix_fds_two (int fd, 00159 const DBusString *buffer1, 00160 int start1, 00161 int len1, 00162 const DBusString *buffer2, 00163 int start2, 00164 int len2, 00165 const int *fds, 00166 int n_fds); 00167 00168 dbus_bool_t _dbus_socket_is_invalid (int fd); 00169 00170 int _dbus_connect_tcp_socket (const char *host, 00171 const char *port, 00172 const char *family, 00173 DBusError *error); 00174 int _dbus_connect_tcp_socket_with_nonce (const char *host, 00175 const char *port, 00176 const char *family, 00177 const char *noncefile, 00178 DBusError *error); 00179 int _dbus_listen_tcp_socket (const char *host, 00180 const char *port, 00181 const char *family, 00182 DBusString *retport, 00183 int **fds_p, 00184 DBusError *error); 00185 int _dbus_accept (int listen_fd); 00186 00187 00188 dbus_bool_t _dbus_read_credentials_socket (int client_fd, 00189 DBusCredentials *credentials, 00190 DBusError *error); 00191 dbus_bool_t _dbus_send_credentials_socket (int server_fd, 00192 DBusError *error); 00193 00194 dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, 00195 const DBusString *username); 00196 dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials); 00197 dbus_bool_t _dbus_append_user_from_current_process (DBusString *str); 00198 00199 dbus_bool_t _dbus_parse_unix_user_from_config (const DBusString *username, 00200 dbus_uid_t *uid_p); 00201 dbus_bool_t _dbus_parse_unix_group_from_config (const DBusString *groupname, 00202 dbus_gid_t *gid_p); 00203 dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, 00204 dbus_gid_t **group_ids, 00205 int *n_group_ids); 00206 dbus_bool_t _dbus_unix_user_is_at_console (dbus_uid_t uid, 00207 DBusError *error); 00208 dbus_bool_t _dbus_unix_user_is_process_owner (dbus_uid_t uid); 00209 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid); 00210 00211 dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory, 00212 DBusCredentials *credentials); 00213 00214 dbus_bool_t _dbus_daemon_is_session_bus_address_published (const char *scope); 00215 00216 dbus_bool_t _dbus_daemon_publish_session_bus_address (const char* address, const char* shm_name); 00217 00218 void _dbus_daemon_unpublish_session_bus_address (void); 00219 00220 dbus_bool_t _dbus_socket_can_pass_unix_fd(int fd); 00221 00225 typedef struct DBusAtomic DBusAtomic; 00226 00230 struct DBusAtomic 00231 { 00232 #ifdef DBUS_WIN 00233 volatile long value; 00234 #else 00235 volatile dbus_int32_t value; 00236 #endif 00237 }; 00238 00239 /* The value we get from autofoo is in the form of a cpp expression; 00240 * convert that to a conventional defined/undef switch. (We can't get 00241 * the conventional defined/undef because of multiarch builds only running 00242 * ./configure once, on Darwin.) */ 00243 #if DBUS_HAVE_ATOMIC_INT_COND 00244 # define DBUS_HAVE_ATOMIC_INT 1 00245 #else 00246 # undef DBUS_HAVE_ATOMIC_INT 00247 #endif 00248 00249 dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic); 00250 dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic); 00251 dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic); 00252 00253 00254 /* AIX uses different values for poll */ 00255 00256 #ifdef _AIX 00257 00258 #define _DBUS_POLLIN 0x0001 00259 00260 #define _DBUS_POLLPRI 0x0004 00261 00262 #define _DBUS_POLLOUT 0x0002 00263 00264 #define _DBUS_POLLERR 0x4000 00265 00266 #define _DBUS_POLLHUP 0x2000 00267 00268 #define _DBUS_POLLNVAL 0x8000 00269 #elif defined(__HAIKU__) 00270 00271 #define _DBUS_POLLIN 0x0001 00272 00273 #define _DBUS_POLLOUT 0x0002 00274 00275 #define _DBUS_POLLERR 0x0004 00276 00277 #define _DBUS_POLLPRI 0x0020 00278 00279 #define _DBUS_POLLHUP 0x0080 00280 00281 #define _DBUS_POLLNVAL 0x1000 00282 #else 00283 00284 #define _DBUS_POLLIN 0x0001 00285 00286 #define _DBUS_POLLPRI 0x0002 00287 00288 #define _DBUS_POLLOUT 0x0004 00289 00290 #define _DBUS_POLLERR 0x0008 00291 00292 #define _DBUS_POLLHUP 0x0010 00293 00294 #define _DBUS_POLLNVAL 0x0020 00295 #endif 00296 00300 typedef struct 00301 { 00302 int fd; 00303 short events; 00304 short revents; 00305 } DBusPollFD; 00306 00307 int _dbus_poll (DBusPollFD *fds, 00308 int n_fds, 00309 int timeout_milliseconds); 00310 00311 void _dbus_sleep_milliseconds (int milliseconds); 00312 00313 void _dbus_get_current_time (long *tv_sec, 00314 long *tv_usec); 00315 00319 dbus_bool_t _dbus_create_directory (const DBusString *filename, 00320 DBusError *error); 00321 dbus_bool_t _dbus_delete_directory (const DBusString *filename, 00322 DBusError *error); 00323 00324 dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir, 00325 const DBusString *next_component); 00326 dbus_bool_t _dbus_string_get_dirname (const DBusString *filename, 00327 DBusString *dirname); 00328 dbus_bool_t _dbus_path_is_absolute (const DBusString *filename); 00329 00330 dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs); 00331 dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs); 00332 00333 dbus_bool_t _dbus_append_system_config_file (DBusString *str); 00334 dbus_bool_t _dbus_append_session_config_file (DBusString *str); 00335 00337 typedef struct DBusDirIter DBusDirIter; 00338 00339 DBusDirIter* _dbus_directory_open (const DBusString *filename, 00340 DBusError *error); 00341 dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter, 00342 DBusString *filename, 00343 DBusError *error); 00344 void _dbus_directory_close (DBusDirIter *iter); 00345 00346 dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir, 00347 DBusError *error); 00348 00349 void _dbus_fd_set_close_on_exec (intptr_t fd); 00350 00351 const char* _dbus_get_tmpdir (void); 00352 00356 void _dbus_generate_pseudorandom_bytes_buffer (char *buffer, 00357 int n_bytes); 00358 void _dbus_generate_random_bytes_buffer (char *buffer, 00359 int n_bytes); 00360 dbus_bool_t _dbus_generate_random_bytes (DBusString *str, 00361 int n_bytes); 00362 dbus_bool_t _dbus_generate_random_ascii (DBusString *str, 00363 int n_bytes); 00364 00365 const char* _dbus_error_from_errno (int error_number); 00366 const char* _dbus_error_from_system_errno (void); 00367 00368 void _dbus_set_errno_to_zero (void); 00369 dbus_bool_t _dbus_get_is_errno_nonzero (void); 00370 dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (void); 00371 dbus_bool_t _dbus_get_is_errno_enomem (void); 00372 dbus_bool_t _dbus_get_is_errno_eintr (void); 00373 dbus_bool_t _dbus_get_is_errno_epipe (void); 00374 const char* _dbus_strerror_from_errno (void); 00375 00376 void _dbus_disable_sigpipe (void); 00377 00378 00379 void _dbus_exit (int code) _DBUS_GNUC_NORETURN; 00380 00381 int _dbus_printf_string_upper_bound (const char *format, 00382 va_list args); 00383 00384 00388 typedef struct 00389 { 00390 unsigned long mode; 00391 unsigned long nlink; 00392 dbus_uid_t uid; 00393 dbus_gid_t gid; 00394 unsigned long size; 00395 unsigned long atime; 00396 unsigned long mtime; 00397 unsigned long ctime; 00398 } DBusStat; 00399 00400 dbus_bool_t _dbus_stat (const DBusString *filename, 00401 DBusStat *statbuf, 00402 DBusError *error); 00403 dbus_bool_t _dbus_full_duplex_pipe (int *fd1, 00404 int *fd2, 00405 dbus_bool_t blocking, 00406 DBusError *error); 00407 00408 void _dbus_print_backtrace (void); 00409 00410 dbus_bool_t _dbus_become_daemon (const DBusString *pidfile, 00411 DBusPipe *print_pid_pipe, 00412 DBusError *error, 00413 dbus_bool_t keep_umask); 00414 00415 dbus_bool_t _dbus_verify_daemon_user (const char *user); 00416 dbus_bool_t _dbus_change_to_daemon_user (const char *user, 00417 DBusError *error); 00418 00419 dbus_bool_t _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, 00420 DBusPipe *print_pid_pipe, 00421 dbus_pid_t pid_to_write, 00422 DBusError *error); 00423 00424 dbus_bool_t _dbus_command_for_pid (unsigned long pid, 00425 DBusString *str, 00426 int max_len, 00427 DBusError *error); 00428 00430 typedef void (* DBusSignalHandler) (int sig); 00431 00432 void _dbus_set_signal_handler (int sig, 00433 DBusSignalHandler handler); 00434 00435 dbus_bool_t _dbus_user_at_console (const char *username, 00436 DBusError *error); 00437 00438 void _dbus_init_system_log (void); 00439 00440 typedef enum { 00441 DBUS_SYSTEM_LOG_INFO, 00442 DBUS_SYSTEM_LOG_SECURITY, 00443 DBUS_SYSTEM_LOG_FATAL 00444 } DBusSystemLogSeverity; 00445 00446 void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (2, 3); 00447 void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args); 00448 00449 /* Define DBUS_VA_COPY() to do the right thing for copying va_list variables. 00450 * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy. 00451 */ 00452 #if !defined (DBUS_VA_COPY) 00453 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) 00454 # define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) 00455 # elif defined (DBUS_VA_COPY_AS_ARRAY) 00456 # define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list)) 00457 # else /* va_list is a pointer */ 00458 # define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2)) 00459 # endif /* va_list is a pointer */ 00460 #endif /* !DBUS_VA_COPY */ 00461 00462 00467 #define _DBUS_BYTE_OF_PRIMITIVE(p, i) \ 00468 (((const char*)&(p))[(i)]) 00469 00474 #define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) \ 00475 (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) && \ 00476 _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) && \ 00477 _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) && \ 00478 _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) && \ 00479 _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) && \ 00480 _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) && \ 00481 _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \ 00482 _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7)) 00483 00484 dbus_bool_t _dbus_get_autolaunch_address (const char *scope, 00485 DBusString *address, 00486 DBusError *error); 00487 00488 dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported, 00489 DBusString *address, 00490 DBusError *error); 00491 00495 typedef union DBusGUID DBusGUID; 00496 00497 dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id, 00498 dbus_bool_t create_if_not_found, 00499 DBusError *error); 00500 00506 dbus_bool_t _dbus_threads_init_platform_specific (void); 00507 00508 dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs, 00509 const char *suffix, 00510 DBusList **dir_list); 00511 00512 unsigned long _dbus_pid_for_log (void); 00513 00514 /* FIXME move back to dbus-sysdeps-unix.h probably - 00515 * the PID file handling just needs a little more abstraction 00516 * in the bus daemon first. 00517 */ 00518 dbus_pid_t _dbus_getpid (void); 00519 00520 dbus_bool_t _dbus_change_to_daemon_user (const char *user, 00521 DBusError *error); 00522 00523 void _dbus_flush_caches (void); 00524 00525 void _dbus_request_file_descriptor_limit (unsigned int limit); 00526 00527 /* 00528 * replaces the term DBUS_PREFIX in configure_time_path by the 00529 * current dbus installation directory. On unix this function is a noop 00530 * 00531 * @param configure_time_path 00532 * @return real path 00533 */ 00534 const char * 00535 _dbus_replace_install_prefix (const char *configure_time_path); 00536 00539 DBUS_END_DECLS 00540 00541 00542 #ifdef DBUS_WIN 00543 #include "dbus-sysdeps-win.h" 00544 #endif 00545 00546 #endif /* DBUS_SYSDEPS_H */