From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LkTjL-0004li-OW for mharc-grub-devel@gnu.org; Thu, 19 Mar 2009 21:41:03 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LkTjK-0004lE-Fw for grub-devel@gnu.org; Thu, 19 Mar 2009 21:41:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LkTjJ-0004kt-OJ for grub-devel@gnu.org; Thu, 19 Mar 2009 21:41:02 -0400 Received: from [199.232.76.173] (port=42254 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkTjJ-0004kn-I6 for grub-devel@gnu.org; Thu, 19 Mar 2009 21:41:01 -0400 Received: from qw-out-1920.google.com ([74.125.92.148]:18716) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LkTjJ-0004I7-7S for grub-devel@gnu.org; Thu, 19 Mar 2009 21:41:01 -0400 Received: by qw-out-1920.google.com with SMTP id 5so467168qwf.24 for ; Thu, 19 Mar 2009 18:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=t0/iK9NjhlRyNrHNFan+XzdHazFcMqyOn+tr6I2RmAk=; b=kdY7KKNXeMjQntXL8KqcQvlZ1soJbSzgQ6olKYwy7NkQaIbpzjlM/82GlsMVwgee1h g0y4uxuAZ5wgwbpmo7/aEhMTACSTbBf4sq+3/FJRet2Fxvfe6m2CnnXyCXae8WNfK1xa yDaPTrKuttqyxr8DKVyCatSMbJgRN4gCte4M4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=PgwowcLOOXc90cUISWp8PoT3lZA/gH0fcEyCDkGclpsNCQJS9w8o5Xc6MI2HH54TAr o/CTGVoGjU331R4NwY/XPXQA7Yvb8sCg1CE0fNry9z732gx7pn+l1qBQl+MHTMBkyXy2 Aje1CBNHuvjHF4I0kQar3PPmSnUh0WX/et53c= Received: by 10.224.67.212 with SMTP id s20mr4868172qai.295.1237513259742; Thu, 19 Mar 2009 18:40:59 -0700 (PDT) Received: from system4.localdomain (76-231-81-179.lightspeed.livnmi.sbcglobal.net [76.231.81.179]) by mx.google.com with ESMTPS id 6sm1472128qwk.27.2009.03.19.18.40.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 19 Mar 2009 18:40:59 -0700 (PDT) Message-ID: <49C2F42A.8090804@gmail.com> Date: Thu, 19 Mar 2009 21:40:58 -0400 From: "Rev. Mr. Gary Meerschaert" User-Agent: Thunderbird 2.0.0.21 (X11/20090302) MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: how to open files with grub_file_open X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2009 01:41:02 -0000 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