Add provisional support for persistent keyrings

This commit is contained in:
David Howells 2013-09-23 15:45:43 +01:00
parent beb130ec12
commit 9967c36d47
2 changed files with 107 additions and 1 deletions

101
get-persist.patch Normal file
View File

@ -0,0 +1,101 @@
commit 91252c4e97c19cb6a4cfd2b62980402274cef607
Author: David Howells <dhowells@redhat.com>
Date: Thu Aug 1 15:12:30 2013 +0100
Add per-UID get-persistent keyring function
diff --git a/keyctl.c b/keyctl.c
index a137e08..dd481a4 100644
--- a/keyctl.c
+++ b/keyctl.c
@@ -63,6 +63,7 @@ static int act_keyctl_reject(int argc, char *argv[]);
static int act_keyctl_reap(int argc, char *argv[]);
static int act_keyctl_purge(int argc, char *argv[]);
static int act_keyctl_invalidate(int argc, char *argv[]);
+static int act_keyctl_get_persistent(int argc, char *argv[]);
const struct command commands[] = {
{ act_keyctl___version, "--version", "" },
@@ -73,6 +74,7 @@ const struct command commands[] = {
{ act_keyctl_describe, "describe", "<keyring>" },
{ act_keyctl_instantiate, "instantiate","<key> <data> <keyring>" },
{ act_keyctl_invalidate,"invalidate", "<key>" },
+ { act_keyctl_get_persistent, "get_persistent", "<keyring> [<uid>]" },
{ act_keyctl_link, "link", "<key> <keyring>" },
{ act_keyctl_list, "list", "<keyring>" },
{ act_keyctl_negate, "negate", "<key> <timeout> <keyring>" },
@@ -1575,6 +1577,38 @@ static int act_keyctl_invalidate(int argc, char *argv[])
/*****************************************************************************/
/*
+ * Get the per-UID persistent keyring
+ */
+static int act_keyctl_get_persistent(int argc, char *argv[])
+{
+ key_serial_t dest, ret;
+ uid_t uid = -1;
+ char *q;
+
+ if (argc != 2 && argc != 3)
+ format();
+
+ dest = get_key_id(argv[1]);
+
+ if (argc > 2) {
+ uid = strtoul(argv[2], &q, 0);
+ if (*q) {
+ fprintf(stderr, "Unparsable uid: '%s'\n", argv[2]);
+ exit(2);
+ }
+ }
+
+ ret = keyctl_get_persistent(uid, dest);
+ if (ret < 0)
+ error("keyctl_get_persistent");
+
+ /* print the resulting key ID */
+ printf("%d\n", ret);
+ return 0;
+}
+
+/*****************************************************************************/
+/*
* parse a key identifier
*/
static key_serial_t get_key_id(const char *arg)
diff --git a/keyutils.c b/keyutils.c
index 329bfae..060674e 100644
--- a/keyutils.c
+++ b/keyutils.c
@@ -229,6 +229,11 @@ long keyctl_invalidate(key_serial_t id)
return keyctl(KEYCTL_INVALIDATE, id);
}
+long keyctl_get_persistent(uid_t uid, key_serial_t id)
+{
+ return keyctl(KEYCTL_GET_PERSISTENT, uid, id);
+}
+
/*****************************************************************************/
/*
* fetch key description into an allocated buffer
diff --git a/keyutils.h b/keyutils.h
index 3ddaeae..49126f7 100644
--- a/keyutils.h
+++ b/keyutils.h
@@ -97,6 +97,7 @@ typedef uint32_t key_perm_t;
#define KEYCTL_REJECT 19 /* reject a partially constructed key */
#define KEYCTL_INSTANTIATE_IOV 20 /* instantiate a partially constructed key */
#define KEYCTL_INVALIDATE 21 /* invalidate a key */
+#define KEYCTL_GET_PERSISTENT 22 /* get a user's persistent keyring */
/*
* syscall wrappers
@@ -150,6 +151,7 @@ extern long keyctl_instantiate_iov(key_serial_t id,
unsigned ioc,
key_serial_t ringid);
extern long keyctl_invalidate(key_serial_t id);
+extern long keyctl_get_persistent(uid_t uid, key_serial_t id);
/*
* utilities

View File

@ -11,13 +11,14 @@
Summary: Linux Key Management Utilities Summary: Linux Key Management Utilities
Name: keyutils Name: keyutils
Version: %{version} Version: %{version}
Release: 1%{?buildid}%{?dist} Release: 2%{?buildid}%{?dist}
License: GPLv2+ and LGPLv2+ License: GPLv2+ and LGPLv2+
Group: System Environment/Base Group: System Environment/Base
ExclusiveOS: Linux ExclusiveOS: Linux
Url: http://people.redhat.com/~dhowells/keyutils/ Url: http://people.redhat.com/~dhowells/keyutils/
Source0: http://people.redhat.com/~dhowells/keyutils/keyutils-%{version}.tar.bz2 Source0: http://people.redhat.com/~dhowells/keyutils/keyutils-%{version}.tar.bz2
Patch1: get-persist.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: glibc-kernheaders >= 2.4-9.1.92 BuildRequires: glibc-kernheaders >= 2.4-9.1.92
@ -46,6 +47,7 @@ This package provides headers and libraries for building key utilities.
%prep %prep
%setup -q %setup -q
%patch1 -p1
%build %build
make \ make \
@ -95,6 +97,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man3/* %{_mandir}/man3/*
%changelog %changelog
* Mon Sep 23 2013 David Howells <dhowells@redhat.com> - 1.5.6-2
- Add provisional support for persistent keyrings.
* Thu Aug 29 2013 David Howells <dhowells@redhat.com> - 1.5.6-1 * Thu Aug 29 2013 David Howells <dhowells@redhat.com> - 1.5.6-1
- Fix the request-key.conf.5 manpage. - Fix the request-key.conf.5 manpage.
- Fix the max depth of key tree dump (keyctl show). - Fix the max depth of key tree dump (keyctl show).