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 user parameter for db connection #1327

Merged
merged 2 commits into from
Oct 15, 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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [21.4] (unreleased)

### Added
- Parameter `--db-user` to set a database user [#1327](https://github.com/greenbone/gvmd/pull/1327)

### Changed
- Move EXE credential generation to a Python script [#1260](https://github.com/greenbone/gvmd/pull/1260) [#1262](https://github.com/greenbone/gvmd/pull/1262)
- Clarify documentation for --scan-host parameter [#1277](https://github.com/greenbone/gvmd/pull/1277)
Expand Down
6 changes: 5 additions & 1 deletion src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static gnutls_certificate_credentials_t client_credentials;
/**
* @brief Database connection info.
*/
static db_conn_info_t database = { NULL, NULL, NULL };
static db_conn_info_t database = { NULL, NULL, NULL, NULL };

/**
* @brief Is this process parent or child?
Expand Down Expand Up @@ -1764,6 +1764,10 @@ gvmd (int argc, char** argv)
&(database.port),
"Use <port> as database port or socket extension for PostgreSQL.",
"<port>" },
{ "db-user", '\0', 0, G_OPTION_ARG_STRING,
&(database.user),
"Use <user> as database user.",
"<user>" },
{ "decrypt-all-credentials", '\0', G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_NONE,
&decrypt_all_credentials,
Expand Down
1 change: 1 addition & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef struct {
gchar *name; ///< The database name
gchar *host; ///< The database host or socket directory
gchar *port; ///< The database port or socket file extension
gchar *user; ///< The database user name
} db_conn_info_t;

/**
Expand Down
1 change: 1 addition & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -16361,6 +16361,7 @@ init_manage_internal (GSList *log_config,
gvmd_db_conn_info.name = database->name ? g_strdup (database->name) : NULL;
gvmd_db_conn_info.host = database->host ? g_strdup (database->host) : NULL;
gvmd_db_conn_info.port = database->port ? g_strdup (database->port) : NULL;
gvmd_db_conn_info.user = database->user ? g_strdup (database->user) : NULL;

if (fork_connection)
manage_fork_connection = fork_connection;
Expand Down
2 changes: 2 additions & 0 deletions src/sql_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,14 @@ sql_open (const db_conn_info_t *database)
conn_info = g_strdup_printf ("dbname='%s'"
" host='%s'"
" port='%s'"
" user='%s'"
" application_name='%s'",
database->name
? database->name
: sql_default_database (),
database->host ? database->host : "",
database->port ? database->port : "",
database->user ? database->user : "",
"gvmd");
conn = PQconnectStart (conn_info);
g_free (conn_info);
Expand Down