KEYS: Allow expiry time to be set when preparsing a key
[deliverable/linux.git] / include / linux / key-type.h
CommitLineData
76181c13
DH
1/* Definitions for key type implementations
2 *
3 * Copyright (C) 2007 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 Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#ifndef _LINUX_KEY_TYPE_H
13#define _LINUX_KEY_TYPE_H
14
15#include <linux/key.h>
5935e6dc 16#include <linux/errno.h>
76181c13
DH
17
18#ifdef CONFIG_KEYS
19
20/*
21 * key under-construction record
22 * - passed to the request_key actor if supplied
23 */
24struct key_construction {
25 struct key *key; /* key being constructed */
26 struct key *authkey;/* authorisation for key being constructed */
27};
28
cf7f601c
DH
29/*
30 * Pre-parsed payload, used by key add, update and instantiate.
31 *
32 * This struct will be cleared and data and datalen will be set with the data
33 * and length parameters from the caller and quotalen will be set from
34 * def_datalen from the key type. Then if the preparse() op is provided by the
35 * key type, that will be called. Then the struct will be passed to the
36 * instantiate() or the update() op.
37 *
38 * If the preparse() op is given, the free_preparse() op will be called to
39 * clear the contents.
40 */
41struct key_preparsed_payload {
42 char *description; /* Proposed key description (or NULL) */
43 void *type_data[2]; /* Private key-type data */
fc7c70e0 44 void *payload[2]; /* Proposed payload */
cf7f601c
DH
45 const void *data; /* Raw data */
46 size_t datalen; /* Raw datalen */
47 size_t quotalen; /* Quota length for proposed payload */
7dfa0ca6 48 time_t expiry; /* Expiry time of key */
008643b8 49 bool trusted; /* True if key is trusted */
cf7f601c
DH
50};
51
76181c13
DH
52typedef int (*request_key_actor_t)(struct key_construction *key,
53 const char *op, void *aux);
54
55/*
56 * kernel managed key type definition
57 */
58struct key_type {
59 /* name of the type */
60 const char *name;
61
62 /* default payload length for quota precalculation (optional)
63 * - this can be used instead of calling key_payload_reserve(), that
64 * function only needs to be called if the real datalen is different
65 */
66 size_t def_datalen;
67
4bdf0bc3
DH
68 /* Default key search algorithm. */
69 unsigned def_lookup_type;
70#define KEYRING_SEARCH_LOOKUP_DIRECT 0x0000 /* Direct lookup by description. */
71#define KEYRING_SEARCH_LOOKUP_ITERATE 0x0001 /* Iterative search. */
72
b9fffa38
DH
73 /* vet a description */
74 int (*vet_description)(const char *description);
75
cf7f601c
DH
76 /* Preparse the data blob from userspace that is to be the payload,
77 * generating a proposed description and payload that will be handed to
78 * the instantiate() and update() ops.
79 */
80 int (*preparse)(struct key_preparsed_payload *prep);
81
82 /* Free a preparse data structure.
83 */
84 void (*free_preparse)(struct key_preparsed_payload *prep);
85
76181c13
DH
86 /* instantiate a key of this type
87 * - this method should call key_payload_reserve() to determine if the
88 * user's quota will hold the payload
89 */
cf7f601c 90 int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
76181c13
DH
91
92 /* update a key of this type (optional)
93 * - this method should call key_payload_reserve() to recalculate the
94 * quota consumption
95 * - the key must be locked against read when modifying
96 */
cf7f601c 97 int (*update)(struct key *key, struct key_preparsed_payload *prep);
76181c13
DH
98
99 /* match a key against a description */
100 int (*match)(const struct key *key, const void *desc);
101
102 /* clear some of the data from a key on revokation (optional)
103 * - the key's semaphore will be write-locked by the caller
104 */
105 void (*revoke)(struct key *key);
106
107 /* clear the data from a key (optional) */
108 void (*destroy)(struct key *key);
109
110 /* describe a key */
111 void (*describe)(const struct key *key, struct seq_file *p);
112
113 /* read a key's data (optional)
114 * - permission checks will be done by the caller
115 * - the key's semaphore will be readlocked by the caller
116 * - should return the amount of data that could be read, no matter how
117 * much is copied into the buffer
118 * - shouldn't do the copy if the buffer is NULL
119 */
120 long (*read)(const struct key *key, char __user *buffer, size_t buflen);
121
122 /* handle request_key() for this type instead of invoking
123 * /sbin/request-key (optional)
124 * - key is the key to instantiate
125 * - authkey is the authority to assume when instantiating this key
126 * - op is the operation to be done, usually "create"
127 * - the call must not return until the instantiation process has run
128 * its course
129 */
130 request_key_actor_t request_key;
131
132 /* internal fields */
133 struct list_head link; /* link in types list */
7845bc39 134 struct lock_class_key lock_class; /* key->sem lock class */
76181c13
DH
135};
136
137extern struct key_type key_type_keyring;
138
139extern int register_key_type(struct key_type *ktype);
140extern void unregister_key_type(struct key_type *ktype);
141
142extern int key_payload_reserve(struct key *key, size_t datalen);
143extern int key_instantiate_and_link(struct key *key,
144 const void *data,
145 size_t datalen,
146 struct key *keyring,
147 struct key *instkey);
fdd1b945 148extern int key_reject_and_link(struct key *key,
76181c13 149 unsigned timeout,
fdd1b945 150 unsigned error,
76181c13
DH
151 struct key *keyring,
152 struct key *instkey);
153extern void complete_request_key(struct key_construction *cons, int error);
154
fdd1b945
DH
155static inline int key_negate_and_link(struct key *key,
156 unsigned timeout,
157 struct key *keyring,
158 struct key *instkey)
159{
160 return key_reject_and_link(key, timeout, ENOKEY, keyring, instkey);
161}
162
6a09d17b
DH
163extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep);
164
76181c13
DH
165#endif /* CONFIG_KEYS */
166#endif /* _LINUX_KEY_TYPE_H */
This page took 0.792596 seconds and 5 git commands to generate.