/daten/src/linux-2.4.27-rsbac-v1.2.3/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 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/config.h> 00021 #include <linux/module.h> 00022 #include <linux/types.h> 00023 #include <linux/kernel.h> 00024 #include <linux/string.h> 00025 #include <linux/fs.h> 00026 #include <rsbac/types.h> 00027 #include <rsbac/reg.h> 00028 #include <rsbac/adf.h> 00029 #include <rsbac/aci.h> 00030 #include <rsbac/getname.h> 00031 #include <rsbac/error.h> 00032 #include <rsbac/proc_fs.h> 00033 #include <linux/usb.h> 00034 00035 MODULE_AUTHOR("Michal Purzynski"); 00036 MODULE_DESCRIPTION("RSBAC REG root_plug decision module"); 00037 MODULE_LICENSE("GPL"); 00038 00039 MODULE_PARM(vendor_id, "h"); 00040 MODULE_PARM_DESC(vendor_id, "USB Vendor ID of device to look for"); 00041 00042 MODULE_PARM(product_id, "h"); 00043 MODULE_PARM_DESC(product_id, "USB Product ID of device to look for"); 00044 00045 static long handle = 999999; 00046 00047 /* default is a generic type of usb to serial converter */ 00048 static int vendor_id = 0x0557; 00049 static int product_id = 0x2008; 00050 00051 /**** Decision Functions ****/ 00052 00053 static int request_func (enum rsbac_adf_request_t request, 00054 rsbac_pid_t owner_pid, 00055 enum rsbac_target_t target, 00056 union rsbac_target_id_t tid, 00057 enum rsbac_attribute_t attr, 00058 union rsbac_attribute_value_t attr_val, 00059 rsbac_uid_t owner) 00060 { 00061 struct usb_device *dev; 00062 00063 dev = usb_find_device(vendor_id, product_id); 00064 00065 if (!dev) { 00066 00067 switch (request) { 00068 case R_CHANGE_OWNER: 00069 case R_CHANGE_GROUP: 00070 case R_CLONE: 00071 switch (target) { 00072 case T_PROCESS: 00073 switch (attr) { 00074 case A_owner: 00075 switch (attr_val.owner) { 00076 case 0: 00077 return NOT_GRANTED; 00078 default: 00079 return DO_NOT_CARE; 00080 } 00081 default: 00082 return DO_NOT_CARE; 00083 } 00084 default: 00085 return DO_NOT_CARE; 00086 } 00087 default: 00088 return DO_NOT_CARE; 00089 } 00090 } 00091 00092 return DO_NOT_CARE; 00093 } 00094 00095 /**** Init ****/ 00096 00097 int init_module(void) 00098 { 00099 struct rsbac_reg_entry_t entry; 00100 00101 printk(KERN_INFO "RSBAC REG decision module root_plug: Initializing.\n"); 00102 00103 /* clearing registration entries */ 00104 memset(&entry, 0, sizeof(entry)); 00105 00106 strcpy(entry.name, "RSBAC REG root_plug ADF module"); 00107 printk(KERN_INFO "RSBAC REG decision module root_plug: REG Version: %u, Name: %s, Handle: %li\n", \ 00108 RSBAC_REG_VERSION, entry.name, handle); 00109 00110 entry.handle = handle; 00111 entry.request_func = request_func; 00112 entry.switch_on = TRUE; 00113 00114 printk(KERN_INFO "RSBAC REG decision module root_plug: Registering to ADF.\n"); 00115 00116 if(rsbac_reg_register(RSBAC_REG_VERSION, entry) < 0) { 00117 printk(KERN_WARNING "RSBAC REG decision module sample 1: Registering failed. Unloading.\n"); 00118 return -ENOEXEC; 00119 } 00120 00121 printk(KERN_INFO "RSBAC REG decision module root_plug: Loaded.\n"); 00122 00123 return 0; 00124 } 00125 00126 void cleanup_module(void) 00127 { 00128 printk(KERN_INFO "RSBAC REG decision module root_plug: Unregistering.\n"); 00129 00130 if(rsbac_reg_unregister(handle)) 00131 { 00132 printk(KERN_ERR "RSBAC REG decision module root_plug: Unregistering failed \ 00133 - beware of possible system failure!\n"); 00134 } 00135 00136 printk(KERN_INFO "RSBAC REG decision module root_plug: Unloaded.\n"); 00137 } 00138

Generated on Tue Aug 31 10:05:24 2004 for RSBAC by doxygen 1.3.8