Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --get-roles #992

Merged
merged 3 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
35 changes: 35 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down