rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
Petr Šabata 81d24c
diff -up openssh/auth2-pubkey.c.refactor openssh/auth2-pubkey.c
Petr Šabata 81d24c
--- openssh/auth2-pubkey.c.refactor	2019-04-04 13:19:12.188821236 +0200
Petr Šabata 81d24c
+++ openssh/auth2-pubkey.c	2019-04-04 13:19:12.276822078 +0200
Petr Šabata 81d24c
@@ -72,6 +72,9 @@
Petr Šabata 81d24c
 extern ServerOptions options;
Petr Šabata 81d24c
 extern u_char *session_id2;
Petr Šabata 81d24c
 extern u_int session_id2_len;
Petr Šabata 81d24c
+extern int inetd_flag;
Petr Šabata 81d24c
+extern int rexeced_flag;
Petr Šabata 81d24c
+extern Authctxt *the_authctxt;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 static char *
Petr Šabata 81d24c
 format_key(const struct sshkey *key)
Petr Šabata 81d24c
@@ -511,7 +514,8 @@ match_principals_command(struct ssh *ssh
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	if ((pid = subprocess("AuthorizedPrincipalsCommand", runas_pw, command,
Petr Šabata 81d24c
 	    ac, av, &f,
Petr Šabata 81d24c
-	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD)) == 0)
Petr Šabata 81d24c
+	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD,
Petr Šabata 81d24c
+	    (inetd_flag && !rexeced_flag), the_authctxt)) == 0)
Petr Šabata 81d24c
 		goto out;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	uid_swapped = 1;
Petr Šabata 81d24c
@@ -981,7 +985,8 @@ user_key_command_allowed2(struct ssh *ss
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	if ((pid = subprocess("AuthorizedKeysCommand", runas_pw, command,
Petr Šabata 81d24c
 	    ac, av, &f,
Petr Šabata 81d24c
-	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD)) == 0)
Petr Šabata 81d24c
+	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD,
Petr Šabata 81d24c
+	    (inetd_flag && !rexeced_flag), the_authctxt)) == 0)
Petr Šabata 81d24c
 		goto out;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	uid_swapped = 1;
Petr Šabata 81d24c
diff -up openssh/auth.c.refactor openssh/auth.c
Petr Šabata 81d24c
--- openssh/auth.c.refactor	2019-04-04 13:19:12.235821686 +0200
Petr Šabata 81d24c
+++ openssh/auth.c	2019-04-04 13:19:12.276822078 +0200
Petr Šabata 81d24c
@@ -756,7 +756,8 @@ auth_get_canonical_hostname(struct ssh *
Petr Šabata 81d24c
  */
Petr Šabata 81d24c
 pid_t
Petr Šabata 81d24c
 subprocess(const char *tag, struct passwd *pw, const char *command,
Petr Šabata 81d24c
-    int ac, char **av, FILE **child, u_int flags)
Petr Šabata 81d24c
+    int ac, char **av, FILE **child, u_int flags, int inetd,
Petr Šabata 81d24c
+    void *the_authctxt)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
 	FILE *f = NULL;
Petr Šabata 81d24c
 	struct stat st;
