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