...which is much more efficient than walking the keyring by hand.
Signed-off-by: Jeff Layton <[email protected]>
---
cifscreds.c | 46 +---------------------------------------------
1 files changed, 1 insertions(+), 45 deletions(-)
diff --git a/cifscreds.c b/cifscreds.c
index 5c5b578..64da070 100644
--- a/cifscreds.c
+++ b/cifscreds.c
@@ -109,54 +109,10 @@ static key_serial_t
key_search(const char *addr, char keytype)
{
char desc[INET6_ADDRSTRLEN + sizeof(THIS_PROGRAM_NAME) + 4];
- key_serial_t key, *pk;
- void *keylist;
- char *buffer;
- int count, dpos, n, ret;
sprintf(desc, "%s:%c:%s", THIS_PROGRAM_NAME, keytype, addr);
- /* read the key payload data */
- count = keyctl_read_alloc(DEST_KEYRING, &keylist);
- if (count < 0)
- return 0;
-
- count /= sizeof(key_serial_t);
-
- if (count == 0) {
- ret = 0;
- goto key_search_out;
- }
-
- /* list the keys in the keyring */
- pk = keylist;
- do {
- key = *pk++;
-
- ret = keyctl_describe_alloc(key, &buffer);
- if (ret < 0)
- continue;
-
- n = sscanf(buffer, "%*[^;];%*d;%*d;%*x;%n", &dpos);
- if (n) {
- free(buffer);
- continue;
- }
-
- if (!strcmp(buffer + dpos, desc)) {
- ret = key;
- free(buffer);
- goto key_search_out;
- }
- free(buffer);
-
- } while (--count);
-
- ret = 0;
-
-key_search_out:
- free(keylist);
- return ret;
+ return keyctl_search(DEST_KEYRING, CIFS_KEY_TYPE, desc, 0);
}
/* search all program's keys in keyring */
--
1.7.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html