dazuko_core.h

Go to the documentation of this file.
00001 /* DazukoXP. Allow cross platform file access control for 3rd-party applications.
00002    Written by John Ogness <jogness@antivir.de>
00003 
00004    Copyright (c) 2002, 2003, 2004, 2005, 2006 H+BEDV Datentechnik GmbH
00005    All rights reserved.
00006 
00007    Redistribution and use in source and binary forms, with or without
00008    modification, are permitted provided that the following conditions
00009    are met:
00010 
00011    1. Redistributions of source code must retain the above copyright notice,
00012    this list of conditions and the following disclaimer.
00013 
00014    2. Redistributions in binary form must reproduce the above copyright notice,
00015    this list of conditions and the following disclaimer in the documentation
00016    and/or other materials provided with the distribution.
00017 
00018    3. Neither the name of Dazuko nor the names of its contributors may be used
00019    to endorse or promote products derived from this software without specific
00020    prior written permission.
00021 
00022    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00026    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00028    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00029    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00030    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00031    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032    POSSIBILITY OF SUCH DAMAGE.
00033 */
00034 
00035 #ifndef DAZUKO_XP_H
00036 #define DAZUKO_XP_H
00037 
00038 #include "dazuko_transport.h"
00039 #include "dazuko_events.h"
00040 
00041 /* xp_id compare results */
00042 #define DAZUKO_DIFFERENT        0
00043 #define DAZUKO_SUSPICIOUS       1
00044 #define DAZUKO_CHILD            2
00045 #define DAZUKO_SAME             3
00046 
00047 /* file types */
00048 #define DAZUKO_NONE             0
00049 #define DAZUKO_REGULAR          1
00050 #define DAZUKO_DIRECTORY        2
00051 #define DAZUKO_LINK             3
00052 
00053 
00054 /*********************************************************
00055  * structures that MUST be implemented by platform-layer *
00056  *********************************************************/
00057 
00058 /*
00059 struct xp_mutex;
00060 struct xp_atomic;
00061 struct xp_file_struct;
00062 struct xp_queue;
00063 struct xp_rwlock;
00064 struct xp_daemon_id;
00065 */
00066 
00067 
00068 /******************************************
00069  * structures available to platform-layer *
00070  ******************************************/
00071 
00072 struct event_properties
00073 {
00074         int     flags;
00075         char    set_flags;
00076         int     mode;
00077         char    set_mode;
00078         int     uid;
00079         char    set_uid;
00080         int     pid;
00081         char    set_pid;
00082 };
00083 
00084 struct file_properties
00085 {
00086         unsigned long   size;
00087         char            set_size;
00088         int             uid;
00089         char            set_uid;
00090         int             gid;
00091         char            set_gid;
00092         int             mode;
00093         char            set_mode;
00094         int             device_type;
00095         char            set_device_type;
00096         int             type;
00097         char            set_type;
00098 };
00099 
00100 struct dazuko_file_listnode
00101 {
00102         char                            *filename;
00103         int                             filename_length;
00104         struct dazuko_file_listnode     *next;
00105 };
00106 
00107 struct dazuko_file_struct
00108 {
00109         /* A structure designed for simple and
00110          * intelligent memory management when
00111          * doing filename lookups in the kernel. */
00112 
00113         char                            *filename;              /* filename to report (pointer in alias list) */
00114         int                             filename_length;        /* length of filename reported */
00115         struct dazuko_file_listnode     *aliases;               /* list of file names (alias names) */
00116         struct file_properties          file_p;                 /* properties of file */
00117         struct xp_file_struct           *extra_data;            /* extra platform-dependant data */
00118 };
00119 
00120 
00121 /********************************************************
00122  * functions that MUST be implemented by platform-layer *
00123  ********************************************************/
00124 
00125 /* mutex */
00126 void xp_init_mutex(struct xp_mutex *mutex);
00127 void xp_down(struct xp_mutex *mutex);
00128 void xp_up(struct xp_mutex *mutex);
00129 void xp_destroy_mutex(struct xp_mutex *mutex);
00130 
00131 /* read-write lock */
00132 void xp_init_rwlock(struct xp_rwlock *rwlock);
00133 void xp_write_lock(struct xp_rwlock *rwlock);
00134 void xp_write_unlock(struct xp_rwlock *rwlock);
00135 void xp_read_lock(struct xp_rwlock *rlock);
00136 void xp_read_unlock(struct xp_rwlock *rlock);
00137 void xp_destroy_rwlock(struct xp_rwlock *rwlock);
00138 
00139 /* wait-notify queue */
00140 int xp_init_queue(struct xp_queue *queue);
00141 int xp_wait_until_condition(struct xp_queue *queue, int (*cfunction)(void *), void *cparam, int allow_interrupt);
00142 int xp_notify(struct xp_queue *queue);
00143 int xp_destroy_queue(struct xp_queue *queue);
00144 
00145 /* memory */
00146 void* xp_malloc(size_t size);
00147 int xp_free(void *ptr);
00148 int xp_copyin(const void *user_src, void *kernel_dest, size_t size);
00149 int xp_copyout(const void *kernel_src, void *user_dest, size_t size);
00150 int xp_verify_user_writable(const void *user_ptr, size_t size);
00151 int xp_verify_user_readable(const void *user_ptr, size_t size);
00152 
00153 /* path attribute */
00154 int xp_is_absolute_path(const char *path);
00155 
00156 /* atomic */
00157 int xp_atomic_set(struct xp_atomic *atomic, int value);
00158 int xp_atomic_inc(struct xp_atomic *atomic);
00159 int xp_atomic_dec(struct xp_atomic *atomic);
00160 int xp_atomic_read(struct xp_atomic *atomic);
00161 
00162 /* system hook */
00163 int xp_sys_hook(void);
00164 int xp_sys_unhook(void);
00165 
00166 /* file structure */
00167 int xp_fill_file_struct(struct dazuko_file_struct *dfs);
00168 
00169 /* daemon id */
00170 int xp_id_compare(struct xp_daemon_id *id1, struct xp_daemon_id *id2, int check_related);
00171 int xp_id_free(struct xp_daemon_id *id);
00172 struct xp_daemon_id* xp_id_copy(struct xp_daemon_id *id);
00173 
00174 /* event */
00175 int xp_set_event_properties(struct event_properties *event_p, struct xp_daemon_id *xp_id);
00176 
00177 /* cache settings */
00178 int xp_init_cache(unsigned long ttl);
00179 
00180 /* output */
00181 int xp_print(const char *fmt, ...);
00182 
00183 /* debug */
00184 #ifdef DEBUG
00185 #define DPRINT(fmt) xp_print fmt
00186 #else
00187 #define DPRINT(fmt)
00188 #endif
00189 
00190 
00191 /*****************************************
00192  * functions available to platform-layer *
00193  *****************************************/
00194 
00195 struct slot_list;
00196 
00197 int dazuko_vsnprintf(char *str, size_t size, const char *format, va_list ap);
00198 int dazuko_snprintf(char *str, size_t size, const char *format, ...);
00199 int dazuko_is_our_daemon(struct xp_daemon_id *xp_id, struct slot_list **slotlist);
00200 int dazuko_get_value(const char *key, const char *string, char **value);
00201 int dazuko_unregister_daemon(struct xp_daemon_id *xp_id);
00202 int dazuko_handle_user_request(const char *request_buffer, struct xp_daemon_id *xp_id);
00203 int dazuko_handle_user_request_compat1(void *ptr, int cmd, struct xp_daemon_id *xp_id);
00204 int dazuko_get_filename_length(const char *filename);
00205 void dazuko_bzero(void *p, int len);
00206 int dazuko_check_access(unsigned long event, int daemon_is_allowed, struct xp_daemon_id *xp_id, struct slot_list **cached_lookup);
00207 int dazuko_process_access(unsigned long event, struct dazuko_file_struct *kfs, struct event_properties *event_p, struct slot_list *cached_lookup);
00208 int dazuko_init(void);
00209 int dazuko_exit(void);
00210 
00211 #endif

Generated on Sun May 21 14:30:49 2006 for RSBAC by  doxygen 1.4.2