/linux-2.6.21.1-rsbac-1.3.4/rsbac/adf/reg/reg_sample3.c File Reference

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/smp.h>
#include <linux/smp_lock.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <rsbac/types.h>
#include <rsbac/reg.h>
#include <rsbac/adf.h>
#include <rsbac/aci.h>
#include <rsbac/lists.h>
#include <rsbac/getname.h>
#include <rsbac/error.h>
#include <rsbac/proc_fs.h>

Go to the source code of this file.

Defines

#define ORD_request   1
#define ORD_set_attr   2
#define ORD_overwrite   3
#define ORD_write   4
#define ORD_syscall   5
#define FILENAME   "regsmp3"
#define LIST_VERSION   1

Functions

 MODULE_AUTHOR ("Amon Ott")
 MODULE_DESCRIPTION ("RSBAC REG sample decision module 3")
 MODULE_LICENSE ("GPL")
 module_param (name, charp, 0000)
 MODULE_PARM_DESC (name,"Name")
 module_param (syscall_name, charp, 0000)
 MODULE_PARM_DESC (syscall_name,"Syscall name")
 module_param (listkey, int, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
 MODULE_PARM_DESC (listkey,"List key")
 module_param (handle, long, S_IRUSR)
 MODULE_PARM_DESC (handle,"Handle")
 module_param (syscall_registration_handle, long, S_IRUSR)
 MODULE_PARM_DESC (syscall_registration_handle,"Syscall registration handle")
 module_param (syscall_dispatcher_handle, long, S_IRUSR)
 MODULE_PARM_DESC (syscall_dispatcher_handle,"Syscall dispatcher handle")
static int compare (void *desc1, void *desc2)
static int request_func (enum rsbac_adf_request_t request, rsbac_pid_t owner_pid, enum rsbac_target_t target, union rsbac_target_id_t tid, enum rsbac_attribute_t attr, union rsbac_attribute_value_t attr_val, rsbac_uid_t owner)
static int set_attr_func (enum rsbac_adf_request_t request, rsbac_pid_t owner_pid, enum rsbac_target_t target, union rsbac_target_id_t tid, enum rsbac_target_t new_target, union rsbac_target_id_t new_tid, enum rsbac_attribute_t attr, union rsbac_attribute_value_t attr_val, rsbac_uid_t owner)
static rsbac_boolean_t need_overwrite_func (struct dentry *dentry_p)
static int write_func (rsbac_boolean_t need_lock)
static int syscall_func (void *arg)
int init_module (void)
void cleanup_module (void)

Variables

static u_long nr_request_calls = 0
static u_long nr_set_attr_calls = 0
static u_long nr_need_overwrite_calls = 0
static u_long nr_write_calls = 0
static u_long nr_system_calls = 0
static void * system_call_arg = 0
static char * name = NULL
static char * syscall_name = NULL
static u_int listkey = 133457
static long handle = 133457
static long syscall_registration_handle = 754331
static long syscall_dispatcher_handle = 3
static rsbac_list_handle_t list_handle


Define Documentation

#define FILENAME   "regsmp3"

Definition at line 83 of file reg_sample3.c.

#define LIST_VERSION   1

Definition at line 86 of file reg_sample3.c.

Referenced by init_module().

#define ORD_overwrite   3

Definition at line 34 of file reg_sample3.c.

Referenced by init_module(), and need_overwrite_func().

#define ORD_request   1

Definition at line 30 of file reg_sample3.c.

Referenced by init_module(), and request_func().

#define ORD_set_attr   2

Definition at line 32 of file reg_sample3.c.

Referenced by init_module(), and set_attr_func().

#define ORD_syscall   5

Definition at line 38 of file reg_sample3.c.

Referenced by init_module(), and syscall_func().

#define ORD_write   4

Definition at line 36 of file reg_sample3.c.

Referenced by init_module(), and write_func().


Function Documentation

void cleanup_module ( void   ) 

Definition at line 441 of file reg_sample3.c.

References handle, list_handle, listkey, proc_rsbac_root_p, rsbac_list_detach(), rsbac_printk(), rsbac_reg_unregister(), rsbac_reg_unregister_syscall(), and syscall_registration_handle.

00442 {
00443   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Unregistering.\n");
00444   #if defined(CONFIG_RSBAC_PROC)
00445   remove_proc_entry(PROC_NAME, proc_rsbac_root_p);
00446   #endif 
00447   if(rsbac_reg_unregister_syscall(syscall_registration_handle))
00448     {
00449       rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering syscall failed - beware of possible system failure!\n");
00450     }
00451   if(rsbac_reg_unregister(handle))
00452     {
00453       rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering module failed - beware of possible system failure!\n");
00454     }
00455   if(rsbac_list_detach(&list_handle, listkey))
00456     rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Unregistering list failed - beware!\n");
00457   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Unloaded.\n");
00458 }

static int compare ( void *  desc1,
void *  desc2 
) [static]

Definition at line 210 of file reg_sample3.c.

Referenced by init_module(), lookup_lol_subitem_compare(), and lookup_lol_subitem_user_compare().

00211   {
00212     return memcmp((u_int *) desc1, (u_int *) desc2, sizeof(u_int) );
00213   }

int init_module ( void   ) 

Definition at line 294 of file reg_sample3.c.

References compare(), rsbac_list_info_t::data_size, rsbac_list_info_t::desc_size, dummy_buf, dummy_buf2, FILENAME, handle, rsbac_list_info_t::key, list_handle, LIST_VERSION, listkey, rsbac_list_info_t::max_age, name, need_overwrite_func(), nr_need_overwrite_calls, nr_request_calls, nr_set_attr_calls, nr_system_calls, nr_write_calls, NULL, ORD_overwrite, ORD_request, ORD_set_attr, ORD_syscall, ORD_write, proc_rsbac_root_p, request_func(), RSBAC_LIST_BACKUP, rsbac_list_detach(), rsbac_list_exist(), rsbac_list_get_data(), RSBAC_LIST_PERSIST, rsbac_list_register(), RSBAC_LIST_VERSION, rsbac_printk(), RSBAC_REG_NAME_LEN, rsbac_reg_register(), rsbac_reg_register_syscall(), rsbac_reg_unregister(), rsbac_reg_unregister_syscall(), RSBAC_REG_VERSION, set_attr_func(), syscall_dispatcher_handle, syscall_func(), syscall_name, syscall_registration_handle, TRUE, rsbac_list_info_t::version, and write_func().

00295 {
00296   struct rsbac_reg_entry_t entry;
00297   struct rsbac_reg_syscall_entry_t syscall_entry;
00298   struct rsbac_list_info_t list_info;
00299   __u32 ord;
00300 
00301   if(!listkey)
00302     listkey = 133457;
00303   if(!handle)
00304     handle = 133457;
00305   if(!syscall_registration_handle)
00306     syscall_registration_handle = 754331;
00307   if(!syscall_dispatcher_handle)
00308     syscall_dispatcher_handle = 3;
00309 
00310   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Initializing.\n");
00311 
00312   /* clearing registration entries */
00313   memset(&entry, 0, sizeof(entry));
00314   memset(&syscall_entry, 0, sizeof(syscall_entry));
00315 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0)
00316   if((dummy_buf[0] != 'T') || (dummy_buf2[0] != 'T'))
00317     {
00318       rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Not loaded due to invalid param string.\n");
00319       return -ENOEXEC;
00320     }
00321 #endif
00322   /* Register a generic list */
00323   list_info.version = LIST_VERSION;
00324   list_info.key = listkey;
00325   list_info.desc_size = sizeof(__u32);
00326   list_info.data_size = sizeof(nr_request_calls);
00327   list_info.max_age = 3600; /* 1h */
00328   if(rsbac_list_register(RSBAC_LIST_VERSION,
00329                          &list_handle,
00330                          &list_info,
00331                          RSBAC_LIST_PERSIST | RSBAC_LIST_BACKUP,
00332                          compare,
00333                          NULL,
00334                          NULL,
00335                          FILENAME,
00336                          0))
00337     {
00338       rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Registering list failed. Unloading.\n");
00339       return -ENOEXEC;
00340     }
00341   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: List Version: %u, Name: %s, Handle: %p, Key: %u\n",
00342          RSBAC_LIST_VERSION, FILENAME, list_handle, listkey);
00343   ord = ORD_request;
00344   if(rsbac_list_exist(list_handle, &ord))
00345     rsbac_list_get_data(list_handle, &ord, &nr_request_calls);
00346   ord = ORD_set_attr;
00347   if(rsbac_list_exist(list_handle, &ord))
00348     rsbac_list_get_data(list_handle, &ord, &nr_set_attr_calls);
00349   ord = ORD_overwrite;
00350   if(rsbac_list_exist(list_handle, &ord))
00351     rsbac_list_get_data(list_handle, &ord, &nr_need_overwrite_calls);
00352   ord = ORD_write;
00353   if(rsbac_list_exist(list_handle, &ord))
00354     rsbac_list_get_data(list_handle, &ord, &nr_write_calls);
00355   ord = ORD_syscall;
00356   if(rsbac_list_exist(list_handle, &ord))
00357     rsbac_list_get_data(list_handle, &ord, &nr_system_calls);
00358 
00359   /* Register to ADF */
00360   if(name)
00361     {
00362       strncpy(entry.name, name, RSBAC_REG_NAME_LEN);
00363       entry.name[RSBAC_REG_NAME_LEN] = 0;
00364     }
00365   else
00366     strcpy(entry.name, "RSBAC REG sample 3 ADF module");
00367   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: REG Version: %u, Name: %s, Handle: %li\n",
00368          RSBAC_REG_VERSION, entry.name, handle);
00369 
00370   entry.handle = handle;
00371   entry.request_func = request_func;
00372   entry.set_attr_func = set_attr_func;
00373   entry.need_overwrite_func = need_overwrite_func;
00374   entry.write_func = write_func;
00375   entry.switch_on = TRUE;
00376 
00377   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Registering to ADF.\n");
00378   if(rsbac_reg_register(RSBAC_REG_VERSION, entry) < 0)
00379     {
00380       rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Registering failed. Unloading.\n");
00381       if(rsbac_list_detach(&list_handle, listkey))
00382         rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Unregistering list failed - beware!\n");
00383       return -ENOEXEC;
00384     }
00385 
00386   if(syscall_name)
00387     {
00388       strncpy(syscall_entry.name, syscall_name, RSBAC_REG_NAME_LEN);
00389       syscall_entry.name[RSBAC_REG_NAME_LEN] = 0;
00390     }
00391   else
00392     strcpy(syscall_entry.name, "RSBAC REG sample 3 syscall");
00393   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: REG Version: %u, Name: %s, Dispatcher Handle: %li\n",
00394          RSBAC_REG_VERSION, syscall_entry.name, syscall_dispatcher_handle);
00395 
00396   syscall_entry.registration_handle = syscall_registration_handle;
00397   syscall_entry.dispatcher_handle = syscall_dispatcher_handle;
00398   syscall_entry.syscall_func = syscall_func;
00399 
00400   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Registering syscall.\n");
00401   syscall_registration_handle = rsbac_reg_register_syscall(RSBAC_REG_VERSION, syscall_entry);
00402   if(syscall_registration_handle < 0)
00403     {
00404       rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Registering syscall failed. Unloading.\n");
00405       if(rsbac_reg_unregister(handle))
00406         {
00407           rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering failed - beware of possible system failure!\n");
00408         }
00409       if(rsbac_list_detach(&list_handle, listkey))
00410         rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Unregistering list failed - beware!\n");
00411       return -ENOEXEC;
00412     }
00413 
00414   #if defined(CONFIG_RSBAC_PROC)
00415   proc_reg_sample_p = create_proc_entry(PROC_NAME,
00416                                         S_IFREG | S_IRUGO,
00417                                         proc_rsbac_root_p);
00418   if(!proc_reg_sample_p)
00419     {
00420       rsbac_printk(KERN_WARNING "%s: Not loaded due to failed proc entry registering.\n", name);
00421       if(rsbac_reg_unregister_syscall(syscall_registration_handle))
00422         {
00423           rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering syscall failed - beware of possible system failure!\n");
00424         }
00425       if(rsbac_reg_unregister(handle))
00426         {
00427           rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering from ADF failed - beware of possible system failure!\n");
00428         }
00429       if(rsbac_list_detach(&list_handle, listkey))
00430         rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Unregistering list failed - beware!\n");
00431       return -ENOEXEC;
00432     }
00433   proc_reg_sample_p->get_info = adf_sample_proc_info;
00434   #endif 
00435 
00436   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Loaded.\n");
00437 
00438   return 0;
00439 }

