1
#include <linux/security.h>
2
#include <linux/module.h>
3
#include <linux/namei.h>
5
static void log_path(char *op, struct dentry *dentry, struct vfsmount *mnt)
10
printk(KERN_INFO "foobar(%s): %p NULL vfsmnt\n", op, dentry);
14
page = (char *)__get_free_page(GFP_KERNEL);
16
printk(KERN_ERR "foobar(%s): Unable to get page for path %p/%p\n",
21
name=d_path(dentry, mnt, page, PAGE_SIZE);
23
printk(KERN_ERR "foobar(%s): Error path %p/%p overflowed buffer\n",
28
printk(KERN_INFO "foobar(%s): %p/%p->'%s'\n",
29
op, mnt, dentry, name);
33
free_page((unsigned long)page);
36
static int foobar_inode_mkdir(struct inode *inode, struct dentry *dentry,
37
struct vfsmount *mnt, int mask)
39
log_path("inode_mkdir", dentry, mnt);
44
static int foobar_inode_rmdir(struct inode *inode, struct dentry *dentry,
47
log_path("inode_rmdir", dentry, mnt);
52
static int foobar_inode_create(struct inode *inode, struct dentry *dentry,
53
struct vfsmount *mnt, int mask)
55
log_path("inode_create", dentry, mnt);
60
static int foobar_inode_link(struct dentry *old_dentry,
61
struct vfsmount *old_mnt,
63
struct dentry *new_dentry,
64
struct vfsmount *new_mnt)
66
log_path("inode_link (old)", old_dentry, old_mnt);
67
log_path("inode_link (new)", new_dentry, new_mnt);
72
static int foobar_inode_unlink(struct inode *dir, struct dentry *dentry,
75
log_path("inode_unlink", dentry, mnt);
80
static int foobar_inode_mknod(struct inode *inode, struct dentry *dentry,
81
struct vfsmount *mnt, int mode, dev_t dev)
83
log_path("inode_mknod", dentry, mnt);
88
static int foobar_inode_rename(struct inode *old_inode,
89
struct dentry *old_dentry,
90
struct vfsmount *old_mnt,
91
struct inode *new_inode,
92
struct dentry *new_dentry,
93
struct vfsmount *new_mnt)
95
log_path("inode_rename (old)", old_dentry, old_mnt);
96
log_path("inode_rename (new)", new_dentry, new_mnt);
101
static int foobar_inode_setattr(struct dentry *dentry, struct vfsmount *mnt,
104
log_path("inode_setattr", dentry, mnt);
109
static int foobar_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
110
char *name, void *value, size_t size,
113
log_path("inode_setxattr", dentry, mnt);
118
static int foobar_inode_getxattr(struct dentry *dentry,
119
struct vfsmount *mnt, char *name)
121
log_path("inode_getxattr", dentry, mnt);
126
static int foobar_inode_listxattr(struct dentry *dentry,
127
struct vfsmount *mnt)
129
log_path("inode_listxattr", dentry, mnt);
134
static int foobar_inode_removexattr(struct dentry *dentry,
135
struct vfsmount *mnt, char *name)
137
log_path("inode_removexattr", dentry, mnt);
142
static int foobar_inode_symlink(struct inode *dir,
143
struct dentry *dentry, struct vfsmount *mnt,
144
const char *old_name)
146
log_path("inode_symlink", dentry, mnt);
151
static int foobar_inode_permission(struct inode *inode, int mask,
152
struct nameidata *nd)
154
log_path("inode_permission", nd->dentry, nd->mnt);
159
struct security_operations foobar_ops = {
160
.inode_create = foobar_inode_create,
161
.inode_link = foobar_inode_link,
162
.inode_unlink = foobar_inode_unlink,
163
.inode_mkdir = foobar_inode_mkdir,
164
.inode_rmdir = foobar_inode_rmdir,
165
.inode_mknod = foobar_inode_mknod,
166
.inode_rename = foobar_inode_rename,
167
.inode_setattr = foobar_inode_setattr,
168
.inode_setxattr = foobar_inode_setxattr,
169
.inode_getxattr = foobar_inode_getxattr,
170
.inode_listxattr = foobar_inode_listxattr,
171
.inode_removexattr = foobar_inode_removexattr,
172
.inode_symlink = foobar_inode_symlink,
173
// .inode_permission = foobar_inode_permission,
176
static int __init foobar_init(void)
180
if ((error = register_security(&foobar_ops))) {
181
printk(KERN_ERR "Unable to load dummy module\n");
187
static void __exit foobar_exit(void)
189
if (unregister_security(&foobar_ops))
190
printk(KERN_ERR "Unable to properly unregister module\n");
193
module_init(foobar_init);
194
module_exit(foobar_exit);
196
MODULE_DESCRIPTION("Test module");
197
MODULE_LICENSE("GPL");