mirror of https://git.48k.eu/ogserver
rest: Check no client owns provided mac address
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 roommaster v1.2.5-9
parent
149d1af21a
commit
128bba364a
29
src/rest.c
29
src/rest.c
|
@ -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;
|
||||
|
@ -2209,6 +2210,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,"
|
||||
|
|
Loading…
Reference in New Issue