vishalmishra434 / rpms / openssh

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