Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 1CE964758D7 for ; Sun, 19 May 2002 08:45:00 -0400 (EDT) Received: from localhost (pD9E4FF46.dip.t-dialin.net [217.228.255.70]) by postgresql.org (Postfix) with ESMTP id 19602475473 for ; Sun, 19 May 2002 08:44:59 -0400 (EDT) Received: from eckhard by localhost with local (Exim 3.35 #1 (Debian)) id 179Q3Z-000355-00 for ; Sun, 19 May 2002 14:45:01 +0200 Date: Sun, 19 May 2002 14:45:01 +0200 From: Eckhard Hoeffner To: pgsql-php@postgresql.org Subject: Re: php-postgres-apache Security Message-ID: <20020519124501.GB11674@fifoost.org> Mail-Followup-To: pgsql-php@postgresql.org References: <20020519114355.66376.qmail@web12606.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20020519114355.66376.qmail@web12606.mail.yahoo.com> User-Agent: Mutt/1.3.28i X-Archive-Number: 200205/71 X-Sequence-Number: 1203 * ameen eetemadi [19 05 02 13:43]: >I am writing php on a >server(OS:linux,WebServer:apache) that other users can >write cgi and have shell on it . >I want to connect to a postgres server in my php file >without asking username and password ! >then I must write the username and password in this >file . >Then other users can read it and drop my database . > >can I connect to the postgres through .php file >without a security bog? I think there are two possible solutions:=20 I As far as I know the php-scripts are running under the User-ID of the web server, for example "www-data" if you are using Debian.=20 So you can do the following:=20 1. Create a directory: mkdir /*/file/. 2. Write a file which includes for example just: =20=20 then: =3D> chmod to 400 =3D> chown to www-data 3. If you want to connect to the database, use in the php-script require("/path/to/the/file/filename"); 4. Make shure nobody else can get the user www-data. II You must limit the rights of the users for the db, for example make shure, that you have something like local all password host public_db 127.0.0.1 255.255.255.0 password local my_db reject host my_db 192.168.1.12 255.255.255.0 crypt =20 in your pg_hba.conf. =20=20=20 --=20 --//--\\-- Eckhard Hoeffner e-hoeffner@fifoost.org Tal 44=20 D-80331 M=FCnchen