@@ -142,6 +142,25 @@ nc_server_ssh_set_passwd_auth_clb(int (*passwd_auth_clb)(const struct nc_session
142142 server_opts .passwd_auth_data_free = free_user_data ;
143143}
144144
145+ API void
146+ nc_server_ssh_set_interactive_auth_clb (int (* interactive_auth_clb )(const struct nc_session * session , ssh_message msg , void * user_data ),
147+ void * user_data , void (* free_user_data )(void * user_data ))
148+ {
149+ server_opts .interactive_auth_clb = interactive_auth_clb ;
150+ server_opts .interactive_auth_data = user_data ;
151+ server_opts .interactive_auth_data_free = free_user_data ;
152+ }
153+
154+ API void
155+ nc_server_ssh_set_pubkey_auth_clb (int (* pubkey_auth_clb )(const struct nc_session * session , ssh_key key , void * user_data ),
156+ void * user_data , void (* free_user_data )(void * user_data ))
157+ {
158+ server_opts .pubkey_auth_clb = pubkey_auth_clb ;
159+ server_opts .pubkey_auth_data = user_data ;
160+ server_opts .pubkey_auth_data_free = free_user_data ;
161+ }
162+
163+
145164API int
146165nc_server_ssh_ch_client_add_hostkey (const char * client_name , const char * name , int16_t idx )
147166{
@@ -822,41 +841,37 @@ nc_sshcb_auth_kbdint(struct nc_session *session, ssh_message msg)
822841{
823842 int auth_ret = 1 ;
824843 char * pass_hash ;
825- // Print message for interactive SSH
826- if (!ssh_message_auth_kbdint_is_response (msg )) {
827- const char * prompts [] = {"Password: " };
828- char echo [] = {0 };
829844
830- ssh_message_auth_interactive_request (msg , "Interactive SSH Authentication" , "Type your password:" , 1 , prompts , echo );
845+ if (server_opts .interactive_auth_clb ) {
846+ auth_ret = server_opts .interactive_auth_clb (session , msg , server_opts .interactive_auth_clb );
831847 } else {
832- if (ssh_userauth_kbdint_getnanswers ( session -> ti . libssh . session ) != 1 ) {// failed session
833- ssh_message_reply_default ( msg ) ;
834- return ;
835- }
836- // Check the authentication type
837- if ( server_opts . interactive_auth_clb )
838- {
839- auth_ret = server_opts . interactive_auth_clb ( session , ssh_message_auth_password (msg ), server_opts . interactive_auth_clb );
840- }
841- else {
848+ if (! ssh_message_auth_kbdint_is_response ( msg ) ) {
849+ const char * prompts [] = { "Password: " } ;
850+ char echo [] = { 0 } ;
851+
852+ ssh_message_auth_interactive_request ( msg , "Interactive SSH Authentication" , "Type your password:" , 1 , prompts , echo );
853+ } else {
854+ if ( ssh_userauth_kbdint_getnanswers ( session -> ti . libssh . session ) != 1 ) { // failed session
855+ ssh_message_reply_default (msg );
856+ return ;
857+ }
842858 pass_hash = auth_password_get_pwd_hash (session -> username );// get hashed password
843859 if (pass_hash ) {
844860 auth_ret = auth_password_compare_pwd (pass_hash , ssh_userauth_kbdint_getanswer (session -> ti .libssh .session , 0 ));
845861 free (pass_hash );// free hashed password
846862 }
847863 }
848- // Authenticate message based on outcome
849- if (!auth_ret )
850- {
851- session -> flags |= NC_SESSION_SSH_AUTHENTICATED ;
852- VRB ("User \"%s\" authenticated." , session -> username );
853- ssh_message_auth_reply_success (msg , 0 );
854- }
855- else {
856- ++ session -> opts .server .ssh_auth_attempts ;
857- VRB ("Failed user \"%s\" authentication attempt (#%d)." , session -> username , session -> opts .server .ssh_auth_attempts );
858- ssh_message_reply_default (msg );
859- }
864+ }
865+
866+ /* Authenticate message based on outcome */
867+ if (!auth_ret ) {
868+ session -> flags |= NC_SESSION_SSH_AUTHENTICATED ;
869+ VRB ("User \"%s\" authenticated." , session -> username );
870+ ssh_message_auth_reply_success (msg , 0 );
871+ } else {
872+ ++ session -> opts .server .ssh_auth_attempts ;
873+ VRB ("Failed user \"%s\" authentication attempt (#%d)." , session -> username , session -> opts .server .ssh_auth_attempts );
874+ ssh_message_reply_default (msg );
860875 }
861876}
862877
0 commit comments