├── CREDITS ├── README.md ├── tests ├── 002.phpt └── 001.phpt ├── .gitignore ├── config.m4 ├── php_tcpwrap.h ├── LICENSE ├── package.xml └── tcpwrap.c /CREDITS: -------------------------------------------------------------------------------- 1 | tcpwrap extension 2 | Marcin Gibula -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Issues: https://bugs.php.net/search.php?cmd=display&status=Open&package_name[]=tcpwrap 2 | -------------------------------------------------------------------------------- /tests/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tcpwrap_check() 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | --GET-- 7 | --INI-- 8 | --FILE-- 9 | 13 | --EXPECT-- 14 | boolean 15 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for tcpwrap presence 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | --GET-- 7 | --INI-- 8 | --FILE-- 9 | 12 | --EXPECT-- 13 | tcpwrap extension is available 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs/ 3 | Makefile 4 | Makefile.fragments 5 | Makefile.global 6 | Makefile.objects 7 | acinclude.m4 8 | aclocal.m4 9 | autom4te.cache/ 10 | build/ 11 | config.guess 12 | config.h 13 | config.h.in 14 | config.log 15 | config.nice 16 | config.status 17 | config.sub 18 | configure 19 | configure.in 20 | tcpwrap.la 21 | install-sh 22 | lcov_data 23 | libtool 24 | ltmain.* 25 | missing 26 | mkinstalldirs 27 | modules/ 28 | tcpwrap-*.tgz 29 | *.lo 30 | *.o 31 | run-tests.php 32 | tmp-php.ini 33 | tests/*.diff 34 | tests/*.exp 35 | tests/*.log 36 | tests/*.out 37 | tests/*.php 38 | tests/*.sh 39 | lcov_data 40 | *~ 41 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension tcpwrap 3 | 4 | PHP_ARG_WITH(tcpwrap, for tcpwrap support, 5 | [ --with-tcpwrappers Include tcpwrappers support]) 6 | 7 | if test "$PHP_TCPWRAP" != "no"; then 8 | 9 | SEARCH_PATH="/usr/local /usr" # you might want to change this 10 | SEARCH_FOR="/include/tcpd.h" # you most likely want to change this 11 | if test -r $PHP_TCPWRAP/; then # path given as parameter 12 | TCPWRAP_DIR=$PHP_TCPWRAP 13 | else # search default path list 14 | AC_MSG_CHECKING([for tcpwrappers files in default path]) 15 | for i in $SEARCH_PATH ; do 16 | if test -r $i/$SEARCH_FOR; then 17 | TCPWRAP_DIR=$i 18 | AC_MSG_RESULT(found in $i) 19 | fi 20 | done 21 | fi 22 | 23 | if test -z "$TCPWRAP_DIR"; then 24 | AC_MSG_RESULT([not found]) 25 | AC_MSG_ERROR([Please reinstall the tcpwrappers distribution]) 26 | fi 27 | 28 | PHP_ADD_INCLUDE($TCPWRAP_DIR/include) 29 | 30 | LIBNAME=wrap 31 | LIBSYMBOL=request_init 32 | 33 | PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 34 | [ 35 | PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TCPWRAP_DIR/$PHP_LIBDIR, TCPWRAP_SHARED_LIBADD) 36 | AC_DEFINE(HAVE_TCPWRAPLIB,1,[ ]) 37 | ],[ 38 | AC_MSG_ERROR([wrong tcpwrappers lib version or lib not found]) 39 | ],[ 40 | -L$TCPWRAP_DIR/lib -lm -ldl 41 | ]) 42 | 43 | AC_CHECK_FUNC(gethostbyname_r, [have_gethostbyname_r=yes], [have_gethostbyname_r=no]) 44 | if test "$have_gethostbyname_r" = "no"; then 45 | AC_MSG_ERROR([this extension requires system to support gethostbyname_r function]) 46 | fi 47 | 48 | PHP_SUBST(TCPWRAP_SHARED_LIBADD) 49 | 50 | PHP_NEW_EXTENSION(tcpwrap, tcpwrap.c, $ext_shared) 51 | fi 52 | -------------------------------------------------------------------------------- /php_tcpwrap.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5, 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available at through the world-wide-web at | 10 | | http://www.php.net/license/3.01.txt. | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Marcin Gibula | 16 | +----------------------------------------------------------------------+ 17 | 18 | $Id$ 19 | */ 20 | 21 | #ifndef PHP_TCPWRAP_H 22 | #define PHP_TCPWRAP_H 23 | 24 | extern zend_module_entry tcpwrap_module_entry; 25 | #define phpext_tcpwrap_ptr &tcpwrap_module_entry 26 | 27 | #define PHP_TCPWRAP_VERSION "1.2.0" 28 | 29 | #ifdef PHP_WIN32 30 | #define PHP_TCPWRAP_API __declspec(dllexport) 31 | #else 32 | #define PHP_TCPWRAP_API 33 | #endif 34 | 35 | #ifdef ZTS 36 | #include "TSRM.h" 37 | #endif 38 | 39 | 40 | PHP_MINFO_FUNCTION(tcpwrap); 41 | PHP_FUNCTION(tcpwrap_check); 42 | 43 | #endif /* PHP_TCPWRAP_H */ 44 | 45 | 46 | /* 47 | * Local variables: 48 | * tab-width: 4 49 | * c-basic-offset: 4 50 | * indent-tabs-mode: t 51 | * End: 52 | */ 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------- 2 | The PHP License, version 3.01 3 | Copyright (c) 1999 - 2014 The PHP Group. All rights reserved. 4 | -------------------------------------------------------------------- 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, is permitted provided that the following conditions 8 | are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 18 | 3. The name "PHP" must not be used to endorse or promote products 19 | derived from this software without prior written permission. For 20 | written permission, please contact group@php.net. 21 | 22 | 4. Products derived from this software may not be called "PHP", nor 23 | may "PHP" appear in their name, without prior written permission 24 | from group@php.net. You may indicate that your software works in 25 | conjunction with PHP by saying "Foo for PHP" instead of calling 26 | it "PHP Foo" or "phpfoo" 27 | 28 | 5. The PHP Group may publish revised and/or new versions of the 29 | license from time to time. Each version will be given a 30 | distinguishing version number. 31 | Once covered code has been published under a particular version 32 | of the license, you may always continue to use it under the terms 33 | of that version. You may also choose to use such covered code 34 | under the terms of any subsequent version of the license 35 | published by the PHP Group. No one other than the PHP Group has 36 | the right to modify the terms applicable to covered code created 37 | under this License. 38 | 39 | 6. Redistributions of any form whatsoever must retain the following 40 | acknowledgment: 41 | "This product includes PHP software, freely available from 42 | ". 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND 45 | ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 46 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP 48 | DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 49 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 50 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 51 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 53 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 54 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 55 | OF THE POSSIBILITY OF SUCH DAMAGE. 56 | 57 | -------------------------------------------------------------------- 58 | 59 | This software consists of voluntary contributions made by many 60 | individuals on behalf of the PHP Group. 61 | 62 | The PHP Group can be contacted via Email at group@php.net. 63 | 64 | For more information on the PHP Group and the PHP project, 65 | please see . 66 | 67 | PHP includes the Zend Engine, freely available at 68 | . 69 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | tcpwrap 7 | pecl.php.net 8 | tcpwrappers binding. 9 | This package handles /etc/hosts.allow and /etc/hosts.deny files. 10 | 11 | 12 | Remi Collet 13 | remi 14 | remi@php.net 15 | yes 16 | 17 | 18 | Marcin Gibula 19 | mg 20 | mg@php.net 21 | yes 22 | 23 | 2017-03-21 24 | 25 | 1.2.0 26 | 1.1 27 | 28 | 29 | stable 30 | stable 31 | 32 | PHP License 33 | Add compatibility with recent PHP versions 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 5.3.0 52 | 53 | 54 | 1.4.0b1 55 | 56 | 57 | 58 | tcpwrap 59 | 60 | 61 | 62 | 2008-07-17 63 | 64 | 1.1.3 65 | 1.1 66 | 67 | 68 | stable 69 | stable 70 | 71 | PHP License 72 | Fix compile error on Solaris. 73 | 74 | 75 | 76 | 1.1.2 77 | 1.1 78 | 79 | 80 | stable 81 | stable 82 | 83 | 2008-07-02 84 | PHP License 85 | Fix configure error. 86 | 87 | 88 | 89 | 1.1 90 | 1.1 91 | 92 | 93 | stable 94 | stable 95 | 96 | 2008-07-01 97 | PHP License 98 | This release adds extra parameter to tcpwrap_check function to avoid dns lookups. 99 | 100 | 101 | 102 | 1.0 103 | 1.0 104 | 105 | 106 | stable 107 | stable 108 | 109 | 2003-10-24 110 | PHP License 111 | This is the first release of tcpwrap extension. 112 | 113 | 114 | 115 | 0.1 116 | 0.1 117 | 118 | 119 | beta 120 | beta 121 | 122 | 2003-10-19 123 | PHP License 124 | First offical PEAR/PECL release. 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /tcpwrap.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5, 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available at through the world-wide-web at | 10 | | http://www.php.net/license/3_01.txt. | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | 18 | $Id$ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "php.h" 26 | #include "php_ini.h" 27 | #include "ext/standard/info.h" 28 | #include "php_tcpwrap.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | ZEND_BEGIN_ARG_INFO_EX(arginfo_tcpwrap_check, 0, 0, 2) 36 | ZEND_ARG_INFO(0, daemon) 37 | ZEND_ARG_INFO(0, address) 38 | ZEND_ARG_INFO(0, user) 39 | ZEND_ARG_INFO(0, nodns) 40 | ZEND_END_ARG_INFO(); 41 | 42 | /* {{{ tcpwrap_functions[] 43 | * 44 | * Every user visible function must have an entry in tcpwrap_functions[]. 45 | */ 46 | static zend_function_entry tcpwrap_functions[] = { 47 | PHP_FE(tcpwrap_check, arginfo_tcpwrap_check) 48 | #ifdef PHP_FE_END 49 | PHP_FE_END 50 | #else 51 | {NULL, NULL, NULL} /* Must be the last line in tcpwrap_functions[] */ 52 | #endif 53 | }; 54 | /* }}} */ 55 | 56 | /* {{{ tcpwrap_module_entry 57 | */ 58 | zend_module_entry tcpwrap_module_entry = { 59 | STANDARD_MODULE_HEADER, 60 | "tcpwrap", 61 | tcpwrap_functions, 62 | NULL, 63 | NULL, 64 | NULL, 65 | NULL, 66 | PHP_MINFO(tcpwrap), 67 | PHP_TCPWRAP_VERSION, 68 | STANDARD_MODULE_PROPERTIES 69 | }; 70 | /* }}} */ 71 | 72 | #ifdef COMPILE_DL_TCPWRAP 73 | ZEND_GET_MODULE(tcpwrap) 74 | #endif 75 | 76 | /* {{{ PHP_MINFO_FUNCTION 77 | */ 78 | PHP_MINFO_FUNCTION(tcpwrap) 79 | { 80 | php_info_print_table_start(); 81 | php_info_print_table_header(2, "tcp wrappers support", "enabled"); 82 | php_info_print_table_row(2, "version", PHP_TCPWRAP_VERSION); 83 | php_info_print_table_end(); 84 | } 85 | /* }}} */ 86 | 87 | /* {{{ proto bool tcpwrap_check(string daemon, string address [, string user, [int nodns]]) 88 | Check if client has access according to tcp wrappers table */ 89 | PHP_FUNCTION(tcpwrap_check) 90 | { 91 | int argc, retval; 92 | zend_bool nodns = 0; 93 | #if PHP_VERSION_ID < 70000 94 | int daemon_l, address_l, user_l; 95 | #else 96 | size_t daemon_l, address_l, user_l; 97 | #endif 98 | char data[512], *daemon, *ip, *address, *user = NULL; 99 | int lookup_result, dns_result; 100 | struct in_addr tmp; 101 | struct hostent host_entry, *result; 102 | 103 | argc = ZEND_NUM_ARGS(); 104 | if (zend_parse_parameters(argc TSRMLS_CC, "ss|sb", &daemon, &daemon_l, &address, &address_l, &user, &user_l, &nodns) == FAILURE) { 105 | return; 106 | } 107 | 108 | #if defined(__sun) 109 | result = gethostbyname_r(address, &host_entry, data, sizeof(data), &dns_result); 110 | #else 111 | dns_result = gethostbyname_r(address, &host_entry, data, sizeof(data), &result, &lookup_result); 112 | #endif 113 | 114 | if (!user) { 115 | user = STRING_UNKNOWN; 116 | } 117 | 118 | if (inet_aton(address, &tmp)) { 119 | ip = address; 120 | address = STRING_UNKNOWN; 121 | } else { 122 | if (nodns || !result || dns_result != 0) { 123 | ip = STRING_UNKNOWN; 124 | } else { 125 | memcpy(&tmp.s_addr, *host_entry.h_addr_list, sizeof(tmp.s_addr)); 126 | ip = inet_ntoa(tmp); 127 | } 128 | } 129 | 130 | retval = hosts_ctl(daemon, address, ip, user); 131 | 132 | if (!retval) { 133 | RETURN_FALSE; 134 | } 135 | 136 | RETURN_TRUE; 137 | } 138 | /* }}} */ 139 | 140 | /* 141 | * Local variables: 142 | * tab-width: 4 143 | * c-basic-offset: 4 144 | * End: 145 | * vim600: noet sw=4 ts=4 fdm=marker 146 | * vim<600: noet sw=4 ts=4 147 | */ 148 | --------------------------------------------------------------------------------