From 5d97a721d0d475ea86e9d503a2e413e22f53492b Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Thu, 19 Sep 2024 10:30:46 +0200 Subject: 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. --- src/dbi.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/dbi.c') 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; +} -- cgit v1.2.3-18-g5258