Commit f9167789 authored by David Howells's avatar David Howells

KEYS: user: Use key preparsing

Make use of key preparsing in user-defined and logon keys so that quota size
determination can take place prior to keyring locking when a key is being
added.

Also the idmapper key types need to change to match as they use the
user-defined key type routines.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarSteve Dickson <steved@redhat.com>
Acked-by: default avatarJeff Layton <jlayton@primarydata.com>
parent 4d8c0250
...@@ -174,7 +174,9 @@ static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen) ...@@ -174,7 +174,9 @@ static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen)
static struct key_type key_type_id_resolver = { static struct key_type key_type_id_resolver = {
.name = "id_resolver", .name = "id_resolver",
.instantiate = user_instantiate, .preparse = user_preparse,
.free_preparse = user_free_preparse,
.instantiate = generic_key_instantiate,
.match = user_match, .match = user_match,
.revoke = user_revoke, .revoke = user_revoke,
.destroy = user_destroy, .destroy = user_destroy,
...@@ -394,7 +396,9 @@ static const struct rpc_pipe_ops idmap_upcall_ops = { ...@@ -394,7 +396,9 @@ static const struct rpc_pipe_ops idmap_upcall_ops = {
static struct key_type key_type_id_resolver_legacy = { static struct key_type key_type_id_resolver_legacy = {
.name = "id_legacy", .name = "id_legacy",
.instantiate = user_instantiate, .preparse = user_preparse,
.free_preparse = user_free_preparse,
.instantiate = generic_key_instantiate,
.match = user_match, .match = user_match,
.revoke = user_revoke, .revoke = user_revoke,
.destroy = user_destroy, .destroy = user_destroy,
......
...@@ -37,7 +37,8 @@ extern struct key_type key_type_logon; ...@@ -37,7 +37,8 @@ extern struct key_type key_type_logon;
struct key_preparsed_payload; struct key_preparsed_payload;
extern int user_instantiate(struct key *key, struct key_preparsed_payload *prep); extern int user_preparse(struct key_preparsed_payload *prep);
extern void user_free_preparse(struct key_preparsed_payload *prep);
extern int user_update(struct key *key, struct key_preparsed_payload *prep); extern int user_update(struct key *key, struct key_preparsed_payload *prep);
extern int user_match(const struct key *key, const void *criterion); extern int user_match(const struct key *key, const void *criterion);
extern void user_revoke(struct key *key); extern void user_revoke(struct key *key);
......
...@@ -27,7 +27,9 @@ static int logon_vet_description(const char *desc); ...@@ -27,7 +27,9 @@ static int logon_vet_description(const char *desc);
struct key_type key_type_user = { struct key_type key_type_user = {
.name = "user", .name = "user",
.def_lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, .def_lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT,
.instantiate = user_instantiate, .preparse = user_preparse,
.free_preparse = user_free_preparse,
.instantiate = generic_key_instantiate,
.update = user_update, .update = user_update,
.match = user_match, .match = user_match,
.revoke = user_revoke, .revoke = user_revoke,
...@@ -47,7 +49,9 @@ EXPORT_SYMBOL_GPL(key_type_user); ...@@ -47,7 +49,9 @@ EXPORT_SYMBOL_GPL(key_type_user);
struct key_type key_type_logon = { struct key_type key_type_logon = {
.name = "logon", .name = "logon",
.def_lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, .def_lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT,
.instantiate = user_instantiate, .preparse = user_preparse,
.free_preparse = user_free_preparse,
.instantiate = generic_key_instantiate,
.update = user_update, .update = user_update,
.match = user_match, .match = user_match,
.revoke = user_revoke, .revoke = user_revoke,
...@@ -58,38 +62,37 @@ struct key_type key_type_logon = { ...@@ -58,38 +62,37 @@ struct key_type key_type_logon = {
EXPORT_SYMBOL_GPL(key_type_logon); EXPORT_SYMBOL_GPL(key_type_logon);
/* /*
* instantiate a user defined key * Preparse a user defined key payload
*/ */
int user_instantiate(struct key *key, struct key_preparsed_payload *prep) int user_preparse(struct key_preparsed_payload *prep)
{ {
struct user_key_payload *upayload; struct user_key_payload *upayload;
size_t datalen = prep->datalen; size_t datalen = prep->datalen;
int ret;
ret = -EINVAL;
if (datalen <= 0 || datalen > 32767 || !prep->data) if (datalen <= 0 || datalen > 32767 || !prep->data)
goto error; return -EINVAL;
ret = key_payload_reserve(key, datalen);
if (ret < 0)
goto error;
ret = -ENOMEM;
upayload = kmalloc(sizeof(*upayload) + datalen, GFP_KERNEL); upayload = kmalloc(sizeof(*upayload) + datalen, GFP_KERNEL);
if (!upayload) if (!upayload)
goto error; return -ENOMEM;
/* attach the data */ /* attach the data */
prep->quotalen = datalen;
prep->payload[0] = upayload;
upayload->datalen = datalen; upayload->datalen = datalen;
memcpy(upayload->data, prep->data, datalen); memcpy(upayload->data, prep->data, datalen);
rcu_assign_keypointer(key, upayload); return 0;
ret = 0;
error:
return ret;
} }
EXPORT_SYMBOL_GPL(user_preparse);
EXPORT_SYMBOL_GPL(user_instantiate); /*
* Free a preparse of a user defined key payload
*/
void user_free_preparse(struct key_preparsed_payload *prep)
{
kfree(prep->payload[0]);
}
EXPORT_SYMBOL_GPL(user_free_preparse);
/* /*
* update a user defined key * update a user defined key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment