From ed0d86b010d2b8b8ec6e16de62d5bf9e1c1dea85 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Mon, 22 Feb 2021 10:12:56 +0100 Subject: #1019 Fix queued Wake on LAN UMA and UPV report that Wake on LAN command (in queue mode) does not work. We improved WoL command, now ogServer calculates the broadcast address of the network to which the client belongs. To calculate this address ogServer needs the IP and the netmask of the client. We updated ogServer to retrieve the netmask from the database in non-queue mode, but we forgot to add this in queue mode. This patch adds netmask retrieving to queued WoL. --- src/rest.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/rest.c b/src/rest.c index 9f03f9f..bee5e24 100644 --- a/src/rest.c +++ b/src/rest.c @@ -2138,6 +2138,7 @@ void og_cmd_free(const struct og_cmd *cmd) int i; for (i = 0; i < params->ips_array_len; i++) { + free((void *)params->netmask_array[i]); free((void *)params->ips_array[i]); free((void *)params->mac_array[i]); } @@ -2164,16 +2165,43 @@ static void og_cmd_init(struct og_cmd *cmd, enum og_rest_method method, static int og_cmd_legacy_wol(const char *input, struct og_cmd *cmd) { char wol_type[2] = {}; + const char *msglog; + struct og_dbi *dbi; + dbi_result result; if (sscanf(input, "mar=%s", wol_type) != 1) { syslog(LOG_ERR, "malformed database legacy input\n"); return -1; } + dbi = og_dbi_open(&ogconfig.db); + if (!dbi) { + syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", + __func__, __LINE__); + return -1; + } + + result = dbi_conn_queryf(dbi->conn, + "SELECT mascara FROM ordenadores " + "WHERE ip = '%s'", cmd->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; + } + dbi_result_next_row(result); + og_cmd_init(cmd, OG_METHOD_NO_HTTP, OG_CMD_WOL, NULL); + cmd->params.netmask_array[0] = dbi_result_get_string_copy(result, + "mascara"); cmd->params.mac_array[0] = strdup(cmd->mac); cmd->params.wol_type = strdup(wol_type); + dbi_result_free(result); + og_dbi_close(dbi); + return 0; } -- cgit v1.2.3-18-g5258