summaryrefslogtreecommitdiff
path: root/openbsd-compat/port-linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/port-linux.c')
-rw-r--r--openbsd-compat/port-linux.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c
index 89b9a7340..c0ac9065e 100644
--- a/openbsd-compat/port-linux.c
+++ b/openbsd-compat/port-linux.c
@@ -29,6 +29,12 @@
29#include <string.h> 29#include <string.h>
30#include <stdio.h> 30#include <stdio.h>
31 31
32#ifdef WITH_SELINUX
33#include "key.h"
34#include "hostfile.h"
35#include "auth.h"
36#endif
37
32#include "log.h" 38#include "log.h"
33#include "xmalloc.h" 39#include "xmalloc.h"
34#include "port-linux.h" 40#include "port-linux.h"
@@ -38,6 +44,8 @@
38#include <selinux/flask.h> 44#include <selinux/flask.h>
39#include <selinux/get_context_list.h> 45#include <selinux/get_context_list.h>
40 46
47extern Authctxt *the_authctxt;
48
41/* Wrapper around is_selinux_enabled() to log its return value once only */ 49/* Wrapper around is_selinux_enabled() to log its return value once only */
42int 50int
43ssh_selinux_enabled(void) 51ssh_selinux_enabled(void)
@@ -56,8 +64,8 @@ ssh_selinux_enabled(void)
56static security_context_t 64static security_context_t
57ssh_selinux_getctxbyname(char *pwname) 65ssh_selinux_getctxbyname(char *pwname)
58{ 66{
59 security_context_t sc; 67 security_context_t sc = NULL;
60 char *sename = NULL, *lvl = NULL; 68 char *sename = NULL, *role = NULL, *lvl = NULL;
61 int r; 69 int r;
62 70
63#ifdef HAVE_GETSEUSERBYNAME 71#ifdef HAVE_GETSEUSERBYNAME
@@ -67,11 +75,20 @@ ssh_selinux_getctxbyname(char *pwname)
67 sename = pwname; 75 sename = pwname;
68 lvl = NULL; 76 lvl = NULL;
69#endif 77#endif
78 if (the_authctxt)
79 role = the_authctxt->role;
70 80
71#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL 81#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
72 r = get_default_context_with_level(sename, lvl, NULL, &sc); 82 if (role != NULL && role[0])
83 r = get_default_context_with_rolelevel(sename, role, lvl, NULL,
84 &sc);
85 else
86 r = get_default_context_with_level(sename, lvl, NULL, &sc);
73#else 87#else
74 r = get_default_context(sename, NULL, &sc); 88 if (role != NULL && role[0])
89 r = get_default_context_with_role(sename, role, NULL, &sc);
90 else
91 r = get_default_context(sename, NULL, &sc);
75#endif 92#endif
76 93
77 if (r != 0) { 94 if (r != 0) {