diff --git a/CHANGELOG.md b/CHANGELOG.md index 7090e8477..c778b1217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Automatically load predefined configs from the feed [#931](https://github.com/greenbone/gvmd/pull/931) [#933](https://github.com/greenbone/gvmd/pull/933) [#934](https://github.com/greenbone/gvmd/pull/934) - Automatically load predefined port lists from the feed [#950](https://github.com/greenbone/gvmd/pull/950) [#952](https://github.com/greenbone/gvmd/pull/952) - Automatically load predefined report formats from the feed [#968](https://github.com/greenbone/gvmd/pull/968) [#970](https://github.com/greenbone/gvmd/pull/970) -- Print UUIDs in --get-users when --verbose given [#991](https://github.com/greenbone/gvmd/pull/968) [#970](https://github.com/greenbone/gvmd/pull/991) +- Print UUIDs in --get-users when --verbose given [#991](https://github.com/greenbone/gvmd/pull/991) +- Add --get-roles [#992](https://github.com/greenbone/gvmd/pull/992) ### Changed - Update SCAP and CERT feed info in sync scripts [#810](https://github.com/greenbone/gvmd/pull/810) diff --git a/src/gvmd.c b/src/gvmd.c index 34f7d8455..dd4efb5fd 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -1589,6 +1589,7 @@ gvmd (int argc, char** argv) static gboolean decrypt_all_credentials = FALSE; static gboolean disable_password_policy = FALSE; static gboolean disable_scheduling = FALSE; + static gboolean get_roles = FALSE; static gboolean get_users = FALSE; static gboolean get_scanners = FALSE; static gboolean foreground = FALSE; @@ -1705,6 +1706,10 @@ gvmd (int argc, char** argv) &foreground, "Run in foreground.", NULL }, + { "get-roles", '\0', 0, G_OPTION_ARG_NONE, + &get_roles, + "List roles and exit.", + NULL }, { "get-scanners", '\0', 0, G_OPTION_ARG_NONE, &get_scanners, "List scanners and exit.", @@ -2387,6 +2392,22 @@ gvmd (int argc, char** argv) return EXIT_SUCCESS; } + if (get_roles) + { + int ret; + + proctitle_set ("gvmd: Getting roles"); + + if (option_lock (&lockfile_checking)) + return EXIT_FAILURE; + + ret = manage_get_roles (log_config, database, verbose); + log_config_free (); + if (ret) + return EXIT_FAILURE; + return EXIT_SUCCESS; + } + if (get_users) { int ret; diff --git a/src/manage.h b/src/manage.h index 04ee269e7..e6c7d96cf 100644 --- a/src/manage.h +++ b/src/manage.h @@ -2885,6 +2885,9 @@ delete_permissions_cache_for_user (user_t); /* Roles. */ +int +manage_get_roles (GSList *, const gchar *, int); + int init_role_iterator (iterator_t *, const get_data_t *); diff --git a/src/manage_sql.c b/src/manage_sql.c index 51b2eba68..bab5b06fb 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -45331,6 +45331,41 @@ modify_permission (const char *permission_id, const char *name_arg, /* Roles. */ +/** + * @brief List roles. + * + * @param[in] log_config Log configuration. + * @param[in] database Location of manage database. + * @param[in] verbose Whether to print UUID. + * + * @return 0 success, -1 error. + */ +int +manage_get_roles (GSList *log_config, const gchar *database, int verbose) +{ + iterator_t roles; + int ret; + + g_info (" Getting roles."); + + ret = manage_option_setup (log_config, database); + if (ret) + return ret; + + init_iterator (&roles, "SELECT name, uuid FROM roles;"); + while (next (&roles)) + if (verbose) + printf ("%s %s\n", iterator_string (&roles, 0), iterator_string (&roles, 1)); + else + printf ("%s\n", iterator_string (&roles, 0)); + + cleanup_iterator (&roles); + + manage_option_cleanup (); + + return 0; +} + /** * @brief Create a role from an existing role. *