ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / security / capability.c
1 /*
2  *  Capabilities Linux Security Module
3  *
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.
8  *
9  */
10
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
26 #ifdef CONFIG_SECURITY
27
28
29 static struct security_operations capability_ops = {
30         .ptrace =                       cap_ptrace,
31         .capget =                       cap_capget,
32         .capset_check =                 cap_capset_check,
33         .capset_set =                   cap_capset_set,
34         .capable =                      cap_capable,
35         .netlink_send =                 cap_netlink_send,
36         .netlink_recv =                 cap_netlink_recv,
37
38         .bprm_apply_creds =             cap_bprm_apply_creds,
39         .bprm_set_security =            cap_bprm_set_security,
40         .bprm_secureexec =              cap_bprm_secureexec,
41
42         .inode_setxattr =               cap_inode_setxattr,
43         .inode_removexattr =            cap_inode_removexattr,
44
45         .task_post_setuid =             cap_task_post_setuid,
46         .task_reparent_to_init =        cap_task_reparent_to_init,
47
48         .syslog =                       cap_syslog,
49
50         .vm_enough_memory =             cap_vm_enough_memory,
51 };
52
53 #if defined(CONFIG_SECURITY_CAPABILITIES_MODULE)
54 #define MY_NAME THIS_MODULE->name
55 #else
56 #define MY_NAME "capability"
57 #endif
58
59 /* flag to keep track of how we were registered */
60 static int secondary;
61
62
63 static int __init capability_init (void)
64 {
65         /* register ourselves with the security framework */
66         if (register_security (&capability_ops)) {
67                 printk (KERN_INFO
68                         "Failure registering capabilities with the kernel\n");
69                 /* try registering with primary module */
70                 if (mod_reg_security (MY_NAME, &capability_ops)) {
71                         printk (KERN_INFO "Failure registering capabilities "
72                                 "with primary security module.\n");
73                         return -EINVAL;
74                 }
75                 secondary = 1;
76         }
77         printk (KERN_INFO "Capability LSM initialized\n");
78         return 0;
79 }
80
81 static void __exit capability_exit (void)
82 {
83         /* remove ourselves from the security framework */
84         if (secondary) {
85                 if (mod_unreg_security (MY_NAME, &capability_ops))
86                         printk (KERN_INFO "Failure unregistering capabilities "
87                                 "with primary module.\n");
88                 return;
89         }
90
91         if (unregister_security (&capability_ops)) {
92                 printk (KERN_INFO
93                         "Failure unregistering capabilities with the kernel\n");
94         }
95 }
96
97 security_initcall (capability_init);
98 module_exit (capability_exit);
99
100 MODULE_DESCRIPTION("Standard Linux Capabilities Security Module");
101 MODULE_LICENSE("GPL");
102
103 #endif  /* CONFIG_SECURITY */