summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-09-19 10:30:46 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-23 13:51:07 +0200
commit5d97a721d0d475ea86e9d503a2e413e22f53492b (patch)
treeddc362e3525685cbfa00b21e1dc1c41febb157bf /src/dbi.c
parentad31c3832d08fa1aca7bb473141cd5265e6f670d (diff)
ogAdmServer: replace old actualizaConfiguracion
Reimplement the legacy funcion actualizaConfiguracion with og_update_client_config in src/client.c if disk does not exist, add it, otherwise update disk contents. if partition size, code, filesystem or os is different, reset image id, otherwise update partition usage only. delete partitions that are gone at the end.
Diffstat (limited to 'src/dbi.c')
-rw-r--r--src/dbi.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 78485a6..0b5bbbb 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -456,3 +456,64 @@ int og_dbi_get_repository_ip(const struct og_dbi *dbi, const uint32_t repo_id,
return 0;
}
+
+int og_dbi_get_os_id(const struct og_dbi *dbi, const char *os_name, uint32_t *os_id)
+{
+ const char *msglog;
+ dbi_result result;
+
+ if (strlen(os_name) == 0)
+ return 0;
+
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT idnombreso FROM nombresos "
+ "WHERE nombreso = '%s'", os_name);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query OS id (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ if (dbi_result_next_row(result)) {
+ *os_id = dbi_result_get_uint(result, "idnombreso");
+ dbi_result_free(result);
+ return 0;
+ }
+
+ dbi_result_free(result);
+
+ result = dbi_conn_queryf(dbi->conn,
+ "INSERT INTO nombresos (nombreso) "
+ "VALUES ('%s') ", os_name);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to insert OS id (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ dbi_result_free(result);
+
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT idnombreso FROM nombresos "
+ "WHERE nombreso = '%s'", os_name);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query OS id (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ if (!dbi_result_next_row(result)) {
+ dbi_result_free(result);
+ syslog(LOG_ERR, "failed to query OS id (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ *os_id = dbi_result_get_uint(result, "idnombreso");
+ dbi_result_free(result);
+
+ return 0;
+}