MODULE_AUTHOR ( "Amon Ott"   ) 

MODULE_DESCRIPTION ( "RSBAC REG sample decision module 3"   ) 

MODULE_LICENSE ( "GPL"   ) 

module_param ( syscall_dispatcher_handle  ,
long  ,
S_IRUSR   
)

module_param ( syscall_registration_handle  ,
long  ,
S_IRUSR   
)

module_param ( handle  ,
long  ,
S_IRUSR   
)

module_param ( listkey  ,
int  ,
S_IRUSR|S_IWUSR|S_IRGRP|  S_IROTH 
)

module_param ( syscall_name  ,
charp  ,
0000   
)

module_param ( name  ,
charp  ,
0000   
)

MODULE_PARM_DESC ( syscall_dispatcher_handle  ,
"Syscall dispatcher handle  
)

MODULE_PARM_DESC ( syscall_registration_handle  ,
"Syscall registration handle  
)

MODULE_PARM_DESC ( handle  ,
"Handle"   
)

MODULE_PARM_DESC ( listkey  ,
"List key"   
)

MODULE_PARM_DESC ( syscall_name  ,
"Syscall name  
)

MODULE_PARM_DESC ( name  ,
"Name"   
)

static rsbac_boolean_t need_overwrite_func ( struct dentry *  dentry_p  )  [static]

