summaryrefslogtreecommitdiff
path: root/sshconnect.c
diff options
context:
space:
mode:
authorjcs@openbsd.org <jcs@openbsd.org>2015-11-15 22:26:49 +0000
committerDamien Miller <djm@mindrot.org>2015-11-16 11:31:39 +1100
commitf361df474c49a097bfcf16d1b7b5c36fcd844b4b (patch)
tree493beb15e73f9b57f42244e8c927bdf75480188f /sshconnect.c
parentd87063d9baf5479b6e813d47dfb694a97df6f6f5 (diff)
upstream commit
Add an AddKeysToAgent client option which can be set to 'yes', 'no', 'ask', or 'confirm', and defaults to 'no'. When enabled, a private key that is used during authentication will be added to ssh-agent if it is running (with confirmation enabled if set to 'confirm'). Initial version from Joachim Schipper many years ago. ok markus@ Upstream-ID: a680db2248e8064ec55f8be72d539458c987d5f4
Diffstat (limited to 'sshconnect.c')
-rw-r--r--sshconnect.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/sshconnect.c b/sshconnect.c
index c9f88e035..19d393f7b 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.265 2015/09/04 04:55:24 djm Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.266 2015/11/15 22:26:49 jcs Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -65,6 +65,7 @@
65#include "version.h" 65#include "version.h"
66#include "authfile.h" 66#include "authfile.h"
67#include "ssherr.h" 67#include "ssherr.h"
68#include "authfd.h"
68 69
69char *client_version_string = NULL; 70char *client_version_string = NULL;
70char *server_version_string = NULL; 71char *server_version_string = NULL;
@@ -1487,3 +1488,30 @@ ssh_local_cmd(const char *args)
1487 1488
1488 return (WEXITSTATUS(status)); 1489 return (WEXITSTATUS(status));
1489} 1490}
1491
1492void
1493maybe_add_key_to_agent(char *authfile, Key *private, char *comment,
1494 char *passphrase)
1495{
1496 int auth_sock = -1, r;
1497
1498 if (options.add_keys_to_agent == 0)
1499 return;
1500
1501 if ((r = ssh_get_authentication_socket(&auth_sock)) != 0) {
1502 debug3("no authentication agent, not adding key");
1503 return;
1504 }
1505
1506 if (options.add_keys_to_agent == 2 &&
1507 !ask_permission("Add key %s (%s) to agent?", authfile, comment)) {
1508 debug3("user denied adding this key");
1509 return;
1510 }
1511
1512 if ((r = ssh_add_identity_constrained(auth_sock, private, comment, 0,
1513 (options.add_keys_to_agent == 3))) == 0)
1514 debug("identity added to agent: %s", authfile);
1515 else
1516 debug("could not add identity to agent: %s (%d)", authfile, r);
1517}