|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) 2020 Arthur Schiwon <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @author Arthur Schiwon <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU AGPL version 3 or any later version |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OCA\User_LDAP\PagedResults; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class Php73 |
|
29
|
|
|
* |
|
30
|
|
|
* implements paged results support with PHP APIs available from PHP 7.3 |
|
31
|
|
|
* |
|
32
|
|
|
* @package OCA\User_LDAP\PagedResults |
|
33
|
|
|
*/ |
|
34
|
|
|
class Php73 implements IAdapter { |
|
35
|
|
|
use TLinkId; |
|
36
|
|
|
|
|
37
|
|
|
/** @var array */ |
|
38
|
|
|
protected $linkData = []; |
|
39
|
|
|
|
|
40
|
|
|
public function getResponseCallFunc(): string { |
|
41
|
|
|
return 'ldap_parse_result'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function responseCall($link): bool { |
|
45
|
|
|
$linkId = $this->getLinkId($link); |
|
46
|
|
|
return ldap_parse_result(...$this->linkData[$linkId]['responseArgs']); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getResponseCallArgs(array $originalArgs): array { |
|
50
|
|
|
$link = array_shift($originalArgs); |
|
51
|
|
|
$linkId = $this->getLinkId($link); |
|
52
|
|
|
|
|
53
|
|
|
if(!isset($this->linkData[$linkId])) { |
|
54
|
|
|
$this->linkData[$linkId] = []; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->linkData[$linkId]['responseErrorCode'] = 0; |
|
58
|
|
|
$this->linkData[$linkId]['responseErrorMessage'] = ''; |
|
59
|
|
|
$this->linkData[$linkId]['serverControls'] = []; |
|
60
|
|
|
$matchedDn = null; |
|
61
|
|
|
$referrals = []; |
|
62
|
|
|
|
|
63
|
|
|
$this->linkData[$linkId]['responseArgs'] = [ |
|
64
|
|
|
$link, |
|
65
|
|
|
array_shift($originalArgs), |
|
66
|
|
|
&$this->linkData[$linkId]['responseErrorCode'], |
|
67
|
|
|
$matchedDn, |
|
68
|
|
|
&$this->linkData[$linkId]['responseErrorMessage'], |
|
69
|
|
|
$referrals, |
|
70
|
|
|
&$this->linkData[$linkId]['serverControls'] |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
return $this->linkData[$linkId]['responseArgs']; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getCookie($link): string { |
|
78
|
|
|
$linkId = $this->getLinkId($link); |
|
79
|
|
|
return $this->linkData[$linkId]['serverControls'][LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? ''; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getRequestCallFunc(): ?string { |
|
83
|
|
|
return null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function setRequestParameters($link, int $pageSize, bool $isCritical): void { |
|
87
|
|
|
$linkId = $this->getLinkId($link); |
|
88
|
|
|
if(!isset($this->linkData[$linkId])) { |
|
89
|
|
|
$this->linkData[$linkId] = []; |
|
90
|
|
|
} |
|
91
|
|
|
$this->linkData[$linkId]['requestArgs'] = []; |
|
92
|
|
|
$this->linkData[$linkId]['requestArgs']['pageSize'] = $pageSize; |
|
93
|
|
|
$this->linkData[$linkId]['requestArgs']['isCritical'] = $isCritical; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function getRequestCallArgs($link): array { |
|
97
|
|
|
// no separate call |
|
98
|
|
|
return []; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function requestCall($link): bool { |
|
102
|
|
|
// no separate call |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function setSearchArgs( |
|
107
|
|
|
$link, |
|
108
|
|
|
string $baseDN, |
|
109
|
|
|
string $filter, |
|
110
|
|
|
array $attr, |
|
111
|
|
|
int $attrsOnly, |
|
112
|
|
|
int $limit |
|
113
|
|
|
): void { |
|
114
|
|
|
$linkId = $this->getLinkId($link); |
|
115
|
|
|
if(!isset($this->linkData[$linkId])) { |
|
116
|
|
|
$this->linkData[$linkId] = []; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$this->linkData[$linkId]['searchArgs'] = func_get_args(); |
|
120
|
|
|
$this->preparePagesResultsArgs($linkId, 'searchArgs'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getSearchArgs($link): array { |
|
124
|
|
|
$linkId = $this->getLinkId($link); |
|
125
|
|
|
return $this->linkData[$linkId]['searchArgs']; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function setReadArgs($link, string $baseDN, string $filter, array $attr): void { |
|
129
|
|
|
$linkId = $this->getLinkId($link); |
|
130
|
|
|
if(!isset($this->linkData[$linkId])) { |
|
131
|
|
|
$this->linkData[$linkId] = []; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
$this->linkData[$linkId]['readArgs'] = func_get_args(); |
|
135
|
|
|
$this->linkData[$linkId]['readArgs'][] = 0; // $attrsonly default |
|
136
|
|
|
$this->linkData[$linkId]['readArgs'][] = -1; // $sizelimit default |
|
137
|
|
|
$this->preparePagesResultsArgs($linkId, 'readArgs'); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function getReadArgs($link): array { |
|
141
|
|
|
$linkId = $this->getLinkId($link); |
|
142
|
|
|
return $this->linkData[$linkId]['readArgs']; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
protected function preparePagesResultsArgs(int $linkId, string $methodKey): void { |
|
146
|
|
|
if(!isset($this->linkData[$linkId]['requestArgs'])) { |
|
147
|
|
|
return; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$serverControls = [[ |
|
151
|
|
|
'oid' => LDAP_CONTROL_PAGEDRESULTS, |
|
|
|
|
|
|
152
|
|
|
'value' => [ |
|
153
|
|
|
'size' => $this->linkData[$linkId]['requestArgs']['pageSize'], |
|
154
|
|
|
'cookie' => $this->linkData[$linkId]['serverControls'][LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '' |
|
155
|
|
|
] |
|
156
|
|
|
]]; |
|
157
|
|
|
|
|
158
|
|
|
$this->linkData[$linkId][$methodKey][] = -1; // timelimit |
|
159
|
|
|
$this->linkData[$linkId][$methodKey][] = LDAP_DEREF_NEVER; |
|
160
|
|
|
$this->linkData[$linkId][$methodKey][] = $serverControls; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.