diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2021-02-22 10:12:56 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-02-22 11:05:34 +0100 |
commit | ed0d86b010d2b8b8ec6e16de62d5bf9e1c1dea85 (patch) | |
tree | 3439c4297fa9b055c27aa67d617de67171654b2a /src/rest.c | |
parent | e4cb91b5f660984f437c85b1b60b8ba7682759bf (diff) |
#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.
Diffstat (limited to 'src/rest.c')
-rw-r--r-- | src/rest.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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; } |