1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: |
|
20: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
21: |
|
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: |
|
30: | include_once $GLOBALS['xoops']->path('class/auth/auth_ldap.php');
|
31: |
|
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: |
|
40: | class XoopsAuthAds extends XoopsAuthLdap
|
41: | {
|
42: | |
43: | |
44: | |
45: |
|
46: | public function __construct(XoopsDatabase $dao = null)
|
47: | {
|
48: | parent::__construct($dao);
|
49: | }
|
50: |
|
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: |
|
61: | public function authenticate($uname, $pwd = null)
|
62: | {
|
63: | $authenticated = false;
|
64: | if (!extension_loaded('ldap')) {
|
65: | $this->setErrors(0, _AUTH_LDAP_EXTENSION_NOT_LOAD);
|
66: |
|
67: | return $authenticated;
|
68: | }
|
69: | $this->_ds = ldap_connect($this->ldap_server, $this->ldap_port);
|
70: | if ($this->_ds) {
|
71: | ldap_set_option($this->_ds, LDAP_OPT_PROTOCOL_VERSION, $this->ldap_version);
|
72: | ldap_set_option($this->_ds, LDAP_OPT_REFERRALS, 0);
|
73: | if ($this->ldap_use_TLS) {
|
74: | if (!ldap_start_tls($this->_ds)) {
|
75: | $this->setErrors(0, _AUTH_LDAP_START_TLS_FAILED);
|
76: | }
|
77: | }
|
78: |
|
79: |
|
80: | $userUPN = $this->getUPN($uname);
|
81: | if (!$userUPN) {
|
82: | return false;
|
83: | }
|
84: |
|
85: | $authenticated = ldap_bind($this->_ds, $userUPN, $this->cp1252_to_utf8(stripslashes($pwd)));
|
86: | if ($authenticated) {
|
87: |
|
88: | $dn = $this->getUserDN($uname);
|
89: | if ($dn) {
|
90: | return $this->loadXoopsUser($dn, $uname, $pwd);
|
91: | } else {
|
92: | return false;
|
93: | }
|
94: | } else {
|
95: | $this->setErrors(ldap_errno($this->_ds), ldap_err2str(ldap_errno($this->_ds)) . '(' . $userUPN . ')');
|
96: | }
|
97: | } else {
|
98: | $this->setErrors(0, _AUTH_LDAP_SERVER_NOT_FOUND);
|
99: | }
|
100: | @ldap_close($this->_ds);
|
101: |
|
102: | return $authenticated;
|
103: | }
|
104: |
|
105: | |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | |
114: |
|
115: | public function getUPN($uname)
|
116: | {
|
117: | $userDN = $uname . '@' . $this->ldap_domain_name;
|
118: |
|
119: | return $userDN;
|
120: | }
|
121: | }
|
122: |
|
123: | |