hdt: preventing pxe mode being reach w/o pxelinux
authorerwan <erwan@laptopR1.(none)>
Sun, 8 Mar 2009 10:26:03 +0000 (11:26 +0100)
committererwan <erwan@laptopR1.(none)>
Sun, 8 Mar 2009 10:26:03 +0000 (11:26 +0100)
If the current bootloader isn't pxelinux, the pxe
mode mustn't be available in the cli mode
The syslinux detection have been refactorised too

com32/hdt/hdt-cli-pxe.c
com32/hdt/hdt-cli.c
com32/hdt/hdt-common.c
com32/hdt/hdt-common.h
com32/hdt/hdt-menu-syslinux.c
com32/hdt/hdt-menu.c
com32/hdt/hdt-menu.h
com32/hdt/hdt.c

index ea19093..c88d444 100644 (file)
 #include <stdlib.h>
 #include <errno.h>
 #include <syslinux/pxe.h>
+#include <syslinux/config.h>
 
 void main_show_pxe(struct s_hardware *hardware,struct s_cli_mode *cli_mode) {
  char buffer[81];
  memset(buffer,0,sizeof(81));
+ if (hardware->sv->filesystem == SYSLINUX_FS_PXELINUX) {
+        more_printf("You are not currently using PXELINUX\n");
+        return;
+ }
 
  detect_pxe(hardware);
  more_printf("PXE\n");
index 5847d7f..a92d5f5 100644 (file)
@@ -30,6 +30,7 @@
 #include "hdt-common.h"
 #include <stdlib.h>
 #include <string.h>
+#include <syslinux/config.h>
 
 void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *hardware) {
  switch (mode) {
@@ -44,6 +45,10 @@ void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *h
         break;
 
   case PXE_MODE:
+       if (hardware->sv->filesystem == SYSLINUX_FS_PXELINUX) {
+               more_printf("You are not currently using PXELINUX\n");
+               break;
+       }
         cli_mode->mode=mode;
         snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s> ", CLI_PXE);
         break;
@@ -213,14 +218,15 @@ void main_show_summary(struct s_hardware *hardware, struct s_cli_mode *cli_mode)
    main_show_kernel(hardware,cli_mode);
 }
 
-void show_main_help() {
+void show_main_help(struct s_hardware *hardware) {
   more_printf("Show supports the following commands : \n");
   more_printf(" %s\n",CLI_SUMMARY);
   more_printf(" %s\n",CLI_PCI);
   more_printf(" %s\n",CLI_DMI);
   more_printf(" %s\n",CLI_CPU);
-  more_printf(" %s\n",CLI_PXE);
   more_printf(" %s\n",CLI_KERNEL);
+  if (hardware->sv->filesystem == SYSLINUX_FS_PXELINUX)
+         more_printf(" %s\n",CLI_PXE);
 }
 
 void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_mode) {
@@ -230,5 +236,5 @@ void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_m
  if (!strncmp(item,CLI_CPU, sizeof (CLI_CPU))) { main_show_cpu(hardware,cli_mode); return; }
  if (!strncmp(item,CLI_PXE, sizeof (CLI_PXE))) { main_show_pxe(hardware,cli_mode); return; }
  if (!strncmp(item,CLI_KERNEL, sizeof (CLI_KERNEL))) { main_show_kernel(hardware,cli_mode); return; }
- show_main_help();
+ show_main_help(hardware);
 }
index 231c35f..39af948 100644 (file)
 #include <stdio.h>
 #include "syslinux/config.h"
 
+void detect_syslinux(struct s_hardware *hardware) {
+  hardware->sv = syslinux_version();
+  switch(hardware->sv->filesystem) {
+        case SYSLINUX_FS_SYSLINUX: strlcpy(hardware->syslinux_fs,"SYSlinux",9); break;
+        case SYSLINUX_FS_PXELINUX: strlcpy(hardware->syslinux_fs,"PXElinux",9); break;
+        case SYSLINUX_FS_ISOLINUX: strlcpy(hardware->syslinux_fs,"ISOlinux",9); break;
+        case SYSLINUX_FS_EXTLINUX: strlcpy(hardware->syslinux_fs,"EXTlinux",9); break;
+        case SYSLINUX_FS_UNKNOWN:
+        default: strlcpy(hardware->syslinux_fs,"Unknown Bootloader",sizeof hardware->syslinux_fs); break;
+  }
+}
+
 void init_hardware(struct s_hardware *hardware) {
   hardware->pci_ids_return_code=0;
   hardware->modules_pcimap_return_code=0;
@@ -50,6 +62,7 @@ void init_hardware(struct s_hardware *hardware) {
   memset(&hardware->dmi,0,sizeof(s_dmi));
   memset(&hardware->cpu,0,sizeof(s_cpu));
   memset(&hardware->pxe,0,sizeof(struct s_pxe));
+  memset(hardware->syslinux_fs,0,sizeof hardware->syslinux_fs);
 }
 
 /* Detecting if a DMI table exist
@@ -82,7 +95,6 @@ int detect_pxe(struct s_hardware *hardware) {
  void *dhcpdata;
 
  size_t dhcplen;
- const struct syslinux_version *sv;
  t_PXENV_UNDI_GET_NIC_TYPE gnt;
 
  if (hardware->pxe_detection == true) return -1;
@@ -91,9 +103,8 @@ int detect_pxe(struct s_hardware *hardware) {
  memset(&gnt,0, sizeof(t_PXENV_UNDI_GET_NIC_TYPE));
  memset(&hardware->pxe,0, sizeof(struct s_pxe));
 
- sv = syslinux_version();
  /* This code can only work if pxelinux is loaded*/
- if (sv->filesystem != SYSLINUX_FS_PXELINUX) {
+ if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) {
         return -1;
  }
 
index 04a46e4..5cf8060 100644 (file)
@@ -93,6 +93,9 @@ struct s_hardware {
   bool cpu_detection; /* Does the cpu stuff have been already detected */
   bool disk_detection; /* Does the disk stuff have been already detected */
   bool pxe_detection; /* Does the pxe stuff have been already detected*/
+
+ char syslinux_fs[22];
+ struct syslinux_version *sv;
 };
 
 char *find_argument(const char **argv, const char *argument);
@@ -103,4 +106,5 @@ void cpu_detect(struct s_hardware *hardware);
 int detect_pxe(struct s_hardware *hardware);
 void init_hardware(struct s_hardware *hardware);
 void clear_screen(void);
+void detect_syslinux(struct s_hardware *hardware);
 #endif
index 4ee6d1d..d17070f 100644 (file)
 #include "hdt-menu.h"
 
 /* Computing Syslinux menu*/
-void compute_syslinuxmenu(struct s_my_menu *menu) {
-  char syslinux_fs[22];
+void compute_syslinuxmenu(struct s_my_menu *menu, struct s_hardware *hardware) {
   char syslinux_fs_menu[24];
   char buffer[SUBMENULEN+1];
   char statbuffer[STATLEN+1];
-  const struct syslinux_version *sv;
 
-
-  memset(syslinux_fs,0,sizeof syslinux_fs);
   memset(syslinux_fs_menu,0,sizeof syslinux_fs_menu);
 
-  sv = syslinux_version();
-  switch(sv->filesystem) {
-        case SYSLINUX_FS_SYSLINUX: strlcpy(syslinux_fs,"SYSlinux",9); break;
-        case SYSLINUX_FS_PXELINUX: strlcpy(syslinux_fs,"PXElinux",9); break;
-        case SYSLINUX_FS_ISOLINUX: strlcpy(syslinux_fs,"ISOlinux",9); break;
-        case SYSLINUX_FS_EXTLINUX: strlcpy(syslinux_fs,"EXTlinux",9); break;
-        case SYSLINUX_FS_UNKNOWN:
-        default: strlcpy(syslinux_fs,"Unknown Bootloader",sizeof syslinux_fs); break;
-  }
-  snprintf(syslinux_fs_menu,sizeof syslinux_fs_menu," %s ",syslinux_fs);
+  snprintf(syslinux_fs_menu,sizeof syslinux_fs_menu," %s ",hardware->syslinux_fs);
   menu->menu = add_menu(syslinux_fs_menu,-1);
   menu->items_count=0;
   set_menu_pos(SUBMENU_Y,SUBMENU_X);
 
-  snprintf(buffer, sizeof buffer, "Bootloader : %s", syslinux_fs);
-  snprintf(statbuffer, sizeof statbuffer, "Bootloader: %s", syslinux_fs);
+  snprintf(buffer, sizeof buffer, "Bootloader : %s", hardware->syslinux_fs);
+  snprintf(statbuffer, sizeof statbuffer, "Bootloader: %s", hardware->syslinux_fs);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer, sizeof buffer, "Version    : %s", sv->version_string+2);
-  snprintf(statbuffer, sizeof statbuffer, "Version: %s", sv->version_string+2);
+  snprintf(buffer, sizeof buffer, "Version    : %s", hardware->sv->version_string+2);
+  snprintf(statbuffer, sizeof statbuffer, "Version: %s", hardware->sv->version_string+2);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer, sizeof buffer, "Version    : %u",sv->version);
-  snprintf(statbuffer, sizeof statbuffer, "Version: %u",sv->version);
+  snprintf(buffer, sizeof buffer, "Version    : %u",hardware->sv->version);
+  snprintf(statbuffer, sizeof statbuffer, "Version: %u",hardware->sv->version);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
-  snprintf(buffer, sizeof buffer, "Max API    : %u",sv->max_api);
-  snprintf(statbuffer, sizeof statbuffer, "Max API: %u",sv->max_api);
+  snprintf(buffer, sizeof buffer, "Max API    : %u",hardware->sv->max_api);
+  snprintf(statbuffer, sizeof statbuffer, "Max API: %u",hardware->sv->max_api);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
   add_item("","",OPT_SEP,"",0);
 
-  snprintf(buffer, sizeof buffer, "%s", sv->copyright_string+1);
-  snprintf(statbuffer, sizeof statbuffer, "%s", sv->copyright_string+1);
+  snprintf(buffer, sizeof buffer, "%s", hardware->sv->copyright_string+1);
+  snprintf(statbuffer, sizeof statbuffer, "%s", hardware->sv->copyright_string+1);
   add_item(buffer,statbuffer,OPT_INACTIVE,NULL,0);
   menu->items_count++;
 
index 7380a07..0853f09 100644 (file)
@@ -144,7 +144,7 @@ void compute_submenus(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware)
   compute_kernel(&(hdt_menu->kernel_menu),hardware);
 #endif
   compute_summarymenu(&(hdt_menu->summary_menu),hardware);
-  compute_syslinuxmenu(&(hdt_menu->syslinux_menu));
+  compute_syslinuxmenu(&(hdt_menu->syslinux_menu),hardware);
   compute_aboutmenu(&(hdt_menu->about_menu));
 }
 
index 19986cc..db94057 100644 (file)
@@ -102,7 +102,7 @@ void compute_memory_module(struct s_my_menu *menu, s_dmi *dmi, int slot_number);
 void compute_processor(struct s_my_menu *menu,struct s_hardware *hardware);
 
 // Syslinux stuff
-void compute_syslinuxmenu(struct s_my_menu *menu);
+void compute_syslinuxmenu(struct s_my_menu *menu,struct s_hardware *hardware);
 
 // About menu
 void compute_aboutmenu(struct s_my_menu *menu);
index c96d0b9..ec667c3 100644 (file)
@@ -52,6 +52,9 @@ int main(int argc, char *argv[])
   /* Cleaning structures */
   init_hardware(&hardware);
 
+  /* Detecting Syslinux Version*/
+  detect_syslinux(&hardware);
+
   /* Opening the syslinux console */
   openconsole(&dev_stdcon_r, &dev_ansicon_w);