Description: upstream: session: use opendir
 Check `~/.ssh' folder existence with opendir(3)
 (see #802212); meant to be submitted to the
 upstream maintainer.
Origin: debian
Forwarded: dormant-upstream
Author: Jerome Benoit <calculus@rezozer.net>
Last-Update: 2022-01-09

--- a/pam_ssh.c
+++ b/pam_ssh.c
@@ -915,6 +915,7 @@
 	char hname[MAXHOSTNAMELEN];	/* local hostname */
 	int no_link;      /* link per-agent file? */
 	char *dotdir;		        /* .ssh dir name */
+        DIR *dotstr;                    /* .ssh dir stream */
 	char *per_agent;		/* to store env */
 	char *per_session;		/* per-session filename */
 	const struct passwd *pwent;	/* user's passwd entry */
@@ -974,12 +975,15 @@
 		openpam_restore_cred(pamh);
 		return PAM_SERVICE_ERR;
 	}
-	if ((access(dotdir,F_OK)) == -1) {
+	if ((dotstr=opendir(dotdir)) == NULL) {
 		pam_ssh_log(LOG_DEBUG, "inexistent configuration directory");
 		free(dotdir);
 		openpam_restore_cred(pamh);
 		return PAM_SUCCESS;
 	}
+        else {
+                closedir(dotstr);
+	}
 
 	/* the per-agent file contains just the hostname */
 
@@ -1159,6 +1163,7 @@
 	struct stat sb;			/* to check st_nlink */
 	const char *user;               /* username */
 	char *dotdir;		        /* .ssh dir name */
+        DIR *dotstr;                    /* .ssh dir stream */
 
 	pam_ssh_log(LOG_DEBUG, "close session");
 
@@ -1185,11 +1190,14 @@
 		openpam_restore_cred(pamh);
 		return PAM_SERVICE_ERR;
 	}
-	if ((access(dotdir,F_OK)) == -1) {
+	if ((dotstr=opendir(dotdir)) == NULL) {
 		pam_ssh_log(LOG_DEBUG, "inexistent configuration directory");
 		free(dotdir);
 		openpam_restore_cred(pamh);
 		return PAM_SUCCESS;
+        }
+        else {
+                closedir(dotstr);
 	}
 	free(dotdir);
 
