@@ -345,7 +345,8 @@ class SessionCallback
345345 {
346346 server_cb.userdata = this ;
347347 server_cb.auth_pubkey_function = authPublickeyAdapter<ssh_session, const char *, ssh_key, char >;
348- ssh_set_auth_methods (session.getInternalPtr (), SSH_AUTH_METHOD_PUBLICKEY);
348+ server_cb.auth_password_function = authPasswordAdapter<ssh_session, const char *, const char *>;
349+ ssh_set_auth_methods (session.getInternalPtr (), SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_PUBLICKEY);
349350 server_cb.channel_open_request_session_function = channelOpenAdapter<ssh_session>;
350351
351352 ssh_callbacks_init (&server_cb)
@@ -395,11 +396,11 @@ class SessionCallback
395396 {
396397 auto user_has_ssh_auth_type = [](auto user_authentication_type) { return user_authentication_type == AuthenticationType::SSH_KEY; };
397398 auto user_auth_types = db_session_created->getAuthenticationTypes (user_name);
399+
400+ // / User {} doesn't have SSH_KEY authentication type, so we will try to authenticate it using a password.
398401 if (auto result = std::ranges::find_if (user_auth_types, user_has_ssh_auth_type); result == user_auth_types.end ())
399- {
400- LOG_WARNING (log, " User {} doesn't have SSH_KEY authentication type" , user_name);
401- return SSH_AUTH_DENIED;
402- }
402+ return SSH_AUTH_PARTIAL;
403+
403404 return SSH_AUTH_SUCCESS;
404405 }
405406
@@ -431,6 +432,27 @@ class SessionCallback
431432
432433 GENERATE_ADAPTER_FUNCTION (SessionCallback, authPublickey, int )
433434
435+ int authPassword(ssh_session, const char * user, const char * password)
436+ {
437+ try
438+ {
439+ LOG_TRACE (log, " Authenticating with password" );
440+ auto db_session_created = std::make_unique<Session>(server_context, ClientInfo::Interface::LOCAL);
441+ db_session_created->authenticate (BasicCredentials{user, password}, peer_address);
442+ authenticated = true ;
443+ db_session = std::move (db_session_created);
444+ return SSH_AUTH_SUCCESS;
445+ }
446+ catch (...)
447+ {
448+ tryLogCurrentException (log);
449+ ++auth_attempts;
450+ return SSH_AUTH_DENIED;
451+ }
452+ }
453+
454+ GENERATE_ADAPTER_FUNCTION (SessionCallback, authPassword, int )
455+
434456 ssh_server_callbacks_struct server_cb = {};
435457};
436458
0 commit comments