|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth-pam.c.pam_selinux openssh-5.8p1/auth-pam.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/auth-pam.c.pam_selinux 2009-07-12 14:07:21.000000000 +0200
|
|
Jan F |
003cb0 |
+++ openssh-5.8p1/auth-pam.c 2011-02-12 10:49:57.000000000 +0100
|
|
Tomáš Mráz |
1961bc |
@@ -1069,7 +1069,7 @@ is_pam_session_open(void)
|
|
Tomáš Mráz |
1961bc |
* during the ssh authentication process.
|
|
Tomáš Mráz |
1961bc |
*/
|
|
Tomáš Mráz |
1961bc |
int
|
|
Tomáš Mráz |
1961bc |
-do_pam_putenv(char *name, char *value)
|
|
Tomáš Mráz |
1961bc |
+do_pam_putenv(char *name, const char *value)
|
|
Tomáš Mráz |
1961bc |
{
|
|
Tomáš Mráz |
1961bc |
int ret = 1;
|
|
Tomáš Mráz |
1961bc |
#ifdef HAVE_PAM_PUTENV
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/auth-pam.h.pam_selinux openssh-5.8p1/auth-pam.h
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/auth-pam.h.pam_selinux 2004-09-11 14:17:26.000000000 +0200
|
|
Jan F |
003cb0 |
+++ openssh-5.8p1/auth-pam.h 2011-02-12 10:49:57.000000000 +0100
|
|
Jan F. Chadima |
974c89 |
@@ -38,7 +38,7 @@ void do_pam_session(void);
|
|
Jan F. Chadima |
974c89 |
void do_pam_set_tty(const char *);
|
|
Jan F. Chadima |
974c89 |
void do_pam_setcred(int );
|
|
Jan F. Chadima |
974c89 |
void do_pam_chauthtok(void);
|
|
Jan F. Chadima |
974c89 |
-int do_pam_putenv(char *, char *);
|
|
Jan F. Chadima |
974c89 |
+int do_pam_putenv(char *, const char *);
|
|
Jan F. Chadima |
974c89 |
char ** fetch_pam_environment(void);
|
|
Jan F. Chadima |
974c89 |
char ** fetch_pam_child_environment(void);
|
|
Jan F. Chadima |
974c89 |
void free_pam_environment(char **);
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/openbsd-compat/port-linux.c.pam_selinux openssh-5.8p1/openbsd-compat/port-linux.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/openbsd-compat/port-linux.c.pam_selinux 2011-02-12 10:49:57.000000000 +0100
|
|
Jan F |
003cb0 |
+++ openssh-5.8p1/openbsd-compat/port-linux.c 2011-02-12 10:55:52.000000000 +0100
|
|
Jan F. Chadima |
974c89 |
@@ -36,6 +36,7 @@
|
|
Tomáš Mráz |
1961bc |
#include "hostfile.h"
|
|
Tomáš Mráz |
1961bc |
#include "auth.h"
|
|
Tomáš Mráz |
1961bc |
#include "xmalloc.h"
|
|
Tomáš Mráz |
1961bc |
+#include "servconf.h"
|
|
Tomáš Mráz |
1961bc |
|
|
Jan F. Chadima |
974c89 |
#ifdef WITH_SELINUX
|
|
Tomáš Mráz |
1961bc |
#include <selinux/selinux.h>
|
|
Jan F. Chadima |
974c89 |
@@ -50,6 +51,7 @@
|
|
Tomáš Mráz |
1961bc |
#include <unistd.h>
|
|
Tomáš Mráz |
1961bc |
#endif
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
+extern ServerOptions options;
|
|
Tomáš Mráz |
1961bc |
extern Authctxt *the_authctxt;
|
|
Tomáš Mráz |
1961bc |
extern int inetd_flag;
|
|
Tomáš Mráz |
1961bc |
extern int rexeced_flag;
|
|
Jan F |
003cb0 |
@@ -197,29 +199,38 @@ get_user_context(const char *sename, con
|
|
Jan F |
003cb0 |
return -1;
|
|
Tomáš Mráz |
1961bc |
}
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
+static void
|
|
Tomáš Mráz |
1961bc |
+ssh_selinux_get_role_level(char **role, const char **level)
|
|
Tomáš Mráz |
1961bc |
+{
|
|
Tomáš Mráz |
1961bc |
+ *role = NULL;
|
|
Tomáš Mráz |
1961bc |
+ *level = NULL;
|
|
Tomáš Mráz |
1961bc |
+ if (the_authctxt) {
|
|
Tomáš Mráz |
1961bc |
+ if (the_authctxt->role != NULL) {
|
|
Tomáš Mráz |
1961bc |
+ char *slash;
|
|
Tomáš Mráz |
1961bc |
+ *role = xstrdup(the_authctxt->role);
|
|
Tomáš Mráz |
1961bc |
+ if ((slash = strchr(*role, '/')) != NULL) {
|
|
Tomáš Mráz |
1961bc |
+ *slash = '\0';
|
|
Tomáš Mráz |
1961bc |
+ *level = slash + 1;
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+}
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
/* Return the default security context for the given username */
|
|
Tomáš Mráz |
1961bc |
static int
|
|
Tomáš Mráz |
1961bc |
ssh_selinux_getctxbyname(char *pwname,
|
|
Tomáš Mráz |
1961bc |
security_context_t *default_sc, security_context_t *user_sc)
|
|
Tomáš Mráz |
1961bc |
{
|
|
Tomáš Mráz |
1961bc |
char *sename, *lvl;
|
|
Tomáš Mráz |
1961bc |
- const char *reqlvl = NULL;
|
|
Tomáš Mráz |
1961bc |
- char *role = NULL;
|
|
Tomáš Mráz |
1961bc |
+ const char *reqlvl;
|
|
Tomáš Mráz |
1961bc |
+ char *role;
|
|
Tomáš Mráz |
1961bc |
int r = -1;
|
|
Tomáš Mráz |
1961bc |
context_t con = NULL;
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
*default_sc = NULL;
|
|
Tomáš Mráz |
1961bc |
*user_sc = NULL;
|
|
Tomáš Mráz |
1961bc |
- if (the_authctxt) {
|
|
Tomáš Mráz |
1961bc |
- if (the_authctxt->role != NULL) {
|
|
Tomáš Mráz |
1961bc |
- char *slash;
|
|
Tomáš Mráz |
1961bc |
- role = xstrdup(the_authctxt->role);
|
|
Tomáš Mráz |
1961bc |
- if ((slash = strchr(role, '/')) != NULL) {
|
|
Tomáš Mráz |
1961bc |
- *slash = '\0';
|
|
Tomáš Mráz |
1961bc |
- reqlvl = slash + 1;
|
|
Tomáš Mráz |
1961bc |
- }
|
|
Tomáš Mráz |
1961bc |
- }
|
|
Tomáš Mráz |
1961bc |
- }
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ ssh_selinux_get_role_level(&role, &reqlvl);
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
#ifdef HAVE_GETSEUSERBYNAME
|
|
Tomáš Mráz |
1961bc |
if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
|
|
Jan F |
003cb0 |
@@ -300,6 +311,36 @@ ssh_selinux_getctxbyname(char *pwname,
|
|
Tomáš Mráz |
1961bc |
return (r);
|
|
Tomáš Mráz |
1961bc |
}
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
+/* Setup environment variables for pam_selinux */
|
|
Tomáš Mráz |
1961bc |
+static int
|
|
Tomáš Mráz |
1961bc |
+ssh_selinux_setup_pam_variables(void)
|
|
Tomáš Mráz |
1961bc |
+{
|
|
Tomáš Mráz |
1961bc |
+ const char *reqlvl;
|
|
Tomáš Mráz |
1961bc |
+ char *role;
|
|
Tomáš Mráz |
1961bc |
+ char *use_current;
|
|
Tomáš Mráz |
1961bc |
+ int rv;
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ debug3("%s: setting execution context", __func__);
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ ssh_selinux_get_role_level(&role, &reqlvl);
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ rv = do_pam_putenv("SELINUX_ROLE_REQUESTED", role ? role : "");
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ if (inetd_flag && !rexeced_flag) {
|
|
Tomáš Mráz |
1961bc |
+ use_current = "1";
|
|
Tomáš Mráz |
1961bc |
+ } else {
|
|
Tomáš Mráz |
1961bc |
+ use_current = "";
|
|
Tomáš Mráz |
1961bc |
+ rv = rv || do_pam_putenv("SELINUX_LEVEL_REQUESTED", reqlvl ? reqlvl: "");
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ rv = rv || do_pam_putenv("SELINUX_USE_CURRENT_RANGE", use_current);
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ if (role != NULL)
|
|
Tomáš Mráz |
1961bc |
+ xfree(role);
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
+ return rv;
|
|
Tomáš Mráz |
1961bc |
+}
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
/* Set the execution context to the default for the specified user */
|
|
Tomáš Mráz |
1961bc |
void
|
|
Tomáš Mráz |
1961bc |
ssh_selinux_setup_exec_context(char *pwname)
|
|
Jan F |
003cb0 |
@@ -311,6 +352,24 @@ ssh_selinux_setup_exec_context(char *pwn
|
|
Tomáš Mráz |
1961bc |
if (!ssh_selinux_enabled())
|
|
Tomáš Mráz |
1961bc |
return;
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
+ if (options.use_pam) {
|
|
Tomáš Mráz |
1961bc |
+ /* do not compute context, just setup environment for pam_selinux */
|
|
Tomáš Mráz |
1961bc |
+ if (ssh_selinux_setup_pam_variables()) {
|
|
Tomáš Mráz |
1961bc |
+ switch (security_getenforce()) {
|
|
Tomáš Mráz |
1961bc |
+ case -1:
|
|
Tomáš Mráz |
1961bc |
+ fatal("%s: security_getenforce() failed", __func__);
|
|
Tomáš Mráz |
1961bc |
+ case 0:
|
|
Tomáš Mráz |
1961bc |
+ error("%s: SELinux PAM variable setup failure. Continuing in permissive mode.",
|
|
Tomáš Mráz |
1961bc |
+ __func__);
|
|
Tomáš Mráz |
1961bc |
+ break;
|
|
Tomáš Mráz |
1961bc |
+ default:
|
|
Tomáš Mráz |
1961bc |
+ fatal("%s: SELinux PAM variable setup failure. Aborting connection.",
|
|
Tomáš Mráz |
1961bc |
+ __func__);
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+ return;
|
|
Tomáš Mráz |
1961bc |
+ }
|
|
Tomáš Mráz |
1961bc |
+
|
|
Tomáš Mráz |
1961bc |
debug3("%s: setting execution context", __func__);
|
|
Tomáš Mráz |
1961bc |
|
|
Tomáš Mráz |
1961bc |
r = ssh_selinux_getctxbyname(pwname, &default_ctx, &user_ctx);
|