/linux-2.6.21.1-rsbac-1.3.4/rsbac/adf/reg/root_plug.c

Go to the documentation of this file.
00001 /*
00002  * RSBAC REG decision module kproc_hide.
00003  *
00004  * Originally written for a Linux Journal as LSM sample module.
00005  * Rewriten for RSBAC by Michal Purzynski <albeiro@rsbac.org>
00006  *
00007  * Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
00008  *
00009  * Prevents any programs running with egid == 0 if a specific USB device
00010  * is not present in the system.  Yes, it can be gotten around, but is a
00011  * nice starting point for people to play with, and learn the LSM interface.
00012  *
00013  * See http://www.linuxjournal.com/article.php?sid=6279 for more information about this code.
00014  *
00015  * This program is free software; you can redistribute it and/or 
00016  * modify it under the terms of the GNU General Public License as
00017  * published by the Free Software Foundation, version 2 of the License.
00018  */
00019 
00020 #include <linux/module.h>
00021 #include <linux/types.h>
00022 #include <linux/kernel.h>
00023 #include <linux/string.h>
00024 #include <linux/fs.h>
00025 #include <rsbac/types.h>
00026 #include <rsbac/reg.h>
00027 #include <rsbac/adf.h>
00028 #include <rsbac/aci.h>
00029 #include <rsbac/getname.h>
00030 #include <rsbac/error.h>
00031 #include <rsbac/proc_fs.h>
00032 #include <linux/usb.h>
00033 
00034 MODULE_AUTHOR("Michal Purzynski");
00035 MODULE_DESCRIPTION("RSBAC REG root_plug decision module");
00036 MODULE_LICENSE("GPL");
00037 
00038 #ifdef CONFIG_USB
00039 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00040 /* default is a generic type of usb to serial converter */
00041 static int vendor_id = 0x0557;
00042 static int product_id = 0x2008;
00043 
00044 module_param(vendor_id, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
00045 MODULE_PARM_DESC(vendor_id, "Vendor ID");
00046 module_param(product_id, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
00047 MODULE_PARM_DESC(product_id, "Product ID");
00048 #else
00049 MODULE_PARM(vendor_id, "h");
00050 MODULE_PARM_DESC(vendor_id, "USB Vendor ID of device to look for");
00051 MODULE_PARM(product_id, "h");
00052 MODULE_PARM_DESC(product_id, "USB Product ID of device to look for");
00053 /* default is a generic type of usb to serial converter */
00054 static int vendor_id = 0x0557;
00055 static int product_id = 0x2008;
00056 #endif
00057 #endif
00058 
00059 static long handle = 999999;
00060 
00061 /**** Decision Functions ****/
00062 
00063 static int request_func (enum  rsbac_adf_request_t      request,
00064                         rsbac_pid_t                     owner_pid,
00065                         enum  rsbac_target_t            target,
00066                         union rsbac_target_id_t         tid,
00067                         enum  rsbac_attribute_t         attr,
00068                         union rsbac_attribute_value_t   attr_val,
00069                         rsbac_uid_t                     owner)
00070 {
00071         struct usb_device *dev = NULL;
00072       
00073 #ifdef CONFIG_USB
00074         dev = usb_find_device(vendor_id, product_id);
00075 #endif
00076 
00077         if (!dev) {
00078 
00079                 switch (request) {
00080                         case R_CHANGE_OWNER:
00081                         case R_CHANGE_GROUP:
00082                         case R_CLONE:
00083                                 switch (target) {
00084                                         case T_PROCESS:
00085                                                 switch (attr) {
00086                                                         case A_owner:
00087                                                                 switch (attr_val.owner) {
00088                                                                         case 0:
00089                                                                                 return NOT_GRANTED;
00090                                                                         default:
00091                                                                                 return DO_NOT_CARE;
00092                                                                 }
00093                                                         default:
00094                                                                 return DO_NOT_CARE;
00095                                                 }
00096                                         default:
00097                                                 return DO_NOT_CARE;
00098                                 }
00099                         default:
00100                                 return DO_NOT_CARE;
00101                 }
00102         }
00103         
00104         return DO_NOT_CARE;
00105 }
00106 
00107 /**** Init ****/
00108 
00109 int init_module(void)
00110 {
00111         struct rsbac_reg_entry_t entry;
00112 
00113         rsbac_printk(KERN_INFO "RSBAC REG decision module root_plug: Initializing.\n");
00114 
00115         /* clearing registration entries */
00116         memset(&entry, 0, sizeof(entry));
00117 
00118         strcpy(entry.name, "RSBAC REG root_plug ADF module");
00119         rsbac_printk(KERN_INFO "RSBAC REG decision module root_plug: REG Version: %u, Name: %s, Handle: %li\n",
00120                         RSBAC_REG_VERSION, entry.name, handle);
00121 
00122         entry.handle = handle;
00123         entry.request_func = request_func;
00124         entry.switch_on = TRUE;
00125 
00126         rsbac_printk(KERN_INFO "RSBAC REG decision module root_plug: Registering to ADF.\n");
00127 
00128         if(rsbac_reg_register(RSBAC_REG_VERSION, entry) < 0) {
00129                 rsbac_printk(KERN_WARNING "RSBAC REG decision module sample 1: Registering failed. Unloading.\n");
00130                 return -ENOEXEC;
00131         }
00132 
00133         rsbac_printk(KERN_INFO "RSBAC REG decision module root_plug: Loaded.\n");
00134 
00135         return 0;
00136 }
00137 
00138 void cleanup_module(void)
00139 {
00140         rsbac_printk(KERN_INFO "RSBAC REG decision module root_plug: Unregistering.\n");
00141         
00142         if(rsbac_reg_unregister(handle))
00143         {
00144                 rsbac_printk(KERN_ERR "RSBAC REG decision module root_plug: Unregistering failed - beware of possible system failure!\n");
00145         }
00146         
00147         rsbac_printk(KERN_INFO "RSBAC REG decision module root_plug: Unloaded.\n");
00148 }
00149 

Generated on Wed May 16 11:53:35 2007 for RSBAC by  doxygen 1.5.1