On Friday 25 Mar 2011 21:19:40 Michael Brown wrote:
> > Alternately, we may be able to solve *most* of this problem if we could
> > use iPXE variables (i.e. ${hostname}, ${mac}) inside of vesamenu.c32, so
> > that pointing at things like our FOG server (which generates MAC-specific
> > pxelinux.cfg files to perform 'tasks') could be done in a dynamic
> > fashion.
> >
> > If there's a way to do either of these, please let me know.
> 
> There isn't yet, but it sounds useful.  We currently perform settings
> expansion when parsing the DHCP-provided filename and root-path.  We could
> pretty easily also expand filenames received via the PXE FILE API.  Could
>  you try the attached (untested) patch, and see if it does what you need?

I should read my own code before sending it.  There was a missing call to 
free().  Modified patch attached.

Michael
diff --git a/src/arch/i386/interface/pxe/pxe_file.c b/src/arch/i386/interface/pxe/pxe_file.c
index 2676256..713dbbf 100644
--- a/src/arch/i386/interface/pxe/pxe_file.c
+++ b/src/arch/i386/interface/pxe/pxe_file.c
@@ -50,25 +50,31 @@ FEATURE ( FEATURE_MISC, "PXEXT", DHCP_EB_FEATURE_PXE_EXT, 2 );
  *
  */
 PXENV_EXIT_t pxenv_file_open ( struct s_PXENV_FILE_OPEN *file_open ) {
-	userptr_t filename;
-	size_t filename_len;
+	userptr_t raw_filename;
+	size_t raw_filename_len;
+	char *filename;
 	int fd;
 
 	DBG ( "PXENV_FILE_OPEN" );
 
 	/* Copy name from external program, and open it */
-	filename = real_to_user ( file_open->FileName.segment,
-			      file_open->FileName.offset );
-	filename_len = strlen_user ( filename, 0 );
+	raw_filename = real_to_user ( file_open->FileName.segment,
+				      file_open->FileName.offset );
+	raw_filename_len = strlen_user ( raw_filename, 0 );
 	{
-		char uri_string[ filename_len + 1 ];
+		char buf[ raw_filename_len + 1 /* NUL */ ];
 
-		copy_from_user ( uri_string, filename, 0,
-				 sizeof ( uri_string ) );
-		DBG ( " %s", uri_string );
-		fd = open ( uri_string );
+		copy_from_user ( buf, raw_filename, 0, sizeof ( buf ) );
+		DBG ( " %s", buf );
+
+		filename = expand_settings ( buf );
+		if ( ! filename ) {
+			file_open->Status = PXENV_STATUS_OUT_OF_RESOURCES;
+			return PXENV_EXIT_FAILURE;
+		}
 	}
 
+	fd = open ( filename );
 	if ( fd < 0 ) {
 		file_open->Status = PXENV_STATUS ( fd );
 		return PXENV_EXIT_FAILURE;
_______________________________________________
ipxe-devel mailing list
[email protected]
https://lists.ipxe.org/mailman/listinfo/ipxe-devel

Reply via email to