[PATCH] RTC subsystem: SA1100 cleanup
[pv_ops_mirror.git] / security / capability.c
blobf9b35cc0b248f4ed49146651930fc49cad3b65d5
1 /*
2 * Capabilities Linux Security Module
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 */
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/security.h>
16 #include <linux/file.h>
17 #include <linux/mm.h>
18 #include <linux/mman.h>
19 #include <linux/pagemap.h>
20 #include <linux/swap.h>
21 #include <linux/smp_lock.h>
22 #include <linux/skbuff.h>
23 #include <linux/netlink.h>
24 #include <linux/ptrace.h>
25 #include <linux/moduleparam.h>
27 static struct security_operations capability_ops = {
28 .ptrace = cap_ptrace,
29 .capget = cap_capget,
30 .capset_check = cap_capset_check,
31 .capset_set = cap_capset_set,
32 .capable = cap_capable,
33 .settime = cap_settime,
34 .netlink_send = cap_netlink_send,
35 .netlink_recv = cap_netlink_recv,
37 .bprm_apply_creds = cap_bprm_apply_creds,
38 .bprm_set_security = cap_bprm_set_security,
39 .bprm_secureexec = cap_bprm_secureexec,
41 .inode_setxattr = cap_inode_setxattr,
42 .inode_removexattr = cap_inode_removexattr,
44 .task_post_setuid = cap_task_post_setuid,
45 .task_reparent_to_init = cap_task_reparent_to_init,
47 .syslog = cap_syslog,
49 .vm_enough_memory = cap_vm_enough_memory,
52 /* flag to keep track of how we were registered */
53 static int secondary;
55 static int capability_disable;
56 module_param_named(disable, capability_disable, int, 0);
57 MODULE_PARM_DESC(disable, "To disable capabilities module set disable = 1");
59 static int __init capability_init (void)
61 if (capability_disable) {
62 printk(KERN_INFO "Capabilities disabled at initialization\n");
63 return 0;
65 /* register ourselves with the security framework */
66 if (register_security (&capability_ops)) {
67 /* try registering with primary module */
68 if (mod_reg_security (KBUILD_MODNAME, &capability_ops)) {
69 printk (KERN_INFO "Failure registering capabilities "
70 "with primary security module.\n");
71 return -EINVAL;
73 secondary = 1;
75 printk (KERN_INFO "Capability LSM initialized%s\n",
76 secondary ? " as secondary" : "");
77 return 0;
80 static void __exit capability_exit (void)
82 if (capability_disable)
83 return;
84 /* remove ourselves from the security framework */
85 if (secondary) {
86 if (mod_unreg_security (KBUILD_MODNAME, &capability_ops))
87 printk (KERN_INFO "Failure unregistering capabilities "
88 "with primary module.\n");
89 return;
92 if (unregister_security (&capability_ops)) {
93 printk (KERN_INFO
94 "Failure unregistering capabilities with the kernel\n");
98 security_initcall (capability_init);
99 module_exit (capability_exit);
101 MODULE_DESCRIPTION("Standard Linux Capabilities Security Module");
102 MODULE_LICENSE("GPL");