Browse Source

[autoboot] Allow setting expansions in filename and root-path

Allow the DHCP filename and root-path to contain settings expansions,
such as

  http://boot.ipxe.org/demo/boot.php?mac=${mac:hexhyp}

Originally-implemented-by: Jarrod Johnson <jarrod.b.johnson@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
3ed849bbf2
1 changed files with 32 additions and 10 deletions
  1. 32
    10
      src/usr/autoboot.c

+ 32
- 10
src/usr/autoboot.c View File

@@ -230,7 +230,9 @@ static void close_all_netdevs ( void ) {
230 230
  */
231 231
 struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
232 232
 	struct in_addr next_server;
233
-	char filename[256];
233
+	char buf[256];
234
+	char *filename;
235
+	struct uri *uri;
234 236
 
235 237
 	/* Fetch next-server setting */
236 238
 	fetch_ipv4_setting ( settings, &next_server_setting, &next_server );
@@ -239,11 +241,20 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
239 241
 
240 242
 	/* Fetch filename setting */
241 243
 	fetch_string_setting ( settings, &filename_setting,
242
-			       filename, sizeof ( filename ) );
243
-	if ( filename[0] )
244
-		printf ( "Filename: %s\n", filename );
244
+			       buf, sizeof ( buf ) );
245
+	if ( buf[0] )
246
+		printf ( "Filename: %s\n", buf );
247
+
248
+	/* Expand filename setting */
249
+	filename = expand_settings ( buf );
250
+	if ( ! filename )
251
+		return NULL;
245 252
 
246
-	return parse_next_server_and_filename ( next_server, filename );
253
+	/* Parse next server and filename */
254
+	uri = parse_next_server_and_filename ( next_server, filename );
255
+
256
+	free ( filename );
257
+	return uri;
247 258
 }
248 259
 
249 260
 /**
@@ -253,15 +264,26 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
253 264
  * @ret uri		URI, or NULL on failure
254 265
  */
255 266
 static struct uri * fetch_root_path ( struct settings *settings ) {
256
-	char root_path[256];
267
+	char buf[256];
268
+	char *root_path;
269
+	struct uri *uri;
257 270
 
258 271
 	/* Fetch root-path setting */
259 272
 	fetch_string_setting ( settings, &root_path_setting,
260
-			       root_path, sizeof ( root_path ) );
261
-	if ( root_path[0] )
262
-		printf ( "Root path: %s\n", root_path );
273
+			       buf, sizeof ( buf ) );
274
+	if ( buf[0] )
275
+		printf ( "Root path: %s\n", buf );
276
+
277
+	/* Expand filename setting */
278
+	root_path = expand_settings ( buf );
279
+	if ( ! root_path )
280
+		return NULL;
263 281
 
264
-	return parse_uri ( root_path );
282
+	/* Parse root path */
283
+	uri = parse_uri ( root_path );
284
+
285
+	free ( root_path );
286
+	return uri;
265 287
 }
266 288
 
267 289
 /**

Loading…
Cancel
Save