~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to normal/auth.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2009  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <grub/auth.h>
20
 
#include <grub/list.h>
21
 
#include <grub/mm.h>
22
 
#include <grub/misc.h>
23
 
#include <grub/env.h>
24
 
#include <grub/normal.h>
25
 
#include <grub/time.h>
26
 
#include <grub/i18n.h>
27
 
 
28
 
struct grub_auth_user
29
 
{
30
 
  struct grub_auth_user *next;
31
 
  char *name;
32
 
  grub_auth_callback_t callback;
33
 
  void *arg;
34
 
  int authenticated;
35
 
};
36
 
 
37
 
struct grub_auth_user *users = NULL;
38
 
 
39
 
grub_err_t
40
 
grub_auth_register_authentication (const char *user,
41
 
                                   grub_auth_callback_t callback,
42
 
                                   void *arg)
43
 
{
44
 
  struct grub_auth_user *cur;
45
 
 
46
 
  cur = grub_named_list_find (GRUB_AS_NAMED_LIST (users), user);
47
 
  if (!cur)
48
 
    cur = grub_zalloc (sizeof (*cur));
49
 
  if (!cur)
50
 
    return grub_errno;
51
 
  cur->callback = callback;
52
 
  cur->arg = arg;
53
 
  if (! cur->name)
54
 
    {
55
 
      cur->name = grub_strdup (user);
56
 
      if (!cur->name)
57
 
        {
58
 
          grub_free (cur);
59
 
          return grub_errno;
60
 
        }
61
 
      grub_list_push (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur));
62
 
    }
63
 
  return GRUB_ERR_NONE;
64
 
}
65
 
 
66
 
grub_err_t
67
 
grub_auth_unregister_authentication (const char *user)
68
 
{
69
 
  struct grub_auth_user *cur;
70
 
  cur = grub_named_list_find (GRUB_AS_NAMED_LIST (users), user);
71
 
  if (!cur)
72
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "user '%s' not found", user);
73
 
  if (!cur->authenticated)
74
 
    {
75
 
      grub_free (cur->name);
76
 
      grub_list_remove (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur));
77
 
      grub_free (cur);
78
 
    }
79
 
  else
80
 
    {
81
 
      cur->callback = NULL;
82
 
      cur->arg = NULL;
83
 
    }
84
 
  return GRUB_ERR_NONE;
85
 
}
86
 
 
87
 
grub_err_t
88
 
grub_auth_authenticate (const char *user)
89
 
{
90
 
  struct grub_auth_user *cur;
91
 
 
92
 
  cur = grub_named_list_find (GRUB_AS_NAMED_LIST (users), user);
93
 
  if (!cur)
94
 
    cur = grub_zalloc (sizeof (*cur));
95
 
  if (!cur)
96
 
    return grub_errno;
97
 
 
98
 
  cur->authenticated = 1;
99
 
 
100
 
  if (! cur->name)
101
 
    {
102
 
      cur->name = grub_strdup (user);
103
 
      if (!cur->name)
104
 
        {
105
 
          grub_free (cur);
106
 
          return grub_errno;
107
 
        }
108
 
      grub_list_push (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur));
109
 
    }
110
 
 
111
 
  return GRUB_ERR_NONE;
112
 
}
113
 
 
114
 
grub_err_t
115
 
grub_auth_deauthenticate (const char *user)
116
 
{
117
 
  struct grub_auth_user *cur;
118
 
  cur = grub_named_list_find (GRUB_AS_NAMED_LIST (users), user);
119
 
  if (!cur)
120
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "user '%s' not found", user);
121
 
  if (!cur->callback)
122
 
    {
123
 
      grub_free (cur->name);
124
 
      grub_list_remove (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur));
125
 
      grub_free (cur);
126
 
    }
127
 
  else
128
 
    cur->authenticated = 0;
129
 
  return GRUB_ERR_NONE;
130
 
}
131
 
 
132
 
static int
133
 
