blob: e8b8a7a5c4968b8c3b4e4dc07e8a047fe2a7ec09 [file] [log] [blame]
David Howells3e301482005-06-23 22:00:56 -07001/* key-ui.h: key userspace interface stuff
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 */
11
12#ifndef _LINUX_KEY_UI_H
13#define _LINUX_KEY_UI_H
14
15#include <linux/key.h>
16
17/* the key tree */
18extern struct rb_root key_serial_tree;
19extern spinlock_t key_serial_lock;
20
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 */
David Howells29db9192005-10-30 15:02:44 -080027#define KEY_SETATTR 0x20 /* require permission to change attributes */
28#define KEY_ALL 0x3f /* all the above permissions */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/*
31 * the keyring payload contains a list of the keys to which the keyring is
32 * subscribed
33 */
34struct keyring_list {
David Howells76d8aea2005-06-23 22:00:49 -070035 struct rcu_head rcu; /* RCU deletion hook */
36 unsigned short maxkeys; /* max keys this list can hold */
37 unsigned short nkeys; /* number of keys currently held */
38 unsigned short delkey; /* key to be unlinked by RCU */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 struct key *keys[0];
40};
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/*
43 * check to see whether permission is granted to use a key in the desired way
44 */
David Howells468ed2b2005-10-07 15:07:38 +010045extern int key_task_permission(const key_ref_t key_ref,
46 struct task_struct *context,
47 key_perm_t perm);
48
David Howells664cceb2005-09-28 17:03:15 +010049static inline int key_permission(const key_ref_t key_ref, key_perm_t perm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
David Howells468ed2b2005-10-07 15:07:38 +010051 return key_task_permission(key_ref, current, perm);
David Howells3e301482005-06-23 22:00:56 -070052}
53
David Howells664cceb2005-09-28 17:03:15 +010054extern key_ref_t lookup_user_key(struct task_struct *context,
55 key_serial_t id, int create, int partial,
56 key_perm_t perm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58extern long join_session_keyring(const char *name);
59
60extern struct key_type *key_type_lookup(const char *type);
61extern void key_type_put(struct key_type *ktype);
62
63#define key_negative_timeout 60 /* default timeout on a negative key's existence */
64
65
66#endif /* _LINUX_KEY_UI_H */