From 5b7e88dbe0ad700e2994989c7b01f08f9e6b31d4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 22 Oct 2004 00:24:27 +0000 Subject: [PATCH] Prevent pg_ctl from being run as root. Since it uses configuration files owned by postgres, doing "pg_ctl start" as root could allow a privilege escalation attack, as pointed out by iDEFENSE. Of course the postmaster would fail, but we ought to fail a little sooner to protect sysadmins unfamiliar with Postgres. The chosen fix is to disable root use of pg_ctl in all cases, just to be confident there are no other holes. --- src/bin/pg_ctl/pg_ctl.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_ctl/pg_ctl.sh b/src/bin/pg_ctl/pg_ctl.sh index c0bffd44ee0..72fe2928735 100755 --- a/src/bin/pg_ctl/pg_ctl.sh +++ b/src/bin/pg_ctl/pg_ctl.sh @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.36.4.1 2004/08/28 21:10:00 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.36.4.2 2004/10/22 00:24:27 tgl Exp $ # #------------------------------------------------------------------------- @@ -111,6 +111,14 @@ fi po_path="$PGPATH/postmaster" +if [ `$PGPATH/pg_id -u` -eq 0 ] +then + echo "$CMDNAME: cannot be run as root" 1>&2 + echo "Please log in (using, e.g., \"su\") as the (unprivileged) user that will" 1>&2 + echo "own the server process." 1>&2 + exit 1 +fi + wait= wait_seconds=60 logfile= -- 2.39.5