Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14297 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29454 invoked by uid 1010); 6 Jan 2005 21:45:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 20557 invoked from network); 6 Jan 2005 21:41:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2005 21:41:12 -0000 X-Host-Fingerprint: 193.45.238.241 novell.stoldgods.nu Linux 2.5 (sometimes 2.4) (4) Received: from ([193.45.238.241:34450] helo=novell.stoldgods.nu) by pb1.pair.com (ecelerity HEAD (r4049:4050)) with SMTP id 1F/47-30894-770BDD14 for ; Thu, 06 Jan 2005 16:41:11 -0500 Received: from localhost (localhost [127.0.0.1]) by novell.stoldgods.nu (Postfix) with ESMTP id 74B82325F for ; Thu, 6 Jan 2005 22:41:05 +0100 (CET) Received: from novell.stoldgods.nu ([127.0.0.1]) by localhost (netsrv2 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25018-04 for ; Thu, 6 Jan 2005 22:40:55 +0100 (CET) Received: from novell.stoldgods.nu (unknown [10.0.1.254]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by novell.stoldgods.nu (Postfix) with ESMTP id A48852E6F for ; Thu, 6 Jan 2005 22:40:52 +0100 (CET) To: internals@lists.php.net Date: Thu, 6 Jan 2005 22:40:35 +0100 User-Agent: KMail/1.7.1 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_UBb3B2OomzbBmAD" Message-ID: <200501062240.36242.magnus@php.net> Subject: [PATCH] 3rd Resend: Add posix_access() FR #14924 From: magnus@php.net (Magnus =?iso-8859-1?q?M=E4=E4tt=E4?=) --Boundary-00=_UBb3B2OomzbBmAD Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, This patch adds posix_access() to the posix extension. access(2) will report correct permission on systems using ACL for example. This is useful when running, for example, SELinux. I've updated it to include both open_basedir and safe_mode checks. I'll go ahead and commit it if noone have any complains. Will close bugs: #29615 #14924 /Magnus -- Bill Dickey is learning me his experience. -- Yogi Berra in his rookie season. --Boundary-00=_UBb3B2OomzbBmAD Content-Type: text/x-diff; charset="us-ascii"; name="posix_access.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="posix_access.patch" Index: php_posix.h =================================================================== RCS file: /repository/php-src/ext/posix/php_posix.h,v retrieving revision 1.14 diff -u -r1.14 php_posix.h --- php_posix.h 8 Jan 2004 17:32:41 -0000 1.14 +++ php_posix.h 4 Jan 2005 20:27:44 -0000 @@ -90,6 +90,9 @@ PHP_FUNCTION(posix_mkfifo); #endif +/* POSIX.1, 5.6 */ +PHP_FUNCTION(posix_access); + /* POSIX.1, 9.2 */ PHP_FUNCTION(posix_getgrnam); PHP_FUNCTION(posix_getgrgid); Index: posix.c =================================================================== RCS file: /repository/php-src/ext/posix/posix.c,v retrieving revision 1.60 diff -u -r1.60 posix.c --- posix.c 18 Apr 2004 21:49:10 -0000 1.60 +++ posix.c 4 Jan 2005 20:27:45 -0000 @@ -108,6 +108,8 @@ PHP_FE(posix_mkfifo, NULL) #endif + /* POSIX.1, 5.6 */ + PHP_FE(posix_access, NULL) /* POSIX.1, 9.2 */ PHP_FE(posix_getgrnam, NULL) PHP_FE(posix_getgrgid, NULL) @@ -146,6 +148,10 @@ static PHP_MINIT_FUNCTION(posix) { ZEND_INIT_MODULE_GLOBALS(posix, php_posix_init_globals, NULL); + REGISTER_LONG_CONSTANT("POSIX_F_OK", F_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_X_OK", X_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_W_OK", W_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_R_OK", R_OK, CONST_CS | CONST_PERSISTENT); return SUCCESS; } /* }}} */ @@ -638,15 +644,47 @@ POSIX.1, 5.5.1 unlink() POSIX.1, 5.5.2 rmdir() POSIX.1, 5.5.3 rename() - POSIX.1, 5.6.x stat(), access(), chmod(), utime() - already supported by PHP (access() not supported, because it is - braindead and dangerous and gives outdated results). + POSIX.1, 5.6.x stat(), chmod(), utime() already supported by PHP. +*/ + +/* {{{ proto bool posix_access(string file [, int mode]) + Determine accessibility of a file (POSIX.1 5.6.3) */ +PHP_FUNCTION(posix_access) +{ + long mode = 0; + int filename_len, ret; + char *filename, *path; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &mode) == FAILURE) + return; + + path = expand_filepath(filename, NULL TSRMLS_CC); + + if (php_check_open_basedir_ex(path, 0 TSRMLS_CC) || + (PG(safe_mode) && (!php_checkuid_ex(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR, CHECKUID_NO_ERRORS)))) { + efree(path); + POSIX_G(last_error) = EPERM; + RETURN_FALSE; + } + + ret = access(path, mode); + efree(path); + + if (ret) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ +/* POSIX.1, 6.x most I/O functions already supported by PHP. POSIX.1, 7.x tty functions, TODO POSIX.1, 8.x interactions with other C language functions - POSIX.1, 9.x system database access - */ + POSIX.1, 9.x system database access +*/ /* {{{ proto array posix_getgrnam(string groupname) Group database access (POSIX.1, 9.2.1) */ --Boundary-00=_UBb3B2OomzbBmAD--