Skip to content

Commit

Permalink
- -I FILENAME can be specified multiple times.
Browse files Browse the repository at this point in the history
- some fix
- 1.10
  • Loading branch information
ganaware committed Apr 12, 2016
1 parent c237bb4 commit ec68749
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION = 1
MINOR_VERSION = 9
MINOR_VERSION = 10

DISTRIB = win-ssh-agent-$(shell printf %d.%02d $(MAJOR_VERSION) $(MINOR_VERSION)).tgz

Expand Down
30 changes: 25 additions & 5 deletions README-ja.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,38 @@
で identity ファイルを指定します。このオプションは複数
指定可能です。

-I, --default-identity -

win-ssh-agent 起動時にパスフレーズを問い合わせるダイア
ログを表示します。このオプションは一つしか指定できませ
ん。

ssh-add を引数なしで実行した場合と同じ identity ファイ
ルのパスフレーズを問い合わせます。
(~/.ssh/id_rsa, ~/.ssh/id_dsa,
~/.ssh/id_ecdsa, ~/.ssh/id_ed25519, ~/.ssh/identity)

このオプションはデフォルトで指定されています。

このオプションを指定した場合、-I FILENAME の効果は無効
になります。

-I, --default-identity FILENAME

-i と同じですが、win-ssh-agent 起動時にパスフレーズ
を問い合わせるダイアログを表示します。このオプションは
一つしか指定できません
複数指定可能です

デフォルトでは -I - が暗黙に指定されています。FILENAME
として - を指定すると、ssh-add を引数なしで実行した場
合と同じファイル (~/.ssh/id_rsa, ~/.ssh/id_dsa,
~/.ssh/id_ecdsa, ~/.ssh/identity) を指定したことになり
このオプションを指定した場合、-I - の効果は無効になり
ます。

--no-default-identity

デフォルトで -I - が指定されないようにします。

このオプションを指定した場合、-I - , -I FILENAME の効
果は無効になります。

-e, --exec PROGRAM [OPTION ...]

このオプション以降に書いたプログラムを win-ssh-agent
Expand Down Expand Up @@ -181,6 +197,10 @@

9. 履歴

2016/04/12 1.10
* -I FILENAME を複数指定可能に
* 細かな修正

2016/03/10 1.09
* Cygwin 64-bit 用修正

Expand Down
28 changes: 22 additions & 6 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,34 @@
identity file will be specified by this option. This
option can be specified more more than once.

-I, --default-identity -

It shows dialogue which asks the pass-phrase at the time of
start. This option can be specified only once.

The same identity files are considerd to be specified
as the ssh-add with no-options uses.
(i.e. ~/.ssh/id_rsa, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa,
~/.ssh/id_ed25519, ~/.ssh/identity)

In the case of default, -I - is set up automatically.

This option invalidates -I FILENAME.

-I, --default-identity FILENAME

This option works almost as same as -i. But, it shows
a dialogue which asks the pass-phrase at the time of
start. This option can be specified only once.
start. This option can be specified multiple times.

In the case of default, -I - is set up automatically.
If - is specified as a FILENAME, the same identity
files are considerd to be specified as the ssh-add
with no-options uses. (i.e. ~/.ssh/id_rsa,
~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/identity)
This option invalidates -I -.

--no-default-identity

It stops that -I - is set in the case of default.

This option invalidates -I -, and -I FILENAME.

-e, --exec PROGRAM [OPTION ...]

After the win-ssh-agent started, it executes the
Expand Down Expand Up @@ -196,6 +208,10 @@

9. History

2016/04/12 1.10
* -I FILENAME can be specified multiple times.
* some fix

2016/03/10 1.09
* Fixed for Cygwin 64-bit.

Expand Down
53 changes: 39 additions & 14 deletions agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdarg.h>
#include <errno.h>
#include <locale.h>
#include <vector>

#include "agentrc.h"
#include "misc.h"
Expand All @@ -19,7 +20,8 @@
typedef std::list<const char *> IdentityFiles;

static IdentityFiles g_option_identityFiles; // --identity, --default-identity
static const char *g_option_defaultIdentityFile = ""; // --default-identity
static IdentityFiles g_option_defaultIdentityFiles; // --default-identity
static bool g_option_isDefaultIdentityFilesDefault = true; // -I -
static const char *g_option_bindAddress = NULL; // -a
static const char *g_option_lifetime = NULL; // -t
static bool g_option_no_ssh_agent = false; // --no-ssh-agent
Expand Down Expand Up @@ -132,7 +134,7 @@ std::string getAskpassPath()
}

