Esempio n. 1
0
 /**
  * Fast authentication of a certain user
  * 
  * Returns a PEAR_Error if:
  *   o file doesn't exist
  *   o file couldn't be opened in read mode
  *   o file couldn't be locked exclusively
  *   o file couldn't be unlocked (only if auth fails)
  *   o file couldn't be closed (only if auth fails)
  *
  * @static   call this method statically for a reasonable fast authentication
  * @access   public
  * @return   mixed   true if authenticated, false if not or PEAR_Error
  * @param    string  $file   path to passwd file
  * @param    string  $user   user to authenticate
  * @param    string  $pass   plaintext password
  */
 function staticAuth($file, $user, $pass)
 {
     $line = File_Passwd_Common::_auth($file, $user);
     if (!$line || PEAR::isError($line)) {
         return $line;
     }
     @(list(, $real) = explode(':', $line));
     return File_Passwd_Cvs::generatePassword($pass, $real) === $real;
 }
Esempio n. 2
0
 /**
  * Fast authentication of a certain user
  * 
  * Returns a PEAR_Error if:
  *   o file doesn't exist
  *   o file couldn't be opened in read mode
  *   o file couldn't be locked exclusively
  *   o file couldn't be unlocked (only if auth fails)
  *   o file couldn't be closed (only if auth fails)
  *   o invalid encryption mode <var>$mode</var> was provided
  *
  * @static   call this method statically for a reasonable fast authentication
  * @access   public
  * @return   mixed   true if authenticated, false if not or PEAR_Error
  * @param    string  $file   path to passwd file
  * @param    string  $user   user to authenticate
  * @param    string  $pass   plaintext password
  * @param    string  $mode   encryption mode to use (des or md5)
  */
 function staticAuth($file, $user, $pass, $mode)
 {
     $line = File_Passwd_Common::_auth($file, $user);
     if (!$line || PEAR::isError($line)) {
         return $line;
     }
     list(, $real) = explode(':', $line);
     $crypted = File_Passwd_Unix::_genPass($pass, $real, $mode);
     if (PEAR::isError($crypted)) {
         return $crypted;
     }
     return $crypted === $real;
 }
