rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
1d31ef
diff -up openssh-7.4p1/auth2.c.expose-pam openssh-7.4p1/auth2.c
1d31ef
--- openssh-7.4p1/auth2.c.expose-pam	2016-12-23 15:40:26.768447868 +0100
1d31ef
+++ openssh-7.4p1/auth2.c	2016-12-23 15:40:26.818447876 +0100
1d31ef
@@ -310,6 +310,7 @@ userauth_finish(Authctxt *authctxt, int
1d31ef
     const char *submethod)
1d31ef
 {
1d31ef
 	char *methods;
1d31ef
+	char *prev_auth_details;
1d31ef
 	int partial = 0;
1d31ef
 
1d31ef
 	if (!authctxt->valid && authenticated)
1d31ef
@@ -340,6 +341,18 @@ userauth_finish(Authctxt *authctxt, int
1d31ef
 	if (authctxt->postponed)
1d31ef
 		return;
1d31ef
 
1d31ef
+	if (authenticated || partial) {
1d31ef
+		prev_auth_details = authctxt->auth_details;
1d31ef
+		xasprintf(&authctxt->auth_details, "%s%s%s%s%s",
1d31ef
+		    prev_auth_details ? prev_auth_details : "",
1d31ef
+		    prev_auth_details ? ", " : "", method,
1d31ef
+		    authctxt->last_details ? ": " : "",
1d31ef
+		    authctxt->last_details ? authctxt->last_details : "");
1d31ef
+		free(prev_auth_details);
1d31ef
+	}
1d31ef
+	free(authctxt->last_details);
1d31ef
+	authctxt->last_details = NULL;
1d31ef
+
1d31ef
 #ifdef USE_PAM
1d31ef
 	if (options.use_pam && authenticated) {
1d31ef
 		if (!PRIVSEP(do_pam_account())) {
1d31ef
diff -up openssh-7.4p1/auth2-gss.c.expose-pam openssh-7.4p1/auth2-gss.c
1d31ef
--- openssh-7.4p1/auth2-gss.c.expose-pam	2016-12-23 15:40:26.769447868 +0100
1d31ef
+++ openssh-7.4p1/auth2-gss.c	2016-12-23 15:40:26.818447876 +0100
1d31ef
@@ -276,6 +276,9 @@ input_gssapi_exchange_complete(int type,
1d31ef
 	authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
1d31ef
 	    authctxt->pw));
1d31ef
 
1d31ef
+	if (authenticated)
1d31ef
+		authctxt->last_details = ssh_gssapi_get_displayname();
1d31ef
+
1d31ef
 	authctxt->postponed = 0;
1d31ef
 	dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
1d31ef
 	dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL);
1d31ef
@@ -322,6 +325,9 @@ input_gssapi_mic(int type, u_int32_t ple
1d31ef
 	else
1d31ef
 		logit("GSSAPI MIC check failed");
1d31ef
 
1d31ef
+	if (authenticated)
1d31ef
+		authctxt->last_details = ssh_gssapi_get_displayname();
1d31ef
+
1d31ef
 	buffer_free(&b);
1d31ef
 	if (micuser != authctxt->user)
1d31ef
 		free(micuser);
1d31ef
diff -up openssh-7.4p1/auth2-hostbased.c.expose-pam openssh-7.4p1/auth2-hostbased.c
1d31ef
--- openssh-7.4p1/auth2-hostbased.c.expose-pam	2016-12-23 15:40:26.731447862 +0100
1d31ef
+++ openssh-7.4p1/auth2-hostbased.c	2016-12-23 15:40:26.818447876 +0100
1d31ef
@@ -60,7 +60,7 @@ userauth_hostbased(Authctxt *authctxt)
1d31ef
 {
1d31ef
 	Buffer b;
1d31ef
 	Key *key = NULL;
1d31ef
-	char *pkalg, *cuser, *chost, *service;
1d31ef
+	char *pkalg, *cuser, *chost, *service, *pubkey;
1d31ef
 	u_char *pkblob, *sig;
1d31ef
 	u_int alen, blen, slen;
1d31ef
 	int pktype;
1d31ef
@@ -140,15 +140,21 @@ userauth_hostbased(Authctxt *authctxt)
1d31ef
 	buffer_dump(&b);
1d31ef
 #endif
1d31ef
 
1d31ef
-	pubkey_auth_info(authctxt, key,
1d31ef
-	    "client user \"%.100s\", client host \"%.100s\"", cuser, chost);
1d31ef
+	pubkey = sshkey_format_oneline(key, options.fingerprint_hash);
1d31ef
+	auth_info(authctxt,
1d31ef
+	    "%s, client user \"%.100s\", client host \"%.100s\"",
1d31ef
+	    pubkey, cuser, chost);
1d31ef
 
1d31ef
 	/* test for allowed key and correct signature */
1d31ef
 	authenticated = 0;
1d31ef
 	if (PRIVSEP(hostbased_key_allowed(authctxt->pw, cuser, chost, key)) &&
1d31ef
 	    PRIVSEP(key_verify(key, sig, slen, buffer_ptr(&b),
1d31ef
-			buffer_len(&b))) == 1)
1d31ef
+			buffer_len(&b))) == 1) {
1d31ef
 		authenticated = 1;
1d31ef
+		authctxt->last_details = pubkey;
1d31ef
+	} else {
1d31ef
+		free(pubkey);
1d31ef
+	}
1d31ef
 
1d31ef
 	buffer_free(&b);
1d31ef
 done:
1d31ef
diff -up openssh-7.4p1/auth2-pubkey.c.expose-pam openssh-7.4p1/auth2-pubkey.c
1d31ef
--- openssh-7.4p1/auth2-pubkey.c.expose-pam	2016-12-23 15:40:26.746447864 +0100
1d31ef
+++ openssh-7.4p1/auth2-pubkey.c	2016-12-23 15:40:26.819447876 +0100
1d31ef
@@ -79,7 +79,7 @@ userauth_pubkey(Authctxt *authctxt)
1d31ef
 {
1d31ef
 	Buffer b;
1d31ef
 	Key *key = NULL;
1d31ef
-	char *pkalg, *userstyle, *fp = NULL;
1d31ef
+	char *pkalg, *userstyle, *pubkey, *fp = NULL;
1d31ef
 	u_char *pkblob, *sig;
1d31ef
 	u_int alen, blen, slen;
1d31ef
 	int have_sig, pktype;
1d31ef
@@ -177,7 +177,8 @@ userauth_pubkey(Authctxt *authctxt)
1d31ef
 #ifdef DEBUG_PK
1d31ef
 		buffer_dump(&b);
1d31ef
 #endif
1d31ef
-		pubkey_auth_info(authctxt, key, NULL);
1d31ef
+		pubkey = sshkey_format_oneline(key, options.fingerprint_hash);
1d31ef
+		auth_info(authctxt, "%s", pubkey);
1d31ef
 
1d31ef
 		/* test for correct signature */
1d31ef
 		authenticated = 0;
1d31ef
@@ -185,9 +186,12 @@ userauth_pubkey(Authctxt *authctxt)
1d31ef
 		    PRIVSEP(key_verify(key, sig, slen, buffer_ptr(&b),
1d31ef
 		    buffer_len(&b))) == 1) {
1d31ef
 			authenticated = 1;
1d31ef
+			authctxt->last_details = pubkey;
1d31ef
 			/* Record the successful key to prevent reuse */
1d31ef
 			auth2_record_userkey(authctxt, key);
1d31ef
 			key = NULL; /* Don't free below */
1d31ef
+		} else {
1d31ef
+			free(pubkey);
1d31ef
 		}
1d31ef
 		buffer_free(&b);
1d31ef
 		free(sig);
1d31ef
@@ -228,7 +232,7 @@ done:
1d31ef
 void
1d31ef
 pubkey_auth_info(Authctxt *authctxt, const Key *key, const char *fmt, ...)
1d31ef
 {
1d31ef
-	char *fp, *extra;
1d31ef
+	char *extra, *pubkey;
1d31ef
 	va_list ap;
1d31ef
 	int i;
1d31ef
 
1d31ef
@@ -238,27 +242,13 @@ pubkey_auth_info(Authctxt *authctxt, con
1d31ef
 		i = vasprintf(&extra, fmt, ap);
1d31ef
 		va_end(ap);
1d31ef
 		if (i < 0 || extra == NULL)
1d31ef
-			fatal("%s: vasprintf failed", __func__);	
1d31ef
+			fatal("%s: vasprintf failed", __func__);
1d31ef
 	}
1d31ef
 
1d31ef
-	if (key_is_cert(key)) {
1d31ef
-		fp = sshkey_fingerprint(key->cert->signature_key,
1d31ef
-		    options.fingerprint_hash, SSH_FP_DEFAULT);
1d31ef
-		auth_info(authctxt, "%s ID %s (serial %llu) CA %s %s%s%s", 
1d31ef
-		    key_type(key), key->cert->key_id,
1d31ef
-		    (unsigned long long)key->cert->serial,
1d31ef
-		    key_type(key->cert->signature_key),
1d31ef
-		    fp == NULL ? "(null)" : fp,
1d31ef
-		    extra == NULL ? "" : ", ", extra == NULL ? "" : extra);
1d31ef
-		free(fp);
1d31ef
-	} else {
1d31ef
-		fp = sshkey_fingerprint(key, options.fingerprint_hash,
1d31ef
-		    SSH_FP_DEFAULT);
1d31ef
-		auth_info(authctxt, "%s %s%s%s", key_type(key),
1d31ef
-		    fp == NULL ? "(null)" : fp,
1d31ef
-		    extra == NULL ? "" : ", ", extra == NULL ? "" : extra);
1d31ef
-		free(fp);
1d31ef
-	}
1d31ef
+	pubkey = sshkey_format_oneline(key, options.fingerprint_hash);
1d31ef
+	auth_info(authctxt, "%s%s%s", pubkey, extra == NULL ? "" : ", ",
1d31ef
+	    extra == NULL ? "" : extra);
1d31ef
+	free(pubkey);
1d31ef
 	free(extra);
1d31ef
 }
1d31ef
 
1d31ef
diff -up openssh-7.4p1/auth.h.expose-pam openssh-7.4p1/auth.h
1d31ef
--- openssh-7.4p1/auth.h.expose-pam	2016-12-23 15:40:26.782447870 +0100
1d31ef
+++ openssh-7.4p1/auth.h	2016-12-23 15:40:26.819447876 +0100
1d31ef
@@ -84,6 +84,9 @@ struct Authctxt {
1d31ef
 
1d31ef
 	struct sshkey	**prev_userkeys;
1d31ef
 	u_int		 nprev_userkeys;
1d31ef
+
1d31ef
+	char		*last_details;
1d31ef
+	char		*auth_details;
1d31ef
 };
1d31ef
 /*
1d31ef
  * Every authentication method has to handle authentication requests for
1d31ef
diff -up openssh-7.4p1/auth-pam.c.expose-pam openssh-7.4p1/auth-pam.c
1d31ef
--- openssh-7.4p1/auth-pam.c.expose-pam	2016-12-23 15:40:26.731447862 +0100
1d31ef
+++ openssh-7.4p1/auth-pam.c	2016-12-23 15:40:26.819447876 +0100
1d31ef
@@ -688,6 +688,11 @@ sshpam_init_ctx(Authctxt *authctxt)
1d31ef
 		return (NULL);
1d31ef
 	}
1d31ef
 
1d31ef
+	/* Notify PAM about any already successful auth methods */
1d31ef
+	if (options.expose_auth_methods >= EXPOSE_AUTHMETH_PAMONLY &&
1d31ef
+			authctxt->auth_details)
1d31ef
+		do_pam_putenv("SSH_USER_AUTH", authctxt->auth_details);
1d31ef
+
1d31ef
 	ctxt = xcalloc(1, sizeof *ctxt);
1d31ef
 
1d31ef
 	/* Start the authentication thread */
1d31ef
diff -up openssh-7.4p1/gss-serv.c.expose-pam openssh-7.4p1/gss-serv.c
1d31ef
--- openssh-7.4p1/gss-serv.c.expose-pam	2016-12-23 15:40:26.808447874 +0100
1d31ef
+++ openssh-7.4p1/gss-serv.c	2016-12-23 15:40:26.819447876 +0100
1d31ef
@@ -441,6 +441,16 @@ ssh_gssapi_do_child(char ***envp, u_int
1d31ef
 }
1d31ef
 
1d31ef
 /* Privileged */
1d31ef
+char*
1d31ef
+ssh_gssapi_get_displayname(void)
1d31ef
+{
1d31ef
+	if (gssapi_client.displayname.length != 0 &&
1d31ef
+	    gssapi_client.displayname.value != NULL)
1d31ef
+		return strdup((char *)gssapi_client.displayname.value);
1d31ef
+	return NULL;
1d31ef
+}
1d31ef
+
1d31ef
+/* Privileged */
1d31ef
 int
1d31ef
 ssh_gssapi_userok(char *user, struct passwd *pw)
1d31ef
 {
1d31ef
diff -up openssh-7.4p1/monitor.c.expose-pam openssh-7.4p1/monitor.c
1d31ef
--- openssh-7.4p1/monitor.c.expose-pam	2016-12-23 15:40:26.794447872 +0100
1d31ef
+++ openssh-7.4p1/monitor.c	2016-12-23 15:41:16.473455863 +0100
1d31ef
@@ -300,6 +300,7 @@ monitor_child_preauth(Authctxt *_authctx
1d31ef
 {
1d31ef
 	struct mon_table *ent;
1d31ef
 	int authenticated = 0, partial = 0;
1d31ef
+	char *prev_auth_details;
1d31ef
 
1d31ef
 	debug3("preauth child monitor started");
1d31ef
 
1d31ef
@@ -330,6 +331,18 @@ monitor_child_preauth(Authctxt *_authctx
1d31ef
 		auth_submethod = NULL;
1d31ef
 		authenticated = (monitor_read(pmonitor, mon_dispatch, &ent) == 1);
1d31ef
 
1d31ef
+		if (authenticated) {
1d31ef
+			prev_auth_details = authctxt->auth_details;
1d31ef
+			xasprintf(&authctxt->auth_details, "%s%s%s%s%s",
1d31ef
+			    prev_auth_details ? prev_auth_details : "",
1d31ef
+			    prev_auth_details ? ", " : "", auth_method,
1d31ef
+			    authctxt->last_details ? ": " : "",
1d31ef
+			    authctxt->last_details ? authctxt->last_details : "");
1d31ef
+			free(prev_auth_details);
1d31ef
+		}
1d31ef
+		free(authctxt->last_details);
1d31ef
+		authctxt->last_details = NULL;
1d31ef
+
1d31ef
 		/* Special handling for multiple required authentications */
1d31ef
 		if (options.num_auth_methods != 0) {
1d31ef
 			if (authenticated &&
1d31ef
@@ -1417,6 +1430,10 @@ mm_answer_keyverify(int sock, Buffer *m)
1d31ef
 	debug3("%s: key %p signature %s",
1d31ef
 	    __func__, key, (verified == 1) ? "verified" : "unverified");
1d31ef
 
1d31ef
+	if (verified == 1)
1d31ef
+		authctxt->last_details = sshkey_format_oneline(key,
1d31ef
+		    options.fingerprint_hash);
1d31ef
+
1d31ef
 	/* If auth was successful then record key to ensure it isn't reused */
1d31ef
 	if (verified == 1 && key_blobtype == MM_USERKEY)
1d31ef
 		auth2_record_userkey(authctxt, key);
1d31ef
@@ -1860,6 +1877,9 @@ mm_answer_gss_userok(int sock, Buffer *m
1d31ef
 
1d31ef
 	auth_method = "gssapi-with-mic";
1d31ef
 
1d31ef
+	if (authenticated)
1d31ef
+		authctxt->last_details = ssh_gssapi_get_displayname();
1d31ef
+
1d31ef
 	/* Monitor loop will terminate if authenticated */
1d31ef
 	return (authenticated);
1d31ef
 }
1d31ef
diff -up openssh-7.4p1/servconf.c.expose-pam openssh-7.4p1/servconf.c
1d31ef
--- openssh-7.4p1/servconf.c.expose-pam	2016-12-23 15:40:26.810447875 +0100
1d31ef
+++ openssh-7.4p1/servconf.c	2016-12-23 15:44:04.691482920 +0100
1d31ef
@@ -171,6 +171,7 @@ initialize_server_options(ServerOptions
1d31ef
 	options->version_addendum = NULL;
1d31ef
 	options->use_kuserok = -1;
1d31ef
 	options->enable_k5users = -1;
1d31ef
+	options->expose_auth_methods = -1;
1d31ef
 	options->fingerprint_hash = -1;
1d31ef
 	options->disable_forwarding = -1;
1d31ef
 }
1d31ef
@@ -354,6 +355,8 @@ fill_default_server_options(ServerOption
1d31ef
 		options->use_kuserok = 1;
1d31ef
 	if (options->enable_k5users == -1)
1d31ef
 		options->enable_k5users = 0;
1d31ef
+	if (options->expose_auth_methods == -1)
1d31ef
+		options->expose_auth_methods = EXPOSE_AUTHMETH_NEVER;
1d31ef
 	if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1d31ef
 		options->fwd_opts.streamlocal_bind_mask = 0177;
1d31ef
 	if (options->fwd_opts.streamlocal_bind_unlink == -1)
1d31ef
@@ -439,6 +442,7 @@ typedef enum {
1d31ef
 	sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
1d31ef
 	sStreamLocalBindMask, sStreamLocalBindUnlink,
1d31ef
 	sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
1d31ef
+	sExposeAuthenticationMethods,
1d31ef
 	sDeprecated, sIgnore, sUnsupported
1d31ef
 } ServerOpCodes;
1d31ef
 
1d31ef
@@ -595,6 +599,7 @@ static struct {
1d31ef
 	{ "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
1d31ef
 	{ "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
1d31ef
 	{ "disableforwarding", sDisableForwarding, SSHCFG_ALL },
1d31ef
+	{ "exposeauthenticationmethods", sExposeAuthenticationMethods, SSHCFG_ALL },
1d31ef
 	{ NULL, sBadOption, 0 }
1d31ef
 };
1d31ef
 
1d31ef
@@ -984,6 +989,12 @@ static const struct multistate multistat
1d31ef
 	{ "local",			FORWARD_LOCAL },
1d31ef
 	{ NULL, -1 }
1d31ef
 };
1d31ef
+static const struct multistate multistate_exposeauthmeth[] = {
1d31ef
+	{ "never",			EXPOSE_AUTHMETH_NEVER },
1d31ef
+	{ "pam-only",			EXPOSE_AUTHMETH_PAMONLY },
1d31ef
+	{ "pam-and-env",		EXPOSE_AUTHMETH_PAMENV },
1d31ef
+	{ NULL, -1}
1d31ef
+};
1d31ef
 
1d31ef
 int
1d31ef
 process_server_config_line(ServerOptions *options, char *line,
1d31ef
@@ -1902,6 +1913,11 @@ process_server_config_line(ServerOptions
1d31ef
 			options->fingerprint_hash = value;
1d31ef
 		break;
1d31ef
 
1d31ef
+	case sExposeAuthenticationMethods:
1d31ef
+		intptr = &options->expose_auth_methods;
1d31ef
+		multistate_ptr = multistate_exposeauthmeth;
1d31ef
+		goto parse_multistate;
1d31ef
+
1d31ef
 	case sDeprecated:
1d31ef
 	case sIgnore:
1d31ef
 	case sUnsupported:
1d31ef
@@ -2060,6 +2076,7 @@ copy_set_server_options(ServerOptions *d
1d31ef
 	M_CP_INTOPT(enable_k5users);
1d31ef
 	M_CP_INTOPT(rekey_limit);
1d31ef
 	M_CP_INTOPT(rekey_interval);
1d31ef
+	M_CP_INTOPT(expose_auth_methods);
1d31ef
 
1d31ef
 	/*
1d31ef
 	 * The bind_mask is a mode_t that may be unsigned, so we can't use
1d31ef
@@ -2176,6 +2193,8 @@ fmt_intarg(ServerOpCodes code, int val)
1d31ef
 		return fmt_multistate_int(val, multistate_tcpfwd);
1d31ef
 	case sFingerprintHash:
1d31ef
 		return ssh_digest_alg_name(val);
1d31ef
+	case sExposeAuthenticationMethods:
1d31ef
+		return fmt_multistate_int(val, multistate_exposeauthmeth);
1d31ef
 	default:
1d31ef
 		switch (val) {
1d31ef
 		case 0:
1d31ef
@@ -2356,6 +2375,7 @@ dump_config(ServerOptions *o)
1d31ef
 	dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
1d31ef
 	dump_cfg_fmtint(sKerberosUseKuserok, o->use_kuserok);
1d31ef
 	dump_cfg_fmtint(sGssEnablek5users, o->enable_k5users);
1d31ef
+	dump_cfg_fmtint(sExposeAuthenticationMethods, o->expose_auth_methods);
1d31ef
 	dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1d31ef
 
1d31ef
 	/* string arguments */
1d31ef
diff -up openssh-7.4p1/servconf.h.expose-pam openssh-7.4p1/servconf.h
1d31ef
--- openssh-7.4p1/servconf.h.expose-pam	2016-12-23 15:40:26.810447875 +0100
1d31ef
+++ openssh-7.4p1/servconf.h	2016-12-23 15:40:26.821447876 +0100
1d31ef
@@ -48,6 +48,11 @@
1d31ef
 #define FORWARD_LOCAL		(1<<1)
1d31ef
 #define FORWARD_ALLOW		(FORWARD_REMOTE|FORWARD_LOCAL)
1d31ef
 
1d31ef
+/* Expose AuthenticationMethods */
1d31ef
+#define EXPOSE_AUTHMETH_NEVER   0
1d31ef
+#define EXPOSE_AUTHMETH_PAMONLY 1
1d31ef
+#define EXPOSE_AUTHMETH_PAMENV  2
1d31ef
+
1d31ef
 #define DEFAULT_AUTH_FAIL_MAX	6	/* Default for MaxAuthTries */
1d31ef
 #define DEFAULT_SESSIONS_MAX	10	/* Default for MaxSessions */
1d31ef
 
1d31ef
@@ -195,6 +200,8 @@ typedef struct {
1d31ef
 	char   *auth_methods[MAX_AUTH_METHODS];
1d31ef
 
1d31ef
 	int	fingerprint_hash;
1d31ef
+
1d31ef
+	int	expose_auth_methods; /* EXPOSE_AUTHMETH_* above */
1d31ef
 }       ServerOptions;
1d31ef
 
1d31ef
 /* Information about the incoming connection as used by Match */
1d31ef
diff -up openssh-7.4p1/session.c.expose-pam openssh-7.4p1/session.c
1d31ef
--- openssh-7.4p1/session.c.expose-pam	2016-12-23 15:40:26.794447872 +0100
1d31ef
+++ openssh-7.4p1/session.c	2016-12-23 15:40:26.821447876 +0100
1d31ef
@@ -997,6 +997,12 @@ copy_environment(char **source, char ***
1d31ef
 		}
1d31ef
 		*var_val++ = '\0';
1d31ef
 
1d31ef
+		if (options.expose_auth_methods < EXPOSE_AUTHMETH_PAMENV &&
1d31ef
+				strcmp(var_name, "SSH_USER_AUTH") == 0) {
1d31ef
+			free(var_name);
1d31ef
+			continue;
1d31ef
+		}
1d31ef
+
1d31ef
 		debug3("Copy environment: %s=%s", var_name, var_val);
1d31ef
 		child_set_env(env, envsize, var_name, var_val);
1d31ef
 
1d31ef
@@ -1173,6 +1179,11 @@ do_setup_env(Session *s, const char *she
1d31ef
 	}
1d31ef
 #endif /* USE_PAM */
1d31ef
 
1d31ef
+	if (options.expose_auth_methods >= EXPOSE_AUTHMETH_PAMENV &&
1d31ef
+			s->authctxt->auth_details)
1d31ef
+		child_set_env(&env, &envsize, "SSH_USER_AUTH",
1d31ef
+		     s->authctxt->auth_details);
1d31ef
+
1d31ef
 	if (auth_sock_name != NULL)
1d31ef
 		child_set_env(&env, &envsize, SSH_AUTHSOCKET_ENV_NAME,
1d31ef
 		    auth_sock_name);
1d31ef
@@ -2561,6 +2572,9 @@ do_cleanup(Authctxt *authctxt)
1d31ef
 	if (authctxt == NULL)
1d31ef
 		return;
1d31ef
 
1d31ef
+	free(authctxt->auth_details);
1d31ef
+	authctxt->auth_details = NULL;
1d31ef
+
1d31ef
 #ifdef USE_PAM
1d31ef
 	if (options.use_pam) {
1d31ef
 		sshpam_cleanup();
1d31ef
diff -up openssh-7.4p1/ssh.1.expose-pam openssh-7.4p1/ssh.1
1d31ef
--- openssh-7.4p1/ssh.1.expose-pam	2016-12-23 15:40:26.810447875 +0100
1d31ef
+++ openssh-7.4p1/ssh.1	2016-12-23 15:40:26.822447877 +0100
1d31ef
@@ -1421,6 +1421,10 @@ server IP address, and server port numbe
1d31ef
 This variable contains the original command line if a forced command
1d31ef
 is executed.
1d31ef
 It can be used to extract the original arguments.
1d31ef
+.It Ev SSH_USER_AUTH
1d31ef
+This variable contains, for SSH2 only, a comma-separated list of authentication
1d31ef
+methods that were successfuly used to authenticate. When possible, these
1d31ef
+methods are extended with detailed information on the credential used.
1d31ef
 .It Ev SSH_TTY
1d31ef
 This is set to the name of the tty (path to the device) associated
1d31ef
 with the current shell or command.
1d31ef
diff -up openssh-7.4p1/sshd_config.5.expose-pam openssh-7.4p1/sshd_config.5
1d31ef
--- openssh-7.4p1/sshd_config.5.expose-pam	2016-12-23 15:40:26.822447877 +0100
1d31ef
+++ openssh-7.4p1/sshd_config.5	2016-12-23 15:45:22.411495421 +0100
1d31ef
@@ -570,6 +570,21 @@ Disables all forwarding features, includ
1d31ef
 TCP and StreamLocal.
1d31ef
 This option overrides all other forwarding-related options and may
1d31ef
 simplify restricted configurations.
1d31ef
+.It Cm ExposeAuthenticationMethods
1d31ef
+When using SSH2, this option controls the exposure of the list of
1d31ef
+successful authentication methods to PAM during the authentication
1d31ef
+and to the shell environment via the
1d31ef
+.Cm SSH_USER_AUTH
1d31ef
+variable. See the description of this variable for more details.
1d31ef
+Valid options are:
1d31ef
+.Cm never
1d31ef
+(Do not expose successful authentication methods),
1d31ef
+.Cm pam-only
1d31ef
+(Only expose them to PAM during authentication, not afterwards),
1d31ef
+.Cm pam-and-env
1d31ef
+(Expose them to PAM and keep them in the shell environment).
1d31ef
+The default is
1d31ef
+.Cm never .
1d31ef
 .It Cm FingerprintHash
1d31ef
 Specifies the hash algorithm used when logging key fingerprints.
1d31ef
 Valid options are:
1d31ef
diff -up openssh-7.4p1/ssh-gss.h.expose-pam openssh-7.4p1/ssh-gss.h
1d31ef
--- openssh-7.4p1/ssh-gss.h.expose-pam	2016-12-23 15:40:26.811447875 +0100
1d31ef
+++ openssh-7.4p1/ssh-gss.h	2016-12-23 15:40:26.823447877 +0100
1d31ef
@@ -159,6 +159,7 @@ int ssh_gssapi_server_check_mech(Gssctxt
1d31ef
     const char *);
1d31ef
 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
1d31ef
 int ssh_gssapi_userok(char *name, struct passwd *);
1d31ef
+char* ssh_gssapi_get_displayname(void);
1d31ef
 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
1d31ef
 void ssh_gssapi_do_child(char ***, u_int *);
1d31ef
 void ssh_gssapi_cleanup_creds(void);
1d31ef
diff -up openssh-7.4p1/sshkey.c.expose-pam openssh-7.4p1/sshkey.c
1d31ef
--- openssh-7.4p1/sshkey.c.expose-pam	2016-12-23 15:40:26.777447869 +0100
1d31ef
+++ openssh-7.4p1/sshkey.c	2016-12-23 15:40:26.823447877 +0100
1d31ef
@@ -57,6 +57,7 @@
1d31ef
 #define SSHKEY_INTERNAL
1d31ef
 #include "sshkey.h"
1d31ef
 #include "match.h"
1d31ef
+#include "xmalloc.h"
1d31ef
 
1d31ef
 /* openssh private key file format */
1d31ef
 #define MARK_BEGIN		"-----BEGIN OPENSSH PRIVATE KEY-----\n"
1d31ef
@@ -1191,6 +1192,30 @@ sshkey_fingerprint(const struct sshkey *
1d31ef
 	return retval;
1d31ef
 }
1d31ef
 
1d31ef
+char *
1d31ef
+sshkey_format_oneline(const struct sshkey *key, int dgst_alg)
1d31ef
+{
1d31ef
+	char *fp, *result;
1d31ef
+
1d31ef
+	if (sshkey_is_cert(key)) {
1d31ef
+		fp = sshkey_fingerprint(key->cert->signature_key, dgst_alg,
1d31ef
+		    SSH_FP_DEFAULT);
1d31ef
+		xasprintf(&result, "%s ID %s (serial %llu) CA %s %s",
1d31ef
+		    sshkey_type(key), key->cert->key_id,
1d31ef
+		    (unsigned long long)key->cert->serial,
1d31ef
+		    sshkey_type(key->cert->signature_key),
1d31ef
+		    fp == NULL ? "(null)" : fp);
1d31ef
+		free(fp);
1d31ef
+	} else {
1d31ef
+		fp = sshkey_fingerprint(key, dgst_alg, SSH_FP_DEFAULT);
1d31ef
+		xasprintf(&result, "%s %s", sshkey_type(key),
1d31ef
+		    fp == NULL ? "(null)" : fp);
1d31ef
+		free(fp);
1d31ef
+	}
1d31ef
+
1d31ef
+	return result;
1d31ef
+}
1d31ef
+
1d31ef
 #ifdef WITH_SSH1
1d31ef
 /*
1d31ef
  * Reads a multiple-precision integer in decimal from the buffer, and advances
1d31ef
diff -up openssh-7.4p1/sshkey.h.expose-pam openssh-7.4p1/sshkey.h
1d31ef
--- openssh-7.4p1/sshkey.h.expose-pam	2016-12-23 15:40:26.777447869 +0100
1d31ef
+++ openssh-7.4p1/sshkey.h	2016-12-23 15:40:26.823447877 +0100
1d31ef
@@ -124,6 +124,7 @@ char		*sshkey_fingerprint(const struct s
1d31ef
     int, enum sshkey_fp_rep);
1d31ef
 int		 sshkey_fingerprint_raw(const struct sshkey *k,
1d31ef
     int, u_char **retp, size_t *lenp);
1d31ef
+char		*sshkey_format_oneline(const struct sshkey *k, int dgst_alg);
1d31ef
 const char	*sshkey_type(const struct sshkey *);
1d31ef
 const char	*sshkey_cert_type(const struct sshkey *);
1d31ef
 int		 sshkey_write(const struct sshkey *, FILE *);