diff options
author | Darren Tucker <dtucker@zip.com.au> | 2009-10-24 15:04:12 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2009-10-24 15:04:12 +1100 |
commit | 4d6656b1030c2090f8769ce9cce0a9e5dd135945 (patch) | |
tree | 6cd9e06190cfbe4be752b82de995cb09d9303e9b | |
parent | 6ac91a7c83a7343e9fdf24c2857b301b50e21a9c (diff) |
- (dtucker) [session.c openbsd-compat/port-linux.{c,h}] Bug #1637: if selinux
is enabled set the security context to "sftpd_t" before running the
internal sftp server Based on a patch from jchadima at redhat.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | openbsd-compat/port-linux.c | 37 | ||||
-rw-r--r-- | openbsd-compat/port-linux.h | 3 | ||||
-rw-r--r-- | session.c | 3 |
4 files changed, 44 insertions, 2 deletions
@@ -28,6 +28,9 @@ | |||
28 | [ssh-keygen.1] | 28 | [ssh-keygen.1] |
29 | ssh-keygen now uses AES-128 for private keys | 29 | ssh-keygen now uses AES-128 for private keys |
30 | - (dtucker) [mdoc2man.awk] Teach it to understand the .Ux macro. | 30 | - (dtucker) [mdoc2man.awk] Teach it to understand the .Ux macro. |
31 | - (dtucker) [session.c openbsd-compat/port-linux.{c,h}] Bug #1637: if selinux | ||
32 | is enabled set the security context to "sftpd_t" before running the | ||
33 | internal sftp server Based on a patch from jchadima at redhat. | ||
31 | 34 | ||
32 | 20091011 | 35 | 20091011 |
33 | - (dtucker) [configure.ac sftp-client.c] Remove the gyrations required for | 36 | - (dtucker) [configure.ac sftp-client.c] Remove the gyrations required for |
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c index ad262758e..88c601e20 100644 --- a/openbsd-compat/port-linux.c +++ b/openbsd-compat/port-linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-linux.c,v 1.5 2008/03/26 20:27:21 dtucker Exp $ */ | 1 | /* $Id: port-linux.c,v 1.6 2009/10/24 04:04:13 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> | 4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> |
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #ifdef WITH_SELINUX | 30 | #ifdef WITH_SELINUX |
31 | #include "log.h" | 31 | #include "log.h" |
32 | #include "xmalloc.h" | ||
32 | #include "port-linux.h" | 33 | #include "port-linux.h" |
33 | 34 | ||
34 | #include <selinux/selinux.h> | 35 | #include <selinux/selinux.h> |
@@ -168,4 +169,38 @@ ssh_selinux_setup_pty(char *pwname, const char *tty) | |||
168 | freecon(user_ctx); | 169 | freecon(user_ctx); |
169 | debug3("%s: done", __func__); | 170 | debug3("%s: done", __func__); |
170 | } | 171 | } |
172 | |||
173 | void | ||
174 | ssh_selinux_change_context(const char *newname) | ||
175 | { | ||
176 | int len, newlen; | ||
177 | char *oldctx, *newctx, *cx; | ||
178 | |||
179 | if (!ssh_selinux_enabled()) | ||
180 | return; | ||
181 | |||
182 | if (getcon((security_context_t *)&oldctx) < 0) { | ||
183 | logit("%s: getcon failed with %s", __func__, strerror (errno)); | ||
184 | return; | ||
185 | } | ||
186 | if ((cx = index(oldctx, ':')) == NULL || (cx = index(cx + 1, ':')) == | ||
187 | NULL) { | ||
188 | logit ("%s: unparseable context %s", __func__, oldctx); | ||
189 | return; | ||
190 | } | ||
191 | |||
192 | newlen = strlen(oldctx) + strlen(newname) + 1; | ||
193 | newctx = xmalloc(newlen); | ||
194 | len = cx - oldctx + 1; | ||
195 | memcpy(newctx, oldctx, len); | ||
196 | strlcpy(newctx + len, newname, newlen - len); | ||
197 | if ((cx = index(cx + 1, ':'))) | ||
198 | strlcat(newctx, cx, newlen); | ||
199 | debug3("%s: setting context from '%s' to '%s'", __func__, oldctx, | ||
200 | newctx); | ||
201 | if (setcon(newctx) < 0) | ||
202 | logit("%s: setcon failed with %s", __func__, strerror (errno)); | ||
203 | xfree(oldctx); | ||
204 | xfree(newctx); | ||
205 | } | ||
171 | #endif /* WITH_SELINUX */ | 206 | #endif /* WITH_SELINUX */ |
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h index 5cd39bf83..6ad4a49f6 100644 --- a/openbsd-compat/port-linux.h +++ b/openbsd-compat/port-linux.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-linux.h,v 1.2 2008/03/26 20:27:21 dtucker Exp $ */ | 1 | /* $Id: port-linux.h,v 1.3 2009/10/24 04:04:13 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2006 Damien Miller <djm@openbsd.org> | 4 | * Copyright (c) 2006 Damien Miller <djm@openbsd.org> |
@@ -23,6 +23,7 @@ | |||
23 | int ssh_selinux_enabled(void); | 23 | int ssh_selinux_enabled(void); |
24 | void ssh_selinux_setup_pty(char *, const char *); | 24 | void ssh_selinux_setup_pty(char *, const char *); |
25 | void ssh_selinux_setup_exec_context(char *); | 25 | void ssh_selinux_setup_exec_context(char *); |
26 | void ssh_selinux_change_context(const char *); | ||
26 | #endif | 27 | #endif |
27 | 28 | ||
28 | #endif /* ! _PORT_LINUX_H */ | 29 | #endif /* ! _PORT_LINUX_H */ |
@@ -1796,6 +1796,9 @@ do_child(Session *s, const char *command) | |||
1796 | argv[i] = NULL; | 1796 | argv[i] = NULL; |
1797 | optind = optreset = 1; | 1797 | optind = optreset = 1; |
1798 | __progname = argv[0]; | 1798 | __progname = argv[0]; |
1799 | #ifdef WITH_SELINUX | ||
1800 | ssh_selinux_change_context("sftpd_t"); | ||
1801 | #endif | ||
1799 | exit(sftp_server_main(i, argv, s->pw)); | 1802 | exit(sftp_server_main(i, argv, s->pw)); |
1800 | } | 1803 | } |
1801 | 1804 | ||