@@ -923,7 +923,7 @@ nc_server_ssh_auth_kbdint_pam(struct nc_session *session, const char *username,
923923 * @return 0 on success, non-zero otherwise.
924924 */
925925static int
926- nc_server_ssh_auth_kbdint_system (struct nc_session * session , const char * username , ssh_message msg )
926+ nc_server_ssh_auth_kbdint_passwd (struct nc_session * session , const char * username , ssh_message msg )
927927{
928928 int ret = 0 , n_answers ;
929929 const char * name = "Keyboard-Interactive Authentication" ;
@@ -975,6 +975,32 @@ nc_server_ssh_auth_kbdint_system(struct nc_session *session, const char *usernam
975975
976976#endif
977977
978+ /**
979+ * @brief Keyboard-interactive authentication method using the system's authentication methods.
980+ *
981+ * @param[in] session NETCONF session.
982+ * @param[in] msg SSH message with a keyboard-interactive authentication request.
983+ * @return 0 on success, non-zero otherwise.
984+ */
985+ static int
986+ nc_server_ssh_auth_kbdint_system (struct nc_session * session , ssh_message msg )
987+ {
988+ int rc ;
989+
990+ #ifdef HAVE_LIBPAM
991+ /* authenticate using PAM */
992+ rc = nc_server_ssh_auth_kbdint_pam (session , session -> username , msg );
993+ #elif defined (HAVE_SHADOW )
994+ /* authenticate using /etc/passwd and /etc/shadow */
995+ rc = nc_server_ssh_auth_kbdint_passwd (session , session -> username , msg );
996+ #else
997+ ERR (NULL , "Keyboard-interactive method not supported." );
998+ rc = 1 ;
999+ #endif
1000+
1001+ return rc ;
1002+ }
1003+
9781004API void
9791005nc_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 ),
9801006 void * user_data , void (* free_user_data )(void * user_data ))
@@ -1319,22 +1345,19 @@ nc_server_ssh_auth_kbdint(struct nc_session *session, int local_users_supported,
13191345
13201346 assert (!local_users_supported || auth_client );
13211347
1322- if (local_users_supported && !auth_client -> kb_int_enabled ) {
1348+ if (local_users_supported && !auth_client -> kbdint_method ) {
13231349 VRB (session , "User \"%s\" does not have Keyboard-interactive method configured, but a request was received." , session -> username );
13241350 return 1 ;
13251351 } else if (server_opts .interactive_auth_clb ) {
13261352 rc = server_opts .interactive_auth_clb (session , session -> ti .libssh .session , msg , server_opts .interactive_auth_data );
13271353 } else {
1328- #ifdef HAVE_LIBPAM
1329- /* authenticate using PAM */
1330- rc = nc_server_ssh_auth_kbdint_pam (session , session -> username , msg );
1331- #elif defined (HAVE_SHADOW )
1332- /* authenticate using the system */
1333- rc = nc_server_ssh_auth_kbdint_system (session , session -> username , msg );
1334- #else
1335- ERR (NULL , "Keyboard-interactive method not supported." );
1336- return 1 ;
1337- #endif
1354+ /* perform the authentication based on the configured method */
1355+ if (auth_client -> kbdint_method == NC_KBDINT_AUTH_METHOD_SYSTEM ) {
1356+ rc = nc_server_ssh_auth_kbdint_system (session , msg );
1357+ } else {
1358+ ERR (session , "Keyboard-interactive authentication method not supported." );
1359+ rc = 1 ;
1360+ }
13381361 }
13391362
13401363 return rc ? 1 : 0 ;
@@ -1509,7 +1532,7 @@ nc_server_ssh_auth(struct nc_session *session, struct nc_server_ssh_opts *opts,
15091532 auth_state -> methods |= SSH_AUTH_METHOD_PASSWORD ;
15101533 auth_state -> method_count ++ ;
15111534 }
1512- if (auth_client -> kb_int_enabled ) {
1535+ if (auth_client -> kbdint_method ) {
15131536 auth_state -> methods |= SSH_AUTH_METHOD_INTERACTIVE ;
15141537 auth_state -> method_count ++ ;
15151538 }
0 commit comments