1 /* loadenv.c - command to load/save environment variable. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008,2009,2010 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 static grub_envblk_t UNUSED
21 read_envblk_file (grub_file_t file
)
23 grub_off_t offset
= 0;
25 grub_size_t size
= grub_file_size (file
);
28 buf
= grub_malloc (size
);
36 ret
= grub_file_read (file
, buf
+ offset
, size
);
47 envblk
= grub_envblk_open (buf
, offset
);
51 grub_error (GRUB_ERR_BAD_FILE_TYPE
, "invalid environment block");
58 struct grub_env_whitelist
63 typedef struct grub_env_whitelist grub_env_whitelist_t
;
66 test_whitelist_membership (const char* name
,
67 const grub_env_whitelist_t
* whitelist
)
71 for (i
= 0; i
< whitelist
->len
; i
++)
72 if (grub_strcmp (name
, whitelist
->list
[i
]) == 0)
73 return 1; /* found it */
75 return 0; /* not found */
78 /* Helper for grub_cmd_load_env. */
80 set_var (const char *name
, const char *value
, void *whitelist
)
84 grub_env_set (name
, value
);
88 if (test_whitelist_membership (name
,
89 (const grub_env_whitelist_t
*) whitelist
))
90 grub_env_set (name
, value
);