/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000, 2001, 2010 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/script_sh.h>
#include <grub/legacy_parse.h>
#include <grub/partition.h>
GRUB_MOD_LICENSE ("GPLv3+");
static grub_err_t
{
{
*line = 0;
return GRUB_ERR_NONE;
}
if (!suffix)
return grub_errno;
if (! file)
return grub_errno;
menu = grub_env_get_menu ();
if (! menu)
{
if (! menu)
return grub_errno;
}
while (1)
{
if (!buf && grub_errno)
{
return grub_errno;
}
if (!buf)
break;
{
char *newsuffix;
char *ptr;
if (newsuffix)
{
char *t;
t = suffix;
if (!suffix)
{
grub_free (t);
return grub_errno;
}
}
{
if (!args)
{
return grub_errno;
}
entrysrc, 0);
entrysrc[0] = 0;
}
}
{
grub_print_error ();
}
else if (parsed)
{
if (!entrysrc)
else
{
char *t;
t = entrysrc;
if (!entrysrc)
{
grub_free (t);
return grub_errno;
}
}
}
}
if (entryname)
{
if (!args)
{
return grub_errno;
}
}
grub_print_error ();
return GRUB_ERR_NONE;
}
static grub_err_t
{
if (argc != 1)
: (sizeof ("legacy_") - 1)] == 'c');
if (new_env)
grub_cls ();
if (extractor)
if (new_env)
{
menu = grub_env_get_menu ();
if (!extractor)
}
if (extractor)
return ret;
}
static enum
{
} kernel_type;
static grub_err_t
{
int i;
#ifdef TODO
int no_mem_option = 0;
#endif
char **cutargs;
int cutargc;
for (i = 0; i < 2; i++)
{
/* FIXME: really support this. */
{
#ifdef TODO
no_mem_option = 1;
#endif
argc--;
args++;
continue;
}
/* linux16 handles both zImages and bzImages. */
{
kernel_type = LINUX;
argc--;
args++;
continue;
}
{
argc--;
args++;
continue;
}
{
argc--;
args++;
continue;
}
{
argc--;
args++;
continue;
}
{
argc--;
args++;
continue;
}
}
if (argc < 2)
do
{
/* First try Linux. */
{
if (cmd)
{
{
kernel_type = LINUX;
return GRUB_ERR_NONE;
}
}
}
/* Then multiboot. */
{
if (cmd)
{
{
return GRUB_ERR_NONE;
}
}
}
{
{
const char *hdbiasstr;
int hdbias = 0;
if (hdbiasstr)
{
}
dev = grub_device_open (0);
{
{
}
}
}
/* k*BSD didn't really work well with grub-legacy. */
{
if (bsd_device != -1)
{
else if (bsd_slice != -1)
else
}
else
grub_env_unset ("kFreeBSD.vfs.root.mountfrom");
if (cmd)
{
{
return GRUB_ERR_NONE;
}
}
}
{
char **bsdargs;
int bsdargc;
if (bsd_device == -1)
{
}
else
{
"wd%d%c", bsd_device,
}
{
if (cmd)
{
{
return GRUB_ERR_NONE;
}
}
}
{
if (cmd)
{
{
return GRUB_ERR_NONE;
}
}
}
}
}
}
while (0);
args[0]);
}
static grub_err_t
{
if (kernel_type == LINUX)
{
if (!cmd)
}
if (kernel_type == MULTIBOOT)
{
if (!cmd)
}
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"no kernel with module support is loaded in legacy way");
}
static grub_err_t
{
if (kernel_type == LINUX)
{
if (!cmd)
}
if (kernel_type == MULTIBOOT)
{
char **newargs;
if (!newargs)
return grub_errno;
newargs[0] = "--nounzip";
if (!cmd)
return err;
}
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"no kernel with module support is loaded in legacy way");
}
static grub_err_t
{
return GRUB_ACCESS_DENIED;
}
struct legacy_md5_password
{
int saltlen;
};
static int
struct legacy_md5_password *pw)
{
unsigned char *digest;
int i;
for (i = enteredlen; i > 0; i >>= 1)
for (i = 0; i < 1000; i++)
{
if ((i & 1) != 0)
else
if (i % 3 != 0)
if (i % 7 != 0)
if ((i & 1) != 0)
else
}
}
static grub_err_t
const char *entered,
void *password)
{
return GRUB_ACCESS_DENIED;
return GRUB_ERR_NONE;
}
static inline int
ib64t (char c)
{
if (c == '.')
return 0;
if (c == '/')
return 1;
if (c >= '0' && c <= '9')
return c - '0' + 2;
if (c >= 'A' && c <= 'Z')
return c - 'A' + 12;
if (c >= 'a' && c <= 'z')
return c - 'a' + 38;
return -1;
}
static struct legacy_md5_password *
{
int i;
const char *p;
goto fail;
if (argc == 1)
goto fail;
goto fail;
if (!saltend)
goto fail;
if (!pw)
goto fail;
p = saltend + 1;
for (i = 0; i < 5; i++)
{
int n;
grub_uint32_t w = 0;
for (n = 0; n < 4; n++)
{
if (ww == -1)
goto fail;
w |= ww << (n * 6);
}
}
{
int n;
grub_uint32_t w = 0;
for (n = 0; n < 2; n++)
{
if (ww == -1)
goto fail;
w |= ww << (6 * n);
}
if (w >= 0x100)
goto fail;
}
goto fail;
return pw;
fail:
return NULL;
}
static grub_err_t
{
if (argc == 0)
if (pw)
else
/* This is to imitate minor difference between grub-legacy in GRUB2.
If 2 password commands are executed in a row and second one fails
on GRUB2 the password of first one is used, whereas in grub-legacy
authenthication is denied. In case of no password command was executed
early both versions deny any access. */
NULL);
}
static grub_err_t
{
if (argc == 0)
return GRUB_ACCESS_DENIED;
{
return GRUB_ACCESS_DENIED;
return GRUB_ERR_NONE;
}
if (!pw)
return GRUB_ACCESS_DENIED;
return GRUB_ACCESS_DENIED;
return GRUB_ERR_NONE;
}
{
= grub_register_command ("legacy_source",
N_("FILE"),
N_("Parse legacy config in same context"));
= grub_register_command ("legacy_configfile",
N_("FILE"),
N_("Parse legacy config in new context"));
= grub_register_command ("extract_legacy_entries_source",
N_("FILE"),
N_("Parse legacy config in same context taking only menu entries"));
= grub_register_command ("extract_legacy_entries_configfile",
N_("FILE"),
N_("Parse legacy config in new context taking only menu entries"));
N_("[--no-mem-option] [--type=TYPE] FILE [ARG ...]"),
N_("Simulate grub-legacy kernel command"));
N_("FILE [ARG ...]"),
N_("Simulate grub-legacy initrd command"));
N_("FILE [ARG ...]"),
N_("Simulate grub-legacy modulenounzip command"));
N_("[--md5] PASSWD [FILE]"),
N_("Simulate grub-legacy password command"));
N_("[--md5] PASSWD [FILE]"),
N_("Simulate grub-legacy password command in menuentry mode"));
}
{
}