MAX_PASSLEN based authentication
This commit is contained in:
parent
10e53efaee
commit
228734ab02
3 changed files with 13 additions and 63 deletions
|
@ -26,18 +26,20 @@
|
|||
|
||||
static grub_dl_t my_mod;
|
||||
|
||||
#define MAX_PASSLEN 1024
|
||||
|
||||
static grub_err_t
|
||||
check_password (const char *user,
|
||||
void *password)
|
||||
{
|
||||
char entered[1024];
|
||||
char entered[MAX_PASSLEN];
|
||||
|
||||
grub_memset (entered, 0, sizeof (entered));
|
||||
|
||||
if (!GRUB_GET_PASSWORD (entered, sizeof (entered) - 1))
|
||||
return GRUB_ACCESS_DENIED;
|
||||
|
||||
if (grub_auth_strcmp (entered, password) != 0)
|
||||
if (grub_crypto_memcmp (entered, password, MAX_PASSLEN) != 0)
|
||||
return GRUB_ACCESS_DENIED;
|
||||
|
||||
grub_auth_authenticate (user);
|
||||
|
@ -51,13 +53,18 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)),
|
|||
{
|
||||
grub_err_t err;
|
||||
char *pass;
|
||||
int copylen;
|
||||
|
||||
if (argc != 2)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two arguments expected.");
|
||||
|
||||
pass = grub_strdup (args[1]);
|
||||
pass = grub_zalloc (MAX_PASSLEN);
|
||||
if (!pass)
|
||||
return grub_errno;
|
||||
copylen = grub_strlen (argv[1]);
|
||||
if (copylen >= MAX_PASSLEN)
|
||||
copylen = MAX_PASSLEN - 1;
|
||||
grub_memcpy (pass, argv[1], copylen);
|
||||
|
||||
err = grub_auth_register_authentication (args[0], check_password, pass);
|
||||
if (err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue