pageinfo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 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. #include "php.h"
  19. #include "pageinfo.h"
  20. #include "SAPI.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #if HAVE_PWD_H
  24. #ifdef PHP_WIN32
  25. #include "win32/pwd.h"
  26. #else
  27. #include <pwd.h>
  28. #endif
  29. #endif
  30. #if HAVE_GRP_H
  31. # ifdef PHP_WIN32
  32. # include "win32/grp.h"
  33. # else
  34. # include <grp.h>
  35. # endif
  36. #endif
  37. #ifdef PHP_WIN32
  38. #undef getgid
  39. #define getgroups(a, b) 0
  40. #define getgid() 1
  41. #define getuid() 1
  42. #endif
  43. #if HAVE_UNISTD_H
  44. #include <unistd.h>
  45. #endif
  46. #include <sys/stat.h>
  47. #include <sys/types.h>
  48. #ifdef PHP_WIN32
  49. #include <process.h>
  50. #endif
  51. #include "ext/standard/basic_functions.h"
  52. /* {{{ php_statpage
  53. */
  54. PHPAPI void php_statpage(void)
  55. {
  56. zend_stat_t *pstat;
  57. pstat = sapi_get_stat();
  58. if (BG(page_uid)==-1 || BG(page_gid)==-1) {
  59. if(pstat) {
  60. BG(page_uid) = pstat->st_uid;
  61. BG(page_gid) = pstat->st_gid;
  62. BG(page_inode) = pstat->st_ino;
  63. BG(page_mtime) = pstat->st_mtime;
  64. } else { /* handler for situations where there is no source file, ex. php -r */
  65. BG(page_uid) = getuid();
  66. BG(page_gid) = getgid();
  67. }
  68. }
  69. }
  70. /* }}} */
  71. /* {{{ php_getuid
  72. */
  73. zend_long php_getuid(void)
  74. {
  75. php_statpage();
  76. return (BG(page_uid));
  77. }
  78. /* }}} */
  79. zend_long php_getgid(void)
  80. {
  81. php_statpage();
  82. return (BG(page_gid));
  83. }
  84. /* {{{ proto int getmyuid(void)
  85. Get PHP script owner's UID */
  86. PHP_FUNCTION(getmyuid)
  87. {
  88. zend_long uid;
  89. if (zend_parse_parameters_none() == FAILURE) {
  90. return;
  91. }
  92. uid = php_getuid();
  93. if (uid < 0) {
  94. RETURN_FALSE;
  95. } else {
  96. RETURN_LONG(uid);
  97. }
  98. }
  99. /* }}} */
  100. /* {{{ proto int getmygid(void)
  101. Get PHP script owner's GID */
  102. PHP_FUNCTION(getmygid)
  103. {
  104. zend_long gid;
  105. if (zend_parse_parameters_none() == FAILURE) {
  106. return;
  107. }
  108. gid = php_getgid();
  109. if (gid < 0) {
  110. RETURN_FALSE;
  111. } else {
  112. RETURN_LONG(gid);
  113. }
  114. }
  115. /* }}} */
  116. /* {{{ proto int getmypid(void)
  117. Get current process ID */
  118. PHP_FUNCTION(getmypid)
  119. {
  120. zend_long pid;
  121. if (zend_parse_parameters_none() == FAILURE) {
  122. return;
  123. }
  124. pid = getpid();
  125. if (pid < 0) {
  126. RETURN_FALSE;
  127. } else {
  128. RETURN_LONG(pid);
  129. }
  130. }
  131. /* }}} */
  132. /* {{{ proto int getmyinode(void)
  133. Get the inode of the current script being parsed */
  134. PHP_FUNCTION(getmyinode)
  135. {
  136. if (zend_parse_parameters_none() == FAILURE) {
  137. return;
  138. }
  139. php_statpage();
  140. if (BG(page_inode) < 0) {
  141. RETURN_FALSE;
  142. } else {
  143. RETURN_LONG(BG(page_inode));
  144. }
  145. }
  146. /* }}} */
  147. PHPAPI time_t php_getlastmod(void)
  148. {
  149. php_statpage();
  150. return BG(page_mtime);
  151. }
  152. /* {{{ proto int getlastmod(void)
  153. Get time of last page modification */
  154. PHP_FUNCTION(getlastmod)
  155. {
  156. zend_long lm;
  157. if (zend_parse_parameters_none() == FAILURE) {
  158. return;
  159. }
  160. lm = php_getlastmod();
  161. if (lm < 0) {
  162. RETURN_FALSE;
  163. } else {
  164. RETURN_LONG(lm);
  165. }
  166. }
  167. /* }}} */
  168. /*nma
  169. * Local variables:
  170. * tab-width: 4
  171. * c-basic-offset: 4
  172. * End:
  173. * vim600: sw=4 ts=4 fdm=marker
  174. * vim<600: sw=4 ts=4
  175. */