Definition at line 264 of file reg_sample3.c.

References FALSE, list_handle, nr_need_overwrite_calls, ORD_overwrite, and rsbac_list_add().

00265   {
00266     __u32 ord = ORD_overwrite;
00267 
00268     nr_need_overwrite_calls++;
00269     rsbac_list_add(list_handle, &ord, &nr_need_overwrite_calls);
00270     return FALSE;
00271   }

static int request_func ( enum rsbac_adf_request_t  request,
rsbac_pid_t  owner_pid,
enum rsbac_target_t  target,
union rsbac_target_id_t  tid,
enum rsbac_attribute_t  attr,
union rsbac_attribute_value_t  attr_val,
rsbac_uid_t  owner 
) [static]

Definition at line 224 of file reg_sample3.c.

References GRANTED, list_handle, nr_request_calls, ORD_request, R_SEARCH, and rsbac_list_add().

00231   {
00232     /* count call, but not for SEARCH request */
00233     if(request != R_SEARCH)
00234       {
00235         __u32 ord = ORD_request;
00236 
00237         nr_request_calls++;
00238         rsbac_list_add(list_handle, &ord, &nr_request_calls);
00239       }
00240     return GRANTED;
00241   }

static int set_attr_func ( enum rsbac_adf_request_t  request,
rsbac_pid_t  owner_pid,
enum rsbac_target_t  target,
union rsbac_target_id_t  tid,
enum rsbac_target_t  new_target,
union rsbac_target_id_t  new_tid,
enum rsbac_attribute_t  attr,
union rsbac_attribute_value_t  attr_val,
rsbac_uid_t  owner 
) [static]

