/atk/security/class.auth_pop3.inc

https://github.com/BlackNinjaDruid/eyATK · PHP · 135 lines · 67 code · 14 blank · 54 comment · 12 complexity · 0377bf0e54f19319daacb28579a70269 MD5 · raw file

  1. <?php
  2. /**
  3. * This file is part of the Achievo ATK distribution.
  4. * Detailed copyright and licensing information can be found
  5. * in the doc/COPYRIGHT and doc/LICENSE files which should be
  6. * included in the distribution.
  7. *
  8. * @package atk
  9. * @subpackage security
  10. *
  11. * @copyright (c)2000-2004 Ibuildings.nl BV
  12. * @license http://www.achievo.org/atk/licensing ATK Open Source License
  13. *
  14. * @version $Revision: 6280 $
  15. * $Id: class.auth_pop3.inc 6354 2009-04-15 02:41:21Z mvdam $
  16. */
  17. /**
  18. * Driver for authentication using pop3.
  19. *
  20. * Does not support authorization.
  21. *
  22. * @author Ivo Jansch <ivo@achievo.org>
  23. * @package atk
  24. * @subpackage security
  25. *
  26. */
  27. class auth_pop3 extends auth_interface
  28. {
  29. /**
  30. * Validate user.
  31. * @param String $user the username
  32. * @param String $passwd the password
  33. * @return int AUTH_SUCCESS - Authentication succesful
  34. * AUTH_MISMATCH - Authentication failed, wrong
  35. * user/password combination
  36. * AUTH_LOCKED - Account is locked, can not login
  37. * with current username.
  38. * AUTH_ERROR - Authentication failed due to some
  39. * error which cannot be solved by
  40. * just trying again. If you return
  41. * this value, you *must* also
  42. * fill the m_fatalError variable.
  43. */
  44. function validateUser($user, $passwd)
  45. {
  46. if ($user=="") return AUTH_UNVERIFIED; // can't verify if we have no userid
  47. global $g_pop3_responses;
  48. /* if it's a virtual mail server add @<domain> to the username */
  49. if(atkconfig("auth_mail_virtual") == true)
  50. $user = $user . "@" . atkconfig("auth_mail_suffix");
  51. $server = atkconfig("auth_mail_server");
  52. // Special feature
  53. if ($server=="[db]")
  54. {
  55. // if server is set to [db], that means we have a different server per
  56. // user. We lookup in the database what server we need to call.
  57. $db = &atkGetDb();
  58. $res = $db->getrows("SELECT auth_server
  59. FROM ".atkconfig("auth_usertable")."
  60. WHERE ".atkconfig("auth_userfield")."='".$user."'");
  61. if (count($res)==0)
  62. {
  63. // User not found.
  64. return AUTH_MISMATCH;
  65. }
  66. $server = $res[0]["auth_server"];
  67. }
  68. $secMgr = &atkGetSecurityManager();
  69. if ($server=="")
  70. {
  71. $secMgr->log(1,"pop3auth error: No server specified");
  72. atkdebug("pop3auth error: No server specified");
  73. $this->m_fatalError = atktext("auth_no_server");
  74. return AUTH_ERROR;
  75. }
  76. /* connect */
  77. $port = atkconfig("auth_mail_port");
  78. $link_id = fsockopen($server, $port, $errno, $errstr, 30);
  79. if (!$link_id)
  80. {
  81. $secMgr->log(1,"pop3auth serverconnect error $server: $errstr");
  82. atkdebug("Error connecting to server $server: $errstr");
  83. $this->m_fatalError = atktext("auth_unable_to_connect");
  84. return AUTH_ERROR;
  85. }
  86. /* authenticate */
  87. $void = fgets($link_id, 1000);
  88. fputs($link_id, "USER ".$user."\r\n");
  89. $void = fgets($link_id, 1000);
  90. fputs($link_id, "PASS ".$passwd."\r\n");
  91. $auth = fgets($link_id, 1000);
  92. fputs($link_id, "QUIT\r\n");
  93. fclose($link_id);
  94. $secMgr->log(1, "pop3auth response for user $user: ".trim($auth));
  95. // search application specified pop3 responses..
  96. if (is_array($g_pop3_responses))
  97. {
  98. foreach($g_pop3_responses as $substring => $message)
  99. {
  100. if (stristr($auth, $substring)!=false)
  101. {
  102. $this->m_fatalError = $message;
  103. return AUTH_ERROR;
  104. }
  105. }
  106. }
  107. /* login ok? */
  108. if (!stristr($auth, "ERR")) return AUTH_SUCCESS;
  109. else return AUTH_MISMATCH;
  110. }
  111. /**
  112. * Pop3 can't handle md5 passwords since they must be sent to the server
  113. * as plain text.
  114. * @return boolean False
  115. */
  116. function canMd5()
  117. {
  118. return false;
  119. }
  120. }
  121. ?>