diff options
author | Javier Hernandez <jhernandez@soleta.eu> | 2024-01-16 11:37:10 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-01-16 13:30:27 +0100 |
commit | 128bba364ab73661b72a2ba1ce7c0299d0b25b47 (patch) | |
tree | 4a10c835c0a45262d9f81c53c44ada2d08679b7c /src/rest.c | |
parent | 149d1af21a9d8348cd504b21ad29fd2d742e8f77 (diff) |
rest: Check no client owns provided mac addressv1.2.5-9
Reply with an error if user tries to create a client with a mac that is
already owned by another client
Write to syslog info about the client that owns the mac: client's name,
ip, mac address and room
Diffstat (limited to 'src/rest.c')
-rw-r--r-- | src/rest.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -2116,6 +2116,7 @@ static int og_cmd_post_client_add(json_t *element, struct og_msg_params *params, char *buffer_reply) { + const char *room_name, *computer_name, *computer_ip, *hwaddr; struct og_computer computer = {}; const char *key, *msglog; struct og_dbi *dbi; @@ -2210,6 +2211,34 @@ static int og_cmd_post_client_add(json_t *element, dbi_result_free(result); result = dbi_conn_queryf(dbi->conn, + "SELECT nombreordenador, ip, nombreaula" + " FROM ordenadores" + " INNER JOIN aulas on ordenadores.idaula = aulas.idaula" + " WHERE mac='%s'", + computer.mac); + + 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)) { + room_name = dbi_result_get_string(result, "nombreaula"); + computer_name = dbi_result_get_string(result, "nombreordenador"); + computer_ip = dbi_result_get_string(result, "ip"); + hwaddr = dbi_result_get_string(result, "mac"); + syslog(LOG_ERR, "Failed to add client %s because %s (%s) in room %s already owns MAC address %s\n", + computer.ip, computer_ip, computer_name, room_name, hwaddr); + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } + dbi_result_free(result); + + result = dbi_conn_queryf(dbi->conn, "INSERT INTO ordenadores(" " nombreordenador," " numserie," |