aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssh/ssh-add.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/ssh-add.c')
-rw-r--r--crypto/openssh/ssh-add.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/crypto/openssh/ssh-add.c b/crypto/openssh/ssh-add.c
index 1e9eddf9048e..7ce45103644e 100644
--- a/crypto/openssh/ssh-add.c
+++ b/crypto/openssh/ssh-add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-add.c,v 1.186 2026/03/05 05:44:15 djm Exp $ */
+/* $OpenBSD: ssh-add.c,v 1.187 2026/06/29 02:13:05 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -813,7 +813,7 @@ main(int argc, char **argv)
{
extern char *optarg;
extern int optind;
- int agent_fd;
+ int agent_fd = -1;
char *pkcs11provider = NULL, *skprovider = NULL;
char **dest_constraint_strings = NULL, **hostkey_files = NULL;
int r, i, ch, deleting = 0, ret = 0, key_only = 0, cert_only = 0;
@@ -835,19 +835,6 @@ main(int argc, char **argv)
setvbuf(stdout, NULL, _IOLBF, 0);
- /* First, get a connection to the authentication agent. */
- switch (r = ssh_get_authentication_socket(&agent_fd)) {
- case 0:
- break;
- case SSH_ERR_AGENT_NOT_PRESENT:
- fprintf(stderr, "Could not open a connection to your "
- "authentication agent.\n");
- exit(2);
- default:
- fprintf(stderr, "Error connecting to agent: %s\n", ssh_err(r));
- exit(2);
- }
-
skprovider = getenv("SSH_SK_PROVIDER");
while ((ch = getopt(argc, argv, "vkKlLNCcdDTxXE:e:h:H:M:m:Qqs:S:t:")) != -1) {
@@ -943,7 +930,21 @@ main(int argc, char **argv)
if ((xflag != 0) + (lflag != 0) + (Dflag != 0) + (Qflag != 0) > 1)
fatal("Invalid combination of actions");
- else if (xflag) {
+
+ /* First, get a connection to the authentication agent. */
+ switch (r = ssh_get_authentication_socket(&agent_fd)) {
+ case 0:
+ break;
+ case SSH_ERR_AGENT_NOT_PRESENT:
+ fprintf(stderr, "Could not open a connection to your "
+ "authentication agent.\n");
+ exit(2);
+ default:
+ fprintf(stderr, "Error connecting to agent: %s\n", ssh_err(r));
+ exit(2);
+ }
+
+ if (xflag) {
if (lock_agent(agent_fd, xflag == 'x' ? 1 : 0) == -1)
ret = 1;
goto done;