mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/shell: add pseudomodule shell_lock_auto_locking
Module to lock the shell after a given timeout of time x. When the shell did not receive any input within time x, then the shell is locked automatically.
This commit is contained in:
parent
2284f87fdb
commit
ccc795133f
@ -202,6 +202,7 @@ PSEUDOMODULES += senml_saul
|
||||
PSEUDOMODULES += sha1sum
|
||||
PSEUDOMODULES += sha256sum
|
||||
PSEUDOMODULES += shell_hooks
|
||||
PSEUDOMODULES += shell_lock_auto_locking
|
||||
PSEUDOMODULES += slipdev_stdio
|
||||
PSEUDOMODULES += slipdev_l2addr
|
||||
PSEUDOMODULES += sock
|
||||
|
@ -42,6 +42,15 @@ extern "C" {
|
||||
*/
|
||||
#define CONFIG_SHELL_LOCK_ATTEMPTS_BEFORE_TIME_LOCK 3
|
||||
|
||||
#ifndef CONFIG_SHELL_LOCK_AUTO_LOCK_TIMEOUT_MS
|
||||
/**
|
||||
* @brief Lock the shell after this time span without user input
|
||||
* Defaults to 5 minutes but can be overwritten in the applications
|
||||
* Makefile.
|
||||
*/
|
||||
#define CONFIG_SHELL_LOCK_AUTO_LOCK_TIMEOUT_MS (5 * 60 * 1000)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Entry point for the lock mechanism. If locked, the user will
|
||||
* be asked for a password. This function won't return until the
|
||||
|
@ -64,7 +64,7 @@ XFA_INIT_CONST(shell_command_t*, shell_commands_xfa);
|
||||
|
||||
extern void shell_lock_checkpoint(char *line_buf, int len);
|
||||
extern bool shell_lock_is_locked(void);
|
||||
extern void shell_lock_reset(void);
|
||||
extern void shell_lock_auto_lock_refresh(void);
|
||||
|
||||
enum parse_state {
|
||||
PARSE_BLANK = 0x0,
|
||||
@ -492,6 +492,11 @@ void shell_run_once(const shell_command_t *shell_commands,
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_USED(MODULE_SHELL_LOCK_AUTO_LOCKING)) {
|
||||
/* reset lock countdown in case of new input */
|
||||
shell_lock_auto_lock_refresh();
|
||||
}
|
||||
|
||||
switch (res) {
|
||||
|
||||
case EOF:
|
||||
|
@ -18,6 +18,10 @@
|
||||
* slow down brute force attacks.
|
||||
* Does not make use of any cryptographic features yet.
|
||||
*
|
||||
* This module also provides a pseudomodule for automated locking after a given
|
||||
* interval. Add "USEMODULE += shell_lock_auto_locking" to your Makefile to
|
||||
* enable this feature.
|
||||
*
|
||||
* @author Hendrik van Essen <hendrik.ve@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
@ -29,7 +33,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "shell_lock.h"
|
||||
|
||||
@ -41,6 +45,10 @@
|
||||
|
||||
static bool _shell_is_locked = true;
|
||||
|
||||
#ifdef MODULE_SHELL_LOCK_AUTO_LOCKING
|
||||
static ztimer_t _shell_auto_lock_ztimer;
|
||||
#endif
|
||||
|
||||
/* defined in shell.c */
|
||||
extern int readline(char *buf, size_t size);
|
||||
|
||||
@ -135,6 +143,22 @@ static void _login_barrier(char *line_buf, size_t buf_size)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MODULE_SHELL_LOCK_AUTO_LOCKING
|
||||
static void _shell_auto_lock_ztimer_callback(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
|
||||
_shell_is_locked = true;
|
||||
}
|
||||
|
||||
void shell_lock_auto_lock_refresh(void)
|
||||
{
|
||||
ztimer_remove(ZTIMER_MSEC, &_shell_auto_lock_ztimer);
|
||||
ztimer_set(ZTIMER_MSEC, &_shell_auto_lock_ztimer,
|
||||
CONFIG_SHELL_LOCK_AUTO_LOCK_TIMEOUT_MS);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool shell_lock_is_locked(void)
|
||||
{
|
||||
return _shell_is_locked;
|
||||
@ -147,6 +171,20 @@ void shell_lock_checkpoint(char *line_buf, int buf_size)
|
||||
|
||||
_login_barrier(line_buf, buf_size);
|
||||
|
||||
if (IS_USED(MODULE_SHELL_LOCK_AUTO_LOCKING)) {
|
||||
printf("Shell was unlocked.\n\n");
|
||||
}
|
||||
else {
|
||||
printf("Shell was unlocked.\n\n"
|
||||
"IMPORTANT: Don't forget to lock the shell after usage, "
|
||||
"because it won't lock itself.\n\n");
|
||||
}
|
||||
|
||||
_shell_is_locked = false;
|
||||
}
|
||||
|
||||
#ifdef MODULE_SHELL_LOCK_AUTO_LOCKING
|
||||
_shell_auto_lock_ztimer.callback = &_shell_auto_lock_ztimer_callback;
|
||||
shell_lock_auto_lock_refresh();
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user