Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / security / keys / internal.h
blob67b2b93a7489a8dfcaf5ebaab0b8d864a19170fd
1 /* internal.h: authentication token and access key management internal defs
3 * Copyright (C) 2003 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 _INTERNAL_H
13 #define _INTERNAL_H
15 #include <linux/key.h>
16 #include <linux/key-ui.h>
18 extern struct key_type key_type_dead;
19 extern struct key_type key_type_user;
21 /*****************************************************************************/
23 * keep track of keys for a user
24 * - this needs to be separate to user_struct to avoid a refcount-loop
25 * (user_struct pins some keyrings which pin this struct)
26 * - this also keeps track of keys under request from userspace for this UID
28 struct key_user {
29 struct rb_node node;
30 struct list_head consq; /* construction queue */
31 spinlock_t lock;
32 atomic_t usage; /* for accessing qnkeys & qnbytes */
33 atomic_t nkeys; /* number of keys */
34 atomic_t nikeys; /* number of instantiated keys */
35 uid_t uid;
36 int qnkeys; /* number of keys allocated to this user */
37 int qnbytes; /* number of bytes allocated to this user */
40 #define KEYQUOTA_MAX_KEYS 100
41 #define KEYQUOTA_MAX_BYTES 10000
42 #define KEYQUOTA_LINK_BYTES 4 /* a link in a keyring is worth 4 bytes */
44 extern struct rb_root key_user_tree;
45 extern spinlock_t key_user_lock;
46 extern struct key_user root_key_user;
48 extern struct key_user *key_user_lookup(uid_t uid);
49 extern void key_user_put(struct key_user *user);
53 extern struct rb_root key_serial_tree;
54 extern spinlock_t key_serial_lock;
55 extern struct semaphore key_alloc_sem;
56 extern struct rw_semaphore key_construction_sem;
57 extern wait_queue_head_t request_key_conswq;
60 extern void keyring_publish_name(struct key *keyring);
62 extern int __key_link(struct key *keyring, struct key *key);
64 extern struct key *__keyring_search_one(struct key *keyring,
65 const struct key_type *type,
66 const char *description,
67 key_perm_t perm);
69 typedef int (*key_match_func_t)(const struct key *, const void *);
71 extern struct key *keyring_search_aux(struct key *keyring,
72 struct key_type *type,
73 const void *description,
74 key_match_func_t match);
76 extern struct key *search_process_keyrings_aux(struct key_type *type,
77 const void *description,
78 key_match_func_t match);
80 extern struct key *find_keyring_by_name(const char *name, key_serial_t bound);
82 extern int install_thread_keyring(struct task_struct *tsk);
85 * keyctl functions
87 extern long keyctl_get_keyring_ID(key_serial_t, int);
88 extern long keyctl_join_session_keyring(const char __user *);
89 extern long keyctl_update_key(key_serial_t, const void __user *, size_t);
90 extern long keyctl_revoke_key(key_serial_t);
91 extern long keyctl_keyring_clear(key_serial_t);
92 extern long keyctl_keyring_link(key_serial_t, key_serial_t);
93 extern long keyctl_keyring_unlink(key_serial_t, key_serial_t);
94 extern long keyctl_describe_key(key_serial_t, char __user *, size_t);
95 extern long keyctl_keyring_search(key_serial_t, const char __user *,
96 const char __user *, key_serial_t);
97 extern long keyctl_read_key(key_serial_t, char __user *, size_t);
98 extern long keyctl_chown_key(key_serial_t, uid_t, gid_t);
99 extern long keyctl_setperm_key(key_serial_t, key_perm_t);
100 extern long keyctl_instantiate_key(key_serial_t, const void __user *,
101 size_t, key_serial_t);
102 extern long keyctl_negate_key(key_serial_t, unsigned, key_serial_t);
106 * debugging key validation
108 #ifdef KEY_DEBUGGING
109 extern void __key_check(const struct key *);
111 static inline void key_check(const struct key *key)
113 if (key && (IS_ERR(key) || key->magic != KEY_DEBUG_MAGIC))
114 __key_check(key);
117 #else
119 #define key_check(key) do {} while(0)
121 #endif
123 #endif /* _INTERNAL_H */