@@ -320,7 +320,7 @@ static int CheckPasswordHashUnix(const char* input, char* stored)
320320 }
321321
322322 /* empty password case */
323- if (stored [0 ] == 0 && WSTRLEN (input ) == 0 ) {
323+ if (ret == WSSHD_AUTH_SUCCESS && stored [0 ] == 0 && WSTRLEN (input ) == 0 ) {
324324 wolfSSH_Log (WS_LOG_INFO ,
325325 "[SSHD] User logged in with empty password" );
326326 return ret ;
@@ -1206,49 +1206,47 @@ static int RequestAuthentication(WS_UserAuthData* authData,
12061206 }
12071207 #endif
12081208
1209- if (ret == WOLFSSH_USERAUTH_SUCCESS ) {
1210- /* if this is a certificate and no specific authorized keys file has
1211- * been set then rely on CA to have verified the cert */
1212- if (authData -> sf .publicKey .isCert &&
1213- !wolfSSHD_ConfigGetAuthKeysFileSet (authCtx -> conf )) {
1214- wolfSSH_Log (WS_LOG_INFO ,
1215- "[SSHD] Relying on CA for public key check" );
1216- #ifdef WIN32
1217- /* Still need to get users token on Windows */
1218- rc = SetupUserTokenWin (usr , & authData -> sf .publicKey ,
1219- wolfSSHD_ConfigGetUserCAKeysFile (authCtx -> conf ), authCtx );
1220- if (rc == WSSHD_AUTH_SUCCESS ) {
1221- wolfSSH_Log (WS_LOG_INFO , "[SSHD] Got users token ok." );
1222- ret = WOLFSSH_USERAUTH_SUCCESS ;
1223- }
1224- else {
1225- wolfSSH_Log (WS_LOG_ERROR ,
1226- "[SSHD] Error getting users token." );
1227- ret = WOLFSSH_USERAUTH_FAILURE ;
1228- }
1229- #else
1209+ /* if this is a certificate and no specific authorized keys file has
1210+ * been set then rely on CA to have verified the cert */
1211+ if (authData -> sf .publicKey .isCert &&
1212+ !wolfSSHD_ConfigGetAuthKeysFileSet (authCtx -> conf )) {
1213+ wolfSSH_Log (WS_LOG_INFO ,
1214+ "[SSHD] Relying on CA for public key check" );
1215+ #ifdef WIN32
1216+ /* Still need to get users token on Windows */
1217+ rc = SetupUserTokenWin (usr , & authData -> sf .publicKey ,
1218+ wolfSSHD_ConfigGetUserCAKeysFile (authCtx -> conf ), authCtx );
1219+ if (rc == WSSHD_AUTH_SUCCESS ) {
1220+ wolfSSH_Log (WS_LOG_INFO , "[SSHD] Got users token ok." );
12301221 ret = WOLFSSH_USERAUTH_SUCCESS ;
1231- #endif
12321222 }
12331223 else {
1234- /* if not a certificate then parse through authorized key file */
1235- rc = authCtx -> checkPublicKeyCb (usr , & authData -> sf .publicKey ,
1236- wolfSSHD_ConfigGetUserCAKeysFile (authCtx -> conf ),
1237- authCtx );
1238- if (rc == WSSHD_AUTH_SUCCESS ) {
1239- wolfSSH_Log (WS_LOG_INFO , "[SSHD] Public key ok." );
1240- ret = WOLFSSH_USERAUTH_SUCCESS ;
1241- }
1242- else if (rc == WSSHD_AUTH_FAILURE ) {
1243- wolfSSH_Log (WS_LOG_INFO ,
1244- "[SSHD] Public key not authorized." );
1245- ret = WOLFSSH_USERAUTH_INVALID_PUBLICKEY ;
1246- }
1247- else {
1248- wolfSSH_Log (WS_LOG_ERROR ,
1249- "[SSHD] Error checking public key." );
1250- ret = WOLFSSH_USERAUTH_FAILURE ;
1251- }
1224+ wolfSSH_Log (WS_LOG_ERROR ,
1225+ "[SSHD] Error getting users token." );
1226+ ret = WOLFSSH_USERAUTH_FAILURE ;
1227+ }
1228+ #else
1229+ ret = WOLFSSH_USERAUTH_SUCCESS ;
1230+ #endif
1231+ }
1232+ else {
1233+ /* if not a certificate then parse through authorized key file */
1234+ rc = authCtx -> checkPublicKeyCb (usr , & authData -> sf .publicKey ,
1235+ wolfSSHD_ConfigGetUserCAKeysFile (authCtx -> conf ),
1236+ authCtx );
1237+ if (rc == WSSHD_AUTH_SUCCESS ) {
1238+ wolfSSH_Log (WS_LOG_INFO , "[SSHD] Public key ok." );
1239+ ret = WOLFSSH_USERAUTH_SUCCESS ;
1240+ }
1241+ else if (rc == WSSHD_AUTH_FAILURE ) {
1242+ wolfSSH_Log (WS_LOG_INFO ,
1243+ "[SSHD] Public key not authorized." );
1244+ ret = WOLFSSH_USERAUTH_INVALID_PUBLICKEY ;
1245+ }
1246+ else {
1247+ wolfSSH_Log (WS_LOG_ERROR ,
1248+ "[SSHD] Error checking public key." );
1249+ ret = WOLFSSH_USERAUTH_FAILURE ;
12521250 }
12531251 }
12541252 }
@@ -1545,23 +1543,23 @@ int wolfSSHD_AuthReducePermissions(WOLFSSHD_AUTH* auth)
15451543 byte flag = 0 ;
15461544 int ret = WS_SUCCESS ;
15471545
1546+ if (!auth ) {
1547+ return WS_BAD_ARGUMENT ;
1548+ }
1549+
15481550 flag = wolfSSHD_ConfigGetPrivilegeSeparation (auth -> conf );
15491551#ifndef WIN32
15501552 if (flag == WOLFSSHD_PRIV_SEPARAT || flag == WOLFSSHD_PRIV_SANDBOX ) {
15511553 wolfSSH_Log (WS_LOG_INFO , "[SSHD] Lowering permissions level" );
1552- if (auth ) {
1553- if (setegid (auth -> gid ) != 0 ) {
1554- wolfSSH_Log (WS_LOG_ERROR , "[SSHD] Error setting sshd gid" );
1555- ret = WS_FATAL_ERROR ;
1556- }
15571554
1558- if (seteuid (auth -> uid ) != 0 ) {
1559- wolfSSH_Log (WS_LOG_ERROR , "[SSHD] Error setting sshd uid" );
1560- ret = WS_FATAL_ERROR ;
1561- }
1555+ if (setegid (auth -> gid ) != 0 ) {
1556+ wolfSSH_Log (WS_LOG_ERROR , "[SSHD] Error setting sshd gid" );
1557+ ret = WS_FATAL_ERROR ;
15621558 }
1563- else {
1564- ret = WS_BAD_ARGUMENT ;
1559+
1560+ if (seteuid (auth -> uid ) != 0 ) {
1561+ wolfSSH_Log (WS_LOG_ERROR , "[SSHD] Error setting sshd uid" );
1562+ ret = WS_FATAL_ERROR ;
15651563 }
15661564 }
15671565#endif
0 commit comments