From 075725b1feef20a0cec4ef8affdf792aba2d6e23 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 16 Jul 2024 10:45:07 +0200 Subject: rest: delete pxe files on client delete and update call og_delete_tftpboot_file for both pxe configuration files in client/delete and client/update. Delete files for client/update only if the MAC changes. --- src/rest.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/rest.c b/src/rest.c index 48caf3b..708d53a 100644 --- a/src/rest.c +++ b/src/rest.c @@ -1392,6 +1392,30 @@ static int og_remove_tftpboot_file(unsigned int boot_type, const char *mac) return 0; } +static int og_remove_tftpboot_files(struct og_dbi *dbi, const char *ip) +{ + const char *msglog, *old_mac; + dbi_result result; + + result = dbi_conn_queryf(dbi->conn, + "SELECT mac FROM ordenadores WHERE ip='%s'", ip); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + og_dbi_close(dbi); + return -1; + } + if (dbi_result_next_row(result)) { + old_mac = dbi_result_get_string(result, "mac"); + og_remove_tftpboot_file(OG_TFTP_BOOT_BIOS, old_mac); + og_remove_tftpboot_file(OG_TFTP_BOOT_UEFI, old_mac); + } + + dbi_result_free(result); + return 0; +} + static int og_create_boot_file(unsigned int boot_type, const char *mac, const char *mode, char *params) { @@ -2293,6 +2317,8 @@ static int og_cmd_post_client_update(json_t *element, dbi_result_free(result); + og_remove_tftpboot_files(dbi, computer.ip); + result = dbi_conn_queryf(dbi->conn, "UPDATE ordenadores" " SET numserie='%s'," @@ -2960,6 +2986,8 @@ static int og_cmd_post_client_delete(json_t *element, } for (i = 0; i < params->ips_array_len; i++) { + og_remove_tftpboot_files(dbi, params->ips_array[i]); + result = dbi_conn_queryf(dbi->conn, "DELETE FROM ordenadores WHERE ip='%s'", params->ips_array[i]); -- cgit v1.2.3-18-g5258