~jonathank89/burg/burg-percise

« back to all changes in this revision

Viewing changes to commands/password.c

merge mainline into mips

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include <grub/auth.h>
 
20
#include <grub/crypto.h>
20
21
#include <grub/list.h>
21
22
#include <grub/mm.h>
22
23
#include <grub/misc.h>
23
24
#include <grub/env.h>
24
25
#include <grub/normal.h>
25
26
#include <grub/dl.h>
 
27
#include <grub/i18n.h>
26
28
 
27
29
static grub_dl_t my_mod;
28
30
 
29
31
static grub_err_t
30
 
check_password (const char *user,
 
32
check_password (const char *user, const char *entered,
31
33
                void *password)
32
34
{
33
 
  char entered[1024];
34
 
 
35
 
  grub_memset (entered, 0, sizeof (entered));
36
 
 
37
 
  if (!GRUB_GET_PASSWORD (entered, sizeof (entered) - 1))
38
 
    return GRUB_ACCESS_DENIED;
39
 
 
40
 
  if (grub_auth_strcmp (entered, password) != 0)
 
35
  if (grub_crypto_memcmp (entered, password, GRUB_AUTH_MAX_PASSLEN) != 0)
41
36
    return GRUB_ACCESS_DENIED;
42
37
 
43
38
  grub_auth_authenticate (user);
51
46
{
52
47
  grub_err_t err;
53
48
  char *pass;
 
49
  int copylen;
54
50
 
55
51
  if (argc != 2)
56
52
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "two arguments expected");
57
53
 
58
 
  pass = grub_strdup (args[1]);
 
54
  pass = grub_zalloc (GRUB_AUTH_MAX_PASSLEN);
59
55
  if (!pass)
60
56
    return grub_errno;
 
57
  copylen = grub_strlen (args[1]);
 
58
  if (copylen >= GRUB_AUTH_MAX_PASSLEN)
 
59
    copylen = GRUB_AUTH_MAX_PASSLEN - 1;
 
60
  grub_memcpy (pass, args[1], copylen);
61
61
 
62
62
  err = grub_auth_register_authentication (args[0], check_password, pass);
63
63
  if (err)
75
75
{
76
76
  my_mod = mod;
77
77
  cmd = grub_register_command ("password", grub_cmd_password,
78
 
                               "USER PASSWORD",
79
 
                               "Set user password (plaintext). "
80
 
                               "Unrecommended and insecure.");
 
78
                               N_("USER PASSWORD"),
 
79
                               N_("Set user password (plaintext). "
 
80
                               "Unrecommended and insecure."));
81
81
}
82
82
 
83
83
GRUB_MOD_FINI(password)