php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #61089
Patch posix_getgrouplist revision 2012-02-14 19:50 UTC by dab1818 at gmail dot com

Patch posix_getgrouplist for POSIX related Bug #61089

Patch version 2012-02-14 19:50 UTC

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

Developer: dab1818@gmail.com

--- ext/posix/config.m4.orig	2009-01-21 23:23:03.000000000 +0400
+++ ext/posix/config.m4	2010-01-24 18:52:05.000000000 +0400
@@ -11,7 +11,7 @@
 
   AC_CHECK_HEADERS(sys/mkdev.h)
 
-  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r)
+  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups getgrouplist makedev initgroups getpwuid_r getgrgid_r)
 
   AC_MSG_CHECKING([for working ttyname_r() implementation])
   AC_TRY_RUN([
--- ext/posix/php_posix.h.orig	2008-12-31 15:17:49.000000000 +0400
+++ ext/posix/php_posix.h	2010-01-24 18:51:47.000000000 +0400
@@ -57,6 +57,9 @@
 #ifdef HAVE_GETGROUPS
 PHP_FUNCTION(posix_getgroups);
 #endif
+#ifdef HAVE_GETGROUPLIST
+PHP_FUNCTION(posix_getgrouplist);
+#endif
 #ifdef HAVE_GETLOGIN
 PHP_FUNCTION(posix_getlogin);
 #endif
--- ext/posix/posix.c.orig	2009-08-06 16:11:15.000000000 +0500
+++ ext/posix/posix.c	2010-01-24 18:58:36.000000000 +0400
@@ -82,6 +82,9 @@
 #ifdef HAVE_GETGROUPS
 	PHP_FE(posix_getgroups,	NULL)
 #endif
+#ifdef HAVE_GETGROUPLIST
+	PHP_FE(posix_getgrouplist,NULL)
+#endif
 #ifdef HAVE_GETLOGIN
 	PHP_FE(posix_getlogin,	NULL)
 #endif
@@ -358,6 +361,52 @@
 #endif
 /* }}} */
 
+/* {{{ proto array posix_getgrouplist(string name, int base_group_id)
+   Get list of groups to which a user belongs.
+   (This function is non-standard; it appears on most BSDs) */
+#ifdef HAVE_GETGROUPLIST
+PHP_FUNCTION(posix_getgrouplist)
+{
+	gid_t  *gidlist;
+	int    result;
+	int    i;
+	int    ngroups;
+
+	long basegid;
+	char *name;
+	int name_len;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &name, &name_len, &basegid) == FAILURE) {
+		RETURN_FALSE;
+	}
+
+	if (name_len == 0) {
+		RETURN_FALSE;
+	}
+
+	ngroups = NGROUPS_MAX - 1;
+	gidlist = emalloc(ngroups * sizeof (gid_t));
+	if (gidlist == NULL) {
+		RETURN_FALSE;
+	}
+
+	if ((result = getgrouplist(name, basegid, gidlist, &ngroups)) < 0) {
+		POSIX_G(last_error) = errno;
+		efree(gidlist);
+		RETURN_FALSE;
+	}
+
+	array_init(return_value);
+
+	for (i=0; i<ngroups; i++) {
+		add_next_index_long(return_value, gidlist[i]);
+	}
+
+	efree(gidlist);
+}
+#endif
+/* }}} */
+
 /* {{{ proto string posix_getlogin(void) 
    Get user name (POSIX.1, 4.2.4) */
 #ifdef HAVE_GETLOGIN
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 21:01:28 2024 UTC