From 423c64e803518802ada5903b3432cf5a97d675e0 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Sat, 20 Dec 2014 13:44:57 +0100 Subject: [PATCH] Debian: fixes a problem when migrating to dbconfig The Bareos database maintenance scripts for the postgres backend create the Bareos database using the database administrator account and grant permission to the Bareos database user. When a Bareos update requires a database schema update, the user has to call update_bareos_tables and grant_bareos_privileges. When using dbconfig (Bareos >= 14.1), only update_bareos_tables is performed, as grant_bareos_privileges would require variable substitutions (db_name, db_user and db_password), which is not supported in dbconfig (dbc_sql_substitutions only works on installing, not on updates). Therefore it is necessary, that new tables are created as the Bareos database user, so it automatically has sufficient permissions. As the Bareos database user can not drop tables not created by himself, the drop statement must be executed as database administrator user. This patch implements this. The resuls to: Updating from Bareos < 14.1: database: owner postgres tables already existing before 14.1: owner postgres, permission to baroes tables created after 14.1: owner bareos Installing Bareos >= 14.1: database: owner bareos tables: owner bareos Fixes #380: Debian: when migrating from 13.2 to 14.2 with postgres backend, database permissions are not set correctly --- debian/bareos-database-common.config.in | 2 +- debian/bareos-database-common.postinst.in | 3 ++ debian/bareos-database-mysql.install.in | 2 +- debian/bareos-database-postgresql.install.in | 1 + debian/bareos-database-sqlite3.install.in | 2 +- platforms/debian/Makefile.in | 30 +++++++++++++++----- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/debian/bareos-database-common.config.in b/debian/bareos-database-common.config.in index d18b3fb3a18..be5245f71e9 100644 --- a/debian/bareos-database-common.config.in +++ b/debian/bareos-database-common.config.in @@ -58,7 +58,7 @@ if [ -r @scriptdir@/bareos-config-lib.sh ]; then # empty passwords require special treatment, see below bareos_database_password=`get_database_password` || true # if password is given, set authmethod to password, - # otherwise postgresql configuration will stay at default ident + # otherwise postgresql configuration will stay at default "ident" method. if [ "${bareos_database_password}" ]; then dbc_authmethod_user="password" fi diff --git a/debian/bareos-database-common.postinst.in b/debian/bareos-database-common.postinst.in index 3ae84d74e53..cd34d35b90b 100644 --- a/debian/bareos-database-common.postinst.in +++ b/debian/bareos-database-common.postinst.in @@ -46,6 +46,9 @@ if [ -r @scriptdir@/bareos-config-lib.sh ]; then # dbc_dbfile_owner: only required for sqlite3 dbc_dbfile_owner=`get_user_dir`:`get_group_dir` + # substitution is only done on installs, not on updates! + #dbc_sql_substitutions="yes" + # run dbconfig dbc_go bareos-database-common $param1 $param2 $@ diff --git a/debian/bareos-database-mysql.install.in b/debian/bareos-database-mysql.install.in index ab9b7278306..c9dc1c5c464 100644 --- a/debian/bareos-database-mysql.install.in +++ b/debian/bareos-database-mysql.install.in @@ -1,4 +1,4 @@ @backenddir@/libbareoscats-mysql*.so @scriptdir@/ddl/*/mysql*.sql /usr/share/dbconfig-common/data/bareos-database-common/install/mysql -/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/mysql/* +/usr/share/dbconfig-common/data/bareos-database-common/upgrade/mysql/* diff --git a/debian/bareos-database-postgresql.install.in b/debian/bareos-database-postgresql.install.in index b05338d1f4e..ab245cafcb7 100644 --- a/debian/bareos-database-postgresql.install.in +++ b/debian/bareos-database-postgresql.install.in @@ -2,3 +2,4 @@ @scriptdir@/ddl/*/postgresql*.sql /usr/share/dbconfig-common/data/bareos-database-common/install/pgsql /usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/pgsql/* +/usr/share/dbconfig-common/data/bareos-database-common/upgrade/pgsql/* diff --git a/debian/bareos-database-sqlite3.install.in b/debian/bareos-database-sqlite3.install.in index efc55d677d1..6dbae1dade8 100644 --- a/debian/bareos-database-sqlite3.install.in +++ b/debian/bareos-database-sqlite3.install.in @@ -1,4 +1,4 @@ @backenddir@/libbareoscats-sqlite3*.so @scriptdir@/ddl/*/sqlite3*.sql /usr/share/dbconfig-common/data/bareos-database-common/install/sqlite3 -/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/sqlite3/* +/usr/share/dbconfig-common/data/bareos-database-common/upgrade/sqlite3/* diff --git a/platforms/debian/Makefile.in b/platforms/debian/Makefile.in index 23cbc406ea2..5f79dd65d2a 100644 --- a/platforms/debian/Makefile.in +++ b/platforms/debian/Makefile.in @@ -50,26 +50,42 @@ install-dbconfig: @echo "Installing dbconfig files ..." @$(INSTALL_PROGRAM) set_dbconfig_vars.sh $(DESTDIR)/${scriptdir}/ @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/install/ + # + # mysql + # @$(SYMLINK) $(scriptdir)/ddl/creates/mysql.sql $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/install/mysql - @$(SYMLINK) $(scriptdir)/ddl/creates/postgresql.sql $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/install/pgsql - @$(SYMLINK) $(scriptdir)/ddl/creates/sqlite3.sql $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/install/sqlite3 - @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/mysql/ + @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade/mysql/ for i in $(DESTDIR)/$(scriptdir)/ddl/updates/mysql.*.sql; do \ BASENAME=`basename $$i`; \ VERSION=`echo $$BASENAME | sed -r 's/mysql\.[0-9]*_([0-9]*)\.sql/\1/'`; \ - $(SYMLINK) $(scriptdir)/ddl/updates/$$BASENAME $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/mysql/$$VERSION; \ + $(SYMLINK) $(scriptdir)/ddl/updates/$$BASENAME $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade/mysql/$$VERSION; \ done + # + # postgresql + # + @$(SYMLINK) $(scriptdir)/ddl/creates/postgresql.sql $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/install/pgsql + @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade/pgsql/ @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/pgsql/ + # if the initial install has not used dbconfig, + # the bareos database user might not have the required permissions + # to drop tables. Therefore droping tables will be done as database admin user. + # Tables are created by the bareos database user, + # because otherwise it do not receive the required permissions. for i in $(DESTDIR)/$(scriptdir)/ddl/updates/postgresql.*.sql; do \ BASENAME=`basename $$i`; \ VERSION=`echo $$BASENAME | sed -r 's/postgresql\.[0-9]*_([0-9]*)\.sql/\1/'`; \ - $(SYMLINK) $(scriptdir)/ddl/updates/$$BASENAME $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/pgsql/$$VERSION; \ + grep -E -i "^DROP|^--|^$$" $$i > $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/pgsql/$$VERSION; \ + sed 's/^DROP/-- upgrade-dbadmin: DROP/' $$i > $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade/pgsql/$$VERSION; \ done - @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/sqlite3/ + # + # sqlite + # + @$(SYMLINK) $(scriptdir)/ddl/creates/sqlite3.sql $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/install/sqlite3 + @$(MKDIR) $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade/sqlite3/ for i in $(DESTDIR)/$(scriptdir)/ddl/updates/sqlite3.*.sql; do \ BASENAME=`basename $$i`; \ VERSION=`echo $$BASENAME | sed -r 's/sqlite3\.[0-9]*_([0-9]*)\.sql/\1/'`; \ - $(SYMLINK) $(scriptdir)/ddl/updates/$$BASENAME $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade-dbadmin/sqlite3/$$VERSION; \ + $(SYMLINK) $(scriptdir)/ddl/updates/$$BASENAME $(DESTDIR)/usr/share/dbconfig-common/data/bareos-database-common/upgrade/sqlite3/$$VERSION; \ done clean: