mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-06 10:27:22 +09:00
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>
This commit is contained in:
committed by
Andreas Schneider
parent
026879e9f0
commit
abc88c025c
49
src/auth.c
49
src/auth.c
@@ -975,6 +975,55 @@ struct ssh_auth_auto_state_struct {
|
||||
ssh_key pubkey;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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"
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user