// run ssh-add
int run_ssh_add(const char *i_identityFile)
int run_ssh_add(const IdentityFiles &i_identityFiles)
{
verbose("\n(run ssh-add)\n");
pid_t childPID = fork();
Expand All @@ -143,10 +145,23 @@ int run_ssh_add(const char *i_identityFile)
verbose("$ export SSH_ASKPASS=%s\n", getenv("SSH_ASKPASS"));
setenv("DISPLAY", ":0", 0);
verbose("$ export DISPLAY=%s\n", getenv("DISPLAY"));
verbose("$ ssh-add %s\n", i_identityFile ? i_identityFile : "");
if (i_identityFile && !i_identityFile[0])
i_identityFile = NULL;
execlp("ssh-add", "ssh-add", i_identityFile, NULL);
verbose("$ ssh-add");
typedef std::vector<char *> Argv;
Argv argv;
{
argv.resize(i_identityFiles.size() + 2);
argv[0] = const_cast<char *>("ssh-add");
argv[argv.size() - 1] = NULL;
int i = 1;
for (IdentityFiles::const_iterator itr = i_identityFiles.begin();
itr != i_identityFiles.end(); ++ itr, ++ i)
{
argv[i] = const_cast<char *>(*itr);
verbose(" %s", *itr);
}
}
verbose("\n");
execvp("ssh-add", &argv[0]);

std::wstring message(L"Failed to exec ssh-add.exe : \r\n");
message += to_wstring(sys_errlist[errno]);
Expand Down Expand Up @@ -268,6 +283,11 @@ bool checkOptions(int i_argc, char **i_argv)
; // ignore
else if (a == "--verbose")
g_option_verbose = true;
else if (a == "--no-default-identity")
{
g_option_defaultIdentityFiles.clear();
g_option_isDefaultIdentityFilesDefault = false;
}
else if (i + 1 < i_argc)
{
if (a == "-i" || a == "--identity")
Expand All @@ -276,15 +296,17 @@ bool checkOptions(int i_argc, char **i_argv)
{
++ i;
if (std::string(i_argv[i]) == "-")
g_option_defaultIdentityFile = "";
{
g_option_defaultIdentityFiles.clear();
g_option_isDefaultIdentityFilesDefault = true;
}
else
{
g_option_identityFiles.push_back(i_argv[i]);
g_option_defaultIdentityFile = i_argv[i];
g_option_defaultIdentityFiles.push_back(i_argv[i]);
g_option_isDefaultIdentityFilesDefault = false;
}
}
else if (a == "--no-default-identity")
g_option_defaultIdentityFile = NULL;
else if (a == "-a")
g_option_bindAddress = i_argv[++ i];
else if (a == "-t")
Expand Down Expand Up @@ -404,7 +426,7 @@ class TaskTray : private noncopyable
switch (id)
{
case ID_MENUITEM_Add:
run_ssh_add(NULL);
run_ssh_add(g_option_defaultIdentityFiles);
break;
case ID_MENUITEM_Exit:
PostQuitMessage(0);
Expand All @@ -417,7 +439,9 @@ class TaskTray : private noncopyable
IdentityFiles::iterator itr = g_option_identityFiles.begin();
for (int i = id - ID_MENUITEM_Add - 1; 0 < i; -- i)
++ itr;
run_ssh_add(*itr);
IdentityFiles identityFiles;
identityFiles.push_back(*itr);
run_ssh_add(identityFiles);
}
break;
}
Expand Down Expand Up @@ -668,8 +692,9 @@ int main(int i_argc, char **i_argv)
registoryEnvironment.broadcastSetenv();

// run
if (g_option_defaultIdentityFile) {
int status = run_ssh_add(g_option_defaultIdentityFile);
if (g_option_defaultIdentityFiles.size() ||
g_option_isDefaultIdentityFilesDefault) {
int status = run_ssh_add(g_option_defaultIdentityFiles);
if (g_option_execArgs && (status == 0)) {
run_program(g_option_execArgs);
}
Expand Down
2 changes: 1 addition & 1 deletion agent.manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.9.0.0"
version="1.10.0.0"
processorArchitecture="*"
name="ganaware.win-ssh-askpass.win-ssh-agent"
type="win32"
Expand Down
2 changes: 1 addition & 1 deletion askpass.manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.9.0.0"
version="1.10.0.0"
processorArchitecture="*"
name="ganaware.win-ssh-askpass.win-ssh-askpass"
type="win32"
Expand Down

0 comments on commit ec68749

Please sign in to comment.