Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13144163
CurrentProcess.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
CurrentProcess.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\OS
;
class
CurrentProcess
{
/**
* Determines if the current process, ie the PHP interpreter,
* runs as root on UNIX systems or in elevated mode on Windows.
*
* Cygwin processes are considered as Windows processes.
*/
public
static
function
isPrivileged
()
:
bool
{
if
(
CurrentOS
::
isWindows
())
{
// `net session` is known to only work as privileged process.
// To wrap in cmd allows avoiding /dev/null for Cygwin,
// or $null when invoked from PowerShell. NUL: will always be used.
exec
(
'cmd /C "net session >NUL 2>&1"'
,
$_
,
$exitCode
);
return
$exitCode
===
0
;
}
if
(!
function_exists
(
'posix_geteuid'
))
{
// POSIX PHP functions aren't always available, e.g. on FreeBSD
// In such cases, `id` will probably be available.
return
trim
((
string
)
shell_exec
(
'id -u'
))
===
'0'
;
}
return
posix_geteuid
()
===
0
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 21, 16:56 (15 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3160333
Default Alt Text
CurrentProcess.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment