]> git.proxmox.com Git - grub2.git/blob - grub-core/commands/legacycfg.c
tsc: Use alternative delay sources whenever appropriate.
[grub2.git] / grub-core / commands / legacycfg.c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2000, 2001, 2010 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/types.h>
20 #include <grub/misc.h>
21 #include <grub/command.h>
22 #include <grub/mm.h>
23 #include <grub/err.h>
24 #include <grub/dl.h>
25 #include <grub/file.h>
26 #include <grub/normal.h>
27 #include <grub/script_sh.h>
28 #include <grub/i18n.h>
29 #include <grub/term.h>
30 #include <grub/legacy_parse.h>
31 #include <grub/crypto.h>
32 #include <grub/auth.h>
33 #include <grub/disk.h>
34 #include <grub/partition.h>
35
36 GRUB_MOD_LICENSE ("GPLv3+");
37
38 /* Helper for legacy_file. */
39 static grub_err_t
40 legacy_file_getline (char **line, int cont __attribute__ ((unused)),
41 void *data __attribute__ ((unused)))
42 {
43 *line = 0;
44 return GRUB_ERR_NONE;
45 }
46
47 static grub_err_t
48 legacy_file (const char *filename)
49 {
50 grub_file_t file;
51 char *entryname = NULL, *entrysrc = NULL;
52 grub_menu_t menu;
53 char *suffix = grub_strdup ("");
54
55 if (!suffix)
56 return grub_errno;
57
58 file = grub_file_open (filename);
59 if (! file)
60 {
61 grub_free (suffix);
62 return grub_errno;
63 }
64
65 menu = grub_env_get_menu ();
66 if (! menu)
67 {
68 menu = grub_zalloc (sizeof (*menu));
69 if (! menu)
70 {
71 grub_free (suffix);
72 return grub_errno;
73 }
74
75 grub_env_set_menu (menu);
76 }
77
78 while (1)
79 {
80 char *buf = grub_file_getline (file);
81 char *parsed = NULL;
82
83 if (!buf && grub_errno)
84 {
85 grub_file_close (file);
86 grub_free (suffix);
87 return grub_errno;
88 }
89
90 if (!buf)
91 break;
92
93 {
94 char *oldname = NULL;
95 char *newsuffix;
96 char *ptr;
97
98 for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++);
99
100 oldname = entryname;
101 parsed = grub_legacy_parse (ptr, &entryname, &newsuffix);
102 grub_free (buf);
103 buf = NULL;
104 if (newsuffix)
105 {
106 char *t;
107
108 t = suffix;
109 suffix = grub_realloc (suffix, grub_strlen (suffix)
110 + grub_strlen (newsuffix) + 1);
111 if (!suffix)
112 {
113 grub_free (t);
114 grub_free (entrysrc);
115 grub_free (parsed);
116 grub_free (newsuffix);
117 grub_free (suffix);
118 return grub_errno;
119 }
120 grub_memcpy (suffix + grub_strlen (suffix), newsuffix,
121 grub_strlen (newsuffix) + 1);
122 grub_free (newsuffix);
123 newsuffix = NULL;
124 }
125 if (oldname != entryname && oldname)
126 {
127 const char **args = grub_malloc (sizeof (args[0]));
128 if (!args)
129 {
130 grub_file_close (file);
131 return grub_errno;
132 }
133 args[0] = oldname;
134 grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy",
135 NULL, NULL,
136 entrysrc, 0);
137 grub_free (args);
138 entrysrc[0] = 0;
139 grub_free (oldname);
140 }
141 }
142
143 if (parsed && !entryname)
144 {
145 grub_normal_parse_line (parsed, legacy_file_getline, NULL);
146 grub_print_error ();
147 grub_free (parsed);
148 parsed = NULL;
149 }
150 else if (parsed)
151 {
152 if (!entrysrc)
153 entrysrc = parsed;
154 else
155 {
156 char *t;
157
158 t = entrysrc;
159 entrysrc = grub_realloc (entrysrc, grub_strlen (entrysrc)
160 + grub_strlen (parsed) + 1);
161 if (!entrysrc)
162 {
163 grub_free (t);
164 grub_free (parsed);
165 grub_free (suffix);
166 return grub_errno;
167 }
168 grub_memcpy (entrysrc + grub_strlen (entrysrc), parsed,
169 grub_strlen (parsed) + 1);
170 grub_free (parsed);
171 parsed = NULL;
172 }
173 }
174 }
175 grub_file_close (file);
176
177 if (entryname)
178 {
179 const char **args = grub_malloc (sizeof (args[0]));
180 if (!args)
181 {
182 grub_file_close (file);
183 grub_free (suffix);
184 grub_free (entrysrc);
185 return grub_errno;
186 }
187 args[0] = entryname;
188 grub_normal_add_menu_entry (1, args, NULL, NULL, NULL,
189 NULL, NULL, entrysrc, 0);
190 grub_free (args);
191 }
192
193 grub_normal_parse_line (suffix, legacy_file_getline, NULL);
194 grub_print_error ();
195 grub_free (suffix);
196 grub_free (entrysrc);
197
198 return GRUB_ERR_NONE;
199 }
200
201 static grub_err_t
202 grub_cmd_legacy_source (struct grub_command *cmd,
203 int argc, char **args)
204 {
205 int new_env, extractor;
206 grub_err_t ret;
207
208 if (argc != 1)
209 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
210
211 extractor = (cmd->name[0] == 'e');
212 new_env = (cmd->name[extractor ? (sizeof ("extract_legacy_entries_") - 1)
213 : (sizeof ("legacy_") - 1)] == 'c');
214
215 if (new_env)
216 grub_cls ();
217
218 if (new_env && !extractor)
219 grub_env_context_open ();
220 if (extractor)
221 grub_env_extractor_open (!new_env);
222
223 ret = legacy_file (args[0]);
224
225 if (new_env)
226 {
227 grub_menu_t menu;
228 menu = grub_env_get_menu ();
229 if (menu && menu->size)
230 grub_show_menu (menu, 1, 0);
231 if (!extractor)
232 grub_env_context_close ();
233 }
234 if (extractor)
235 grub_env_extractor_close (!new_env);
236
237 return ret;
238 }
239
240 static enum
241 {
242 GUESS_IT, LINUX, MULTIBOOT, KFREEBSD, KNETBSD, KOPENBSD
243 } kernel_type;
244
245 static grub_err_t
246 grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
247 int argc, char **args)
248 {
249 int i;
250 #ifdef TODO
251 int no_mem_option = 0;
252 #endif
253 struct grub_command *cmd;
254 char **cutargs;
255 int cutargc;
256
257 for (i = 0; i < 2; i++)
258 {
259 /* FIXME: really support this. */
260 if (argc >= 1 && grub_strcmp (args[0], "--no-mem-option") == 0)
261 {
262 #ifdef TODO
263 no_mem_option = 1;
264 #endif
265 argc--;
266 args++;
267 continue;
268 }
269
270 /* linux16 handles both zImages and bzImages. */
271 if (argc >= 1 && (grub_strcmp (args[0], "--type=linux") == 0
272 || grub_strcmp (args[0], "--type=biglinux") == 0))
273 {
274 kernel_type = LINUX;
275 argc--;
276 args++;
277 continue;
278 }
279
280 if (argc >= 1 && grub_strcmp (args[0], "--type=multiboot") == 0)
281 {
282 kernel_type = MULTIBOOT;
283 argc--;
284 args++;
285 continue;
286 }
287
288 if (argc >= 1 && grub_strcmp (args[0], "--type=freebsd") == 0)
289 {
290 kernel_type = KFREEBSD;
291 argc--;
292 args++;
293 continue;
294 }
295
296 if (argc >= 1 && grub_strcmp (args[0], "--type=openbsd") == 0)
297 {
298 kernel_type = KOPENBSD;
299 argc--;
300 args++;
301 continue;
302 }
303
304 if (argc >= 1 && grub_strcmp (args[0], "--type=netbsd") == 0)
305 {
306 kernel_type = KNETBSD;
307 argc--;
308 args++;
309 continue;
310 }
311 }
312
313 if (argc < 2)
314 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
315
316 cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1));
317 cutargc = argc - 1;
318 grub_memcpy (cutargs + 1, args + 2, sizeof (cutargs[0]) * (argc - 2));
319 cutargs[0] = args[0];
320
321 do
322 {
323 /* First try Linux. */
324 if (kernel_type == GUESS_IT || kernel_type == LINUX)
325 {
326 #ifdef GRUB_MACHINE_PCBIOS
327 cmd = grub_command_find ("linux16");
328 #else
329 cmd = grub_command_find ("linux");
330 #endif
331 if (cmd)
332 {
333 if (!(cmd->func) (cmd, cutargc, cutargs))
334 {
335 kernel_type = LINUX;
336 return GRUB_ERR_NONE;
337 }
338 }
339 grub_errno = GRUB_ERR_NONE;
340 }
341
342 /* Then multiboot. */
343 if (kernel_type == GUESS_IT || kernel_type == MULTIBOOT)
344 {
345 cmd = grub_command_find ("multiboot");
346 if (cmd)
347 {
348 if (!(cmd->func) (cmd, argc, args))
349 {
350 kernel_type = MULTIBOOT;
351 return GRUB_ERR_NONE;
352 }
353 }
354 grub_errno = GRUB_ERR_NONE;
355 }
356
357 {
358 int bsd_device = -1;
359 int bsd_slice = -1;
360 int bsd_part = -1;
361 {
362 grub_device_t dev;
363 const char *hdbiasstr;
364 int hdbias = 0;
365 hdbiasstr = grub_env_get ("legacy_hdbias");
366 if (hdbiasstr)
367 {
368 hdbias = grub_strtoul (hdbiasstr, 0, 0);
369 grub_errno = GRUB_ERR_NONE;
370 }
371 dev = grub_device_open (0);
372 if (dev && dev->disk
373 && dev->disk->dev->id == GRUB_DISK_DEVICE_BIOSDISK_ID
374 && dev->disk->id >= 0x80 && dev->disk->id <= 0x90)
375 {
376 struct grub_partition *part = dev->disk->partition;
377 bsd_device = dev->disk->id - 0x80 - hdbias;
378 if (part && (grub_strcmp (part->partmap->name, "netbsd") == 0
379 || grub_strcmp (part->partmap->name, "openbsd") == 0
380 || grub_strcmp (part->partmap->name, "bsd") == 0))
381 {
382 bsd_part = part->number;
383 part = part->parent;
384 }
385 if (part && grub_strcmp (part->partmap->name, "msdos") == 0)
386 bsd_slice = part->number;
387 }
388 if (dev)
389 grub_device_close (dev);
390 }
391
392 /* k*BSD didn't really work well with grub-legacy. */
393 if (kernel_type == GUESS_IT || kernel_type == KFREEBSD)
394 {
395 char buf[sizeof("adXXXXXXXXXXXXsXXXXXXXXXXXXYYY")];
396 if (bsd_device != -1)
397 {
398 if (bsd_slice != -1 && bsd_part != -1)
399 grub_snprintf(buf, sizeof(buf), "ad%ds%d%c", bsd_device,
400 bsd_slice, 'a' + bsd_part);
401 else if (bsd_slice != -1)
402 grub_snprintf(buf, sizeof(buf), "ad%ds%d", bsd_device,
403 bsd_slice);
404 else
405 grub_snprintf(buf, sizeof(buf), "ad%d", bsd_device);
406 grub_env_set ("kFreeBSD.vfs.root.mountfrom", buf);
407 }
408 else
409 grub_env_unset ("kFreeBSD.vfs.root.mountfrom");
410 cmd = grub_command_find ("kfreebsd");
411 if (cmd)
412 {
413 if (!(cmd->func) (cmd, cutargc, cutargs))
414 {
415 kernel_type = KFREEBSD;
416 return GRUB_ERR_NONE;
417 }
418 }
419 grub_errno = GRUB_ERR_NONE;
420 }
421 {
422 char **bsdargs;
423 int bsdargc;
424 char bsddevname[sizeof ("wdXXXXXXXXXXXXY")];
425 if (bsd_device == -1)
426 {
427 bsdargs = cutargs;
428 bsdargc = cutargc;
429 }
430 else
431 {
432 char rbuf[3] = "-r";
433 bsdargc = cutargc + 2;
434 bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc);
435 grub_memcpy (bsdargs, args, argc * sizeof (bsdargs[0]));
436 bsdargs[argc] = rbuf;
437 bsdargs[argc + 1] = bsddevname;
438 grub_snprintf (bsddevname, sizeof (bsddevname),
439 "wd%d%c", bsd_device,
440 bsd_part != -1 ? bsd_part + 'a' : 'c');
441 }
442 if (kernel_type == GUESS_IT || kernel_type == KNETBSD)
443 {
444 cmd = grub_command_find ("knetbsd");
445 if (cmd)
446 {
447 if (!(cmd->func) (cmd, bsdargc, bsdargs))
448 {
449 kernel_type = KNETBSD;
450 return GRUB_ERR_NONE;
451 }
452 }
453 grub_errno = GRUB_ERR_NONE;
454 }
455 if (kernel_type == GUESS_IT || kernel_type == KOPENBSD)
456 {
457 cmd = grub_command_find ("kopenbsd");
458 if (cmd)
459 {
460 if (!(cmd->func) (cmd, bsdargc, bsdargs))
461 {
462 kernel_type = KOPENBSD;
463 return GRUB_ERR_NONE;
464 }
465 }
466 grub_errno = GRUB_ERR_NONE;
467 }
468 if (bsdargs != cutargs)
469 grub_free (bsdargs);
470 }
471 }
472 }
473 while (0);
474
475 return grub_error (GRUB_ERR_BAD_OS, "couldn't load file %s",
476 args[0]);
477 }
478
479 static grub_err_t
480 grub_cmd_legacy_initrd (struct grub_command *mycmd __attribute__ ((unused)),
481 int argc, char **args)
482 {
483 struct grub_command *cmd;
484
485 if (kernel_type == LINUX)
486 {
487 #ifdef GRUB_MACHINE_PCBIOS
488 cmd = grub_command_find ("initrd16");
489 #else
490 cmd = grub_command_find ("initrd");
491 #endif
492 if (!cmd)
493 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
494 #ifdef GRUB_MACHINE_PCBIOS
495 "initrd16"
496 #else
497 "initrd"
498 #endif
499 );
500
501 return cmd->func (cmd, argc, args);
502 }
503 if (kernel_type == MULTIBOOT)
504 {
505 cmd = grub_command_find ("module");
506 if (!cmd)
507 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
508 "module");
509
510 return cmd->func (cmd, argc, args);
511 }
512
513 return grub_error (GRUB_ERR_BAD_ARGUMENT,
514 N_("you need to load the kernel first"));
515 }
516
517 static grub_err_t
518 grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused)),
519 int argc, char **args)
520 {
521 struct grub_command *cmd;
522
523 if (kernel_type == LINUX)
524 {
525 cmd = grub_command_find ("initrd16");
526 if (!cmd)
527 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
528 "initrd16");
529
530 return cmd->func (cmd, argc, args);
531 }
532 if (kernel_type == MULTIBOOT)
533 {
534 char **newargs;
535 grub_err_t err;
536 char nounzipbuf[10] = "--nounzip";
537 newargs = grub_malloc ((argc + 1) * sizeof (newargs[0]));
538 if (!newargs)
539 return grub_errno;
540 grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0]));
541 newargs[0] = nounzipbuf;
542 cmd = grub_command_find ("module");
543 if (!cmd)
544 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
545 "module");
546
547 err = cmd->func (cmd, argc + 1, newargs);
548 grub_free (newargs);
549 return err;
550 }
551
552 return grub_error (GRUB_ERR_BAD_ARGUMENT,
553 N_("you need to load the kernel first"));
554 }
555
556 static grub_err_t
557 check_password_deny (const char *user __attribute__ ((unused)),
558 const char *entered __attribute__ ((unused)),
559 void *password __attribute__ ((unused)))
560 {
561 return GRUB_ACCESS_DENIED;
562 }
563
564 #define MD5_HASHLEN 16
565
566 struct legacy_md5_password
567 {
568 grub_uint8_t *salt;
569 int saltlen;
570 grub_uint8_t hash[MD5_HASHLEN];
571 };
572
573 static int
574 check_password_md5_real (const char *entered,
575 struct legacy_md5_password *pw)
576 {
577 grub_size_t enteredlen = grub_strlen (entered);
578 unsigned char alt_result[MD5_HASHLEN];
579 unsigned char *digest;
580 grub_uint8_t *ctx;
581 grub_size_t i;
582 int ret;
583
584 ctx = grub_zalloc (GRUB_MD_MD5->contextsize);
585 if (!ctx)
586 return 0;
587
588 GRUB_MD_MD5->init (ctx);
589 GRUB_MD_MD5->write (ctx, entered, enteredlen);
590 GRUB_MD_MD5->write (ctx, pw->salt + 3, pw->saltlen - 3);
591 GRUB_MD_MD5->write (ctx, entered, enteredlen);
592 digest = GRUB_MD_MD5->read (ctx);
593 GRUB_MD_MD5->final (ctx);
594 grub_memcpy (alt_result, digest, MD5_HASHLEN);
595
596 GRUB_MD_MD5->init (ctx);
597 GRUB_MD_MD5->write (ctx, entered, enteredlen);
598 GRUB_MD_MD5->write (ctx, pw->salt, pw->saltlen); /* include the $1$ header */
599 for (i = enteredlen; i > 16; i -= 16)
600 GRUB_MD_MD5->write (ctx, alt_result, 16);
601 GRUB_MD_MD5->write (ctx, alt_result, i);
602
603 for (i = enteredlen; i > 0; i >>= 1)
604 GRUB_MD_MD5->write (ctx, entered + ((i & 1) ? enteredlen : 0), 1);
605 digest = GRUB_MD_MD5->read (ctx);
606 GRUB_MD_MD5->final (ctx);
607
608 for (i = 0; i < 1000; i++)
609 {
610 grub_memcpy (alt_result, digest, 16);
611
612 GRUB_MD_MD5->init (ctx);
613 if ((i & 1) != 0)
614 GRUB_MD_MD5->write (ctx, entered, enteredlen);
615 else
616 GRUB_MD_MD5->write (ctx, alt_result, 16);
617
618 if (i % 3 != 0)
619 GRUB_MD_MD5->write (ctx, pw->salt + 3, pw->saltlen - 3);
620
621 if (i % 7 != 0)
622 GRUB_MD_MD5->write (ctx, entered, enteredlen);
623
624 if ((i & 1) != 0)
625 GRUB_MD_MD5->write (ctx, alt_result, 16);
626 else
627 GRUB_MD_MD5->write (ctx, entered, enteredlen);
628 digest = GRUB_MD_MD5->read (ctx);
629 GRUB_MD_MD5->final (ctx);
630 }
631
632 ret = (grub_crypto_memcmp (digest, pw->hash, MD5_HASHLEN) == 0);
633 grub_free (ctx);
634 return ret;
635 }
636
637 static grub_err_t
638 check_password_md5 (const char *user,
639 const char *entered,
640 void *password)
641 {
642 if (!check_password_md5_real (entered, password))
643 return GRUB_ACCESS_DENIED;
644
645 grub_auth_authenticate (user);
646
647 return GRUB_ERR_NONE;
648 }
649
650 static inline int
651 ib64t (char c)
652 {
653 if (c == '.')
654 return 0;
655 if (c == '/')
656 return 1;
657 if (c >= '0' && c <= '9')
658 return c - '0' + 2;
659 if (c >= 'A' && c <= 'Z')
660 return c - 'A' + 12;
661 if (c >= 'a' && c <= 'z')
662 return c - 'a' + 38;
663 return -1;
664 }
665
666 static struct legacy_md5_password *
667 parse_legacy_md5 (int argc, char **args)
668 {
669 const char *salt, *saltend;
670 struct legacy_md5_password *pw = NULL;
671 int i;
672 const char *p;
673
674 if (grub_memcmp (args[0], "--md5", sizeof ("--md5")) != 0)
675 goto fail;
676 if (argc == 1)
677 goto fail;
678 if (grub_strlen(args[1]) <= 3)
679 goto fail;
680 salt = args[1];
681 saltend = grub_strchr (salt + 3, '$');
682 if (!saltend)
683 goto fail;
684 pw = grub_malloc (sizeof (*pw));
685 if (!pw)
686 goto fail;
687
688 p = saltend + 1;
689 for (i = 0; i < 5; i++)
690 {
691 int n;
692 grub_uint32_t w = 0;
693
694 for (n = 0; n < 4; n++)
695 {
696 int ww = ib64t(*p++);
697 if (ww == -1)
698 goto fail;
699 w |= ww << (n * 6);
700 }
701 pw->hash[i == 4 ? 5 : 12+i] = w & 0xff;
702 pw->hash[6+i] = (w >> 8) & 0xff;
703 pw->hash[i] = (w >> 16) & 0xff;
704 }
705 {
706 int n;
707 grub_uint32_t w = 0;
708 for (n = 0; n < 2; n++)
709 {
710 int ww = ib64t(*p++);
711 if (ww == -1)
712 goto fail;
713 w |= ww << (6 * n);
714 }
715 if (w >= 0x100)
716 goto fail;
717 pw->hash[11] = w;
718 }
719
720 pw->saltlen = saltend - salt;
721 pw->salt = (grub_uint8_t *) grub_strndup (salt, pw->saltlen);
722 if (!pw->salt)
723 goto fail;
724
725 return pw;
726
727 fail:
728 grub_free (pw);
729 return NULL;
730 }
731
732 static grub_err_t
733 grub_cmd_legacy_password (struct grub_command *mycmd __attribute__ ((unused)),
734 int argc, char **args)
735 {
736 struct legacy_md5_password *pw = NULL;
737
738 if (argc == 0)
739 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
740 if (args[0][0] != '-' || args[0][1] != '-')
741 return grub_normal_set_password ("legacy", args[0]);
742
743 pw = parse_legacy_md5 (argc, args);
744
745 if (pw)
746 return grub_auth_register_authentication ("legacy", check_password_md5, pw);
747 else
748 /* This is to imitate minor difference between grub-legacy in GRUB2.
749 If 2 password commands are executed in a row and second one fails
750 on GRUB2 the password of first one is used, whereas in grub-legacy
751 authenthication is denied. In case of no password command was executed
752 early both versions deny any access. */
753 return grub_auth_register_authentication ("legacy", check_password_deny,
754 NULL);
755 }
756
757 int
758 grub_legacy_check_md5_password (int argc, char **args,
759 char *entered)
760 {
761 struct legacy_md5_password *pw = NULL;
762 int ret;
763
764 if (args[0][0] != '-' || args[0][1] != '-')
765 {
766 char correct[GRUB_AUTH_MAX_PASSLEN];
767
768 grub_memset (correct, 0, sizeof (correct));
769 grub_strncpy (correct, args[0], sizeof (correct));
770
771 return grub_crypto_memcmp (entered, correct, GRUB_AUTH_MAX_PASSLEN) == 0;
772 }
773
774 pw = parse_legacy_md5 (argc, args);
775
776 if (!pw)
777 return 0;
778
779 ret = check_password_md5_real (entered, pw);
780 grub_free (pw);
781 return ret;
782 }
783
784 static grub_err_t
785 grub_cmd_legacy_check_password (struct grub_command *mycmd __attribute__ ((unused)),
786 int argc, char **args)
787 {
788 char entered[GRUB_AUTH_MAX_PASSLEN];
789
790 if (argc == 0)
791 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
792 grub_puts_ (N_("Enter password: "));
793 if (!grub_password_get (entered, GRUB_AUTH_MAX_PASSLEN))
794 return GRUB_ACCESS_DENIED;
795
796 if (!grub_legacy_check_md5_password (argc, args,
797 entered))
798 return GRUB_ACCESS_DENIED;
799
800 return GRUB_ERR_NONE;
801 }
802
803 static grub_command_t cmd_source, cmd_configfile;
804 static grub_command_t cmd_source_extract, cmd_configfile_extract;
805 static grub_command_t cmd_kernel, cmd_initrd, cmd_initrdnounzip;
806 static grub_command_t cmd_password, cmd_check_password;
807
808 GRUB_MOD_INIT(legacycfg)
809 {
810 cmd_source
811 = grub_register_command ("legacy_source",
812 grub_cmd_legacy_source,
813 N_("FILE"),
814 /* TRANSLATORS: "legacy config" means
815 "config as used by grub-legacy". */
816 N_("Parse legacy config in same context"));
817 cmd_configfile
818 = grub_register_command ("legacy_configfile",
819 grub_cmd_legacy_source,
820 N_("FILE"),
821 N_("Parse legacy config in new context"));
822 cmd_source_extract
823 = grub_register_command ("extract_legacy_entries_source",
824 grub_cmd_legacy_source,
825 N_("FILE"),
826 N_("Parse legacy config in same context taking only menu entries"));
827 cmd_configfile_extract
828 = grub_register_command ("extract_legacy_entries_configfile",
829 grub_cmd_legacy_source,
830 N_("FILE"),
831 N_("Parse legacy config in new context taking only menu entries"));
832
833 cmd_kernel = grub_register_command ("legacy_kernel",
834 grub_cmd_legacy_kernel,
835 N_("[--no-mem-option] [--type=TYPE] FILE [ARG ...]"),
836 N_("Simulate grub-legacy `kernel' command"));
837
838 cmd_initrd = grub_register_command ("legacy_initrd",
839 grub_cmd_legacy_initrd,
840 N_("FILE [ARG ...]"),
841 N_("Simulate grub-legacy `initrd' command"));
842 cmd_initrdnounzip = grub_register_command ("legacy_initrd_nounzip",
843 grub_cmd_legacy_initrdnounzip,
844 N_("FILE [ARG ...]"),
845 N_("Simulate grub-legacy `modulenounzip' command"));
846
847 cmd_password = grub_register_command ("legacy_password",
848 grub_cmd_legacy_password,
849 N_("[--md5] PASSWD [FILE]"),
850 N_("Simulate grub-legacy `password' command"));
851
852 cmd_check_password = grub_register_command ("legacy_check_password",
853 grub_cmd_legacy_check_password,
854 N_("[--md5] PASSWD [FILE]"),
855 N_("Simulate grub-legacy `password' command in menu entry mode"));
856
857 }
858
859 GRUB_MOD_FINI(legacycfg)
860 {
861 grub_unregister_command (cmd_source);
862 grub_unregister_command (cmd_configfile);
863 grub_unregister_command (cmd_source_extract);
864 grub_unregister_command (cmd_configfile_extract);
865
866 grub_unregister_command (cmd_kernel);
867 grub_unregister_command (cmd_initrd);
868 grub_unregister_command (cmd_initrdnounzip);
869
870 grub_unregister_command (cmd_password);
871 grub_unregister_command (cmd_check_password);
872 }