File: bug-235988-better-postgres-suport.patch

package info (click to toggle)
wwwconfig-common 0.3.0
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 488 kB
  • sloc: sh: 952; makefile: 5
file content (77 lines) | stat: -rw-r--r-- 3,121 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From: Hilko Bengen <bengen@debian.org>
Date: Mon, 08 Mar 2004 18:33:15 +0100

retitle 235988 Patch for better Postgres support
tags 235988 +patch
thanks

The attached diff provides two changes to the PostgreSQL support in
wwwconfig-common:

(1) psql-createuser.sh uses the SQL command CREATE USER rather than
    modifying the pg_shadow table directly. This has the benefit of
    proper passwords being added to the record

(2) the pgsqlcmd() function provided in psql.get now knows about
    several authentication mechanisms:

    a) Connection via Unix domain socket; su postgres -c $COMMAND:
    This mechanism needs no password and works on the default
    PostgreSQL installation that is provided by Debian. Of course,
    this requires that the script is run as root or postgres (which is
    the case in maintainer scripts).

    b) Setting the PGUSER, PGPASSWORD environment variables. 

    The PostgreSQL documentation mentions that PGPASSWORD is
    considered deprecated because of security functions and advises
    that one should use a file $HOME/.pgpass. It works for now, but
    generating a directory, setting $HOME and writing a .pgpass file
    should also be possible in the script.

Cheers,
-Hilko

diff -uir wwwconfig-common-0.0.34/pgsql-createuser.sh wwwconfig-common-0.0.34.0hillu1/pgsql-createuser.sh
--- wwwconfig-common-0.0.34/pgsql-createuser.sh	2003-08-31 13:30:26.000000000 +0200
+++ wwwconfig-common-0.0.34.0hillu1/pgsql-createuser.sh	2004-03-08 16:39:56.000000000 +0100
@@ -66,7 +66,7 @@
 	# . pgsql-nextsysid.get
 	if [ "$status" = "error" ] ; then
 	    error="Unable to create user $dbuser. Something is wrong with the database."
-	elif eval $pgsqlcmd -d $systemdb -c "\"INSERT INTO pg_shadow (usename, usesysid, usecreatedb, usesuper, usecatupd, passwd) VALUES ('$dbuser', $nextsysid, '${dbusercc:-f}', 'f', '${dbusercau:-f}','$dbpass')\"" > /dev/null 2>&1; then
+	elif eval $pgsqlcmd -d $systemdb -c "\"CREATE USER $dbuser WITH SYSID $nextsysid PASSWORD '$dbpass'\"" ; > /dev/null 2>&1; then
 	    tmpuser=$(eval $pgsqlcmd -d $systemdb -q -t -A -c "\"SELECT usename FROM pg_shadow WHERE usename='$dbuser';\"")
 	    if [ "$tmpuser" = "$dbuser" ] ; then
 		log="${log}Pgsql user $dbuser created."
diff -uir wwwconfig-common-0.0.34/pgsql.get wwwconfig-common-0.0.34.0hillu1/pgsql.get
--- wwwconfig-common-0.0.34/pgsql.get	2003-08-31 13:30:26.000000000 +0200
+++ wwwconfig-common-0.0.34.0hillu1/pgsql.get	2004-03-08 18:02:18.000000000 +0100
@@ -36,7 +36,6 @@
 if [ "$dbserver" != "localhost" ] ; then
     hostopt="-h '$dbserver'"
 fi
-passopt=""
 
 pgsqlcmd()
 {
@@ -47,7 +46,18 @@
         shift
     done
 
-    su -s /bin/sh $dbadmin -c "psql $hostopt $passopt $_psql_args"
+    MYUID=`id -un`
+    if [ -z "$hostopt" -a \( "$MYUID" = root -o "$UID" = "$dbadmin" \) ] && grep -q ^"$dbadmin": /etc/passwd ; then
+	su -s /bin/sh $dbadmin -c "psql $hostopt $_psql_args"
+    else
+	export PGUSER="$dbadmin"
+	if [ ! -z "$dbadmpass" ] ; then
+	    export PGPASSWORD="$dbadmpass"
+	fi
+	eval psql $hostopt $_psql_args
+	unset PGUSER
+	unset PGPASSWORD
+    fi
 }
 
 pgsqlcmd=pgsqlcmd