blob: 07ddce7bf3745168281e3375d480a77c5b8da000 [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>
Darrel Goeddel376bd9c2006-02-24 15:44:05 -060018
19#include "security.h"
20#include "objsec.h"
21
22void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid)
23{
24 struct task_security_struct *tsec = tsk->security;
25 if (selinux_enabled)
26 *ctxid = tsec->sid;
27 else
28 *ctxid = 0;
29}
Steve Grubb1b50eed2006-04-03 14:06:13 -040030
31int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen)
32{
33 if (selinux_enabled)
34 return security_sid_to_context(ctxid, ctx, ctxlen);
35 else {
36 *ctx = NULL;
37 *ctxlen = 0;
38 }
39
40 return 0;
41}
42
43void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
44{
45 if (selinux_enabled) {
46 struct inode_security_struct *isec = inode->i_security;
47 *sid = isec->sid;
48 return;
49 }
50 *sid = 0;
51}
52