Latest SANDPIT - MERGE from CVS (MERGE-GIT)

This commit is contained in:
Deon George
2009-07-01 16:09:17 +10:00
parent 388783fc84
commit ea17aadef4
210 changed files with 37284 additions and 52716 deletions

View File

@@ -1,7 +1,8 @@
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/emuhash_functions.php,v 1.6.10.2 2008/12/12 12:20:23 wurley Exp $
// $Header$
/*******************************************************************************
* @package default
* emuhash - partly emulates the php mhash functions
* version: 2004040701
*
@@ -27,69 +28,70 @@
/* Do we have builtin mhash support in this PHP version ? */
/******************************************************************************/
if( ! function_exists( 'mhash' ) && ! function_exists( 'mhash_keygen_s2k' ) ) {
if( ! isset( $emuhash_openssl ) )
$emuhash_openssl = '/usr/bin/openssl';
if (! function_exists('mhash') && ! function_exists('mhash_keygen_s2k')) {
$emuhash_emu = array();
// don't create mhash functions if we don't have a working openssl
if( ! file_exists( $emuhash_openssl ) )
unset( $emuhash_openssl );
if (! isset($emuhash_emu['openssl']))
$emuhash_emu['openssl'] = '/usr/bin/openssl';
elseif ( function_exists( 'is_executable' ) && ! is_executable( $emuhash_openssl ) )
unset( $emuhash_openssl );
# Don't create mhash functions if we don't have a working openssl
if (! file_exists($emuhash_emu['openssl']))
unset($emuhash_emu['openssl']);
elseif (function_exists('is_executable') && ! is_executable($emuhash_emu['openssl']))
unset($emuhash_emu['openssl']);
else {
if( ! isset( $emuhash_temp_dir ) )
$emuhash_temp_dir = '/tmp';
if (! isset($emuhash_emu['tmpdir']))
$emuhash_emu['tmpdir'] = '/tmp';
/******************************************************************************/
/* Define constants used in the mhash emulation code. */
/******************************************************************************/
define('MHASH_MD5', 'md5');
define('MHASH_SHA1', 'sha1');
define('MHASH_RIPEMD160', 'rmd160');
define('MHASH_MD5','md5');
define('MHASH_SHA1','sha1');
define('MHASH_RIPEMD160','rmd160');
/******************************************************************************/
/* Functions to emulate parts of php-mash. */
/******************************************************************************/
function openssl_hash( $openssl_hash_id, $password_clear ) {
global $emuhash_openssl, $emuhash_temp_dir;
function openssl_hash($openssl_hash_id,$password_clear) {
global $emuhash_emu;
$current_magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime( 0 );
$tmpfile = tempnam( $emuhash_temp_dir, "emuhash" );
$pwhandle = fopen( $tmpfile, "w" );
set_magic_quotes_runtime(0);
$tmpfile = tempnam($emuhash_emu['tmpdir'],'emuhash');
$pwhandle = fopen($tmpfile,'w');
if( ! $pwhandle )
if (! $pwhandle)
error(sprintf('Unable to create a temporary file %s to create hashed password',$tmpfile) ,'error','index.php');
fwrite( $pwhandle, $password_clear );
fclose( $pwhandle );
$cmd = $emuhash_openssl . ' ' . $openssl_hash_id . ' -binary < ' . $tmpfile;
$prog = popen( $cmd, "r" );
$pass = fread( $prog, 1024 );
pclose( $prog );
unlink( $tmpfile );
set_magic_quotes_runtime( $current_magic_quotes );
fwrite($pwhandle,$password_clear);
fclose($pwhandle);
$cmd = sprintf('%s %s -binary <%s',$emuhash_emu['openssl'],$openssl_hash_id,$tmpfile);
$prog = popen($cmd,'r');
$pass = fread($prog,1024);
pclose($prog);
unlink($tmpfile);
set_magic_quotes_runtime($current_magic_quotes);
return $pass;
}
function mhash( $hash_id, $password_clear ) {
switch( $hash_id ) {
function mhash($hash_id,$password_clear) {
switch($hash_id) {
case MHASH_MD5:
$emuhash = openssl_hash( MHASH_MD5, $password_clear );
$emuhash = openssl_hash(MHASH_MD5,$password_clear);
break;
case MHASH_SHA1:
$emuhash = openssl_hash( MHASH_SHA1, $password_clear );
$emuhash = openssl_hash(MHASH_SHA1,$password_clear);
break;
case MHASH_RIPEMD160:
$emuhash = openssl_hash( MHASH_RIPEMD160, $password_clear );
$emuhash = openssl_hash(MHASH_RIPEMD160,$password_clear);
break;
default:
@@ -99,13 +101,9 @@ if( ! function_exists( 'mhash' ) && ! function_exists( 'mhash_keygen_s2k' ) ) {
return $emuhash;
}
function mhash_keygen_s2k( $hash_id, $password_clear, $salt, $bytes ) {
return substr(pack("H*", bin2hex(mhash($hash_id, ($salt . $password_clear)))), 0, $bytes);
function mhash_keygen_s2k($hash_id,$password_clear,$salt,$bytes) {
return substr(pack('H*',bin2hex(mhash($hash_id,($salt.$password_clear)))),0,$bytes);
}
/******************************************************************************/
}
}
?>