123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #include "php.h"
- #include "pageinfo.h"
- #include "SAPI.h"
- #include <stdio.h>
- #include <stdlib.h>
- #if HAVE_PWD_H
- #ifdef PHP_WIN32
- #include "win32/pwd.h"
- #else
- #include <pwd.h>
- #endif
- #endif
- #if HAVE_GRP_H
- # include <grp.h>
- #endif
- #ifdef PHP_WIN32
- #undef getgid
- #define getgroups(a, b) 0
- #define getgid() 1
- #define getuid() 1
- #endif
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #include <sys/stat.h>
- #include <sys/types.h>
- #ifdef PHP_WIN32
- #include <process.h>
- #endif
- #include "ext/standard/basic_functions.h"
- PHPAPI void php_statpage(void)
- {
- zend_stat_t *pstat;
- pstat = sapi_get_stat();
- if (BG(page_uid)==-1 || BG(page_gid)==-1) {
- if(pstat) {
- BG(page_uid) = pstat->st_uid;
- BG(page_gid) = pstat->st_gid;
- BG(page_inode) = pstat->st_ino;
- BG(page_mtime) = pstat->st_mtime;
- } else {
- BG(page_uid) = getuid();
- BG(page_gid) = getgid();
- }
- }
- }
- zend_long php_getuid(void)
- {
- php_statpage();
- return (BG(page_uid));
- }
- zend_long php_getgid(void)
- {
- php_statpage();
- return (BG(page_gid));
- }
- PHP_FUNCTION(getmyuid)
- {
- zend_long uid;
- ZEND_PARSE_PARAMETERS_NONE();
- uid = php_getuid();
- if (uid < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(uid);
- }
- }
- PHP_FUNCTION(getmygid)
- {
- zend_long gid;
- ZEND_PARSE_PARAMETERS_NONE();
- gid = php_getgid();
- if (gid < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(gid);
- }
- }
- PHP_FUNCTION(getmypid)
- {
- zend_long pid;
- ZEND_PARSE_PARAMETERS_NONE();
- pid = getpid();
- if (pid < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(pid);
- }
- }
- PHP_FUNCTION(getmyinode)
- {
- ZEND_PARSE_PARAMETERS_NONE();
- php_statpage();
- if (BG(page_inode) < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(BG(page_inode));
- }
- }
- PHPAPI time_t php_getlastmod(void)
- {
- php_statpage();
- return BG(page_mtime);
- }
- PHP_FUNCTION(getlastmod)
- {
- zend_long lm;
- ZEND_PARSE_PARAMETERS_NONE();
- lm = php_getlastmod();
- if (lm < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(lm);
- }
- }
|