From e3a73a504f6a63bf1a716131cf9dea75dc7b0b41 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Fri, 6 Sep 2024 12:25:01 +0200 Subject: rest: add GET /efi Add GET /efi request to obtain information about the client's boot entries. Field inside the /refresh payload 'efi': { 'entries': [ { "order": 0, "name": "Boot0000", "active": false, "description": "grub" }, { "order": 1, "name": "Boot0001", "active": true, "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller" } ] } If the client is not a EFI system it won't add the 'efi' field. If an entry is not in the boot order it won't have the 'order' field. GET /efi resquest payload structure: { 'clients': ['10.141.10.21', '10.141.10.22'] } GET /efi response's structure: { 'clients': [ { 'ip': '10.141.10.21', 'entries': [ { "order": 0, "name": "Boot0000", "active": false, "description": "grub" }, { "order": 1, "name": "Boot0001", "active": true, "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller" } ] }, { 'ip': '10.141.10.22', 'entries': [] } ] } The client with ip 10.141.10.22 is a BIOS system. If an entry does not appear in the boot order it won't have the 'order' field. --- src/client.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index 675be74..17bc8a7 100644 --- a/src/client.c +++ b/src/client.c @@ -435,6 +435,45 @@ static int og_update_cache_info(struct og_dbi *dbi, struct list_head *cache_list return 0; } +static int og_update_boot_entries(struct og_dbi *dbi, struct list_head *boot_entry_list, int client_id) +{ + struct og_boot_entry *boot_entry; + const char *msglog; + dbi_result result; + + /* Remove old boot entries */ + result = dbi_conn_queryf(dbi->conn, + "DELETE FROM boot_entries WHERE client_id=%d;", client_id); + + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + /* Add new boot entries */ + list_for_each_entry(boot_entry, boot_entry_list, list) { + result = dbi_conn_queryf(dbi->conn, + "INSERT INTO boot_entries (client_id, name, active, description, entry_order)" + "VALUES (%d, '%s', %d, '%s', %d)", + client_id, + boot_entry->name, + boot_entry->active ? 1 : 0, + boot_entry->description, + boot_entry->order == UINT64_MAX ? -1 : boot_entry->order); + + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + } + return 0; +} + static int og_resp_update_cache(json_t *data, struct og_client *cli) { struct og_computer computer = {}; @@ -496,6 +535,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) struct og_computer computer = {}; json_t *value, *cache = NULL; const char *status = NULL; + LIST_HEAD(boot_entry_list); LIST_HEAD(cache_list); char cfg[4096] = {}; struct og_dbi *dbi; @@ -519,6 +559,8 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) err = og_json_parse_string(value, &status); } else if (!strcmp(key, "link")) { err = og_json_parse_uint(value, &link); + } else if (!strcmp(key, "efi")) { + err = og_json_parse_efi(value, &boot_entry_list); } else if (!strcmp(key, "cache")) { err = og_json_parse_cache(value, &cache_list); cache = value; @@ -595,6 +637,12 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) goto err_out; } + res = og_update_boot_entries(dbi, &boot_entry_list, computer.id); + if (err < 0) { + og_dbi_close(dbi); + goto err_out; + } + res = actualizaConfiguracion(dbi, cfg, computer.id); og_dbi_close(dbi); @@ -611,9 +659,11 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) } og_cache_image_free(&cache_list); + og_boot_entry_free(&boot_entry_list); return 0; err_out: og_cache_image_free(&cache_list); + og_boot_entry_free(&boot_entry_list); return -1; } -- cgit v1.2.3-18-g5258