So that it can be used from libsystemd. No external dependencies.
bufsize = (size_t) n;
}
}
+
+int keyring_describe(key_serial_t serial, char **ret) {
+ _cleanup_free_ char *tuple = NULL;
+ size_t sz = 64;
+ int c = -1; /* Workaround for maybe-uninitialized false positive due to missing_syscall indirection */
+
+ assert(ret);
+
+ for (;;) {
+ tuple = new(char, sz);
+ if (!tuple)
+ return log_oom_debug();
+
+ c = keyctl(KEYCTL_DESCRIBE, serial, (unsigned long) tuple, c, 0);
+ if (c < 0)
+ return log_debug_errno(errno, "Failed to describe key id %d: %m", serial);
+
+ if ((size_t) c <= sz)
+ break;
+
+ sz = c;
+ free(tuple);
+ }
+
+ /* The kernel returns a final NUL in the string, verify that. */
+ assert(tuple[c-1] == 0);
+
+ *ret = TAKE_PTR(tuple);
+
+ return 0;
+}
#define TAKE_KEY_SERIAL(key_serial) TAKE_GENERIC(key_serial, key_serial_t, -1)
int keyring_read(key_serial_t serial, void **ret, size_t *ret_size);
+int keyring_describe(key_serial_t serial, char **ret);
'lock-util.c',
'log.c',
'login-util.c',
+ 'keyring-util.c',
'memfd-util.c',
'memory-util.c',
'mempool.c',
#include "hmac.h"
#include "id128-util.h"
#include "io-util.h"
+#include "keyring-util.h"
#include "macro.h"
#include "missing_syscall.h"
#include "missing_threads.h"
char *d, *p, *g, *u, *e;
unsigned long perms;
key_serial_t key;
- size_t sz = 256;
uid_t uid;
gid_t gid;
int r, c;
return -errno;
}
- for (;;) {
- description = new(char, sz);
- if (!description)
- return -ENOMEM;
-
- c = keyctl(KEYCTL_DESCRIBE, key, (unsigned long) description, sz, 0);
- if (c < 0)
- return -errno;
-
- if ((size_t) c <= sz)
- break;
-
- sz = c;
- free(description);
- }
-
- /* The kernel returns a final NUL in the string, verify that. */
- assert(description[c-1] == 0);
+ r = keyring_describe(key, &description);
+ if (r < 0)
+ return r;
/* Chop off the final description string */
d = strrchr(description, ';');
'kbd-util.c',
'kernel-config.c',
'kernel-image.c',
- 'keyring-util.c',
'killall.c',
'label-util.c',
'libarchive-util.c',