|
D-Bus
1.6.30
|
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 dbus_bool_t _dbus_check_setuid (void); 00091 const char* _dbus_getenv (const char *varname); 00092 dbus_bool_t _dbus_setenv (const char *varname, 00093 const char *value); 00094 dbus_bool_t _dbus_clearenv (void); 00095 char ** _dbus_get_environment (void); 00096 00098 typedef unsigned long dbus_pid_t; 00100 typedef unsigned long dbus_uid_t; 00102 typedef unsigned long dbus_gid_t; 00103 00105 #define DBUS_PID_UNSET ((dbus_pid_t) -1) 00106 00107 #define DBUS_UID_UNSET ((dbus_uid_t) -1) 00108 00109 #define DBUS_GID_UNSET ((dbus_gid_t) -1) 00110 00112 #define DBUS_PID_FORMAT "%lu" 00113 00114 #define DBUS_UID_FORMAT "%lu" 00115 00116 #define DBUS_GID_FORMAT "%lu" 00117 00118 00129 dbus_bool_t _dbus_close_socket (int fd, 00130 DBusError *error); 00131 int _dbus_read_socket (int fd, 00132 DBusString *buffer, 00133 int count); 00134 int _dbus_write_socket (int fd, 00135 const DBusString *buffer, 00136 int start, 00137 int len); 00138 int _dbus_write_socket_two (int fd, 00139 const DBusString *buffer1, 00140 int start1, 00141 int len1, 00142 const DBusString *buffer2, 00143 int start2, 00144 int len2); 00145 00146 int _dbus_read_socket_with_unix_fds (int fd, 00147 DBusString *buffer, 00148 int count, 00149 int *fds, 00150 int *n_fds); 00151 int _dbus_write_socket_with_unix_fds (int fd, 00152 const DBusString *buffer, 00153 int start, 00154 int len, 00155 const int *fds, 00156 int n_fds); 00157 int _dbus_write_socket_with_unix_fds_two (int fd, 00158 const DBusString *buffer1, 00159 int start1, 00160 int len1, 00161 const DBusString *buffer2, 00162 int start2, 00163 int len2, 00164 const int *fds, 00165 int n_fds); 00166 00167 dbus_bool_t _dbus_socket_is_invalid (int fd); 00168 00169 int _dbus_connect_tcp_socket (const char *host, 00170 const char *port, 00171 const char *family, 00172 DBusError *error); 00173 int _dbus_connect_tcp_socket_with_nonce (const char *host, 00174 const char *port, 00175 const char *family, 00176 const char *noncefile, 00177 DBusError *error); 00178 int _dbus_listen_tcp_socket (const char *host, 00179 const char *port, 00180 const char *family, 00181 DBusString *retport, 00182 int **fds_p, 00183 DBusError *error); 00184 int _dbus_accept (int listen_fd); 00185 00186 00187 dbus_bool_t _dbus_read_credentials_socket (int client_fd, 00188 DBusCredentials *credentials, 00189 DBusError *error); 00190 dbus_bool_t _dbus_send_credentials_socket (int server_fd, 00191 DBusError *error); 00192 00193 dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, 00194 const DBusString *username); 00195 dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials); 00196 dbus_bool_t _dbus_append_user_from_current_process (DBusString *str); 00197 00198 dbus_bool_t _dbus_parse_unix_user_from_config (const DBusString *username, 00199 dbus_uid_t *uid_p); 00200 dbus_bool_t _dbus_parse_unix_group_from_config (const DBusString *groupname, 00201 dbus_gid_t *gid_p); 00202 dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, 00203 dbus_gid_t **group_ids, 00204 int *n_group_ids); 00205 dbus_bool_t _dbus_unix_user_is_at_console (dbus_uid_t uid, 00206 DBusError *error); 00207 dbus_bool_t _dbus_unix_user_is_process_owner (dbus_uid_t uid); 00208 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid); 00209 00210 dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory, 00211 DBusCredentials *credentials); 00212 00213 dbus_bool_t _dbus_daemon_is_session_bus_address_published (const char *scope); 00214 00215 dbus_bool_t _dbus_daemon_publish_session_bus_address (const char* address, const char* shm_name); 00216 00217 void _dbus_daemon_unpublish_session_bus_address (void); 00218 00219 dbus_bool_t _dbus_socket_can_pass_unix_fd(int fd); 00220 00224 typedef struct DBusAtomic DBusAtomic; 00225 00229 struct DBusAtomic 00230 { 00231 #ifdef DBUS_WIN 00232 volatile long value; 00233 #else 00234 volatile dbus_int32_t value; 00235 #endif 00236 }; 00237 00238 /* The value we get from autofoo is in the form of a cpp expression; 00239 * convert that to a conventional defined/undef switch. (We can't get 00240 * the conventional defined/undef because of multiarch builds only running 00241 * ./configure once, on Darwin.) */ 00242 #if DBUS_HAVE_ATOMIC_INT_COND 00243 # define DBUS_HAVE_ATOMIC_INT 1 00244 #else 00245 # undef DBUS_HAVE_ATOMIC_INT 00246 #endif 00247 00248 dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic); 00249 dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic); 00250 dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic); 00251 00252 00253 /* AIX uses different values for poll */ 00254 00255 #ifdef _AIX 00256 00257 #define _DBUS_POLLIN 0x0001 00258 00259 #define _DBUS_POLLPRI 0x0004 00260 00261 #define _DBUS_POLLOUT 0x0002 00262 00263 #define _DBUS_POLLERR 0x4000 00264 00265 #define _DBUS_POLLHUP 0x2000 00266 00267 #define _DBUS_POLLNVAL 0x8000 00268 #elif defined(__HAIKU__) 00269 00270 #define _DBUS_POLLIN 0x0001 00271 00272 #define _DBUS_POLLOUT 0x0002 00273 00274 #define _DBUS_POLLERR 0x0004 00275 00276 #define _DBUS_POLLPRI 0x0020 00277 00278 #define _DBUS_POLLHUP 0x0080 00279 00280 #define _DBUS_POLLNVAL 0x1000 00281 #else 00282 00283 #define _DBUS_POLLIN 0x0001 00284 00285 #define _DBUS_POLLPRI 0x0002 00286 00287 #define _DBUS_POLLOUT 0x0004 00288 00289 #define _DBUS_POLLERR 0x0008 00290 00291 #define _DBUS_POLLHUP 0x0010 00292 00293 #define _DBUS_POLLNVAL 0x0020 00294 #endif 00295 00299 typedef struct 00300 { 00301 int fd; 00302 short events; 00303 short revents; 00304 } DBusPollFD; 00305 00306 int _dbus_poll (DBusPollFD *fds, 00307 int n_fds, 00308 int timeout_milliseconds); 00309 00310 void _dbus_sleep_milliseconds (int milliseconds); 00311 00312 void _dbus_get_monotonic_time (long *tv_sec, 00313 long *tv_usec); 00314 00315 void _dbus_get_real_time (long *tv_sec, 00316 long *tv_usec); 00317 00321 dbus_bool_t _dbus_create_directory (const DBusString *filename, 00322 DBusError *error); 00323 dbus_bool_t _dbus_delete_directory (const DBusString *filename, 00324 DBusError *error); 00325 00326 dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir, 00327 const DBusString *next_component); 00328 dbus_bool_t _dbus_string_get_dirname (const DBusString *filename, 00329 DBusString *dirname); 00330 dbus_bool_t _dbus_path_is_absolute (const DBusString *filename); 00331 00332 dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs); 00333 dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs); 00334 00335 dbus_bool_t _dbus_append_system_config_file (DBusString *str); 00336 dbus_bool_t _dbus_append_session_config_file (DBusString *str); 00337 00339 typedef struct DBusDirIter DBusDirIter; 00340 00341 DBusDirIter* _dbus_directory_open (const DBusString *filename, 00342 DBusError *error); 00343 dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter, 00344 DBusString *filename, 00345 DBusError *error); 00346 void _dbus_directory_close (DBusDirIter *iter); 00347 00348 dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir, 00349 DBusError *error); 00350 00351 void _dbus_fd_set_close_on_exec (intptr_t fd); 00352 00353 const char* _dbus_get_tmpdir (void); 00354 00358 void _dbus_generate_pseudorandom_bytes_buffer (char *buffer, 00359 int n_bytes); 00360 void _dbus_generate_random_bytes_buffer (char *buffer, 00361 int n_bytes); 00362 dbus_bool_t _dbus_generate_random_bytes (DBusString *str, 00363 int n_bytes); 00364 dbus_bool_t _dbus_generate_random_ascii (DBusString *str, 00365 int n_bytes); 00366 00367 const char* _dbus_error_from_errno (int error_number); 00368 const char* _dbus_error_from_system_errno (void); 00369 00370 void _dbus_set_errno_to_zero (void); 00371 dbus_bool_t _dbus_get_is_errno_nonzero (void); 00372 dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (void); 00373 dbus_bool_t _dbus_get_is_errno_enomem (void); 00374 dbus_bool_t _dbus_get_is_errno_eintr (void); 00375 dbus_bool_t _dbus_get_is_errno_epipe (void); 00376 dbus_bool_t _dbus_get_is_errno_etoomanyrefs (void); 00377 const char* _dbus_strerror_from_errno (void); 00378 00379 void _dbus_disable_sigpipe (void); 00380 00381 00382 void _dbus_exit (int code) _DBUS_GNUC_NORETURN; 00383 00384 int _dbus_printf_string_upper_bound (const char *format, 00385 va_list args); 00386 00387 00391 typedef struct 00392 { 00393 unsigned long mode; 00394 unsigned long nlink; 00395 dbus_uid_t uid; 00396 dbus_gid_t gid; 00397 unsigned long size; 00398 unsigned long atime; 00399 unsigned long mtime; 00400 unsigned long ctime; 00401 } DBusStat; 00402 00403 dbus_bool_t _dbus_stat (const DBusString *filename, 00404 DBusStat *statbuf, 00405 DBusError *error); 00406 dbus_bool_t _dbus_full_duplex_pipe (int *fd1, 00407 int *fd2, 00408 dbus_bool_t blocking, 00409 DBusError *error); 00410 00411 void _dbus_print_backtrace (void); 00412 00413 dbus_bool_t _dbus_become_daemon (const DBusString *pidfile, 00414 DBusPipe *print_pid_pipe, 00415 DBusError *error, 00416 dbus_bool_t keep_umask); 00417 00418 dbus_bool_t _dbus_verify_daemon_user (const char *user); 00419 dbus_bool_t _dbus_change_to_daemon_user (const char *user, 00420 DBusError *error); 00421 00422 dbus_bool_t _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, 00423 DBusPipe *print_pid_pipe, 00424 dbus_pid_t pid_to_write, 00425 DBusError *error); 00426 00427 dbus_bool_t _dbus_command_for_pid (unsigned long pid, 00428 DBusString *str, 00429 int max_len, 00430 DBusError *error); 00431 00433 typedef void (* DBusSignalHandler) (int sig); 00434 00435 void _dbus_set_signal_handler (int sig, 00436 DBusSignalHandler handler); 00437 00438 dbus_bool_t _dbus_user_at_console (const char *username, 00439 DBusError *error); 00440 00441 void _dbus_init_system_log (void); 00442 00443 typedef enum { 00444 DBUS_SYSTEM_LOG_INFO, 00445 DBUS_SYSTEM_LOG_SECURITY, 00446 DBUS_SYSTEM_LOG_FATAL 00447 } DBusSystemLogSeverity; 00448 00449 void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (2, 3); 00450 void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args); 00451 00452 /* Define DBUS_VA_COPY() to do the right thing for copying va_list variables. 00453 * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy. 00454 */ 00455 #if !defined (DBUS_VA_COPY) 00456 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) 00457 # define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) 00458 # elif defined (DBUS_VA_COPY_AS_ARRAY) 00459 # define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list)) 00460 # else /* va_list is a pointer */ 00461 # define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2)) 00462 # endif /* va_list is a pointer */ 00463 #endif /* !DBUS_VA_COPY */ 00464 00465 00470 #define _DBUS_BYTE_OF_PRIMITIVE(p, i) \ 00471 (((const char*)&(p))[(i)]) 00472 00477 #define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) \ 00478 (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) && \ 00479 _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) && \ 00480 _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) && \ 00481 _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) && \ 00482 _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) && \ 00483 _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) && \ 00484 _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \ 00485 _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7)) 00486 00487 dbus_bool_t _dbus_get_autolaunch_address (const char *scope, 00488 DBusString *address, 00489 DBusError *error); 00490 00491 dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported, 00492 DBusString *address, 00493 DBusError *error); 00494 00498 typedef union DBusGUID DBusGUID; 00499 00500 dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id, 00501 dbus_bool_t create_if_not_found, 00502 DBusError *error); 00503 00509 dbus_bool_t _dbus_threads_init_platform_specific (void); 00510 00511 dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs, 00512 const char *suffix, 00513 DBusList **dir_list); 00514 00515 unsigned long _dbus_pid_for_log (void); 00516 00517 /* FIXME move back to dbus-sysdeps-unix.h probably - 00518 * the PID file handling just needs a little more abstraction 00519 * in the bus daemon first. 00520 */ 00521 dbus_pid_t _dbus_getpid (void); 00522 00523 dbus_bool_t _dbus_change_to_daemon_user (const char *user, 00524 DBusError *error); 00525 00526 void _dbus_flush_caches (void); 00527 00528 /* 00529 * replaces the term DBUS_PREFIX in configure_time_path by the 00530 * current dbus installation directory. On unix this function is a noop 00531 * 00532 * @param configure_time_path 00533 * @return real path 00534 */ 00535 const char * 00536 _dbus_replace_install_prefix (const char *configure_time_path); 00537 00538 /* Do not set this too high: it is a denial-of-service risk. 00539 * See <https://bugs.freedesktop.org/show_bug.cgi?id=82820> 00540 * 00541 * (This needs to be in the non-Unix-specific header so that 00542 * the config-parser can use it.) 00543 */ 00544 #define DBUS_DEFAULT_MESSAGE_UNIX_FDS 16 00545 00546 typedef struct DBusRLimit DBusRLimit; 00547 00548 DBusRLimit *_dbus_rlimit_save_fd_limit (DBusError *error); 00549 dbus_bool_t _dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired, 00550 DBusError *error); 00551 dbus_bool_t _dbus_rlimit_restore_fd_limit (DBusRLimit *saved, 00552 DBusError *error); 00553 void _dbus_rlimit_free (DBusRLimit *lim); 00554 00557 DBUS_END_DECLS 00558 00559 00560 #ifdef DBUS_WIN 00561 #include "dbus-sysdeps-win.h" 00562 #endif 00563 00564 #endif /* DBUS_SYSDEPS_H */
1.7.6.1