vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
f5835d
diff -up openssh/auth2-pubkey.c.refactor openssh/auth2-pubkey.c
f5835d
--- openssh/auth2-pubkey.c.refactor	2017-09-27 13:10:19.556830609 +0200
f5835d
+++ openssh/auth2-pubkey.c	2017-09-27 13:10:19.677831274 +0200
f5835d
@@ -72,6 +72,9 @@
f5835d
 extern ServerOptions options;
f5835d
 extern u_char *session_id2;
f5835d
 extern u_int session_id2_len;
f5835d
+extern int inetd_flag;
f5835d
+extern int rexeced_flag;
f5835d
+extern Authctxt *the_authctxt;
f5835d
 
f5835d
 static char *
f5835d
 format_key(const struct sshkey *key)
f5835d
@@ -432,7 +435,8 @@ match_principals_command(struct passwd *
f5835d
 
f5835d
 	if ((pid = subprocess("AuthorizedPrincipalsCommand", runas_pw, command,
f5835d
 	    ac, av, &f,
f5835d
-	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD)) == 0)
f5835d
+	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD,
f5835d
+	    (inetd_flag && !rexeced_flag), the_authctxt)) == 0)
f5835d
 		goto out;
f5835d
 
f5835d
 	uid_swapped = 1;
f5835d
@@ -762,7 +766,8 @@ user_key_command_allowed2(struct passwd
f5835d
 
f5835d
 	if ((pid = subprocess("AuthorizedKeysCommand", runas_pw, command,
f5835d
 	    ac, av, &f,
f5835d
-	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD)) == 0)
f5835d
+	    SSH_SUBPROCESS_STDOUT_CAPTURE|SSH_SUBPROCESS_STDERR_DISCARD,
f5835d
+	    (inetd_flag && !rexeced_flag), the_authctxt)) == 0)
f5835d
 		goto out;
f5835d
 
f5835d
 	uid_swapped = 1;
f5835d
diff -up openssh/auth.c.refactor openssh/auth.c
f5835d
--- openssh/auth.c.refactor	2017-09-27 13:10:19.640831071 +0200
f5835d
+++ openssh/auth.c	2017-09-27 13:10:19.678831279 +0200
f5835d
@@ -1435,7 +1435,8 @@ argv_assemble(int argc, char **argv)
f5835d
  */
f5835d
 pid_t
