Skip to content

Commit

Permalink
Merge pull request #1446 from greenbone/mergify/bp/gvmd-21.04/pr-1444
Browse files Browse the repository at this point in the history
Add check if PostgreSQL extensions are installed (bp #1444)
  • Loading branch information
timopollmeier authored Mar 15, 2021
2 parents a5724a4 + 967ba61 commit 8821e38
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Add standard info elem fields for NVTs in get_info [#1426](https://github.com/greenbone/gvmd/pull/1426)
- Add --ldap-debug option [#1439](https://github.com/greenbone/gvmd/pull/1439)
- Add check if PostgreSQL extensions are installed [#1444](https://github.com/greenbone/gvmd/pull/1444)

### Changed

Expand Down
45 changes: 45 additions & 0 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,51 @@ check_db_sequences ()
cleanup_iterator (&sequence_tables);
}

/**
* @brief Check if an extension is installed.
*
* @param[in] extname Name of the extension to check.
*
* @return TRUE extension is installed, FALSE otherwise.
*/
static gboolean
db_extension_installed (const char *extname)
{
if (sql_int ("SELECT count(*) FROM pg_extension WHERE extname = '%s'",
extname))
{
g_debug ("%s: Extension '%s' is installed.",
__func__, extname);
return TRUE;
}
else
{
g_message ("%s: Extension '%s' is not installed.",
__func__, extname);
return FALSE;
}
}

/**
* @brief Check if all extensions are installed.
*
* @return 0 success, 1 extension missing.
*/
int
check_db_extensions ()
{
if (db_extension_installed ("uuid-ossp")
&& db_extension_installed ("pgcrypto"))
{
g_debug ("%s: All required extensions are installed.", __func__);
return 0;
}
else
{
g_warning ("%s: A required extension is not installed.", __func__);
return 1;
}
}

/* SecInfo. */

Expand Down
5 changes: 5 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ create_tables ();
void
check_db_sequences ();

int
check_db_extensions ();

static int
check_db_encryption_key ();

Expand Down Expand Up @@ -16062,6 +16065,8 @@ check_db (int check_encryption_key)
* process accessing the db. Nothing else should be accessing the db, access
* should always go through Manager. */
sql_begin_immediate ();
if (check_db_extensions ())
goto fail;
create_tables ();
check_db_sequences ();
set_db_version (GVMD_DATABASE_VERSION);
Expand Down

0 comments on commit 8821e38

Please sign in to comment.