summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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]);