/*
* 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"
#include "tomoyo.h"
#include "realpath.h"
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
/*
* tomoyo_globally_readable_file_entry is a structure which is used for holding
* "allow_read" entries.
* It has following fields.
*
* (1) "list" which is linked to tomoyo_globally_readable_list .
* (2) "filename" is a pathname which is allowed to open(O_RDONLY).
* (3) "is_deleted" is a bool which is true if marked as deleted, false
* otherwise.
*/
struct tomoyo_globally_readable_file_entry {
struct list_head list;
const struct tomoyo_path_info *filename;
bool is_deleted;
};
/*
* tomoyo_pattern_entry is a structure which is used for holding
* "tomoyo_pattern_list" entries.
* It has following fields.
*
* (1) "list" which is linked to tomoyo_pattern_list .
* (2) "pattern" is a pathname pattern which is used for converting pathnames
* to pathname patterns during learning mode.
* (3) "is_deleted" is a bool which is true if marked as deleted, false
* otherwise.
*/
struct tomoyo_pattern_entry {
struct list_head list;
const struct tomoyo_path_info *pattern;
bool is_deleted;
};
/*
* tomoyo_no_rewrite_entry is a structure which is used for holding
* "deny_rewrite" entries.
* It has following fields.
*
* (1) "list" which is linked to tomoyo_no_rewrite_list .
* (2) "pattern" is a pathname which is by default not permitted to modify
* already existing content.
* (3) "is_deleted" is a bool which is true if marked as deleted, false
* otherwise.
*/
struct tomoyo_no_rewrite_entry {
struct list_head list;
const struct tomoyo_path_info *pattern;
bool is_deleted;
};
/* 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",
};
/* 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_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)