Skip to content

Commit 9fd2b6d

Browse files
committed
Simplify the code base as this getpwd() was used only once
1 parent 126be8e commit 9fd2b6d

13 files changed

+31
-149
lines changed

main/config.w32.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
#define HAVE_ASSERT_H 1
163163
#define HAVE_FCNTL_H 1
164164
#define HAVE_GRP_H 0
165-
#define HAVE_PWD_H 1
165+
#undef HAVE_PWD_H
166166
#define HAVE_STRING_H 1
167167
#undef HAVE_SYS_FILE_H
168168
#undef HAVE_SYS_SOCKET_H

main/fopen_wrappers.c

-4
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@
4646
#include "php_network.h"
4747

4848
#if HAVE_PWD_H
49-
#ifdef PHP_WIN32
50-
#include "win32/pwd.h"
51-
#else
5249
#include <pwd.h>
5350
#endif
54-
#endif
5551

5652
#include <sys/types.h>
5753
#if HAVE_SYS_SOCKET_H

main/php.h

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ char *strerror(int);
199199

200200
#if HAVE_PWD_H
201201
# ifdef PHP_WIN32
202-
#include "win32/pwd.h"
203202
#include "win32/param.h"
204203
# else
205204
#include <pwd.h>

main/safe_mode.c

+22-9
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ PHPAPI int php_checkuid(const char *filename, const char *fopen_mode, int mode)
197197

198198
PHPAPI char *php_get_current_user()
199199
{
200-
struct passwd *pwd;
201200
struct stat *pstat;
202201
TSRMLS_FETCH();
203202

@@ -213,15 +212,29 @@ PHPAPI char *php_get_current_user()
213212

214213
if (!pstat) {
215214
return "";
216-
}
215+
} else {
216+
#ifdef PHP_WIN32
217+
char name[256];
218+
DWORD len = sizeof(name)-1;
217219

218-
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
219-
return "";
220-
}
221-
SG(request_info).current_user_length = strlen(pwd->pw_name);
222-
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
223-
224-
return SG(request_info).current_user;
220+
if (!GetUserName(name, &len)) {
221+
return "";
222+
}
223+
name[len] = '\0';
224+
SG(request_info).current_user_length = len;
225+
SG(request_info).current_user = estrndup(name, len);
226+
return SG(request_info).current_user;
227+
#else
228+
struct passwd *pwd;
229+
230+
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
231+
return "";
232+
}
233+
SG(request_info).current_user_length = strlen(pwd->pw_name);
234+
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
235+
return SG(request_info).current_user;
236+
#endif
237+
}
225238
}
226239

227240
/*

win32/build/config.w32

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ ADD_SOURCES("main", "main.c snprintf.c spprintf.c safe_mode.c fopen_wrappers.c \
264264
ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
265265
userspace.c transports.c xp_socket.c mmap.c");
266266

267-
ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c pwd.c readdir.c \
267+
ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c readdir.c \
268268
registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c");
269269

270270
ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c");

win32/build/config.w32.h.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
#define HAVE_ASSERT_H 1
101101
#define HAVE_FCNTL_H 1
102102
#define HAVE_GRP_H 0
103-
#define HAVE_PWD_H 1
103+
#undef HAVE_PWD_H
104104
#define HAVE_STRING_H 1
105105
#undef HAVE_SYS_FILE_H
106106
#undef HAVE_SYS_SOCKET_H

win32/glob.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
#include <dirent.h>
8282
#include <pwd.h>
8383
#include <unistd.h>
84-
#else
85-
#include "win32/pwd.h"
8684
#endif
8785
#include <errno.h>
8886
#include "glob.h"
@@ -359,7 +357,9 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
359357
size_t patbuf_len;
360358
glob_t *pglob;
361359
{
360+
#ifndef PHP_WIN32
362361
struct passwd *pwd;
362+
#endif
363363
char *h;
364364
const Char *p;
365365
Char *b, *eb;
@@ -399,10 +399,14 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
399399
/*
400400
* Expand a ~user
401401
*/
402+
#ifndef PHP_WIN32
402403
if ((pwd = getpwnam((char*) patbuf)) == NULL)
403404
return pattern;
404405
else
405406
h = pwd->pw_dir;
407+
#else
408+
return pattern;
409+
#endif
406410
}
407411

408412
/* Copy the home directory */

win32/globals.c

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ PHP_RSHUTDOWN_FUNCTION(win32_core_globals)
4343
#endif
4444
;
4545

46-
STR_FREE(wg->login_name);
47-
4846
memset(wg, 0, sizeof(*wg));
4947
return SUCCESS;
5048
}

win32/php5dll.dsp

-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

win32/php5dllts.dsp

-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

win32/php_win32_globals.h

-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
/* misc globals for thread-safety under win32 */
2525

26-
#include "pwd.h"
27-
2826
typedef struct _php_win32_core_globals php_win32_core_globals;
2927

3028
#ifdef ZTS
@@ -40,12 +38,6 @@ struct _php_win32_core_globals {
4038
char *log_header;
4139
HANDLE log_source;
4240

43-
/* getpwuid */
44-
struct passwd pwd;
45-
46-
/* getlogin */
47-
char *login_name;
48-
4941
/* time */
5042
struct timeval starttime;
5143
__int64 lasttime, freq;

win32/pwd.c

-66
This file was deleted.

win32/pwd.h

-38
This file was deleted.

0 commit comments

Comments
 (0)