1 /* Definitions for key type implementations
3 * Copyright (C) 2007 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 Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #ifndef _LINUX_KEY_TYPE_H
13 #define _LINUX_KEY_TYPE_H
15 #include <linux/key.h>
16 #include <linux/errno.h>
21 * key under-construction record
22 * - passed to the request_key actor if supplied
24 struct key_construction
{
25 struct key
*key
; /* key being constructed */
26 struct key
*authkey
;/* authorisation for key being constructed */
29 typedef int (*request_key_actor_t
)(struct key_construction
*key
,
30 const char *op
, void *aux
);
33 * kernel managed key type definition
36 /* name of the type */
39 /* default payload length for quota precalculation (optional)
40 * - this can be used instead of calling key_payload_reserve(), that
41 * function only needs to be called if the real datalen is different
45 /* vet a description */
46 int (*vet_description
)(const char *description
);
48 /* instantiate a key of this type
49 * - this method should call key_payload_reserve() to determine if the
50 * user's quota will hold the payload
52 int (*instantiate
)(struct key
*key
, const void *data
, size_t datalen
);
54 /* update a key of this type (optional)
55 * - this method should call key_payload_reserve() to recalculate the
57 * - the key must be locked against read when modifying
59 int (*update
)(struct key
*key
, const void *data
, size_t datalen
);
61 /* match a key against a description */
62 int (*match
)(const struct key
*key
, const void *desc
);
64 /* clear some of the data from a key on revokation (optional)
65 * - the key's semaphore will be write-locked by the caller
67 void (*revoke
)(struct key
*key
);
69 /* clear the data from a key (optional) */
70 void (*destroy
)(struct key
*key
);
73 void (*describe
)(const struct key
*key
, struct seq_file
*p
);
75 /* read a key's data (optional)
76 * - permission checks will be done by the caller
77 * - the key's semaphore will be readlocked by the caller
78 * - should return the amount of data that could be read, no matter how
79 * much is copied into the buffer
80 * - shouldn't do the copy if the buffer is NULL
82 long (*read
)(const struct key
*key
, char __user
*buffer
, size_t buflen
);
84 /* handle request_key() for this type instead of invoking
85 * /sbin/request-key (optional)
86 * - key is the key to instantiate
87 * - authkey is the authority to assume when instantiating this key
88 * - op is the operation to be done, usually "create"
89 * - the call must not return until the instantiation process has run
92 request_key_actor_t request_key
;
95 struct list_head link
; /* link in types list */
96 struct lock_class_key lock_class
; /* key->sem lock class */
99 extern struct key_type key_type_keyring
;
101 extern int register_key_type(struct key_type
*ktype
);
102 extern void unregister_key_type(struct key_type
*ktype
);
104 extern int key_payload_reserve(struct key
*key
, size_t datalen
);
105 extern int key_instantiate_and_link(struct key
*key
,
109 struct key
*instkey
);
110 extern int key_reject_and_link(struct key
*key
,
114 struct key
*instkey
);
115 extern void complete_request_key(struct key_construction
*cons
, int error
);
117 static inline int key_negate_and_link(struct key
*key
,
122 return key_reject_and_link(key
, timeout
, ENOKEY
, keyring
, instkey
);
125 #endif /* CONFIG_KEYS */
126 #endif /* _LINUX_KEY_TYPE_H */