summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/port-linux.c27
-rw-r--r--openbsd-compat/port-linux.h4
2 files changed, 22 insertions, 9 deletions
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c
index 8c5325cc3..8a3e5c68d 100644
--- a/openbsd-compat/port-linux.c
+++ b/openbsd-compat/port-linux.c
@@ -27,6 +27,12 @@
27#include <string.h> 27#include <string.h>
28#include <stdio.h> 28#include <stdio.h>
29 29
30#ifdef WITH_SELINUX
31#include "key.h"
32#include "hostfile.h"
33#include "auth.h"
34#endif
35
30#include "log.h" 36#include "log.h"
31#include "xmalloc.h" 37#include "xmalloc.h"
32#include "port-linux.h" 38#include "port-linux.h"
@@ -55,7 +61,7 @@ ssh_selinux_enabled(void)
55 61
56/* Return the default security context for the given username */ 62/* Return the default security context for the given username */
57static security_context_t 63static security_context_t
58ssh_selinux_getctxbyname(char *pwname) 64ssh_selinux_getctxbyname(char *pwname, const char *role)
59{ 65{
60 security_context_t sc = NULL; 66 security_context_t sc = NULL;
61 char *sename = NULL, *lvl = NULL; 67 char *sename = NULL, *lvl = NULL;
@@ -70,9 +76,16 @@ ssh_selinux_getctxbyname(char *pwname)
70#endif 76#endif
71 77
72#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL 78#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
73 r = get_default_context_with_level(sename, lvl, NULL, &sc); 79 if (role != NULL && role[0])
80 r = get_default_context_with_rolelevel(sename, role, lvl, NULL,
81 &sc);
82 else
83 r = get_default_context_with_level(sename, lvl, NULL, &sc);
74#else 84#else
75 r = get_default_context(sename, NULL, &sc); 85 if (role != NULL && role[0])
86 r = get_default_context_with_role(sename, role, NULL, &sc);
87 else
88 r = get_default_context(sename, NULL, &sc);
76#endif 89#endif
77 90
78 if (r != 0) { 91 if (r != 0) {
@@ -102,7 +115,7 @@ ssh_selinux_getctxbyname(char *pwname)
102 115
103/* Set the execution context to the default for the specified user */ 116/* Set the execution context to the default for the specified user */
104void 117void
105ssh_selinux_setup_exec_context(char *pwname) 118ssh_selinux_setup_exec_context(char *pwname, const char *role)
106{ 119{
107 security_context_t user_ctx = NULL; 120 security_context_t user_ctx = NULL;
108 121
@@ -111,7 +124,7 @@ ssh_selinux_setup_exec_context(char *pwname)
111 124
112 debug3("%s: setting execution context", __func__); 125 debug3("%s: setting execution context", __func__);
113 126
114 user_ctx = ssh_selinux_getctxbyname(pwname); 127 user_ctx = ssh_selinux_getctxbyname(pwname, role);
115 if (setexeccon(user_ctx) != 0) { 128 if (setexeccon(user_ctx) != 0) {
116 switch (security_getenforce()) { 129 switch (security_getenforce()) {
117 case -1: 130 case -1:
@@ -133,7 +146,7 @@ ssh_selinux_setup_exec_context(char *pwname)
133 146
134/* Set the TTY context for the specified user */ 147/* Set the TTY context for the specified user */
135void 148void
136ssh_selinux_setup_pty(char *pwname, const char *tty) 149ssh_selinux_setup_pty(char *pwname, const char *tty, const char *role)
137{ 150{
138 security_context_t new_tty_ctx = NULL; 151 security_context_t new_tty_ctx = NULL;
139 security_context_t user_ctx = NULL; 152 security_context_t user_ctx = NULL;
@@ -145,7 +158,7 @@ ssh_selinux_setup_pty(char *pwname, const char *tty)
145 158
146 debug3("%s: setting TTY context on %s", __func__, tty); 159 debug3("%s: setting TTY context on %s", __func__, tty);
147 160
148 user_ctx = ssh_selinux_getctxbyname(pwname); 161 user_ctx = ssh_selinux_getctxbyname(pwname, role);
149 162
150 /* XXX: should these calls fatal() upon failure in enforcing mode? */ 163 /* XXX: should these calls fatal() upon failure in enforcing mode? */
151 164
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
index 3c22a854d..c88129428 100644
--- a/openbsd-compat/port-linux.h
+++ b/openbsd-compat/port-linux.h
@@ -19,8 +19,8 @@
19 19
20#ifdef WITH_SELINUX 20#ifdef WITH_SELINUX
21int ssh_selinux_enabled(void); 21int ssh_selinux_enabled(void);
22void ssh_selinux_setup_pty(char *, const char *); 22void ssh_selinux_setup_pty(char *, const char *, const char *);
23void ssh_selinux_setup_exec_context(char *); 23void ssh_selinux_setup_exec_context(char *, const char *);
24void ssh_selinux_change_context(const char *); 24void ssh_selinux_change_context(const char *);
25void ssh_selinux_setfscreatecon(const char *); 25void ssh_selinux_setfscreatecon(const char *);
26#endif 26#endif