| 1 | <?php defined('SYSPATH') or die('No direct script access.'); |
|---|
| 2 | |
|---|
| 3 | class LDAP_Auth extends Auth_Core { |
|---|
| 4 | |
|---|
| 5 | protected $ldap_version = 3; |
|---|
| 6 | protected $ldap_host = 'localhost'; |
|---|
| 7 | protected $ldap_base = ''; |
|---|
| 8 | |
|---|
| 9 | public function protocol($version) |
|---|
| 10 | { |
|---|
| 11 | if ($version == 2 OR $version == 3) |
|---|
| 12 | $this->ldap_version = $version; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | public function host($host) |
|---|
| 16 | { |
|---|
| 17 | $this->ldap_host = $host; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | public function base($base) |
|---|
| 21 | { |
|---|
| 22 | $this->ldap_base = $base; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | public function login($user, $password, $remember = FALSE) |
|---|
| 26 | { |
|---|
| 27 | if (empty($password)) |
|---|
| 28 | return FALSE; |
|---|
| 29 | |
|---|
| 30 | $user = 'cn='.$user.','.$this->ldap_base; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | $ds = ldap_connect($this->ldap_host); |
|---|
| 34 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $this->ldap_version); |
|---|
| 35 | $r = @ldap_bind($ds, $user, $password); |
|---|
| 36 | $password = NULL; |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | if ($r) |
|---|
| 40 | { |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | $this->complete_login($user); |
|---|
| 59 | |
|---|
| 60 | return TRUE; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | return FALSE; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | protected function complete_login($user) |
|---|
| 67 | { |
|---|
| 68 | |
|---|
| 69 | $this->session->set(array |
|---|
| 70 | ( |
|---|
| 71 | 'username' => $user |
|---|
| 72 | )); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | } |
|---|