Coverage Report

Created: 2026-06-02 06:36

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