iliaa Wed Nov 29 23:46:26 2006 UTC
Modified files:
/php-src/ext/standard filestat.c
Log:
MFB: Fixed bug #39648 (Implementation of PHP functions chown() and chgrp()
are not thread safe).
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/filestat.c?r1=1.151&r2=1.152&diff_format=u
Index: php-src/ext/standard/filestat.c
diff -u php-src/ext/standard/filestat.c:1.151
php-src/ext/standard/filestat.c:1.152
--- php-src/ext/standard/filestat.c:1.151 Mon Nov 6 14:55:14 2006
+++ php-src/ext/standard/filestat.c Wed Nov 29 23:46:25 2006
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: filestat.c,v 1.151 2006/11/06 14:55:14 dmitry Exp $ */
+/* $Id: filestat.c,v 1.152 2006/11/29 23:46:25 iliaa Exp $ */
#include "php.h"
#include "fopen_wrappers.h"
@@ -417,14 +417,29 @@
if (Z_TYPE_P(group) == IS_LONG) {
gid = (gid_t)Z_LVAL_P(group);
} else {
- struct group *gr;
+#if HAVE_GETGRNAM_R
+ struct group gr;
+ struct group *retgrptr;
+ int grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+ char *grbuf = emalloc(grbuflen);
convert_to_string(group);
+ if (getgrnam_r(Z_STRVAL_PP(group), &gr, grbuf, grbuflen,
&retgrptr) != 0 || retgrptr == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to
find gid for %s", Z_STRVAL_PP(group));
+ efree(grbuf);
+ RETURN_FALSE;
+ }
+ efree(grbuf);
+ gid = gr.gr_gid;
+#else
+ struct group *gr;
+ convert_to_string(group);
if (!(gr = getgrnam(Z_STRVAL_P(group)))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to
find gid for %s", Z_STRVAL_P(group));
RETURN_FALSE;
}
gid = gr->gr_gid;
+#endif
}
if (filename_type == IS_UNICODE) {
@@ -506,6 +521,21 @@
if (Z_TYPE_P(user) == IS_LONG) {
uid = (uid_t)Z_LVAL_P(user);
} else {
+#ifdef HAVE_GETPWNAM_R
+ struct passwd pw;
+ struct passwd *retpwptr = NULL;
+ int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *pwbuf = emalloc(pwbuflen);
+
+ convert_to_string(user);
+ if (getpwnam_r(Z_STRVAL_PP(user), &pw, pwbuf, pwbuflen,
&retpwptr) != 0 || retpwptr == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to
find uid for %s", Z_STRVAL_PP(user));
+ efree(pwbuf);
+ RETURN_FALSE;
+ }
+ efree(pwbuf);
+ uid = pw.pw_uid;
+#else
struct passwd *pw;
convert_to_string(user);
@@ -514,6 +544,7 @@
RETURN_FALSE;
}
uid = pw->pw_uid;
+#endif
}
if (filename_type == IS_UNICODE) {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php