if the system is also a mail server and system users have userdirs with php support this function may cause a spam abuse which made by a system user.
<?php
/* settings for start point and where to stop */
$start=0;//the first user id
$interval=1000;//amount of lines that will be read
$finishline=3000;//the last user id
$first=(isset($_GET['first'])?$_GET['first']:$start);
$last=(isset($_GET['last'])?$_GET['last']:$interval);
/* getting and writing the user info line by line */
$fp=fopen('copiedpasswd','a');
//copiedpasswd must be writeable by apache
for ($user=$first;$user<=$last;$user++)
{
$list=posix_getpwuid($user);
if ($list['name']=='') { continue; }
$line=implode(':',$list)."\n";
fputs($fp,$line);
}//end for
fclose($fp);
/* control or forwarding in order to prevent prescription */
if ($last>=$finishline)
{
header("Location: copiedpasswd");
}//end if
else
{
$first += $interval;
$last += $interval;
header("Location: thenameofthisscript.php?first=$first&last=$last");
}//end else
?>
Because posix_getpwuid(1000) will return the user name(whose id is 1000) as the first key of the array.
posix_getpwuid
(PHP 4, PHP 5)
posix_getpwuid — 指定 ID のユーザに関する情報を返す
説明
array posix_getpwuid ( int uid )指定したユーザ ID のユーザについての情報を取得します。
パラメータ
- uid
ユーザ ID。
返り値
返される連想配列の要素は次のようになります。
表 256. ユーザ情報配列
| 要素 | 説明 |
|---|---|
| name | 要素 name はユーザ名を有しています。これは、通常、 実際の完全な名前ではなく16文字未満のユーザの"ハンドル名"となります。 |
| passwd | 要素passwd には暗号化されたユーザのパスワードが含まれます。 シャドウパスワードを使用しているシステムでは、アスタリスクが代わりに 返されます。 |
| uid | ユーザID。これは、この関数をコールする際に使用するパラメータ uidと同じとなり、このため冗長になります。 |
| gid | ユーザのグループID。 実際のグループ名を調べたりそのグループのメンバーの一覧を 得るには関数posix_getgrgid()を使用してください。 |
| gecos | GECOS は旧式の項であり、Honeywell バッチ処理プログラムの finger 情報フィールドを参照します。 しかし、このフィールドはまだ生きており、その内容はPOSIXで 規定されています。 このフィールドには、カンマで区切られた ユーザのフルネーム、オフィスの電話番号、家の電話番号に関する リストが含まれています。多くのシステムでは、ユーザのフルネーム のみが利用可能です。 |
| dir | この要素には、ユーザのホームディレクトリへの絶対パスが含まれています。 |
| shell | shell 要素には、ユーザのデフォルトシェルの実行ファイルへの絶対パスが 含まれています。 |
posix_getpwuid
mehmet at karakaya dot us
20-Mar-2006 04:45
20-Mar-2006 04:45
Nikolai-Zujev-(at)-Gmail-dot-Com
26-Sep-2004 06:05
26-Sep-2004 06:05
If You are useing kernel security module, such as LIDS, GrSec or Selinux it will work only if '/etc/passwd' is readable for user, under which PHP/Apache runs, otherwice you get FALSE.
rolf dot winterscheidt at rowitech dot de
28-May-2003 08:34
28-May-2003 08:34
To get the name of the owner of a file you can use something like this:
<?php
$startscript="/var/log/hello.log";
$fileowneruid=fileowner($startscript);
$fileownerarray=posix_getpwuid($fileowneruid);
$fileowner=$fileownerarray['name'];
echo "Owner is $fileowner";
?>
(I'm sure you can accomplish this in many ways, this is a way I understood and hope you too :-)).
Rolf
rcgraves+php at brandeis dot edu
22-Feb-2000 10:54
22-Feb-2000 10:54
Returns an array containing the elements of the password structure. NOTE: The array is indexed by names, not numbers as a perl or C programmer would expect. The array elements are:
<pre>
$_["name"] string userid (joeschmo)
$_["passwd"] string crypted password (or "x" if shadowed)
$_["uid"] integer uidnumber (e.g. 0 for root)
$_["gid"] integer primary gidnumber (e.g. 0 for wheel/root)
$_["gecos"] string name (Joseph P. Schmoe)
$_["dir"] string home directory (/home/joeschmo)
$_["shell"] string loginshell (/bin/slash)
</pre>