Skip to content

Commit 65d5efd

Browse files
committed
Add php_get_current_running_user() API
1 parent 385ede4 commit 65d5efd

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

UPGRADING.INTERNALS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES
1717
- Core
1818
. PG(arg_separator).input and PG(arg_separator).output are now `zend_string*`
1919
instead of `char*`.
20+
. Added php_get_current_running_user() API to get the (effective) user
21+
running the script.
2022

2123
- Zend
2224
. Added zend_safe_assign_to_variable_noref() function to safely assign

main/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,22 @@ static char *php_translate_uid_to_username(uid_t uid, size_t *len)
15421542
}
15431543
#endif
15441544

1545+
PHPAPI char *php_get_current_running_user(size_t *len)
1546+
{
1547+
#ifdef PHP_WIN32
1548+
char *name = php_win32_get_username();
1549+
if (!name) {
1550+
return NULL;
1551+
}
1552+
*len = strlen(name);
1553+
char *result = estrndup(name, *len);
1554+
free(name);
1555+
return result;
1556+
#else
1557+
return php_translate_uid_to_username(geteuid(), len);
1558+
#endif
1559+
}
1560+
15451561
/* {{{ php_get_current_user */
15461562
PHPAPI char *php_get_current_user(void)
15471563
{

main/php.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ PHPAPI int php_register_internal_extensions(void);
337337
PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
338338
PHPAPI void php_com_initialize(void);
339339
PHPAPI char *php_get_current_user(void);
340+
PHPAPI char *php_get_current_running_user(size_t *len);
340341

341342
PHPAPI const char *php_get_internal_encoding(void);
342343
PHPAPI const char *php_get_input_encoding(void);

0 commit comments

Comments
 (0)