3212a23735bc3eeb388e8c12c3a3b94324e233db
[platform/upstream/dbus.git] / dbus / dbus-sysdeps.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-sysdeps.h Wrappers around system/libc features (internal to D-BUS implementation)
3  * 
4  * Copyright (C) 2002  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
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.
12  *
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.
17  * 
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
21  *
22  */
23
24 #ifndef DBUS_SYSDEPS_H
25 #define DBUS_SYSDEPS_H
26
27 #include <dbus/dbus-string.h>
28 #include <dbus/dbus-errors.h>
29
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.
32  */
33 #include <string.h>
34
35 /* and it would just be annoying to abstract this */
36 #include <errno.h>
37
38 DBUS_BEGIN_DECLS;
39
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
46  * dbus-memory.c)
47  */
48
49 void _dbus_abort (void);
50
51 const char* _dbus_getenv (const char *varname);
52
53
54 int _dbus_read      (int               fd,
55                      DBusString       *buffer,
56                      int               count);
57 int _dbus_write     (int               fd,
58                      const DBusString *buffer,
59                      int               start,
60                      int               len);
61 int _dbus_write_two (int               fd,
62                      const DBusString *buffer1,
63                      int               start1,
64                      int               len1,
65                      const DBusString *buffer2,
66                      int               start2,
67                      int               len2);
68
69 typedef struct
70 {
71   /* -1 if not available */
72   int pid;
73   int uid;
74   int gid;
75 } DBusCredentials;
76
77 int _dbus_connect_unix_socket (const char     *path,
78                                DBusResultCode *result);
79 int _dbus_listen_unix_socket  (const char     *path,
80                                DBusResultCode *result);
81 int _dbus_accept              (int             listen_fd);
82
83 dbus_bool_t _dbus_read_credentials_unix_socket (int              client_fd,
84                                                 DBusCredentials *credentials,
85                                                 DBusResultCode  *result);
86 dbus_bool_t _dbus_send_credentials_unix_socket (int              server_fd,
87                                                 DBusResultCode  *result);
88
89
90 dbus_bool_t _dbus_credentials_from_username        (const DBusString      *username,
91                                                     DBusCredentials       *credentials);
92 dbus_bool_t _dbus_credentials_from_uid_string      (const DBusString      *uid_str,
93                                                     DBusCredentials       *credentials);
94 void        _dbus_credentials_from_current_process (DBusCredentials       *credentials);
95 dbus_bool_t _dbus_credentials_match                (const DBusCredentials *expected_credentials,
96                                                     const DBusCredentials *provided_credentials);
97
98 dbus_bool_t _dbus_string_append_our_uid (DBusString *str);
99
100
101
102 #define _DBUS_POLLIN      0x0001    /* There is data to read */
103 #define _DBUS_POLLPRI     0x0002    /* There is urgent data to read */
104 #define _DBUS_POLLOUT     0x0004    /* Writing now will not block */
105 #define _DBUS_POLLERR     0x0008    /* Error condition */
106 #define _DBUS_POLLHUP     0x0010    /* Hung up */
107 #define _DBUS_POLLNVAL    0x0020    /* Invalid request: fd not open */
108
109 typedef struct
110 {
111   int fd;
112   short events;
113   short revents;
114 } DBusPollFD;
115
116 int _dbus_poll (DBusPollFD *fds,
117                 int         n_fds,
118                 int         timeout_milliseconds);
119
120 void _dbus_sleep_milliseconds (int milliseconds);
121
122 void _dbus_get_current_time (long *tv_sec,
123                              long *tv_usec);
124
125 DBusResultCode _dbus_file_get_contents   (DBusString       *str,
126                                           const DBusString *filename);
127 DBusResultCode _dbus_string_save_to_file (const DBusString *str,
128                                           const DBusString *filename);
129
130 dbus_bool_t _dbus_concat_dir_and_file (DBusString       *dir,
131                                        const DBusString *next_component);
132
133 typedef struct DBusDirIter DBusDirIter;
134
135 DBusDirIter* _dbus_directory_open          (const DBusString *filename,
136                                             DBusResultCode   *result);
137 dbus_bool_t  _dbus_directory_get_next_file (DBusDirIter      *iter,
138                                             DBusString       *filename,
139                                             DBusResultCode   *result);
140 void         _dbus_directory_close         (DBusDirIter      *iter);
141
142
143 dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
144                                          int         n_bytes);
145
146 DBUS_END_DECLS;
147
148 #endif /* DBUS_SYSDEPS_H */