summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/posix.php
blob: 6ae99d88cce8965b550f63c1bb3b904c528ff540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?php

namespace Safe;

use Safe\Exceptions\PosixException;

/**
 * posix_access checks the user's permission of a file.
 *
 * @param string $file The name of the file to be tested.
 * @param int $mode A mask consisting of one or more of POSIX_F_OK,
 * POSIX_R_OK, POSIX_W_OK and
 * POSIX_X_OK.
 *
 * POSIX_R_OK, POSIX_W_OK and
 * POSIX_X_OK request checking whether the file
 * exists and has read, write and execute permissions, respectively.
 * POSIX_F_OK just requests checking for the
 * existence of the file.
 * @throws PosixException
 *
 */
function posix_access(string $file, int $mode = POSIX_F_OK): void
{
    error_clear_last();
    $result = \posix_access($file, $mode);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Gets information about a group provided its name.
 *
 * @param string $name The name of the group
 * @return array Returns an array on success.
 * The array elements returned are:
 *
 * The group information array
 *
 *
 *
 * Element
 * Description
 *
 *
 *
 *
 * name
 *
 * The name element contains the name of the group. This is
 * a short, usually less than 16 character "handle" of the
 * group, not the real, full name.  This should be the same as
 * the name parameter used when
 * calling the function, and hence redundant.
 *
 *
 *
 * passwd
 *
 * The passwd element contains the group's password in an
 * encrypted format. Often, for example on a system employing
 * "shadow" passwords, an asterisk is returned instead.
 *
 *
 *
 * gid
 *
 * Group ID of the group in numeric form.
 *
 *
 *
 * members
 *
 * This consists of an array of
 * string's for all the members in the group.
 *
 *
 *
 *
 *
 * @throws PosixException
 *
 */
function posix_getgrnam(string $name): array
{
    error_clear_last();
    $result = \posix_getgrnam($name);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
    return $result;
}


/**
 * Returns the process group identifier of the process
 * pid.
 *
 * @param int $pid The process id.
 * @return int Returns the identifier, as an integer.
 * @throws PosixException
 *
 */
function posix_getpgid(int $pid): int
{
    error_clear_last();
    $result = \posix_getpgid($pid);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
    return $result;
}


/**
 * Calculates the group access list for the user specified in name.
 *
 * @param string $name The user to calculate the list for.
 * @param int $base_group_id Typically the group number from the password file.
 * @throws PosixException
 *
 */
function posix_initgroups(string $name, int $base_group_id): void
{
    error_clear_last();
    $result = \posix_initgroups($name, $base_group_id);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Send the signal sig to the process with
 * the process identifier pid.
 *
 * @param int $pid The process identifier.
 * @param int $sig One of the PCNTL signals constants.
 * @throws PosixException
 *
 */
function posix_kill(int $pid, int $sig): void
{
    error_clear_last();
    $result = \posix_kill($pid, $sig);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * posix_mkfifo creates a special
 * FIFO file which exists in the file system and acts as
 * a bidirectional communication endpoint for processes.
 *
 * @param string $pathname Path to the FIFO file.
 * @param int $mode The second parameter mode has to be given in
 * octal notation (e.g. 0644). The permission of the newly created
 * FIFO also depends on the setting of the current
 * umask. The permissions of the created file are
 * (mode &amp; ~umask).
 * @throws PosixException
 *
 */
function posix_mkfifo(string $pathname, int $mode): void
{
    error_clear_last();
    $result = \posix_mkfifo($pathname, $mode);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Creates a special or ordinary file.
 *
 * @param string $pathname The file to create
 * @param int $mode This parameter is constructed by a bitwise OR between file type (one of
 * the following constants: POSIX_S_IFREG,
 * POSIX_S_IFCHR, POSIX_S_IFBLK,
 * POSIX_S_IFIFO or
 * POSIX_S_IFSOCK) and permissions.
 * @param int $major The major device kernel identifier (required to pass when using
 * S_IFCHR or S_IFBLK).
 * @param int $minor The minor device kernel identifier.
 * @throws PosixException
 *
 */
function posix_mknod(string $pathname, int $mode, int $major = 0, int $minor = 0): void
{
    error_clear_last();
    $result = \posix_mknod($pathname, $mode, $major, $minor);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Set the effective group ID of the current process. This is a
 * privileged function and needs appropriate privileges (usually
 * root) on the system to be able to perform this function.
 *
 * @param int $gid The group id.
 * @throws PosixException
 *
 */
function posix_setegid(int $gid): void
{
    error_clear_last();
    $result = \posix_setegid($gid);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Set the effective user ID of the current process. This is a privileged
 * function and needs appropriate privileges (usually root) on
 * the system to be able to perform this function.
 *
 * @param int $uid The user id.
 * @throws PosixException
 *
 */
function posix_seteuid(int $uid): void
{
    error_clear_last();
    $result = \posix_seteuid($uid);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Set the real group ID of the current process. This is a
 * privileged function and needs appropriate privileges (usually
 * root) on the system to be able to perform this function. The
 * appropriate order of function calls is
 * posix_setgid first,
 * posix_setuid last.
 *
 * @param int $gid The group id.
 * @throws PosixException
 *
 */
function posix_setgid(int $gid): void
{
    error_clear_last();
    $result = \posix_setgid($gid);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Let the process pid join the process group
 * pgid.
 *
 * @param int $pid The process id.
 * @param int $pgid The process group id.
 * @throws PosixException
 *
 */
function posix_setpgid(int $pid, int $pgid): void
{
    error_clear_last();
    $result = \posix_setpgid($pid, $pgid);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * posix_setrlimit sets the soft and hard limits for a
 * given system resource.
 *
 *
 * Each resource has an associated soft and hard limit.  The soft
 * limit is the value that the kernel enforces for the corresponding
 * resource.  The hard limit acts as a ceiling for the soft limit.
 * An unprivileged process may only set its soft limit to a value
 * from 0 to the hard limit, and irreversibly lower its hard limit.
 *
 * @param int $resource The
 * resource limit constant
 * corresponding to the limit that is being set.
 * @param int $softlimit The soft limit, in whatever unit the resource limit requires, or
 * POSIX_RLIMIT_INFINITY.
 * @param int $hardlimit The hard limit, in whatever unit the resource limit requires, or
 * POSIX_RLIMIT_INFINITY.
 * @throws PosixException
 *
 */
function posix_setrlimit(int $resource, int $softlimit, int $hardlimit): void
{
    error_clear_last();
    $result = \posix_setrlimit($resource, $softlimit, $hardlimit);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}


/**
 * Set the real user ID of the current process. This is a privileged
 * function that needs appropriate privileges (usually root) on
 * the system to be able to perform this function.
 *
 * @param int $uid The user id.
 * @throws PosixException
 *
 */
function posix_setuid(int $uid): void
{
    error_clear_last();
    $result = \posix_setuid($uid);
    if ($result === false) {
        throw PosixException::createFromPhpError();
    }
}