1999-04-17 00:37:12 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 08:18:22 +00:00
|
|
|
| PHP Version 5 |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2005-08-03 14:08:58 +00:00
|
|
|
| Copyright (c) 1997-2005 The PHP Group |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2003-06-10 20:04:29 +00:00
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
1999-07-16 13:13:16 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 08:29:35 +00:00
|
|
|
| Author: Jim Winstead <jimw@php.net> |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-07-24 01:40:02 +00:00
|
|
|
*/
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
/* $Id$ */
|
1999-04-23 20:06:01 +00:00
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "php.h"
|
|
|
|
#include "pageinfo.h"
|
1999-04-26 17:26:37 +00:00
|
|
|
#include "SAPI.h"
|
1999-04-17 00:37:12 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#if HAVE_PWD_H
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "win32/pwd.h"
|
|
|
|
#else
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2002-08-16 15:04:00 +00:00
|
|
|
#if HAVE_GRP_H
|
|
|
|
# ifdef PHP_WIN32
|
|
|
|
# include "win32/grp.h"
|
|
|
|
# else
|
|
|
|
# include <grp.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef PHP_WIN32
|
|
|
|
#undef getgid
|
|
|
|
#define getgroups(a, b) 0
|
|
|
|
#define getgid() 1
|
|
|
|
#define getuid() 1
|
|
|
|
#endif
|
1999-04-17 00:37:12 +00:00
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/stat.h>
|
2002-08-16 12:47:56 +00:00
|
|
|
#include <sys/types.h>
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 00:37:12 +00:00
|
|
|
#include <process.h>
|
|
|
|
#endif
|
|
|
|
|
1999-12-12 16:14:40 +00:00
|
|
|
#include "ext/standard/basic_functions.h"
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_statpage
|
|
|
|
*/
|
2001-12-03 05:11:29 +00:00
|
|
|
PHPAPI void php_statpage(TSRMLS_D)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2000-02-10 18:19:04 +00:00
|
|
|
struct stat *pstat;
|
1999-06-26 23:21:18 +00:00
|
|
|
|
2001-07-31 06:28:05 +00:00
|
|
|
pstat = sapi_get_stat(TSRMLS_C);
|
2000-02-10 18:19:04 +00:00
|
|
|
|
2001-07-09 17:36:04 +00:00
|
|
|
if (BG(page_uid)==-1 || BG(page_gid)==-1) {
|
2000-08-08 15:50:28 +00:00
|
|
|
if(pstat) {
|
|
|
|
BG(page_uid) = pstat->st_uid;
|
2001-07-09 17:36:04 +00:00
|
|
|
BG(page_gid) = pstat->st_gid;
|
2000-08-08 15:50:28 +00:00
|
|
|
BG(page_inode) = pstat->st_ino;
|
2004-09-25 15:23:35 +00:00
|
|
|
#ifdef NETWARE
|
|
|
|
BG(page_mtime) = (pstat->st_mtime).tv_sec;
|
2002-09-06 07:44:30 +00:00
|
|
|
#else
|
2000-08-08 15:50:28 +00:00
|
|
|
BG(page_mtime) = pstat->st_mtime;
|
2002-09-06 07:44:30 +00:00
|
|
|
#endif
|
2002-08-16 15:04:00 +00:00
|
|
|
} else { /* handler for situations where there is no source file, ex. php -r */
|
2002-08-16 12:47:56 +00:00
|
|
|
BG(page_uid) = getuid();
|
|
|
|
BG(page_gid) = getgid();
|
|
|
|
}
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_getuid
|
|
|
|
*/
|
1999-12-17 19:51:39 +00:00
|
|
|
long php_getuid(void)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2001-07-28 11:36:37 +00:00
|
|
|
TSRMLS_FETCH();
|
1999-12-12 16:14:40 +00:00
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
php_statpage(TSRMLS_C);
|
1999-12-12 16:14:40 +00:00
|
|
|
return (BG(page_uid));
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2001-07-09 17:36:04 +00:00
|
|
|
long php_getgid(void)
|
|
|
|
{
|
2001-07-28 11:36:37 +00:00
|
|
|
TSRMLS_FETCH();
|
2001-07-09 17:36:04 +00:00
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
php_statpage(TSRMLS_C);
|
2001-07-09 17:36:04 +00:00
|
|
|
return (BG(page_gid));
|
|
|
|
}
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
/* {{{ proto int getmyuid(void)
|
|
|
|
Get PHP script owner's UID */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(getmyuid)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
|
|
|
long uid;
|
|
|
|
|
1999-12-17 19:51:39 +00:00
|
|
|
uid = php_getuid();
|
1999-04-17 00:37:12 +00:00
|
|
|
if (uid < 0) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_LONG(uid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-07-09 17:36:04 +00:00
|
|
|
/* {{{ proto int getmygid(void)
|
|
|
|
Get PHP script owner's GID */
|
|
|
|
PHP_FUNCTION(getmygid)
|
|
|
|
{
|
|
|
|
long gid;
|
|
|
|
|
|
|
|
gid = php_getgid();
|
|
|
|
if (gid < 0) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_LONG(gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
/* {{{ proto int getmypid(void)
|
|
|
|
Get current process ID */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(getmypid)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
pid = getpid();
|
|
|
|
if (pid < 0) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_LONG((long) pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int getmyinode(void)
|
|
|
|
Get the inode of the current script being parsed */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(getmyinode)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2001-07-28 11:36:37 +00:00
|
|
|
php_statpage(TSRMLS_C);
|
1999-12-12 16:14:40 +00:00
|
|
|
if (BG(page_inode) < 0) {
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
1999-12-12 16:14:40 +00:00
|
|
|
RETURN_LONG(BG(page_inode));
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-03 05:11:29 +00:00
|
|
|
PHPAPI long php_getlastmod(TSRMLS_D)
|
|
|
|
{
|
|
|
|
php_statpage(TSRMLS_C);
|
|
|
|
return BG(page_mtime);
|
|
|
|
}
|
|
|
|
|
1999-04-17 00:37:12 +00:00
|
|
|
/* {{{ proto int getlastmod(void)
|
|
|
|
Get time of last page modification */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(getlastmod)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2001-12-03 05:11:29 +00:00
|
|
|
long lm = php_getlastmod(TSRMLS_C);
|
|
|
|
if (lm < 0) {
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
2001-12-03 05:11:29 +00:00
|
|
|
RETURN_LONG(lm);
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2001-06-05 13:12:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 13:29:31 +00:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-05 13:12:10 +00:00
|
|
|
*/
|