[syslinux] Fwd: [PATCH] {vesa}menu.c32 feature => hide menu entry for specific sources

brlev at free.fr brlev at free.fr
Wed Jun 29 06:27:16 PDT 2016


good afternoon.

As promised to Mr Cumm few weeks before, I forward you the mail that I had wrongly sent directly to Mr Anvin.

This is something I've done for my company usage and I submit it to you. Feel free to include it if you think this can be usefull for others ..

Context:
In my company, we have several distinct PXE server (depending on the location: europe, asia, ....). each of these servers must have a some configuration adjustement ( mainly pxechain for local WDS ) 

Goal : 
Having a unique configuration file that can be synchronized (headachesfree updates ;) )

I've added an option "MENU HIDEIFNOT" that can take the following values :
- "ISO"
- "SYS"
- an IP address (ie: 192.168.100.1)

shorlty, the menu entry is hidden if :
- you're booting from isolinux but option is not set to "ISO"
- you're booting from syslinux but option is not set to "SYS"
- you're booting from pxelinux but option is not set to the TFTP server from which the menu is downloaded


--- syslinux-6.03/com32/menu/readconfig.c.orig	2016-05-06 16:45:43.589511704 +0200
+++ syslinux-6.03/com32/menu/readconfig.c	2016-05-06 18:37:06.573393370 +0200
@@ -232,6 +232,7 @@ struct labeldata {
 int save;
 int immediate;
 struct menu *submenu;
+ const char *visiblesource;
 };
 
 /* Menu currently being parsed */
@@ -318,6 +319,7 @@ static void record(struct menu *m, struc
 int i;
 struct menu_entry *me;
 const struct syslinux_ipappend_strings *ipappend;
+	const union syslinux_derivative_info *sdi;
 
 if (!ld->label)
 	return;			/* Nothing defined */
@@ -326,6 +328,34 @@ static void record(struct menu *m, struc
 if (ld->menuhide)
 	m = hide_menu;
 
+	/* if HIDEIFNOT is specified , then send this entry to "hidden menu" until source doesn't match */
+ if (ld->visiblesource){
+		sdi = syslinux_derivative_info();
+		uint32_t srvip;
+		char strsrvip[50];
+		switch (sdi->c.filesystem) {
+			case SYSLINUX_FS_ISOLINUX:
+				if (strcmp(ld->visiblesource, "ISO")!=0)	// if booting from CD and ISO is not specified => hide
+					m = hide_menu;
+				break;
+			case SYSLINUX_FS_PXELINUX:	// if booting from pxe and tftp sever IP address doesn't match => hide
+				srvip = sdi->pxe.ipinfo->serverip;
+				sprintf(strsrvip,"%u.%u.%u.%u",((uint8_t *)&srvip)[0], ((uint8_t *)&srvip)[1], ((uint8_t *)&srvip)[2], ((uint8_t *)&srvip)[3]);
+				if (strcmp(ld->visiblesource, strsrvip)!=0)
+					m = hide_menu;
+				break;
+			case SYSLINUX_FS_SYSLINUX:	// if booting from syslinux and SYS is not specified => hide (can surely be improved with media type control)
+				if (strcmp(ld->visiblesource, "SYS")!=0)
+					m = hide_menu;
+				break;
+			case SYSLINUX_FS_UNKNOWN: // if booting from CD unknown => hide
+				break;
+			default:
+				m = hide_menu;
+				break;
+		}
+ }
+
 if (ld->label) {
 	char ipoptions[4096], *ipp;
 	const char *a;
@@ -744,9 +774,14 @@ static void parse_config_file(FILE * f)
 	 } else if ((ep = looking_at(p, "include"))) {
 		goto do_include;
 	 } else if ((ep = looking_at(p, "background"))) {
-		p = skipspace(ep);
-		refstr_put(m->menu_background);
-		m->menu_background = refdup_word(&p);
+			p = skipspace(ep);
+			refstr_put(m->menu_background);
+			m->menu_background = refdup_word(&p);
+	 } else if ((ep = looking_at(p, "hideifnot"))){
+			if (ld.label) {
+				refstr_put(ld.visiblesource);
+				ld.visiblesource = refstrdup(skipspace(p + 9));
+			}
 	 } else if ((ep = looking_at(p, "hidden"))) {
 		hiddenmenu = 1;
 	 } else if (looking_at(p, "hiddenkey")) {



As always , I'm sorry for my english :) !!
hope this can help.

Bruno Levert

Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that
(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

Bruno Levert <brlev at free.fr>


More information about the Syslinux mailing list