TOMOYO: Split files into some pieces.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / security / tomoyo / securityfs_if.c
blob5eb53510c4a772a6063c08196773983d7f083a33
1 /*
2 * security/tomoyo/common.c
4 * Securityfs interface for TOMOYO.
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
7 */
9 #include <linux/security.h>
10 #include "common.h"
12 /**
13 * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.
15 * @inode: Pointer to "struct inode".
16 * @file: Pointer to "struct file".
18 * Returns 0 on success, negative value otherwise.
20 static int tomoyo_open(struct inode *inode, struct file *file)
22 const int key = ((u8 *) file->f_path.dentry->d_inode->i_private)
23 - ((u8 *) NULL);
24 return tomoyo_open_control(key, file);
27 /**
28 * tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface.
30 * @inode: Pointer to "struct inode".
31 * @file: Pointer to "struct file".
33 * Returns 0 on success, negative value otherwise.
35 static int tomoyo_release(struct inode *inode, struct file *file)
37 return tomoyo_close_control(file);
40 /**
41 * tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface.
43 * @file: Pointer to "struct file".
44 * @buf: Pointer to buffer.
45 * @count: Size of @buf.
46 * @ppos: Unused.
48 * Returns bytes read on success, negative value otherwise.
50 static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
51 loff_t *ppos)
53 return tomoyo_read_control(file, buf, count);
56 /**
57 * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.
59 * @file: Pointer to "struct file".
60 * @buf: Pointer to buffer.
61 * @count: Size of @buf.
62 * @ppos: Unused.
64 * Returns @count on success, negative value otherwise.
66 static ssize_t tomoyo_write(struct file *file, const char __user *buf,
67 size_t count, loff_t *ppos)
69 return tomoyo_write_control(file, buf, count);
73 * tomoyo_operations is a "struct file_operations" which is used for handling
74 * /sys/kernel/security/tomoyo/ interface.
76 * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
77 * See tomoyo_io_buffer for internals.
79 static const struct file_operations tomoyo_operations = {
80 .open = tomoyo_open,
81 .release = tomoyo_release,
82 .read = tomoyo_read,
83 .write = tomoyo_write,
86 /**
87 * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.
89 * @name: The name of the interface file.
90 * @mode: The permission of the interface file.
91 * @parent: The parent directory.
92 * @key: Type of interface.
94 * Returns nothing.
96 static void __init tomoyo_create_entry(const char *name, const mode_t mode,
97 struct dentry *parent, const u8 key)
99 securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
100 &tomoyo_operations);
104 * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
106 * Returns 0.
108 static int __init tomoyo_initerface_init(void)
110 struct dentry *tomoyo_dir;
112 /* Don't create securityfs entries unless registered. */
113 if (current_cred()->security != &tomoyo_kernel_domain)
114 return 0;
116 tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
117 tomoyo_create_entry("query", 0600, tomoyo_dir,
118 TOMOYO_QUERY);
119 tomoyo_create_entry("domain_policy", 0600, tomoyo_dir,
120 TOMOYO_DOMAINPOLICY);
121 tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
122 TOMOYO_EXCEPTIONPOLICY);
123 tomoyo_create_entry("self_domain", 0400, tomoyo_dir,
124 TOMOYO_SELFDOMAIN);
125 tomoyo_create_entry(".domain_status", 0600, tomoyo_dir,
126 TOMOYO_DOMAIN_STATUS);
127 tomoyo_create_entry(".process_status", 0600, tomoyo_dir,
128 TOMOYO_PROCESS_STATUS);
129 tomoyo_create_entry("meminfo", 0600, tomoyo_dir,
130 TOMOYO_MEMINFO);
131 tomoyo_create_entry("profile", 0600, tomoyo_dir,
132 TOMOYO_PROFILE);
133 tomoyo_create_entry("manager", 0600, tomoyo_dir,
134 TOMOYO_MANAGER);
135 tomoyo_create_entry("version", 0400, tomoyo_dir,
136 TOMOYO_VERSION);
137 return 0;
140 fs_initcall(tomoyo_initerface_init);