|
|
44b0f8 |
From d4c22fcd5943fe35db648dee971f631d40b3eb94 Mon Sep 17 00:00:00 2001
|
|
|
44b0f8 |
From: Stephen Smalley <sds@tycho.nsa.gov>
|
|
|
44b0f8 |
Date: Thu, 20 Feb 2020 10:40:19 -0500
|
|
|
44b0f8 |
Subject: [PATCH] libselinux: deprecate security_compute_user(), update man
|
|
|
44b0f8 |
pages
|
|
|
44b0f8 |
|
|
|
44b0f8 |
commit 1f89c4e7879fcf6da5d8d1b025dcc03371f30fc9 ("libselinux: Eliminate
|
|
|
44b0f8 |
use of security_compute_user()") eliminated the use of
|
|
|
44b0f8 |
security_compute_user() by get_ordered_context_list(). Deprecate
|
|
|
44b0f8 |
all use of security_compute_user() by updating the headers and man
|
|
|
44b0f8 |
pages and logging a warning message on any calls to it. Remove
|
|
|
44b0f8 |
the example utility that called the interface. While here, also
|
|
|
44b0f8 |
fix the documentation of correct usage of the user argument to these
|
|
|
44b0f8 |
interfaces.
|
|
|
44b0f8 |
|
|
|
44b0f8 |
Fixes: https://github.com/SELinuxProject/selinux/issues/70
|
|
|
44b0f8 |
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
|
|
|
44b0f8 |
Acked-by: Petr Lautrbach <plautrba@redhat.com>
|
|
|
44b0f8 |
---
|
|
|
44b0f8 |
libselinux/include/selinux/selinux.h | 8 +++-
|
|
|
44b0f8 |
.../man/man3/get_ordered_context_list.3 | 24 +++++++++---
|
|
|
44b0f8 |
libselinux/man/man3/security_compute_av.3 | 5 ++-
|
|
|
44b0f8 |
libselinux/src/compute_user.c | 3 ++
|
|
|
44b0f8 |
libselinux/utils/compute_user.c | 38 -------------------
|
|
|
44b0f8 |
5 files changed, 31 insertions(+), 47 deletions(-)
|
|
|
44b0f8 |
delete mode 100644 libselinux/utils/compute_user.c
|
|
|
44b0f8 |
|
|
|
44b0f8 |
diff --git a/libselinux/include/selinux/selinux.h b/libselinux/include/selinux/selinux.h
|
|
|
44b0f8 |
index a34d54fc..a5ada324 100644
|
|
|
44b0f8 |
--- a/libselinux/include/selinux/selinux.h
|
|
|
44b0f8 |
+++ b/libselinux/include/selinux/selinux.h
|
|
|
44b0f8 |
@@ -246,8 +246,12 @@ extern int security_compute_member_raw(const char * scon,
|
|
|
44b0f8 |
security_class_t tclass,
|
|
|
44b0f8 |
char ** newcon);
|
|
|
44b0f8 |
|
|
|
44b0f8 |
-/* Compute the set of reachable user contexts and set *con to refer to
|
|
|
44b0f8 |
- the NULL-terminated array of contexts. Caller must free via freeconary. */
|
|
|
44b0f8 |
+/*
|
|
|
44b0f8 |
+ * Compute the set of reachable user contexts and set *con to refer to
|
|
|
44b0f8 |
+ * the NULL-terminated array of contexts. Caller must free via freeconary.
|
|
|
44b0f8 |
+ * These interfaces are deprecated. Use get_ordered_context_list() or
|
|
|
44b0f8 |
+ * one of its variant interfaces instead.
|
|
|
44b0f8 |
+ */
|
|
|
44b0f8 |
extern int security_compute_user(const char * scon,
|
|
|
44b0f8 |
const char *username,
|
|
|
44b0f8 |
char *** con);
|
|
|
44b0f8 |
diff --git a/libselinux/man/man3/get_ordered_context_list.3 b/libselinux/man/man3/get_ordered_context_list.3
|
|
|
44b0f8 |
index e084da40..3ed14a96 100644
|
|
|
44b0f8 |
--- a/libselinux/man/man3/get_ordered_context_list.3
|
|
|
44b0f8 |
+++ b/libselinux/man/man3/get_ordered_context_list.3
|
|
|
44b0f8 |
@@ -26,14 +26,28 @@ get_ordered_context_list, get_ordered_context_list_with_level, get_default_conte
|
|
|
44b0f8 |
.BI "int get_default_type(const char *" role ", char **" type );
|
|
|
44b0f8 |
.
|
|
|
44b0f8 |
.SH "DESCRIPTION"
|
|
|
44b0f8 |
+
|
|
|
44b0f8 |
+This family of functions can be used to obtain either a prioritized list of
|
|
|
44b0f8 |
+all reachable security contexts for a given SELinux user or a single default
|
|
|
44b0f8 |
+(highest priority) context for a given SELinux user for use by login-like
|
|
|
44b0f8 |
+programs. These functions takes a SELinux user identity that must
|
|
|
44b0f8 |
+be defined in the SELinux policy as their input, not a Linux username.
|
|
|
44b0f8 |
+Most callers should typically first call
|
|
|
44b0f8 |
+.BR getseuserbyname(3)
|
|
|
44b0f8 |
+to look up the SELinux user identity and level for a given
|
|
|
44b0f8 |
+Linux username and then invoke one of
|
|
|
44b0f8 |
+.BR get_ordered_context_list_with_level ()
|
|
|
44b0f8 |
+or
|
|
|
44b0f8 |
+.BR get_default_context_with_level ()
|
|
|
44b0f8 |
+with the returned SELinux user and level as inputs.
|
|
|
44b0f8 |
+
|
|
|
44b0f8 |
.BR get_ordered_context_list ()
|
|
|
44b0f8 |
-invokes the
|
|
|
44b0f8 |
-.BR security_compute_user (3)
|
|
|
44b0f8 |
-function to obtain the list of contexts for the specified
|
|
|
44b0f8 |
+obtains the list of contexts for the specified
|
|
|
44b0f8 |
+SELinux
|
|
|
44b0f8 |
.I user
|
|
|
44b0f8 |
-that are reachable from the specified
|
|
|
44b0f8 |
+identity that are reachable from the specified
|
|
|
44b0f8 |
.I fromcon
|
|
|
44b0f8 |
-context. The function then orders the resulting list based on the global
|
|
|
44b0f8 |
+context based on the global
|
|
|
44b0f8 |
.I \%/etc/selinux/{SELINUXTYPE}/contexts/default_contexts
|
|
|
44b0f8 |
file and the per-user
|
|
|
44b0f8 |
.I \%/etc/selinux/{SELINUXTYPE}/contexts/users/<username>
|
|
|
44b0f8 |
diff --git a/libselinux/man/man3/security_compute_av.3 b/libselinux/man/man3/security_compute_av.3
|
|
|
44b0f8 |
index 2aade5fe..8e1f746a 100644
|
|
|
44b0f8 |
--- a/libselinux/man/man3/security_compute_av.3
|
|
|
44b0f8 |
+++ b/libselinux/man/man3/security_compute_av.3
|
|
|
44b0f8 |
@@ -97,8 +97,9 @@ instance.
|
|
|
44b0f8 |
|
|
|
44b0f8 |
.BR security_compute_user ()
|
|
|
44b0f8 |
is used to determine the set of user contexts that can be reached from a
|
|
|
44b0f8 |
-source context. It is mainly used by
|
|
|
44b0f8 |
-.BR get_ordered_context_list ().
|
|
|
44b0f8 |
+source context. This function is deprecated; use
|
|
|
44b0f8 |
+.BR get_ordered_context_list (3)
|
|
|
44b0f8 |
+instead.
|
|
|
44b0f8 |
|
|
|
44b0f8 |
.BR security_get_initial_context ()
|
|
|
44b0f8 |
is used to get the context of a kernel initial security identifier specified by
|
|
|
44b0f8 |
diff --git a/libselinux/src/compute_user.c b/libselinux/src/compute_user.c
|
|
|
44b0f8 |
index 401fd107..0f55de84 100644
|
|
|
44b0f8 |
--- a/libselinux/src/compute_user.c
|
|
|
44b0f8 |
+++ b/libselinux/src/compute_user.c
|
|
|
44b0f8 |
@@ -8,6 +8,7 @@
|
|
|
44b0f8 |
#include "selinux_internal.h"
|
|
|
44b0f8 |
#include "policy.h"
|
|
|
44b0f8 |
#include <limits.h>
|
|
|
44b0f8 |
+#include "callbacks.h"
|
|
|
44b0f8 |
|
|
|
44b0f8 |
int security_compute_user_raw(const char * scon,
|
|
|
44b0f8 |
const char *user, char *** con)
|
|
|
44b0f8 |
@@ -24,6 +25,8 @@ int security_compute_user_raw(const char * scon,
|
|
|
44b0f8 |
return -1;
|
|
|
44b0f8 |
}
|
|
|
44b0f8 |
|
|
|
44b0f8 |
+ selinux_log(SELINUX_WARNING, "Direct use of security_compute_user() is deprecated, switch to get_ordered_context_list()\n");
|
|
|
44b0f8 |
+
|
|
|
44b0f8 |
if (! scon) {
|
|
|
44b0f8 |
errno=EINVAL;
|
|
|
44b0f8 |
return -1;
|
|
|
44b0f8 |
diff --git a/libselinux/utils/compute_user.c b/libselinux/utils/compute_user.c
|
|
|
44b0f8 |
deleted file mode 100644
|
|
|
44b0f8 |
index cae62b26..00000000
|
|
|
44b0f8 |
--- a/libselinux/utils/compute_user.c
|
|
|
44b0f8 |
+++ /dev/null
|
|
|
44b0f8 |
@@ -1,38 +0,0 @@
|
|
|
44b0f8 |
-#include <unistd.h>
|
|
|
44b0f8 |
-#include <sys/types.h>
|
|
|
44b0f8 |
-#include <fcntl.h>
|
|
|
44b0f8 |
-#include <stdio.h>
|
|
|
44b0f8 |
-#include <stdlib.h>
|
|
|
44b0f8 |
-#include <errno.h>
|
|
|
44b0f8 |
-#include <string.h>
|
|
|
44b0f8 |
-#include <ctype.h>
|
|
|
44b0f8 |
-#include <selinux/selinux.h>
|
|
|
44b0f8 |
-
|
|
|
44b0f8 |
-int main(int argc, char **argv)
|
|
|
44b0f8 |
-{
|
|
|
44b0f8 |
- char **buf, **ptr;
|
|
|
44b0f8 |
- int ret;
|
|
|
44b0f8 |
-
|
|
|
44b0f8 |
- if (argc != 3) {
|
|
|
44b0f8 |
- fprintf(stderr, "usage: %s context user\n", argv[0]);
|
|
|
44b0f8 |
- exit(1);
|
|
|
44b0f8 |
- }
|
|
|
44b0f8 |
-
|
|
|
44b0f8 |
- ret = security_compute_user(argv[1], argv[2], &buf;;
|
|
|
44b0f8 |
- if (ret < 0) {
|
|
|
44b0f8 |
- fprintf(stderr, "%s: security_compute_user(%s,%s) failed\n",
|
|
|
44b0f8 |
- argv[0], argv[1], argv[2]);
|
|
|
44b0f8 |
- exit(2);
|
|
|
44b0f8 |
- }
|
|
|
44b0f8 |
-
|
|
|
44b0f8 |
- if (!buf[0]) {
|
|
|
44b0f8 |
- printf("none\n");
|
|
|
44b0f8 |
- exit(0);
|
|
|
44b0f8 |
- }
|
|
|
44b0f8 |
-
|
|
|
44b0f8 |
- for (ptr = buf; *ptr; ptr++) {
|
|
|
44b0f8 |
- printf("%s\n", *ptr);
|
|
|
44b0f8 |
- }
|
|
|
44b0f8 |
- freeconary(buf);
|
|
|
44b0f8 |
- exit(0);
|
|
|
44b0f8 |
-}
|
|
|
44b0f8 |
--
|
|
|
44b0f8 |
2.25.4
|
|
|
44b0f8 |
|