[PATCH] Keys: Split key permissions checking into a .c file

The attached patch splits key permissions checking out of key-ui.h and
moves it into a .c file.  It's quite large and called quite a lot, and
it's about to get bigger with the addition of LSM support for keys...

key_any_permission() is also discarded as it's no longer used.

Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
David Howells
2005-10-07 15:07:38 +01:00
committed by Linus Torvalds
parent f1a9badcf6
commit 468ed2b0c8
3 changed files with 76 additions and 86 deletions

View File

@@ -38,97 +38,16 @@ struct keyring_list {
struct key *keys[0];
};
/*
* check to see whether permission is granted to use a key in the desired way
*/
extern int key_task_permission(const key_ref_t key_ref,
struct task_struct *context,
key_perm_t perm);
static inline int key_permission(const key_ref_t key_ref, key_perm_t perm)
{
struct key *key = key_ref_to_ptr(key_ref);
key_perm_t kperm;
if (is_key_possessed(key_ref))
kperm = key->perm >> 24;
else if (key->uid == current->fsuid)
kperm = key->perm >> 16;
else if (key->gid != -1 &&
key->perm & KEY_GRP_ALL &&
in_group_p(key->gid)
)
kperm = key->perm >> 8;
else
kperm = key->perm;
kperm = kperm & perm & KEY_ALL;
return kperm == perm;
}
/*
* check to see whether permission is granted to use a key in at least one of
* the desired ways
*/
static inline int key_any_permission(const key_ref_t key_ref, key_perm_t perm)
{
struct key *key = key_ref_to_ptr(key_ref);
key_perm_t kperm;
if (is_key_possessed(key_ref))
kperm = key->perm >> 24;
else if (key->uid == current->fsuid)
kperm = key->perm >> 16;
else if (key->gid != -1 &&
key->perm & KEY_GRP_ALL &&
in_group_p(key->gid)
)
kperm = key->perm >> 8;
else
kperm = key->perm;
kperm = kperm & perm & KEY_ALL;
return kperm != 0;
}
static inline int key_task_groups_search(struct task_struct *tsk, gid_t gid)
{
int ret;
task_lock(tsk);
ret = groups_search(tsk->group_info, gid);
task_unlock(tsk);
return ret;
}
static inline int key_task_permission(const key_ref_t key_ref,
struct task_struct *context,
key_perm_t perm)
{
struct key *key = key_ref_to_ptr(key_ref);
key_perm_t kperm;
if (is_key_possessed(key_ref)) {
kperm = key->perm >> 24;
}
else if (key->uid == context->fsuid) {
kperm = key->perm >> 16;
}
else if (key->gid != -1 &&
key->perm & KEY_GRP_ALL && (
key->gid == context->fsgid ||
key_task_groups_search(context, key->gid)
)
) {
kperm = key->perm >> 8;
}
else {
kperm = key->perm;
}
kperm = kperm & perm & KEY_ALL;
return kperm == perm;
return key_task_permission(key_ref, current, perm);
}
extern key_ref_t lookup_user_key(struct task_struct *context,