aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarius Vollmer <mvollmer@redhat.com>2020-09-02 15:41:00 +0300
committerAndreas Schneider <asn@cryptomilk.org>2020-12-10 09:22:13 +0100
commitabc88c025c0e1530c7de5531281eb4404135b5ce (patch)
tree572e80892cff2fc94dbb282678d43948978f9328 /src
parent026879e9f0d766ebe651e6d3fd9809e243928391 (diff)
downloadlibssh-abc88c025c0e1530c7de5531281eb4404135b5ce.tar.gz
libssh-abc88c025c0e1530c7de5531281eb4404135b5ce.tar.xz
libssh-abc88c025c0e1530c7de5531281eb4404135b5ce.zip
auth: Add ssh_userauth_publickey_auto_get_current_identity()
Signed-off-by: Marius Vollmer <mvollmer@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/auth.c49
-rw-r--r--src/libssh.map1
2 files changed, 50 insertions, 0 deletions
diff --git a/src/auth.c b/src/auth.c
index 89272290..fcf39b7a 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -976,6 +976,55 @@ struct ssh_auth_auto_state_struct {
};
/**
+ * @brief Get the identity that is currenly being processed by
+ * ssh_userauth_publickey_auto()
+ *
+ * This is meant to be used by a callback that happens as part of the
+ * execution of ssh_userauth_publickey_auto(). The auth_function
+ * callback might want to know which key a passphrase is needed for,
+ * for example.
+ *
+ * @param[in] session The SSH session.
+ *
+ * @param[out] value The value to get into. As a char**, space will be
+ * allocated by the function for the value, it is
+ * your responsibility to free the memory using
+ * ssh_string_free_char().
+ *
+ * @return SSH_OK on success, SSH_ERROR on error.
+ */
+int ssh_userauth_publickey_auto_get_current_identity(ssh_session session,
+ char** value)
+{
+ const char *id = NULL;
+
+ if (session == NULL) {
+ return SSH_ERROR;
+ }
+
+ if (value == NULL) {
+ ssh_set_error_invalid(session);
+ return SSH_ERROR;
+ }
+
+ if (session->auth.auto_state != NULL && session->auth.auto_state->it != NULL) {
+ id = session->auth.auto_state->it->data;
+ }
+
+ if (id == NULL) {
+ return SSH_ERROR;
+ }
+
+ *value = strdup(id);
+ if (*value == NULL) {
+ ssh_set_error_oom(session);
+ return SSH_ERROR;
+ }
+
+ return SSH_OK;
+}
+
+/**
* @brief Tries to automatically authenticate with public key and "none"
*
* It may fail, for instance it doesn't ask for a password and uses a default
diff --git a/src/libssh.map b/src/libssh.map
index c9bedee0..e30c2449 100644
--- a/src/libssh.map
+++ b/src/libssh.map
@@ -402,6 +402,7 @@ LIBSSH_4_5_0 # Released
ssh_userauth_pubkey;
ssh_userauth_publickey;
ssh_userauth_publickey_auto;
+ ssh_userauth_publickey_auto_get_current_identity;
ssh_userauth_try_publickey;
ssh_version;
ssh_write_knownhost;