uawdijnntqw1x1x1
IP : 216.73.217.6
Hostname : webm002.cluster111.gra.hosting.ovh.net
Kernel : Linux webm002.cluster111.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
OS : Linux
PATH:
/
home
/
atelierpru
/
provence
/
6bf95
/
..
/
plugins
/
..
/
52177
/
auth.tar
/
/
spip.php000066600000033216152442520560006246 0ustar00<?php /***************************************************************************\ * SPIP, Systeme de publication pour l'internet * * * * Copyright (c) 2001-2019 * * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * * * * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * \***************************************************************************/ /** * Gestion de l'authentification par SPIP * * @package SPIP\Core\Authentification\SPIP **/ if (!defined('_ECRIRE_INC_VERSION')) { return; } /** * Authentifie et si ok retourne le tableau de la ligne SQL de l'utilisateur * Si risque de secu repere a l'installation retourne False * * @param string $login * @param string $pass * @param string $serveur * @param bool $phpauth * @return array|bool */ function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { // retrouver le login $login = auth_spip_retrouver_login($login); // login inconnu, n'allons pas plus loin if (!$login) { return array(); } $md5pass = ""; $shapass = $shanext = ""; if (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i", $pass, $regs)) { $shapass = $regs[1]; $shanext = $regs[2]; } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash elseif (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i", $pass, $regs)) { $shapass = $regs[1]; $shanext = $regs[2]; $md5pass = $regs[3]; //$md5next = $regs[4]; } // si envoi non crypte, crypter maintenant elseif ($pass) { $row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); if ($row) { include_spip('auth/sha256.inc'); $shapass = _nano_sha256($row['alea_actuel'] . $pass); $shanext = _nano_sha256($row['alea_futur'] . $pass); $md5pass = md5($row['alea_actuel'] . $pass); } } // login inexistant ou mot de passe vide if (!$shapass and !$md5pass) { return array(); } $row = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur, 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); // compat avec les anciennes bases en md5 if (!$row and $md5pass) { $row = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur, 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); } // login/mot de passe incorrect if (!$row) { return array(); } // fait tourner le codage du pass dans la base // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() if ($shanext and !$phpauth) { include_spip('inc/acces'); // pour creer_uniqid @sql_update('spip_auteurs', array( 'alea_actuel' => 'alea_futur', 'pass' => sql_quote($shanext, $serveur, 'text'), 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') ), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur, 'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); // En profiter pour verifier la securite de tmp/ // Si elle ne fonctionne pas a l'installation, prevenir if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { return false; } } return $row; } /** * Completer le formulaire de login avec le js ou les saisie specifiques a ce mode d'auth * * @param array $flux * @return array */ function auth_spip_formulaire_login($flux) { // faut il encore envoyer md5 ? // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle // les hash md5 ont une longueur 32, les sha 64 // en evitant une requete sql a chaque affichage du formulaire login sans session // (perf issue pour les sites qui mettent le formulaire de login sur la home) $compat_md5 = false; if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { $compat_md5 = sql_countsel("spip_auteurs", "length(pass)=32 AND statut<>'poubelle'"); if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { effacer_meta('sha_256_only'); } if (!$compat_md5) { ecrire_meta('sha_256_only', 'oui'); } } // javascript qui gere la securite du login en evitant de faire circuler le pass en clair $flux['data'] .= ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' . '<script type="text/javascript">/*<![CDATA[*/' . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," . "'login':'" . $flux['args']['contexte']['var_login'] . "'," . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," . "'informe_auteur_en_cours':false," . "'attente_informe':0," . "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};" . "jQuery(function(){ jQuery('#password').after(\"<em id='pass_securise'><img src='" . chemin_image('cadenas-16.png') . "' width='16' height='16' alt='" . attribut_html(_T('login_securise')) . "' title='" . attribut_html(_T('login_securise')) . "' \/><\/em>\"); affiche_login_secure(); jQuery('#var_login').change(actualise_auteur); jQuery('form#formulaire_login').submit(login_submit); });" . "/*]]>*/</script>"; return $flux; } /** * Informer du droit de modifier ou non son login * * @param string $serveur * @return bool * toujours true pour un auteur cree dans SPIP */ function auth_spip_autoriser_modifier_login($serveur = '') { if (strlen($serveur)) { return false; } // les fonctions d'ecriture sur base distante sont encore incompletes return true; } /** * Verification de la validite d'un login pour le mode d'auth concerne * * @param string $new_login * @param int $id_auteur * si auteur existant deja * @param string $serveur * @return string * message d'erreur si login non valide, chaine vide sinon */ function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { // login et mot de passe if (strlen($new_login)) { if (strlen($new_login) < _LOGIN_TROP_COURT) { return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT)); } else { $n = sql_countsel('spip_auteurs', "login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '', $serveur); if ($n) { return _T('info_login_existant'); } } } return ''; } /** * Modifier le login d'un auteur SPIP * * @param string $new_login * @param int $id_auteur * @param string $serveur * @return bool */ function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { return false; } if (!$id_auteur = intval($id_auteur) or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) ) { return false; } if ($new_login == $auteur['login']) { return true; } // on a rien fait mais c'est bon ! include_spip('action/editer_auteur'); // vider le login des auteurs a la poubelle qui avaient ce meme login if (strlen($new_login)) { $anciens = sql_allfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur); while ($row = array_pop($anciens)) { auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur } } auteur_modifier($id_auteur, array('login' => $new_login), true); // manque la gestion de $serveur return true; } /** * Retrouver le login de quelqu'un qui cherche a se loger * Reconnaitre aussi ceux qui donnent leur nom ou email au lieu du login * * @param string $login * @param string $serveur * @return string */ function auth_spip_retrouver_login($login, $serveur = '') { if (!strlen($login)) { return null; } // pas la peine de requeter $l = sql_quote($login, $serveur, 'text'); if ($r = sql_getfetsel('login', 'spip_auteurs', "statut<>'5poubelle'" . " AND (length(pass)>0)" . " AND (login=$l)", '', '', '', '', $serveur) ) { return $r; } // Si pas d'auteur avec ce login // regarder s'il a saisi son nom ou son mail. // Ne pas fusionner avec la requete precedente // car un nom peut etre homonyme d'un autre login else { return sql_getfetsel('login', 'spip_auteurs', "statut<>'5poubelle'" . " AND (length(pass)>0)" . " AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur); } } /** * informer sur un login * Ce dernier transmet le tableau ci-dessous a la fonction JS informer_auteur * Il est invoque par la fonction JS actualise_auteur via la globale JS * page_auteur=#URL_PAGE{informer_auteur} dans le squelette login * N'y aurait-il pas plus simple ? * * @param array $infos * @param array $row * @param string $serveur * @return array */ function auth_spip_informer_login($infos, $row, $serveur = '') { // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec $infos['alea_actuel'] = $row['alea_actuel']; $infos['alea_futur'] = $row['alea_futur']; return $infos; } /** * Informer du droit de modifier ou non le pass * * @param string $serveur * @return bool * toujours true pour un auteur cree dans SPIP */ function auth_spip_autoriser_modifier_pass($serveur = '') { if (strlen($serveur)) { return false; } // les fonctions d'ecriture sur base distante sont encore incompletes return true; } /** * Verification de la validite d'un mot de passe pour le mode d'auth concerne * c'est ici que se font eventuellement les verifications de longueur mini/maxi * ou de force * * @param string $login * Le login de l'auteur : permet de verifier que pass et login sont differents * meme a la creation lorsque l'auteur n'existe pas encore * @param string $new_pass * Nouveau mot de passe * @param int $id_auteur * si auteur existant deja * @param string $serveur * @return string * message d'erreur si login non valide, chaine vide sinon */ function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { // login et mot de passe if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { return _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI)); } return ''; } /** * Modifier le mot de passe de l'auteur sur le serveur concerne * en s'occupant du hash et companie * * @param string $login * @param string $new_pass * @param int $id_auteur * @param string $serveur * @return bool */ function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { return false; } if (!$id_auteur = intval($id_auteur) or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) ) { return false; } $c = array(); include_spip('inc/acces'); include_spip('auth/sha256.inc'); $htpass = generer_htpass($new_pass); $alea_actuel = creer_uniqid(); $alea_futur = creer_uniqid(); $pass = _nano_sha256($alea_actuel . $new_pass); $c['pass'] = $pass; $c['htpass'] = $htpass; $c['alea_actuel'] = $alea_actuel; $c['alea_futur'] = $alea_futur; $c['low_sec'] = ''; include_spip('action/editer_auteur'); auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur return true; // on a bien modifie le pass } /** * Synchroniser les fichiers htpasswd * * @param int $id_auteur * @param array $champs * @param array $options * all=>true permet de demander la regeneration complete des acces apres operation en base (import, upgrade) * @param string $serveur * @return void */ function auth_spip_synchroniser_distant($id_auteur, $champs, $options = array(), $serveur = '') { // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess if (strlen($serveur)) { return; } // si un login, pass ou statut a ete modifie // regenerer les fichier htpass if (isset($champs['login']) or isset($champs['pass']) or isset($champs['statut']) or (isset($options['all']) and $options['all']) ) { $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; $htpasswd = _DIR_TMP . _AUTH_USER_FILE; // Cette variable de configuration peut etre posee par un plugin // par exemple acces_restreint ; // si .htaccess existe, outrepasser spip_meta if ((!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) and !@file_exists($htaccess) ) { spip_unlink($htpasswd); spip_unlink($htpasswd . "-admin"); return; } # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre # de devenir redacteur le cas echeant (auth http)... a nettoyer // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) $p1 = ''; // login:htpass pour tous $p2 = ''; // login:htpass pour les admins $s = sql_select("login, htpass, statut", "spip_auteurs", sql_in("statut", array('1comite', '0minirezo', 'nouveau'))); while ($t = sql_fetch($s)) { if (strlen($t['login']) and strlen($t['htpass'])) { $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; if ($t['statut'] == '0minirezo') { $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; } } } sql_free($s); if ($p1) { ecrire_fichier($htpasswd, $p1); ecrire_fichier($htpasswd . '-admin', $p2); spip_log("Ecriture de $htpasswd et $htpasswd-admin"); } } } sha256.inc.php000066600000036425152442520560007060 0ustar00<?php /** * Transparent SHA-256 Implementation for PHP 4 and PHP 5 * * Author: Perry McGee (pmcgee@nanolink.ca) * Website: http://www.nanolink.ca/pub/sha256 * * Copyright (C) 2006,2007,2008,2009 Nanolink Solutions * * Created: Feb 11, 2006 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * or see <http://www.gnu.org/licenses/>. * * Include: * * require_once("[path/]sha256.inc.php"); * * Usage Options: * * 1) $shaStr = hash('sha256', $string_to_hash); * * 2) $shaStr = sha256($string_to_hash[, bool ignore_php5_hash = false]); * * 3) $obj = new nanoSha2([bool $upper_case_output = false]); * $shaStr = $obj->hash($string_to_hash[, bool $ignore_php5_hash = false]); * * Reference: http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html * * 2007-12-13: Cleaned up for initial public release * 2008-05-10: Moved all helper functions into a class. API access unchanged. * 2009-06-23: Created abstraction of hash() routine * 2009-07-23: Added detection of 32 vs 64bit platform, and patches. * Ability to define "_NANO_SHA2_UPPER" to yeild upper case hashes. * 2009-08-01: Added ability to attempt to use mhash() prior to running pure * php code. * * 2010-06-10: Added support for 16bytes char and utf8 in string * * NOTE: Some sporadic versions of PHP do not handle integer overflows the * same as the majority of builds. If you get hash results of: * 7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff * * If you do not have permissions to change PHP versions (if you did * you'd probably upgrade to PHP 5 anyway) it is advised you install a * module that will allow you to use their hashing routines, examples are: * - mhash module : http://ca3.php.net/mhash * - Suhosin : http://www.hardened-php.net/suhosin/ * * If you install the Suhosin module, this script will transparently * use their routine and define the PHP routine as _nano_sha256(). * * If the mhash module is present, and $ignore_php5_hash = false the * script will attempt to use the output from mhash prior to running * the PHP code. * * @package SPIP\Core\Authentification\Sha256 */ if (!class_exists('nanoSha2')) { /** * Classe de calcul d'un SHA */ class nanoSha2 { // php 4 - 5 compatable class properties /** Le résultat doit être passé en majuscule ? * * @var bool */ var $toUpper; /** 32 ou 64 bits ? * * @var int */ var $platform; /** bytes par caractères */ var $bytesString = 16; /** * Constructor * * @param bool $toUpper */ function __construct($toUpper = false) { // Determine if the caller wants upper case or not. $this->toUpper = is_bool($toUpper) ? $toUpper : ((defined('_NANO_SHA2_UPPER')) ? true : false); // Deteremine if the system is 32 or 64 bit. $tmpInt = (int)4294967295; $this->platform = ($tmpInt > 0) ? 64 : 32; } /** * Here are the bitwise and functions as defined in FIPS180-2 Standard * * @param int $x * @param int $y * @param int $n * @return int */ function addmod2n($x, $y, $n = 4294967296) // Z = (X + Y) mod 2^32 { $mask = 0x80000000; if ($x < 0) { $x &= 0x7FFFFFFF; $x = (float)$x+$mask; } if ($y < 0) { $y &= 0x7FFFFFFF; $y = (float)$y+$mask; } $r = $x+$y; if ($r >= $n) { while ($r >= $n) { $r -= $n; } } return (int)$r; } /** * Logical bitwise right shift (PHP default is arithmetic shift) * * @param int $x * @param int $n * return int */ function SHR($x, $n) // x >> n { if ($n >= 32) { // impose some limits to keep it 32-bit return (int)0; } if ($n <= 0) { return (int)$x; } $mask = 0x40000000; if ($x < 0) { $x &= 0x7FFFFFFF; $mask = $mask >> ($n-1); return ($x >> $n) | $mask; } return (int)$x >> (int)$n; } /** ROTR * * @param int $x * @param int $n * @return int */ function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); } /** Ch * * @param int $x * @param int $y * @param int $z * @return int */ function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); } /** Maj * * @param int $x * @param int $y * @param int $z * @return int */ function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); } /** Sigma0 * * @param int $x * @return int */ function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); } /** Sigma1 * * @param int $x * @return int */ function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); } /** Sigma_0 * * @param int $x * @return int */ function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); } /** Sigma_1 * * @param int $x * @return int */ function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); } /** String 2 ord UTF8 * * @param string $s * @param int $byteSize * @return array **/ function string2ordUTF8($s, &$byteSize) { $chars = array(); // par defaut sur 8bits $byteSize = 8; $i = 0; while ($i < strlen($s)) { $chars[] = $this->ordUTF8($s, $i, $bytes); $i += $bytes; // mais si un char necessite 16bits, on passe tout sur 16 // sinon on ne concorde pas avec le lecture de la chaine en js // et le sha256 js if ($bytes > 1) { $byteSize = 16; } } return $chars; } /** Ord UTF8 * * @param string $c * @param int $index * @param int $bytes * @return unknown **/ function ordUTF8($c, $index = 0, &$bytes) { $len = strlen($c); $bytes = 0; if ($index >= $len) { return false; } $h = ord($c{$index}); if ($h <= 0x7F) { $bytes = 1; return $h; } else { if ($h < 0xC2) { // pas utf mais renvoyer quand meme ce qu'on a $bytes = 1; return $h; } else { if ($h <= 0xDF && $index < $len-1) { $bytes = 2; return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F); } else { if ($h <= 0xEF && $index < $len-2) { $bytes = 3; return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6 | (ord($c{$index+2}) & 0x3F); } else { if ($h <= 0xF4 && $index < $len-3) { $bytes = 4; return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12 | (ord($c{$index+2}) & 0x3F) << 6 | (ord($c{$index+3}) & 0x3F); } else { // pas utf mais renvoyer quand meme ce qu'on a $bytes = 1; return $h; } } } } } } /** String 2 bin int * * @param string $str * @param int $npad * @return int[] **/ function string2binint($str, $npad = 512) { $bin = array(); $ords = $this->string2ordUTF8($str, $this->bytesString); $npad = $npad/$this->bytesString; $length = count($ords); $ords[] = 0x80; // append the "1" bit followed by 7 0's $pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString; $ords = array_pad($ords, $pad, 0); $mask = (1 << $this->bytesString)-1; for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) { if (!isset($bin[$i >> 5])) { $bin[$i >> 5] = 0; } // pour eviter des notices. $bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32); } $bin[] = $length*$this->bytesString; return $bin; } /** Array split * * @param array $a * @param int $n * @return array **/ function array_split($a, $n) { $split = array(); while (count($a) > $n) { $s = array(); for ($i = 0; $i < $n; $i++) { $s[] = array_shift($a); } $split[] = $s; } if (count($a)) { $a = array_pad($a, $n, 0); $split[] = $a; } return $split; } /** * Process and return the hash. * * @param $str Input string to hash * @param $ig_func Option param to ignore checking for php > 5.1.2 * @return string Hexadecimal representation of the message digest */ function hash($str, $ig_func = true) { unset($binStr); // binary representation of input string unset($hexStr); // 256-bit message digest in readable hex format // check for php's internal sha256 function, ignore if ig_func==true if ($ig_func == false) { if (version_compare(PHP_VERSION, '5.1.2', '>=') AND !defined('_NO_HASH_DEFINED')) { return hash("sha256", $str, false); } else { if (function_exists('mhash') && defined('MHASH_SHA256')) { return base64_encode(bin2hex(mhash(MHASH_SHA256, $str))); } } } /* * SHA-256 Constants * Sequence of sixty-four constant 32-bit words representing the * first thirty-two bits of the fractional parts of the cube roots * of the first sixtyfour prime numbers. */ $K = array( (int)0x428a2f98, (int)0x71374491, (int)0xb5c0fbcf, (int)0xe9b5dba5, (int)0x3956c25b, (int)0x59f111f1, (int)0x923f82a4, (int)0xab1c5ed5, (int)0xd807aa98, (int)0x12835b01, (int)0x243185be, (int)0x550c7dc3, (int)0x72be5d74, (int)0x80deb1fe, (int)0x9bdc06a7, (int)0xc19bf174, (int)0xe49b69c1, (int)0xefbe4786, (int)0x0fc19dc6, (int)0x240ca1cc, (int)0x2de92c6f, (int)0x4a7484aa, (int)0x5cb0a9dc, (int)0x76f988da, (int)0x983e5152, (int)0xa831c66d, (int)0xb00327c8, (int)0xbf597fc7, (int)0xc6e00bf3, (int)0xd5a79147, (int)0x06ca6351, (int)0x14292967, (int)0x27b70a85, (int)0x2e1b2138, (int)0x4d2c6dfc, (int)0x53380d13, (int)0x650a7354, (int)0x766a0abb, (int)0x81c2c92e, (int)0x92722c85, (int)0xa2bfe8a1, (int)0xa81a664b, (int)0xc24b8b70, (int)0xc76c51a3, (int)0xd192e819, (int)0xd6990624, (int)0xf40e3585, (int)0x106aa070, (int)0x19a4c116, (int)0x1e376c08, (int)0x2748774c, (int)0x34b0bcb5, (int)0x391c0cb3, (int)0x4ed8aa4a, (int)0x5b9cca4f, (int)0x682e6ff3, (int)0x748f82ee, (int)0x78a5636f, (int)0x84c87814, (int)0x8cc70208, (int)0x90befffa, (int)0xa4506ceb, (int)0xbef9a3f7, (int)0xc67178f2 ); // Pre-processing: Padding the string $binStr = $this->string2binint($str, 512); // Parsing the Padded Message (Break into N 512-bit blocks) $M = $this->array_split($binStr, 16); // Set the initial hash values $h[0] = (int)0x6a09e667; $h[1] = (int)0xbb67ae85; $h[2] = (int)0x3c6ef372; $h[3] = (int)0xa54ff53a; $h[4] = (int)0x510e527f; $h[5] = (int)0x9b05688c; $h[6] = (int)0x1f83d9ab; $h[7] = (int)0x5be0cd19; // loop through message blocks and compute hash. ( For i=1 to N : ) $N = count($M); for ($i = 0; $i < $N; $i++) { // Break input block into 16 32bit words (message schedule prep) $MI = $M[$i]; // Initialize working variables $_a = (int)$h[0]; $_b = (int)$h[1]; $_c = (int)$h[2]; $_d = (int)$h[3]; $_e = (int)$h[4]; $_f = (int)$h[5]; $_g = (int)$h[6]; $_h = (int)$h[7]; unset($_s0); unset($_s1); unset($_T1); unset($_T2); $W = array(); // Compute the hash and update for ($t = 0; $t < 16; $t++) { // Prepare the first 16 message schedule values as we loop $W[$t] = $MI[$t]; // Compute hash $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]); $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c)); // Update working variables $_h = $_g; $_g = $_f; $_f = $_e; $_e = $this->addmod2n($_d, $_T1); $_d = $_c; $_c = $_b; $_b = $_a; $_a = $this->addmod2n($_T1, $_T2); } for (; $t < 64; $t++) { // Continue building the message schedule as we loop $_s0 = $W[($t+1) & 0x0F]; $_s0 = $this->sigma_0($_s0); $_s1 = $W[($t+14) & 0x0F]; $_s1 = $this->sigma_1($_s1); $W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]); // Compute hash $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t & 0xF]); $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c)); // Update working variables $_h = $_g; $_g = $_f; $_f = $_e; $_e = $this->addmod2n($_d, $_T1); $_d = $_c; $_c = $_b; $_b = $_a; $_a = $this->addmod2n($_T1, $_T2); } $h[0] = $this->addmod2n($h[0], $_a); $h[1] = $this->addmod2n($h[1], $_b); $h[2] = $this->addmod2n($h[2], $_c); $h[3] = $this->addmod2n($h[3], $_d); $h[4] = $this->addmod2n($h[4], $_e); $h[5] = $this->addmod2n($h[5], $_f); $h[6] = $this->addmod2n($h[6], $_g); $h[7] = $this->addmod2n($h[7], $_h); } // Convert the 32-bit words into human readable hexadecimal format. $hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]); return ($this->toUpper) ? strtoupper($hexStr) : $hexStr; } } } /** * Main routine called from an application using this include. * * General usage: * require_once('sha256.inc.php'); * $hashstr = sha256('abc'); * * @Note * PHP Strings are limitd to (2^31)-1, so it is not worth it to * check for input strings > 2^64 as the FIPS180-2 defines. * * @param string $str Chaîne dont on veut calculer le SHA * @param bool $ig_func * @return string Le SHA de la chaîne */ function _nano_sha256($str, $ig_func = true) { $obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false); return $obj->hash($str, $ig_func); } // 2009-07-23: Added check for function as the Suhosin plugin adds this routine. if (!function_exists('sha256')) { /** * Calcul du SHA256 * * @param string $str Chaîne dont on veut calculer le SHA * @param bool $ig_func * @return string Le SHA de la chaîne */ function sha256($str, $ig_func = true) { return _nano_sha256($str, $ig_func); } } // support to give php4 the hash() routine which abstracts this code. if (!function_exists('hash')) { define('_NO_HASH_DEFINED', true); /** * Retourne le calcul d'un hachage d'une chaîne (pour PHP4) * * @param string $algo Nom de l'algorythme de hachage * @param string $data Chaîne à hacher * @return string|bool * Hash de la chaîne * False si pas d'algo trouvé */ function hash($algo, $data) { if (empty($algo) || !is_string($algo) || !is_string($data)) { return false; } if (function_exists($algo)) { return $algo($data); } } }ldap.php000066600000023733152442520560006216 0ustar00<?php /***************************************************************************\ * SPIP, Systeme de publication pour l'internet * * * * Copyright (c) 2001-2019 * * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * * * * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * \***************************************************************************/ /** * Gestion de l'authentification par LDAP * * @package SPIP\Core\Authentification\Ldap **/ if (!defined('_ECRIRE_INC_VERSION')) { return; } // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login // ne pas ecraser une definition perso dans mes_options if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { $GLOBALS['ldap_attributes'] = array( 'login' => array('sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'), 'nom' => "cn", 'email' => "mail", 'bio' => "description" ); } /** * Fonction principale d'authentification du module auth/ldap * * - On se bind avec le compte generique defini dans config/ldap.php, * - On determine le DN de l'utilisateur candidat a l'authentification, * - On se re-bind avec ce DN et le mot de passe propose. * * Si la connexion est autorisee, on renvoie pour enregistrement en session, * en plus des champs SQL habituels, les informations de connexion de * l'utilisateur (DN et password). Cela permettra de se binder en cours de * session sous son identite specifique pour les operations necessitant des * privileges particuliers. * TODO: Gerer une constante de conf qui permette de choisir entre ce * comportement et tout faire avec le compte generique. * * @param string $login * @param string $pass * @param string $serveur * @param bool $phpauth * @return string */ function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); // Utilisateur connu ? // si http auth, inutile de reauthentifier: cela // ne marchera pas avec auth http autre que basic. $checkpass = isset($_SERVER["REMOTE_USER"]) ? false : true; if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { return array(); } $credentials_ldap = array('ldap_dn' => $dn, 'ldap_password' => $pass); // Si l'utilisateur figure deja dans la base, y recuperer les infos $r = sql_fetsel("*", "spip_auteurs", "login=" . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); if ($r) { return array_merge($r, $credentials_ldap); } // sinon importer les infos depuis LDAP, if ($GLOBALS['meta']["ldap_statut_import"] and $desc = auth_ldap_retrouver($dn, array(), $serveur) ) { // rajouter le statut indique a l'install $desc['statut'] = $GLOBALS['meta']["ldap_statut_import"]; $desc['login'] = $login; $desc['source'] = 'ldap'; $desc['pass'] = ''; $r = sql_insertq('spip_auteurs', $desc, '', $serveur); } if ($r) { return array_merge( $credentials_ldap, sql_fetsel("*", "spip_auteurs", "id_auteur=" . intval($r), '', '', '', '', $serveur) ); } // sinon echec spip_log("Creation de l'auteur '$login' impossible"); return array(); } /** * Connexion à l'annuaire LDAP * * Il faut passer par `spip_connect()` pour avoir les info * donc potentiellement indiquer un serveur * meme si dans les fait cet argument est toujours vide * * @param string $serveur * @return array */ function auth_ldap_connect($serveur = '') { include_spip('base/connect_sql'); static $connexions_ldap = array(); if (isset($connexions_ldap[$serveur])) { return $connexions_ldap[$serveur]; } $connexion = spip_connect($serveur); if (!is_array($connexion['ldap'])) { if ($connexion['authentification']['ldap']) { $f = _DIR_CONNECT . $connexion['authentification']['ldap']; unset($GLOBALS['ldap_link']); if (is_readable($f)) { include_once($f); }; if (isset($GLOBALS['ldap_link'])) { $connexion['ldap'] = array( 'link' => $GLOBALS['ldap_link'], 'base' => $GLOBALS['ldap_base'] ); } else { spip_log("connection LDAP $serveur mal definie dans $f"); } if (isset($GLOBALS['ldap_champs'])) { $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; } } else { spip_log("connection LDAP $serveur inconnue"); } } return $connexions_ldap[$serveur] = $connexion['ldap']; } /** * Retrouver un login, et vérifier son pass si demandé par `$checkpass` * * @param string $login * @param string $pass * @param bool $checkpass * @param string $serveur * @return string * Le login trouvé ou chaine vide si non trouvé */ function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { // Securite anti-injection et contre un serveur LDAP laxiste $login_search = preg_replace("/[^-@._\s\d\w]/", "", $login); if (!strlen($login_search) or ($checkpass and !strlen($pass))) { return ''; } // verifier la connexion if (!$ldap = auth_ldap_connect($serveur)) { return ''; } $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; $logins = is_array($desc['login']) ? $desc['login'] : array($desc['login']); // Tenter une recherche pour essayer de retrouver le DN foreach ($logins as $att) { $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", array("dn")); $info = @ldap_get_entries($ldap_link, $result); // Ne pas accepter les resultats si plus d'une entree // (on veut un attribut unique) if (is_array($info) and $info['count'] == 1) { $dn = $info[0]['dn']; if (!$checkpass) { return $dn; } if (@ldap_bind($ldap_link, $dn, $pass)) { return $dn; } } } if ($checkpass and !isset($dn)) { // Si echec, essayer de deviner le DN foreach ($logins as $att) { $dn = "$att=$login_search, $ldap_base"; if (@ldap_bind($ldap_link, $dn, $pass)) { return "$att=$login_search, $ldap_base"; } } } return ''; } /** * Retrouver un DN depuis LDAP * * @param string $dn * @param array $desc * @param string $serveur * @return array */ function auth_ldap_retrouver($dn, $desc = array(), $serveur = '') { // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP if (!$ldap = spip_connect_ldap($serveur)) { spip_log("ldap $serveur injoignable"); return array(); } $ldap_link = $ldap['link']; if (!$desc) { $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; unset($desc['login']); } $result = @ldap_read($ldap_link, $dn, "objectClass=*", array_values($desc)); if (!$result) { return array(); } // Recuperer les donnees du premier (unique?) compte de l'auteur $val = @ldap_get_entries($ldap_link, $result); if (!is_array($val) or !is_array($val[0])) { return array(); } $val = $val[0]; // Convertir depuis UTF-8 (jeu de caracteres par defaut) include_spip('inc/charsets'); foreach ($desc as $k => $v) { $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); } return $desc; } /** * Retrouver le login de quelqu'un qui cherche à se loger * * @param string $login * @param string $serveur * @return string */ function auth_ldap_retrouver_login($login, $serveur = '') { return auth_ldap_search($login, '', false, $serveur) ? $login : ''; } /** * Vérification de la validité d'un mot de passe pour le mode d'auth concerné * * C'est ici que se font éventuellement les vérifications de longueur mini/maxi * ou de force. * * @param string $login * Le login de l'auteur : permet de vérifier que pass et login sont différents * même à la creation lorsque l'auteur n'existe pas encore * @param string $new_pass * @param int $id_auteur * Si auteur existant déjà * @param string $serveur * @return string * Message d'erreur si login non valide, chaîne vide sinon */ function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { include_spip('auth/spip'); return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); } /** * Informer du droit de modifier ou non le pass * * On ne peut pas détecter à l'avance si l'autorisation sera donnée, il * faudra informer l'utilisateur a posteriori si la modif n'a pas pu se * faire. * * @param string $serveur * @return bool * Pour un auteur LDAP, a priori toujours true, à conditiion que le serveur * l'autorise: par exemple, pour OpenLDAP il faut avoir dans slapd.conf: * ``` * access to attr=userPassword * by self write * ... * ``` */ function auth_ldap_autoriser_modifier_pass($serveur = '') { return true; } /** * Fonction de modification du mot de passe * * On se bind au LDAP cette fois sous l'identité de l'utilisateur, car le * compte générique defini dans config/ldap.php n'a généralement pas (et * ne devrait pas avoir) les droits suffisants pour faire la modification. * * @param $login * @param $new_pass * @param $id_auteur * @param string $serveur * @return bool * Informe du succès ou de l'echec du changement du mot de passe */ function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { return false; } if (!$ldap = auth_ldap_connect($serveur)) { return ''; } $link = $ldap['link']; include_spip("inc/session"); $dn = session_get('ldap_dn'); if ('' == $dn) { return false; } if (!ldap_bind($link, $dn, session_get('ldap_password'))) { return false; } $encoded_pass = "{MD5}" . base64_encode(pack("H*", md5($new_pass))); $success = ldap_mod_replace($link, $dn, array('userPassword' => $encoded_pass)); return $success; }
/home/atelierpru/provence/6bf95/../plugins/../52177/auth.tar