summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cfg.c16
-rw-r--r--src/cfg.h12
-rw-r--r--src/client.c13
-rw-r--r--src/dbi.c6
-rw-r--r--src/dbi.h8
-rw-r--r--src/main.c2
-rw-r--r--src/ogAdmServer.c20
-rw-r--r--src/ogAdmServer.h12
-rw-r--r--src/rest.c32
-rw-r--r--src/wol.c3
10 files changed, 36 insertions, 88 deletions
diff --git a/src/cfg.c b/src/cfg.c
index 42da3a5..6ac2f2d 100644
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -58,8 +58,7 @@ static int parse_json_db(struct og_server_cfg *cfg, json_t *element)
if (og_json_parse_string(value, &cfg->db.name) < 0)
return -1;
} else if (!strcmp(key, "port")) {
- if (og_json_parse_uint(value, &cfg->db.port) < 0 ||
- cfg->db.port > UINT16_MAX)
+ if (og_json_parse_string(value, &cfg->db.port) < 0)
return -1;
} else {
syslog(LOG_ERR, "unknown key `%s' in db\n", key);
@@ -188,16 +187,3 @@ int parse_json_config(const char *filename, struct og_server_cfg *cfg)
return ret;
}
-
-void from_json_to_legacy(struct og_server_cfg *cfg)
-{
- snprintf(servidoradm, sizeof(servidoradm), "%s", cfg->rest.ip);
- snprintf(puerto, sizeof(puerto), "%s", cfg->rest.port);
- snprintf(usuario, sizeof(usuario), "%s", cfg->db.user);
- snprintf(pasguor, sizeof(pasguor), "%s", cfg->db.pass);
- snprintf(datasource, sizeof(datasource), "%s", cfg->db.ip);
- snprintf(catalog, sizeof(catalog), "%s", cfg->db.name);
- snprintf(interface, sizeof(interface), "%s", cfg->wol.interface);
- snprintf(auth_token, sizeof(auth_token), "%s", cfg->rest.api_token);
- snprintf(db_port, sizeof(db_port), "%u", cfg->db.port);
-}
diff --git a/src/cfg.h b/src/cfg.h
index 75678da..97e47cf 100644
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -1,14 +1,11 @@
#ifndef _OG_SERVER_CFG_H
#define _OG_SERVER_CFG_H
+#include <jansson.h>
+#include "dbi.h"
+
struct og_server_cfg {
- struct {
- const char *user;
- const char *pass;
- const char *ip;
- unsigned int port;
- const char *name;
- } db;
+ struct og_dbi_config db;
struct {
const char *ip;
const char *port;
@@ -24,7 +21,6 @@ struct og_server_cfg {
};
int parse_json_config(const char *filename, struct og_server_cfg *cfg);
-void from_json_to_legacy(struct og_server_cfg *cfg);
extern struct og_server_cfg ogconfig;
diff --git a/src/client.c b/src/client.c
index b475189..ebac662 100644
--- a/src/client.c
+++ b/src/client.c
@@ -7,6 +7,7 @@
*/
#include "ogAdmServer.h"
+#include "cfg.h"
#include "dbi.h"
#include "utils.h"
#include "list.h"
@@ -129,7 +130,7 @@ static int og_resp_hardware(json_t *data, struct og_client *cli)
return -1;
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -197,7 +198,7 @@ static int og_resp_software(json_t *data, struct og_client *cli)
return -1;
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -265,7 +266,7 @@ static int og_dbi_queue_autorun(uint32_t computer_id, uint32_t proc_id)
};
struct og_dbi *dbi;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database "
"(%s:%d)\n", __func__, __LINE__);
@@ -343,7 +344,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
partitions[i].used_size);
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -460,7 +461,7 @@ static int og_resp_image_create(json_t *data, struct og_client *cli)
return -1;
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -560,7 +561,7 @@ static int og_resp_image_restore(json_t *data, struct og_client *cli)
return -1;
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
diff --git a/src/dbi.c b/src/dbi.c
index 3c4ae51..968b00e 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -30,11 +30,11 @@ struct og_dbi *og_dbi_open(struct og_dbi_config *config)
return NULL;
}
- dbi_conn_set_option(dbi->conn, "host", config->host);
+ dbi_conn_set_option(dbi->conn, "host", config->ip);
dbi_conn_set_option(dbi->conn, "port", config->port);
dbi_conn_set_option(dbi->conn, "username", config->user);
- dbi_conn_set_option(dbi->conn, "password", config->passwd);
- dbi_conn_set_option(dbi->conn, "dbname", config->database);
+ dbi_conn_set_option(dbi->conn, "password", config->pass);
+ dbi_conn_set_option(dbi->conn, "dbname", config->name);
dbi_conn_set_option(dbi->conn, "encoding", "UTF-8");
if (dbi_conn_connect(dbi->conn) < 0) {
diff --git a/src/dbi.h b/src/dbi.h
index e92ce43..7bfe311 100644
--- a/src/dbi.h
+++ b/src/dbi.h
@@ -6,10 +6,10 @@
struct og_dbi_config {
const char *user;
- const char *passwd;
- const char *host;
+ const char *pass;
+ const char *ip;
const char *port;
- const char *database;
+ const char *name;
};
struct og_dbi {
@@ -54,8 +54,6 @@ struct og_legacy_partition {
char format[2]; /* Format is a boolean 0 or 1 => length is 2 */
};
-extern struct og_dbi_config dbi_config;
-
struct og_computer {
unsigned int procedure_id;
unsigned int hardware_id;
diff --git a/src/main.c b/src/main.c
index 8ca7283..36b2fe0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -69,8 +69,6 @@ int main(int argc, char *argv[])
if (parse_json_config(config_file, &ogconfig) < 0)
return EXIT_FAILURE;
- from_json_to_legacy(&ogconfig);
-
socket_rest = og_socket_server_init(ogconfig.rest.port);
if (socket_rest < 0) {
syslog(LOG_ERR, "Cannot open REST API server socket\n");
diff --git a/src/ogAdmServer.c b/src/ogAdmServer.c
index 1568386..22fbfb1 100644
--- a/src/ogAdmServer.c
+++ b/src/ogAdmServer.c
@@ -23,26 +23,6 @@
#include <jansson.h>
#include <time.h>
-char usuario[4096]; // Usuario de acceso a la base de datos
-char pasguor[4096]; // Password del usuario
-char datasource[4096]; // Dirección IP del gestor de base de datos
-char catalog[4096]; // Nombre de la base de datos
-char interface[4096]; // Interface name
-char auth_token[4096]; // API token
-char servidoradm[4096]; // Dirección IP del servidor de administración
-char puerto[4096]; // Puerto de comunicación
-char db_port[4096];
-
-struct og_dbi_config dbi_config = {
- .user = usuario,
- .passwd = pasguor,
- .host = datasource,
- .port = db_port,
- .database = catalog,
-};
-
-#define OG_CMD_MAXLEN 64
-
// ________________________________________________________________________________________________________
// Función: actualizaConfiguracion
//
diff --git a/src/ogAdmServer.h b/src/ogAdmServer.h
index 049c5e0..77e5683 100644
--- a/src/ogAdmServer.h
+++ b/src/ogAdmServer.h
@@ -20,18 +20,6 @@
#include <stdbool.h>
#include "ogAdmLib.h"
-extern char auth_token[4096];
-extern char usuario[4096];
-extern char pasguor[4096];
-extern char catalog[4096];
-extern char datasource[4096];
-extern char interface[4096];
-extern char api_token[4096];
-extern char servidoradm[4096];
-extern char puerto[4096];
-extern char db_port[4096];
-
-struct og_client;
struct og_dbi;
bool actualizaConfiguracion(struct og_dbi *,char* ,int);
diff --git a/src/rest.c b/src/rest.c
index f8eefc5..a51134a 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -985,7 +985,7 @@ static int og_cmd_post_modes(json_t *element, struct og_msg_params *params)
}
ips_str[ips_str_len - 1] = '\0';
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -1066,7 +1066,7 @@ static int og_cmd_get_client_setup(json_t *element,
}
json_object_set_new(root, "partitions", partitions_array);
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
json_decref(root);
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
@@ -1177,7 +1177,7 @@ static int og_cmd_get_client_info(json_t *element,
if (inet_aton(params->ips_array[0], &addr) == 0)
return -1;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
@@ -1283,7 +1283,7 @@ static int og_cmd_post_client_add(json_t *element,
break;
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
@@ -1434,7 +1434,7 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
return -1;
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -1638,7 +1638,7 @@ static int og_cmd_images(char *buffer_reply)
json_object_set_new(root, "images", images);
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -2556,7 +2556,7 @@ int og_dbi_update_action(uint32_t id, bool success)
if (!id)
return 0;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -2598,7 +2598,7 @@ void og_schedule_run(unsigned int task_id, unsigned int schedule_id,
struct og_dbi *dbi;
unsigned int i;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -2673,7 +2673,7 @@ static int og_cmd_task_post(json_t *element, struct og_msg_params *params)
if (!og_msg_params_validate(params, OG_REST_PARAM_TASK))
return -1;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -2863,7 +2863,7 @@ static int og_cmd_scope_get(json_t *element, struct og_msg_params *params,
}
json_object_set_new(root, "scope", array);
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -2893,7 +2893,7 @@ int og_dbi_schedule_get(void)
const char *msglog;
dbi_result result;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -3156,7 +3156,7 @@ static int og_task_schedule_create(struct og_msg_params *params)
else
return -1;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -3257,7 +3257,7 @@ static int og_cmd_schedule_update(json_t *element, struct og_msg_params *params)
OG_REST_PARAM_TIME_AM_PM))
return -1;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -3302,7 +3302,7 @@ static int og_cmd_schedule_delete(json_t *element, struct og_msg_params *params)
if (!og_msg_params_validate(params, OG_REST_PARAM_ID))
return -1;
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -3348,7 +3348,7 @@ static int og_cmd_schedule_get(json_t *element, struct og_msg_params *params,
}
}
- dbi = og_dbi_open(&dbi_config);
+ dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
@@ -3468,7 +3468,7 @@ int og_client_state_process_payload_rest(struct og_client *cli)
body = strstr(cli->buf, "\r\n\r\n") + 4;
- if (strcmp(cli->auth_token, auth_token)) {
+ if (strcmp(cli->auth_token, ogconfig.rest.api_token)) {
syslog(LOG_ERR, "wrong Authentication key\n");
return og_client_not_authorized(cli);
}
diff --git a/src/wol.c b/src/wol.c
index 40a390c..0ebf718 100644
--- a/src/wol.c
+++ b/src/wol.c
@@ -18,6 +18,7 @@
#include <sys/socket.h>
#include <fcntl.h>
#include "wol.h"
+#include "cfg.h"
#include "ogAdmServer.h"
int wol_socket_open(void)
@@ -73,7 +74,7 @@ bool wake_up_broadcast(int sd, struct sockaddr_in *client,
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL ||
ifa->ifa_addr->sa_family != AF_INET ||
- strcmp(ifa->ifa_name, interface) != 0)
+ strcmp(ifa->ifa_name, ogconfig.wol.interface) != 0)
continue;
broadcast_addr =