reg_sample3.c File Reference

#include <linux/config.h>
#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_PARM (name,"s")
 MODULE_PARM (syscall_name,"s")
 MODULE_PARM (listkey,"l")
 MODULE_PARM (handle,"l")
 MODULE_PARM (syscall_registration_handle,"l")
 MODULE_PARM (syscall_dispatcher_handle,"l")
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 dummy_buf [70] = "To protect against wrong insmod params"
static char * syscall_name = NULL
static char dummy_buf2 [70] = "To protect against wrong insmod params"
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 66 of file reg_sample3.c.

#define LIST_VERSION   1
 

Definition at line 69 of file reg_sample3.c.

Referenced by init_module().

#define ORD_overwrite   3
 

Definition at line 35 of file reg_sample3.c.

Referenced by init_module(), and need_overwrite_func().

#define ORD_request   1
 

Definition at line 31 of file reg_sample3.c.

Referenced by init_module(), and request_func().

#define ORD_set_attr   2
 

Definition at line 33 of file reg_sample3.c.

Referenced by init_module(), and set_attr_func().

#define ORD_syscall   5
 

Definition at line 39 of file reg_sample3.c.

Referenced by init_module(), and syscall_func().

#define ORD_write   4
 

Definition at line 37 of file reg_sample3.c.

Referenced by init_module(), and write_func().


Function Documentation

void cleanup_module void   ) 
 

Definition at line 424 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.

00425 {
00426   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Unregistering.\n");
00427   #if defined(CONFIG_RSBAC_PROC)
00428   remove_proc_entry(PROC_NAME, proc_rsbac_root_p);
00429   #endif 
00430   if(rsbac_reg_unregister_syscall(syscall_registration_handle))
00431     {
00432       rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering syscall failed - beware of possible system failure!\n");
00433     }
00434   if(rsbac_reg_unregister(handle))
00435     {
00436       rsbac_printk(KERN_ERR "RSBAC REG decision module sample 3: Unregistering module failed - beware of possible system failure!\n");
00437     }
00438   if(rsbac_list_detach(&list_handle, listkey))
00439     rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 3: Unregistering list failed - beware!\n");
00440   rsbac_printk(KERN_INFO "RSBAC REG decision module sample 3: Unloaded.\n");
00441 }

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

Definition at line 193 of file reg_sample3.c.

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

00194   {
00195     return memcmp((u_int *) desc1, (u_int *) desc2, sizeof(u_int) );
00196   }

int init_module void   ) 
 

Definition at line 277 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().

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

MODULE_AUTHOR "Amon Ott"   ) 
 

MODULE_DESCRIPTION "RSBAC REG sample decision module 3"   ) 
 

MODULE_LICENSE "GPL"   ) 
 

MODULE_PARM syscall_dispatcher_handle  ,
"l" 
 

MODULE_PARM syscall_registration_handle  ,
"l" 
 

MODULE_PARM handle  ,
"l" 
 

MODULE_PARM listkey  ,
"l" 
 

MODULE_PARM syscall_name  ,
"s" 
 

MODULE_PARM name  ,
"s" 
 

static rsbac_boolean_t need_overwrite_func struct dentry *  dentry_p  )  [static]
 

Definition at line 247 of file reg_sample3.c.

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

00248   {
00249     __u32 ord = ORD_overwrite;
00250 
00251     nr_need_overwrite_calls++;
00252     rsbac_list_add(list_handle, &ord, &nr_need_overwrite_calls);
00253     return FALSE;
00254   }

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 207 of file reg_sample3.c.

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

00214   {
00215     /* count call, but not for SEARCH request */
00216     if(request != R_SEARCH)
00217       {
00218         __u32 ord = ORD_request;
00219 
00220         nr_request_calls++;
00221         rsbac_list_add(list_handle, &ord, &nr_request_calls);
00222       }
00223     return GRANTED;
00224   }

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 226 of file reg_sample3.c.

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

00235   {
00236     __u32 ord = ORD_set_attr;
00237 
00238     /* count call, but not for SEARCH request */
00239     if(request != R_SEARCH)
00240       {
00241         nr_set_attr_calls++;
00242         rsbac_list_add(list_handle, &ord, &nr_set_attr_calls);
00243       }
00244     return 0;
00245   }

static int syscall_func void *  arg  )  [static]
 

Definition at line 265 of file reg_sample3.c.

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

00266   {
00267     __u32 ord = ORD_syscall;
00268 
00269     nr_system_calls++;
00270     system_call_arg = arg;
00271     rsbac_list_add(list_handle, &ord, &nr_system_calls);
00272     return nr_system_calls;
00273    }

static int write_func rsbac_boolean_t  need_lock  )  [static]
 

Definition at line 256 of file reg_sample3.c.

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

00257   {
00258     __u32 ord = ORD_write;
00259 
00260     nr_write_calls++;
00261     rsbac_list_add(list_handle, &ord, &nr_write_calls);
00262     return(0);
00263   }


Variable Documentation

char dummy_buf[70] = "To protect against wrong insmod params" [static]
 

Definition at line 48 of file reg_sample3.c.

char dummy_buf2[70] = "To protect against wrong insmod params" [static]
 

Definition at line 52 of file reg_sample3.c.

long handle = 133457 [static]
 

Definition at line 58 of file reg_sample3.c.

rsbac_list_handle_t list_handle [static]
 

Definition at line 71 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 55 of file reg_sample3.c.

Referenced by cleanup_module(), and init_module().

char* name = NULL [static]
 

Definition at line 47 of file reg_sample3.c.

u_long nr_need_overwrite_calls = 0 [static]
 

Definition at line 34 of file reg_sample3.c.

u_long nr_request_calls = 0 [static]
 

Definition at line 30 of file reg_sample3.c.

u_long nr_set_attr_calls = 0 [static]
 

Definition at line 32 of file reg_sample3.c.

u_long nr_system_calls = 0 [static]
 

Definition at line 38 of file reg_sample3.c.

u_long nr_write_calls = 0 [static]
 

Definition at line 36 of file reg_sample3.c.

Referenced by init_module(), and write_func().

long syscall_dispatcher_handle = 3 [static]
 

Definition at line 63 of file reg_sample3.c.

char* syscall_name = NULL [static]
 

Definition at line 51 of file reg_sample3.c.

long syscall_registration_handle = 754331 [static]
 

Definition at line 61 of file reg_sample3.c.

void* system_call_arg = 0 [static]
 

Definition at line 40 of file reg_sample3.c.


Generated on Sun May 21 14:31:03 2006 for RSBAC by  doxygen 1.4.2