From 85d092864cddb8390c13915ead3b24b48d2b2306 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Fri, 18 Dec 2020 11:55:26 +0000 Subject: #802 add uefi folder for post_modes pxe template lookup When executing og_cmd_post_modes ogServer is looking up for the template related to the mode coming as a parameter. This lookup is only done for the bios boot mode. (ie. /opt/opengnsys/tftpboot/menu.lst/templates/) Templates can be created for a given boot mode, for example you can create a UEFI-only template (it. /opt/opengnsys/tftpboot/grub/templates). When a UEFI only template was coming as a parameter to og_cmd_post_modes the file can't be located because the UEFI template folder is never tested. Add UEFI folder to the lookup of pxe templates, try this folder if bios mode fails. PS: Later on a bash script "setclientmode" is to be executed, which will take its own way of updating these pxe files (ie. templates/../), this script updates every boot mode if an available template is found. --- src/rest.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/rest.c b/src/rest.c index d5b046d..5ca27ad 100644 --- a/src/rest.c +++ b/src/rest.c @@ -865,6 +865,7 @@ static int og_cmd_reboot(json_t *element, struct og_msg_params *params) return og_send_request(OG_METHOD_POST, OG_CMD_REBOOT, params, NULL); } +#define OG_TFTP_TMPL_PATH_UEFI "/opt/opengnsys/tftpboot/grub/templates" #define OG_TFTP_TMPL_PATH "/opt/opengnsys/tftpboot/menu.lst/templates" static int og_cmd_get_modes(json_t *element, struct og_msg_params *params, @@ -1016,6 +1017,7 @@ static int og_set_client_mode(struct og_dbi *dbi, const char *mac, static int og_cmd_post_modes(json_t *element, struct og_msg_params *params) { char ips_str[(OG_DB_IP_MAXLEN + 1) * OG_CLIENTS_MAX + 1] = {}; + char template_file_uefi[PATH_MAX + 1] = {}; char template_file[PATH_MAX + 1] = {}; char template_name[PATH_MAX + 1] = {}; char first_line[PATH_MAX + 1] = {}; @@ -1052,9 +1054,17 @@ static int og_cmd_post_modes(json_t *element, struct og_msg_params *params) OG_TFTP_TMPL_PATH, mode_str); f = fopen(template_file, "r"); if (!f) { - syslog(LOG_ERR, "cannot open file (%s:%d)\n", - __func__, __LINE__); - return -1; + syslog(LOG_WARNING, "cannot open file %s (%s:%d). Trying UEFI template instead.\n", + template_file, __func__, __LINE__); + + snprintf(template_file_uefi, sizeof(template_file_uefi), "%s/%s", + OG_TFTP_TMPL_PATH_UEFI, mode_str); + f = fopen(template_file_uefi, "r"); + if (!f) { + syslog(LOG_ERR, "cannot open file %s (%s:%d). No template found.\n", + template_file_uefi, __func__, __LINE__); + return -1; + } } if (!fgets(first_line, sizeof(first_line), f)) { -- cgit v1.2.3-18-g5258