From 775334cd2b626312290de44a4cf005b2221e0982 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Thu, 24 Feb 2022 14:21:31 +0100 Subject: [PATCH 1/4] Added the appliance_status response field to get_license command. Added the appliance_status response field to the get_license command, so that the notification about license choices can be handled. --- src/gmp_license.c | 11 ++++++++--- src/manage_license.c | 43 ++++++++++++++++++++++++++++++++++++++++--- src/manage_license.h | 2 +- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/gmp_license.c b/src/gmp_license.c index da5664ab6..e34959b33 100644 --- a/src/gmp_license.c +++ b/src/gmp_license.c @@ -181,13 +181,15 @@ get_license_run (gmp_parser_t *gmp_parser, int ret; gchar *license_status; + gchar *appliance_status; theia_license_t *license_data; license_status = NULL; license_data = NULL; ret = manage_get_license (&license_status, - &license_data); + &license_data, + &appliance_status); switch (ret) { @@ -200,10 +202,12 @@ get_license_run (gmp_parser_t *gmp_parser, "" "" - "%s", + "%s" + "%s", STATUS_OK, STATUS_OK_TEXT, - license_status); + license_status, + appliance_status ? appliance_status : ""); if (license_data) { @@ -245,6 +249,7 @@ get_license_run (gmp_parser_t *gmp_parser, } g_free (license_status); + g_free (appliance_status); #ifdef HAS_LIBTHEIA theia_license_free (license_data); diff --git a/src/manage_license.c b/src/manage_license.c index 8093056c0..b9705b0ac 100644 --- a/src/manage_license.c +++ b/src/manage_license.c @@ -26,6 +26,7 @@ #include "manage_acl.h" #include "manage_license.h" #include "utils.h" +#include "sql.h" #undef G_LOG_DOMAIN /** @@ -166,21 +167,52 @@ manage_update_license_file (const char *new_license, return 0; } +/** + * @brief Get the current appliance status + * + * @param[in] got_license_info The info about the received license + * + * @return appliance status or NULL if not available + */ +static gchar* +get_appliance_status(theia_got_license_info_t *gli) +{ + gchar *comm_app; + gchar *app_status; + + comm_app = sql_string ("SELECT value from public.meta" + " where name = 'community_appliance';"); + + if (comm_app && atoi (comm_app)) + app_status = g_strdup("community"); + else if (gli && gli->license && gli->license->meta) + app_status = g_strdup_printf ("%s_%s", gli->license->meta->type, + gli->status); + else + app_status = NULL; + + return app_status; +} + /** * @brief Get the current license information. * - * @param[out] status The validation status (e.g. "valid", "expired"). - * @param[out] license_data The content of the license organized in a struct. + * @param[out] status The validation status (e.g. "valid", "expired"). + * @param[out] license_data The content of the license organized in a struct. + * @param[out] appliance_status The status of the appliance. * * @return 0 success, 1 service unavailable, 2 error sending command, * 3 error receiving response, 99 permission denied, -1 internal error. */ int manage_get_license (gchar **status, - theia_license_t **license_data) + theia_license_t **license_data, + gchar **appliance_status) { if (status) *status = NULL; + if (appliance_status) + *appliance_status = NULL; if (license_data) *license_data = NULL; @@ -260,6 +292,11 @@ manage_get_license (gchar **status, theia_client_disconnect (client); + if (appliance_status) + { + *appliance_status = get_appliance_status(got_license_info); + } + if (status) { *status = got_license_info->status; diff --git a/src/manage_license.h b/src/manage_license.h index 14b2983d4..81b15b2d0 100644 --- a/src/manage_license.h +++ b/src/manage_license.h @@ -37,4 +37,4 @@ int manage_update_license_file (const char *, gboolean *, char **); int -manage_get_license (char **, theia_license_t **); +manage_get_license (gchar **, theia_license_t **, gchar**); From c1ef2855f56cf3e49012a8c6e8288c3d3496daf5 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Thu, 24 Feb 2022 15:07:19 +0100 Subject: [PATCH 2/4] Added a missing "#ifdef HAS_LIBTHEIA" --- src/manage_license.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/manage_license.c b/src/manage_license.c index b9705b0ac..35bfbb864 100644 --- a/src/manage_license.c +++ b/src/manage_license.c @@ -167,6 +167,8 @@ manage_update_license_file (const char *new_license, return 0; } +#ifdef HAS_LIBTHEIA + /** * @brief Get the current appliance status * @@ -194,6 +196,8 @@ get_appliance_status(theia_got_license_info_t *gli) return app_status; } +#endif // HAS_LIBTHEIA + /** * @brief Get the current license information. * From 6812ea1f18f88eb7d71f8a606681f5bf76783945 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Thu, 24 Feb 2022 16:20:46 +0100 Subject: [PATCH 3/4] Outsourced the SQL query for the community appliance value. Outsourced the SQL query for the community appliance value from manage_license.c to manage_sql.c. --- src/manage_license.c | 5 ++--- src/manage_sql.c | 12 ++++++++++++ src/manage_sql.h | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/manage_license.c b/src/manage_license.c index 35bfbb864..8023af2ab 100644 --- a/src/manage_license.c +++ b/src/manage_license.c @@ -26,7 +26,7 @@ #include "manage_acl.h" #include "manage_license.h" #include "utils.h" -#include "sql.h" +#include "manage_sql.h" #undef G_LOG_DOMAIN /** @@ -182,8 +182,7 @@ get_appliance_status(theia_got_license_info_t *gli) gchar *comm_app; gchar *app_status; - comm_app = sql_string ("SELECT value from public.meta" - " where name = 'community_appliance';"); + comm_app = get_community_appliance_value (); if (comm_app && atoi (comm_app)) app_status = g_strdup("community"); diff --git a/src/manage_sql.c b/src/manage_sql.c index d488ed584..eac17f85a 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -55493,6 +55493,18 @@ delete_permissions_cache_for_user (user_t user) sql ("DELETE FROM permissions_get_tasks WHERE \"user\" = %llu;", user); } +/** + * @brief Get the community appliance value + * + * @return community appliance value or NULL if not available or on error + */ +gchar * +get_community_appliance_value () +{ + return (sql_string ("SELECT value from public.meta" + " where name = 'community_appliance';")); +} + /* Optimize. */ diff --git a/src/manage_sql.h b/src/manage_sql.h index 51233b11a..f83b8c516 100644 --- a/src/manage_sql.h +++ b/src/manage_sql.h @@ -480,4 +480,8 @@ config_family_entire_and_growing (config_t, const char*); void reports_clear_count_cache_dynamic (); + +gchar * +get_community_appliance_value (); + #endif /* not _GVMD_MANAGE_SQL_H */ From 7708246d951ebb4ecd3da8fa09df44fae3d4c45b Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Thu, 24 Feb 2022 17:07:45 +0100 Subject: [PATCH 4/4] Augmented the GMP documentation with the appliance_status element. Augmented the GMP documentation with the documentation of the element of the response of the get license command. --- src/schema_formats/XML/GMP.xml.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/schema_formats/XML/GMP.xml.in b/src/schema_formats/XML/GMP.xml.in index 5575ebf55..c5e72fabd 100644 --- a/src/schema_formats/XML/GMP.xml.in +++ b/src/schema_formats/XML/GMP.xml.in @@ -12632,6 +12632,7 @@ along with this program. If not, see . The license information status + appliance_status content @@ -12639,6 +12640,11 @@ along with this program. If not, see . Status of the license text + + appliance_status + Status of the appliance + text + content The main content of the license file @@ -12776,6 +12782,7 @@ along with this program. If not, see . active + commercial_active 4711