Main Page   Modules   Data Structures   File List   Data Fields   Related Pages  

dbus-sysdeps.h

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
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 1.2
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  */
00024 
00025 #ifndef DBUS_SYSDEPS_H
00026 #define DBUS_SYSDEPS_H
00027 
00028 #include <dbus/dbus-string.h>
00029 #include <dbus/dbus-errors.h>
00030 
00031 /* this is perhaps bogus, but strcmp() etc. are faster if we use the
00032  * stuff straight out of string.h, so have this here for now.
00033  */
00034 #include <string.h>
00035 
00036 /* and it would just be annoying to abstract this */
00037 #include <errno.h>
00038 
00039 DBUS_BEGIN_DECLS;
00040 
00041 /* The idea of this file is to encapsulate everywhere that we're
00042  * relying on external libc features, for ease of security
00043  * auditing. The idea is from vsftpd. This also gives us a chance to
00044  * make things more convenient to use, e.g.  by reading into a
00045  * DBusString. Operating system headers aren't intended to be used
00046  * outside of this file and a limited number of others (such as
00047  * dbus-memory.c)
00048  */
00049 
00050 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00051 #define _DBUS_GNUC_PRINTF( format_idx, arg_idx )    \
00052   __attribute__((__format__ (__printf__, format_idx, arg_idx)))
00053 #define _DBUS_GNUC_SCANF( format_idx, arg_idx )     \
00054   __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
00055 #define _DBUS_GNUC_FORMAT( arg_idx )                \
00056   __attribute__((__format_arg__ (arg_idx)))
00057 #define _DBUS_GNUC_NORETURN                         \
00058   __attribute__((__noreturn__))
00059 #else   /* !__GNUC__ */
00060 #define _DBUS_GNUC_PRINTF( format_idx, arg_idx )
00061 #define _DBUS_GNUC_SCANF( format_idx, arg_idx )
00062 #define _DBUS_GNUC_FORMAT( arg_idx )
00063 #define _DBUS_GNUC_NORETURN
00064 #endif  /* !__GNUC__ */
00065 
00066 void _dbus_abort (void) _DBUS_GNUC_NORETURN;
00067 
00068 const char* _dbus_getenv (const char *varname);
00069 dbus_bool_t _dbus_setenv (const char *varname,
00070                           const char *value);
00071 
00072 int _dbus_read      (int               fd,
00073                      DBusString       *buffer,
00074                      int               count);
00075 int _dbus_write     (int               fd,
00076                      const DBusString *buffer,
00077                      int               start,
00078                      int               len);
00079 int _dbus_write_two (int               fd,
00080                      const DBusString *buffer1,
00081                      int               start1,
00082                      int               len1,
00083                      const DBusString *buffer2,
00084                      int               start2,
00085                      int               len2);
00086 
00087 typedef unsigned long dbus_pid_t;
00088 typedef unsigned long dbus_uid_t;
00089 typedef unsigned long dbus_gid_t;
00090 
00091 #define DBUS_PID_UNSET ((dbus_pid_t) -1)
00092 #define DBUS_UID_UNSET ((dbus_uid_t) -1)
00093 #define DBUS_GID_UNSET ((dbus_gid_t) -1)
00094 
00095 #define DBUS_PID_FORMAT "%lu"
00096 #define DBUS_UID_FORMAT "%lu"
00097 #define DBUS_GID_FORMAT "%lu"
00098 
00099 typedef struct
00100 {
00101   /* Set to DBUS_PID_UNSET etc. if not available */
00102   dbus_pid_t pid;
00103   dbus_uid_t uid;
00104   dbus_gid_t gid;
00105 } DBusCredentials;
00106 
00107 int _dbus_connect_unix_socket (const char     *path,
00108                                dbus_bool_t     abstract,
00109                                DBusError      *error);
00110 int _dbus_listen_unix_socket  (const char     *path,
00111                                dbus_bool_t     abstract,
00112                                DBusError      *error);
00113 int _dbus_connect_tcp_socket  (const char     *host,
00114                                dbus_uint32_t   port,
00115                                DBusError      *error);
00116 int _dbus_listen_tcp_socket   (const char     *host,
00117                                dbus_uint32_t   port,
00118                                DBusError      *error);
00119 int _dbus_accept              (int             listen_fd);
00120 
00121 dbus_bool_t _dbus_read_credentials_unix_socket (int              client_fd,
00122                                                 DBusCredentials *credentials,
00123                                                 DBusError       *error);
00124 dbus_bool_t _dbus_send_credentials_unix_socket (int              server_fd,
00125                                                 DBusError       *error);
00126 
00127 
00128 void        _dbus_credentials_clear                (DBusCredentials       *credentials);
00129 void        _dbus_credentials_from_current_process (DBusCredentials       *credentials);
00130 dbus_bool_t _dbus_credentials_match                (const DBusCredentials *expected_credentials,
00131                                                     const DBusCredentials *provided_credentials);
00132 
00133 
00134 typedef struct DBusUserInfo  DBusUserInfo;
00135 typedef struct DBusGroupInfo DBusGroupInfo;
00136 
00137 struct DBusUserInfo
00138 {
00139   dbus_uid_t  uid;            
00140   dbus_gid_t  primary_gid;    
00141   dbus_gid_t *group_ids;      
00142   int         n_group_ids;    
00143   char       *username;       
00144   char       *homedir;        
00145 };
00146 
00147 struct DBusGroupInfo
00148 {
00149   dbus_gid_t  gid;            
00150   char       *groupname;      
00151 };
00152 
00153 dbus_bool_t _dbus_user_info_fill     (DBusUserInfo     *info,
00154                                       const DBusString *username,
00155                                       DBusError        *error);
00156 dbus_bool_t _dbus_user_info_fill_uid (DBusUserInfo     *info,
00157                                       dbus_uid_t        uid,
00158                                       DBusError        *error);
00159 void        _dbus_user_info_free     (DBusUserInfo     *info);
00160 
00161 dbus_bool_t _dbus_group_info_fill     (DBusGroupInfo    *info,
00162                                        const DBusString *groupname,
00163                                        DBusError        *error);
00164 dbus_bool_t _dbus_group_info_fill_gid (DBusGroupInfo    *info,
00165                                        dbus_gid_t        gid,
00166                                        DBusError        *error);
00167 void        _dbus_group_info_free     (DBusGroupInfo    *info);
00168 
00169 
00170 unsigned long _dbus_getpid (void);
00171 dbus_uid_t    _dbus_getuid (void);
00172 dbus_gid_t    _dbus_getgid (void);
00173 
00174 typedef struct DBusAtomic DBusAtomic;
00175 struct DBusAtomic
00176 {
00177   volatile dbus_int32_t value;
00178 };
00179 
00180 dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic);
00181 dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
00182 
00183 #define _DBUS_POLLIN      0x0001    /* There is data to read */
00184 #define _DBUS_POLLPRI     0x0002    /* There is urgent data to read */
00185 #define _DBUS_POLLOUT     0x0004    /* Writing now will not block */
00186 #define _DBUS_POLLERR     0x0008    /* Error condition */
00187 #define _DBUS_POLLHUP     0x0010    /* Hung up */
00188 #define _DBUS_POLLNVAL    0x0020    /* Invalid request: fd not open */
00189 
00190 typedef struct
00191 {
00192   int fd;
00193   short events;
00194   short revents;
00195 } DBusPollFD;
00196 
00197 int _dbus_poll (DBusPollFD *fds,
00198                 int         n_fds,
00199                 int         timeout_milliseconds);
00200 
00201 void _dbus_sleep_milliseconds (int milliseconds);
00202 
00203 void _dbus_get_current_time (long *tv_sec,
00204                              long *tv_usec);
00205 
00206 
00207 dbus_bool_t _dbus_file_get_contents   (DBusString       *str,
00208                                        const DBusString *filename,
00209                                        DBusError        *error);
00210 dbus_bool_t _dbus_string_save_to_file (const DBusString *str,
00211                                        const DBusString *filename,
00212                                        DBusError        *error);
00213 
00214 dbus_bool_t    _dbus_create_file_exclusively (const DBusString *filename,
00215                                               DBusError        *error);
00216 dbus_bool_t    _dbus_delete_file             (const DBusString *filename,
00217                                               DBusError        *error);
00218 dbus_bool_t    _dbus_create_directory        (const DBusString *filename,
00219                                               DBusError        *error);
00220 
00221 dbus_bool_t _dbus_concat_dir_and_file (DBusString       *dir,
00222                                        const DBusString *next_component);
00223 dbus_bool_t _dbus_string_get_dirname  (const DBusString *filename,
00224                                        DBusString       *dirname);
00225 dbus_bool_t _dbus_path_is_absolute    (const DBusString *filename);
00226 
00227 typedef struct DBusDirIter DBusDirIter;
00228 
00229 DBusDirIter* _dbus_directory_open          (const DBusString *filename,
00230                                             DBusError        *error);
00231 dbus_bool_t  _dbus_directory_get_next_file (DBusDirIter      *iter,
00232                                             DBusString       *filename,
00233                                             DBusError        *error);
00234 void         _dbus_directory_close         (DBusDirIter      *iter);
00235 
00236 
00237 dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
00238                                          int         n_bytes);
00239 dbus_bool_t _dbus_generate_random_ascii (DBusString *str,
00240                                          int         n_bytes);
00241 
00242 const char *_dbus_errno_to_string  (int errnum);
00243 const char* _dbus_error_from_errno (int error_number);
00244 
00245 void _dbus_disable_sigpipe (void);
00246 
00247 void _dbus_fd_set_close_on_exec (int fd);
00248 
00249 void _dbus_exit (int code) _DBUS_GNUC_NORETURN;
00250 
00251 typedef struct
00252 {
00253   unsigned long mode;
00254   unsigned long nlink;
00255   dbus_uid_t    uid;
00256   dbus_gid_t    gid;
00257   unsigned long size;
00258   unsigned long atime;
00259   unsigned long mtime;
00260   unsigned long ctime;
00261 } DBusStat;
00262 
00263 dbus_bool_t _dbus_stat             (const DBusString *filename,
00264                                     DBusStat         *statbuf,
00265                                     DBusError        *error);
00266 dbus_bool_t _dbus_full_duplex_pipe (int              *fd1,
00267                                     int              *fd2,
00268                                     dbus_bool_t       blocking,
00269                                     DBusError        *error);
00270 dbus_bool_t _dbus_close            (int               fd,
00271                                     DBusError        *error);
00272 
00273 void        _dbus_print_backtrace  (void);
00274 
00275 dbus_bool_t _dbus_become_daemon   (const DBusString *pidfile,
00276                                    DBusError        *error);
00277 dbus_bool_t _dbus_write_pid_file  (const DBusString *filename,
00278                                    unsigned long     pid,
00279                                    DBusError        *error);
00280 dbus_bool_t _dbus_change_identity (unsigned long     uid,
00281                                    unsigned long     gid,
00282                                    DBusError        *error);
00283 
00284 typedef void (* DBusSignalHandler) (int sig);
00285 
00286 void _dbus_set_signal_handler (int               sig,
00287                                DBusSignalHandler handler);
00288 
00289 
00290 DBUS_END_DECLS;
00291 
00292 #endif /* DBUS_SYSDEPS_H */

Generated on Wed Oct 22 14:05:05 2003 for D-BUS by doxygen1.3-rc3