[PHP-users 2671] Re: PostgreSQLのパスワードに関して

TATSUYA php-users@php.gr.jp
Fri, 12 Oct 2001 23:37:31 +0900


>From   「"BosProject T.Takeuchi" <webmaster@bos-project.com>」 さんの
Subject「[PHP-users 2670] Re: PostgreSQLのパスワードに関して」 への返信です。

竹内さん。返答ありがとうございます。
TATSUYA@S-Lines.netです。

>  apacheのsuexec機能を使って、phpスクリプト自体には
> パスワードを書かず、別ファイルでパスワードを宣言して、
> パスワードファイルの権限を600にするというものです。
>  httpd.confで適切にUserやGroupを設定すれば、他の
> ユーザーからパスワードを覗かれることはなくなると
> 思います。
  apacheのsuexeは有効にしてあります。

  そして、メインのphpスクリプトは
--- main.php
<html>
<head><title>PHP and PostgreSQL</title></head>
<body>
<center>
<h2>E-Mail List</h2>
<table border=2>
<tr><th>name</th><th>email</th></tr>
<?php
        $con = pg_connect("dbname=emaillist user=www password=******");
        $rtn = pg_exec($con, "select * from ELIST");
        $num = pg_numrows($rtn);
        for($i=0; $i<$num; $i++){
                $name  = pg_result($rtn, $i, 0);
                $email = pg_result($rtn, $i, 1);
                print("<tr><td>$name</td><td>$email</td></tr>");
        }
        pg_close($con);
?>
</table>
</center>
</body>
</html>
---
です。

そして、その後考えたのが別ファイルにする方法で、
--- main.php
<?
include('pass.inc');
?>
<html>
<head><title>PHP and PostgreSQL</title></head>
<body>
<center>
<h2>E-Mail List</h2>
<table border=2>
<tr><th>name</th><th>email</th></tr>
<?php
        $con = pg_connect("dbname=emaillist user=www password=$pass");
        $rtn = pg_exec($con, "select * from ELIST");
        $num = pg_numrows($rtn);
        for($i=0; $i<$num; $i++){
                $name  = pg_result($rtn, $i, 0);
                $email = pg_result($rtn, $i, 1);
                print("<tr><td>$name</td><td>$email</td></tr>");
        }
        pg_close($con);
?>
</table>
</center>
</body>
</html>
---
--- pass.inc
<?
$pass = "*****";
?>
---

  上のようにして main.php にアクセスすると
Warning: Failed opening 'pass.inc' for inclusion (include_path='.:/usr/local/lib/php') in /usr/home/www/htdocs/main.php on line 2
  となってしまい、実行できません。

  Suexecが有効になってないかとも思ったのですが、CGIは
 744や700などでも実行できるので、Suexecは問題ないと考えています。

  これはなぜなのでしょうか?

  原因がわかれば教えていただきたいです。よろしくお願いします。

---
 TATSUYA   E-Mail : tatsuya@ps.sakura.ne.jp
           W e b  : http://TatsuyaUeda.com/
           Phone  : tatsuya_ueda@jp-c.ne.jp
 Flet's ADSL + FreeBSD HomeServer -> http://www.S-Lines.net/