summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-16 10:45:07 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-18 09:26:11 +0200
commit075725b1feef20a0cec4ef8affdf792aba2d6e23 (patch)
tree0129a2ceda86b1eac9d0106bec6a072bf1a50b2e /src/rest.c
parent8a23579cabb747cc6662b1b1bafefb7ba79e22b8 (diff)
rest: delete pxe files on client delete and updatev1.2.5-15v1.2.5-14
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.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c28
1 files changed, 28 insertions, 0 deletions
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]);