Definition at line 243 of file reg_sample3.c.

References list_handle, nr_set_attr_calls, ORD_set_attr, R_SEARCH, and rsbac_list_add().

00252   {
00253     __u32 ord = ORD_set_attr;
00254 
00255     /* count call, but not for SEARCH request */
00256     if(request != R_SEARCH)
00257       {
00258         nr_set_attr_calls++;
00259         rsbac_list_add(list_handle, &ord, &nr_set_attr_calls);
00260       }
00261     return 0;
00262   }

static int syscall_func ( void *  arg  )  [static]

Definition at line 282 of file reg_sample3.c.

References list_handle, nr_system_calls, ORD_syscall, rsbac_list_add(), and system_call_arg.

00283   {
00284     __u32 ord = ORD_syscall;
00285 
00286     nr_system_calls++;
00287     system_call_arg = arg;
00288     rsbac_list_add(list_handle, &ord, &nr_system_calls);
00289     return nr_system_calls;
00290    }

static int write_func ( rsbac_boolean_t  need_lock  )  [static]

Definition at line 273 of file reg_sample3.c.

References list_handle, nr_write_calls, ORD_write, and rsbac_list_add().

00274   {
00275     __u32 ord = ORD_write;
00276 
00277     nr_write_calls++;
00278     rsbac_list_add(list_handle, &ord, &nr_write_calls);
00279     return(0);
00280   }


Variable Documentation

long handle = 133457 [static]

Definition at line 49 of file reg_sample3.c.

rsbac_list_handle_t list_handle [static]

Definition at line 88 of file reg_sample3.c.

Referenced by cleanup_module(), init_module(), need_overwrite_func(), request_func(), set_attr_func(), syscall_func(), and write_func().

u_int listkey = 133457 [static]

Definition at line 48 of file reg_sample3.c.

Referenced by cleanup_module(), and init_module().

char* name = NULL [static]

Definition at line 46 of file reg_sample3.c.

u_long nr_need_overwrite_calls = 0 [static]

Definition at line 33 of file reg_sample3.c.

u_long nr_request_calls = 0 [static]

Definition at line 29 of file reg_sample3.c.

u_long nr_set_attr_calls = 0 [static]

Definition at line 31 of file reg_sample3.c.

u_long nr_system_calls = 0 [static]

Definition at line 37 of file reg_sample3.c.

u_long nr_write_calls = 0 [static]

Definition at line 35 of file reg_sample3.c.

Referenced by init_module(), and write_func().

long syscall_dispatcher_handle = 3 [static]

Definition at line 51 of file reg_sample3.c.

char* syscall_name = NULL [static]

Definition at line 47 of file reg_sample3.c.

long syscall_registration_handle = 754331 [static]

Definition at line 50 of file reg_sample3.c.

void* system_call_arg = 0 [static]

Definition at line 39 of file reg_sample3.c.


Generated on Wed May 16 11:54:18 2007 for RSBAC by  doxygen 1.5.1