cvs: pecl /pam CREDITS README pam.c php_pam.h /pam/tests pam.inc

From: Date: Mon, 13 Nov 2006 08:12:39 +0000
Subject: cvs: pecl /pam CREDITS README pam.c php_pam.h /pam/tests pam.inc
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6629@lists.php.net to get a copy of this message
mikl Mon Nov 13 08:12:39 2006 UTC Modified files: /pecl/pam CREDITS README pam.c php_pam.h /pecl/pam/tests pam.inc Log: Removed some mysterious DOS linefeeds

http://cvs.php.net/viewvc.cgi/pecl/pam/CREDITS?r1=1.1&r2=1.2&diff_format=u Index: pecl/pam/CREDITS diff -u pecl/pam/CREDITS:1.1 pecl/pam/CREDITS:1.2 --- pecl/pam/CREDITS:1.1 Mon Nov 13 07:47:40 2006 +++ pecl/pam/CREDITS Mon Nov 13 08:12:39 2006 @@ -1,3 +1,3 @@ -PAM -Mikael Johansson +PAM +Mikael Johansson Chad Cunningham \ No newline at end of file http://cvs.php.net/viewvc.cgi/pecl/pam/README?r1=1.2&r2=1.3&diff_format=u Index: pecl/pam/README diff -u pecl/pam/README:1.2 pecl/pam/README:1.3 --- pecl/pam/README:1.2 Mon Nov 13 07:58:47 2006 +++ pecl/pam/README Mon Nov 13 08:12:39 2006 @@ -1,106 +1,106 @@ - - bool pam_auth(string $username, string $password [, string &$error ]) - bool pam_chpass(string $username, string $oldpassword, string $newpassword [, string &$error ]) - - -INSTALLATION - - For pam_auth to work, pam must know about the php service. - - For the module itself, the only real configuration is the servicename. By - default, this is set to php. It can be changed by adding the following to your - php.ini: - - pam.servicename = "php"; - - Next, you'll need to create a pam service file for php. If you are on linux, - you'll need to create the file /etc/pam.d/php. You can copy another one to work - off of (/etc/pam.d/login is a good choice). - - Some examples that should work: - - on linux: - -# /etc/pam.d/php -# -# note: both an auth and account entry are required - -auth sufficient /lib/security/pam_pwdb.so shadow nodelay -account sufficient /lib/security/pam_pwdb.so - - on solaris: - -# add to /etc/pam.conf - -php auth required /usr/lib/security/pam_unix.so.1 -php account required /usr/lib/security/pam_unix.so.1 - - These would authenticate out of the unix password and shadow file. However - please checking other /etc/pam.d/ entries, as the libraries these examples - point to may not be correct. - - -FAQ - - * What is PAM? - - PAM stands for Pluggable Authentication Module. It is a system that abstracts - user authentication to allow arbitrary modules to handle the real work. In this - way, pam enabled services can use a variety of complex authentication schemes - without modifying the applications. For more Information, and available - modules, see http://www.kernel.org/pub/linux/libs/pam/. - - - * Why would I want to use PAM from PHP? - - PAM gives you very flexible control over authentication. As an example, there - are PAM modules that will authenticate against a local shadow or password file, - a Windows NT domain, an SQL database, LDAP, Kerberos, Radius, and more. In - addition, pam modules can give you the ability to have restrictions on the - authentication, such as the pam_tally module which limits the number of login - attempts, and the pam_listfile which let's you restrict access to a list of - users. Please note, using pam does not mean you can securely authenticate - users, it simply gives you the ability to do so with proper configuration and - planning. - - - * How can I get pam? - - If you are running linux or solaris, you already have it! Linux and Solaris - both natively use pam for all authentication, so you're are all set. If you are - on other systems, well, you're on your own. I have no idea what PAM has been - ported too... - - - * I'm getting an Authentication Failure error, why? - - The most likely reason for this is that you are trying to authenticate via a - local shadow file and you do not have permission to do so. The PAM modules - handling shadow authentication (used on Linux and Solaris) require that the - application have permission to read the shadow file (makes sense, eh?). If you - are running php as a cgi or as a webserver module, it is executed as your - webservers user and group. - - By default, most Linux and Solaris systems are configured to only allow the root - user to read the shadow file. The recommended - way around this is to change permissions on the shadow file so that it is group - readable, and chgrp the file to the a group that the webserver is in. Before - doing this, you should give it some serious thought as allowing your webserver - to read the shadow file gives hackers another way to crack away at your system. - - If you decide to enable this, I stronly suggest usage of the pam_tally module - to limit failed logins to a reasonable number of attempts, and one of the other - modules which will allow you to block root and other system users. - - - * The pam_auth function doesn't return anything, whattup? - - Did you remember to create an entry in the pam configuration for the php - service? - - - * Logs indicate pam authenticated the user, but the function doesn't return - true, what gives? - - Make sure your pam configuration has an entry for both auth and account, if you - do not have both, it will not work. + + bool pam_auth(string $username, string $password [, string &$error ]) + bool pam_chpass(string $username, string $oldpassword, string $newpassword [, string &$error ]) + + +INSTALLATION + + For pam_auth to work, pam must know about the php service. + + For the module itself, the only real configuration is the servicename. By + default, this is set to php. It can be changed by adding the following to your + php.ini: + + pam.servicename = "php"; + + Next, you'll need to create a pam service file for php. If you are on linux, + you'll need to create the file /etc/pam.d/php. You can copy another one to work + off of (/etc/pam.d/login is a good choice). + + Some examples that should work: + + on linux: + +# /etc/pam.d/php +# +# note: both an auth and account entry are required + +auth sufficient /lib/security/pam_pwdb.so shadow nodelay +account sufficient /lib/security/pam_pwdb.so + + on solaris: + +# add to /etc/pam.conf + +php auth required /usr/lib/security/pam_unix.so.1 +php account required /usr/lib/security/pam_unix.so.1 + + These would authenticate out of the unix password and shadow file. However + please checking other /etc/pam.d/ entries, as the libraries these examples + point to may not be correct. + + +FAQ + + * What is PAM? + + PAM stands for Pluggable Authentication Module. It is a system that abstracts + user authentication to allow arbitrary modules to handle the real work. In this + way, pam enabled services can use a variety of complex authentication schemes + without modifying the applications. For more Information, and available + modules, see http://www.kernel.org/pub/linux/libs/pam/. + + + * Why would I want to use PAM from PHP? + + PAM gives you very flexible control over authentication. As an example, there + are PAM modules that will authenticate against a local shadow or password file, + a Windows NT domain, an SQL database, LDAP, Kerberos, Radius, and more. In + addition, pam modules can give you the ability to have restrictions on the + authentication, such as the pam_tally module which limits the number of login + attempts, and the pam_listfile which let's you restrict access to a list of + users. Please note, using pam does not mean you can securely authenticate + users, it simply gives you the ability to do so with proper configuration and + planning. + + + * How can I get pam? + + If you are running linux or solaris, you already have it! Linux and Solaris + both natively use pam for all authentication, so you're are all set. If you are + on other systems, well, you're on your own. I have no idea what PAM has been + ported too... + + + * I'm getting an Authentication Failure error, why? + + The most likely reason for this is that you are trying to authenticate via a + local shadow file and you do not have permission to do so. The PAM modules + handling shadow authentication (used on Linux and Solaris) require that the + application have permission to read the shadow file (makes sense, eh?). If you + are running php as a cgi or as a webserver module, it is executed as your + webservers user and group. + + By default, most Linux and Solaris systems are configured to only allow the root + user to read the shadow file. The recommended + way around this is to change permissions on the shadow file so that it is group + readable, and chgrp the file to the a group that the webserver is in. Before + doing this, you should give it some serious thought as allowing your webserver + to read the shadow file gives hackers another way to crack away at your system. + + If you decide to enable this, I stronly suggest usage of the pam_tally module + to limit failed logins to a reasonable number of attempts, and one of the other + modules which will allow you to block root and other system users. + + + * The pam_auth function doesn't return anything, whattup? + + Did you remember to create an entry in the pam configuration for the php + service? + + + * Logs indicate pam authenticated the user, but the function doesn't return + true, what gives? + + Make sure your pam configuration has an entry for both auth and account, if you + do not have both, it will not work. http://cvs.php.net/viewvc.cgi/pecl/pam/pam.c?r1=1.1&r2=1.2&diff_format=u Index: pecl/pam/pam.c diff -u pecl/pam/pam.c:1.1 pecl/pam/pam.c:1.2 --- pecl/pam/pam.c:1.1 Mon Nov 13 07:47:40 2006 +++ pecl/pam/pam.c Mon Nov 13 08:12:39 2006 @@ -1,304 +1,304 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Mikael Johansson <mikael AT synd DOT info> | - | Chad Cunningham | - +----------------------------------------------------------------------+ -*/ - -/* $Id: pam.c,v 1.1 2006/11/13 07:47:40 mikl Exp $ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "php_pam.h" -#include <security/pam_appl.h> - -ZEND_DECLARE_MODULE_GLOBALS(pam) - -/* {{{ pam_functions[] - */ -zend_function_entry pam_functions[] = { - PHP_FE(pam_auth, NULL) - PHP_FE(pam_chpass, NULL) - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ pam_module_entry - */ -zend_module_entry pam_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - "pam", - pam_functions, - PHP_MINIT(pam), - PHP_MSHUTDOWN(pam), - NULL, /* Replace with NULL if there's nothing to do at request start */ - NULL, /* Replace with NULL if there's nothing to do at request end */ - PHP_MINFO(pam), -#if ZEND_MODULE_API_NO >= 20010901 - NO_VERSION_YET, /* Replace with version number for your extension */ -#endif - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - -#ifdef COMPILE_DL_PAM -ZEND_GET_MODULE(pam) -#endif - -/* {{{ PHP_INI - */ -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("pam.servicename", "php", PHP_INI_ALL, OnUpdateString, servicename, zend_pam_globals, pam_globals) -PHP_INI_END() -/* }}} */ - -/* {{{ php_pam_init_globals - */ -static void php_pam_init_globals(zend_pam_globals *pam_globals) -{ - pam_globals->servicename = NULL; -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(pam) -{ - ZEND_INIT_MODULE_GLOBALS(pam, php_pam_init_globals, NULL); - REGISTER_INI_ENTRIES(); - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION - */ -PHP_MSHUTDOWN_FUNCTION(pam) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(pam) -{ - php_info_print_table_start(); - php_info_print_table_header(2, "PAM support", "enabled"); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); -} -/* }}} */ - -/* - * auth_pam_talker: supply authentication information to PAM when asked - * - * Assumptions: - * A password is asked for by requesting input without echoing - * A username is asked for by requesting input _with_ echoing - * - */ -static -int auth_pam_talker(int num_msg, - const struct pam_message ** msg, - struct pam_response ** resp, - void *appdata_ptr) -{ - unsigned short i = 0; - pam_auth_t *userinfo = (pam_auth_t *) appdata_ptr; - struct pam_response *response = 0; - - /* parameter sanity checking */ - if (!resp || !msg || !userinfo) - return PAM_CONV_ERR; - - /* allocate memory to store response */ - response = malloc(num_msg * sizeof(struct pam_response)); - if (!response) - return PAM_CONV_ERR; - - /* copy values */ - for (i = 0; i < num_msg; i++) { - /* initialize to safe values */ - response[i].resp_retcode = 0; - response[i].resp = 0; - - /* select response based on requested output style */ - switch (msg[i]->msg_style) { - case PAM_PROMPT_ECHO_ON: - /* on memory allocation failure, auth fails */ - response[i].resp = strdup(userinfo->name); - break; - case PAM_PROMPT_ECHO_OFF: - response[i].resp = strdup(userinfo->pw); - break; - default: - if (response) - free(response); - return PAM_CONV_ERR; - } - } - /* everything okay, set PAM response values */ - *resp = response; - return PAM_SUCCESS; -} - -/* - * chpass_pam_talker: supply authentication information to PAM when asked - * - * Assumptions: - * A password is asked for by requesting input without echoing - * A username is asked for by requesting input _with_ echoing - * - */ -static -int chpass_pam_talker(int num_msg, - const struct pam_message ** msg, - struct pam_response ** resp, - void *appdata_ptr) -{ - unsigned short i = 0; - pam_chpass_t *userinfo = (pam_chpass_t *) appdata_ptr; - struct pam_response *response = 0; - - /* parameter sanity checking */ - if (!resp || !msg || !userinfo) - return PAM_CONV_ERR; - - /* allocate memory to store response */ - response = malloc(num_msg * sizeof(struct pam_response)); - if (!response) - return PAM_CONV_ERR; - - /* copy values */ - for (i = 0; i < num_msg; i++) { - /* initialize to safe values */ - response[i].resp_retcode = 0; - response[i].resp = 0; - - /* select response based on requested output style */ - switch (msg[i]->msg_style) { - case PAM_PROMPT_ECHO_ON: - /* on memory allocation failure, auth fails */ - response[i].resp = strdup(userinfo->name); - break; - case PAM_PROMPT_ECHO_OFF: - if (userinfo->count++) { - response[i].resp = strdup(userinfo->newpw); - } - else { - response[i].resp = strdup(userinfo->oldpw); - } - break; - default: - if (response) - free(response); - return PAM_CONV_ERR; - } - } - /* everything okay, set PAM response values */ - *resp = response; - return PAM_SUCCESS; -} - -/* {{{ proto bool pam_auth( string host, string password [, string &status ]) - Authenticates a user and returns TRUE on success, FALSE on failure */ -PHP_FUNCTION(pam_auth) -{ - char *username, *password; - int username_len, password_len; - zval *status = NULL; - - pam_auth_t userinfo = {NULL, NULL}; - struct pam_conv conv_info = {&auth_pam_talker, (void *) &userinfo}; - pam_handle_t *pamh = NULL; - int result; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &username, &username_len, &password, &password_len, &status) == FAILURE) { - return; - } - - userinfo.name = username; - userinfo.pw = password; - - if ((result = pam_start(PAM_G(servicename), userinfo.name, &conv_info, &pamh)) != PAM_SUCCESS || - (result = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS || - (result = pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) { - if (status) { - zval_dtor(status); - ZVAL_STRING(status, (char *) pam_strerror(pamh, result), 1); - } - pam_end(pamh, result); - RETURN_FALSE; - } - - pam_end(pamh, PAM_SUCCESS); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool pam_auth( string host, string password [, string &status ]) - Changes a users password and returns TRUE on success, FALSE on failure */ -PHP_FUNCTION(pam_chpass) -{ - char *username, *oldpass, *newpass; - int username_len, oldpass_len, newpass_len; - zval *status = NULL; - - pam_chpass_t userinfo = {NULL, NULL, NULL, 0}; - struct pam_conv conv_info = {&chpass_pam_talker, (void *) &userinfo}; - pam_handle_t *pamh = NULL; - int result; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|z", &username, &username_len, &oldpass, &oldpass_len, &newpass, &newpass_len, &status) == FAILURE) { - return; - } - - userinfo.name = username; - userinfo.oldpw = oldpass; - userinfo.newpw = newpass; - - if ((result = pam_start(PAM_G(servicename), userinfo.name, &conv_info, &pamh)) != PAM_SUCCESS || - (result = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS || - (result = pam_chauthtok(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) { - if (status) { - zval_dtor(status); - ZVAL_STRING(status, (char *) pam_strerror(pamh, result), 1); - } - pam_end(pamh, PAM_SUCCESS); - RETURN_FALSE; - } - - pam_end(pamh, PAM_SUCCESS); - RETURN_TRUE; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Mikael Johansson <mikael AT synd DOT info> | + | Chad Cunningham | + +----------------------------------------------------------------------+ +*/ + +/* $Id: pam.c,v 1.2 2006/11/13 08:12:39 mikl Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" +#include "php_pam.h" +#include <security/pam_appl.h> + +ZEND_DECLARE_MODULE_GLOBALS(pam) + +/* {{{ pam_functions[] + */ +zend_function_entry pam_functions[] = { + PHP_FE(pam_auth, NULL) + PHP_FE(pam_chpass, NULL) + {NULL, NULL, NULL} +}; +/* }}} */ + +/* {{{ pam_module_entry + */ +zend_module_entry pam_module_entry = { +#if ZEND_MODULE_API_NO >= 20010901 + STANDARD_MODULE_HEADER, +#endif + "pam", + pam_functions, + PHP_MINIT(pam), + PHP_MSHUTDOWN(pam), + NULL, /* Replace with NULL if there's nothing to do at request start */ + NULL, /* Replace with NULL if there's nothing to do at request end */ + PHP_MINFO(pam), +#if ZEND_MODULE_API_NO >= 20010901 + NO_VERSION_YET, /* Replace with version number for your extension */ +#endif + STANDARD_MODULE_PROPERTIES +}; +/* }}} */ + +#ifdef COMPILE_DL_PAM +ZEND_GET_MODULE(pam) +#endif + +/* {{{ PHP_INI + */ +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("pam.servicename", "php", PHP_INI_ALL, OnUpdateString, servicename, zend_pam_globals, pam_globals) +PHP_INI_END() +/* }}} */ + +/* {{{ php_pam_init_globals + */ +static void php_pam_init_globals(zend_pam_globals *pam_globals) +{ + pam_globals->servicename = NULL; +} +/* }}} */ + +/* {{{ PHP_MINIT_FUNCTION + */ +PHP_MINIT_FUNCTION(pam) +{ + ZEND_INIT_MODULE_GLOBALS(pam, php_pam_init_globals, NULL); + REGISTER_INI_ENTRIES(); + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MSHUTDOWN_FUNCTION + */ +PHP_MSHUTDOWN_FUNCTION(pam) +{ + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION + */ +PHP_MINFO_FUNCTION(pam) +{ + php_info_print_table_start(); + php_info_print_table_header(2, "PAM support", "enabled"); + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); +} +/* }}} */ + +/* + * auth_pam_talker: supply authentication information to PAM when asked + * + * Assumptions: + * A password is asked for by requesting input without echoing + * A username is asked for by requesting input _with_ echoing + * + */ +static +int auth_pam_talker(int num_msg, + const struct pam_message ** msg, + struct pam_response ** resp, + void *appdata_ptr) +{ + unsigned short i = 0; + pam_auth_t *userinfo = (pam_auth_t *) appdata_ptr; + struct pam_response *response = 0; + + /* parameter sanity checking */ + if (!resp || !msg || !userinfo) + return PAM_CONV_ERR; + + /* allocate memory to store response */ + response = malloc(num_msg * sizeof(struct pam_response)); + if (!response) + return PAM_CONV_ERR; + + /* copy values */ + for (i = 0; i < num_msg; i++) { + /* initialize to safe values */ + response[i].resp_retcode = 0; + response[i].resp = 0; + + /* select response based on requested output style */ + switch (msg[i]->msg_style) { + case PAM_PROMPT_ECHO_ON: + /* on memory allocation failure, auth fails */ + response[i].resp = strdup(userinfo->name); + break; + case PAM_PROMPT_ECHO_OFF: + response[i].resp = strdup(userinfo->pw); + break; + default: + if (response) + free(response); + return PAM_CONV_ERR; + } + } + /* everything okay, set PAM response values */ + *resp = response; + return PAM_SUCCESS; +} + +/* + * chpass_pam_talker: supply authentication information to PAM when asked + * + * Assumptions: + * A password is asked for by requesting input without echoing + * A username is asked for by requesting input _with_ echoing + * + */ +static +int chpass_pam_talker(int num_msg, + const struct pam_message ** msg, + struct pam_response ** resp, + void *appdata_ptr) +{ + unsigned short i = 0; + pam_chpass_t *userinfo = (pam_chpass_t *) appdata_ptr; + struct pam_response *response = 0; + + /* parameter sanity checking */ + if (!resp || !msg || !userinfo) + return PAM_CONV_ERR; + + /* allocate memory to store response */ + response = malloc(num_msg * sizeof(struct pam_response)); + if (!response) + return PAM_CONV_ERR; + + /* copy values */ + for (i = 0; i < num_msg; i++) { + /* initialize to safe values */ + response[i].resp_retcode = 0; + response[i].resp = 0; + + /* select response based on requested output style */ + switch (msg[i]->msg_style) { + case PAM_PROMPT_ECHO_ON: + /* on memory allocation failure, auth fails */ + response[i].resp = strdup(userinfo->name); + break; + case PAM_PROMPT_ECHO_OFF: + if (userinfo->count++) { + response[i].resp = strdup(userinfo->newpw); + } + else { + response[i].resp = strdup(userinfo->oldpw); + } + break; + default: + if (response) + free(response); + return PAM_CONV_ERR; + } + } + /* everything okay, set PAM response values */ + *resp = response; + return PAM_SUCCESS; +} + +/* {{{ proto bool pam_auth( string host, string password [, string &status ]) + Authenticates a user and returns TRUE on success, FALSE on failure */ +PHP_FUNCTION(pam_auth) +{ + char *username, *password; + int username_len, password_len; + zval *status = NULL; + + pam_auth_t userinfo = {NULL, NULL}; + struct pam_conv conv_info = {&auth_pam_talker, (void *) &userinfo}; + pam_handle_t *pamh = NULL; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &username, &username_len, &password, &password_len, &status) == FAILURE) { + return; + } + + userinfo.name = username; + userinfo.pw = password; + + if ((result = pam_start(PAM_G(servicename), userinfo.name, &conv_info, &pamh)) != PAM_SUCCESS || + (result = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS || + (result = pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) { + if (status) { + zval_dtor(status); + ZVAL_STRING(status, (char *) pam_strerror(pamh, result), 1); + } + pam_end(pamh, result); + RETURN_FALSE; + } + + pam_end(pamh, PAM_SUCCESS); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool pam_auth( string host, string password [, string &status ]) + Changes a users password and returns TRUE on success, FALSE on failure */ +PHP_FUNCTION(pam_chpass) +{ + char *username, *oldpass, *newpass; + int username_len, oldpass_len, newpass_len; + zval *status = NULL; + + pam_chpass_t userinfo = {NULL, NULL, NULL, 0}; + struct pam_conv conv_info = {&chpass_pam_talker, (void *) &userinfo}; + pam_handle_t *pamh = NULL; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|z", &username, &username_len, &oldpass, &oldpass_len, &newpass, &newpass_len, &status) == FAILURE) { + return; + } + + userinfo.name = username; + userinfo.oldpw = oldpass; + userinfo.newpw = newpass; + + if ((result = pam_start(PAM_G(servicename), userinfo.name, &conv_info, &pamh)) != PAM_SUCCESS || + (result = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS || + (result = pam_chauthtok(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) { + if (status) { + zval_dtor(status); + ZVAL_STRING(status, (char *) pam_strerror(pamh, result), 1); + } + pam_end(pamh, PAM_SUCCESS); + RETURN_FALSE; + } + + pam_end(pamh, PAM_SUCCESS); + RETURN_TRUE; +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ http://cvs.php.net/viewvc.cgi/pecl/pam/php_pam.h?r1=1.1&r2=1.2&diff_format=u Index: pecl/pam/php_pam.h diff -u pecl/pam/php_pam.h:1.1 pecl/pam/php_pam.h:1.2 --- pecl/pam/php_pam.h:1.1 Mon Nov 13 07:47:40 2006 +++ pecl/pam/php_pam.h Mon Nov 13 08:12:39 2006 @@ -1,73 +1,73 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Mikael Johansson <mikael AT synd DOT info> | - | Chad Cunningham | - +----------------------------------------------------------------------+ -*/ - -/* $Id: php_pam.h,v 1.1 2006/11/13 07:47:40 mikl Exp $ */ - -#ifndef PHP_PAM_H -#define PHP_PAM_H - -extern zend_module_entry pam_module_entry; -#define phpext_pam_ptr &pam_module_entry - -#ifdef PHP_WIN32 -#define PHP_PAM_API __declspec(dllexport) -#else -#define PHP_PAM_API -#endif - -#ifdef ZTS -#include "TSRM.h" -#endif - -PHP_MINIT_FUNCTION(pam); -PHP_MSHUTDOWN_FUNCTION(pam); -PHP_MINFO_FUNCTION(pam); - -PHP_FUNCTION(pam_auth); -PHP_FUNCTION(pam_chpass); - -ZEND_BEGIN_MODULE_GLOBALS(pam) - char *servicename; -ZEND_END_MODULE_GLOBALS(pam) - -typedef struct { - char *name, *pw; -} pam_auth_t; - -typedef struct { - char *name, *oldpw, *newpw; - int count; -} pam_chpass_t; - -#ifdef ZTS -#define PAM_G(v) TSRMG(pam_globals_id, zend_pam_globals *, v) -#else -#define PAM_G(v) (pam_globals.v) -#endif - -#endif /* PHP_PAM_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Mikael Johansson <mikael AT synd DOT info> | + | Chad Cunningham | + +----------------------------------------------------------------------+ +*/ + +/* $Id: php_pam.h,v 1.2 2006/11/13 08:12:39 mikl Exp $ */ + +#ifndef PHP_PAM_H +#define PHP_PAM_H + +extern zend_module_entry pam_module_entry; +#define phpext_pam_ptr &pam_module_entry + +#ifdef PHP_WIN32 +#define PHP_PAM_API __declspec(dllexport) +#else +#define PHP_PAM_API +#endif + +#ifdef ZTS +#include "TSRM.h" +#endif + +PHP_MINIT_FUNCTION(pam); +PHP_MSHUTDOWN_FUNCTION(pam); +PHP_MINFO_FUNCTION(pam); + +PHP_FUNCTION(pam_auth); +PHP_FUNCTION(pam_chpass); + +ZEND_BEGIN_MODULE_GLOBALS(pam) + char *servicename; +ZEND_END_MODULE_GLOBALS(pam) + +typedef struct { + char *name, *pw; +} pam_auth_t; + +typedef struct { + char *name, *oldpw, *newpw; + int count; +} pam_chpass_t; + +#ifdef ZTS +#define PAM_G(v) TSRMG(pam_globals_id, zend_pam_globals *, v) +#else +#define PAM_G(v) (pam_globals.v) +#endif + +#endif /* PHP_PAM_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ http://cvs.php.net/viewvc.cgi/pecl/pam/tests/pam.inc?r1=1.1&r2=1.2&diff_format=u Index: pecl/pam/tests/pam.inc diff -u pecl/pam/tests/pam.inc:1.1 pecl/pam/tests/pam.inc:1.2 --- pecl/pam/tests/pam.inc:1.1 Mon Nov 13 07:47:40 2006 +++ pecl/pam/tests/pam.inc Mon Nov 13 08:12:39 2006 @@ -1,10 +1,10 @@ -<? - -if (!extension_loaded("pam")) { - print "skip"; - return; -} - -// Change these to a valid username and password -//$username = 'nobody'; +<? + +if (!extension_loaded("pam")) { + print "skip"; + return; +} + +// Change these to a valid username and password +//$username = 'nobody'; //$password = 'secret'; \ No newline at end of file
« previous php.pecl.cvs (#6629) next »