Skip to content

Commit

Permalink
session server ssh UPDATE kbint auth clb add param
Browse files Browse the repository at this point in the history
Added ssh_session param to keyboard interactive auth callback
  • Loading branch information
roman committed Sep 4, 2023
1 parent e9a02e2 commit 7621590
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/session_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ struct nc_server_opts {
void *pubkey_auth_data;
void (*pubkey_auth_data_free)(void *data);

int (*interactive_auth_clb)(const struct nc_session *session, ssh_message msg, void *user_data);
int (*interactive_auth_clb)(const struct nc_session *session, ssh_session ssh_sess, ssh_message msg, void *user_data);
void *interactive_auth_data;
void (*interactive_auth_data_free)(void *data);

Expand Down
18 changes: 18 additions & 0 deletions src/session_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,24 @@ nc_server_destroy(void)
nc_server_config_ch(NULL, NC_OP_DELETE);

#ifdef NC_ENABLED_SSH_TLS
if (server_opts.passwd_auth_data && server_opts.passwd_auth_data_free) {
server_opts.passwd_auth_data_free(server_opts.passwd_auth_data);
}
server_opts.passwd_auth_data = NULL;
server_opts.passwd_auth_data_free = NULL;

if (server_opts.pubkey_auth_data && server_opts.pubkey_auth_data_free) {
server_opts.pubkey_auth_data_free(server_opts.pubkey_auth_data);
}
server_opts.pubkey_auth_data = NULL;
server_opts.pubkey_auth_data_free = NULL;

if (server_opts.interactive_auth_data && server_opts.interactive_auth_data_free) {
server_opts.interactive_auth_data_free(server_opts.interactive_auth_data);
}
server_opts.interactive_auth_data = NULL;
server_opts.interactive_auth_data_free = NULL;

nc_server_config_ks_keystore(NULL, NC_OP_DELETE);
nc_server_config_ts_truststore(NULL, NC_OP_DELETE);
curl_global_cleanup();
Expand Down
4 changes: 2 additions & 2 deletions src/session_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@ void nc_server_ssh_set_passwd_auth_clb(int (*passwd_auth_clb)(const struct nc_se
void *user_data), void *user_data, void (*free_user_data)(void *user_data));

/**
* @brief Set the callback for SSH interactive authentication. If none is set, local system users are used.
* @brief Set the callback for SSH interactive authentication. If not set, local PAM-based authentication is used.
*
* @param[in] interactive_auth_clb Callback that should authenticate the user.
* Zero return indicates success, non-zero an error.
* @param[in] user_data Optional arbitrary user data that will be passed to @p interactive_auth_clb.
* @param[in] free_user_data Optional callback that will be called during cleanup to free any @p user_data.
*/
void nc_server_ssh_set_interactive_auth_clb(int (*interactive_auth_clb)(const struct nc_session *session,
const ssh_message msg, void *user_data), void *user_data, void (*free_user_data)(void *user_data));
ssh_session ssh_sess, ssh_message msg, void *user_data), void *user_data, void (*free_user_data)(void *user_data));

/**
* @brief Set the callback for SSH public key authentication. If none is set, local system users are used.
Expand Down
6 changes: 3 additions & 3 deletions src/session_server_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ nc_server_ssh_set_passwd_auth_clb(int (*passwd_auth_clb)(const struct nc_session
}

API void
nc_server_ssh_set_interactive_auth_clb(int (*interactive_auth_clb)(const struct nc_session *session, ssh_message msg, void *user_data),
void *user_data, void (*free_user_data)(void *user_data))
nc_server_ssh_set_interactive_auth_clb(int (*interactive_auth_clb)(const struct nc_session *session, ssh_session ssh_sess,
ssh_message msg, void *user_data), void *user_data, void (*free_user_data)(void *user_data))
{
server_opts.interactive_auth_clb = interactive_auth_clb;
server_opts.interactive_auth_data = user_data;
Expand Down Expand Up @@ -476,7 +476,7 @@ nc_sshcb_auth_kbdint(struct nc_session *session, struct nc_server_ssh_opts *opts
int auth_ret = 1;

if (server_opts.interactive_auth_clb) {
auth_ret = server_opts.interactive_auth_clb(session, msg, server_opts.interactive_auth_data);
auth_ret = server_opts.interactive_auth_clb(session, session->ti.libssh.session, msg, server_opts.interactive_auth_data);
} else {
#ifdef HAVE_LIBPAM
if (nc_pam_auth(session, opts, msg) == PAM_SUCCESS) {
Expand Down

0 comments on commit 7621590

Please sign in to comment.