diff options
author | Dmitry Stogov <dmitry@php.net> | 2006-11-10 09:56:37 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2006-11-10 09:56:37 +0000 |
commit | dc34d34230ec152abfe27bf492d206a294359320 (patch) | |
tree | 280b450fbaf33ac84e773e6bf52e654882f6617b | |
parent | 0daf1284cd0fff6d967a2265578427b38100db9f (diff) | |
download | php-git-dc34d34230ec152abfe27bf492d206a294359320.tar.gz |
Simplify the code base as this getpwd() was used only once
-rw-r--r-- | ext/standard/basic_functions.c | 29 | ||||
-rw-r--r-- | main/config.w32.h | 2 | ||||
-rw-r--r-- | main/fopen_wrappers.c | 4 | ||||
-rw-r--r-- | main/php.h | 1 | ||||
-rw-r--r-- | win32/build/config.w32 | 2 | ||||
-rw-r--r-- | win32/build/config.w32.h.in | 2 | ||||
-rw-r--r-- | win32/glob.c | 8 | ||||
-rwxr-xr-x | win32/globals.c | 2 | ||||
-rw-r--r-- | win32/php5dll.dsp | 8 | ||||
-rw-r--r-- | win32/php5dllts.dsp | 8 | ||||
-rwxr-xr-x | win32/php_win32_globals.h | 8 | ||||
-rw-r--r-- | win32/pwd.c | 66 | ||||
-rw-r--r-- | win32/pwd.h | 38 |
13 files changed, 30 insertions, 148 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 596e99c4d9..3d62891751 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4957,7 +4957,6 @@ PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers T PHPAPI char *php_get_current_user() { - struct passwd *pwd; struct stat *pstat; TSRMLS_FETCH(); @@ -4973,15 +4972,29 @@ PHPAPI char *php_get_current_user() if (!pstat) { return ""; - } + } else { +#ifdef PHP_WIN32 + char name[256]; + DWORD len = sizeof(name)-1; - if ((pwd=getpwuid(pstat->st_uid))==NULL) { - return ""; + 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 ((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 } - 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; } /* {{{ proto array error_get_last() U diff --git a/main/config.w32.h b/main/config.w32.h index 6a3a8ca476..554894e7e7 100644 --- a/main/config.w32.h +++ b/main/config.w32.h @@ -156,7 +156,7 @@ #define HAVE_ASSERT_H 1 #define HAVE_FCNTL_H 1 #define HAVE_GRP_H 0 -#define HAVE_PWD_H 1 +#undef HAVE_PWD_H #define HAVE_STRING_H 1 #undef HAVE_SYS_FILE_H #undef HAVE_SYS_SOCKET_H diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 7f22be32ba..b4f302d838 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -45,12 +45,8 @@ #include "php_network.h" #if HAVE_PWD_H -#ifdef PHP_WIN32 -#include "win32/pwd.h" -#else #include <pwd.h> #endif -#endif #include <sys/types.h> #if HAVE_SYS_SOCKET_H diff --git a/main/php.h b/main/php.h index 37635b024a..c4070065c5 100644 --- a/main/php.h +++ b/main/php.h @@ -199,7 +199,6 @@ char *strerror(int); #if HAVE_PWD_H # ifdef PHP_WIN32 -#include "win32/pwd.h" #include "win32/param.h" # else #include <pwd.h> diff --git a/win32/build/config.w32 b/win32/build/config.w32 index e1c84063e0..b6605eff09 100644 --- a/win32/build/config.w32 +++ b/win32/build/config.w32 @@ -281,7 +281,7 @@ ADD_SOURCES("main", "main.c snprintf.c spprintf.c fopen_wrappers.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 unicode_filter.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"); ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c"); diff --git a/win32/build/config.w32.h.in b/win32/build/config.w32.h.in index c73882cc7e..0ca962e701 100644 --- a/win32/build/config.w32.h.in +++ b/win32/build/config.w32.h.in @@ -99,7 +99,7 @@ #define HAVE_ASSERT_H 1 #define HAVE_FCNTL_H 1 #define HAVE_GRP_H 0 -#define HAVE_PWD_H 1 +#undef HAVE_PWD_H #define HAVE_STRING_H 1 #undef HAVE_SYS_FILE_H #undef HAVE_SYS_SOCKET_H diff --git a/win32/glob.c b/win32/glob.c index a8c2cd83e2..b369362c19 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -81,8 +81,6 @@ #include <dirent.h> #include <pwd.h> #include <unistd.h> -#else -#include "win32/pwd.h" #endif #include <errno.h> #include "glob.h" @@ -359,7 +357,9 @@ globtilde(pattern, patbuf, patbuf_len, pglob) size_t patbuf_len; glob_t *pglob; { +#ifndef PHP_WIN32 struct passwd *pwd; +#endif char *h; const Char *p; Char *b, *eb; @@ -399,10 +399,14 @@ globtilde(pattern, patbuf, patbuf_len, pglob) /* * Expand a ~user */ +#ifndef PHP_WIN32 if ((pwd = getpwnam((char*) patbuf)) == NULL) return pattern; else h = pwd->pw_dir; +#else + return pattern; +#endif } /* Copy the home directory */ diff --git a/win32/globals.c b/win32/globals.c index eee53cb5a9..ae9120095c 100755 --- a/win32/globals.c +++ b/win32/globals.c @@ -43,8 +43,6 @@ PHP_RSHUTDOWN_FUNCTION(win32_core_globals) #endif ; - STR_FREE(wg->login_name); - memset(wg, 0, sizeof(*wg)); return SUCCESS; } diff --git a/win32/php5dll.dsp b/win32/php5dll.dsp index 21486fdfd4..9a3bfd57d5 100644 --- a/win32/php5dll.dsp +++ b/win32/php5dll.dsp @@ -1540,10 +1540,6 @@ SOURCE=..\ext\com\conversion.c # End Source File
# Begin Source File
-SOURCE=..\win32\pwd.c
-# End Source File
-# Begin Source File
-
SOURCE=..\win32\readdir.c
# End Source File
# Begin Source File
@@ -1616,10 +1612,6 @@ SOURCE=..\ext\com\php_versioning.h # End Source File
# Begin Source File
-SOURCE=..\win32\pwd.h
-# End Source File
-# Begin Source File
-
SOURCE=..\win32\readdir.h
# End Source File
# Begin Source File
diff --git a/win32/php5dllts.dsp b/win32/php5dllts.dsp index eb8966c99b..e6569a774c 100644 --- a/win32/php5dllts.dsp +++ b/win32/php5dllts.dsp @@ -2032,10 +2032,6 @@ SOURCE=.\md5crypt.c # End Source File
# Begin Source File
-SOURCE=..\win32\pwd.c
-# End Source File
-# Begin Source File
-
SOURCE=..\win32\readdir.c
# End Source File
# Begin Source File
@@ -2096,10 +2092,6 @@ SOURCE=..\win32\php_registry.h # End Source File
# Begin Source File
-SOURCE=..\win32\pwd.h
-# End Source File
-# Begin Source File
-
SOURCE=..\win32\readdir.h
# End Source File
# Begin Source File
diff --git a/win32/php_win32_globals.h b/win32/php_win32_globals.h index 89caed1a37..c130d5bc50 100755 --- a/win32/php_win32_globals.h +++ b/win32/php_win32_globals.h @@ -23,8 +23,6 @@ /* misc globals for thread-safety under win32 */ -#include "pwd.h" - typedef struct _php_win32_core_globals php_win32_core_globals; #ifdef ZTS @@ -40,12 +38,6 @@ struct _php_win32_core_globals { char *log_header; HANDLE log_source; - /* getpwuid */ - struct passwd pwd; - - /* getlogin */ - char *login_name; - /* time */ struct timeval starttime; __int64 lasttime, freq; diff --git a/win32/pwd.c b/win32/pwd.c deleted file mode 100644 index 092740e249..0000000000 --- a/win32/pwd.c +++ /dev/null @@ -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); -} - diff --git a/win32/pwd.h b/win32/pwd.h deleted file mode 100644 index 597f60c48c..0000000000 --- a/win32/pwd.h +++ /dev/null @@ -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 |