Parcourir la source

ssh: log ssh logins separately from telnet ones

Sergey Alirzaev il y a 5 ans
Parent
commit
031d4ff811
5 fichiers modifiés avec 23 ajouts et 3 suppressions
  1. 1 1
      modules/SSH_Server/server.c
  2. 14 1
      modules/cli/cli.c
  3. 2 1
      modules/cli/cli.h
  4. 3 0
      modules/log/log.c
  5. 3 0
      modules/log/log.h

+ 1 - 1
modules/SSH_Server/server.c

@@ -275,7 +275,7 @@ static int wsUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
     char password[MAX_WEB_PASSWD_LEN];
     strncpy(password, (char *)authData->sf.password.password, sizeof(password));
     password[min(MAX_WEB_PASSWD_LEN - 1, authData->sf.password.passwordSz)] = 0;
-    *user_id = cli_auth_user(authData->username, password);
+    *user_id = cli_auth_user((const char *)authData->username, password, LOG_LOGIN_SSH);
     if (*user_id != MAX_USER_LEVELS) {
         return WOLFSSH_USERAUTH_SUCCESS;
     }

+ 14 - 1
modules/cli/cli.c

@@ -278,7 +278,7 @@ void cli_hello(cli_state_t *cli_state)
 	cli_state->send(cli_state->num_connect, hello, sizeof(hello));
 }
 
-user_level_t cli_auth_user(char *user, char *password)
+user_level_t cli_auth_user(const char *user, const char *password, log_type_t log_entry_type)
 {
 	user_level_t rv = MAX_USER_LEVELS;
 	char WebPassword[MAX_WEB_PASSWD_LEN];
@@ -294,6 +294,19 @@ user_level_t cli_auth_user(char *user, char *password)
 
 			/* Login and pass are valid */
 			rv = user_id;
+			const char *username;
+			switch (user_id) {
+				case 0:
+					username = "Администратор";
+					break;
+				case 1:
+					username = "Пользователь";
+					break;
+				default:
+					break;
+			}
+
+			log_event_data(log_entry_type, username);
 			break;
 		}
 	}

+ 2 - 1
modules/cli/cli.h

@@ -6,6 +6,7 @@
 #include "FreeRTOS.h"
 #include "fr_timers.h"
 #include "settings_api.h"
+#include "log.h"
 
 /* Dimensions the buffer into which input characters are placed. */
 #define cmdMAX_INPUT_SIZE			144
@@ -54,7 +55,7 @@ void cli_getchar(cli_state_t *s, char incoming_char);
 cli_state_t *alloc_state(void);
 void free_state(cli_state_t *state);
 void cli_hello(cli_state_t *cli_state);
-user_level_t cli_auth_user(char *user, char *password);
+user_level_t cli_auth_user(const char *user, const char *password, log_type_t log_entry_type);
 void cli_close_connections(void);
 
 #endif

+ 3 - 0
modules/log/log.c

@@ -26,6 +26,9 @@ const char* logsStrShortRu[] =
     "Сохранение настроек",
 #if	defined HARDWARE_BT6707 || HARDWARE_BT6709
     "Авторизация (Telnet)",
+#ifdef HARDWARE_BT6709
+    "Авторизация (SSH)",
+#endif // HARDWARE_BT6709
 #endif
     "Авторизация",
     "Тест ИБП",

+ 3 - 0
modules/log/log.h

@@ -24,6 +24,9 @@ typedef __packed enum {
 	LOG_SETTING_SAVE,		//
 #if	defined HARDWARE_BT6707 || HARDWARE_BT6709
 	LOG_LOGIN_TELNET,		//
+#ifdef HARDWARE_BT6709
+	LOG_LOGIN_SSH,
+#endif // HARDWARE_BT6709
 #endif
 	LOG_LOGIN,		//
 	LOG_TEST_UPS,		//