mcst-linux-kernel/patches-2024.06.26/php-pam-1.0.3/0001-Update-PHP-PAM-module-...

418 lines
12 KiB
Diff

diff -Naur a/LICENSE b/LICENSE
--- a/LICENSE 1970-01-01 03:00:00.000000000 +0300
+++ b/LICENSE 2018-10-23 15:04:33.000000000 +0300
@@ -0,0 +1,68 @@
+--------------------------------------------------------------------
+ The PHP License, version 3.01
+Copyright (c) 1999 - 2018 The PHP Group. All rights reserved.
+--------------------------------------------------------------------
+
+Redistribution and use in source and binary forms, with or without
+modification, is permitted provided that the following conditions
+are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ 3. The name "PHP" must not be used to endorse or promote products
+ derived from this software without prior written permission. For
+ written permission, please contact group@php.net.
+
+ 4. Products derived from this software may not be called "PHP", nor
+ may "PHP" appear in their name, without prior written permission
+ from group@php.net. You may indicate that your software works in
+ conjunction with PHP by saying "Foo for PHP" instead of calling
+ it "PHP Foo" or "phpfoo"
+
+ 5. The PHP Group may publish revised and/or new versions of the
+ license from time to time. Each version will be given a
+ distinguishing version number.
+ Once covered code has been published under a particular version
+ of the license, you may always continue to use it under the terms
+ of that version. You may also choose to use such covered code
+ under the terms of any subsequent version of the license
+ published by the PHP Group. No one other than the PHP Group has
+ the right to modify the terms applicable to covered code created
+ under this License.
+
+ 6. Redistributions of any form whatsoever must retain the following
+ acknowledgment:
+ "This product includes PHP software, freely available from
+ <http://www.php.net/software/>".
+
+THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
+ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
+DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+--------------------------------------------------------------------
+
+This software consists of voluntary contributions made by many
+individuals on behalf of the PHP Group.
+
+The PHP Group can be contacted via Email at group@php.net.
+
+For more information on the PHP Group and the PHP project,
+please see <http://www.php.net>.
+
+PHP includes the Zend Engine, freely available at
+<http://www.zend.com>.
diff -Naur a/pam.c b/pam.c
--- a/pam.c 2009-11-29 13:49:35.000000000 +0300
+++ b/pam.c 2018-10-23 15:04:33.000000000 +0300
@@ -19,22 +19,45 @@
/* $Id: pam.c 291416 2009-11-29 10:47:35Z mikl $ */
-#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)
+static PHP_MINIT_FUNCTION(pam);
+static PHP_MSHUTDOWN_FUNCTION(pam);
+static PHP_MINFO_FUNCTION(pam);
+static PHP_GINIT_FUNCTION(pam);
+
+static PHP_FUNCTION(pam_auth);
+static PHP_FUNCTION(pam_chpass);
+
+/* {{{ globals */
+ZEND_DECLARE_MODULE_GLOBALS(pam);
+/* }}} */
+
+/* {{{ 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()
+/* }}} */
+
+#ifdef ZEND_BEGIN_ARG_INFO
+ZEND_BEGIN_ARG_INFO_EX(arginfo_pam_auth, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2)
+ZEND_ARG_INFO(0, username)
+ZEND_ARG_INFO(0, password)
+ZEND_ARG_INFO(0, status)
+ZEND_ARG_INFO(0, checkacctmgmt)
+ZEND_END_ARG_INFO()
+#else
+#define arginfo_pam_parse third_arg_force_ref
+#define arginfo_pam_parse_file third_arg_force_ref
+#define arginfo_parm_parse_url third_arg_force_ref
+#endif
+
/* {{{ pam_functions[]
*/
zend_function_entry pam_functions[] = {
- PHP_FE(pam_auth, NULL)
+ PHP_FE(pam_auth, arginfo_pam_auth)
PHP_FE(pam_chpass, NULL)
{NULL, NULL, NULL}
};
@@ -43,47 +66,30 @@
/* {{{ pam_module_entry
*/
zend_module_entry pam_module_entry = {
-#if ZEND_MODULE_API_NO >= 20010901
- STANDARD_MODULE_HEADER,
-#endif
- "pam",
+ STANDARD_MODULE_HEADER_EX,
+ NULL,
+ NULL,
+ PHP_PAM_EXTENSION_NAME,
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 */
+ NULL, /* RINIT */
+ NULL, /* RSHUTDOWN */
PHP_MINFO(pam),
-#if ZEND_MODULE_API_NO >= 20010901
- PHP_PAM_VERSION,
-#endif
- STANDARD_MODULE_PROPERTIES
+ PHP_PAM_EXTENSION_VERSION,
+ PHP_MODULE_GLOBALS(pam),
+ PHP_GINIT(pam),
+ NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
-
-#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;
}
@@ -104,11 +110,25 @@
{
php_info_print_table_start();
php_info_print_table_header(2, "PAM support", "enabled");
- php_info_print_table_row(2, "Extension version", PHP_PAM_VERSION);
+ php_info_print_table_row(2, "Extension version", PHP_PAM_EXTENSION_VERSION);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
+
+/* {{{ PHP_GINIT_FUNCTION() */
+static PHP_GINIT_FUNCTION(pam)
+{
+ pam_globals->servicename = NULL;
+}
+/* }}} */
+
+/* {{{ php_pam_init_globals
+ */
+static void php_pam_init_globals(zend_pam_globals *pam_globals)
+{
+ pam_globals->servicename = NULL;
+}
/* }}} */
/*
@@ -226,16 +246,21 @@
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, **server, **remote_addr;
+ zval *status = NULL;
+ zval *server;
+ zval *remote_addr;
zend_bool checkacctmgmt = 1;
+ int result;
+ int username_len = 0;
+ char *username = {0};
+ int password_len = 0;
+ char *password = {0};
pam_auth_t userinfo = {NULL, NULL};
struct pam_conv conv_info = {&auth_pam_talker, (void *) &userinfo};
pam_handle_t *pamh = NULL;
- int result;
char *error_msg;
+ zend_string *hash_key;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|zb", &username, &username_len, &password, &password_len, &status, &checkacctmgmt) == FAILURE) {
return;
@@ -248,14 +273,17 @@
if (status) {
spprintf(&error_msg, 0, "%s (in %s)", (char *) pam_strerror(pamh, result), "pam_start");
zval_dtor(status);
- ZVAL_STRING(status, error_msg, 0);
+ ZVAL_STRING(status, error_msg);
+ efree(error_msg);
}
RETURN_FALSE;
}
-
- if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **)&server) == SUCCESS && Z_TYPE_PP(server) == IS_ARRAY) {
- if (zend_hash_find(Z_ARRVAL_PP(server), "REMOTE_ADDR", sizeof("REMOTE_ADDR"), (void **)&remote_addr) == SUCCESS && Z_TYPE_PP(remote_addr) == IS_STRING) {
- pam_set_item(pamh, PAM_RHOST, Z_STRVAL_PP(remote_addr));
+ hash_key = zend_string_init("_SERVER", sizeof ( "_SERVER"), 0);
+ if (zend_hash_exists(&EG(symbol_table), hash_key)) {
+ if ((server = zend_hash_str_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER")-1)) != NULL && Z_TYPE_P(server) == IS_ARRAY) {
+ if ((remote_addr = zend_hash_str_find(Z_ARRVAL_P(server), "REMOTE_ADDR", sizeof("REMOTE_ADDR")-1)) != NULL && Z_TYPE_P(remote_addr) == IS_STRING) {
+ pam_set_item(pamh, PAM_RHOST, Z_STRVAL_P(remote_addr));
+ }
}
}
@@ -263,7 +291,8 @@
if (status) {
spprintf(&error_msg, 0, "%s (in %s)", (char *) pam_strerror(pamh, result), "pam_authenticate");
zval_dtor(status);
- ZVAL_STRING(status, error_msg, 0);
+ ZVAL_STRING(status, error_msg);
+ efree(error_msg);
}
pam_end(pamh, PAM_SUCCESS);
RETURN_FALSE;
@@ -274,7 +303,8 @@
if (status) {
spprintf(&error_msg, 0, "%s (in %s)", (char *) pam_strerror(pamh, result), "pam_acct_mgmt");
zval_dtor(status);
- ZVAL_STRING(status, error_msg, 0);
+ ZVAL_STRING(status, error_msg);
+ efree(error_msg);
}
pam_end(pamh, PAM_SUCCESS);
RETURN_FALSE;
@@ -290,9 +320,13 @@
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;
+ int username_len = 0;
+ int oldpass_len = 0;
+ int newpass_len = 0;
+ char *username = {0};
+ char *oldpass = {0};
+ char *newpass = {0};
pam_chpass_t userinfo = {NULL, NULL, NULL, 0};
struct pam_conv conv_info = {&chpass_pam_talker, (void *) &userinfo};
@@ -312,7 +346,8 @@
if (status) {
spprintf(&error_msg, 0, "%s (in %s)", (char *) pam_strerror(pamh, result), "pam_start");
zval_dtor(status);
- ZVAL_STRING(status, error_msg, 0);
+ ZVAL_STRING(status, error_msg);
+ efree(error_msg);
}
RETURN_FALSE;
}
@@ -321,7 +356,8 @@
if (status) {
spprintf(&error_msg, 0, "%s (in %s)", (char *) pam_strerror(pamh, result), "pam_authenticate");
zval_dtor(status);
- ZVAL_STRING(status, error_msg, 0);
+ ZVAL_STRING(status, error_msg);
+ efree(error_msg);
}
pam_end(pamh, PAM_SUCCESS);
RETURN_FALSE;
@@ -331,7 +367,8 @@
if (status) {
spprintf(&error_msg, 0, "%s (in %s)", (char *) pam_strerror(pamh, result), "pam_chauthtok");
zval_dtor(status);
- ZVAL_STRING(status, error_msg, 0);
+ ZVAL_STRING(status, error_msg);
+ efree(error_msg);
}
pam_end(pamh, PAM_SUCCESS);
RETURN_FALSE;
diff -Naur a/php_pam.h b/php_pam.h
--- a/php_pam.h 2009-11-29 13:49:35.000000000 +0300
+++ b/php_pam.h 2018-10-23 15:04:33.000000000 +0300
@@ -20,13 +20,36 @@
/* $Id: php_pam.h 291417 2009-11-29 10:49:27Z mikl $ */
#ifndef PHP_PAM_H
-#define PHP_PAM_H
+#define PHP_PAM_H 1
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <php.h>
+#include <php_ini.h>
+#include <SAPI.h>
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+#include <ext/standard/info.h>
+#include <ext/standard/base64.h>
+#include <ext/standard/basic_functions.h>
+#include <ext/standard/php_var.h>
+#include <ext/standard/php_smart_string.h>
+#include <Zend/zend_extensions.h>
+#include <Zend/zend_hash.h>
+#include <Zend/zend_interfaces.h>
+#include <Zend/zend_smart_str.h>
+
+#include <security/pam_appl.h>
+
+#define PHP_PAM_EXTENSION_VERSION "1.0.4"
+#define PHP_PAM_EXTENSION_NAME "pam"
extern zend_module_entry pam_module_entry;
#define phpext_pam_ptr &pam_module_entry
-#define PHP_PAM_VERSION "1.0.3"
-
#ifdef PHP_WIN32
#define PHP_PAM_API __declspec(dllexport)
#else
@@ -34,19 +57,15 @@
#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);
+#define PAM_G(v) TSRMG(pam_globals_id, zend_pam_globals *, v)
+#else
+#define PAM_G(v) (pam_globals.v)
+#endif
ZEND_BEGIN_MODULE_GLOBALS(pam)
- char *servicename;
+ const char *servicename;
ZEND_END_MODULE_GLOBALS(pam)
+ZEND_EXTERN_MODULE_GLOBALS(pam)
typedef struct {
char *name, *pw;
@@ -57,13 +76,7 @@
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 */
+#endif /* PHP_PAM_H */
/*
* Local variables: