/*
* security/tomoyo/file.c
*
* Implementation of the Domain-Based Mandatory Access Control.
*
* Copyright (C) 2005-2009 NTT DATA CORPORATION
*
* Version: 2.2.0 2009/04/01
*
*/
#include "common.h"
/* Keyword array for single path operations. */
static const char *tomoyo_sp_keyword[TOMOYO_MAX_SINGLE_PATH_OPERATION] = {
[TOMOYO_TYPE_READ_WRITE_ACL] = "read/write",
[TOMOYO_TYPE_EXECUTE_ACL] = "execute",
[TOMOYO_TYPE_READ_ACL] = "read",
[TOMOYO_TYPE_WRITE_ACL] = "write",
[TOMOYO_TYPE_CREATE_ACL] = "create",
[TOMOYO_TYPE_UNLINK_ACL] = "unlink",
[TOMOYO_TYPE_MKDIR_ACL] = "mkdir",
[TOMOYO_TYPE_RMDIR_ACL] = "rmdir",
[TOMOYO_TYPE_MKFIFO_ACL] = "mkfifo",
[TOMOYO_TYPE_MKSOCK_ACL] = "mksock",
[TOMOYO_TYPE_MKBLOCK_ACL] = "mkblock",
[TOMOYO_TYPE_MKCHAR_ACL] = "mkchar",
[TOMOYO_TYPE_TRUNCATE_ACL] = "truncate",
[TOMOYO_TYPE_SYMLINK_ACL] = "symlink",
[TOMOYO_TYPE_REWRITE_ACL] = "rewrite",
[TOMOYO_TYPE_IOCTL_ACL] = "ioctl",
[TOMOYO_TYPE_CHMOD_ACL] = "chmod",
[TOMOYO_TYPE_CHOWN_ACL] = "chown",
[TOMOYO_TYPE_CHGRP_ACL] = "chgrp",
[TOMOYO_TYPE_CHROOT_ACL] = "chroot",
[TOMOYO_TYPE_MOUNT_ACL] = "mount",
[TOMOYO_TYPE_UMOUNT_ACL] = "unmount",
};
/* Keyword array for double path operations. */
static const char *tomoyo_dp_keyword[TOMOYO_MAX_DOUBLE_PATH_OPERATION] = {
[TOMOYO_TYPE_LINK_ACL] = "link",
[TOMOYO_TYPE_RENAME_ACL] = "rename",
[TOMOYO_TYPE_PIVOT_ROOT_ACL] = "pivot_root",
};
/**
* tomoyo_sp2keyword - Get the name of single path operation.
*
* @operation: Type of operation.
*
* Returns the name of single path operation.
*/
const char *tomoyo_sp2keyword(const u8 operation)
{
return (operation < TOMOYO_MAX_SINGLE_PATH_OPERATION)
? tomoyo_sp_keyword[operation] : NULL;
}
/**
* tomoyo_dp2keyword - Get the name of double path operation.
*
* @operation: Type of operation.
*
* Returns the name of double path operation.
*/
const char *tomoyo_dp2keyword(const u8 operation)
{
return (operation < TOMOYO_MAX_DOUBLE_PATH_OPERATION)
? tomoyo_dp_keyword[operation] : NULL;
}
/**
* tomoyo_strendswith - Check whether the token ends with the given token.
*
* @name: The token to check.
* @tail: The token to find.
*
* Returns true if @name ends with @tail, false otherwise.
*/
static bool tomoyo_strendswith(const char *name, const char *tail)
{
int len;
if (!name || !tail)