Esempio n. 3
0
 /**
  * Fast authentication of a certain user
  * 
  * Returns a PEAR_Error if:
  *   o file doesn't exist
  *   o file couldn't be opened in read mode
  *   o file couldn't be locked exclusively
  *   o file couldn't be unlocked (only if auth fails)
  *   o file couldn't be closed (only if auth fails)
  *   o invalid encryption method <var>$nt_or_lm</var> was provided
  *
  * @static   call this method statically for a reasonable fast authentication
  * @access   public
  * @return   mixed   true if authenticated, false if not or PEAR_Error
  * @param    string  $file       path to passwd file
  * @param    string  $user       user to authenticate
  * @param    string  $pass       plaintext password
  * @param    string  $nt_or_lm   encryption mode to use (NT or LM hash)
  */
 function staticAuth($file, $user, $pass, $nt_or_lm = 'nt')
 {
     $line = File_Passwd_Common::_auth($file, $user);
     if (!$line || PEAR::isError($line)) {
         return $line;
     }
     @(list(, , $lm, $nt) = explode(':', $line));
     $chap =& new Crypt_CHAP_MSv1();
     switch (strToLower($nt_or_lm)) {
         case FILE_PASSWD_NT:
             $real = $nt;
             $crypted = $chap->ntPasswordHash($pass);
             break;
         case FILE_PASSWD_LM:
             $real = $lm;
             $crypted = $chap->lmPasswordHash($pass);
             break;
         default:
             return PEAR::raiseError(sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, $nt_or_lm), FILE_PASSWD_E_INVALID_ENC_MODE);
     }
     return strToUpper(bin2hex($crypted)) === $real;
 }
 /**
  * Fast authentication of a certain user
  * 
  * Returns a PEAR_Error if:
  *   o file doesn't exist
  *   o file couldn't be opened in read mode
  *   o file couldn't be locked exclusively
  *   o file couldn't be unlocked (only if auth fails)
  *   o file couldn't be closed (only if auth fails)
  *
  * @static   call this method statically for a reasonable fast authentication
  * 
  * @throws   PEAR_Error
  * @access   public
  * @return   mixed   true if authenticated, false if not or PEAR_Error
  * @param    string  $file   path to passwd file
  * @param    string  $user   user to authenticate
  * @param    string  $pass   plaintext password
  * @param    string  $realm  the realm the user is in
  */
 function staticAuth($file, $user, $pass, $realm)
 {
     $line = File_Passwd_Common::_auth($file, $user . ':' . $realm);
     if (!$line || PEAR::isError($line)) {
         return $line;
     }
     @(list(, , $real) = explode(':', $line));
     return md5("{$user}:{$realm}:{$pass}") === $real;
 }
 /**
  * Fast authentication of a certain user
  * 
  * Returns a PEAR_Error if:
  *   o file doesn't exist
  *   o file couldn't be opened in read mode
  *   o file couldn't be locked exclusively
  *   o file couldn't be unlocked (only if auth fails)
  *   o file couldn't be closed (only if auth fails)
  *   o invalid encryption function <var>$opts[0]</var>,
  *     or no delimiter character <var>$opts[1]</var> was provided
  *
  * @throws   PEAR_Error  FILE_PASSWD_E_UNDEFINED |
  *                       FILE_PASSWD_E_FILE_NOT_OPENED |
  *                       FILE_PASSWD_E_FILE_NOT_LOCKED |
  *                       FILE_PASSWD_E_FILE_NOT_UNLOCKED |
  *                       FILE_PASSWD_E_FILE_NOT_CLOSED |
  *                       FILE_PASSWD_E_INVALID_ENC_MODE
  * @static   call this method statically for a reasonable fast authentication
  * @access   public
  * @return   mixed   Returns &true; if authenticated, &false; if not or 
  *                   <classname>PEAR_Error</classname> on failure.
  * @param    string  $file   path to passwd file
  * @param    string  $user   user to authenticate
  * @param    string  $pass   plaintext password
  * @param    array   $otps   encryption function and delimiter charachter
  *                           (in this order)
  */
 function staticAuth($file, $user, $pass, $opts)
 {
     setType($opts, 'array');
     if (count($opts) != 2 || empty($opts[1])) {
         return PEAR::raiseError('Insufficient options.', 0);
     }
     $line = File_Passwd_Common::_auth($file, $user, $opts[1]);
     if (!$line || PEAR::isError($line)) {
         return $line;
     }
     list(, $real) = explode($opts[1], $line);
     $crypted = File_Passwd_Custom::_genPass($pass, $real, $opts[0]);
     if (PEAR::isError($crypted)) {
         return $crypted;
     }
     return $crypted === $real;
 }
Esempio n. 6
0
 /**
  * Base method for File_Passwd::staticAuth()
  * 
  * Returns a PEAR_Error if:
  *   o file doesn't exist
  *   o file couldn't be opened in read mode
  *   o file couldn't be locked exclusively
  *   o file couldn't be unlocked (only if auth fails)
  *   o file couldn't be closed (only if auth fails)
  * 
  * @throws   PEAR_Error
  * @access   protected
  * @return   mixed       line of passwd file containing <var>$id</var>,
  *                       false if <var>$id</var> wasn't found or PEAR_Error
  * @param    string      $file   path to passwd file
  * @param    string      $id     user_id to search for
  * @param    string      $sep    field separator
  */
 function _auth($file, $id, $sep = ':')
 {
     $file = realpath($file);
     if (!is_file($file)) {
         return PEAR::raiseError("File '{$file}' couldn't be found.", 0);
     }
     $fh =& File_Passwd_Common::_open('r', $file);
     if (PEAR::isError($fh)) {
         return $fh;
     }
     $cmp = $id . $sep;
     $len = strlen($cmp);
     while ($line = fgets($fh)) {
         if (!strncmp($line, $cmp, $len)) {
             File_Passwd_Common::_close($fh);
             return trim($line);
         }
     }
     $e = File_Passwd_Common::_close($fh);
     if (PEAR::isError($e)) {
         return $e;
     }
     return false;
 }
Esempio n. 7
0
 function test_auth()
 {
     $this->assertTrue('1stLine' === File_Passwd_Common::_auth('common.txt', '1stLine'));
     $this->assertFalse(File_Passwd_Common::_auth('common.txt', 'nonexist'));
 }