blob: 7357cf247f60643de226da97ac6232ff21759bb3 [file] [log] [blame]
Darrel Goeddel376bd9c2006-02-24 15:44:05 -06001/*
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>
Steve Grubb1b50eed2006-04-03 14:06:13 -040017#include <linux/fs.h>
Steve Grubb9c7aa6a2006-03-31 15:22:49 -050018#include <linux/ipc.h>
Darrel Goeddel376bd9c2006-02-24 15:44:05 -060019
20#include "security.h"
21#include "objsec.h"
22
23void 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}
Steve Grubb1b50eed2006-04-03 14:06:13 -040031
32int 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
44void 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
Steve Grubb9c7aa6a2006-03-31 15:22:49 -050054void 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