diff options
Diffstat (limited to 'include/linux/key-ui.h')
| -rw-r--r-- | include/linux/key-ui.h | 87 |
1 files changed, 8 insertions, 79 deletions
diff --git a/include/linux/key-ui.h b/include/linux/key-ui.h index cc326174a808..7a2e332067c3 100644 --- a/include/linux/key-ui.h +++ b/include/linux/key-ui.h | |||
| @@ -38,92 +38,21 @@ struct keyring_list { | |||
| 38 | struct key *keys[0]; | 38 | struct key *keys[0]; |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| 41 | |||
| 42 | /* | 41 | /* |
| 43 | * check to see whether permission is granted to use a key in the desired way | 42 | * check to see whether permission is granted to use a key in the desired way |
| 44 | */ | 43 | */ |
| 45 | static inline int key_permission(const struct key *key, key_perm_t perm) | 44 | extern int key_task_permission(const key_ref_t key_ref, |
| 46 | { | 45 | struct task_struct *context, |
| 47 | key_perm_t kperm; | 46 | key_perm_t perm); |
| 48 | |||
| 49 | if (key->uid == current->fsuid) | ||
| 50 | kperm = key->perm >> 16; | ||
| 51 | else if (key->gid != -1 && | ||
| 52 | key->perm & KEY_GRP_ALL && | ||
| 53 | in_group_p(key->gid) | ||
| 54 | ) | ||
| 55 | kperm = key->perm >> 8; | ||
| 56 | else | ||
| 57 | kperm = key->perm; | ||
| 58 | |||
| 59 | kperm = kperm & perm & KEY_ALL; | ||
| 60 | |||
| 61 | return kperm == perm; | ||
| 62 | } | ||
| 63 | |||
| 64 | /* | ||
| 65 | * check to see whether permission is granted to use a key in at least one of | ||
| 66 | * the desired ways | ||
| 67 | */ | ||
| 68 | static inline int key_any_permission(const struct key *key, key_perm_t perm) | ||
| 69 | { | ||
| 70 | key_perm_t kperm; | ||
| 71 | |||
| 72 | if (key->uid == current->fsuid) | ||
| 73 | kperm = key->perm >> 16; | ||
| 74 | else if (key->gid != -1 && | ||
| 75 | key->perm & KEY_GRP_ALL && | ||
| 76 | in_group_p(key->gid) | ||
| 77 | ) | ||
| 78 | kperm = key->perm >> 8; | ||
| 79 | else | ||
| 80 | kperm = key->perm; | ||
| 81 | 47 | ||
| 82 | kperm = kperm & perm & KEY_ALL; | 48 | static inline int key_permission(const key_ref_t key_ref, key_perm_t perm) |
| 83 | |||
| 84 | return kperm != 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | static inline int key_task_groups_search(struct task_struct *tsk, gid_t gid) | ||
| 88 | { | 49 | { |
| 89 | int ret; | 50 | return key_task_permission(key_ref, current, perm); |
| 90 | |||
| 91 | task_lock(tsk); | ||
| 92 | ret = groups_search(tsk->group_info, gid); | ||
| 93 | task_unlock(tsk); | ||
| 94 | return ret; | ||
| 95 | } | ||
| 96 | |||
| 97 | static inline int key_task_permission(const struct key *key, | ||
| 98 | struct task_struct *context, | ||
| 99 | key_perm_t perm) | ||
| 100 | { | ||
| 101 | key_perm_t kperm; | ||
| 102 | |||
| 103 | if (key->uid == context->fsuid) { | ||
| 104 | kperm = key->perm >> 16; | ||
| 105 | } | ||
| 106 | else if (key->gid != -1 && | ||
| 107 | key->perm & KEY_GRP_ALL && ( | ||
| 108 | key->gid == context->fsgid || | ||
| 109 | key_task_groups_search(context, key->gid) | ||
| 110 | ) | ||
| 111 | ) { | ||
| 112 | kperm = key->perm >> 8; | ||
| 113 | } | ||
| 114 | else { | ||
| 115 | kperm = key->perm; | ||
| 116 | } | ||
| 117 | |||
| 118 | kperm = kperm & perm & KEY_ALL; | ||
| 119 | |||
| 120 | return kperm == perm; | ||
| 121 | |||
| 122 | } | 51 | } |
| 123 | 52 | ||
| 124 | extern struct key *lookup_user_key(struct task_struct *context, | 53 | extern key_ref_t lookup_user_key(struct task_struct *context, |
| 125 | key_serial_t id, int create, int partial, | 54 | key_serial_t id, int create, int partial, |
| 126 | key_perm_t perm); | 55 | key_perm_t perm); |
| 127 | 56 | ||
| 128 | extern long join_session_keyring(const char *name); | 57 | extern long join_session_keyring(const char *name); |
| 129 | 58 | ||
