pageinfo.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Jim Winstead <jimw@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #include "php.h"
  20. #include "pageinfo.h"
  21. #include "SAPI.h"
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #if HAVE_PWD_H
  25. #ifdef PHP_WIN32
  26. #include "win32/pwd.h"
  27. #else
  28. #include <pwd.h>
  29. #endif
  30. #endif
  31. #if HAVE_GRP_H
  32. # ifdef PHP_WIN32
  33. # include "win32/grp.h"
  34. # else
  35. # include <grp.h>
  36. # endif
  37. #endif
  38. #ifdef PHP_WIN32
  39. #undef getgid
  40. #define getgroups(a, b) 0
  41. #define getgid() 1
  42. #define getuid() 1
  43. #endif
  44. #if HAVE_UNISTD_H
  45. #include <unistd.h>
  46. #endif
  47. #include <sys/stat.h>
  48. #include <sys/types.h>
  49. #ifdef PHP_WIN32
  50. #include <process.h>
  51. #endif
  52. #include "ext/standard/basic_functions.h"
  53. /* {{{ php_statpage
  54. */
  55. PHPAPI void php_statpage(TSRMLS_D)
  56. {
  57. struct stat *pstat;
  58. pstat = sapi_get_stat(TSRMLS_C);
  59. if (BG(page_uid)==-1 || BG(page_gid)==-1) {
  60. if(pstat) {
  61. BG(page_uid) = pstat->st_uid;
  62. BG(page_gid) = pstat->st_gid;
  63. BG(page_inode) = pstat->st_ino;
  64. BG(page_mtime) = pstat->st_mtime;
  65. } else { /* handler for situations where there is no source file, ex. php -r */
  66. BG(page_uid) = getuid();
  67. BG(page_gid) = getgid();
  68. }
  69. }
  70. }
  71. /* }}} */
  72. /* {{{ php_getuid
  73. */
  74. long php_getuid(TSRMLS_D)
  75. {
  76. php_statpage(TSRMLS_C);
  77. return (BG(page_uid));
  78. }
  79. /* }}} */
  80. long php_getgid(TSRMLS_D)
  81. {
  82. php_statpage(TSRMLS_C);
  83. return (BG(page_gid));
  84. }
  85. /* {{{ proto int getmyuid(void)
  86. Get PHP script owner's UID */
  87. PHP_FUNCTION(getmyuid)
  88. {
  89. long uid;
  90. if (zend_parse_parameters_none() == FAILURE) {
  91. return;
  92. }
  93. uid = php_getuid(TSRMLS_C);
  94. if (uid < 0) {
  95. RETURN_FALSE;
  96. } else {
  97. RETURN_LONG(uid);
  98. }
  99. }
  100. /* }}} */
  101. /* {{{ proto int getmygid(void)
  102. Get PHP script owner's GID */
  103. PHP_FUNCTION(getmygid)
  104. {
  105. long gid;
  106. if (zend_parse_parameters_none() == FAILURE) {
  107. return;
  108. }
  109. gid = php_getgid(TSRMLS_C);
  110. if (gid < 0) {
  111. RETURN_FALSE;
  112. } else {
  113. RETURN_LONG(gid);
  114. }
  115. }
  116. /* }}} */
  117. /* {{{ proto int getmypid(void)
  118. Get current process ID */
  119. PHP_FUNCTION(getmypid)
  120. {
  121. int pid;
  122. if (zend_parse_parameters_none() == FAILURE) {
  123. return;
  124. }
  125. pid = getpid();
  126. if (pid < 0) {
  127. RETURN_FALSE;
  128. } else {
  129. RETURN_LONG((long) pid);
  130. }
  131. }
  132. /* }}} */
  133. /* {{{ proto int getmyinode(void)
  134. Get the inode of the current script being parsed */
  135. PHP_FUNCTION(getmyinode)
  136. {
  137. if (zend_parse_parameters_none() == FAILURE) {
  138. return;
  139. }
  140. php_statpage(TSRMLS_C);
  141. if (BG(page_inode) < 0) {
  142. RETURN_FALSE;
  143. } else {
  144. RETURN_LONG(BG(page_inode));
  145. }
  146. }
  147. /* }}} */
  148. PHPAPI long php_getlastmod(TSRMLS_D)
  149. {
  150. php_statpage(TSRMLS_C);
  151. return BG(page_mtime);
  152. }
  153. /* {{{ proto int getlastmod(void)
  154. Get time of last page modification */
  155. PHP_FUNCTION(getlastmod)
  156. {
  157. long lm;
  158. if (zend_parse_parameters_none() == FAILURE) {
  159. return;
  160. }
  161. lm = php_getlastmod(TSRMLS_C);
  162. if (lm < 0) {
  163. RETURN_FALSE;
  164. } else {
  165. RETURN_LONG(lm);
  166. }
  167. }
  168. /* }}} */
  169. /*nma
  170. * Local variables:
  171. * tab-width: 4
  172. * c-basic-offset: 4
  173. * End:
  174. * vim600: sw=4 ts=4 fdm=marker
  175. * vim<600: sw=4 ts=4
  176. */