Anomalie php 7.1 phpLDAPAdmin

De EjnTricks

Lors de la mise à jour de la version Ubuntu 17.10, la version de php est mise à jour en version 7.1. Cependant la fonction mcrypt_module_open devient dépréciée et cela provoque une erreur lors de l'utilisation de l'application.


Hand-icon.png Votre avis

Nobody voted on this yet

 You need to enable JavaScript to vote


Study icon.png Etude

La fonction mcrypt_module_open est utilisée lors du cryptage / decryptage d'informations. Suite au passage en version 7.1, le message d'erreur suivant est affiché sur l'interface.

Fichier	/var/opt/phpldapadmin-1.2.3.1/lib/functions.php (184)
 	Chiffrement	error (a:5:{i:0;s:75:"Numéro d'erreur inconnu: 8192: Fun...)
Fichier	/var/opt/phpldapadmin-1.2.3.1/lib/functions.php (749)
 	Chiffrement	app_error_handler (a:5:{i:0;i:8192;i:1;s:43:"Function mcrypt_module_o...)
Fichier	/var/opt/phpldapadmin-1.2.3.1/lib/ds.php (227)
 	Chiffrement	blowfish_encrypt (a:1:{i:0;s:27:"cn=admin,dc=ejnserver,dc=fr";})
Fichier	/var/opt/phpldapadmin-1.2.3.1/lib/ds_ldap.php (276)
 	Chiffrement	setLogin (a:3:{i:0;s:27:"cn=admin,dc=ejnserver,dc=fr";i:1;s:...)
Fichier	/var/opt/phpldapadmin-1.2.3.1/htdocs/login.php (25)
 	Chiffrement	login (a:3:{i:0;s:27:"cn=admin,dc=ejnserver,dc=fr";i:1;s:...)
Fichier	/var/opt/phpldapadmin-1.2.3.1/htdocs/cmd.php (59)
 	Chiffrement	include (a:1:{i:0;s:46:"/var/opt/phpldapadmin-1.2.3.1/htdoc...)

Cette fonction est appelée uniquement dans le fichier lib/functions/php.

De plus, la gestion des erreurs est déportée vers la fonction spécifique app_error_handler par l'exécution des lignes suivantes dans le fichier lib/common.php

# Call our custom defined error handler, if it is defined in functions.php
if (function_exists('app_error_handler'))
	set_error_handler('app_error_handler');

La documentation officielle de php indique comment gérer les erreurs remontées. Par exemple, pour ne pas remonter les erreurs E_DEPRECATED, il suffit de modifier le fichier php.ini chargé avec la ligne suivante, ce qui est le paramétrage par défaut sous Ubuntu.

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT


Update icon.png Patch gestion erreur

Le premier patch mis en place se base sur la modification de la gestion des erreurs, soit la fonction app_error_handler définie dans le fichier lib/functions.php. Dans celle-ci, si la valeur de error_reporting est 0, alors rien n'est exécuté. Dans le cas contraire, un rapport spécifique est présenté.

function app_error_handler($errno,$errstr,$file,$lineno) {
	if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
		debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);

	/**
	 * error_reporting will be 0 if the error context occurred
	 * within a function call with '@' preprended (ie, @ldap_bind() );
	 * So, don't report errors if the caller has specifically
	 * disabled them with '@'
	 */
	if (ini_get('error_reporting') == 0 || error_reporting() == 0)
		return;

	$file = basename($file);
	$caller = basename($_SERVER['PHP_SELF']);
	$errtype = '';

	switch ($errno) {
		case E_STRICT: $errtype = 'E_STRICT'; break;
		case E_ERROR: $errtype = 'E_ERROR'; break;
		case E_WARNING: $errtype = 'E_WARNING'; break;
		case E_PARSE: $errtype = 'E_PARSE'; break;
		case E_NOTICE: $errtype = 'E_NOTICE'; break;
		case E_CORE_ERROR: $errtype = 'E_CORE_ERROR'; break;
		case E_CORE_WARNING: $errtype = 'E_CORE_WARNING'; break;
		case E_COMPILE_ERROR: $errtype = 'E_COMPILE_ERROR'; break;
		case E_COMPILE_WARNING: $errtype = 'E_COMPILE_WARNING'; break;
		case E_USER_ERROR: $errtype = 'E_USER_ERROR'; break;
		case E_USER_WARNING: $errtype = 'E_USER_WARNING'; break;
		case E_USER_NOTICE: $errtype = 'E_USER_NOTICE'; break;
		case E_ALL: $errtype = 'E_ALL'; break;

		default: $errtype = sprintf('%s: %s',_('Unrecognized error number'),$errno);
	}

	# Take out extra spaces in error strings.
	$errstr = preg_replace('/\s+/',' ',$errstr);

	if ($errno == E_NOTICE) {
		$body = '<table class="notice">';
		$body .= sprintf('<tr><td>%s:</td><td><b>%s</b> (<b>%s</b>)</td></tr>',_('Error'),$errstr,$errtype);
		$body .= sprintf('<tr><td>%s:</td><td><b>%s</b> %s <b>%s</b>, %s <b>%s</b></td></tr>',
			_('File'),$file,_('line'),$lineno,_('caller'),$caller);
		$body .= sprintf('<tr><td>Versions:</td><td>PLA: <b>%s</b>, PHP: <b>%s</b>, SAPI: <b>%s</b></td></tr>',
			app_version(),phpversion(),php_sapi_name());
		$body .= sprintf('<tr><td>Web server:</td><td><b>%s</b></td></tr>',isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'SCRIPT');

		if (function_exists('get_href'))
			$body .= sprintf('<tr><td colspan="2"><a href="%s" onclick="target=\'_blank\';"><center>%s.</center></a></td></tr>',
				get_href('search_bug',"&summary_keyword=".rawurlencode($errstr)),
				_('Please check and see if this bug has been reported'));
		$body .= '</table>';

		system_message(array(
			'title'=>_('You found a non-fatal phpLDAPadmin bug!'),
			'body'=>$body,
			'type'=>'error'));

		return;
	}

	# If this is a more serious error, call the error call.
	error(sprintf('%s: %s',$errtype,$errstr),'error',null,true,true);
}

A noter que le type E_DEPRECATED n'est pas pris en compte dans cette fonction spécifique.

Le patch mis en place va simplement quitter la fonction dans le cas où le type d'erreur est E_DEPRECATED.

function app_error_handler($errno,$errstr,$file,$lineno) {
        if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
                debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);

        /**
         * error_reporting will be 0 if the error context occurred
         * within a function call with '@' preprended (ie, @ldap_bind() );
         * So, don't report errors if the caller has specifically
         * disabled them with '@'
         */
        if (ini_get('error_reporting') == 0 || error_reporting() == 0)
                return;

        if ($errno == E_DEPRECATED) {
                return;
        }

        $file = basename($file);
        $caller = basename($_SERVER['PHP_SELF']);
        $errtype = '';

        switch ($errno) {
                case E_STRICT: $errtype = 'E_STRICT'; break;
                case E_ERROR: $errtype = 'E_ERROR'; break;
                case E_WARNING: $errtype = 'E_WARNING'; break;
                case E_PARSE: $errtype = 'E_PARSE'; break;
                case E_NOTICE: $errtype = 'E_NOTICE'; break;
                case E_CORE_ERROR: $errtype = 'E_CORE_ERROR'; break;
                case E_CORE_WARNING: $errtype = 'E_CORE_WARNING'; break;
                case E_COMPILE_ERROR: $errtype = 'E_COMPILE_ERROR'; break;
                case E_COMPILE_WARNING: $errtype = 'E_COMPILE_WARNING'; break;
                case E_USER_ERROR: $errtype = 'E_USER_ERROR'; break;
                case E_USER_WARNING: $errtype = 'E_USER_WARNING'; break;
                case E_USER_NOTICE: $errtype = 'E_USER_NOTICE'; break;
                case E_ALL: $errtype = 'E_ALL'; break;

                default: $errtype = sprintf('%s: %s',_('Unrecognized error number'),$errno);
        }

        # Take out extra spaces in error strings.
        $errstr = preg_replace('/\s+/',' ',$errstr);

        if ($errno == E_NOTICE) {
                $body = '<table class="notice">';
                $body .= sprintf('<tr><td>%s:</td><td><b>%s</b> (<b>%s</b>)</td></tr>',_('Error'),$errstr,$errtype);
                $body .= sprintf('<tr><td>%s:</td><td><b>%s</b> %s <b>%s</b>, %s <b>%s</b></td></tr>',
                        _('File'),$file,_('line'),$lineno,_('caller'),$caller);
                $body .= sprintf('<tr><td>Versions:</td><td>PLA: <b>%s</b>, PHP: <b>%s</b>, SAPI: <b>%s</b></td></tr>',
                        app_version(),phpversion(),php_sapi_name());
                $body .= sprintf('<tr><td>Web server:</td><td><b>%s</b></td></tr>',isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'SCRIPT');

                if (function_exists('get_href'))
                        $body .= sprintf('<tr><td colspan="2"><a href="%s" onclick="target=\'_blank\';"><center>%s.</center></a></td></tr>',
                                get_href('search_bug',"&summary_keyword=".rawurlencode($errstr)),
                                _('Please check and see if this bug has been reported'));
                $body .= '</table>';

                system_message(array(
                        'title'=>_('You found a non-fatal phpLDAPadmin bug!'),
                        'body'=>$body,
                        'type'=>'error'));

                return;
        }

        # If this is a more serious error, call the error call.
        error(sprintf('%s: %s',$errtype,$errstr),'error',null,true,true);
}

Le fichier modifié est disponible dans le patch patch-1.2.3_php-7.1.tar.gz.