Implemented posix_getspnam() function #72

wants to merge 2 commits into


None yet
6 participants

igmar commented May 1, 2012

Added posix_getspnam() function to the posix extension.

@@ -49,6 +49,9 @@
#include <errno.h>
#include <grp.h>
#include <pwd.h>
+# include <shadow.h>

derickr May 1, 2012


Shouldn't there be a test for HAVE_SHADOW_H here instead? (or as well?)


igmar May 1, 2012

AC_CHECK_FUNCS() should take care of that. You either have it and it's in shadow.h, or you don't. I haven't seen it done in a different way. It's not POSIX, so we might run into other implementations.

+int php_posix_spwd_to_array(struct spwd *spw, zval *return_value) /* {{{ */
+ if (NULL == spw)
+ return 0;

derickr May 1, 2012


Please use { and } with if statements.


igmar May 1, 2012

This is a direct copy from php_posix_passwd_to_array(). Should I fix both ?

@@ -1120,6 +1132,28 @@ int php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
/* }}} */
+int php_posix_spwd_to_array(struct spwd *spw, zval *return_value) /* {{{ */

laruence May 1, 2012


declare it with static if you don't want intentionally expose it.


dsp commented May 2, 2012

getspwnam is not part of the POSIX.1, POSIX.1b or POSIX.1c standard.

From the Linux Manpages:

The shadow password database and its associated API are not specified in POSIX.1-2001. However, many other systems provide a similar API.

I'm not sure if this should belong to ext/posix, but then on the other hand there is no suitable other extension to add this function too.

igmar commented May 7, 2012

The reason I've put it in ext/posix because similar functions are also in that extension. It's not POSIX, I agree, but it also serves special use cases. It's harmless in all other cases.

@ghost ghost assigned dsp May 25, 2012

+ array_init(return_value);
+ if (!php_posix_spwd_to_array(spw, return_value)) {
+ zval_dtor(return_value);

dsp May 25, 2012


in case you have ZTS and GETSPANAM_R so

#if defined(ZTS) && defined(HAVE_GETSPNAM_R)

get's execute you have buf allocated. In case php_posix_spwd_to_array fails you are not
freeing buf anymore.


lstrojny commented Jan 6, 2013

@igmar ping


lstrojny commented Jan 14, 2013

@igmar ping again

Comment on behalf of stas at

No response for a year. If this patch is still relevant please update it according to comments and reopen the pull.

@php-pulls php-pulls closed this Jul 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment