summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Layton <jlayton@samba.org>2012-01-17 16:35:55 -0500
committerJeff Layton <jlayton@samba.org>2012-01-17 16:35:55 -0500
commitaed556765b5b7c42cee5107ab7fd657732e15df8 (patch)
tree87709cb9765a821d7e215b46d4d0562f9ce41bac
parent32238d0e8e0994b0614d31f6922c7bfa56ac74bc (diff)
downloadcifs-utils-aed556765b5b7c42cee5107ab7fd657732e15df8.tar.gz
cifs-utils-aed556765b5b7c42cee5107ab7fd657732e15df8.tar.bz2
cifs-utils-aed556765b5b7c42cee5107ab7fd657732e15df8.zip
cifscreds: make key_search use keyctl_search
...which is much more efficient than walking the keyring by hand. Signed-off-by: Jeff Layton <jlayton@samba.org>
-rw-r--r--cifscreds.c46
1 files changed, 1 insertions, 45 deletions
diff --git a/cifscreds.c b/cifscreds.c
index cc8df3f..3b6e9ee 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 */