Exemplo n.º 1
0
static grub_menu_t
read_config_file (const char *config)
{
  grub_file_t file;

  auto grub_err_t getline (char **line, int cont);
  grub_err_t getline (char **line, int cont __attribute__ ((unused)))
    {
      while (1)
	{
	  char *buf;

	  *line = buf = grub_file_getline (file);
	  if (! buf)
	    return grub_errno;

	  if (buf[0] == '#')
	    grub_free (*line);
	  else
	    break;
	}

      return GRUB_ERR_NONE;
    }

  grub_menu_t newmenu;

  newmenu = grub_env_get_menu ();
  if (! newmenu)
    {
      newmenu = grub_zalloc (sizeof (*newmenu));
      if (! newmenu)
	return 0;

      grub_env_set_menu (newmenu);
    }

  /* Try to open the config file.  */
  file = grub_file_open (config);
  if (! file)
    return 0;

  while (1)
    {
      char *line;

      /* Print an error, if any.  */
      grub_print_error ();
      grub_errno = GRUB_ERR_NONE;

      if ((getline (&line, 0)) || (! line))
	break;

      grub_normal_parse_line (line, getline);
      grub_free (line);
    }

  grub_file_close (file);

  return newmenu;
}
Exemplo n.º 2
0
/* Read the file crypto.lst for auto-loading.  */
void
read_crypto_list (const char *prefix)
{
  char *filename;
  grub_file_t file;
  char *buf = NULL;

  if (!prefix)
    {
      grub_errno = GRUB_ERR_NONE;
      return;
    }
  
  filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM
			     "/crypto.lst", prefix);
  if (!filename)
    {
      grub_errno = GRUB_ERR_NONE;
      return;
    }

  file = grub_file_open (filename);
  grub_free (filename);
  if (!file)
    {
      grub_errno = GRUB_ERR_NONE;
      return;
    }

  /* Override previous crypto.lst.  */
  grub_crypto_spec_free ();

  for (;; grub_free (buf))
    {
      char *p, *name;
      struct load_spec *cur;
      
      buf = grub_file_getline (file);
	
      if (! buf)
	break;
      
      name = buf;
      while (grub_isspace (name[0]))
	name++;

      p = grub_strchr (name, ':');
      if (! p)
	continue;
      
      *p = '\0';
      p++;
      while (*p == ' ' || *p == '\t')
	p++;

      cur = grub_malloc (sizeof (*cur));
      if (!cur)
	{
	  grub_errno = GRUB_ERR_NONE;
	  continue;
	}
      
      cur->name = grub_strdup (name);
      if (! name)
	{
	  grub_errno = GRUB_ERR_NONE;
	  grub_free (cur);
	  continue;
	}
	
      cur->modname = grub_strdup (p);
      if (! cur->modname)
	{
	  grub_errno = GRUB_ERR_NONE;
	  grub_free (cur);
	  grub_free (cur->name);
	  continue;
	}
      cur->next = crypto_specs;
      crypto_specs = cur;
    }
  
  grub_file_close (file);

  grub_errno = GRUB_ERR_NONE;

  grub_crypto_autoload_hook = grub_crypto_autoload;
}
Exemplo n.º 3
0
/* Read the file command.lst for auto-loading.  */
void
read_command_list (const char *prefix)
{
  if (prefix)
    {
      char *filename;

      filename = grub_xasprintf ("%s/command.lst", prefix);
      if (filename)
	{
	  grub_file_t file;

	  file = grub_file_open (filename);
	  if (file)
	    {
	      char *buf = NULL;
	      grub_command_t ptr, last = 0, next;

	      /* Override previous commands.lst.  */
	      for (ptr = grub_command_list; ptr; ptr = next)
		{
		  next = ptr->next;
		  if (ptr->func == grub_dyncmd_dispatcher)
		    {
		      if (last)
			last->next = ptr->next;
		      else
			grub_command_list = ptr->next;
		      grub_free (ptr);
		    }
		  else
		    last = ptr;
		}

	      for (;; grub_free (buf))
		{
		  char *p, *name, *modname;
		  grub_command_t cmd;
		  int prio = 0;

		  buf = grub_file_getline (file);

		  if (! buf)
		    break;

		  name = buf;
		  if (*name == '*')
		    {
		      name++;
		      prio++;
		    }

		  if (! grub_isgraph (name[0]))
		    continue;

		  p = grub_strchr (name, ':');
		  if (! p)
		    continue;

		  *p = '\0';
		  while (*++p == ' ')
		    ;

		  if (! grub_isgraph (*p))
		    continue;

		  if (grub_dl_get (p))
		    continue;

		  name = grub_strdup (name);
		  if (! name)
		    continue;

		  modname = grub_strdup (p);
		  if (! modname)
		    {
		      grub_free (name);
		      continue;
		    }

		  cmd = grub_register_command_prio (name,
						    grub_dyncmd_dispatcher,
						    0, N_("not loaded"), prio);
		  if (! cmd)
		    {
		      grub_free (name);
		      grub_free (modname);
		      continue;
		    }
		  cmd->flags |= GRUB_COMMAND_FLAG_DYNCMD;
		  cmd->data = modname;

		  /* Update the active flag.  */
		  grub_command_find (name);
		}

	      grub_file_close (file);
	    }

	  grub_free (filename);
	}
    }

  /* Ignore errors.  */
  grub_errno = GRUB_ERR_NONE;
}
Exemplo n.º 4
0
/* Read the file fs.lst for auto-loading.  */
void
read_fs_list (const char *prefix)
{
  if (prefix)
    {
      char *filename;

      filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM
				 "/fs.lst", prefix);
      if (filename)
	{
	  grub_file_t file;
	  grub_fs_autoload_hook_t tmp_autoload_hook;

	  /* This rules out the possibility that read_fs_list() is invoked
	     recursively when we call grub_file_open() below.  */
	  tmp_autoload_hook = grub_fs_autoload_hook;
	  grub_fs_autoload_hook = NULL;

	  file = grub_file_open (filename);
	  if (file)
	    {
	      /* Override previous fs.lst.  */
	      while (fs_module_list)
		{
		  grub_named_list_t tmp;
		  tmp = fs_module_list->next;
		  grub_free (fs_module_list);
		  fs_module_list = tmp;
		}

	      while (1)
		{
		  char *buf;
		  char *p;
		  char *q;
		  grub_named_list_t fs_mod;

		  buf = grub_file_getline (file);
		  if (! buf)
		    break;

		  p = buf;
		  q = buf + grub_strlen (buf) - 1;

		  /* Ignore space.  */
		  while (grub_isspace (*p))
		    p++;

		  while (p < q && grub_isspace (*q))
		    *q-- = '\0';

		  /* If the line is empty, skip it.  */
		  if (p >= q)
		    {
		      grub_free (buf);
		      continue;
		    }

		  fs_mod = grub_malloc (sizeof (*fs_mod));
		  if (! fs_mod)
		    {
		      grub_free (buf);
		      continue;
		    }

		  fs_mod->name = grub_strdup (p);
		  grub_free (buf);
		  if (! fs_mod->name)
		    {
		      grub_free (fs_mod);
		      continue;
		    }

		  fs_mod->next = fs_module_list;
		  fs_module_list = fs_mod;
		}

	      grub_file_close (file);
	      grub_fs_autoload_hook = tmp_autoload_hook;
	    }

	  grub_free (filename);
	}
    }

  /* Ignore errors.  */
  grub_errno = GRUB_ERR_NONE;

  /* Set the hook.  */
  grub_fs_autoload_hook = autoload_fs_module;
}
Exemplo n.º 5
0
/* Read the file crypto.lst for auto-loading.  */
void
read_crypto_list (void)
{
    const char *prefix;
    char *filename;
    grub_file_t file;
    char *buf = NULL;

    prefix = grub_env_get ("prefix");
    if (!prefix)
    {
        grub_errno = GRUB_ERR_NONE;
        return;
    }

    filename = grub_xasprintf ("%s/crypto.lst", prefix);
    if (!filename)
    {
        grub_errno = GRUB_ERR_NONE;
        return;
    }

    file = grub_file_open (filename);
    grub_free (filename);
    if (!file)
    {
        grub_errno = GRUB_ERR_NONE;
        return;
    }

    /* Override previous crypto.lst.  */
    grub_crypto_spec_free ();

    for (;; grub_free (buf))
    {
        char *p, *name;
        struct load_spec *cur;

        buf = grub_file_getline (file);

        if (! buf)
            break;

        name = buf;

        p = grub_strchr (name, ':');
        if (! p)
            continue;

        *p = '\0';
        while (*++p == ' ')
            ;

        cur = grub_malloc (sizeof (*cur));
        if (!cur)
        {
            grub_errno = GRUB_ERR_NONE;
            continue;
        }

        cur->name = grub_strdup (name);
        if (! name)
        {
            grub_errno = GRUB_ERR_NONE;
            grub_free (cur);
            continue;
        }

        cur->modname = grub_strdup (p);
        if (! cur->modname)
        {
            grub_errno = GRUB_ERR_NONE;
            grub_free (cur);
            grub_free (cur->name);
            continue;
        }
        cur->next = crypto_specs;
        crypto_specs = cur;
    }

    grub_file_close (file);

    grub_errno = GRUB_ERR_NONE;

    grub_crypto_autoload_hook = grub_crypto_autoload;
}