exports.c 2.0 KB
Newer Older
1 2 3 4 5 6 7
/*
 * SELinux services exported to the rest of the kernel.
 *
 * Author: James Morris <jmorris@redhat.com>
 *
 * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
 * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
8
 * Copyright (C) 2006 IBM Corporation, Timothy R. Chavez <tinytim@us.ibm.com>
9 10 11 12 13 14 15 16 17
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 */
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/selinux.h>
S
Steve Grubb 已提交
18
#include <linux/fs.h>
S
Steve Grubb 已提交
19
#include <linux/ipc.h>
20 21 22 23

#include "security.h"
#include "objsec.h"

S
Steve Grubb 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen)
{
	if (selinux_enabled)
		return security_sid_to_context(ctxid, ctx, ctxlen);
	else {
		*ctx = NULL;
		*ctxlen = 0;
	}

	return 0;
}

void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
{
	if (selinux_enabled) {
		struct inode_security_struct *isec = inode->i_security;
		*sid = isec->sid;
		return;
	}
	*sid = 0;
}

S
Steve Grubb 已提交
46 47 48 49 50 51 52 53 54 55
void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
{
	if (selinux_enabled) {
		struct ipc_security_struct *isec = ipcp->security;
		*sid = isec->sid;
		return;
	}
	*sid = 0;
}

56 57 58 59 60 61 62 63 64 65
void selinux_get_task_sid(struct task_struct *tsk, u32 *sid)
{
	if (selinux_enabled) {
		struct task_security_struct *tsec = tsk->security;
		*sid = tsec->sid;
		return;
	}
	*sid = 0;
}

J
James Morris 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
int selinux_string_to_sid(char *str, u32 *sid)
{
	if (selinux_enabled)
		return security_context_to_sid(str, strlen(str), sid);
	else {
		*sid = 0;
		return 0;
	}
}
EXPORT_SYMBOL_GPL(selinux_string_to_sid);

int selinux_relabel_packet_permission(u32 sid)
{
	if (selinux_enabled) {
		struct task_security_struct *tsec = current->security;

		return avc_has_perm(tsec->sid, sid, SECCLASS_PACKET,
				    PACKET__RELABELTO, NULL);
	}
	return 0;
}
EXPORT_SYMBOL_GPL(selinux_relabel_packet_permission);