[PATCH] pcmcia: remove client services version (fix)
[linux-2.6/sactl.git] / include / linux / key-ui.h
blobcc326174a80886d8c6aba40e11055455de84a60f
1 /* key-ui.h: key userspace interface stuff
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #ifndef _LINUX_KEY_UI_H
13 #define _LINUX_KEY_UI_H
15 #include <linux/key.h>
17 /* the key tree */
18 extern struct rb_root key_serial_tree;
19 extern spinlock_t key_serial_lock;
21 /* required permissions */
22 #define KEY_VIEW 0x01 /* require permission to view attributes */
23 #define KEY_READ 0x02 /* require permission to read content */
24 #define KEY_WRITE 0x04 /* require permission to update / modify */
25 #define KEY_SEARCH 0x08 /* require permission to search (keyring) or find (key) */
26 #define KEY_LINK 0x10 /* require permission to link */
27 #define KEY_ALL 0x1f /* all the above permissions */
30 * the keyring payload contains a list of the keys to which the keyring is
31 * subscribed
33 struct keyring_list {
34 struct rcu_head rcu; /* RCU deletion hook */
35 unsigned short maxkeys; /* max keys this list can hold */
36 unsigned short nkeys; /* number of keys currently held */
37 unsigned short delkey; /* key to be unlinked by RCU */
38 struct key *keys[0];
43 * check to see whether permission is granted to use a key in the desired way
45 static inline int key_permission(const struct key *key, key_perm_t perm)
47 key_perm_t kperm;
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)
55 kperm = key->perm >> 8;
56 else
57 kperm = key->perm;
59 kperm = kperm & perm & KEY_ALL;
61 return kperm == perm;
65 * check to see whether permission is granted to use a key in at least one of
66 * the desired ways
68 static inline int key_any_permission(const struct key *key, key_perm_t perm)
70 key_perm_t kperm;
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)
78 kperm = key->perm >> 8;
79 else
80 kperm = key->perm;
82 kperm = kperm & perm & KEY_ALL;
84 return kperm != 0;
87 static inline int key_task_groups_search(struct task_struct *tsk, gid_t gid)
89 int ret;
91 task_lock(tsk);
92 ret = groups_search(tsk->group_info, gid);
93 task_unlock(tsk);
94 return ret;
97 static inline int key_task_permission(const struct key *key,
98 struct task_struct *context,
99 key_perm_t perm)
101 key_perm_t kperm;
103 if (key->uid == context->fsuid) {
104 kperm = key->perm >> 16;
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)
112 kperm = key->perm >> 8;
114 else {
115 kperm = key->perm;
118 kperm = kperm & perm & KEY_ALL;
120 return kperm == perm;
124 extern struct key *lookup_user_key(struct task_struct *context,
125 key_serial_t id, int create, int partial,
126 key_perm_t perm);
128 extern long join_session_keyring(const char *name);
130 extern struct key_type *key_type_lookup(const char *type);
131 extern void key_type_put(struct key_type *ktype);
133 #define key_negative_timeout 60 /* default timeout on a negative key's existence */
136 #endif /* _LINUX_KEY_UI_H */