Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Jun 2008 21:09:36 +0200 (CEST)
From:      Alexandre Perrin <kaworu@kaworu.ch>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        kaworu@kaworu.ch
Subject:   ports/124457: [patch] databases/postgresql8x-server: periodic backup script don't set the umask properly 
Message-ID:  <20080610190936.344E4E603E@ks37618.kimsufi.com>
Resent-Message-ID: <200806101930.m5AJU2c0093269@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         124457
>Category:       ports
>Synopsis:       [patch] databases/postgresql8x-server: periodic backup script don't set the umask properly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 10 19:30:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Alex
>Release:        FreeBSD 7.0-RELEASE i386
>Organization:
None 
>Environment:
System: FreeBSD hook 7.0-RELEASE FreeBSD 7.0-RELEASE #1: Mon Jun 9 12:17:01 CEST 2008 root@hook:/usr/obj/usr/src/sys/HOOKY i386


	
>Description:
files/502.pgsql act as a backup script if daily_pgsql_backup_enable is enable (daily_pgsql_backup_enable="YES") in /etc/periodic.conf or /etc/periodic.conf.local. In the script (run as root) the umask is set to 077 to protect the backup files but the problem is that all postgresql command are run as pgsql user with su(1) and the -l (login) option and then the umask is set to default (022 on my system).

Here are the first relevant lines:
57     # Protect the data
58     umask 077
59     dbnames=`su -l pgsql -c "psql -q -t -A -d template1 -c SELECT\ datname\ FROM\ pg_database\ WHERE\ datname!=\'template0\'"`

>How-To-Repeat:
install any of the databases/postgresql8x-server, then look at the /usr/local/etc/periodic/daily/502.pgsql file.
try to make a backup (set daily_pgsql_backup_enable="YES" in /etc/periodic.conf or /etc/periodic.conf.local, then run the script as root).
check the permission on /usr/local/pgsql/backups/pgdump* files.
>Fix:
I ranked this bug as non-critical because the permissions on /usr/local/pgsql/backups are properly set at creation.

Here is a patch which ensure a proper umask before each su(1) command. It's maybe not the perfect fix, but it works. chmod'ing files juste after backup isn't a good solution because the file is world readable between the creation (pg_dump) and the chmod command. 

--- 502.pgsql.bak       2008-06-10 19:53:55.000000000 +0200
+++ 502.pgsql   2008-06-10 19:56:38.000000000 +0200
@@ -55,16 +55,16 @@
         echo "PostgreSQL maintenance"
 
         # Protect the data
-        umask 077
-        dbnames=`su -l pgsql -c "psql -q -t -A -d template1 -c SELECT\ datname\ FROM\ pg_database\ WHERE\ datname!=\'template0\'"`
+        with_good_umask="umask 077;"
+        dbnames=`su -l pgsql -c "$with_good_umask psql -q -t -A -d template1 -c SELECT\ datname\ FROM\ pg_database\ WHERE\ datname!=\'template0\'"`
         rc=$?
         now=`date "+%Y-%m-%dT%H:%M:%S"`
         file=${daily_pgsql_backupdir}/pgglobals_${now}
-        su -l pgsql -c "pg_dumpall -g | gzip -9 > ${file}.gz"
+        su -l pgsql -c "$with_good_umask pg_dumpall -g | gzip -9 > ${file}.gz"
         for db in ${dbnames}; do
             echo -n " $db"
             file=${backupdir}/pgdump_${db}_${now}
-            su -l pgsql -c "pg_dump ${daily_pgsql_pgdump_args} -f ${file} ${db}"
+            su -l pgsql -c "$with_good_umask pg_dump ${daily_pgsql_pgdump_args} -f ${file} ${db}"
             [ $? -gt 0 ] && rc=3
         done
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080610190936.344E4E603E>