Exceptions
5 days ago
apache.php
5 days ago
apcu.php
5 days ago
array.php
5 days ago
bzip2.php
5 days ago
calendar.php
5 days ago
classobj.php
5 days ago
com.php
5 days ago
cubrid.php
5 days ago
curl.php
5 days ago
datetime.php
5 days ago
dir.php
5 days ago
eio.php
5 days ago
errorfunc.php
5 days ago
exec.php
5 days ago
fileinfo.php
5 days ago
filesystem.php
5 days ago
filter.php
5 days ago
fpm.php
5 days ago
ftp.php
5 days ago
funchand.php
5 days ago
functionsList.php
5 days ago
gmp.php
5 days ago
gnupg.php
5 days ago
hash.php
5 days ago
ibase.php
5 days ago
ibmDb2.php
5 days ago
iconv.php
5 days ago
image.php
5 days ago
imap.php
5 days ago
info.php
5 days ago
ingres-ii.php
5 days ago
inotify.php
5 days ago
json.php
5 days ago
ldap.php
5 days ago
libxml.php
5 days ago
lzf.php
5 days ago
mailparse.php
5 days ago
mbstring.php
5 days ago
misc.php
5 days ago
msql.php
5 days ago
mysql.php
5 days ago
mysqli.php
5 days ago
mysqlndMs.php
5 days ago
mysqlndQc.php
5 days ago
network.php
5 days ago
oci8.php
5 days ago
opcache.php
5 days ago
openssl.php
5 days ago
outcontrol.php
5 days ago
password.php
5 days ago
pcntl.php
5 days ago
pcre.php
5 days ago
pdf.php
5 days ago
pgsql.php
5 days ago
posix.php
5 days ago
ps.php
5 days ago
pspell.php
5 days ago
readline.php
5 days ago
rpminfo.php
5 days ago
rrd.php
5 days ago
sem.php
5 days ago
session.php
5 days ago
shmop.php
5 days ago
simplexml.php
5 days ago
sockets.php
5 days ago
sodium.php
5 days ago
solr.php
5 days ago
spl.php
5 days ago
sqlsrv.php
5 days ago
ssdeep.php
5 days ago
ssh2.php
5 days ago
stream.php
5 days ago
strings.php
5 days ago
swoole.php
5 days ago
uodbc.php
5 days ago
uopz.php
5 days ago
url.php
5 days ago
var.php
5 days ago
xdiff.php
5 days ago
xml.php
5 days ago
xmlrpc.php
5 days ago
yaml.php
5 days ago
yaz.php
5 days ago
zip.php
5 days ago
zlib.php
5 days ago
posix.php
305 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\PosixException; |
| 6 | /** |
| 7 | * posix_access checks the user's permission of a file. |
| 8 | * |
| 9 | * @param string $file The name of the file to be tested. |
| 10 | * @param int $mode A mask consisting of one or more of POSIX_F_OK, |
| 11 | * POSIX_R_OK, POSIX_W_OK and |
| 12 | * POSIX_X_OK. |
| 13 | * |
| 14 | * POSIX_R_OK, POSIX_W_OK and |
| 15 | * POSIX_X_OK request checking whether the file |
| 16 | * exists and has read, write and execute permissions, respectively. |
| 17 | * POSIX_F_OK just requests checking for the |
| 18 | * existence of the file. |
| 19 | * @throws PosixException |
| 20 | * |
| 21 | */ |
| 22 | function posix_access(string $file, int $mode = \POSIX_F_OK): void |
| 23 | { |
| 24 | error_clear_last(); |
| 25 | $result = \posix_access($file, $mode); |
| 26 | if ($result === \false) { |
| 27 | throw PosixException::createFromPhpError(); |
| 28 | } |
| 29 | } |
| 30 | /** |
| 31 | * Gets information about a group provided its name. |
| 32 | * |
| 33 | * @param string $name The name of the group |
| 34 | * @return array Returns an array on success. |
| 35 | * The array elements returned are: |
| 36 | * |
| 37 | * The group information array |
| 38 | * |
| 39 | * |
| 40 | * |
| 41 | * Element |
| 42 | * Description |
| 43 | * |
| 44 | * |
| 45 | * |
| 46 | * |
| 47 | * name |
| 48 | * |
| 49 | * The name element contains the name of the group. This is |
| 50 | * a short, usually less than 16 character "handle" of the |
| 51 | * group, not the real, full name. This should be the same as |
| 52 | * the name parameter used when |
| 53 | * calling the function, and hence redundant. |
| 54 | * |
| 55 | * |
| 56 | * |
| 57 | * passwd |
| 58 | * |
| 59 | * The passwd element contains the group's password in an |
| 60 | * encrypted format. Often, for example on a system employing |
| 61 | * "shadow" passwords, an asterisk is returned instead. |
| 62 | * |
| 63 | * |
| 64 | * |
| 65 | * gid |
| 66 | * |
| 67 | * Group ID of the group in numeric form. |
| 68 | * |
| 69 | * |
| 70 | * |
| 71 | * members |
| 72 | * |
| 73 | * This consists of an array of |
| 74 | * string's for all the members in the group. |
| 75 | * |
| 76 | * |
| 77 | * |
| 78 | * |
| 79 | * |
| 80 | * @throws PosixException |
| 81 | * |
| 82 | */ |
| 83 | function posix_getgrnam(string $name): array |
| 84 | { |
| 85 | error_clear_last(); |
| 86 | $result = \posix_getgrnam($name); |
| 87 | if ($result === \false) { |
| 88 | throw PosixException::createFromPhpError(); |
| 89 | } |
| 90 | return $result; |
| 91 | } |
| 92 | /** |
| 93 | * Returns the process group identifier of the process |
| 94 | * pid. |
| 95 | * |
| 96 | * @param int $pid The process id. |
| 97 | * @return int Returns the identifier, as an integer. |
| 98 | * @throws PosixException |
| 99 | * |
| 100 | */ |
| 101 | function posix_getpgid(int $pid): int |
| 102 | { |
| 103 | error_clear_last(); |
| 104 | $result = \posix_getpgid($pid); |
| 105 | if ($result === \false) { |
| 106 | throw PosixException::createFromPhpError(); |
| 107 | } |
| 108 | return $result; |
| 109 | } |
| 110 | /** |
| 111 | * Calculates the group access list for the user specified in name. |
| 112 | * |
| 113 | * @param string $name The user to calculate the list for. |
| 114 | * @param int $base_group_id Typically the group number from the password file. |
| 115 | * @throws PosixException |
| 116 | * |
| 117 | */ |
| 118 | function posix_initgroups(string $name, int $base_group_id): void |
| 119 | { |
| 120 | error_clear_last(); |
| 121 | $result = \posix_initgroups($name, $base_group_id); |
| 122 | if ($result === \false) { |
| 123 | throw PosixException::createFromPhpError(); |
| 124 | } |
| 125 | } |
| 126 | /** |
| 127 | * Send the signal sig to the process with |
| 128 | * the process identifier pid. |
| 129 | * |
| 130 | * @param int $pid The process identifier. |
| 131 | * @param int $sig One of the PCNTL signals constants. |
| 132 | * @throws PosixException |
| 133 | * |
| 134 | */ |
| 135 | function posix_kill(int $pid, int $sig): void |
| 136 | { |
| 137 | error_clear_last(); |
| 138 | $result = \posix_kill($pid, $sig); |
| 139 | if ($result === \false) { |
| 140 | throw PosixException::createFromPhpError(); |
| 141 | } |
| 142 | } |
| 143 | /** |
| 144 | * posix_mkfifo creates a special |
| 145 | * FIFO file which exists in the file system and acts as |
| 146 | * a bidirectional communication endpoint for processes. |
| 147 | * |
| 148 | * @param string $pathname Path to the FIFO file. |
| 149 | * @param int $mode The second parameter mode has to be given in |
| 150 | * octal notation (e.g. 0644). The permission of the newly created |
| 151 | * FIFO also depends on the setting of the current |
| 152 | * umask. The permissions of the created file are |
| 153 | * (mode & ~umask). |
| 154 | * @throws PosixException |
| 155 | * |
| 156 | */ |
| 157 | function posix_mkfifo(string $pathname, int $mode): void |
| 158 | { |
| 159 | error_clear_last(); |
| 160 | $result = \posix_mkfifo($pathname, $mode); |
| 161 | if ($result === \false) { |
| 162 | throw PosixException::createFromPhpError(); |
| 163 | } |
| 164 | } |
| 165 | /** |
| 166 | * Creates a special or ordinary file. |
| 167 | * |
| 168 | * @param string $pathname The file to create |
| 169 | * @param int $mode This parameter is constructed by a bitwise OR between file type (one of |
| 170 | * the following constants: POSIX_S_IFREG, |
| 171 | * POSIX_S_IFCHR, POSIX_S_IFBLK, |
| 172 | * POSIX_S_IFIFO or |
| 173 | * POSIX_S_IFSOCK) and permissions. |
| 174 | * @param int $major The major device kernel identifier (required to pass when using |
| 175 | * S_IFCHR or S_IFBLK). |
| 176 | * @param int $minor The minor device kernel identifier. |
| 177 | * @throws PosixException |
| 178 | * |
| 179 | */ |
| 180 | function posix_mknod(string $pathname, int $mode, int $major = 0, int $minor = 0): void |
| 181 | { |
| 182 | error_clear_last(); |
| 183 | $result = \posix_mknod($pathname, $mode, $major, $minor); |
| 184 | if ($result === \false) { |
| 185 | throw PosixException::createFromPhpError(); |
| 186 | } |
| 187 | } |
| 188 | /** |
| 189 | * Set the effective group ID of the current process. This is a |
| 190 | * privileged function and needs appropriate privileges (usually |
| 191 | * root) on the system to be able to perform this function. |
| 192 | * |
| 193 | * @param int $gid The group id. |
| 194 | * @throws PosixException |
| 195 | * |
| 196 | */ |
| 197 | function posix_setegid(int $gid): void |
| 198 | { |
| 199 | error_clear_last(); |
| 200 | $result = \posix_setegid($gid); |
| 201 | if ($result === \false) { |
| 202 | throw PosixException::createFromPhpError(); |
| 203 | } |
| 204 | } |
| 205 | /** |
| 206 | * Set the effective user ID of the current process. This is a privileged |
| 207 | * function and needs appropriate privileges (usually root) on |
| 208 | * the system to be able to perform this function. |
| 209 | * |
| 210 | * @param int $uid The user id. |
| 211 | * @throws PosixException |
| 212 | * |
| 213 | */ |
| 214 | function posix_seteuid(int $uid): void |
| 215 | { |
| 216 | error_clear_last(); |
| 217 | $result = \posix_seteuid($uid); |
| 218 | if ($result === \false) { |
| 219 | throw PosixException::createFromPhpError(); |
| 220 | } |
| 221 | } |
| 222 | /** |
| 223 | * Set the real group ID of the current process. This is a |
| 224 | * privileged function and needs appropriate privileges (usually |
| 225 | * root) on the system to be able to perform this function. The |
| 226 | * appropriate order of function calls is |
| 227 | * posix_setgid first, |
| 228 | * posix_setuid last. |
| 229 | * |
| 230 | * @param int $gid The group id. |
| 231 | * @throws PosixException |
| 232 | * |
| 233 | */ |
| 234 | function posix_setgid(int $gid): void |
| 235 | { |
| 236 | error_clear_last(); |
| 237 | $result = \posix_setgid($gid); |
| 238 | if ($result === \false) { |
| 239 | throw PosixException::createFromPhpError(); |
| 240 | } |
| 241 | } |
| 242 | /** |
| 243 | * Let the process pid join the process group |
| 244 | * pgid. |
| 245 | * |
| 246 | * @param int $pid The process id. |
| 247 | * @param int $pgid The process group id. |
| 248 | * @throws PosixException |
| 249 | * |
| 250 | */ |
| 251 | function posix_setpgid(int $pid, int $pgid): void |
| 252 | { |
| 253 | error_clear_last(); |
| 254 | $result = \posix_setpgid($pid, $pgid); |
| 255 | if ($result === \false) { |
| 256 | throw PosixException::createFromPhpError(); |
| 257 | } |
| 258 | } |
| 259 | /** |
| 260 | * posix_setrlimit sets the soft and hard limits for a |
| 261 | * given system resource. |
| 262 | * |
| 263 | * |
| 264 | * Each resource has an associated soft and hard limit. The soft |
| 265 | * limit is the value that the kernel enforces for the corresponding |
| 266 | * resource. The hard limit acts as a ceiling for the soft limit. |
| 267 | * An unprivileged process may only set its soft limit to a value |
| 268 | * from 0 to the hard limit, and irreversibly lower its hard limit. |
| 269 | * |
| 270 | * @param int $resource The |
| 271 | * resource limit constant |
| 272 | * corresponding to the limit that is being set. |
| 273 | * @param int $softlimit The soft limit, in whatever unit the resource limit requires, or |
| 274 | * POSIX_RLIMIT_INFINITY. |
| 275 | * @param int $hardlimit The hard limit, in whatever unit the resource limit requires, or |
| 276 | * POSIX_RLIMIT_INFINITY. |
| 277 | * @throws PosixException |
| 278 | * |
| 279 | */ |
| 280 | function posix_setrlimit(int $resource, int $softlimit, int $hardlimit): void |
| 281 | { |
| 282 | error_clear_last(); |
| 283 | $result = \posix_setrlimit($resource, $softlimit, $hardlimit); |
| 284 | if ($result === \false) { |
| 285 | throw PosixException::createFromPhpError(); |
| 286 | } |
| 287 | } |
| 288 | /** |
| 289 | * Set the real user ID of the current process. This is a privileged |
| 290 | * function that needs appropriate privileges (usually root) on |
| 291 | * the system to be able to perform this function. |
| 292 | * |
| 293 | * @param int $uid The user id. |
| 294 | * @throws PosixException |
| 295 | * |
| 296 | */ |
| 297 | function posix_setuid(int $uid): void |
| 298 | { |
| 299 | error_clear_last(); |
| 300 | $result = \posix_setuid($uid); |
| 301 | if ($result === \false) { |
| 302 | throw PosixException::createFromPhpError(); |
| 303 | } |
| 304 | } |
| 305 |