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