blob: 1bb416f4bbcef7aa9315e9efcb59d292389ee8b2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* internal.h: authentication token and access key management internal defs
2 *
David Howells3e301482005-06-23 22:00:56 -07003 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 _INTERNAL_H
13#define _INTERNAL_H
14
15#include <linux/key.h>
16#include <linux/key-ui.h>
17
David Howells3e301482005-06-23 22:00:56 -070018#if 0
19#define kenter(FMT, a...) printk("==> %s("FMT")\n",__FUNCTION__ , ## a)
20#define kleave(FMT, a...) printk("<== %s()"FMT"\n",__FUNCTION__ , ## a)
21#define kdebug(FMT, a...) printk(FMT"\n" , ## a)
22#else
23#define kenter(FMT, a...) do {} while(0)
24#define kleave(FMT, a...) do {} while(0)
25#define kdebug(FMT, a...) do {} while(0)
26#endif
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028extern struct key_type key_type_user;
29
30/*****************************************************************************/
31/*
32 * keep track of keys for a user
33 * - this needs to be separate to user_struct to avoid a refcount-loop
34 * (user_struct pins some keyrings which pin this struct)
35 * - this also keeps track of keys under request from userspace for this UID
36 */
37struct key_user {
38 struct rb_node node;
39 struct list_head consq; /* construction queue */
40 spinlock_t lock;
41 atomic_t usage; /* for accessing qnkeys & qnbytes */
42 atomic_t nkeys; /* number of keys */
43 atomic_t nikeys; /* number of instantiated keys */
44 uid_t uid;
45 int qnkeys; /* number of keys allocated to this user */
46 int qnbytes; /* number of bytes allocated to this user */
47};
48
49#define KEYQUOTA_MAX_KEYS 100
50#define KEYQUOTA_MAX_BYTES 10000
51#define KEYQUOTA_LINK_BYTES 4 /* a link in a keyring is worth 4 bytes */
52
53extern struct rb_root key_user_tree;
54extern spinlock_t key_user_lock;
55extern struct key_user root_key_user;
56
57extern struct key_user *key_user_lookup(uid_t uid);
58extern void key_user_put(struct key_user *user);
59
60
61
62extern struct rb_root key_serial_tree;
63extern spinlock_t key_serial_lock;
64extern struct semaphore key_alloc_sem;
65extern struct rw_semaphore key_construction_sem;
66extern wait_queue_head_t request_key_conswq;
67
68
69extern void keyring_publish_name(struct key *keyring);
70
71extern int __key_link(struct key *keyring, struct key *key);
72
David Howells664cceb2005-09-28 17:03:15 +010073extern key_ref_t __keyring_search_one(key_ref_t keyring_ref,
74 const struct key_type *type,
75 const char *description,
76 key_perm_t perm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
David Howells3e301482005-06-23 22:00:56 -070078extern struct key *keyring_search_instkey(struct key *keyring,
79 key_serial_t target_id);
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081typedef int (*key_match_func_t)(const struct key *, const void *);
82
David Howells664cceb2005-09-28 17:03:15 +010083extern key_ref_t keyring_search_aux(key_ref_t keyring_ref,
84 struct task_struct *tsk,
85 struct key_type *type,
86 const void *description,
87 key_match_func_t match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
David Howells664cceb2005-09-28 17:03:15 +010089extern key_ref_t search_process_keyrings(struct key_type *type,
90 const void *description,
91 key_match_func_t match,
92 struct task_struct *tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94extern struct key *find_keyring_by_name(const char *name, key_serial_t bound);
95
96extern int install_thread_keyring(struct task_struct *tsk);
David Howells3e301482005-06-23 22:00:56 -070097extern int install_process_keyring(struct task_struct *tsk);
98
99extern struct key *request_key_and_link(struct key_type *type,
100 const char *description,
101 const char *callout_info,
David Howells4e54f082006-06-29 02:24:28 -0700102 void *aux,
David Howells7e047ef2006-06-26 00:24:50 -0700103 struct key *dest_keyring,
104 unsigned long flags);
David Howells3e301482005-06-23 22:00:56 -0700105
106/*
107 * request_key authorisation
108 */
109struct request_key_auth {
110 struct key *target_key;
111 struct task_struct *context;
David Howellsb5f545c2006-01-08 01:02:47 -0800112 const char *callout_info;
David Howells3e301482005-06-23 22:00:56 -0700113 pid_t pid;
114};
115
116extern struct key_type key_type_request_key_auth;
117extern struct key *request_key_auth_new(struct key *target,
David Howellsb5f545c2006-01-08 01:02:47 -0800118 const char *callout_info);
David Howells3e301482005-06-23 22:00:56 -0700119
120extern struct key *key_get_instantiation_authkey(key_serial_t target_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122/*
123 * keyctl functions
124 */
125extern long keyctl_get_keyring_ID(key_serial_t, int);
126extern long keyctl_join_session_keyring(const char __user *);
127extern long keyctl_update_key(key_serial_t, const void __user *, size_t);
128extern long keyctl_revoke_key(key_serial_t);
129extern long keyctl_keyring_clear(key_serial_t);
130extern long keyctl_keyring_link(key_serial_t, key_serial_t);
131extern long keyctl_keyring_unlink(key_serial_t, key_serial_t);
132extern long keyctl_describe_key(key_serial_t, char __user *, size_t);
133extern long keyctl_keyring_search(key_serial_t, const char __user *,
134 const char __user *, key_serial_t);
135extern long keyctl_read_key(key_serial_t, char __user *, size_t);
136extern long keyctl_chown_key(key_serial_t, uid_t, gid_t);
137extern long keyctl_setperm_key(key_serial_t, key_perm_t);
138extern long keyctl_instantiate_key(key_serial_t, const void __user *,
139 size_t, key_serial_t);
140extern long keyctl_negate_key(key_serial_t, unsigned, key_serial_t);
David Howells3e301482005-06-23 22:00:56 -0700141extern long keyctl_set_reqkey_keyring(int);
David Howells017679c2006-01-08 01:02:43 -0800142extern long keyctl_set_timeout(key_serial_t, unsigned);
David Howellsb5f545c2006-01-08 01:02:47 -0800143extern long keyctl_assume_authority(key_serial_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145
146/*
147 * debugging key validation
148 */
149#ifdef KEY_DEBUGGING
150extern void __key_check(const struct key *);
151
152static inline void key_check(const struct key *key)
153{
154 if (key && (IS_ERR(key) || key->magic != KEY_DEBUG_MAGIC))
155 __key_check(key);
156}
157
158#else
159
160#define key_check(key) do {} while(0)
161
162#endif
163
164#endif /* _INTERNAL_H */