Created
February 12, 2010 10:22
-
-
Save hiboma/302458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/init.h> | |
#include <linux/security.h> | |
/* should we print out debug messages */ | |
static int debug = 0; | |
module_param(debug, bool, 0600); | |
MODULE_PARM_DESC(debug, "Debug enabled or not"); | |
static struct dentry *dir_ino, *config_ino; | |
static ssize_t read_server_config(struct file *filp, char __user *buf, | |
size_t count, loff_t *ppos) | |
{ | |
char tmp[256]; | |
ssize_t len; | |
len = scnprintf(tmp, sizeof(tmp), "%s:%d\n", "192.168.0.1", 80); | |
return simple_read_from_buffer(buf, count, ppos, tmp, len); | |
} | |
static int ioctl_server_config(struct inode *inode, struct file *filp, | |
unsigned int cmd, unsigned long arg) | |
{ | |
printk(KERN_INFO "cmd is %d, arg is %s", cmd, (const char *)arg); | |
return 0; | |
} | |
static long ioctl2_server_config(struct file *filp, unsigned int cmd, | |
unsigned long arg) | |
{ | |
printk(KERN_INFO "cmd is %d, arg is %s", cmd, (const char *)arg); | |
return 0; | |
} | |
static struct file_operations rootconn_file_ops = { | |
.read = read_server_config, | |
.ioctl = ioctl_server_config, | |
.unlocked_ioctl = ioctl2_server_config, | |
.compat_ioctl = ioctl2_server_config, | |
}; | |
static int __init rootplug_init (void) | |
{ | |
int rc = 0; | |
dir_ino = securityfs_create_dir("rootconn", NULL); | |
config_ino = securityfs_create_file("server", S_IRUGO, dir_ino, NULL, | |
&rootconn_file_ops); | |
if (IS_ERR(config_ino)) { | |
rc = PTR_ERR(config_ino); | |
securityfs_remove(dir_ino); | |
return PTR_ERR(config_ino); | |
} | |
printk (KERN_INFO "oreore module registerd\n"); | |
return 0; | |
} | |
static void __exit rootplug_exit (void) | |
{ | |
securityfs_remove(config_ino); | |
securityfs_remove(dir_ino); | |
printk (KERN_INFO "oreore module removed\n"); | |
} | |
security_initcall (rootplug_init); | |
module_exit (rootplug_exit); | |
MODULE_DESCRIPTION("Root Plug sample LSM module, written for Linux Journal article"); | |
MODULE_LICENSE("GPL"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment