From: "Rev. Mr. Gary Meerschaert" <gary.meerschaert@gmail.com>
To: grub-devel@gnu.org
Subject: how to open files with grub_file_open
Date: Thu, 19 Mar 2009 21:40:58 -0400 [thread overview]
Message-ID: <49C2F42A.8090804@gmail.com> (raw)
need to modify grub for a project in my security class. I am adding a a
check of a key stored on a usb drive. I also have the key stored in the
/boot/grub2, /boot/grub, and /boot. I can not open any of them. My
system dual-boots, and the fedora install is in hd0,1.
My code is shown (extra tracing statements included)
static void
grub_key_check (void)
{
grub_file_t key_disk_file;
grub_file_t key_usb_file;
char usb_key[512];
char disk_key[512];
char key_match;
int i;
const char *prefix;
prefix = grub_env_get ("prefix");
grub_printf("In key check\n");
key_match = 'f';
/* look for a key file on the disk */
grub_printf("before disk file open\n");
key_disk_file = grub_file_open("(hd0)grub/key");
grub_printf("after disk file open\n");
if ( ! key_disk_file )
{
grub_printf("No disk key file\n");
grub_printf("before return\n");
return;
}
grub_printf("After disk file open\n");
/* read in the key from the key file. Must be 512 char*/
if ( grub_file_read(key_disk_file, disk_key,512) != 512)
{
grub_printf("Disk key file wrong size\n");
sleep(30);
return;
}
grub_printf("After disk file read\n");
/* read the key file from the usb drive & compare */
while (key_match == 'f')
{
grub_printf("top of key match loop\n");
while ( (key_usb_file = grub_file_open("(hd0)key")) == (grub_file_t)0)
{
grub_printf("usb file open failed\n");
grub_printf("Insert key\n");
sleep(30);
}
grub_printf("usb file open worked\n");
if (grub_file_read (key_usb_file, usb_key, 512) != 512)
{
grub_printf("usb file read failed\n");
grub_file_close(key_usb_file);
grub_printf("Insert key\n");
sleep(30);
continue;
}
grub_printf("usb file read worked\n");
grub_printf("before key check\n");
grub_printf("usb file read worked\n");
grub_printf("before key check\n");
for (i=0; i<512; i++)
{
if (disk_key[i] != usb_key[i])
{
grub_printf("Key match failed at %d\n",i);
break;
}
}
grub_printf("Key check passed\n");
if (i == 512) key_match = 't';
}
grub_printf("Bottom of key_check\n");
}
/* The main routine. */
void
grub_main (void)
{
/* First of all, initialize the machine. */
grub_machine_init ();
/* First of all, initialize the machine. */
grub_machine_init ();
grub_printf("hello - before key_check\n");
/* check for USB drive key */
grub_key_check();
grub_printf("After key check\n");
/* Hello. */
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
grub_printf ("Welcome to GRUB!\n\n");
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
There are some trace satements in the file.c routine also (not shown).
The output I get is:
./grub-emu -r /boot
hello - before key_check
In key check
before disk file open
in grub_file_open, file = (hd0)grub/key
In grub_file_get_device_name, file = (hd0)grub/key
Malloc return = 0
Device name = hd0
device name = hd0
file name now = grub/key
After device_open
after disk file open
No disk key file
before return
After key check
Welcome to GRUB!
Segmentation fault
I have tried the file name as (hd0)/boot/key, (hd0)/boot/grub/key with
the same results.
Can anyone tell me what I am doing wrong?
Thanks,
Gary
next reply other threads:[~2009-03-20 1:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-20 1:40 Rev. Mr. Gary Meerschaert [this message]
2009-03-20 1:57 ` how to open files with grub_file_open Isaac Dupree
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49C2F42A.8090804@gmail.com \
--to=gary.meerschaert@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.