PHPAPI char *php_get_current_user(void) { struct stat *pstat; TSRMLS_FETCH(); if (SG(request_info).current_user) { return SG(request_info).current_user; } /* FIXME: I need to have this somehow handled if USE_SAPI is defined, because cgi will also be interfaced in USE_SAPI */ pstat = sapi_get_stat(TSRMLS_C); if (!pstat) { return ""; } else { #ifdef PHP_WIN32 char name[256]; DWORD len = sizeof(name)-1; if (!GetUserName(name, &len)) { return ""; } name[len] = '\0'; SG(request_info).current_user_length = len; SG(request_info).current_user = estrndup(name, len); return SG(request_info).current_user; #else struct passwd *pwd; #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX) struct passwd _pw; struct passwd *retpwptr = NULL; int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX); char *pwbuf; if (pwbuflen < 1) { return ""; } pwbuf = emalloc(pwbuflen); if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) { efree(pwbuf); return ""; } pwd = &_pw; #else if ((pwd=getpwuid(pstat->st_uid))==NULL) { return ""; } #endif SG(request_info).current_user_length = strlen(pwd->pw_name); SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length); #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX) efree(pwbuf); #endif return SG(request_info).current_user; #endif } }
/* {{{ php_statpage */ PHPAPI void php_statpage(TSRMLS_D) { struct stat *pstat; pstat = sapi_get_stat(TSRMLS_C); if (BG(page_uid)==-1 || BG(page_gid)==-1) { if(pstat) { BG(page_uid) = pstat->st_uid; BG(page_gid) = pstat->st_gid; BG(page_inode) = pstat->st_ino; BG(page_mtime) = pstat->st_mtime; } else { /* handler for situations where there is no source file, ex. php -r */ BG(page_uid) = getuid(); BG(page_gid) = getgid(); } } }