diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-18 15:21:19 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-09-22 15:20:57 +0200 |
commit | cbd9421bae01c62c249cc390af5dfcdf19930e46 (patch) | |
tree | ec9726a3956d1da0079cae54b3575d945c3d732d | |
parent | d7e2022bdd1626fbcb614710bec20b4a42278f9a (diff) |
#941 Extend og_dbi_get_computer_info(...)
For the strings in og_computer we do not need to know the max size in
advance but instead we need to free up memmory using
og_dbi_free_computer_info(...) function.
-rw-r--r-- | src/client.c | 23 | ||||
-rw-r--r-- | src/dbi.c | 53 | ||||
-rw-r--r-- | src/dbi.h | 20 |
3 files changed, 80 insertions, 16 deletions
diff --git a/src/client.c b/src/client.c index b56e861..2b67e54 100644 --- a/src/client.c +++ b/src/client.c @@ -103,8 +103,8 @@ struct og_computer_legacy { static int og_resp_hardware(json_t *data, struct og_client *cli) { struct og_computer_legacy legacy = {}; + struct og_computer computer = {}; const char *hardware = NULL; - struct og_computer computer; struct og_dbi *dbi; const char *key; json_t *value; @@ -133,6 +133,7 @@ static int og_resp_hardware(json_t *data, struct og_client *cli) if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", __func__, __LINE__); + og_dbi_free_computer_info(&computer); return -1; } @@ -149,6 +150,7 @@ static int og_resp_hardware(json_t *data, struct og_client *cli) res = actualizaHardware(dbi, legacy.hardware, legacy.id, computer.name, legacy.center); og_dbi_close(dbi); + og_dbi_free_computer_info(&computer); if (!res) { syslog(LOG_ERR, "Problem updating client configuration\n"); @@ -168,9 +170,9 @@ struct og_software_legacy { static int og_resp_software(json_t *data, struct og_client *cli) { struct og_software_legacy legacy = {}; + struct og_computer computer = {}; const char *partition = NULL; const char *software = NULL; - struct og_computer computer; struct og_dbi *dbi; const char *key; json_t *value; @@ -201,6 +203,7 @@ static int og_resp_software(json_t *data, struct og_client *cli) if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", __func__, __LINE__); + og_dbi_free_computer_info(&computer); return -1; } @@ -218,6 +221,7 @@ static int og_resp_software(json_t *data, struct og_client *cli) res = actualizaSoftware(dbi, legacy.software, legacy.part, legacy.id, computer.name, legacy.center); og_dbi_close(dbi); + og_dbi_free_computer_info(&computer); if (!res) { syslog(LOG_ERR, "Problem updating client configuration\n"); @@ -347,6 +351,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", __func__, __LINE__); + og_dbi_free_computer_info(&computer); return -1; } @@ -361,15 +366,19 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) if (!res) { syslog(LOG_ERR, "Problem updating client configuration\n"); + og_dbi_free_computer_info(&computer); return -1; } if (!cli->autorun && computer.procedure_id) { cli->autorun = true; - if (og_dbi_queue_autorun(computer.id, computer.procedure_id)) + if (og_dbi_queue_autorun(computer.id, computer.procedure_id)) { + og_dbi_free_computer_info(&computer); return -1; + } } + og_dbi_free_computer_info(&computer); return 0; } @@ -403,13 +412,13 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) { struct og_software_legacy soft_legacy; struct og_image_legacy img_legacy; + struct og_computer computer = {}; const char *compressor = NULL; const char *filesystem = NULL; const char *partition = NULL; const char *software = NULL; const char *image_id = NULL; const char *clonator = NULL; - struct og_computer computer; const char *disk = NULL; const char *code = NULL; const char *name = NULL; @@ -493,10 +502,12 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) computer.name, soft_legacy.center); if (!res) { + og_dbi_free_computer_info(&computer); og_dbi_close(dbi); syslog(LOG_ERR, "Problem updating client configuration\n"); return -1; } + og_dbi_free_computer_info(&computer); res = actualizaCreacionImagen(dbi, img_legacy.image_id, @@ -527,9 +538,9 @@ static int og_resp_image_restore(json_t *data, struct og_client *cli) { struct og_software_legacy soft_legacy; struct og_image_legacy img_legacy; + struct og_computer computer = {}; const char *partition = NULL; const char *image_id = NULL; - struct og_computer computer; const char *disk = NULL; dbi_result query_result; struct og_dbi *dbi; @@ -598,6 +609,8 @@ static int og_resp_image_restore(json_t *data, struct og_client *cli) snprintf(img_legacy.disk, sizeof(img_legacy.disk), "%s", disk); snprintf(soft_legacy.id, sizeof(soft_legacy.id), "%d", computer.id); + og_dbi_free_computer_info(&computer); + res = actualizaRestauracionImagen(dbi, img_legacy.image_id, img_legacy.disk, @@ -11,6 +11,8 @@ #include <arpa/inet.h> #include <string.h> #include "dbi.h" +#include <syslog.h> +#include <string.h> struct og_dbi *og_dbi_open(struct og_dbi_config *config) { @@ -57,10 +59,23 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, result = dbi_conn_queryf(dbi->conn, "SELECT ordenadores.idordenador," - " ordenadores.nombreordenador," - " ordenadores.idaula," - " ordenadores.idproautoexec," - " centros.idcentro FROM ordenadores " + " ordenadores.nombreordenador," + " ordenadores.numserie," + " ordenadores.ip," + " ordenadores.mac," + " ordenadores.idaula," + " ordenadores.idperfilhard," + " ordenadores.idrepositorio," + " ordenadores.mascara," + " ordenadores.arranque," + " ordenadores.netiface," + " ordenadores.netdriver," + " ordenadores.idproautoexec," + " ordenadores.oglivedir," + " ordenadores.inremotepc," + " ordenadores.maintenance," + " centros.idcentro " + "FROM ordenadores " "INNER JOIN aulas ON aulas.idaula=ordenadores.idaula " "INNER JOIN centros ON centros.idcentro=aulas.idcentro " "WHERE ordenadores.ip='%s'", inet_ntoa(addr)); @@ -78,14 +93,36 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, } computer->id = dbi_result_get_uint(result, "idordenador"); - computer->center = dbi_result_get_uint(result, "idcentro"); + computer->name = strdup(dbi_result_get_string(result, "nombreordenador")); + computer->serial_number = strdup(dbi_result_get_string(result, "numserie")); + computer->ip = strdup(dbi_result_get_string(result, "ip")); + computer->mac = strdup(dbi_result_get_string(result, "mac")); computer->room = dbi_result_get_uint(result, "idaula"); + computer->hardware_id = dbi_result_get_uint(result, "idperfilhard"); + computer->repo_id = dbi_result_get_uint(result, "idrepositorio"); + computer->netmask = strdup(dbi_result_get_string(result, "mascara")); + computer->boot = strdup(dbi_result_get_string(result, "arranque")); + computer->netiface = strdup(dbi_result_get_string(result, "netiface")); + computer->netdriver = strdup(dbi_result_get_string(result, "netdriver")); computer->procedure_id = dbi_result_get_uint(result, "idproautoexec"); - strncpy(computer->name, - dbi_result_get_string(result, "nombreordenador"), - OG_DB_COMPUTER_NAME_MAXLEN); + computer->livedir = strdup(dbi_result_get_string(result, "oglivedir")); + computer->remote = dbi_result_get_uint(result, "inremotepc") != 0; + computer->maintenance = dbi_result_get_uint(result, "maintenance") != 0; dbi_result_free(result); return 0; } + +void og_dbi_free_computer_info(struct og_computer *computer) +{ + free(computer->serial_number); + free(computer->netdriver); + free(computer->netiface); + free(computer->netmask); + free(computer->livedir); + free(computer->name); + free(computer->boot); + free(computer->mac); + free(computer->ip); +} @@ -2,6 +2,7 @@ #define __OG_DBI #include <dbi/dbi.h> +#include <stdbool.h> struct og_dbi_config { const char *user; @@ -50,15 +51,28 @@ struct og_legacy_partition { extern struct og_dbi_config dbi_config; struct og_computer { - unsigned int id; + unsigned int procedure_id; + unsigned int hardware_id; + unsigned int repo_id; unsigned int center; unsigned int room; - char name[OG_DB_COMPUTER_NAME_MAXLEN + 1]; - unsigned int procedure_id; + unsigned int id; + bool maintenance; + bool remote; + char *serial_number; + char *netdriver; + char *netiface; + char *netmask; + char *livedir; + char *name; + char *boot; + char *mac; + char *ip; }; struct in_addr; int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, struct in_addr addr); +void og_dbi_free_computer_info(struct og_computer *computer); #endif |