is_authenticated (const char *userlist)
134
 
{
135
 
  const char *superusers;
136
 
  struct grub_auth_user *user;
137
 
 
138
 
  superusers = grub_env_get ("superusers");
139
 
 
140
 
  if (!superusers)
141
 
    return 1;
142
 
 
143
 
  FOR_LIST_ELEMENTS (user, users)
144
 
    {
145
 
      if (!(user->authenticated))
146
 
        continue;
147
 
 
148
 
      if ((userlist && grub_strword (userlist, user->name))
149
 
          || grub_strword (superusers, user->name))
150
 
        return 1;
151
 
    }
152
 
 
153
 
  return 0;
154
 
}
155
 
 
156
 
static int
157
 
grub_username_get (char buf[], unsigned buf_size)
158
 
{
159
 
  unsigned cur_len = 0;
160
 
  int key;
161
 
 
162
 
  while (1)
163
 
    {
164
 
      key = GRUB_TERM_ASCII_CHAR (grub_getkey ()); 
165
 
      if (key == '\n' || key == '\r')
166
 
        break;
167
 
 
168
 
      if (key == '\e')
169
 
        {
170
 
          cur_len = 0;
171
 
          break;
172
 
        }
173
 
 
174
 
      if (key == '\b')
175
 
        {
176
 
          cur_len--;
177
 
          grub_printf ("\b");
178
 
          continue;
179
 
        }
180
 
 
181
 
      if (!grub_isprint (key))
182
 
        continue;
183
 
 
184
 
      if (cur_len + 2 < buf_size)
185
 
        {
186
 
          buf[cur_len++] = key;
187
 
          grub_printf ("%c", key);
188
 
        }
189
 
    }
190
 
 
191
 
  grub_memset (buf + cur_len, 0, buf_size - cur_len);
192
 
 
193
 
  grub_xputs ("\n");
194
 
  grub_refresh ();
195
 
 
196
 
  return (key != '\e');
197
 
}
198
 
 
199
 
grub_err_t
200
 
grub_auth_check_authentication (const char *userlist)
201
 
{
202
 
  char login[1024];
203
 
  struct grub_auth_user *cur = NULL;
204
 
  grub_err_t err;
205
 
  static unsigned long punishment_delay = 1;
206
 
  char entered[GRUB_AUTH_MAX_PASSLEN];
207
 
  struct grub_auth_user *user;
208
 
 
209
 
  grub_memset (login, 0, sizeof (login));
210
 
 
211
 
  if (is_authenticated (userlist))
212
 
    {
213
 
      punishment_delay = 1;
214
 
      return GRUB_ERR_NONE;
215
 
    }
216
 
 
217
 
  grub_puts_ (N_("Enter username: "));
218
 
 
219
 
  if (!grub_username_get (login, sizeof (login) - 1))
220
 
    goto access_denied;
221
 
 
222
 
  grub_puts_ (N_("Enter password: "));
223
 
 
224
 
  if (!grub_password_get (entered, GRUB_AUTH_MAX_PASSLEN))
225
 
    goto access_denied;
226
 
 
227
 
  FOR_LIST_ELEMENTS (user, users)
228
 
    {
229
 
      if (grub_strcmp (login, user->name) == 0)
230
 
        cur = user;
231
 
    }
232
 
 
233
 
  if (!cur || ! cur->callback)
234
 
    goto access_denied;
235
 
 
236
 
  err = cur->callback (login, entered, cur->arg);
237
 
  if (is_authenticated (userlist))
238
 
    {
239
 
      punishment_delay = 1;
240
 
      return GRUB_ERR_NONE;
241
 
    }
242
 
 
243
 
 access_denied:
244
 
  grub_sleep (punishment_delay);
245
 
 
246
 
  if (punishment_delay < GRUB_ULONG_MAX / 2)
247
 
    punishment_delay *= 2;
248
 
 
249
 
  return GRUB_ACCESS_DENIED;
250
 
}