File: bug-263813-better-postgres-support.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 (185 lines) | stat: -rw-r--r-- 6,964 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
From: Hilko Bengen <bengen@debian.org>

diff -uir /usr/share/wwwconfig-common/pgsql-createdb.sh 0.0.36hillu1/pgsql-createdb.sh
--- /usr/share/wwwconfig-common/pgsql-createdb.sh	2004-07-22 23:10:04.000000000 +0200
+++ 0.0.36hillu1/pgsql-createdb.sh	2004-08-05 22:16:27.000000000 +0200
@@ -11,7 +11,8 @@
 # Needs:	$dbname    - the database that user should have access to.
 #		$dbserver  - the server to connect to.
 #		$dbadmin   - the administrator name.
-#		$dbadmpass - the administrator password (not supported)
+#		$dbadmpass - the administrator password
+#		$dbuser    - the database's owner if set
 #		which
 #		pgsql
 #		/usr/share/wwwconfig-common/pgsql.get
@@ -24,6 +25,8 @@
 
 . /usr/share/wwwconfig-common/pgsql.get
 
+use_dbuser=false
+
 if [ -z "$dbname" ] ; then
     error="No database name specified. Have to know the name to create it."
 elif [ -z "$dbserver" ] ; then
@@ -42,8 +45,12 @@
 	log="${log}Database $dbname already exists."
 	status=nothing
     else
+	my_dbuser="postgres"
+	if [ ! -z "$dbuser" ]; then 
+	    my_dbuser="$dbuser"
+	fi
 	log="${log}Creating database $dbname."
-	if eval $pgsqlcmd -d $systemdb -c "\"CREATE DATABASE $dbname;\"" > /dev/null 2>&1 ; then
+	if eval $pgsqlcmd -d $systemdb -c "\"CREATE DATABASE $dbname WITH OWNER $my_dbuser;\"" > /dev/null 2>&1 ; then
 	    if ! eval $pgsqlcmd -d $dbname -c "\"\"" > /dev/null 2>&1 ; then
 		error="Database $dbname NOT successfully created. You have to do it manually."
 	    else
diff -uir /usr/share/wwwconfig-common/pgsql-createuser.sh 0.0.36hillu1/pgsql-createuser.sh
--- /usr/share/wwwconfig-common/pgsql-createuser.sh	2004-07-22 23:10:04.000000000 +0200
+++ 0.0.36hillu1/pgsql-createuser.sh	2004-08-05 22:16:27.000000000 +0200
@@ -12,10 +12,6 @@
 #		Fixing postgres issues. Indenting correct.
 #		Fixed insert command, removed '' which should not be there.
 #		Removed need for $dbadmin.
-#	20040705 Hilko Bengen <bengen@debian.org>
-#		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.
 # Needs:	$dbuser    - the user name to create (or replace).
 #		$dbname    - the database that user should have access to.
 #		$dbpass    - the password to use.
@@ -33,6 +29,9 @@
 error=""
 
 . /usr/share/wwwconfig-common/pgsql.get
+
+use_dbuser=false
+
 #. pgsql.get
 if [ -z "$dbuser" ] ; then
     error="No database user specified. Can not create it if it does not exist."
@@ -54,10 +53,7 @@
 	# . pgsql-userpass.get
 	status=nothing
 	if [ "$userpass" != "$dbpass" ] ; then
-	    if eval $pgsqlcmd -d $systemdb -c "\"
-	UPDATE pg_shadow
-	SET passwd='$dbpass'
-	WHERE usename='$dbuser'\"" > /dev/null 2>&1 ; then
+	    if eval $pgsqlcmd -d $systemdb -c "\"ALTER USER $dbuser WITH PASSWORD '$dbpass'\"" > /dev/null 2>&1 ; then
 		log="${log}Password changed for pgsql user $dbuser."
 		status=changepass
 	    else
@@ -71,7 +67,7 @@
 	if [ "$status" = "error" ] ; then
 	    error="Unable to create user $dbuser. Something is wrong with the database."
 	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';\"")
+	    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."
 		status=create
diff -uir /usr/share/wwwconfig-common/pgsql-dropdb.sh 0.0.36hillu1/pgsql-dropdb.sh
--- /usr/share/wwwconfig-common/pgsql-dropdb.sh	2004-07-22 23:10:04.000000000 +0200
+++ 0.0.36hillu1/pgsql-dropdb.sh	2004-08-05 22:16:27.000000000 +0200
@@ -20,6 +20,8 @@
 
 . /usr/share/wwwconfig-common/pgsql.get
 
