php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #77319
Patch chown_gid.patch revision 2018-12-19 06:36 UTC by manuel dot schmitt at manitu dot de

Patch chown_gid.patch for *Directory/Filesystem functions Bug #77319

Patch version 2018-12-19 06:36 UTC

Return to Bug #77319 | Download this patch
Patch Revisions:

Developer: manuel.schmitt@manitu.de

--- php-7.3.0/ext/standard/basic_functions.c	2018/12/19 06:15:02	1.1
+++ php-7.3.0/ext/standard/basic_functions.c	2018/12/19 06:16:28
@@ -1249,6 +1249,7 @@
 ZEND_BEGIN_ARG_INFO(arginfo_chown, 0)
 	ZEND_ARG_INFO(0, filename)
 	ZEND_ARG_INFO(0, user)
+	ZEND_ARG_INFO(0, group)
 ZEND_END_ARG_INFO()
 
 #if HAVE_LCHOWN
@@ -1260,6 +1261,7 @@
 ZEND_BEGIN_ARG_INFO(arginfo_lchown, 0)
 	ZEND_ARG_INFO(0, filename)
 	ZEND_ARG_INFO(0, user)
+	ZEND_ARG_INFO(0, group)
 ZEND_END_ARG_INFO()
 #endif
 
--- php-7.3.0/ext/standard/filestat.c	2018/12/19 06:17:12	1.1
+++ php-7.3.0/ext/standard/filestat.c	2018/12/19 06:32:44
@@ -465,15 +465,19 @@
 	char *filename;
 	size_t filename_len;
 	zval *user;
+	zval *group;
 #if !defined(WINDOWS)
 	uid_t uid;
-	int ret;
+	gid_t gid;
+	int ret, argc = ZEND_NUM_ARGS();
 #endif
 	php_stream_wrapper *wrapper;
 
-	ZEND_PARSE_PARAMETERS_START(2, 2)
+	ZEND_PARSE_PARAMETERS_START(2, 3)
 		Z_PARAM_PATH(filename, filename_len)
 		Z_PARAM_ZVAL(user)
+		Z_PARAM_OPTIONAL
+		Z_PARAM_ZVAL(group)
 	ZEND_PARSE_PARAMETERS_END();
 
 	wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
@@ -496,6 +500,27 @@
 			} else {
 				RETURN_FALSE;
 			}
+
+#if !defined(WINDOWS)	
+			if (argc >= 3) {		
+				if (Z_TYPE_P(group) == IS_LONG) {
+					option = PHP_STREAM_META_GROUP;
+					value = &Z_LVAL_P(group);
+				} else if (Z_TYPE_P(group) == IS_STRING) {
+					option = PHP_STREAM_META_GROUP_NAME;
+					value = Z_STRVAL_P(group);
+				} else {
+					php_error_docref(NULL, E_WARNING, "parameter 3 should be string or int, %s given", zend_zval_type_name(group));
+					RETURN_FALSE;
+				}
+				if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL)) {
+					RETURN_TRUE;
+				} else {
+					RETURN_FALSE;
+				}			
+			}
+#endif
+			
 		} else {
 #if !defined(WINDOWS)
 /* On Windows, we expect regular chown to fail silently by default */
@@ -521,6 +546,27 @@
 		php_error_docref(NULL, E_WARNING, "parameter 2 should be string or int, %s given", zend_zval_type_name(user));
 		RETURN_FALSE;
 	}
+	
+#if !defined(WINDOWS)	
+	if (argc >= 3) {
+		if (Z_TYPE_P(group) == IS_LONG) {
+			gid = (gid_t)Z_LVAL_P(group);
+		} else if (Z_TYPE_P(group) == IS_STRING) {
+			if(php_get_gid_by_name(Z_STRVAL_P(group), &gid) != SUCCESS) {
+				php_error_docref(NULL, E_WARNING, "Unable to find gid for %s", Z_STRVAL_P(group));
+				RETURN_FALSE;
+			}
+		} else {
+			php_error_docref(NULL, E_WARNING, "parameter 3 should be string or int, %s given", zend_zval_type_name(group));
+			RETURN_FALSE;
+		}
+	}		
+	else {
+		gid = -1;
+	}
+#else
+	gid = -1;	
+#endif
 
 	/* Check the basedir */
 	if (php_check_open_basedir(filename)) {
@@ -529,10 +575,10 @@
 
 	if (do_lchown) {
 #if HAVE_LCHOWN
-		ret = VCWD_LCHOWN(filename, uid, -1);
+		ret = VCWD_LCHOWN(filename, uid, gid);
 #endif
 	} else {
-		ret = VCWD_CHOWN(filename, uid, -1);
+		ret = VCWD_CHOWN(filename, uid, gid);
 	}
 	if (ret == -1) {
 		php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 14 17:01:35 2019 UTC