1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-sysdeps.h Wrappers around system/libc features (internal to D-BUS implementation)
4 * Copyright (C) 2002 Red Hat, Inc.
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef DBUS_SYSDEPS_H
25 #define DBUS_SYSDEPS_H
27 #include <dbus/dbus-string.h>
28 #include <dbus/dbus-errors.h>
30 /* this is perhaps bogus, but strcmp() etc. are faster if we use the
31 * stuff straight out of string.h, so have this here for now.
35 /* and it would just be annoying to abstract this */
40 /* The idea of this file is to encapsulate everywhere that we're
41 * relying on external libc features, for ease of security
42 * auditing. The idea is from vsftpd. This also gives us a chance to
43 * make things more convenient to use, e.g. by reading into a
44 * DBusString. Operating system headers aren't intended to be used
45 * outside of this file and a limited number of others (such as
49 void _dbus_abort (void);
51 const char* _dbus_getenv (const char *varname);
52 dbus_bool_t _dbus_setenv (const char *varname,
55 int _dbus_read (int fd,
58 int _dbus_write (int fd,
59 const DBusString *buffer,
62 int _dbus_write_two (int fd,
63 const DBusString *buffer1,
66 const DBusString *buffer2,
72 /* -1 if not available */
78 int _dbus_connect_unix_socket (const char *path,
79 DBusResultCode *result);
80 int _dbus_listen_unix_socket (const char *path,
81 DBusResultCode *result);
82 int _dbus_connect_tcp_socket (const char *host,
84 DBusResultCode *result);
85 int _dbus_listen_tcp_socket (const char *host,
87 DBusResultCode *result);
88 int _dbus_accept (int listen_fd);
90 dbus_bool_t _dbus_read_credentials_unix_socket (int client_fd,
91 DBusCredentials *credentials,
92 DBusResultCode *result);
93 dbus_bool_t _dbus_send_credentials_unix_socket (int server_fd,
94 DBusResultCode *result);
97 dbus_bool_t _dbus_credentials_from_username (const DBusString *username,
98 DBusCredentials *credentials);
99 dbus_bool_t _dbus_credentials_from_uid_string (const DBusString *uid_str,
100 DBusCredentials *credentials);
101 void _dbus_credentials_from_current_process (DBusCredentials *credentials);
102 dbus_bool_t _dbus_credentials_match (const DBusCredentials *expected_credentials,
103 const DBusCredentials *provided_credentials);
105 dbus_bool_t _dbus_string_append_our_uid (DBusString *str);
108 typedef int dbus_atomic_t;
110 dbus_atomic_t _dbus_atomic_inc (dbus_atomic_t *atomic);
111 dbus_atomic_t _dbus_atomic_dec (dbus_atomic_t *atomic);
113 #define _DBUS_POLLIN 0x0001 /* There is data to read */
114 #define _DBUS_POLLPRI 0x0002 /* There is urgent data to read */
115 #define _DBUS_POLLOUT 0x0004 /* Writing now will not block */
116 #define _DBUS_POLLERR 0x0008 /* Error condition */
117 #define _DBUS_POLLHUP 0x0010 /* Hung up */
118 #define _DBUS_POLLNVAL 0x0020 /* Invalid request: fd not open */
127 int _dbus_poll (DBusPollFD *fds,
129 int timeout_milliseconds);
131 void _dbus_sleep_milliseconds (int milliseconds);
133 void _dbus_get_current_time (long *tv_sec,
136 DBusResultCode _dbus_file_get_contents (DBusString *str,
137 const DBusString *filename);
138 DBusResultCode _dbus_string_save_to_file (const DBusString *str,
139 const DBusString *filename);
141 dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir,
142 const DBusString *next_component);
144 typedef struct DBusDirIter DBusDirIter;
146 DBusDirIter* _dbus_directory_open (const DBusString *filename,
147 DBusResultCode *result);
148 dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter,
149 DBusString *filename,
150 DBusResultCode *result);
151 void _dbus_directory_close (DBusDirIter *iter);
154 dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
157 const char *_dbus_errno_to_string (int errnum);
159 typedef void (* DBusSpawnChildSetupFunc) (void *user_data);
161 dbus_bool_t _dbus_spawn_async (char **argv,
162 DBusSpawnChildSetupFunc child_setup,
167 void _dbus_disable_sigpipe (void);
169 void _dbus_fd_set_close_on_exec (int fd);
173 #endif /* DBUS_SYSDEPS_H */