|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth1.c.role openssh-5.8p1/auth1.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/auth1.c.role 2010-08-31 14:36:39.000000000 +0200
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth1.c 2011-03-22 18:32:17.907648664 +0100
|
|
Jan F. Chadima |
974c89 |
@@ -384,6 +384,9 @@ do_authentication(Authctxt *authctxt)
|
|
Jan F. Chadima |
a3ba41 |
{
|
|
Jan F. Chadima |
a3ba41 |
u_int ulen;
|
|
Jan F. Chadima |
ce94da |
char *user, *style = NULL;
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ char *role=NULL;
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
/* Get the name of the user that we wish to log in as. */
|
|
Jan F. Chadima |
a3ba41 |
packet_read_expect(SSH_CMSG_USER);
|
|
Jan F |
003cb0 |
@@ -392,11 +395,24 @@ do_authentication(Authctxt *authctxt)
|
|
Jan F |
003cb0 |
user = packet_get_cstring(&ulen);
|
|
Jan F. Chadima |
a3ba41 |
packet_check_eom();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
a3ba41 |
+ if ((role = strchr(user, '/')) != NULL)
|
|
Jan F. Chadima |
a3ba41 |
+ *role++ = '\0';
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
if ((style = strchr(user, ':')) != NULL)
|
|
Jan F. Chadima |
a3ba41 |
*style++ = '\0';
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
a3ba41 |
+ else
|
|
Jan F. Chadima |
a3ba41 |
+ if (role && (style = strchr(role, ':')) != NULL)
|
|
Jan F. Chadima |
a3ba41 |
+ *style++ = '\0';
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
authctxt->user = user;
|
|
Jan F. Chadima |
a3ba41 |
authctxt->style = style;
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
a3ba41 |
+ authctxt->role = role;
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
/* Verify that the user is a valid user. */
|
|
Jan F. Chadima |
a3ba41 |
if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth2.c.role openssh-5.8p1/auth2.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/auth2.c.role 2011-03-22 18:32:10.876648814 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth2.c 2011-03-22 18:32:17.959648657 +0100
|
|
Jan F. Chadima |
ce94da |
@@ -216,6 +216,9 @@ input_userauth_request(int type, u_int32
|
|
Jan F. Chadima |
ce94da |
Authctxt *authctxt = ctxt;
|
|
Jan F. Chadima |
ce94da |
Authmethod *m = NULL;
|
|
Jan F. Chadima |
ce94da |
char *user, *service, *method, *style = NULL;
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ char *role = NULL;
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
int authenticated = 0;
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
if (authctxt == NULL)
|
|
Jan F. Chadima |
ce94da |
@@ -227,6 +230,11 @@ input_userauth_request(int type, u_int32
|
|
Jan F. Chadima |
ce94da |
debug("userauth-request for user %s service %s method %s", user, service, method);
|
|
Jan F. Chadima |
ce94da |
debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ if ((role = strchr(user, '/')) != NULL)
|
|
Jan F. Chadima |
ce94da |
+ *role++ = 0;
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
+
|
|
Jan F. Chadima |
ce94da |
if ((style = strchr(user, ':')) != NULL)
|
|
Jan F. Chadima |
ce94da |
*style++ = 0;
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F |
3657ad |
@@ -249,8 +257,15 @@ input_userauth_request(int type, u_int32
|
|
Jan F. Chadima |
ce94da |
use_privsep ? " [net]" : "");
|
|
Jan F. Chadima |
ce94da |
authctxt->service = xstrdup(service);
|
|
Jan F. Chadima |
ce94da |
authctxt->style = style ? xstrdup(style) : NULL;
|
|
Jan F. Chadima |
ce94da |
- if (use_privsep)
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ authctxt->role = role ? xstrdup(role) : NULL;
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
+ if (use_privsep) {
|
|
Jan F. Chadima |
ce94da |
mm_inform_authserv(service, style);
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ mm_inform_authrole(role);
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
+ }
|
|
Jan F. Chadima |
ce94da |
userauth_banner();
|
|
Jan F. Chadima |
ce94da |
} else if (strcmp(user, authctxt->user) != 0 ||
|
|
Jan F. Chadima |
ce94da |
strcmp(service, authctxt->service) != 0) {
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth2-gss.c.role openssh-5.8p1/auth2-gss.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/auth2-gss.c.role 2007-12-02 12:59:45.000000000 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth2-gss.c 2011-03-22 18:32:18.009679649 +0100
|
|
Jan F. Chadima |
ce94da |
@@ -258,6 +258,7 @@ input_gssapi_mic(int type, u_int32_t ple
|
|
Jan F. Chadima |
ce94da |
Authctxt *authctxt = ctxt;
|
|
Jan F. Chadima |
ce94da |
Gssctxt *gssctxt;
|
|
Jan F. Chadima |
ce94da |
int authenticated = 0;
|
|
Jan F. Chadima |
ce94da |
+ char *micuser;
|
|
Jan F. Chadima |
ce94da |
Buffer b;
|
|
Jan F. Chadima |
ce94da |
gss_buffer_desc mic, gssbuf;
|
|
Jan F. Chadima |
ce94da |
u_int len;
|
|
Jan F. Chadima |
ce94da |
@@ -270,7 +271,13 @@ input_gssapi_mic(int type, u_int32_t ple
|
|
Jan F. Chadima |
ce94da |
mic.value = packet_get_string(&len;;
|
|
Jan F. Chadima |
ce94da |
mic.length = len;
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
- ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ if (authctxt->role && (strlen(authctxt->role) > 0))
|
|
Jan F. Chadima |
ce94da |
+ xasprintf(&micuser, "%s/%s", authctxt->user, authctxt->role);
|
|
Jan F. Chadima |
ce94da |
+ else
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
+ micuser = authctxt->user;
|
|
Jan F. Chadima |
ce94da |
+ ssh_gssapi_buildmic(&b, micuser, authctxt->service,
|
|
Jan F. Chadima |
ce94da |
"gssapi-with-mic");
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
gssbuf.value = buffer_ptr(&b);
|
|
Jan F. Chadima |
ce94da |
@@ -282,6 +289,8 @@ input_gssapi_mic(int type, u_int32_t ple
|
|
Jan F. Chadima |
ce94da |
logit("GSSAPI MIC check failed");
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
buffer_free(&b);
|
|
Jan F. Chadima |
ce94da |
+ if (micuser != authctxt->user)
|
|
Jan F. Chadima |
ce94da |
+ xfree(micuser);
|
|
Jan F. Chadima |
ce94da |
xfree(mic.value);
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
authctxt->postponed = 0;
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth2-hostbased.c.role openssh-5.8p1/auth2-hostbased.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/auth2-hostbased.c.role 2011-03-22 18:32:12.012648649 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth2-hostbased.c 2011-03-22 18:32:18.052648698 +0100
|
|
Jan F. Chadima |
ce94da |
@@ -106,7 +106,15 @@ userauth_hostbased(Authctxt *authctxt)
|
|
Jan F. Chadima |
ce94da |
buffer_put_string(&b, session_id2, session_id2_len);
|
|
Jan F. Chadima |
ce94da |
/* reconstruct packet */
|
|
Jan F. Chadima |
ce94da |
buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
|
|
Jan F. Chadima |
ce94da |
- buffer_put_cstring(&b, authctxt->user);
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ if (authctxt->role) {
|
|
Jan F. Chadima |
ce94da |
+ buffer_put_int(&b, strlen(authctxt->user)+strlen(authctxt->role)+1);
|
|
Jan F. Chadima |
ce94da |
+ buffer_append(&b, authctxt->user, strlen(authctxt->user));
|
|
Jan F. Chadima |
ce94da |
+ buffer_put_char(&b, '/');
|
|
Jan F. Chadima |
ce94da |
+ buffer_append(&b, authctxt->role, strlen(authctxt->role));
|
|
Jan F. Chadima |
ce94da |
+ } else
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
+ buffer_put_cstring(&b, authctxt->user);
|
|
Jan F. Chadima |
ce94da |
buffer_put_cstring(&b, service);
|
|
Jan F. Chadima |
ce94da |
buffer_put_cstring(&b, "hostbased");
|
|
Jan F. Chadima |
ce94da |
buffer_put_string(&b, pkalg, alen);
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth2-pubkey.c.role openssh-5.8p1/auth2-pubkey.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/auth2-pubkey.c.role 2011-03-22 18:32:16.318648486 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth2-pubkey.c 2011-03-22 18:32:18.107648652 +0100
|
|
Jan F |
003cb0 |
@@ -122,7 +122,15 @@ userauth_pubkey(Authctxt *authctxt)
|
|
Jan F. Chadima |
adad2a |
}
|
|
Jan F. Chadima |
adad2a |
/* reconstruct packet */
|
|
Jan F. Chadima |
adad2a |
buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
|
|
Jan F. Chadima |
adad2a |
- buffer_put_cstring(&b, authctxt->user);
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
adad2a |
+ if (authctxt->role) {
|
|
Jan F. Chadima |
adad2a |
+ buffer_put_int(&b, strlen(authctxt->user)+strlen(authctxt->role)+1);
|
|
Jan F. Chadima |
adad2a |
+ buffer_append(&b, authctxt->user, strlen(authctxt->user));
|
|
Jan F. Chadima |
adad2a |
+ buffer_put_char(&b, '/');
|
|
Jan F. Chadima |
adad2a |
+ buffer_append(&b, authctxt->role, strlen(authctxt->role));
|
|
Jan F. Chadima |
ce94da |
+ } else
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
adad2a |
+ buffer_put_cstring(&b, authctxt->user);
|
|
Jan F. Chadima |
adad2a |
buffer_put_cstring(&b,
|
|
Jan F. Chadima |
adad2a |
datafellows & SSH_BUG_PKSERVICE ?
|
|
Jan F. Chadima |
adad2a |
"ssh-userauth" :
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth.h.role openssh-5.8p1/auth.h
|
|
Jan F |
3657ad |
--- openssh-5.8p1/auth.h.role 2011-03-22 18:32:12.117648630 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth.h 2011-03-22 18:32:18.170648709 +0100
|
|
Jan F. Chadima |
ce94da |
@@ -58,6 +58,9 @@ struct Authctxt {
|
|
Jan F. Chadima |
ce94da |
char *service;
|
|
Jan F. Chadima |
ce94da |
struct passwd *pw; /* set if 'valid' */
|
|
Jan F. Chadima |
ce94da |
char *style;
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ char *role;
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
void *kbdintctxt;
|
|
Jan F. Chadima |
ce94da |
void *jpake_ctx;
|
|
Jan F. Chadima |
ce94da |
#ifdef BSD_AUTH
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth-pam.c.role openssh-5.8p1/auth-pam.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/auth-pam.c.role 2009-07-12 14:07:21.000000000 +0200
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth-pam.c 2011-03-22 18:32:18.230844134 +0100
|
|
Jan F |
003cb0 |
@@ -1069,7 +1069,7 @@ is_pam_session_open(void)
|
|
Jan F |
003cb0 |
* during the ssh authentication process.
|
|
Jan F |
003cb0 |
*/
|
|
Jan F |
003cb0 |
int
|
|
Jan F |
003cb0 |
-do_pam_putenv(char *name, char *value)
|
|
Jan F |
003cb0 |
+do_pam_putenv(char *name, const char *value)
|
|
Jan F |
003cb0 |
{
|
|
Jan F |
003cb0 |
int ret = 1;
|
|
Jan F |
003cb0 |
#ifdef HAVE_PAM_PUTENV
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth-pam.h.role openssh-5.8p1/auth-pam.h
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/auth-pam.h.role 2004-09-11 14:17:26.000000000 +0200
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/auth-pam.h 2011-03-22 18:32:18.280648665 +0100
|
|
Jan F |
003cb0 |
@@ -38,7 +38,7 @@ void do_pam_session(void);
|
|
Jan F |
003cb0 |
void do_pam_set_tty(const char *);
|
|
Jan F |
003cb0 |
void do_pam_setcred(int );
|
|
Jan F |
003cb0 |
void do_pam_chauthtok(void);
|
|
Jan F |
003cb0 |
-int do_pam_putenv(char *, char *);
|
|
Jan F |
003cb0 |
+int do_pam_putenv(char *, const char *);
|
|
Jan F |
003cb0 |
char ** fetch_pam_environment(void);
|
|
Jan F |
003cb0 |
char ** fetch_pam_child_environment(void);
|
|
Jan F |
003cb0 |
void free_pam_environment(char **);
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/monitor.c.role openssh-5.8p1/monitor.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/monitor.c.role 2011-03-22 18:32:14.465661970 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/monitor.c 2011-03-22 18:32:18.337831292 +0100
|
|
Jan F |
3657ad |
@@ -140,6 +140,9 @@ int mm_answer_sign(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
int mm_answer_pwnamallow(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
int mm_answer_auth2_read_banner(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
int mm_answer_authserv(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+int mm_answer_authrole(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
int mm_answer_authpassword(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
int mm_answer_bsdauthquery(int, Buffer *);
|
|
Jan F. Chadima |
ce94da |
int mm_answer_bsdauthrespond(int, Buffer *);
|
|
Jan F |
3657ad |
@@ -221,6 +224,9 @@ struct mon_table mon_dispatch_proto20[]
|
|
Jan F. Chadima |
ce94da |
{MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
|
|
Jan F. Chadima |
ce94da |
{MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
|
|
Jan F. Chadima |
ce94da |
{MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
{MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
|
|
Jan F. Chadima |
ce94da |
{MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
|
|
Jan F. Chadima |
ce94da |
#ifdef USE_PAM
|
|
Jan F |
3657ad |
@@ -708,6 +714,9 @@ mm_answer_pwnamallow(int sock, Buffer *m
|
|
Jan F. Chadima |
ce94da |
else {
|
|
Jan F. Chadima |
ce94da |
/* Allow service/style information on the auth context */
|
|
Jan F. Chadima |
ce94da |
monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
|
|
Jan F. Chadima |
ce94da |
}
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F |
3657ad |
@@ -752,6 +761,25 @@ mm_answer_authserv(int sock, Buffer *m)
|
|
Jan F. Chadima |
ce94da |
return (0);
|
|
Jan F. Chadima |
ce94da |
}
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+int
|
|
Jan F. Chadima |
ce94da |
+mm_answer_authrole(int sock, Buffer *m)
|
|
Jan F. Chadima |
ce94da |
+{
|
|
Jan F. Chadima |
ce94da |
+ monitor_permit_authentications(1);
|
|
Jan F. Chadima |
ce94da |
+
|
|
Jan F. Chadima |
ce94da |
+ authctxt->role = buffer_get_string(m, NULL);
|
|
Jan F. Chadima |
ce94da |
+ debug3("%s: role=%s",
|
|
Jan F. Chadima |
ce94da |
+ __func__, authctxt->role);
|
|
Jan F. Chadima |
ce94da |
+
|
|
Jan F. Chadima |
ce94da |
+ if (strlen(authctxt->role) == 0) {
|
|
Jan F. Chadima |
ce94da |
+ xfree(authctxt->role);
|
|
Jan F. Chadima |
ce94da |
+ authctxt->role = NULL;
|
|
Jan F. Chadima |
ce94da |
+ }
|
|
Jan F. Chadima |
ce94da |
+
|
|
Jan F. Chadima |
ce94da |
+ return (0);
|
|
Jan F. Chadima |
ce94da |
+}
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
+
|
|
Jan F. Chadima |
ce94da |
int
|
|
Jan F. Chadima |
ce94da |
mm_answer_authpassword(int sock, Buffer *m)
|
|
Jan F. Chadima |
ce94da |
{
|
|
Jan F |
3657ad |
@@ -1117,7 +1145,7 @@ static int
|
|
Jan F. Chadima |
ce94da |
monitor_valid_userblob(u_char *data, u_int datalen)
|
|
Jan F. Chadima |
ce94da |
{
|
|
Jan F. Chadima |
ce94da |
Buffer b;
|
|
Jan F. Chadima |
ce94da |
- char *p;
|
|
Jan F. Chadima |
ce94da |
+ char *p, *r;
|
|
Jan F. Chadima |
ce94da |
u_int len;
|
|
Jan F. Chadima |
ce94da |
int fail = 0;
|
|
Jan F. Chadima |
adad2a |
|
|
Jan F |
3657ad |
@@ -1143,6 +1171,8 @@ monitor_valid_userblob(u_char *data, u_i
|
|
Jan F. Chadima |
ce94da |
if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
|
|
Jan F. Chadima |
ce94da |
fail++;
|
|
Jan F. Chadima |
ce94da |
p = buffer_get_string(&b, NULL);
|
|
Jan F. Chadima |
ce94da |
+ if ((r = strchr(p, '/')) != NULL)
|
|
Jan F. Chadima |
ce94da |
+ *r = '\0';
|
|
Jan F. Chadima |
ce94da |
if (strcmp(authctxt->user, p) != 0) {
|
|
Jan F. Chadima |
ce94da |
logit("wrong user name passed to monitor: expected %s != %.100s",
|
|
Jan F. Chadima |
ce94da |
authctxt->user, p);
|
|
Jan F |
3657ad |
@@ -1174,7 +1204,7 @@ monitor_valid_hostbasedblob(u_char *data
|
|
Jan F. Chadima |
ce94da |
char *chost)
|
|
Jan F. Chadima |
ce94da |
{
|
|
Jan F. Chadima |
ce94da |
Buffer b;
|
|
Jan F. Chadima |
ce94da |
- char *p;
|
|
Jan F. Chadima |
ce94da |
+ char *p, *r;
|
|
Jan F. Chadima |
ce94da |
u_int len;
|
|
Jan F. Chadima |
ce94da |
int fail = 0;
|
|
Jan F. Chadima |
ce94da |
|
|
Jan F |
3657ad |
@@ -1191,6 +1221,8 @@ monitor_valid_hostbasedblob(u_char *data
|
|
Jan F. Chadima |
ce94da |
if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
|
|
Jan F. Chadima |
ce94da |
fail++;
|
|
Jan F. Chadima |
ce94da |
p = buffer_get_string(&b, NULL);
|
|
Jan F. Chadima |
ce94da |
+ if ((r = strchr(p, '/')) != NULL)
|
|
Jan F. Chadima |
ce94da |
+ *r = '\0';
|
|
Jan F. Chadima |
ce94da |
if (strcmp(authctxt->user, p) != 0) {
|
|
Jan F. Chadima |
ce94da |
logit("wrong user name passed to monitor: expected %s != %.100s",
|
|
Jan F. Chadima |
ce94da |
authctxt->user, p);
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/monitor.h.role openssh-5.8p1/monitor.h
|
|
Jan F |
3657ad |
--- openssh-5.8p1/monitor.h.role 2011-03-22 18:32:14.512648974 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/monitor.h 2011-03-22 18:32:18.382648691 +0100
|
|
Jan F. Chadima |
ce94da |
@@ -31,6 +31,9 @@
|
|
Jan F. Chadima |
adad2a |
enum monitor_reqtype {
|
|
Jan F. Chadima |
adad2a |
MONITOR_REQ_MODULI, MONITOR_ANS_MODULI,
|
|
Jan F. Chadima |
ce94da |
MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV,
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+ MONITOR_REQ_AUTHROLE,
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
adad2a |
MONITOR_REQ_SIGN, MONITOR_ANS_SIGN,
|
|
Jan F. Chadima |
adad2a |
MONITOR_REQ_PWNAM, MONITOR_ANS_PWNAM,
|
|
Jan F. Chadima |
adad2a |
MONITOR_REQ_AUTH2_READ_BANNER, MONITOR_ANS_AUTH2_READ_BANNER,
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/monitor_wrap.c.role openssh-5.8p1/monitor_wrap.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/monitor_wrap.c.role 2011-03-22 18:32:14.612774442 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/monitor_wrap.c 2011-03-22 18:32:18.433648592 +0100
|
|
Jan F |
003cb0 |
@@ -298,6 +298,25 @@ mm_inform_authserv(char *service, char *
|
|
Jan F. Chadima |
adad2a |
buffer_free(&m);
|
|
Jan F. Chadima |
adad2a |
}
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
adad2a |
+/* Inform the privileged process about role */
|
|
Jan F. Chadima |
adad2a |
+
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
adad2a |
+void
|
|
Jan F. Chadima |
adad2a |
+mm_inform_authrole(char *role)
|
|
Jan F. Chadima |
adad2a |
+{
|
|
Jan F. Chadima |
adad2a |
+ Buffer m;
|
|
Jan F. Chadima |
adad2a |
+
|
|
Jan F. Chadima |
adad2a |
+ debug3("%s entering", __func__);
|
|
Jan F. Chadima |
adad2a |
+
|
|
Jan F. Chadima |
adad2a |
+ buffer_init(&m);
|
|
Jan F. Chadima |
adad2a |
+ buffer_put_cstring(&m, role ? role : "");
|
|
Jan F. Chadima |
adad2a |
+
|
|
Jan F. Chadima |
adad2a |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, &m);
|
|
Jan F. Chadima |
adad2a |
+
|
|
Jan F. Chadima |
adad2a |
+ buffer_free(&m);
|
|
Jan F. Chadima |
adad2a |
+}
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
adad2a |
+
|
|
Jan F. Chadima |
adad2a |
/* Do the password authentication */
|
|
Jan F. Chadima |
adad2a |
int
|
|
Jan F. Chadima |
adad2a |
mm_auth_password(Authctxt *authctxt, char *password)
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/monitor_wrap.h.role openssh-5.8p1/monitor_wrap.h
|
|
Jan F |
3657ad |
--- openssh-5.8p1/monitor_wrap.h.role 2011-03-22 18:32:14.659648967 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/monitor_wrap.h 2011-03-22 18:32:18.486648682 +0100
|
|
Jan F. Chadima |
ce94da |
@@ -41,6 +41,9 @@ int mm_is_monitor(void);
|
|
Jan F. Chadima |
ce94da |
DH *mm_choose_dh(int, int, int);
|
|
Jan F. Chadima |
ce94da |
int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
|
|
Jan F. Chadima |
ce94da |
void mm_inform_authserv(char *, char *);
|
|
Jan F. Chadima |
ce94da |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
ce94da |
+void mm_inform_authrole(char *);
|
|
Jan F. Chadima |
ce94da |
+#endif
|
|
Jan F. Chadima |
ce94da |
struct passwd *mm_getpwnamallow(const char *);
|
|
Jan F. Chadima |
ce94da |
char *mm_auth2_read_banner(void);
|
|
Jan F. Chadima |
ce94da |
int mm_auth_password(struct Authctxt *, char *);
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/openbsd-compat/Makefile.in.role openssh-5.8p1/openbsd-compat/Makefile.in
|
|
Jan F |
3657ad |
--- openssh-5.8p1/openbsd-compat/Makefile.in.role 2011-03-22 18:32:15.000000000 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/openbsd-compat/Makefile.in 2011-03-22 18:34:43.962648778 +0100
|
|
Jan F |
003cb0 |
@@ -20,7 +20,7 @@ OPENBSD=base64.o basename.o bindresvport
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o
|
|
Jan F |
003cb0 |
|
|
Jan F |
3657ad |
-PORTS=port-aix.o port-irix.o port-linux.o port-linux-prng.o port-solaris.o port-tun.o port-uw.o
|
|
Jan F |
3657ad |
+PORTS=port-aix.o port-irix.o port-linux.o port-linux_part_2.o port-linux-prng.o port-solaris.o port-tun.o port-uw.o
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
.c.o:
|
|
Jan F |
003cb0 |
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/openbsd-compat/port-linux.c.role openssh-5.8p1/openbsd-compat/port-linux.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/openbsd-compat/port-linux.c.role 2011-03-22 18:32:17.782648196 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/openbsd-compat/port-linux.c 2011-03-22 18:32:18.604648721 +0100
|
|
Jan F |
003cb0 |
@@ -31,48 +31,73 @@
|
|
Jan F |
003cb0 |
|
|
Jan F. Chadima |
adad2a |
#include "log.h"
|
|
Jan F. Chadima |
974c89 |
#include "xmalloc.h"
|
|
Jan F |
003cb0 |
+#include "servconf.h"
|
|
Jan F. Chadima |
adad2a |
#include "port-linux.h"
|
|
Jan F. Chadima |
adad2a |
+#include "key.h"
|
|
Jan F. Chadima |
adad2a |
+#include "hostfile.h"
|
|
Jan F. Chadima |
adad2a |
+#include "auth.h"
|
|
Jan F. Chadima |
adad2a |
|
|
Jan F. Chadima |
974c89 |
#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
adad2a |
#include <selinux/selinux.h>
|
|
Jan F. Chadima |
adad2a |
#include <selinux/flask.h>
|
|
Jan F. Chadima |
adad2a |
#include <selinux/get_context_list.h>
|
|
Jan F. Chadima |
adad2a |
|
|
Jan F |
003cb0 |
-/* Wrapper around is_selinux_enabled() to log its return value once only */
|
|
Jan F |
003cb0 |
-int
|
|
Jan F |
003cb0 |
-ssh_selinux_enabled(void)
|
|
Jan F |
003cb0 |
-{
|
|
Jan F |
003cb0 |
- static int enabled = -1;
|
|
Jan F |
003cb0 |
+extern ServerOptions options;
|
|
Jan F. Chadima |
adad2a |
+extern Authctxt *the_authctxt;
|
|
Jan F |
003cb0 |
+extern int inetd_flag;
|
|
Jan F |
003cb0 |
+extern int rexeced_flag;
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
- if (enabled == -1) {
|
|
Jan F |
003cb0 |
- enabled = (is_selinux_enabled() == 1);
|
|
Jan F |
003cb0 |
- debug("SELinux support %s", enabled ? "enabled" : "disabled");
|
|
Jan F |
003cb0 |
+static void
|
|
Jan F |
003cb0 |
+ssh_selinux_get_role_level(char **role, const char **level)
|
|
Jan F |
003cb0 |
+{
|
|
Jan F |
003cb0 |
+ *role = NULL;
|
|
Jan F |
003cb0 |
+ *level = NULL;
|
|
Jan F |
003cb0 |
+ if (the_authctxt) {
|
|
Jan F |
003cb0 |
+ if (the_authctxt->role != NULL) {
|
|
Jan F |
003cb0 |
+ char *slash;
|
|
Jan F |
003cb0 |
+ *role = xstrdup(the_authctxt->role);
|
|
Jan F |
003cb0 |
+ if ((slash = strchr(*role, '/')) != NULL) {
|
|
Jan F |
003cb0 |
+ *slash = '\0';
|
|
Jan F |
003cb0 |
+ *level = slash + 1;
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
}
|
|
Jan F |
003cb0 |
-
|
|
Jan F |
003cb0 |
- return (enabled);
|
|
Jan F |
003cb0 |
}
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
/* Return the default security context for the given username */
|
|
Jan F. Chadima |
adad2a |
static security_context_t
|
|
Jan F. Chadima |
adad2a |
ssh_selinux_getctxbyname(char *pwname)
|
|
Jan F. Chadima |
adad2a |
{
|
|
Jan F. Chadima |
adad2a |
- security_context_t sc;
|
|
Jan F. Chadima |
adad2a |
- char *sename = NULL, *lvl = NULL;
|
|
Jan F. Chadima |
adad2a |
- int r;
|
|
Jan F. Chadima |
adad2a |
+ security_context_t sc = NULL;
|
|
Jan F. Chadima |
adad2a |
+ char *sename, *lvl;
|
|
Jan F |
003cb0 |
+ char *role;
|
|
Jan F |
003cb0 |
+ const char *reqlvl;
|
|
Jan F. Chadima |
adad2a |
+ int r = 0;
|
|
Jan F. Chadima |
adad2a |
|
|
Jan F |
003cb0 |
+ ssh_selinux_get_role_level(&role, &reqlvl);
|
|
Jan F. Chadima |
adad2a |
#ifdef HAVE_GETSEUSERBYNAME
|
|
Jan F. Chadima |
adad2a |
- if (getseuserbyname(pwname, &sename, &lvl) != 0)
|
|
Jan F. Chadima |
adad2a |
- return NULL;
|
|
Jan F. Chadima |
adad2a |
+ if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
|
|
Jan F. Chadima |
adad2a |
+ sename = NULL;
|
|
Jan F. Chadima |
adad2a |
+ lvl = NULL;
|
|
Jan F. Chadima |
adad2a |
+ }
|
|
Jan F. Chadima |
adad2a |
#else
|
|
Jan F. Chadima |
adad2a |
sename = pwname;
|
|
Jan F. Chadima |
adad2a |
lvl = NULL;
|
|
Jan F. Chadima |
adad2a |
#endif
|
|
Jan F. Chadima |
adad2a |
|
|
Jan F. Chadima |
adad2a |
+ if (r == 0) {
|
|
Jan F. Chadima |
adad2a |
#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Jan F. Chadima |
adad2a |
- r = get_default_context_with_level(sename, lvl, NULL, &sc);
|
|
Jan F. Chadima |
adad2a |
+ if (role != NULL && role[0])
|
|
Jan F. Chadima |
adad2a |
+ r = get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
|
|
Jan F. Chadima |
adad2a |
+ else
|
|
Jan F. Chadima |
adad2a |
+ r = get_default_context_with_level(sename, lvl, NULL, &sc);
|
|
Jan F. Chadima |
adad2a |
#else
|
|
Jan F. Chadima |
adad2a |
- r = get_default_context(sename, NULL, &sc);
|
|
Jan F. Chadima |
adad2a |
+ if (role != NULL && role[0])
|
|
Jan F. Chadima |
adad2a |
+ r = get_default_context_with_role(sename, role, NULL, &sc);
|
|
Jan F. Chadima |
adad2a |
+ else
|
|
Jan F. Chadima |
adad2a |
+ r = get_default_context(sename, NULL, &sc);
|
|
Jan F. Chadima |
adad2a |
#endif
|
|
Jan F. Chadima |
adad2a |
+ }
|
|
Jan F. Chadima |
adad2a |
|
|
Jan F. Chadima |
adad2a |
if (r != 0) {
|
|
Jan F. Chadima |
adad2a |
switch (security_getenforce()) {
|
|
Jan F |
003cb0 |
@@ -100,6 +125,36 @@ ssh_selinux_getctxbyname(char *pwname)
|
|
Jan F |
003cb0 |
return (sc);
|
|
Jan F |
003cb0 |
}
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
+/* Setup environment variables for pam_selinux */
|
|
Jan F |
003cb0 |
+static int
|
|
Jan F |
003cb0 |
+ssh_selinux_setup_pam_variables(void)
|
|
Jan F |
003cb0 |
+{
|
|
Jan F |
003cb0 |
+ const char *reqlvl;
|
|
Jan F |
003cb0 |
+ char *role;
|
|
Jan F |
003cb0 |
+ char *use_current;
|
|
Jan F |
003cb0 |
+ int rv;
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ debug3("%s: setting execution context", __func__);
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ ssh_selinux_get_role_level(&role, &reqlvl);
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ rv = do_pam_putenv("SELINUX_ROLE_REQUESTED", role ? role : "");
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ if (inetd_flag && !rexeced_flag) {
|
|
Jan F |
003cb0 |
+ use_current = "1";
|
|
Jan F |
003cb0 |
+ } else {
|
|
Jan F |
003cb0 |
+ use_current = "";
|
|
Jan F |
003cb0 |
+ rv = rv || do_pam_putenv("SELINUX_LEVEL_REQUESTED", reqlvl ? reqlvl: "");
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ rv = rv || do_pam_putenv("SELINUX_USE_CURRENT_RANGE", use_current);
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ if (role != NULL)
|
|
Jan F |
003cb0 |
+ xfree(role);
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ return rv;
|
|
Jan F |
003cb0 |
+}
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
/* Set the execution context to the default for the specified user */
|
|
Jan F |
003cb0 |
void
|
|
Jan F |
003cb0 |
ssh_selinux_setup_exec_context(char *pwname)
|
|
Jan F |
003cb0 |
@@ -109,6 +164,24 @@ ssh_selinux_setup_exec_context(char *pwn
|
|
Jan F |
003cb0 |
if (!ssh_selinux_enabled())
|
|
Jan F |
003cb0 |
return;
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
+ if (options.use_pam) {
|
|
Jan F |
003cb0 |
+ /* do not compute context, just setup environment for pam_selinux */
|
|
Jan F |
003cb0 |
+ if (ssh_selinux_setup_pam_variables()) {
|
|
Jan F |
003cb0 |
+ switch (security_getenforce()) {
|
|
Jan F |
003cb0 |
+ case -1:
|
|
Jan F |
003cb0 |
+ fatal("%s: security_getenforce() failed", __func__);
|
|
Jan F |
003cb0 |
+ case 0:
|
|
Jan F |
003cb0 |
+ error("%s: SELinux PAM variable setup failure. Continuing in permissive mode.",
|
|
Jan F |
003cb0 |
+ __func__);
|
|
Jan F |
003cb0 |
+ break;
|
|
Jan F |
003cb0 |
+ default:
|
|
Jan F |
003cb0 |
+ fatal("%s: SELinux PAM variable setup failure. Aborting connection.",
|
|
Jan F |
003cb0 |
+ __func__);
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+ return;
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
debug3("%s: setting execution context", __func__);
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
user_ctx = ssh_selinux_getctxbyname(pwname);
|
|
Jan F |
003cb0 |
@@ -206,21 +279,6 @@ ssh_selinux_change_context(const char *n
|
|
Jan F |
003cb0 |
xfree(newctx);
|
|
Jan F |
003cb0 |
}
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
-void
|
|
Jan F |
003cb0 |
-ssh_selinux_setfscreatecon(const char *path)
|
|
Jan F |
003cb0 |
-{
|
|
Jan F |
003cb0 |
- security_context_t context;
|
|
Jan F |
003cb0 |
-
|
|
Jan F |
003cb0 |
- if (!ssh_selinux_enabled())
|
|
Jan F |
003cb0 |
- return;
|
|
Jan F |
003cb0 |
- if (path == NULL) {
|
|
Jan F |
003cb0 |
- setfscreatecon(NULL);
|
|
Jan F |
003cb0 |
- return;
|
|
Jan F |
003cb0 |
- }
|
|
Jan F |
003cb0 |
- if (matchpathcon(path, 0700, &context) == 0)
|
|
Jan F |
003cb0 |
- setfscreatecon(context);
|
|
Jan F |
003cb0 |
-}
|
|
Jan F |
003cb0 |
-
|
|
Jan F |
003cb0 |
#endif /* WITH_SELINUX */
|
|
Jan F |
003cb0 |
|
|
Jan F |
003cb0 |
#ifdef LINUX_OOM_ADJUST
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/openbsd-compat/port-linux_part_2.c.role openssh-5.8p1/openbsd-compat/port-linux_part_2.c
|
|
Jan F |
3657ad |
--- openssh-5.8p1/openbsd-compat/port-linux_part_2.c.role 2011-03-22 18:32:18.632648682 +0100
|
|
Jan F |
3657ad |
+++ openssh-5.8p1/openbsd-compat/port-linux_part_2.c 2011-03-22 18:32:18.641648698 +0100
|
|
Jan F |
003cb0 |
@@ -0,0 +1,75 @@
|
|
Jan F |
003cb0 |
+/* $Id: port-linux.c,v 1.11.4.2 2011/02/04 00:43:08 djm Exp $ */
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+/*
|
|
Jan F |
003cb0 |
+ * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com>
|
|
Jan F |
003cb0 |
+ * Copyright (c) 2006 Damien Miller <djm@openbsd.org>
|
|
Jan F |
003cb0 |
+ *
|
|
Jan F |
003cb0 |
+ * Permission to use, copy, modify, and distribute this software for any
|
|
Jan F |
003cb0 |
+ * purpose with or without fee is hereby granted, provided that the above
|
|
Jan F |
003cb0 |
+ * copyright notice and this permission notice appear in all copies.
|
|
Jan F |
003cb0 |
+ *
|
|
Jan F |
003cb0 |
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
Jan F |
003cb0 |
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
Jan F |
003cb0 |
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
Jan F |
003cb0 |
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
Jan F |
003cb0 |
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
Jan F |
003cb0 |
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
Jan F |
003cb0 |
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
Jan F |
003cb0 |
+ */
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+/*
|
|
Jan F |
003cb0 |
+ * Linux-specific portability code - just SELinux support at present
|
|
Jan F |
003cb0 |
+ */
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+#include "includes.h"
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+#if defined(WITH_SELINUX) || defined(LINUX_OOM_ADJUST)
|
|
Jan F |
003cb0 |
+#include <errno.h>
|
|
Jan F |
003cb0 |
+#include <stdarg.h>
|
|
Jan F |
003cb0 |
+#include <string.h>
|
|
Jan F |
003cb0 |
+#include <stdio.h>
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+#include "log.h"
|
|
Jan F |
003cb0 |
+#include "xmalloc.h"
|
|
Jan F |
003cb0 |
+#include "port-linux.h"
|
|
Jan F |
003cb0 |
+#include "key.h"
|
|
Jan F |
003cb0 |
+#include "hostfile.h"
|
|
Jan F |
003cb0 |
+#include "auth.h"
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+#ifdef WITH_SELINUX
|
|
Jan F |
003cb0 |
+#include <selinux/selinux.h>
|
|
Jan F |
003cb0 |
+#include <selinux/flask.h>
|
|
Jan F |
003cb0 |
+#include <selinux/get_context_list.h>
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+/* Wrapper around is_selinux_enabled() to log its return value once only */
|
|
Jan F |
003cb0 |
+int
|
|
Jan F |
003cb0 |
+ssh_selinux_enabled(void)
|
|
Jan F |
003cb0 |
+{
|
|
Jan F |
003cb0 |
+ static int enabled = -1;
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ if (enabled == -1) {
|
|
Jan F |
003cb0 |
+ enabled = (is_selinux_enabled() == 1);
|
|
Jan F |
003cb0 |
+ debug("SELinux support %s", enabled ? "enabled" : "disabled");
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ return (enabled);
|
|
Jan F |
003cb0 |
+}
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+void
|
|
Jan F |
003cb0 |
+ssh_selinux_setfscreatecon(const char *path)
|
|
Jan F |
003cb0 |
+{
|
|
Jan F |
003cb0 |
+ security_context_t context;
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+ if (!ssh_selinux_enabled())
|
|
Jan F |
003cb0 |
+ return;
|
|
Jan F |
003cb0 |
+ if (path == NULL) {
|
|
Jan F |
003cb0 |
+ setfscreatecon(NULL);
|
|
Jan F |
003cb0 |
+ return;
|
|
Jan F |
003cb0 |
+ }
|
|
Jan F |
003cb0 |
+ if (matchpathcon(path, 0700, &context) == 0)
|
|
Jan F |
003cb0 |
+ setfscreatecon(context);
|
|
Jan F |
003cb0 |
+}
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+#endif /* WITH_SELINUX */
|
|
Jan F |
003cb0 |
+
|
|
Jan F |
003cb0 |
+#endif /* WITH_SELINUX || LINUX_OOM_ADJUST */
|