Commit 5db5a39b authored by Tetsuo Handa's avatar Tetsuo Handa Committed by James Morris

TOMOYO: Use common code for policy reading.

tomoyo_print_..._acl() are similar. Merge them.
Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 063821c8
...@@ -746,217 +746,121 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head) ...@@ -746,217 +746,121 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head)
} }
/** /**
* tomoyo_print_path_acl - Print a single path ACL entry. * tomoyo_fns - Find next set bit.
*
* @perm: 8 bits value.
* @bit: First bit to find.
*
* Returns next on-bit on success, 8 otherwise.
*/
static u8 tomoyo_fns(const u8 perm, u8 bit)
{
for ( ; bit < 8; bit++)
if (perm & (1 << bit))
break;
return bit;
}
/**
* tomoyo_print_entry - Print an ACL entry.
* *
* @head: Pointer to "struct tomoyo_io_buffer". * @head: Pointer to "struct tomoyo_io_buffer".
* @ptr: Pointer to "struct tomoyo_path_acl". * @acl: Pointer to an ACL entry.
* *
* Returns true on success, false otherwise. * Returns true on success, false otherwise.
*/ */
static bool tomoyo_print_path_acl(struct tomoyo_io_buffer *head, static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
struct tomoyo_path_acl *ptr) struct tomoyo_acl_info *acl)
{ {
int pos; const u8 acl_type = acl->type;
u8 bit; u8 bit = head->read_bit;
const u16 perm = ptr->perm; int pos = head->read_avail;
for (bit = head->read_bit; bit < TOMOYO_MAX_PATH_OPERATION; bit++) { if (acl->is_deleted)
return true;
next:
if (acl_type == TOMOYO_TYPE_PATH_ACL) {
struct tomoyo_path_acl *ptr =
container_of(acl, typeof(*ptr), head);
const u16 perm = ptr->perm;
for ( ; bit < TOMOYO_MAX_PATH_OPERATION; bit++) {
if (!(perm & (1 << bit))) if (!(perm & (1 << bit)))
continue; continue;
if (head->print_execute_only && bit != TOMOYO_TYPE_EXECUTE) if (head->print_execute_only &&
bit != TOMOYO_TYPE_EXECUTE)
continue; continue;
/* Print "read/write" instead of "read" and "write". */ /* Print "read/write" instead of "read" and "write". */
if ((bit == TOMOYO_TYPE_READ || bit == TOMOYO_TYPE_WRITE) if ((bit == TOMOYO_TYPE_READ ||
bit == TOMOYO_TYPE_WRITE)
&& (perm & (1 << TOMOYO_TYPE_READ_WRITE))) && (perm & (1 << TOMOYO_TYPE_READ_WRITE)))
continue; continue;
pos = head->read_avail; break;
}
if (bit >= TOMOYO_MAX_PATH_OPERATION)
goto done;
if (!tomoyo_io_printf(head, "allow_%s ", if (!tomoyo_io_printf(head, "allow_%s ",
tomoyo_path_keyword[bit]) || tomoyo_path_keyword[bit]) ||
!tomoyo_print_name_union(head, &ptr->name) || !tomoyo_print_name_union(head, &ptr->name))
!tomoyo_io_printf(head, "\n"))
goto out; goto out;
} } else if (head->print_execute_only) {
head->read_bit = 0;
return true; return true;
out: } else if (acl_type == TOMOYO_TYPE_PATH2_ACL) {
head->read_bit = bit; struct tomoyo_path2_acl *ptr =
head->read_avail = pos; container_of(acl, typeof(*ptr), head);
return false; bit = tomoyo_fns(ptr->perm, bit);
} if (bit >= TOMOYO_MAX_PATH2_OPERATION)
goto done;
/**
* tomoyo_print_path2_acl - Print a double path ACL entry.
*
* @head: Pointer to "struct tomoyo_io_buffer".
* @ptr: Pointer to "struct tomoyo_path2_acl".
*
* Returns true on success, false otherwise.
*/
static bool tomoyo_print_path2_acl(struct tomoyo_io_buffer *head,
struct tomoyo_path2_acl *ptr)
{
int pos;
const u8 perm = ptr->perm;
u8 bit;
for (bit = head->read_bit; bit < TOMOYO_MAX_PATH2_OPERATION; bit++) {
if (!(perm & (1 << bit)))
continue;
pos = head->read_avail;
if (!tomoyo_io_printf(head, "allow_%s ", if (!tomoyo_io_printf(head, "allow_%s ",
tomoyo_path2_keyword[bit]) || tomoyo_path2_keyword[bit]) ||
!tomoyo_print_name_union(head, &ptr->name1) || !tomoyo_print_name_union(head, &ptr->name1) ||
!tomoyo_print_name_union(head, &ptr->name2) || !tomoyo_print_name_union(head, &ptr->name2))
!tomoyo_io_printf(head, "\n"))
goto out; goto out;
} } else if (acl_type == TOMOYO_TYPE_PATH_NUMBER_ACL) {
head->read_bit = 0; struct tomoyo_path_number_acl *ptr =
return true; container_of(acl, typeof(*ptr), head);
out: bit = tomoyo_fns(ptr->perm, bit);
head->read_bit = bit; if (bit >= TOMOYO_MAX_PATH_NUMBER_OPERATION)
head->read_avail = pos; goto done;
return false;
}
/**
* tomoyo_print_path_number_acl - Print a path_number ACL entry.
*
* @head: Pointer to "struct tomoyo_io_buffer".
* @ptr: Pointer to "struct tomoyo_path_number_acl".
*
* Returns true on success, false otherwise.
*/
static bool tomoyo_print_path_number_acl(struct tomoyo_io_buffer *head,
struct tomoyo_path_number_acl *ptr)
{
int pos;
u8 bit;
const u8 perm = ptr->perm;
for (bit = head->read_bit; bit < TOMOYO_MAX_PATH_NUMBER_OPERATION;
bit++) {
if (!(perm & (1 << bit)))
continue;
pos = head->read_avail;
if (!tomoyo_io_printf(head, "allow_%s", if (!tomoyo_io_printf(head, "allow_%s",
tomoyo_path_number_keyword[bit]) || tomoyo_path_number_keyword[bit]) ||
!tomoyo_print_name_union(head, &ptr->name) || !tomoyo_print_name_union(head, &ptr->name) ||
!tomoyo_print_number_union(head, &ptr->number) || !tomoyo_print_number_union(head, &ptr->number))
!tomoyo_io_printf(head, "\n"))
goto out; goto out;
} } else if (acl_type == TOMOYO_TYPE_MKDEV_ACL) {
head->read_bit = 0; struct tomoyo_mkdev_acl *ptr =
return true; container_of(acl, typeof(*ptr), head);
out: bit = tomoyo_fns(ptr->perm, bit);
head->read_bit = bit; if (bit >= TOMOYO_MAX_MKDEV_OPERATION)
head->read_avail = pos; goto done;
return false;
}
/**
* tomoyo_print_mkdev_acl - Print a mkdev ACL entry.
*
* @head: Pointer to "struct tomoyo_io_buffer".
* @ptr: Pointer to "struct tomoyo_mkdev_acl".
*
* Returns true on success, false otherwise.
*/
static bool tomoyo_print_mkdev_acl(struct tomoyo_io_buffer *head,
struct tomoyo_mkdev_acl *ptr)
{
int pos;
u8 bit;
const u16 perm = ptr->perm;
for (bit = head->read_bit; bit < TOMOYO_MAX_MKDEV_OPERATION;
bit++) {
if (!(perm & (1 << bit)))
continue;
pos = head->read_avail;
if (!tomoyo_io_printf(head, "allow_%s", if (!tomoyo_io_printf(head, "allow_%s",
tomoyo_mkdev_keyword[bit]) || tomoyo_mkdev_keyword[bit]) ||
!tomoyo_print_name_union(head, &ptr->name) || !tomoyo_print_name_union(head, &ptr->name) ||
!tomoyo_print_number_union(head, &ptr->mode) || !tomoyo_print_number_union(head, &ptr->mode) ||
!tomoyo_print_number_union(head, &ptr->major) || !tomoyo_print_number_union(head, &ptr->major) ||
!tomoyo_print_number_union(head, &ptr->minor) || !tomoyo_print_number_union(head, &ptr->minor))
!tomoyo_io_printf(head, "\n"))
goto out; goto out;
} } else if (acl_type == TOMOYO_TYPE_MOUNT_ACL) {
head->read_bit = 0; struct tomoyo_mount_acl *ptr =
return true; container_of(acl, typeof(*ptr), head);
out:
head->read_bit = bit;
head->read_avail = pos;
return false;
}
/**
* tomoyo_print_mount_acl - Print a mount ACL entry.
*
* @head: Pointer to "struct tomoyo_io_buffer".
* @ptr: Pointer to "struct tomoyo_mount_acl".
*
* Returns true on success, false otherwise.
*/
static bool tomoyo_print_mount_acl(struct tomoyo_io_buffer *head,
struct tomoyo_mount_acl *ptr)
{
const int pos = head->read_avail;
if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_MOUNT) || if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_MOUNT) ||
!tomoyo_print_name_union(head, &ptr->dev_name) || !tomoyo_print_name_union(head, &ptr->dev_name) ||
!tomoyo_print_name_union(head, &ptr->dir_name) || !tomoyo_print_name_union(head, &ptr->dir_name) ||
!tomoyo_print_name_union(head, &ptr->fs_type) || !tomoyo_print_name_union(head, &ptr->fs_type) ||
!tomoyo_print_number_union(head, &ptr->flags) || !tomoyo_print_number_union(head, &ptr->flags))
!tomoyo_io_printf(head, "\n")) { goto out;
head->read_avail = pos;
return false;
} }
return true; if (!tomoyo_io_printf(head, "\n"))
} goto out;
head->read_bit = bit;
/** if (acl_type != TOMOYO_TYPE_MOUNT_ACL) {
* tomoyo_print_entry - Print an ACL entry. bit++;
* goto next;
* @head: Pointer to "struct tomoyo_io_buffer".
* @ptr: Pointer to an ACL entry.
*
* Returns true on success, false otherwise.
*/
static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
struct tomoyo_acl_info *ptr)
{
const u8 acl_type = ptr->type;
if (ptr->is_deleted)
return true;
if (acl_type == TOMOYO_TYPE_PATH_ACL) {
struct tomoyo_path_acl *acl
= container_of(ptr, struct tomoyo_path_acl, head);
return tomoyo_print_path_acl(head, acl);
} }
if (head->print_execute_only) done:
head->read_bit = 0;
return true; return true;
if (acl_type == TOMOYO_TYPE_PATH2_ACL) { out:
struct tomoyo_path2_acl *acl head->read_avail = pos;
= container_of(ptr, struct tomoyo_path2_acl, head);
return tomoyo_print_path2_acl(head, acl);
}
if (acl_type == TOMOYO_TYPE_PATH_NUMBER_ACL) {
struct tomoyo_path_number_acl *acl
= container_of(ptr, struct tomoyo_path_number_acl,
head);
return tomoyo_print_path_number_acl(head, acl);
}
if (acl_type == TOMOYO_TYPE_MKDEV_ACL) {
struct tomoyo_mkdev_acl *acl
= container_of(ptr, struct tomoyo_mkdev_acl,
head);
return tomoyo_print_mkdev_acl(head, acl);
}
if (acl_type == TOMOYO_TYPE_MOUNT_ACL) {
struct tomoyo_mount_acl *acl
= container_of(ptr, struct tomoyo_mount_acl, head);
return tomoyo_print_mount_acl(head, acl);
}
BUG(); /* This must not happen. */
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment