From 2d3f584bb443e8a44c2966211565fcf806a1afb3 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 23 Nov 2018 18:31:47 +0100 Subject: [PATCH] added fallback for iconv --- lam/lib/account.inc | 16 ++++++++++++++++ lam/lib/createntlm.inc | 4 ++-- lam/lib/modules/windowsUser.inc | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 9b0a7e81..b8fde23a 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -1635,6 +1635,22 @@ function printJsIncludes($prefix) { } } +/** + * Converts an UTF-8 string to UTF16LE. + * + * @param string $input UTF-8 value + */ +function convertUtf8ToUtf16Le($input) { + if (($input == null) || (strlen($input) == 0)) { + return $input; + } + $output = iconv('UTF-8', 'UTF-16LE', $input); + if (($output === false) || ($output == '')) { + $output = mb_convert_encoding($input, 'UTF-8', 'UTF-16LE'); + } + return $output; +} + /** * LAM exception with title and message. * diff --git a/lam/lib/createntlm.inc b/lam/lib/createntlm.inc index 235d3736..871e9a4e 100644 --- a/lam/lib/createntlm.inc +++ b/lam/lib/createntlm.inc @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2006 Roland Gruber + Copyright (C) 2004 - 2018 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -349,7 +349,7 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 * @return string hash value */ public function nthash($password = "") { - return strtoupper(hash('md4', iconv("UTF-8","UTF-16LE",$password))); + return strtoupper(hash('md4', convertUtf8ToUtf16Le($password))); } /** diff --git a/lam/lib/modules/windowsUser.inc b/lam/lib/modules/windowsUser.inc index db311d71..d390caca 100644 --- a/lam/lib/modules/windowsUser.inc +++ b/lam/lib/modules/windowsUser.inc @@ -3177,7 +3177,7 @@ class windowsUser extends baseModule implements passwordService { * @param String $password password */ public static function pwdAttributeValue($password) { - return iconv('UTF-8', 'UTF-16LE', '"' . $password . '"'); + return convertUtf8ToUtf16Le('"' . $password . '"'); } /**