Commit f6de22e9 authored by Ondrej Sury's avatar Ondrej Sury

Merge tag 'upstream/1.2.7'

Upstream version 1.2.7

Conflicts:
	radius-1.2.7/radius.c
parents b307b472 2675c022
This diff is collapsed.
# $Id: Makefile.in,v 1.3 2003/11/04 19:14:39 mbretter Exp $
# $Id$
LTLIBRARY_NAME = libradius.la
LTLIBRARY_SOURCES = radius.c radlib.c
......
dnl $Id: config.m4,v 1.4 2003/07/17 13:54:39 mbretter Exp $
dnl $Id$
dnl config.m4 for extension radius
PHP_ARG_ENABLE(radius, whether to enable radius support,
......
......@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: mschap.php,v 1.5 2003/01/26 20:31:11 mbretter Exp $
$Id$
*/
include_once 'des.php';
......
......@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: mschaptest.php,v 1.2 2003/01/26 20:31:11 mbretter Exp $
$Id$
*/
include_once('mschap.php');
......
......@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radius-acct.php,v 1.3 2007/03/18 21:17:02 mbretter Exp $
$Id$
*/
if(!extension_loaded('radius')) {
......
......@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radius-auth.php,v 1.3 2007/03/18 21:17:02 mbretter Exp $
$Id$
*/
if(!extension_loaded('radius')) {
......
......@@ -28,7 +28,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: php_radius.h,v 1.7 2003/05/17 19:22:32 mbretter Exp $
$Id$
*/
#include "radlib.h"
......@@ -39,6 +39,8 @@ any other GPL-like (LGPL, GPL2) License.
#define phpext_radius_ptr &radius_module_entry
#define PHP_RADIUS_VERSION "1.2.7"
#ifdef PHP_WIN32
#define PHP_RADIUS_API __declspec(dllexport)
#else
......@@ -102,3 +104,5 @@ PHP_FUNCTION(radius_demangle_mppe_key);
* indent-tabs-mode: t
* End:
*/
/* vim: set ts=8 sw=8 noet: */
......@@ -28,7 +28,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radius.c,v 1.13 2007/03/18 21:17:02 mbretter Exp $
$Id$
*/
#ifdef HAVE_CONFIG_H
......@@ -106,7 +106,7 @@ zend_module_entry radius_module_entry = {
NULL,
PHP_MINFO(radius),
#if ZEND_MODULE_API_NO >= 20010901
"1.2.4", /* Replace with version number for your extension */
PHP_RADIUS_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
......@@ -140,8 +140,8 @@ PHP_MSHUTDOWN_FUNCTION(radius)
PHP_MINFO_FUNCTION(radius)
{
php_info_print_table_start();
php_info_print_table_row(2, "radius support", "enabled");
php_info_print_table_row(2, "Revision", "$Revision: 1.13 $");
php_info_print_table_header(2, "radius support", "enabled");
php_info_print_table_row(2, "version", PHP_RADIUS_VERSION);
php_info_print_table_end();
}
/* }}} */
......@@ -541,9 +541,9 @@ PHP_FUNCTION(radius_get_attr)
/* {{{ proto string radius_get_vendor_attr(data) */
PHP_FUNCTION(radius_get_vendor_attr)
{
int vendor;
const void *data, *raw;
size_t len;
int len;
u_int32_t vendor;
unsigned char type;
size_t data_len;
......@@ -654,7 +654,12 @@ PHP_FUNCTION(radius_server_secret)
ZEND_FETCH_RESOURCE(raddesc, radius_descriptor *, &z_radh, -1, "rad_handle", le_radius);
secret = (char *)rad_server_secret(raddesc->radh);
RETURN_STRINGL(secret, strlen(secret), 1);
if (secret) {
RETURN_STRINGL(secret, strlen(secret), 1);
}
RETURN_FALSE;
}
/* }}} */
......@@ -665,8 +670,7 @@ PHP_FUNCTION(radius_demangle)
zval *z_radh;
const void *mangled;
unsigned char *buf;
size_t len;
int res;
int len, res;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_radh, &mangled, &len) == FAILURE) {
return;
......@@ -681,7 +685,7 @@ PHP_FUNCTION(radius_demangle)
efree(buf);
RETURN_FALSE;
} else {
RETVAL_STRINGL(buf, len, 1);
RETVAL_STRINGL((char *) buf, len, 1);
efree(buf);
return;
}
......@@ -695,8 +699,8 @@ PHP_FUNCTION(radius_demangle_mppe_key)
zval *z_radh;
const void *mangled;
unsigned char *buf;
size_t len, dlen;
int res;
size_t dlen;
int len, res;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_radh, &mangled, &len) == FAILURE) {
return;
......@@ -710,7 +714,7 @@ PHP_FUNCTION(radius_demangle_mppe_key)
efree(buf);
RETURN_FALSE;
} else {
RETVAL_STRINGL(buf, dlen, 1);
RETVAL_STRINGL((char *) buf, dlen, 1);
efree(buf);
return;
}
......@@ -731,6 +735,6 @@ void _radius_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
* vim600: noet sw=8 ts=8 fdm=marker
* vim<600: noet sw=8 ts=8
*/
......@@ -161,3 +161,5 @@ REGISTER_LONG_CONSTANT("RADIUS_VENDOR_MICROSOFT", 311, CONST_PERSISTENT); /* rf
REGISTER_LONG_CONSTANT("RADIUS_MICROSOFT_MS_PRIMARY_NBNS_SERVER", 30, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RADIUS_MICROSOFT_MS_SECONDARY_NBNS_SERVER", 31, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RADIUS_MICROSOFT_MS_ARAP_CHALLENGE", 33, CONST_PERSISTENT);
/* vim: set ts=8 sw=8 noet: */
......@@ -580,6 +580,10 @@ rad_get_attr(struct rad_handle *h, const void **value, size_t *len)
{
int type;
if (h->resp_len == 0) {
generr(h, "No response has been received");
return -1;
}
if (h->resp_pos >= h->resp_len)
return 0;
if (h->resp_pos + 2 > h->resp_len) {
......@@ -693,12 +697,16 @@ rad_auth_open(void)
h->num_servers = 0;
h->ident = php_rand(TSRMLS_C);
h->errmsg[0] = '\0';
memset(h->request, 0, sizeof h->request);
h->req_len = 0;
memset(h->pass, 0, sizeof h->pass);
h->pass_len = 0;
h->pass_pos = 0;
h->chap_pass = 0;
h->type = RADIUS_AUTH;
h->request_created = 0;
h->request_created = 0;
h->resp_len = 0;
h->srv = 0;
}
return h;
}
......@@ -989,6 +997,11 @@ rad_request_authenticator(struct rad_handle *h, char *buf, size_t len)
const char *
rad_server_secret(struct rad_handle *h)
{
if (h->srv >= h->num_servers) {
generr(h, "No RADIUS servers specified");
return NULL;
}
return (h->servers[h->srv].secret);
}
......@@ -1111,3 +1124,5 @@ rad_demangle_mppe_key(struct rad_handle *h, const void *mangled, size_t mlen, u_
memcpy(demangled, P + 1, *len);
return 0;
}
/* vim: set ts=8 sw=8 noet: */
......@@ -203,3 +203,5 @@ const char *rad_strerror(struct rad_handle *);
int rad_demangle(struct rad_handle *, const void *, size_t, u_char *);
#endif /* _RADLIB_H_ */
/* vim: set ts=8 sw=8 noet: */
......@@ -28,7 +28,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radlib_compat.c,v 1.5 2003/04/24 18:07:06 mbretter Exp $
$Id$
*/
#include <stddef.h>
......@@ -71,3 +71,5 @@ char *strsep(char **stringp, const char *delim)
}
/* NOTREACHED */
}
/* vim: set ts=8 sw=8 noet: */
......@@ -28,7 +28,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radlib_compat.h,v 1.6 2003/04/24 18:04:44 mbretter Exp $
$Id$
*/
#ifndef _RADLIB_COMPAT_H_
......@@ -85,3 +85,5 @@ char *strsep(char **stringp, const char *delim);
#endif
#endif
/* vim: set ts=8 sw=8 noet: */
......@@ -28,7 +28,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code cannot simply be copied and put under the GNU Public License or
any other GPL-like (LGPL, GPL2) License.
$Id: radlib_md5.h,v 1.4 2003/01/26 20:31:10 mbretter Exp $
$Id$
*/
#include "php.h"
......@@ -38,3 +38,5 @@ any other GPL-like (LGPL, GPL2) License.
#define MD5Update PHP_MD5Update
#define MD5Final PHP_MD5Final
#define MD5_CTX PHP_MD5_CTX
/* vim: set ts=8 sw=8 noet: */
......@@ -103,3 +103,5 @@ struct vendor_attribute {
};
#endif
/* vim: set ts=8 sw=8 noet: */
......@@ -83,3 +83,5 @@ int rad_put_vendor_string(struct rad_handle *, int, int, const char *);
int rad_demangle_mppe_key(struct rad_handle *, const void *, size_t, u_char *, size_t *);
#endif /* _RADLIB_VS_H_ */
/* vim: set ts=8 sw=8 noet: */
--TEST--
radius_acct_open()
--INI--
display_errors=1
error_reporting=-1
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
$res = radius_acct_open();
var_dump($res);
?>
--EXPECTF--
resource(%d) of type (rad_handle)
--TEST--
radius_auth_open()
--INI--
display_errors=1
error_reporting=-1
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
$res = radius_auth_open();
var_dump($res);
?>
--EXPECTF--
resource(%d) of type (rad_handle)
--TEST--
radius_close()
--INI--
display_errors=1
error_reporting=-1
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
var_dump(radius_close(radius_acct_open()));
var_dump(radius_close(radius_auth_open()));
// The boolean cast is because PHP 4 will return NULL rather than false here.
var_dump((boolean) radius_close(opendir('.')));
?>
--EXPECTF--
bool(true)
bool(true)
Warning: radius_close(): supplied resource is not a valid rad_handle resource in %s on line %d
bool(false)
--TEST--
radius_cvt_addr()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
var_dump(radius_cvt_addr(pack('N', ip2long('127.0.0.1'))));
?>
--EXPECT--
string(9) "127.0.0.1"
--TEST--
radius_cvt_int()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
var_dump(radius_cvt_int(pack('N', 1234)));
?>
--EXPECT--
int(1234)
--TEST--
radius_cvt_string()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
var_dump(radius_cvt_string('127.0.0.1'));
?>
--EXPECT--
string(9) "127.0.0.1"
--TEST--
radius_get_attr()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
include dirname(__FILE__).'/server/fake_server.php';
if (FakeServer::skip()) {
die('SKIP: pcntl, radius and sockets extensions required');
}
?>
--FILE--
<?php
include dirname(__FILE__).'/server/fake_server.php';
$server = new FakeServer;
$res = $server->getAuthResource();
$request = Request::expect(RADIUS_ACCESS_REQUEST, array(
Attribute::expect(RADIUS_USER_NAME, 'foo'),
));
$response = new RadiusResponse;
$response->code = RADIUS_ACCESS_REJECT;
$response->attributes = array(
Attribute::expect(RADIUS_REPLY_MESSAGE, 'Go away'),
);
$server->addTransaction($request, $response);
$server->handle();
radius_create_request($res, RADIUS_ACCESS_REQUEST);
radius_put_string($res, RADIUS_USER_NAME, 'foo');
radius_put_string($res, RADIUS_USER_PASSWORD, 'bar');
var_dump(radius_get_attr($res));
radius_send_request($res);
var_dump(radius_get_attr($res));
var_dump($server->wait());
?>
--EXPECTF--
bool(false)
array(2) {
["attr"]=>
int(18)
["data"]=>
string(7) "Go away"
}
int(0)
--TEST--
radius_get_vendor_attr()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
include dirname(__FILE__).'/server/fake_server.php';
var_dump(radius_get_vendor_attr(''));
// Test with an incorrect length.
$data = 'foo';
var_dump(radius_get_vendor_attr(pack('NCC', RADIUS_VENDOR_MICROSOFT, 1, strlen($data) + 3).$data));
$data = 'foo';
var_dump(radius_get_vendor_attr(pack('NCC', RADIUS_VENDOR_MICROSOFT, 1, strlen($data) + 2).$data));
?>
--EXPECT--
bool(false)
bool(false)
array(3) {
["attr"]=>
int(1)
["vendor"]=>
int(311)
["data"]=>
string(3) "foo"
}
--TEST--
radius_put_addr()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
include dirname(__FILE__).'/server/fake_server.php';
if (FakeServer::skip()) {
die('SKIP: pcntl, radius and sockets extensions required');
}
?>
--FILE--
<?php
include dirname(__FILE__).'/server/fake_server.php';
$server = new FakeServer;
$res = $server->getAuthResource();
$request = Request::expect(RADIUS_ACCESS_REQUEST, array(
Attribute::expect(RADIUS_USER_NAME, 'foo'),
Attribute::expect(RADIUS_NAS_IP_ADDRESS, pack('N', ip2long('127.0.0.1'))),
));
$response = new RadiusResponse;
$response->code = RADIUS_ACCESS_REJECT;
$response->attributes = array(
Attribute::expect(RADIUS_REPLY_MESSAGE, 'Go away'),
);
$server->addTransaction($request, $response);
$server->handle();
var_dump(radius_put_addr($res, RADIUS_NAS_IP_ADDRESS, '127.0.0.1'));
radius_create_request($res, RADIUS_ACCESS_REQUEST);
radius_put_string($res, RADIUS_USER_NAME, 'foo');
radius_put_string($res, RADIUS_USER_PASSWORD, 'bar');
var_dump(radius_put_addr($res, RADIUS_NAS_IP_ADDRESS, '127.0.0.1'));
radius_send_request($res);
var_dump($server->wait());
?>
--EXPECTF--
bool(false)
bool(true)
int(0)
--TEST--
radius_put_attr()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
include dirname(__FILE__).'/server/fake_server.php';
if (FakeServer::skip()) {
die('SKIP: pcntl, radius and sockets extensions required');
}
?>
--FILE--
<?php
include dirname(__FILE__).'/server/fake_server.php';
$server = new FakeServer;
$res = $server->getAuthResource();
$request = Request::expect(RADIUS_ACCESS_REQUEST, array(
Attribute::expect(RADIUS_USER_NAME, 'foo'),
));
$response = new RadiusResponse;
$response->code = RADIUS_ACCESS_REJECT;
$response->attributes = array(
Attribute::expect(RADIUS_REPLY_MESSAGE, 'Go away'),
);
$server->addTransaction($request, $response);
$server->handle();
var_dump(radius_put_attr($res, RADIUS_USER_NAME, 'foo'));
radius_create_request($res, RADIUS_ACCESS_REQUEST);
var_dump(radius_put_attr($res, RADIUS_USER_NAME, 'foo'));
radius_put_string($res, RADIUS_USER_PASSWORD, 'bar');
radius_send_request($res);
var_dump($server->wait());
?>
--EXPECTF--
bool(false)
bool(true)
int(0)
--TEST--
radius_put_int()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
include dirname(__FILE__).'/server/fake_server.php';
if (FakeServer::skip()) {
die('SKIP: pcntl, radius and sockets extensions required');
}
?>
--FILE--
<?php
include dirname(__FILE__).'/server/fake_server.php';
$server = new FakeServer;
$res = $server->getAuthResource();
$request = Request::expect(RADIUS_ACCESS_REQUEST, array(
Attribute::expect(RADIUS_USER_NAME, 'foo'),
Attribute::expect(RADIUS_NAS_PORT, pack('N', 1234)),
));
$response = new RadiusResponse;
$response->code = RADIUS_ACCESS_REJECT;
$response->attributes = array(
Attribute::expect(RADIUS_REPLY_MESSAGE, 'Go away'),
);
$server->addTransaction($request, $response);
$server->handle();
var_dump(radius_put_int($res, RADIUS_NAS_PORT, 1234));
radius_create_request($res, RADIUS_ACCESS_REQUEST);
radius_put_string($res, RADIUS_USER_NAME, 'foo');
radius_put_string($res, RADIUS_USER_PASSWORD, 'bar');
var_dump(radius_put_int($res, RADIUS_NAS_PORT, 1234));
radius_send_request($res);
var_dump($server->wait());
?>
--EXPECTF--
bool(false)
bool(true)
int(0)
--TEST--
radius_put_string()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
include dirname(__FILE__).'/server/fake_server.php';
if (FakeServer::skip()) {
die('SKIP: pcntl, radius and sockets extensions required');
}
?>
--FILE--
<?php
include dirname(__FILE__).'/server/fake_server.php';
$server = new FakeServer;
$res = $server->getAuthResource();
$request = Request::expect(RADIUS_ACCESS_REQUEST, array(
Attribute::expect(RADIUS_USER_NAME, 'foo'),
));
$response = new RadiusResponse;
$response->code = RADIUS_ACCESS_REJECT;
$response->attributes = array(
Attribute::expect(RADIUS_REPLY_MESSAGE, 'Go away'),
);
$server->addTransaction($request, $response);
$server->handle();
var_dump(radius_put_string($res, RADIUS_USER_NAME, 'foo'));
radius_create_request($res, RADIUS_ACCESS_REQUEST);
var_dump(radius_put_string($res, RADIUS_USER_NAME, 'foo'));
radius_put_string($res, RADIUS_USER_PASSWORD, 'bar');
radius_send_request($res);
var_dump($server->wait());
?>
--EXPECTF--
bool(false)
bool(true)
int(0)
--TEST--
radius_request_authenticator()
--INI--
display_errors=1
error_reporting=30719
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
$res = radius_acct_open();
var_dump(radius_request_authenticator($res));
?>
--EXPECTF--
string(16) "%s"
--TEST--
radius_server_secret(): load from radius_add_server()
--INI--
display_errors=1
error_reporting=-1
--SKIPIF--
<?php
if (!extension_loaded('radius')) echo 'SKIP: radius extension required';
?>
--FILE--
<?php
$res = radius_acct_open();
radius_add_server($res, 'localhost', 1234, 'a shared secret', 5, 3);
var_dump(radius_server_secret($res));
radius_close($res);
// This shouldn't create a server, but crashed before 8f1de6f.
$res = radius_acct_open();
radius_add_server($res, 'what.is.hopefully.a.nonexistent.domain', 1234, 'a shared secret', 5, 3);
var_dump(radius_server_secret($res));
var_dump(radius_strerror($res));
radius_close($res);
$res = radius_acct_open();
var_dump(radius_server_secret($res));
radius_close($res);
?>
--EXPECTF--