GRUB-1.98 changes
[grub2/jjazz.git] / normal / crypto.c
blobf051e2c4c6e0fe1345c409a69698674dc9df1106
1 /* crypto.c - support crypto autoload */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/dl.h>
21 #include <grub/mm.h>
22 #include <grub/env.h>
23 #include <grub/misc.h>
24 #include <grub/crypto.h>
25 #include <grub/normal.h>
27 struct load_spec
29 struct load_spec *next;
30 char *name;
31 char *modname;
34 struct load_spec *crypto_specs = NULL;
36 static void
37 grub_crypto_autoload (const char *name)
39 struct load_spec *cur;
40 grub_dl_t mod;
42 for (cur = crypto_specs; cur; cur = cur->next)
43 if (grub_strcasecmp (name, cur->name) == 0)
45 mod = grub_dl_load (cur->modname);
46 if (mod)
47 grub_dl_ref (mod);
48 grub_errno = GRUB_ERR_NONE;
52 static void
53 grub_crypto_spec_free (void)
55 struct load_spec *cur, *next;
56 for (cur = crypto_specs; cur; cur = next)
58 next = cur->next;
59 grub_free (cur->name);
60 grub_free (cur->modname);
61 grub_free (cur);
63 crypto_specs = NULL;
67 /* Read the file crypto.lst for auto-loading. */
68 void
69 read_crypto_list (void)
71 const char *prefix;
72 char *filename;
73 grub_file_t file;
74 char *buf = NULL;
76 prefix = grub_env_get ("prefix");
77 if (!prefix)
79 grub_errno = GRUB_ERR_NONE;
80 return;
83 filename = grub_xasprintf ("%s/crypto.lst", prefix);
84 if (!filename)
86 grub_errno = GRUB_ERR_NONE;
87 return;
90 file = grub_file_open (filename);
91 grub_free (filename);
92 if (!file)
94 grub_errno = GRUB_ERR_NONE;
95 return;
98 /* Override previous crypto.lst. */
99 grub_crypto_spec_free ();
101 for (;; grub_free (buf))
103 char *p, *name;
104 struct load_spec *cur;
106 buf = grub_file_getline (file);
108 if (! buf)
109 break;
111 name = buf;
113 p = grub_strchr (name, ':');
114 if (! p)
115 continue;
117 *p = '\0';
118 while (*++p == ' ')
121 cur = grub_malloc (sizeof (*cur));
122 if (!cur)
124 grub_errno = GRUB_ERR_NONE;
125 continue;
128 cur->name = grub_strdup (name);
129 if (! name)
131 grub_errno = GRUB_ERR_NONE;
132 grub_free (cur);
133 continue;
136 cur->modname = grub_strdup (p);
137 if (! cur->modname)
139 grub_errno = GRUB_ERR_NONE;
140 grub_free (cur);
141 grub_free (cur->name);
142 continue;
144 cur->next = crypto_specs;
145 crypto_specs = cur;
148 grub_file_close (file);
150 grub_errno = GRUB_ERR_NONE;
152 grub_crypto_autoload_hook = grub_crypto_autoload;