]> granicus.if.org Git - php/commitdiff
Simplify the code base as this getpwd() was used only once
authorDmitry Stogov <dmitry@php.net>
Fri, 10 Nov 2006 09:56:37 +0000 (09:56 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 10 Nov 2006 09:56:37 +0000 (09:56 +0000)
13 files changed:
ext/standard/basic_functions.c
main/config.w32.h
main/fopen_wrappers.c
main/php.h
win32/build/config.w32
win32/build/config.w32.h.in
win32/glob.c
win32/globals.c
win32/php5dll.dsp
win32/php5dllts.dsp
win32/php_win32_globals.h
win32/pwd.c [deleted file]
win32/pwd.h [deleted file]

index 596e99c4d9ffc21b412f0c6e0ddd5a21fd54bc58..3d628917510f145acc0be4737af8fc924b60fa84 100644 (file)
@@ -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
index 6a3a8ca476d46a964a0669e3357e60f2232525b0..554894e7e73582322c9280b74292f4d696819889 100644 (file)
 #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
index 7f22be32bab888a6ab054ca0ccf8782f9036af90..b4f302d8383848e77c6f392b77870f2f2c2b5539 100644 (file)
 #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
index 37635b024af5a2c83f99202d3f8cda05f0ef8c14..c4070065c55a19b00400c329e69fe987c3acedf4 100644 (file)
@@ -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>
index e1c84063e0eac884941f454e6ee73696be05711c..b6605eff096e443363a6511bc021f307fc3f1ec0 100644 (file)
@@ -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");
index c73882cc7eeb31a130d12ded8cfc71932fc4c5f4..0ca962e7019b5c9602b13d170c1d1388f12dc7db 100644 (file)
@@ -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
index a8c2cd83e2208ddb20efc0188038c3ff0950113c..b369362c1914fdda26a8d73b921bb476eaba8309 100644 (file)
@@ -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 */
index eee53cb5a9f668e5c7e3f102207f6879e8d1c299..ae9120095c8f5e3774ed007565a22098fb45a1e1 100755 (executable)
@@ -43,8 +43,6 @@ PHP_RSHUTDOWN_FUNCTION(win32_core_globals)
 #endif
                ;
 
-       STR_FREE(wg->login_name);
-       
        memset(wg, 0, sizeof(*wg));
        return SUCCESS;
 }
index 21486fdfd496054fc402923ff1d6d454abffbe22..9a3bfd57d5cbcd56521922c36e5f60db659d5829 100644 (file)
@@ -1540,10 +1540,6 @@ SOURCE=..\ext\com\conversion.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\win32\pwd.c\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\win32\readdir.c\r
 # End Source File\r
 # Begin Source File\r
@@ -1616,10 +1612,6 @@ SOURCE=..\ext\com\php_versioning.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\win32\pwd.h\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\win32\readdir.h\r
 # End Source File\r
 # Begin Source File\r
index eb8966c99bed68d5b2876156c8477a62a1ca4073..e6569a774c71be89c702f50d11702b51bffc77a6 100644 (file)
@@ -2032,10 +2032,6 @@ SOURCE=.\md5crypt.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\win32\pwd.c\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\win32\readdir.c\r
 # End Source File\r
 # Begin Source File\r
@@ -2096,10 +2092,6 @@ SOURCE=..\win32\php_registry.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\win32\pwd.h\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\win32\readdir.h\r
 # End Source File\r
 # Begin Source File\r
index 89caed1a374f70efce760aebcfc269bc770fe3de..c130d5bc507b523ec1993196ec3f675cf2e97300 100755 (executable)
@@ -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 (file)
index 092740e..0000000
+++ /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 (file)
index 597f60c..0000000
+++ /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