~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/key-type.h

Version: ~ [ linux-5.13-rc1 ] ~ [ linux-5.12.2 ] ~ [ linux-5.11.19 ] ~ [ linux-5.10.35 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.117 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.190 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.232 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.268 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.268 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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>
 16 #include <linux/errno.h>
 17 
 18 #ifdef CONFIG_KEYS
 19 
 20 /*
 21  * key under-construction record
 22  * - passed to the request_key actor if supplied
 23  */
 24 struct key_construction {
 25         struct key      *key;   /* key being constructed */
 26         struct key      *authkey;/* authorisation for key being constructed */
 27 };
 28 
 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  */
 41 struct key_preparsed_payload {
 42         char            *description;   /* Proposed key description (or NULL) */
 43         union key_payload payload;      /* Proposed payload */
 44         const void      *data;          /* Raw data */
 45         size_t          datalen;        /* Raw datalen */
 46         size_t          quotalen;       /* Quota length for proposed payload */
 47         time_t          expiry;         /* Expiry time of key */
 48 };
 49 
 50 typedef int (*request_key_actor_t)(struct key_construction *key,
 51                                    const char *op, void *aux);
 52 
 53 /*
 54  * Preparsed matching criterion.
 55  */
 56 struct key_match_data {
 57         /* Comparison function, defaults to exact description match, but can be
 58          * overridden by type->match_preparse().  Should return true if a match
 59          * is found and false if not.
 60          */
 61         bool (*cmp)(const struct key *key,
 62                     const struct key_match_data *match_data);
 63 
 64         const void      *raw_data;      /* Raw match data */
 65         void            *preparsed;     /* For ->match_preparse() to stash stuff */
 66         unsigned        lookup_type;    /* Type of lookup for this search. */
 67 #define KEYRING_SEARCH_LOOKUP_DIRECT    0x0000  /* Direct lookup by description. */
 68 #define KEYRING_SEARCH_LOOKUP_ITERATE   0x0001  /* Iterative search. */
 69 };
 70 
 71 /*
 72  * kernel managed key type definition
 73  */
 74 struct key_type {
 75         /* name of the type */
 76         const char *name;
 77 
 78         /* default payload length for quota precalculation (optional)
 79          * - this can be used instead of calling key_payload_reserve(), that
 80          *   function only needs to be called if the real datalen is different
 81          */
 82         size_t def_datalen;
 83 
 84         /* vet a description */
 85         int (*vet_description)(const char *description);
 86 
 87         /* Preparse the data blob from userspace that is to be the payload,
 88          * generating a proposed description and payload that will be handed to
 89          * the instantiate() and update() ops.
 90          */
 91         int (*preparse)(struct key_preparsed_payload *prep);
 92 
 93         /* Free a preparse data structure.
 94          */
 95         void (*free_preparse)(struct key_preparsed_payload *prep);
 96 
 97         /* instantiate a key of this type
 98          * - this method should call key_payload_reserve() to determine if the
 99          *   user's quota will hold the payload
100          */
101         int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
102 
103         /* update a key of this type (optional)
104          * - this method should call key_payload_reserve() to recalculate the
105          *   quota consumption
106          * - the key must be locked against read when modifying
107          */
108         int (*update)(struct key *key, struct key_preparsed_payload *prep);
109 
110         /* Preparse the data supplied to ->match() (optional).  The
111          * data to be preparsed can be found in match_data->raw_data.
112          * The lookup type can also be set by this function.
113          */
114         int (*match_preparse)(struct key_match_data *match_data);
115 
116         /* Free preparsed match data (optional).  This should be supplied it
117          * ->match_preparse() is supplied. */
118         void (*match_free)(struct key_match_data *match_data);
119 
120         /* clear some of the data from a key on revokation (optional)
121          * - the key's semaphore will be write-locked by the caller
122          */
123         void (*revoke)(struct key *key);
124 
125         /* clear the data from a key (optional) */
126         void (*destroy)(struct key *key);
127 
128         /* describe a key */
129         void (*describe)(const struct key *key, struct seq_file *p);
130 
131         /* read a key's data (optional)
132          * - permission checks will be done by the caller
133          * - the key's semaphore will be readlocked by the caller
134          * - should return the amount of data that could be read, no matter how
135          *   much is copied into the buffer
136          * - shouldn't do the copy if the buffer is NULL
137          */
138         long (*read)(const struct key *key, char __user *buffer, size_t buflen);
139 
140         /* handle request_key() for this type instead of invoking
141          * /sbin/request-key (optional)
142          * - key is the key to instantiate
143          * - authkey is the authority to assume when instantiating this key
144          * - op is the operation to be done, usually "create"
145          * - the call must not return until the instantiation process has run
146          *   its course
147          */
148         request_key_actor_t request_key;
149 
150         /* internal fields */
151         struct list_head        link;           /* link in types list */
152         struct lock_class_key   lock_class;     /* key->sem lock class */
153 };
154 
155 extern struct key_type key_type_keyring;
156 
157 extern int register_key_type(struct key_type *ktype);
158 extern void unregister_key_type(struct key_type *ktype);
159 
160 extern int key_payload_reserve(struct key *key, size_t datalen);
161 extern int key_instantiate_and_link(struct key *key,
162                                     const void *data,
163                                     size_t datalen,
164                                     struct key *keyring,
165                                     struct key *instkey);
166 extern int key_reject_and_link(struct key *key,
167                                unsigned timeout,
168                                unsigned error,
169                                struct key *keyring,
170                                struct key *instkey);
171 extern void complete_request_key(struct key_construction *cons, int error);
172 
173 static inline int key_negate_and_link(struct key *key,
174                                       unsigned timeout,
175                                       struct key *keyring,
176                                       struct key *instkey)
177 {
178         return key_reject_and_link(key, timeout, ENOKEY, keyring, instkey);
179 }
180 
181 extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep);
182 
183 #endif /* CONFIG_KEYS */
184 #endif /* _LINUX_KEY_TYPE_H */
185 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp