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 @@
DistroBaker d029bb
 
DistroBaker d029bb
 /* import */
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
 static char *
Petr Šabata 81d24c
 format_key(const struct sshkey *key)
Petr Šabata 81d24c
@@ -511,7 +514,8 @@ match_principals_command(struct ssh *ssh
DistroBaker d029bb
 	if ((pid = subprocess("AuthorizedPrincipalsCommand", command,
Petr Šabata 81d24c
 	    ac, av, &f,
DistroBaker d029bb
 	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD,
DistroBaker d029bb
-	    runas_pw, temporarily_use_uid, restore_uid)) == 0)
DistroBaker d029bb
+	    runas_pw, temporarily_use_uid, restore_uid,
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
DistroBaker d029bb
 	if ((pid = subprocess("AuthorizedKeysCommand", command,
Petr Šabata 81d24c
 	    ac, av, &f,
DistroBaker d029bb
	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD,
DistroBaker d029bb
-	    runas_pw, temporarily_use_uid, restore_uid)) == 0)
DistroBaker d029bb
+	    runas_pw, temporarily_use_uid, restore_uid,
Petr Šabata 81d24c
+	    (inetd_flag && !rexeced_flag), the_authctxt)) == 0)
Petr Šabata 81d24c
 		goto out;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	uid_swapped = 1;
DistroBaker d029bb
diff -up openssh/misc.c.refactor openssh/misc.c
DistroBaker d029bb
--- openssh/misc.c.refactor	2019-04-04 13:19:12.235821686 +0200
DistroBaker d029bb
+++ openssh/misc.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
 pid_t
DistroBaker d029bb
 subprocess(const char *tag, const char *command,
DistroBaker d029bb
     int ac, char **av, FILE **child, u_int flags,
DistroBaker d029bb
-    struct passwd *pw, privdrop_fn *drop_privs, privrestore_fn *restore_privs)
DistroBaker d029bb
+    struct passwd *pw, privdrop_fn *drop_privs,
DistroBaker d029bb
+    privrestore_fn *restore_privs, int inetd, 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
DistroBaker d029bb
 			_exit(1);
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);
DistroBaker d029bb
diff -up openssh/misc.h.refactor openssh/misc.h
DistroBaker d029bb
--- openssh/misc.h.refactor	2019-04-04 13:19:12.251821839 +0200
DistroBaker d029bb
+++ openssh/misc.h	2019-04-04 13:19:12.276822078 +0200
Petr Šabata 81d24c
@@ -235,7 +235,7 @@ struct passwd *fakepw(void);
DistroBaker d029bb
 #define	SSH_SUBPROCESS_UNSAFE_PATH	(1<<3)	/* Don't check for safe cmd */
DistroBaker d029bb
 #define	SSH_SUBPROCESS_PRESERVE_ENV	(1<<4)	/* Keep parent environment */
DistroBaker d029bb
 pid_t subprocess(const char *, const char *, int, char **, FILE **, u_int,
DistroBaker d029bb
-    struct passwd *, privdrop_fn *, privrestore_fn *);
DistroBaker d029bb
+    struct passwd *, privdrop_fn *, privrestore_fn *, int, void *);
DistroBaker d029bb
 
DistroBaker d029bb
 typedef struct arglist arglist;
DistroBaker d029bb
 struct arglist {
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
 
DistroBaker d029bb
 	debug3_f("setting execution context");
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:
DistroBaker d029bb
 				fatal_f("security_getenforce() failed");
Petr Šabata 81d24c
@@ -410,7 +411,7 @@ sshd_selinux_setup_exec_context(char *pw
Petr Šabata 81d24c
 
DistroBaker d029bb
 	debug3_f("setting execution context");
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) {
DistroBaker d029bb
diff -up openssh/sshconnect.c.refactor openssh/sshconnect.c
DistroBaker d029bb
--- openssh/sshconnect.c.refactor	2021-02-24 00:12:03.065325046 +0100
DistroBaker d029bb
+++ openssh/sshconnect.c	2021-02-24 00:12:12.126449544 +0100
DistroBaker d029bb
@@ -892,7 +892,7 @@ load_hostkeys_command(struct hostkeys *h
DistroBaker d029bb
 
DistroBaker d029bb
 	if ((pid = subprocess(tag, command, ac, av, &f,
DistroBaker d029bb
 	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_UNSAFE_PATH|
DistroBaker d029bb
-	    SSH_SUBPROCESS_PRESERVE_ENV, NULL, NULL, NULL)) == 0)
DistroBaker d029bb
+	    SSH_SUBPROCESS_PRESERVE_ENV, NULL, NULL, NULL, 0, NULL)) == 0)
DistroBaker d029bb
 		goto out;
DistroBaker d029bb
 
DistroBaker d029bb
 	load_hostkeys_file(hostkeys, hostfile_hostname, tag, f, 1);