2003-01-26 Havoc Pennington <hp@pobox.com>
[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
29 /* this is perhaps bogus, but strcmp() etc. are faster if we use the
30  * stuff straight out of string.h, so have this here for now.
31  */
32 #include <string.h>
33
34 /* and it would just be annoying to abstract this */
35 #include <errno.h>
36
37 DBUS_BEGIN_DECLS;
38
39 /* The idea of this file is to encapsulate everywhere that we're
40  * relying on external libc features, for ease of security
41  * auditing. The idea is from vsftpd. This also gives us a chance to
42  * make things more convenient to use, e.g.  by reading into a
43  * DBusString. Operating system headers aren't intended to be used
44  * outside of this file and a limited number of others (such as
45  * dbus-memory.c)
46  */
47
48 void _dbus_abort (void);
49
50 const char* _dbus_getenv (const char *varname);
51
52
53 int _dbus_read      (int               fd,
54                      DBusString       *buffer,
55                      int               count);
56 int _dbus_write     (int               fd,
57                      const DBusString *buffer,
58                      int               start,
59                      int               len);
60 int _dbus_write_two (int               fd,
61                      const DBusString *buffer1,
62                      int               start1,
63                      int               len1,
64                      const DBusString *buffer2,
65                      int               start2,
66                      int               len2);
67
68 typedef struct
69 {
70   /* -1 if not available */
71   int pid;
72   int uid;
73   int gid;
74 } DBusCredentials;
75
76 int _dbus_connect_unix_socket (const char     *path,
77                                DBusResultCode *result);
78 int _dbus_listen_unix_socket  (const char     *path,
79                                DBusResultCode *result);
80 int _dbus_accept              (int             listen_fd);
81
82 dbus_bool_t _dbus_read_credentials_unix_socket (int              client_fd,
83                                                 DBusCredentials *credentials,
84                                                 DBusResultCode  *result);
85 dbus_bool_t _dbus_send_credentials_unix_socket (int              server_fd,
86                                                 DBusResultCode  *result);
87
88
89 dbus_bool_t _dbus_credentials_from_username        (const DBusString      *username,
90                                                     DBusCredentials       *credentials);
91 dbus_bool_t _dbus_credentials_from_uid_string      (const DBusString      *uid_str,
92                                                     DBusCredentials       *credentials);
93 void        _dbus_credentials_from_current_process (DBusCredentials       *credentials);
94 dbus_bool_t _dbus_credentials_match                (const DBusCredentials *expected_credentials,
95                                                     const DBusCredentials *provided_credentials);
96
97 dbus_bool_t _dbus_string_append_our_uid (DBusString *str);
98
99
100
101 #define _DBUS_POLLIN      0x0001    /* There is data to read */
102 #define _DBUS_POLLPRI     0x0002    /* There is urgent data to read */
103 #define _DBUS_POLLOUT     0x0004    /* Writing now will not block */
104 #define _DBUS_POLLERR     0x0008    /* Error condition */
105 #define _DBUS_POLLHUP     0x0010    /* Hung up */
106 #define _DBUS_POLLNVAL    0x0020    /* Invalid request: fd not open */
107
108 typedef struct
109 {
110   int fd;
111   short events;
112   short revents;
113 } DBusPollFD;
114
115 int _dbus_poll (DBusPollFD *fds,
116                 int         n_fds,
117                 int         timeout_milliseconds);
118
119 void _dbus_sleep_milliseconds (int milliseconds);
120
121 void _dbus_get_current_time (long *tv_sec,
122                              long *tv_usec);
123
124 DBusResultCode _dbus_file_get_contents (DBusString       *str,
125                                         const DBusString *filename);
126
127 DBUS_END_DECLS;
128
129 #endif /* DBUS_SYSDEPS_H */