file_exists() криво работает под setuid,setgid скриптами :(

rusxakep

Новичок
file_exists() криво работает под setuid,setgid скриптами :(

Попробовал решить этот вопрос с bugs.php.net (http://bugs.php.net/bug.php?id=49049) , но что-то или я тупой, или они не понимают сути, вообщем решил я его тут задать, может здесь более грамотные люди есть :)

PHP 5.2.10 и сборка от 5.2.11. И это не проблема LFS (есть такая ошибка в bugs.php.net)

Собсно вопрос - почему этот тест не проходит, кому не лень посмотрите плиз.

Запускать под linux (root), за собой все чистит:

#!/bin/sh
# Create test user
useradd -d /home/user1 -g users -m -N -p 12345 -s /bin/sh user1
chmod 0755 /home/user1

# Create wrapper with "execution bit" enabled
echo "#define REAL_PATH \"/home/user1/test.php\"
main(ac, av)
char **av;
{
execv(REAL_PATH, av);
}" > /home/user1/test.c

# Compile and set "execution bit"
cc -o /home/user1/test /home/user1/test.c
chown user1.users /home/user1/test
chmod 6755 /home/user1/test

# Create php script, who'll work under wrapper (see before)
echo "#!/usr/bin/php -q
<?php
if (!file_exists(\"/home/user1/1/2/3/4/5\")) {
if (mkdir (\"/home/user1/1/2/3/4/5\",0700,true)) echo \"MKDIR OK,
directory has been created\n\"; else echo \"MKDIR FAIL\n\";
} else {
echo \"TEST PASSED!\n\";
}
?>
" > /home/user1/test.php

chown user1.users /home/user1/test.php
chmod 755 /home/user1/test.php

# Create second test user
useradd -d /home/user2 -g users -m -N -p 12345 -s /bin/sh user2

# Test!
echo "First run, when directory doesn't exist ...";
su - user2 -c "/home/user1/test"

echo "Second (bug) run, when directory already exist and must be return
TEST PASSED! message";
su - user2 -c "/home/user1/test"

# Cleaning
userdel -f -r user2
userdel -f -r user1)
 

rusxakep

Новичок
Да - маленькая ремарка к скрипту - /home должен иметь возможность работать с suid :) Обычно эти директории имеют флажок в /etc/fstab - nosuid. Его надо убрать и перемонтировать директорию.

Можно поступить проще - переделать скрипт под любую другую директорию, не /home, а например /tmp. Как хотите.
 

MiksIr

miksir@home:~$
http://ru.php.net/manual/en/function.file-exists.php
Note: The check is done using the real UID/GID instead of the effective one.
И ноги тут растут от того, что file_exists делает access, который именно так работает (т.е. это не фича php)
man 2 access
The check is done with the process's real UID and GID, rather than with the effective IDs as is done when actually attempting an operation. This is to allow set-user-ID programs to easily determine the invoking user's authority.

Можно чекать stat-ом или конкретными производными, типа is_dir
 

rusxakep

Новичок
Автор оригинала: MiksIr
http://ru.php.net/manual/en/function.file-exists.php
Note: The check is done using the real UID/GID instead of the effective one.
И ноги тут растут от того, что file_exists делает access, который именно так работает (т.е. это не фича php)
man 2 access
The check is done with the process's real UID and GID, rather than with the effective IDs as is done when actually attempting an operation. This is to allow set-user-ID programs to easily determine the invoking user's authority.

Можно чекать stat-ом или конкретными производными, типа is_dir
Спасибо. А эти буржуям надо поотрывать кое-что, за непонятливость :)
 
Сверху