1 /* key-ui.h: key userspace interface stuff for use by keyfs
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>
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
34 unsigned maxkeys
; /* max keys this list can hold */
35 unsigned nkeys
; /* number of keys currently held */
41 * check to see whether permission is granted to use a key in the desired way
43 static inline int key_permission(const struct key
*key
, key_perm_t perm
)
47 if (key
->uid
== current
->fsuid
)
48 kperm
= key
->perm
>> 16;
49 else if (key
->gid
!= -1 &&
50 key
->perm
& KEY_GRP_ALL
&&
53 kperm
= key
->perm
>> 8;
57 kperm
= kperm
& perm
& KEY_ALL
;
63 * check to see whether permission is granted to use a key in at least one of
66 static inline int key_any_permission(const struct key
*key
, key_perm_t perm
)
70 if (key
->uid
== current
->fsuid
)
71 kperm
= key
->perm
>> 16;
72 else if (key
->gid
!= -1 &&
73 key
->perm
& KEY_GRP_ALL
&&
76 kperm
= key
->perm
>> 8;
80 kperm
= kperm
& perm
& KEY_ALL
;
86 extern struct key
*lookup_user_key(key_serial_t id
, int create
, int part
,
89 extern long join_session_keyring(const char *name
);
91 extern struct key_type
*key_type_lookup(const char *type
);
92 extern void key_type_put(struct key_type
*ktype
);
94 #define key_negative_timeout 60 /* default timeout on a negative key's existence */
97 #endif /* _LINUX_KEY_UI_H */