mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Simplify the code base as this getpwd() was used only once
This commit is contained in:
parent
126be8ec7c
commit
9fd2b6deb4
13 changed files with 31 additions and 149 deletions
|
@ -162,7 +162,7 @@
|
||||||
#define HAVE_ASSERT_H 1
|
#define HAVE_ASSERT_H 1
|
||||||
#define HAVE_FCNTL_H 1
|
#define HAVE_FCNTL_H 1
|
||||||
#define HAVE_GRP_H 0
|
#define HAVE_GRP_H 0
|
||||||
#define HAVE_PWD_H 1
|
#undef HAVE_PWD_H
|
||||||
#define HAVE_STRING_H 1
|
#define HAVE_STRING_H 1
|
||||||
#undef HAVE_SYS_FILE_H
|
#undef HAVE_SYS_FILE_H
|
||||||
#undef HAVE_SYS_SOCKET_H
|
#undef HAVE_SYS_SOCKET_H
|
||||||
|
|
|
@ -46,12 +46,8 @@
|
||||||
#include "php_network.h"
|
#include "php_network.h"
|
||||||
|
|
||||||
#if HAVE_PWD_H
|
#if HAVE_PWD_H
|
||||||
#ifdef PHP_WIN32
|
|
||||||
#include "win32/pwd.h"
|
|
||||||
#else
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#if HAVE_SYS_SOCKET_H
|
#if HAVE_SYS_SOCKET_H
|
||||||
|
|
|
@ -199,7 +199,6 @@ char *strerror(int);
|
||||||
|
|
||||||
#if HAVE_PWD_H
|
#if HAVE_PWD_H
|
||||||
# ifdef PHP_WIN32
|
# ifdef PHP_WIN32
|
||||||
#include "win32/pwd.h"
|
|
||||||
#include "win32/param.h"
|
#include "win32/param.h"
|
||||||
# else
|
# else
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
|
@ -197,7 +197,6 @@ PHPAPI int php_checkuid(const char *filename, const char *fopen_mode, int mode)
|
||||||
|
|
||||||
PHPAPI char *php_get_current_user()
|
PHPAPI char *php_get_current_user()
|
||||||
{
|
{
|
||||||
struct passwd *pwd;
|
|
||||||
struct stat *pstat;
|
struct stat *pstat;
|
||||||
TSRMLS_FETCH();
|
TSRMLS_FETCH();
|
||||||
|
|
||||||
|
@ -213,15 +212,29 @@ PHPAPI char *php_get_current_user()
|
||||||
|
|
||||||
if (!pstat) {
|
if (!pstat) {
|
||||||
return "";
|
return "";
|
||||||
}
|
} else {
|
||||||
|
#ifdef PHP_WIN32
|
||||||
|
char name[256];
|
||||||
|
DWORD len = sizeof(name)-1;
|
||||||
|
|
||||||
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
|
if (!GetUserName(name, &len)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
SG(request_info).current_user_length = strlen(pwd->pw_name);
|
name[len] = '\0';
|
||||||
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
|
SG(request_info).current_user_length = len;
|
||||||
|
SG(request_info).current_user = estrndup(name, len);
|
||||||
return SG(request_info).current_user;
|
return SG(request_info).current_user;
|
||||||
|
#else
|
||||||
|
struct passwd *pwd;
|
||||||
|
|
||||||
|
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
return SG(request_info).current_user;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -264,7 +264,7 @@ ADD_SOURCES("main", "main.c snprintf.c spprintf.c safe_mode.c fopen_wrappers.c \
|
||||||
ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
|
ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
|
||||||
userspace.c transports.c xp_socket.c mmap.c");
|
userspace.c transports.c xp_socket.c mmap.c");
|
||||||
|
|
||||||
ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c pwd.c readdir.c \
|
ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c readdir.c \
|
||||||
registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c");
|
registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c");
|
||||||
|
|
||||||
ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c");
|
ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c");
|
||||||
|
|
|
@ -100,7 +100,7 @@
|
||||||
#define HAVE_ASSERT_H 1
|
#define HAVE_ASSERT_H 1
|
||||||
#define HAVE_FCNTL_H 1
|
#define HAVE_FCNTL_H 1
|
||||||
#define HAVE_GRP_H 0
|
#define HAVE_GRP_H 0
|
||||||
#define HAVE_PWD_H 1
|
#undef HAVE_PWD_H
|
||||||
#define HAVE_STRING_H 1
|
#define HAVE_STRING_H 1
|
||||||
#undef HAVE_SYS_FILE_H
|
#undef HAVE_SYS_FILE_H
|
||||||
#undef HAVE_SYS_SOCKET_H
|
#undef HAVE_SYS_SOCKET_H
|
||||||
|
|
|
@ -81,8 +81,6 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
|
||||||
#include "win32/pwd.h"
|
|
||||||
#endif
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "glob.h"
|
#include "glob.h"
|
||||||
|
@ -359,7 +357,9 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
|
||||||
size_t patbuf_len;
|
size_t patbuf_len;
|
||||||
glob_t *pglob;
|
glob_t *pglob;
|
||||||
{
|
{
|
||||||
|
#ifndef PHP_WIN32
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
|
#endif
|
||||||
char *h;
|
char *h;
|
||||||
const Char *p;
|
const Char *p;
|
||||||
Char *b, *eb;
|
Char *b, *eb;
|
||||||
|
@ -399,10 +399,14 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
|
||||||
/*
|
/*
|
||||||
* Expand a ~user
|
* Expand a ~user
|
||||||
*/
|
*/
|
||||||
|
#ifndef PHP_WIN32
|
||||||
if ((pwd = getpwnam((char*) patbuf)) == NULL)
|
if ((pwd = getpwnam((char*) patbuf)) == NULL)
|
||||||
return pattern;
|
return pattern;
|
||||||
else
|
else
|
||||||
h = pwd->pw_dir;
|
h = pwd->pw_dir;
|
||||||
|
#else
|
||||||
|
return pattern;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the home directory */
|
/* Copy the home directory */
|
||||||
|
|
|
@ -43,8 +43,6 @@ PHP_RSHUTDOWN_FUNCTION(win32_core_globals)
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
STR_FREE(wg->login_name);
|
|
||||||
|
|
||||||
memset(wg, 0, sizeof(*wg));
|
memset(wg, 0, sizeof(*wg));
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1552,10 +1552,6 @@ SOURCE=..\ext\com\conversion.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\win32\pwd.c
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\win32\readdir.c
|
SOURCE=..\win32\readdir.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@ -1628,10 +1624,6 @@ SOURCE=..\ext\com\php_versioning.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\win32\pwd.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\win32\readdir.h
|
SOURCE=..\win32\readdir.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
|
@ -2391,10 +2391,6 @@ SOURCE=.\md5crypt.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\win32\pwd.c
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\win32\readdir.c
|
SOURCE=..\win32\readdir.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@ -2480,10 +2476,6 @@ SOURCE=..\win32\php_registry.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\win32\pwd.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\win32\readdir.h
|
SOURCE=..\win32\readdir.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
|
|
||||||
/* misc globals for thread-safety under win32 */
|
/* misc globals for thread-safety under win32 */
|
||||||
|
|
||||||
#include "pwd.h"
|
|
||||||
|
|
||||||
typedef struct _php_win32_core_globals php_win32_core_globals;
|
typedef struct _php_win32_core_globals php_win32_core_globals;
|
||||||
|
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
|
@ -40,12 +38,6 @@ struct _php_win32_core_globals {
|
||||||
char *log_header;
|
char *log_header;
|
||||||
HANDLE log_source;
|
HANDLE log_source;
|
||||||
|
|
||||||
/* getpwuid */
|
|
||||||
struct passwd pwd;
|
|
||||||
|
|
||||||
/* getlogin */
|
|
||||||
char *login_name;
|
|
||||||
|
|
||||||
/* time */
|
/* time */
|
||||||
struct timeval starttime;
|
struct timeval starttime;
|
||||||
__int64 lasttime, freq;
|
__int64 lasttime, freq;
|
||||||
|
|
66
win32/pwd.c
66
win32/pwd.c
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| PHP Version 5 |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| Copyright (c) 1997-2006 The PHP Group |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| This source file is subject to version 3.01 of the PHP license, |
|
|
||||||
| that is bundled with this package in the file LICENSE, and is |
|
|
||||||
| available through the world-wide-web at the following url: |
|
|
||||||
| http://www.php.net/license/3_01.txt |
|
|
||||||
| If you did not receive a copy of the PHP license and are unable to |
|
|
||||||
| obtain it through the world-wide-web, please send a note to |
|
|
||||||
| license@php.net so we can mail you a copy immediately. |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| Author: Sterling Hughes <sterling@php.net> |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
#include "php.h" /*php specific */
|
|
||||||
#include <lmaccess.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <lmapibuf.h>
|
|
||||||
#include "pwd.h"
|
|
||||||
#include "grp.h"
|
|
||||||
#include "php_win32_globals.h"
|
|
||||||
|
|
||||||
static char *home_dir = ".";
|
|
||||||
static char *login_shell = "not command.com!";
|
|
||||||
|
|
||||||
struct passwd *
|
|
||||||
getpwnam(char *name)
|
|
||||||
{
|
|
||||||
return (struct passwd *) 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *
|
|
||||||
getlogin()
|
|
||||||
{
|
|
||||||
char name[256];
|
|
||||||
DWORD max_len = 256;
|
|
||||||
TSRMLS_FETCH();
|
|
||||||
|
|
||||||
STR_FREE(PW32G(login_name));
|
|
||||||
GetUserName(name, &max_len);
|
|
||||||
name[max_len] = '\0';
|
|
||||||
PW32G(login_name) = estrdup(name);
|
|
||||||
return PW32G(login_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct passwd *
|
|
||||||
getpwuid(int user_id)
|
|
||||||
{
|
|
||||||
TSRMLS_FETCH();
|
|
||||||
PW32G(pwd).pw_name = getlogin();
|
|
||||||
PW32G(pwd).pw_dir = home_dir;
|
|
||||||
PW32G(pwd).pw_shell = login_shell;
|
|
||||||
PW32G(pwd).pw_uid = 0;
|
|
||||||
|
|
||||||
return &PW32G(pwd);
|
|
||||||
}
|
|
||||||
|
|
38
win32/pwd.h
38
win32/pwd.h
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| PHP Version 5 |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| Copyright (c) 1997-2006 The PHP Group |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| This source file is subject to version 3.01 of the PHP license, |
|
|
||||||
| that is bundled with this package in the file LICENSE, and is |
|
|
||||||
| available through the world-wide-web at the following url: |
|
|
||||||
| http://www.php.net/license/3_01.txt |
|
|
||||||
| If you did not receive a copy of the PHP license and are unable to |
|
|
||||||
| obtain it through the world-wide-web, please send a note to |
|
|
||||||
| license@php.net so we can mail you a copy immediately. |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
| Author: Sterling Hughes <sterling@php.net> |
|
|
||||||
+----------------------------------------------------------------------+
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
#ifndef PWD_H
|
|
||||||
#define PWD_H
|
|
||||||
|
|
||||||
struct passwd {
|
|
||||||
char *pw_name;
|
|
||||||
char *pw_passwd;
|
|
||||||
int pw_uid;
|
|
||||||
int pw_gid;
|
|
||||||
char *pw_comment;
|
|
||||||
char *pw_gecos;
|
|
||||||
char *pw_dir;
|
|
||||||
char *pw_shell;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct passwd *getpwuid(int);
|
|
||||||
extern struct passwd *getpwnam(char *name);
|
|
||||||
extern char *getlogin(void);
|
|
||||||
#endif
|
|
Loading…
Add table
Add a link
Reference in a new issue