Petr Šabata 81d24c
@@ -872,7 +873,7 @@ subprocess(const char *tag, struct passw
Petr Šabata 81d24c
 		}
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #ifdef WITH_SELINUX
Petr Šabata 81d24c
-		if (sshd_selinux_setup_env_variables() < 0) {
Petr Šabata 81d24c
+		if (sshd_selinux_setup_env_variables(inetd, the_authctxt) < 0) {
Petr Šabata 81d24c
 			error ("failed to copy environment:  %s",
Petr Šabata 81d24c
 			    strerror(errno));
Petr Šabata 81d24c
 			_exit(127);
Petr Šabata 81d24c
diff -up openssh/auth.h.refactor openssh/auth.h
Petr Šabata 81d24c
--- openssh/auth.h.refactor	2019-04-04 13:19:12.251821839 +0200
Petr Šabata 81d24c
+++ openssh/auth.h	2019-04-04 13:19:12.276822078 +0200
Petr Šabata 81d24c
@@ -235,7 +235,7 @@ struct passwd *fakepw(void);
Petr Šabata 81d24c
 #define	SSH_SUBPROCESS_STDOUT_CAPTURE  (1<<1)  /* Redirect stdout */
Petr Šabata 81d24c
 #define	SSH_SUBPROCESS_STDERR_DISCARD  (1<<2)  /* Discard stderr */
Petr Šabata 81d24c
 pid_t	subprocess(const char *, struct passwd *,
Petr Šabata 81d24c
-    const char *, int, char **, FILE **, u_int flags);
Petr Šabata 81d24c
+    const char *, int, char **, FILE **, u_int flags, int, void *);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 int	 sys_auth_passwd(struct ssh *, const char *);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
diff -up openssh/openbsd-compat/port-linux.h.refactor openssh/openbsd-compat/port-linux.h
Petr Šabata 81d24c
--- openssh/openbsd-compat/port-linux.h.refactor	2019-04-04 13:19:12.256821887 +0200
Petr Šabata 81d24c
+++ openssh/openbsd-compat/port-linux.h	2019-04-04 13:19:12.276822078 +0200
Petr Šabata 81d24c
@@ -26,8 +26,8 @@ void ssh_selinux_setfscreatecon(const ch
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 int sshd_selinux_enabled(void);
Petr Šabata 81d24c
 void sshd_selinux_copy_context(void);
Petr Šabata 81d24c
-void sshd_selinux_setup_exec_context(char *);
Petr Šabata 81d24c
-int sshd_selinux_setup_env_variables(void);
Petr Šabata 81d24c
+void sshd_selinux_setup_exec_context(char *, int, int(char *, const char *), void *, int);
Petr Šabata 81d24c
+int sshd_selinux_setup_env_variables(int inetd, void *);
Petr Šabata 81d24c
 void sshd_selinux_change_privsep_preauth_context(void);
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 
Petr Šabata 81d24c
diff -up openssh/openbsd-compat/port-linux-sshd.c.refactor openssh/openbsd-compat/port-linux-sshd.c
Petr Šabata 81d24c
--- openssh/openbsd-compat/port-linux-sshd.c.refactor	2019-04-04 13:19:12.256821887 +0200
Petr Šabata 81d24c
+++ openssh/openbsd-compat/port-linux-sshd.c	2019-04-04 13:19:12.276822078 +0200
Petr Šabata 81d24c
@@ -49,11 +49,6 @@
Petr Šabata 81d24c
 #include <unistd.h>
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-extern ServerOptions options;
Petr Šabata 81d24c
-extern Authctxt *the_authctxt;
Petr Šabata 81d24c
-extern int inetd_flag;
Petr Šabata 81d24c
-extern int rexeced_flag;
Petr Šabata 81d24c
-
Petr Šabata 81d24c
 /* Wrapper around is_selinux_enabled() to log its return value once only */
Petr Šabata 81d24c
 int
Petr Šabata 81d24c
 sshd_selinux_enabled(void)
Petr Šabata 81d24c
@@ -223,7 +218,8 @@ get_user_context(const char *sename, con
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 static void
Petr Šabata 81d24c
-ssh_selinux_get_role_level(char **role, const char **level)
Petr Šabata 81d24c
+ssh_selinux_get_role_level(char **role, const char **level,
Petr Šabata 81d24c
+    Authctxt *the_authctxt)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
 	*role = NULL;
Petr Šabata 81d24c
 	*level = NULL;
Petr Šabata 81d24c
@@ -241,8 +237,8 @@ ssh_selinux_get_role_level(char **role,
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 /* Return the default security context for the given username */
Petr Šabata 81d24c
 static int
Petr Šabata 81d24c
-sshd_selinux_getctxbyname(char *pwname,
Petr Šabata 81d24c
-	security_context_t *default_sc, security_context_t *user_sc)
Petr Šabata 81d24c
+sshd_selinux_getctxbyname(char *pwname, security_context_t *default_sc,
Petr Šabata 81d24c
+    security_context_t *user_sc, int inetd, Authctxt *the_authctxt)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
 	char *sename, *lvl;
Petr Šabata 81d24c
 	char *role;
Petr Šabata 81d24c
@@ -250,7 +246,7 @@ sshd_selinux_getctxbyname(char *pwname,
Petr Šabata 81d24c
 	int r = 0;
Petr Šabata 81d24c
 	context_t con = NULL;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-	ssh_selinux_get_role_level(&role, &reqlvl);
Petr Šabata 81d24c
+	ssh_selinux_get_role_level(&role, &reqlvl, the_authctxt);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #ifdef HAVE_GETSEUSERBYNAME
Petr Šabata 81d24c
 	if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
Petr Šabata 81d24c
@@ -272,7 +268,7 @@ sshd_selinux_getctxbyname(char *pwname,
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	if (r == 0) {
Petr Šabata 81d24c
 		/* If launched from xinetd, we must use current level */
Petr Šabata 81d24c
-		if (inetd_flag && !rexeced_flag) {
Petr Šabata 81d24c
+		if (inetd) {
Petr Šabata 81d24c
 			security_context_t sshdsc=NULL;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 			if (getcon_raw(&sshdsc) < 0)
Petr Šabata 81d24c
@@ -333,7 +329,8 @@ sshd_selinux_getctxbyname(char *pwname,
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 /* Setup environment variables for pam_selinux */
Petr Šabata 81d24c
 static int
Petr Šabata 81d24c
-sshd_selinux_setup_variables(int(*set_it)(char *, const char *))
Petr Šabata 81d24c
+sshd_selinux_setup_variables(int(*set_it)(char *, const char *), int inetd,
Petr Šabata 81d24c
+    Authctxt *the_authctxt)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
 	const char *reqlvl;
Petr Šabata 81d24c
 	char *role;
Petr Šabata 81d24c
@@ -342,11 +339,11 @@ sshd_selinux_setup_variables(int(*set_it
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	debug3("%s: setting execution context", __func__);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-	ssh_selinux_get_role_level(&role, &reqlvl);
Petr Šabata 81d24c
+	ssh_selinux_get_role_level(&role, &reqlvl, the_authctxt);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	rv = set_it("SELINUX_ROLE_REQUESTED", role ? role : "");
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-	if (inetd_flag && !rexeced_flag) {
Petr Šabata 81d24c
+	if (inetd) {
Petr Šabata 81d24c
 		use_current = "1";
Petr Šabata 81d24c
 	} else {
Petr Šabata 81d24c
 		use_current = "";
Petr Šabata 81d24c
@@ -362,9 +359,10 @@ sshd_selinux_setup_variables(int(*set_it
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 static int
Petr Šabata 81d24c
-sshd_selinux_setup_pam_variables(void)
Petr Šabata 81d24c
+sshd_selinux_setup_pam_variables(int inetd,
Petr Šabata 81d24c
+    int(pam_setenv)(char *, const char *), Authctxt *the_authctxt)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
-	return sshd_selinux_setup_variables(do_pam_putenv);
Petr Šabata 81d24c
+	return sshd_selinux_setup_variables(pam_setenv, inetd, the_authctxt);
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 static int
Petr Šabata 81d24c
@@ -374,25 +372,28 @@ do_setenv(char *name, const char *value)
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 int
Petr Šabata 81d24c
-sshd_selinux_setup_env_variables(void)
Petr Šabata 81d24c
+sshd_selinux_setup_env_variables(int inetd, void *the_authctxt)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
-	return sshd_selinux_setup_variables(do_setenv);
Petr Šabata 81d24c
+	Authctxt *authctxt = (Authctxt *) the_authctxt;
Petr Šabata 81d24c
+	return sshd_selinux_setup_variables(do_setenv, inetd, authctxt);
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 /* Set the execution context to the default for the specified user */
Petr Šabata 81d24c
 void
Petr Šabata 81d24c
-sshd_selinux_setup_exec_context(char *pwname)
Petr Šabata 81d24c
+sshd_selinux_setup_exec_context(char *pwname, int inetd,
Petr Šabata 81d24c
+    int(pam_setenv)(char *, const char *), void *the_authctxt, int use_pam)
Petr Šabata 81d24c
 {
Petr Šabata 81d24c
 	security_context_t user_ctx = NULL;
Petr Šabata 81d24c
 	int r = 0;
Petr Šabata 81d24c
 	security_context_t default_ctx = NULL;
Petr Šabata 81d24c
+	Authctxt *authctxt = (Authctxt *) the_authctxt;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	if (!sshd_selinux_enabled())
Petr Šabata 81d24c
 		return;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-	if (options.use_pam) {
Petr Šabata 81d24c
+	if (use_pam) {
Petr Šabata 81d24c
 		/* do not compute context, just setup environment for pam_selinux */
Petr Šabata 81d24c
-		if (sshd_selinux_setup_pam_variables()) {
Petr Šabata 81d24c
+		if (sshd_selinux_setup_pam_variables(inetd, pam_setenv, authctxt)) {
Petr Šabata 81d24c
 			switch (security_getenforce()) {
Petr Šabata 81d24c
 			case -1:
Petr Šabata 81d24c
 				fatal("%s: security_getenforce() failed", __func__);
Petr Šabata 81d24c
@@ -410,7 +411,7 @@ sshd_selinux_setup_exec_context(char *pw
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	debug3("%s: setting execution context", __func__);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-	r = sshd_selinux_getctxbyname(pwname, &default_ctx, &user_ctx);
Petr Šabata 81d24c
+	r = sshd_selinux_getctxbyname(pwname, &default_ctx, &user_ctx, inetd, authctxt);
Petr Šabata 81d24c
 	if (r >= 0) {
Petr Šabata 81d24c
 		r = setexeccon(user_ctx);
Petr Šabata 81d24c
 		if (r < 0) {
Petr Šabata 81d24c
diff -up openssh/platform.c.refactor openssh/platform.c
Petr Šabata 81d24c
--- openssh/platform.c.refactor	2019-04-04 13:19:12.204821389 +0200
Petr Šabata 81d24c
+++ openssh/platform.c	2019-04-04 13:19:12.277822088 +0200
Petr Šabata 81d24c
@@ -32,6 +32,9 @@
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 extern int use_privsep;
Petr Šabata 81d24c
 extern ServerOptions options;
Petr Šabata 81d24c
+extern int inetd_flag;
Petr Šabata 81d24c
+extern int rexeced_flag;
Petr Šabata 81d24c
+extern Authctxt *the_authctxt;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 void
Petr Šabata 81d24c
 platform_pre_listen(void)
Petr Šabata 81d24c
@@ -183,7 +186,9 @@ platform_setusercontext_post_groups(stru
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
 #endif /* HAVE_SETPCRED */
Petr Šabata 81d24c
 #ifdef WITH_SELINUX
Petr Šabata 81d24c
-	sshd_selinux_setup_exec_context(pw->pw_name);
Petr Šabata 81d24c
+	sshd_selinux_setup_exec_context(pw->pw_name,
Petr Šabata 81d24c
+	    (inetd_flag && !rexeced_flag), do_pam_putenv, the_authctxt,
Petr Šabata 81d24c
+	    options.use_pam);
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
diff -up openssh/sshd.c.refactor openssh/sshd.c
Petr Šabata 81d24c
--- openssh/sshd.c.refactor	2019-04-04 13:19:12.275822068 +0200
Petr Šabata 81d24c
+++ openssh/sshd.c	2019-04-04 13:19:51.270195262 +0200
Petr Šabata 81d24c
@@ -158,7 +158,7 @@ int debug_flag = 0;
Petr Šabata 81d24c
 static int test_flag = 0;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 /* Flag indicating that the daemon is being started from inetd. */
Petr Šabata 81d24c
-static int inetd_flag = 0;
Petr Šabata 81d24c
+int inetd_flag = 0;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 /* Flag indicating that sshd should not detach and become a daemon. */
Petr Šabata 81d24c
 static int no_daemon_flag = 0;
Petr Šabata 81d24c
@@ -171,7 +171,7 @@ static char **saved_argv;
Petr Šabata 81d24c
 static int saved_argc;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 /* re-exec */
Petr Šabata 81d24c
-static int rexeced_flag = 0;
Petr Šabata 81d24c
+int rexeced_flag = 0;
Petr Šabata 81d24c
 static int rexec_flag = 1;
Petr Šabata 81d24c
 static int rexec_argc = 0;
Petr Šabata 81d24c
 static char **rexec_argv;
Petr Šabata 81d24c
@@ -2192,7 +2192,9 @@ main(int ac, char **av)
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 #ifdef WITH_SELINUX
Petr Šabata 81d24c
-	sshd_selinux_setup_exec_context(authctxt->pw->pw_name);
Petr Šabata 81d24c
+	sshd_selinux_setup_exec_context(authctxt->pw->pw_name,
Petr Šabata 81d24c
+	    (inetd_flag && !rexeced_flag), do_pam_putenv, the_authctxt,
Petr Šabata 81d24c
+	    options.use_pam);
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 #ifdef USE_PAM
Petr Šabata 81d24c
 	if (options.use_pam) {