Coverage Report

Created: 2022-02-19 20:27

/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
   | http://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
#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
52
#include "ext/standard/basic_functions.h"
53
54
/* {{{ php_statpage */
55
PHPAPI void php_statpage(void)
56
0
{
57
0
  zend_stat_t *pstat;
58
59
0
  pstat = sapi_get_stat();
60
61
0
  if (BG(page_uid)==-1 || BG(page_gid)==-1) {
62
0
    if(pstat) {
63
0
      BG(page_uid)   = pstat->st_uid;
64
0
      BG(page_gid)   = pstat->st_gid;
65
0
      BG(page_inode) = pstat->st_ino;
66
0
      BG(page_mtime) = pstat->st_mtime;
67
0
    } else { /* handler for situations where there is no source file, ex. php -r */
68
0
      BG(page_uid) = getuid();
69
0
      BG(page_gid) = getgid();
70
0
    }
71
0
  }
72
0
}
73
/* }}} */
74
75
/* {{{ php_getuid */
76
zend_long php_getuid(void)
77
0
{
78
0
  php_statpage();
79
0
  return (BG(page_uid));
80
0
}
81
/* }}} */
82
83
zend_long php_getgid(void)
84
0
{
85
0
  php_statpage();
86
0
  return (BG(page_gid));
87
0
}
88
89
/* {{{ Get PHP script owner's UID */
90
PHP_FUNCTION(getmyuid)
91
0
{
92
0
  zend_long uid;
93
94
0
  ZEND_PARSE_PARAMETERS_NONE();
95
96
0
  uid = php_getuid();
97
0
  if (uid < 0) {
98
0
    RETURN_FALSE;
99
0
  } else {
100
0
    RETURN_LONG(uid);
101
0
  }
102
0
}
103
/* }}} */
104
105
/* {{{ Get PHP script owner's GID */
106
PHP_FUNCTION(getmygid)
107
0
{
108
0
  zend_long gid;
109
110
0
  ZEND_PARSE_PARAMETERS_NONE();
111
112
0
  gid = php_getgid();
113
0
  if (gid < 0) {
114
0
    RETURN_FALSE;
115
0
  } else {
116
0
    RETURN_LONG(gid);
117
0
  }
118
0
}
119
/* }}} */
120
121
/* {{{ Get current process ID */
122
PHP_FUNCTION(getmypid)
123
0
{
124
0
  zend_long pid;
125
126
0
  ZEND_PARSE_PARAMETERS_NONE();
127
128
0
  pid = getpid();
129
0
  if (pid < 0) {
130
0
    RETURN_FALSE;
131
0
  } else {
132
0
    RETURN_LONG(pid);
133
0
  }
134
0
}
135
/* }}} */
136
137
/* {{{ Get the inode of the current script being parsed */
138
PHP_FUNCTION(getmyinode)
139
0
{
140
0
  ZEND_PARSE_PARAMETERS_NONE();
141
142
0
  php_statpage();
143
0
  if (BG(page_inode) < 0) {
144
0
    RETURN_FALSE;
145
0
  } else {
146
0
    RETURN_LONG(BG(page_inode));
147
0
  }
148
0
}
149
/* }}} */
150
151
PHPAPI time_t php_getlastmod(void)
152
0
{
153
0
  php_statpage();
154
0
  return BG(page_mtime);
155
0
}
156
157
/* {{{ Get time of last page modification */
158
PHP_FUNCTION(getlastmod)
159
0
{
160
0
  zend_long lm;
161
162
0
  ZEND_PARSE_PARAMETERS_NONE();
163
164
0
  lm = php_getlastmod();
165
0
  if (lm < 0) {
166
0
    RETURN_FALSE;
167
0
  } else {
168
0
    RETURN_LONG(lm);
169
0
  }
170
0
}
171
/* }}} */