+use_dbuser=false
+
 if [ -z "$dbname" ] ; then
     error="No database name specified. Have to know the name to create it."
 elif [ -z "$dbserver" ] ; then
diff -uir /usr/share/wwwconfig-common/pgsql-dropuser.sh 0.0.36hillu1/pgsql-dropuser.sh
--- /usr/share/wwwconfig-common/pgsql-dropuser.sh	2004-07-22 23:10:04.000000000 +0200
+++ 0.0.36hillu1/pgsql-dropuser.sh	2004-08-05 22:15:41.000000000 +0200
@@ -38,15 +38,13 @@
 else
     TMPU=$(eval $pgsqlcmd -d $systemdb -q -t -A -c "\"SELECT usename FROM pg_shadow WHERE usename='$dbuser';\"")
     if [ "$TMPU" = "$dbuser" ] ; then
-	if eval $pgsqlcmd -q -d $systemdb -c "\"
-	DELETE FROM pg_shadow
-	WHERE usename='$dbuser';\"" ; then
+	if eval $pgsqlcmd -q -d $systemdb -c "\"DROP USER $dbuser;\"" ; then
 	    TMPU=$(eval $pgsqlcmd -d $systemdb -q -t -A -c "\"SELECT usename FROM pg_shadow WHERE usename='$dbuser';\"")
 	    if [ -z "$TMPU" ] ; then
-		log="${log}User $dbuser droped."
+		log="${log}User $dbuser dropped."
 		status=drop
 	    else
-		error="User $dbuser NOT successfully droped. You have to do it manually."
+		error="User $dbuser NOT successfully dropped. You have to do it manually."
 	    fi
 	else
 	    error="Unable to run the drop user script."
diff -uir /usr/share/wwwconfig-common/pgsql.get 0.0.36hillu1/pgsql.get
--- /usr/share/wwwconfig-common/pgsql.get	2004-07-22 23:10:04.000000000 +0200
+++ 0.0.36hillu1/pgsql.get	2004-08-05 22:13:18.000000000 +0200
@@ -18,9 +18,6 @@
 #		 Arndt Sch´┐Żnewald <arndt@lin02384n012.mc.schoenewald.de>
 #		Minor fix from Arndt Sch´┐Żnewald that fix problem if someone
 #		use a non-sh compatible shell.
-#	20040705 Hilko Bengen <bengen@debian.org>
-#		The pgsqlcmd() function provided in psql.get now knows about
-#		several authentication mechanisms:
 # Needs:	$dbserver  - the server to connect to (defaults to localhost).
 #		$dbadmin   - the administrator name (defaults to postgres).
 #		$dbadmpass - the administrator password (not supported).
@@ -40,8 +37,18 @@
     hostopt="-h '$dbserver'"
 fi
 
+use_dbuser=true
+
 pgsqlcmd()
 {
+    if [ "$use_dbuser" = true ]; then
+	local user="$dbuser"
+	local pass="$dbpass"
+    else
+	local user="$dbadmin"
+	local pass="$dbadmpass"
+    fi
+
     _psql_args=
     while [ $# -gt 0 ]
     do
@@ -50,16 +57,27 @@
     done
 
     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"
+    if [ -z "$hostopt" -a \( "$MYUID" = root -o "$UID" = "$user" \) ] && grep -q ^"$user": /etc/passwd ; then
+	su -s /bin/sh $user -c "psql $hostopt $_psql_args"
     else
-	export PGUSER="$dbadmin"
-	if [ ! -z "$dbadmpass" ] ; then
-	    export PGPASSWORD="$dbadmpass"
+	OLDHOME=$HOME
+	HOME=`mktemp -d`
+	if [ $? -ne 0 ]; then
+	    exit 1
 	fi
-	eval psql $hostopt $_psql_args
-	unset PGUSER
-	unset PGPASSWORD
+	export HOME
+
+	if [ ! -z "$pass" ] ; then
+	    OLDUMASK=`umask`
+	    umask 077
+	    echo "*:*:*:$user:$pass" > $HOME/.pgpass
+	    umask $OLDUMASK
+	fi
+
+	eval psql -U "$user" $hostopt $_psql_args
+
+	rm -rf "$HOME"
+	HOME=$OLDHOME
     fi
 }