f5835d
 subprocess(const char *tag, struct passwd *pw, const char *command,
f5835d
-    int ac, char **av, FILE **child, u_int flags)
f5835d
+    int ac, char **av, FILE **child, u_int flags, int inetd,
f5835d
+    void *the_authctxt)
f5835d
 {
f5835d
 	FILE *f = NULL;
f5835d
 	struct stat st;
f5835d
@@ -1551,7 +1552,7 @@ subprocess(const char *tag, struct passw
f5835d
 		}
f5835d
 
f5835d
 #ifdef WITH_SELINUX
f5835d
-		if (sshd_selinux_setup_env_variables() < 0) {
f5835d
+		if (sshd_selinux_setup_env_variables(inetd, the_authctxt) < 0) {
f5835d
 			error ("failed to copy environment:  %s",
f5835d
 			    strerror(errno));
f5835d
 			_exit(127);
f5835d
diff -up openssh/auth.h.refactor openssh/auth.h
f5835d
--- openssh/auth.h.refactor	2017-09-25 01:48:10.000000000 +0200
f5835d
+++ openssh/auth.h	2017-09-27 13:10:19.678831279 +0200
f5835d
@@ -144,7 +144,7 @@ int	 exited_cleanly(pid_t, const char *,
f5835d
 #define	SSH_SUBPROCESS_STDOUT_CAPTURE  (1<<1)  /* Redirect stdout */
f5835d
 #define	SSH_SUBPROCESS_STDERR_DISCARD  (1<<2)  /* Discard stderr */
f5835d
 pid_t	subprocess(const char *, struct passwd *,
f5835d
-    const char *, int, char **, FILE **, u_int flags);
f5835d
+    const char *, int, char **, FILE **, u_int flags, int, void *);
f5835d
 
f5835d
 int	 sys_auth_passwd(struct ssh *, const char *);
f5835d
 
f5835d
diff -up openssh/openbsd-compat/port-linux.h.refactor openssh/openbsd-compat/port-linux.h
f5835d
--- openssh/openbsd-compat/port-linux.h.refactor	2017-09-27 13:10:19.634831038 +0200
f5835d
+++ openssh/openbsd-compat/port-linux.h	2017-09-27 13:10:54.954025248 +0200
f5835d
@@ -26,8 +26,8 @@ void ssh_selinux_setfscreatecon(const ch
f5835d
 
f5835d
 int sshd_selinux_enabled(void);
f5835d
 void sshd_selinux_copy_context(void);
f5835d
-void sshd_selinux_setup_exec_context(char *);
f5835d
-int sshd_selinux_setup_env_variables(void);
f5835d
+void sshd_selinux_setup_exec_context(char *, int, int(char *, const char *), void *, int);
f5835d
+int sshd_selinux_setup_env_variables(int inetd, void *);
f5835d
 void sshd_selinux_change_privsep_preauth_context(void);
f5835d
 #endif
f5835d
 
f5835d
diff -up openssh/openbsd-compat/port-linux-sshd.c.refactor openssh/openbsd-compat/port-linux-sshd.c
f5835d
--- openssh/openbsd-compat/port-linux-sshd.c.refactor	2017-09-27 13:10:19.634831038 +0200
f5835d
+++ openssh/openbsd-compat/port-linux-sshd.c	2017-09-27 13:12:06.811420371 +0200
f5835d
@@ -48,11 +48,6 @@
f5835d
 #include <unistd.h>
f5835d
 #endif
f5835d
 
f5835d
-extern ServerOptions options;
f5835d
-extern Authctxt *the_authctxt;
f5835d
-extern int inetd_flag;
f5835d
-extern int rexeced_flag;
f5835d
-
f5835d
 /* Wrapper around is_selinux_enabled() to log its return value once only */
f5835d
 int
f5835d
 sshd_selinux_enabled(void)
f5835d
@@ -222,7 +217,8 @@ get_user_context(const char *sename, con
f5835d
 }
f5835d
 
f5835d
 static void
f5835d
-ssh_selinux_get_role_level(char **role, const char **level)
f5835d
+ssh_selinux_get_role_level(char **role, const char **level,
f5835d
+    Authctxt *the_authctxt)
f5835d
 {
f5835d
 	*role = NULL;
f5835d
 	*level = NULL;
f5835d
@@ -240,8 +236,8 @@ ssh_selinux_get_role_level(char **role,
f5835d
 
f5835d
 /* Return the default security context for the given username */
f5835d
 static int
f5835d
-sshd_selinux_getctxbyname(char *pwname,
f5835d
-	security_context_t *default_sc, security_context_t *user_sc)
f5835d
+sshd_selinux_getctxbyname(char *pwname, security_context_t *default_sc,
f5835d
+    security_context_t *user_sc, int inetd, Authctxt *the_authctxt)
f5835d
 {
f5835d
 	char *sename, *lvl;
f5835d
 	char *role;
f5835d
@@ -249,7 +245,7 @@ sshd_selinux_getctxbyname(char *pwname,
f5835d
 	int r = 0;
f5835d
 	context_t con = NULL;
f5835d
 
f5835d
-	ssh_selinux_get_role_level(&role, &reqlvl);
f5835d
+	ssh_selinux_get_role_level(&role, &reqlvl, the_authctxt);
f5835d
 
f5835d
 #ifdef HAVE_GETSEUSERBYNAME
f5835d
 	if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
f5835d
@@ -271,7 +267,7 @@ sshd_selinux_getctxbyname(char *pwname,
f5835d
 
f5835d
 	if (r == 0) {
f5835d
 		/* If launched from xinetd, we must use current level */
f5835d
-		if (inetd_flag && !rexeced_flag) {
f5835d
+		if (inetd) {
f5835d
 			security_context_t sshdsc=NULL;
f5835d
 
f5835d
 			if (getcon_raw(&sshdsc) < 0)
f5835d
@@ -332,7 +328,8 @@ sshd_selinux_getctxbyname(char *pwname,
f5835d
 
f5835d
 /* Setup environment variables for pam_selinux */
f5835d
 static int
f5835d
-sshd_selinux_setup_variables(int(*set_it)(char *, const char *))
f5835d
+sshd_selinux_setup_variables(int(*set_it)(char *, const char *), int inetd,
f5835d
+    Authctxt *the_authctxt)
f5835d
 {
f5835d
 	const char *reqlvl;
f5835d
 	char *role;
f5835d
@@ -341,11 +338,11 @@ sshd_selinux_setup_variables(int(*set_it
f5835d
 
f5835d
 	debug3("%s: setting execution context", __func__);
f5835d
 
f5835d
-	ssh_selinux_get_role_level(&role, &reqlvl);
f5835d
+	ssh_selinux_get_role_level(&role, &reqlvl, the_authctxt);
f5835d
 
f5835d
 	rv = set_it("SELINUX_ROLE_REQUESTED", role ? role : "");
f5835d
 
f5835d
-	if (inetd_flag && !rexeced_flag) {
f5835d
+	if (inetd) {
f5835d
 		use_current = "1";
f5835d
 	} else {
f5835d
 		use_current = "";
f5835d
@@ -361,9 +358,10 @@ sshd_selinux_setup_variables(int(*set_it
f5835d
 }
f5835d
 
f5835d
 static int
f5835d
-sshd_selinux_setup_pam_variables(void)
f5835d
+sshd_selinux_setup_pam_variables(int inetd,
f5835d
+    int(pam_setenv)(char *, const char *), Authctxt *the_authctxt)
f5835d
 {
f5835d
-	return sshd_selinux_setup_variables(do_pam_putenv);
f5835d
+	return sshd_selinux_setup_variables(pam_setenv, inetd, the_authctxt);
f5835d
 }
f5835d
 
f5835d
 static int
f5835d
@@ -373,25 +371,28 @@ do_setenv(char *name, const char *value)
f5835d
 }
f5835d
 
f5835d
 int
f5835d
-sshd_selinux_setup_env_variables(void)
f5835d
+sshd_selinux_setup_env_variables(int inetd, void *the_authctxt)
f5835d
 {
f5835d
-	return sshd_selinux_setup_variables(do_setenv);
f5835d
+	Authctxt *authctxt = (Authctxt *) the_authctxt;
f5835d
+	return sshd_selinux_setup_variables(do_setenv, inetd, authctxt);
f5835d
 }
f5835d
 
f5835d
 /* Set the execution context to the default for the specified user */
f5835d
 void
f5835d
-sshd_selinux_setup_exec_context(char *pwname)
f5835d
+sshd_selinux_setup_exec_context(char *pwname, int inetd,
f5835d
+    int(pam_setenv)(char *, const char *), void *the_authctxt, int use_pam)
f5835d
 {
f5835d
 	security_context_t user_ctx = NULL;
f5835d
 	int r = 0;
f5835d
 	security_context_t default_ctx = NULL;
f5835d
+	Authctxt *authctxt = (Authctxt *) the_authctxt;
f5835d
 
f5835d
 	if (!sshd_selinux_enabled())
f5835d
 		return;
f5835d
 
f5835d
-	if (options.use_pam) {
f5835d
+	if (use_pam) {
f5835d
 		/* do not compute context, just setup environment for pam_selinux */
f5835d
-		if (sshd_selinux_setup_pam_variables()) {
f5835d
+		if (sshd_selinux_setup_pam_variables(inetd, pam_setenv, authctxt)) {
f5835d
 			switch (security_getenforce()) {
f5835d
 			case -1:
f5835d
 				fatal("%s: security_getenforce() failed", __func__);
f5835d
@@ -409,7 +410,7 @@ sshd_selinux_setup_exec_context(char *pw
f5835d
 
f5835d
 	debug3("%s: setting execution context", __func__);
f5835d
 
f5835d
-	r = sshd_selinux_getctxbyname(pwname, &default_ctx, &user_ctx);
f5835d
+	r = sshd_selinux_getctxbyname(pwname, &default_ctx, &user_ctx, inetd, authctxt);
f5835d
 	if (r >= 0) {
f5835d
 		r = setexeccon(user_ctx);
f5835d
 		if (r < 0) {
f5835d
diff -up openssh/platform.c.refactor openssh/platform.c
f5835d
--- openssh/platform.c.refactor	2017-09-27 13:10:19.574830708 +0200
f5835d
+++ openssh/platform.c	2017-09-27 13:11:45.475303050 +0200
f5835d
@@ -33,6 +33,9 @@
f5835d
 
f5835d
 extern int use_privsep;
f5835d
 extern ServerOptions options;
f5835d
+extern int inetd_flag;
f5835d
+extern int rexeced_flag;
f5835d
+extern Authctxt *the_authctxt;
f5835d
 
f5835d
 void
f5835d
 platform_pre_listen(void)
f5835d
@@ -184,7 +187,9 @@ platform_setusercontext_post_groups(stru
f5835d
 	}
f5835d
 #endif /* HAVE_SETPCRED */
f5835d
 #ifdef WITH_SELINUX
f5835d
-	sshd_selinux_setup_exec_context(pw->pw_name);
f5835d
+	sshd_selinux_setup_exec_context(pw->pw_name,
f5835d
+	    (inetd_flag && !rexeced_flag), do_pam_putenv, the_authctxt,
f5835d
+	    options.use_pam);
f5835d
 #endif
f5835d
 }
f5835d
 
f5835d
diff -up openssh/sshd.c.refactor openssh/sshd.c
f5835d
--- openssh/sshd.c.refactor	2017-09-27 13:10:19.674831257 +0200
f5835d
+++ openssh/sshd.c	2017-09-27 13:12:01.635391909 +0200
f5835d
@@ -2135,7 +2135,9 @@ main(int ac, char **av)
f5835d
 	}
f5835d
 #endif
f5835d
 #ifdef WITH_SELINUX
f5835d
-	sshd_selinux_setup_exec_context(authctxt->pw->pw_name);
f5835d
+	sshd_selinux_setup_exec_context(authctxt->pw->pw_name,
f5835d
+	    (inetd_flag && !rexeced_flag), do_pam_putenv, the_authctxt,
f5835d
+	    options.use_pam);
f5835d
 #endif
f5835d
 #ifdef USE_PAM
f5835d
 	if (options.use_pam) {