diff options
author | David Howells <dhowells@redhat.com> | 2014-09-16 12:36:06 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2014-09-16 12:36:06 -0400 |
commit | c06cfb08b88dfbe13be44a69ae2fdc3a7c902d81 (patch) | |
tree | 8bc0e3794ffb426b3cbb2c0d7c2dbbd4b28e3054 /security | |
parent | 614d8c39014c185aa0f7254f0a470cc33fc1b284 (diff) |
KEYS: Remove key_type::match in favour of overriding default by match_preparse
A previous patch added a ->match_preparse() method to the key type. This is
allowed to override the function called by the iteration algorithm.
Therefore, we can just set a default that simply checks for an exact match of
the key description with the original criterion data and allow match_preparse
to override it as needed.
The key_type::match op is then redundant and can be removed, as can the
user_match() function.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/keys/big_key.c | 1 | ||||
-rw-r--r-- | security/keys/encrypted-keys/encrypted.c | 1 | ||||
-rw-r--r-- | security/keys/internal.h | 2 | ||||
-rw-r--r-- | security/keys/key.c | 2 | ||||
-rw-r--r-- | security/keys/keyring.c | 15 | ||||
-rw-r--r-- | security/keys/request_key.c | 2 | ||||
-rw-r--r-- | security/keys/request_key_auth.c | 2 | ||||
-rw-r--r-- | security/keys/trusted.c | 1 | ||||
-rw-r--r-- | security/keys/user_defined.c | 12 |
9 files changed, 15 insertions, 23 deletions
diff --git a/security/keys/big_key.c b/security/keys/big_key.c index 4045c13a761a..b6adb94f6d52 100644 --- a/security/keys/big_key.c +++ b/security/keys/big_key.c | |||
@@ -36,7 +36,6 @@ struct key_type key_type_big_key = { | |||
36 | .preparse = big_key_preparse, | 36 | .preparse = big_key_preparse, |
37 | .free_preparse = big_key_free_preparse, | 37 | .free_preparse = big_key_free_preparse, |
38 | .instantiate = generic_key_instantiate, | 38 | .instantiate = generic_key_instantiate, |
39 | .match = user_match, | ||
40 | .revoke = big_key_revoke, | 39 | .revoke = big_key_revoke, |
41 | .destroy = big_key_destroy, | 40 | .destroy = big_key_destroy, |
42 | .describe = big_key_describe, | 41 | .describe = big_key_describe, |
diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c index 5fe443d120af..db9675db1026 100644 --- a/security/keys/encrypted-keys/encrypted.c +++ b/security/keys/encrypted-keys/encrypted.c | |||
@@ -970,7 +970,6 @@ struct key_type key_type_encrypted = { | |||
970 | .name = "encrypted", | 970 | .name = "encrypted", |
971 | .instantiate = encrypted_instantiate, | 971 | .instantiate = encrypted_instantiate, |
972 | .update = encrypted_update, | 972 | .update = encrypted_update, |
973 | .match = user_match, | ||
974 | .destroy = encrypted_destroy, | 973 | .destroy = encrypted_destroy, |
975 | .describe = user_describe, | 974 | .describe = user_describe, |
976 | .read = encrypted_read, | 975 | .read = encrypted_read, |
diff --git a/security/keys/internal.h b/security/keys/internal.h index b47cc532be1e..e66a16cb63e1 100644 --- a/security/keys/internal.h +++ b/security/keys/internal.h | |||
@@ -127,6 +127,8 @@ struct keyring_search_context { | |||
127 | struct timespec now; | 127 | struct timespec now; |
128 | }; | 128 | }; |
129 | 129 | ||
130 | extern int key_default_cmp(const struct key *key, | ||
131 | const struct key_match_data *match_data); | ||
130 | extern key_ref_t keyring_search_aux(key_ref_t keyring_ref, | 132 | extern key_ref_t keyring_search_aux(key_ref_t keyring_ref, |
131 | struct keyring_search_context *ctx); | 133 | struct keyring_search_context *ctx); |
132 | 134 | ||
diff --git a/security/keys/key.c b/security/keys/key.c index b90a68c4e2c4..8c0092ca0443 100644 --- a/security/keys/key.c +++ b/security/keys/key.c | |||
@@ -799,7 +799,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref, | |||
799 | } | 799 | } |
800 | 800 | ||
801 | key_ref = ERR_PTR(-EINVAL); | 801 | key_ref = ERR_PTR(-EINVAL); |
802 | if (!index_key.type->match || !index_key.type->instantiate || | 802 | if (!index_key.type->instantiate || |
803 | (!index_key.description && !index_key.type->preparse)) | 803 | (!index_key.description && !index_key.type->preparse)) |
804 | goto error_put_type; | 804 | goto error_put_type; |
805 | 805 | ||
diff --git a/security/keys/keyring.c b/security/keys/keyring.c index 10f0a5f2d362..253c9a0eb092 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c | |||
@@ -89,7 +89,6 @@ struct key_type key_type_keyring = { | |||
89 | .preparse = keyring_preparse, | 89 | .preparse = keyring_preparse, |
90 | .free_preparse = keyring_free_preparse, | 90 | .free_preparse = keyring_free_preparse, |
91 | .instantiate = keyring_instantiate, | 91 | .instantiate = keyring_instantiate, |
92 | .match = user_match, | ||
93 | .revoke = keyring_revoke, | 92 | .revoke = keyring_revoke, |
94 | .destroy = keyring_destroy, | 93 | .destroy = keyring_destroy, |
95 | .describe = keyring_describe, | 94 | .describe = keyring_describe, |
@@ -512,6 +511,15 @@ struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid, | |||
512 | EXPORT_SYMBOL(keyring_alloc); | 511 | EXPORT_SYMBOL(keyring_alloc); |
513 | 512 | ||
514 | /* | 513 | /* |
514 | * By default, we keys found by getting an exact match on their descriptions. | ||
515 | */ | ||
516 | int key_default_cmp(const struct key *key, | ||
517 | const struct key_match_data *match_data) | ||
518 | { | ||
519 | return strcmp(key->description, match_data->raw_data) == 0; | ||
520 | } | ||
521 | |||
522 | /* | ||
515 | * Iteration function to consider each key found. | 523 | * Iteration function to consider each key found. |
516 | */ | 524 | */ |
517 | static int keyring_search_iterator(const void *object, void *iterator_data) | 525 | static int keyring_search_iterator(const void *object, void *iterator_data) |
@@ -884,7 +892,7 @@ key_ref_t keyring_search(key_ref_t keyring, | |||
884 | .index_key.type = type, | 892 | .index_key.type = type, |
885 | .index_key.description = description, | 893 | .index_key.description = description, |
886 | .cred = current_cred(), | 894 | .cred = current_cred(), |
887 | .match_data.cmp = type->match, | 895 | .match_data.cmp = key_default_cmp, |
888 | .match_data.raw_data = description, | 896 | .match_data.raw_data = description, |
889 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, | 897 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, |
890 | .flags = KEYRING_SEARCH_DO_STATE_CHECK, | 898 | .flags = KEYRING_SEARCH_DO_STATE_CHECK, |
@@ -892,9 +900,6 @@ key_ref_t keyring_search(key_ref_t keyring, | |||
892 | key_ref_t key; | 900 | key_ref_t key; |
893 | int ret; | 901 | int ret; |
894 | 902 | ||
895 | if (!ctx.match_data.cmp) | ||
896 | return ERR_PTR(-ENOKEY); | ||
897 | |||
898 | if (type->match_preparse) { | 903 | if (type->match_preparse) { |
899 | ret = type->match_preparse(&ctx.match_data); | 904 | ret = type->match_preparse(&ctx.match_data); |
900 | if (ret < 0) | 905 | if (ret < 0) |
diff --git a/security/keys/request_key.c b/security/keys/request_key.c index 408523e5e2e2..dc6ed32b7844 100644 --- a/security/keys/request_key.c +++ b/security/keys/request_key.c | |||
@@ -531,7 +531,7 @@ struct key *request_key_and_link(struct key_type *type, | |||
531 | .index_key.type = type, | 531 | .index_key.type = type, |
532 | .index_key.description = description, | 532 | .index_key.description = description, |
533 | .cred = current_cred(), | 533 | .cred = current_cred(), |
534 | .match_data.cmp = type->match, | 534 | .match_data.cmp = key_default_cmp, |
535 | .match_data.raw_data = description, | 535 | .match_data.raw_data = description, |
536 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, | 536 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, |
537 | }; | 537 | }; |
diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c index 9ae02819cc06..6639e2cb8853 100644 --- a/security/keys/request_key_auth.c +++ b/security/keys/request_key_auth.c | |||
@@ -246,7 +246,7 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id) | |||
246 | .index_key.type = &key_type_request_key_auth, | 246 | .index_key.type = &key_type_request_key_auth, |
247 | .index_key.description = description, | 247 | .index_key.description = description, |
248 | .cred = current_cred(), | 248 | .cred = current_cred(), |
249 | .match_data.cmp = user_match, | 249 | .match_data.cmp = key_default_cmp, |
250 | .match_data.raw_data = description, | 250 | .match_data.raw_data = description, |
251 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, | 251 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, |
252 | }; | 252 | }; |
diff --git a/security/keys/trusted.c b/security/keys/trusted.c index 6b804aa4529a..c0594cb07ada 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c | |||
@@ -1096,7 +1096,6 @@ struct key_type key_type_trusted = { | |||
1096 | .name = "trusted", | 1096 | .name = "trusted", |
1097 | .instantiate = trusted_instantiate, | 1097 | .instantiate = trusted_instantiate, |
1098 | .update = trusted_update, | 1098 | .update = trusted_update, |
1099 | .match = user_match, | ||
1100 | .destroy = trusted_destroy, | 1099 | .destroy = trusted_destroy, |
1101 | .describe = user_describe, | 1100 | .describe = user_describe, |
1102 | .read = trusted_read, | 1101 | .read = trusted_read, |
diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c index cd7e726e8646..36b47bbd3d8c 100644 --- a/security/keys/user_defined.c +++ b/security/keys/user_defined.c | |||
@@ -30,7 +30,6 @@ struct key_type key_type_user = { | |||
30 | .free_preparse = user_free_preparse, | 30 | .free_preparse = user_free_preparse, |
31 | .instantiate = generic_key_instantiate, | 31 | .instantiate = generic_key_instantiate, |
32 | .update = user_update, | 32 | .update = user_update, |
33 | .match = user_match, | ||
34 | .revoke = user_revoke, | 33 | .revoke = user_revoke, |
35 | .destroy = user_destroy, | 34 | .destroy = user_destroy, |
36 | .describe = user_describe, | 35 | .describe = user_describe, |
@@ -51,7 +50,6 @@ struct key_type key_type_logon = { | |||
51 | .free_preparse = user_free_preparse, | 50 | .free_preparse = user_free_preparse, |
52 | .instantiate = generic_key_instantiate, | 51 | .instantiate = generic_key_instantiate, |
53 | .update = user_update, | 52 | .update = user_update, |
54 | .match = user_match, | ||
55 | .revoke = user_revoke, | 53 | .revoke = user_revoke, |
56 | .destroy = user_destroy, | 54 | .destroy = user_destroy, |
57 | .describe = user_describe, | 55 | .describe = user_describe, |
@@ -137,16 +135,6 @@ error: | |||
137 | EXPORT_SYMBOL_GPL(user_update); | 135 | EXPORT_SYMBOL_GPL(user_update); |
138 | 136 | ||
139 | /* | 137 | /* |
140 | * match users on their name | ||
141 | */ | ||
142 | int user_match(const struct key *key, const struct key_match_data *match_data) | ||
143 | { | ||
144 | return strcmp(key->description, match_data->raw_data) == 0; | ||
145 | } | ||
146 | |||
147 | EXPORT_SYMBOL_GPL(user_match); | ||
148 | |||
149 | /* | ||
150 | * dispose of the links from a revoked keyring | 138 | * dispose of the links from a revoked keyring |
151 | * - called with the key sem write-locked | 139 | * - called with the key sem write-locked |
152 | */ | 140 | */ |