diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1c2e807..54297b52e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Check and create default permissions individually [#671](https://github.com/greenbone/gvmd/pull/671) - Add -f arg to sendmail call in email alert [#676](https://github.com/greenbone/gvmd/pull/676) [#678](https://github.com/greenbone/gvmd/pull/678) - Change get_tickets to use the status text for filtering. [#697](https://github.com/greenbone/gvmd/pull/697) +- Made checks to prevent duplicate user names stricter. [#708](https://github.com/greenbone/gvmd/pull/708) ### Fixed - A PostgreSQL statement order issue [#611](https://github.com/greenbone/gvmd/issues/611) has been addressed [#642](https://github.com/greenbone/gvmd/pull/642) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74edf966f..831e4a0e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,7 @@ include (CPack) ## Variables -set (GVMD_DATABASE_VERSION 217) +set (GVMD_DATABASE_VERSION 218) set (GVMD_SCAP_DATABASE_VERSION 15) diff --git a/src/manage_migrators.c b/src/manage_migrators.c index 1ee595fe0..69e7d2c35 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -1284,6 +1284,39 @@ migrate_216_to_217 () return 0; } +/** + * @brief Migrate the database from version 217 to version 218. + * + * @return 0 success, -1 error. + */ +int +migrate_217_to_218 () +{ + sql_begin_immediate (); + + /* Ensure that the database is currently version 217. */ + + if (manage_db_version () != 217) + { + sql_rollback (); + return -1; + } + + /* Update the database. */ + + /* Add an UNIQUE constraint to the name column of users */ + + sql ("ALTER TABLE users ADD UNIQUE (name);"); + + /* Set the database version to 218. */ + + set_db_version (218); + + sql_commit (); + + return 0; +} + #undef UPDATE_DASHBOARD_SETTINGS /** @@ -1307,6 +1340,7 @@ static migrator_t database_migrators[] = { {215, migrate_214_to_215}, {216, migrate_215_to_216}, {217, migrate_216_to_217}, + {218, migrate_217_to_218}, /* End marker. */ {-1, NULL}}; diff --git a/src/manage_pg.c b/src/manage_pg.c index 3bef36a63..0294cc5f8 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -2058,7 +2058,7 @@ create_tables () " (id SERIAL PRIMARY KEY," " uuid text UNIQUE NOT NULL," " owner integer REFERENCES users (id) ON DELETE RESTRICT," - " name text NOT NULL," + " name text UNIQUE NOT NULL," " comment text," " password text," " timezone text,"