123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #include "includes.h"
- #include "session.h"
- #include "buffer.h"
- #include "dbutil.h"
- #include "auth.h"
- #include "runopts.h"
- #ifdef ENABLE_SVR_PASSWORD_AUTH
- static int constant_time_strcmp(const char* a, const char* b) {
- size_t la = strlen(a);
- size_t lb = strlen(b);
- if (la != lb) {
- return 1;
- }
- return constant_time_memcmp(a, b, la);
- }
- void svr_auth_password() {
-
- char * passwdcrypt = NULL;
- char * testcrypt = NULL;
- char * password;
- unsigned int passwordlen;
- unsigned int changepw;
- passwdcrypt = ses.authstate.pw_passwd;
- #ifdef DEBUG_HACKCRYPT
-
- passwdcrypt = DEBUG_HACKCRYPT;
- #endif
-
- changepw = buf_getbool(ses.payload);
- if (changepw) {
-
- send_msg_userauth_failure(0, 1);
- return;
- }
- password = buf_getstring(ses.payload, &passwordlen);
-
- testcrypt = crypt(password, passwdcrypt);
- m_burn(password, passwordlen);
- m_free(password);
- if (testcrypt == NULL) {
-
- dropbear_log(LOG_WARNING, "User account '%s' is locked",
- ses.authstate.pw_name);
- send_msg_userauth_failure(0, 1);
- return;
- }
-
- if (passwdcrypt[0] == '\0') {
- dropbear_log(LOG_WARNING, "User '%s' has blank password, rejected",
- ses.authstate.pw_name);
- send_msg_userauth_failure(0, 1);
- return;
- }
- if (constant_time_strcmp(testcrypt, passwdcrypt) == 0) {
-
- dropbear_log(LOG_NOTICE,
- "Password auth succeeded for '%s' from %s",
- ses.authstate.pw_name,
- svr_ses.addrstring);
- send_msg_userauth_success();
- } else {
- dropbear_log(LOG_WARNING,
- "Bad password attempt for '%s' from %s",
- ses.authstate.pw_name,
- svr_ses.addrstring);
- send_msg_userauth_failure(0, 1);
- }
- }
- #endif
|