From 67937907ca7e90bc8fe3019d3c4d6436a8eba7ed Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 25 Jul 2014 18:02:48 +0200 Subject: nix-daemon: Pass on the user's $SSH_AUTH_SOCK to the SSH substituter --- src/download-via-ssh/download-via-ssh.cc | 5 +++++ src/libstore/globals.cc | 8 ++++++++ src/libstore/globals.hh | 2 ++ src/libstore/remote-store.cc | 2 ++ 4 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/download-via-ssh/download-via-ssh.cc b/src/download-via-ssh/download-via-ssh.cc index 0fa089724..466233c7a 100644 --- a/src/download-via-ssh/download-via-ssh.cc +++ b/src/download-via-ssh/download-via-ssh.cc @@ -101,6 +101,11 @@ void run(Strings args) std::cout << std::endl; + /* Pass on the location of the daemon client's SSH authentication + socket. */ + string sshAuthSock = settings.get("ssh-auth-sock"); + if (sshAuthSock != "") setenv("SSH_AUTH_SOCK", sshAuthSock.c_str(), 1); + string host = settings.sshSubstituterHosts.front(); std::pair pipes = connect(host); diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 82f3e952a..e9fe0beca 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -122,6 +122,14 @@ void Settings::set(const string & name, const string & value) } +string Settings::get(const string & name, const string & def) +{ + auto i = settings.find(name); + if (i == settings.end()) return def; + return i->second; +} + + void Settings::update() { get(tryFallback, "build-fallback"); diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index f1748336f..d16969c9e 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -21,6 +21,8 @@ struct Settings { void set(const string & name, const string & value); + string get(const string & name, const string & def = ""); + void update(); string pack(); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index b3967bb24..7c51f395a 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -163,6 +163,8 @@ void RemoteStore::setOptions() if (GET_PROTOCOL_MINOR(daemonVersion) >= 12) { Settings::SettingsMap overrides = settings.getOverrides(); + if (overrides["ssh-auth-sock"] == "") + overrides["ssh-auth-sock"] = getEnv("SSH_AUTH_SOCK"); writeInt(overrides.size(), to); foreach (Settings::SettingsMap::iterator, i, overrides) { writeString(i->first, to); -- cgit v1.2.3