]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/grub-core/commands/loadenv.h
change password input field to type=password (#2427)
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / grub-core / commands / loadenv.h
1 /* loadenv.c - command to load/save environment variable. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 static grub_envblk_t UNUSED
21 read_envblk_file (grub_file_t file)
22 {
23 grub_off_t offset = 0;
24 char *buf;
25 grub_size_t size = grub_file_size (file);
26 grub_envblk_t envblk;
27
28 buf = grub_malloc (size);
29 if (! buf)
30 return 0;
31
32 while (size > 0)
33 {
34 grub_ssize_t ret;
35
36 ret = grub_file_read (file, buf + offset, size);
37 if (ret <= 0)
38 {
39 grub_free (buf);
40 return 0;
41 }
42
43 size -= ret;
44 offset += ret;
45 }
46
47 envblk = grub_envblk_open (buf, offset);
48 if (! envblk)
49 {
50 grub_free (buf);
51 grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
52 return 0;
53 }
54
55 return envblk;
56 }
57
58 struct grub_env_whitelist
59 {
60 grub_size_t len;
61 char **list;
62 };
63 typedef struct grub_env_whitelist grub_env_whitelist_t;
64
65 static int UNUSED
66 test_whitelist_membership (const char* name,
67 const grub_env_whitelist_t* whitelist)
68 {
69 grub_size_t i;
70
71 for (i = 0; i < whitelist->len; i++)
72 if (grub_strcmp (name, whitelist->list[i]) == 0)
73 return 1; /* found it */
74
75 return 0; /* not found */
76 }
77
78 /* Helper for grub_cmd_load_env. */
79 static int UNUSED
80 set_var (const char *name, const char *value, void *whitelist)
81 {
82 if (! whitelist)
83 {
84 grub_env_set (name, value);
85 return 0;
86 }
87
88 if (test_whitelist_membership (name,
89 (const grub_env_whitelist_t *) whitelist))
90 grub_env_set (name, value);
91
92 return 0;
93 }