X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fauth.phh;h=193bca63a551b1c54cad6a63416ff72a2e8d5fc4;hb=4542fee714762f3f2d1b29ad276dd44f24be3aaa;hp=29769a2dfe09e61c6fb0add7ac89d4b9eab1cfae;hpb=29a83e580080f589142bc8639d8a757503fd3175;p=brisk.git diff --git a/web/Obj/auth.phh b/web/Obj/auth.phh index 29769a2..193bca6 100644 --- a/web/Obj/auth.phh +++ b/web/Obj/auth.phh @@ -2,7 +2,7 @@ /* * brisk - auth.phh * - * Copyright (C) 2006-2011 Matteo Nastasi + * Copyright (C) 2006-2012 Matteo Nastasi * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it @@ -24,11 +24,11 @@ require_once("${G_base}Obj/dbase_${G_dbasetype}.phh"); -define(CHAL_SHM_DIMS_MIN, 16384); -define(CHAL_SHM_DIMS_MAX, 65536); -define(CHAL_SHM_DIMS_DLT, 16384); -define(CHAL_VALID_TIME, 15); -define(CHAL_GARBAGE_TIMEOUT, 5); +define('CHAL_SHM_DIMS_MIN', 16384); +define('CHAL_SHM_DIMS_MAX', 65536); +define('CHAL_SHM_DIMS_DLT', 16384); +define('CHAL_VALID_TIME', 15); +define('CHAL_GARBAGE_TIMEOUT', 5); class Challenge { @@ -47,6 +47,8 @@ class Challenge { } class Challenges { + static $delta_t; + var $item; var $item_n; var $mod; @@ -70,13 +72,13 @@ class Challenges { log_auth("xxx", sprintf("Challenges::add [%s]\n", $login)); // FIXME Checks here if ($login == '') { - return ($G_false); + return (FALSE); } // log_auth("xxx", "LOOPI tstamp: ".$this->item[$i]->tstamp." curtime: ".$curtime); - if (($chal = new Challenge($login, $token, $ip, $tstamp)) == null) { - return ($G_false); + if (($chal = new Challenge($login, $token, $ip, $tstamp)) == FALSE) { + return (FALSE); } $this->item[$this->item_n] = $chal; @@ -151,7 +153,7 @@ class Challenges { } // Static functions - static function &create() + static function create() { $chal =& new Challenges(); @@ -160,14 +162,12 @@ class Challenges { return $chal; } - function &load_data() + function load_data() { - GLOBAL $G_false, $sess; - $doexit = FALSE; + GLOBAL $sess; do { - if (($tok = @ftok(FTOK_PATH."/challenges", "B")) == -1) { + if (($tok = @ftok(FTOK_PATH."/challenges", "C")) == -1) { log_main("ftok failed"); - $doexit = TRUE; break; } @@ -179,7 +179,7 @@ class Challenges { $shm_sz = CHAL_SHM_DIMS_MIN; if ($shm = shm_attach($tok, $shm_sz)) { - $chals = @shm_get_var($shm, $tok); + $chals = @shm_get_var($shm, $tok); // CHECKED BELOW log_only("challenges == ".($chals == FALSE ? "FALSE" : "TRUE")." challenges === ".($chals === FALSE ? "FALSE" : "TRUE")." challenges isset ".(isset($chals) ? "TRUE" : "FALSE")); @@ -191,6 +191,7 @@ class Challenges { log_only("PUT_VAR FALLITA ".strlen(serialize($chals))); log_only(serialize($chals)); } + log_shme("Challenges::save_data2"); } $chals->shm_sz = $shm_sz; @@ -199,23 +200,19 @@ class Challenges { $chals->garbage_manager(); - $ret = &$chals; - return ($ret); + return ($chals); } while (0); - if ($doexit) - exit(); - - return ($G_false); + return (FALSE); } - function save_data(&$chals) + function save_data($chals) { $shm = FALSE; $oldmod = $chals->mod; - if (($tok = @ftok(FTOK_PATH."/challenges", "B")) == -1) + if (($tok = @ftok(FTOK_PATH."/challenges", "C")) == -1) return (FALSE); while ($chals->shm_sz < CHAL_SHM_DIMS_MAX) { @@ -226,7 +223,8 @@ class Challenges { log_only("challenges count ".count($chals->item)." _n: ".$chals->item_n); $chals->mod = FALSE; - if (shm_put_var($shm, $tok, $chals) != FALSE) { + if (@shm_put_var($shm, $tok, $chals) != FALSE) { + log_shme("Challenges::save_data"); shm_detach($shm); return (TRUE); } @@ -246,31 +244,26 @@ class Challenges { return (FALSE); } - function lock_data() + static function lock_data($is_exclusive) { - if (($tok = @ftok(FTOK_PATH."/challenges", "B")) == -1) { - return (FALSE); - } - // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { - return (FALSE); - } - if (sem_acquire($res)) { - log_lock("LOCK challenges"); - return ($res); - } - else - return (FALSE); + if (($res = file_lock(FTOK_PATH."/challenges", $is_exclusive)) != FALSE) { + self::$delta_t = microtime(TRUE); + log_lock("LOCK challenges [".self::$delta_t."]"); + + return ($res); + } + + return (FALSE); } - function unlock_data($res) + static function unlock_data($res) { GLOBAL $sess; - log_lock("UNLOCK challenges"); + log_lock("UNLOCK challenges [".(microtime(TRUE) - (self::$delta_t))."]"); - return (sem_release($res)); + file_unlock($res); } } // End CLASS Challenges -?> \ No newline at end of file +?>