Description: upstream: ssh session: differentiate agent flag-file
 Differentiate the agent flag-file for ssh session (Close: #828739);
 meant to be submitted to the upstream maintainer.
Origin: debian
Forwarded: dormant-upstream
Author: Jerome Benoit <calculus@rezozer.net>
Last-Update: 2022-01-08

--- a/pam_ssh.c
+++ b/pam_ssh.c
@@ -1100,14 +1100,25 @@
 	}
         /* else set tty_nodir to the tty with / replaced by _ */
         else {
-                if (!(tty_nodir = strdup(tty_raw))) {
-                        pam_ssh_log(LOG_CRIT, "out of memory");
-                        free(dotdir);
-                        openpam_restore_cred(pamh);
-                        return PAM_SERVICE_ERR;
+                pam_ssh_log(LOG_DEBUG, "controlling tty is '%s'.", tty_raw);
+                if (!strcmp("ssh",tty_raw)) {
+                        if (asprintf(&tty_nodir, "ssh-%ld", (long) getpid()) == -1) {
+                                pam_ssh_log(LOG_CRIT, "out of memory");
+                                free(dotdir);
+                                openpam_restore_cred(pamh);
+                                return PAM_SERVICE_ERR;
+                        }
+                }
+                else {
+                        if (!(tty_nodir = strdup(tty_raw))) {
+                                pam_ssh_log(LOG_CRIT, "out of memory");
+                                free(dotdir);
+                                openpam_restore_cred(pamh);
+                                return PAM_SERVICE_ERR;
+                        }
+                        for (cp = tty_nodir; (cp = strchr(cp, '/')); )
+                                *cp = '_';
                 }
-                for (cp = tty_nodir; (cp = strchr(cp, '/')); )
-                        *cp = '_';
         }
 
 	if (asprintf(&per_session, "%s/agent-%s-%s", dotdir, hname, tty_nodir) == -1) {
