summaryrefslogtreecommitdiff
path: root/examples/common.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-04-16 12:02:20 +0200
committerPatrick Steinhardt <ps@pks.im>2019-04-16 12:02:20 +0200
commit611fbe4f9b7d2682c8b2653e8abc9dcf5a9a984c (patch)
treeca07187858e40d5819fcf4c8965b3edc15f6f74f /examples/common.c
parentd9351c6556fce79efd6f39e122e9e7ef04e32cf9 (diff)
downloadlibgit2-611fbe4f9b7d2682c8b2653e8abc9dcf5a9a984c.tar.gz
examples: implement SSH key credentials
Implement SSH key credentials. This allows users to use the SSH transport with the lg2 example code.
Diffstat (limited to 'examples/common.c')
-rw-r--r--examples/common.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/common.c b/examples/common.c
index e90538c4c..0b52eb583 100644
--- a/examples/common.c
+++ b/examples/common.c
@@ -330,12 +330,12 @@ error:
return error;
}
-static int ask(char **out, const char *prompt)
+static int ask(char **out, const char *prompt, char optional)
{
printf("%s ", prompt);
fflush(stdout);
- if (!readline(out)) {
+ if (!readline(out) && !optional) {
fprintf(stderr, "Could not read response: %s", strerror(errno));
return -1;
}
@@ -359,9 +359,9 @@ int cred_acquire_cb(git_cred **out,
if (allowed_types & GIT_CREDTYPE_SSH_KEY) {
int n;
- if ((error = ask(&username, "Username:")) < 0 ||
- (error = ask(&privkey, "SSH Key:")) < 0 ||
- (error = ask(&password, "Password:")) < 0)
+ if ((error = ask(&username, "Username:", 0)) < 0 ||
+ (error = ask(&privkey, "SSH Key:", 0)) < 0 ||
+ (error = ask(&password, "Password:", 1)) < 0)
goto out;
if ((n = snprintf(NULL, 0, "%s.pub", privkey)) < 0 ||
@@ -371,13 +371,13 @@ int cred_acquire_cb(git_cred **out,
error = git_cred_ssh_key_new(out, username, pubkey, privkey, password);
} else if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT) {
- if ((error = ask(&username, "Username:")) < 0 ||
- (error = ask(&password, "Password:")) < 0)
+ if ((error = ask(&username, "Username:", 0)) < 0 ||
+ (error = ask(&password, "Password:", 1)) < 0)
goto out;
error = git_cred_userpass_plaintext_new(out, username, password);
} else if (allowed_types & GIT_CREDTYPE_USERNAME) {
- if ((error = ask(&username, "Username:")) < 0)
+ if ((error = ask(&username, "Username:", 0)) < 0)
goto out;
error = git_cred_username_new(out, username);