[PATCH] change lspp ipc auditing
[safe/jmp/linux-2.6] / security / selinux / exports.c
1 /*
2  * SELinux services exported to the rest of the kernel.
3  *
4  * Author: James Morris <jmorris@redhat.com>
5  *
6  * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
7  * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2,
11  * as published by the Free Software Foundation.
12  */
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/selinux.h>
17 #include <linux/fs.h>
18 #include <linux/ipc.h>
19
20 #include "security.h"
21 #include "objsec.h"
22
23 void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid)
24 {
25         struct task_security_struct *tsec = tsk->security;
26         if (selinux_enabled)
27                 *ctxid = tsec->sid;
28         else
29                 *ctxid = 0;
30 }
31
32 int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen)
33 {
34         if (selinux_enabled)
35                 return security_sid_to_context(ctxid, ctx, ctxlen);
36         else {
37                 *ctx = NULL;
38                 *ctxlen = 0;
39         }
40
41         return 0;
42 }
43
44 void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
45 {
46         if (selinux_enabled) {
47                 struct inode_security_struct *isec = inode->i_security;
48                 *sid = isec->sid;
49                 return;
50         }
51         *sid = 0;
52 }
53
54 void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
55 {
56         if (selinux_enabled) {
57                 struct ipc_security_struct *isec = ipcp->security;
58                 *sid = isec->sid;
59                 return;
60         }
61         *sid = 0;
62 }
63