Browse Source

Simplify the code base as this getpwd() was used only once

experimental/5.2-WITH_DRCP
Dmitry Stogov 20 years ago
parent
commit
9fd2b6deb4
  1. 2
      main/config.w32.h
  2. 4
      main/fopen_wrappers.c
  3. 1
      main/php.h
  4. 31
      main/safe_mode.c
  5. 2
      win32/build/config.w32
  6. 2
      win32/build/config.w32.h.in
  7. 8
      win32/glob.c
  8. 2
      win32/globals.c
  9. 8
      win32/php5dll.dsp
  10. 8
      win32/php5dllts.dsp
  11. 8
      win32/php_win32_globals.h
  12. 66
      win32/pwd.c
  13. 38
      win32/pwd.h

2
main/config.w32.h

@ -162,7 +162,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

4
main/fopen_wrappers.c

@ -46,12 +46,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

1
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>

31
main/safe_mode.c

@ -197,7 +197,6 @@ PHPAPI int php_checkuid(const char *filename, const char *fopen_mode, int mode)
PHPAPI char *php_get_current_user()
{
struct passwd *pwd;
struct stat *pstat;
TSRMLS_FETCH();
@ -213,15 +212,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 "";
}
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;
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
}
}
/*

2
win32/build/config.w32

@ -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 \
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");
ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c");

2
win32/build/config.w32.h.in

@ -100,7 +100,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

8
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 */

2
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;
}

8
win32/php5dll.dsp

@ -1552,10 +1552,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
@ -1628,10 +1624,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

8
win32/php5dllts.dsp

@ -2391,10 +2391,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
@ -2480,10 +2476,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

8
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;

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

@ -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…
Cancel
Save