@@ -40,874 +40,874 @@ |
||
40 | 40 | use OC\Cache\CappedMemoryCache; |
41 | 41 | |
42 | 42 | class Group_LDAP extends BackendUtility implements \OCP\GroupInterface { |
43 | - protected $enabled = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string[] $cachedGroupMembers array of users with gid as key |
|
47 | - */ |
|
48 | - protected $cachedGroupMembers; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string[] $cachedGroupsByMember array of groups with uid as key |
|
52 | - */ |
|
53 | - protected $cachedGroupsByMember; |
|
54 | - |
|
55 | - public function __construct(Access $access) { |
|
56 | - parent::__construct($access); |
|
57 | - $filter = $this->access->connection->ldapGroupFilter; |
|
58 | - $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
|
59 | - if(!empty($filter) && !empty($gassoc)) { |
|
60 | - $this->enabled = true; |
|
61 | - } |
|
62 | - |
|
63 | - $this->cachedGroupMembers = new CappedMemoryCache(); |
|
64 | - $this->cachedGroupsByMember = new CappedMemoryCache(); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * is user in group? |
|
69 | - * @param string $uid uid of the user |
|
70 | - * @param string $gid gid of the group |
|
71 | - * @return bool |
|
72 | - * |
|
73 | - * Checks whether the user is member of a group or not. |
|
74 | - */ |
|
75 | - public function inGroup($uid, $gid) { |
|
76 | - if(!$this->enabled) { |
|
77 | - return false; |
|
78 | - } |
|
79 | - $cacheKey = 'inGroup'.$uid.':'.$gid; |
|
80 | - $inGroup = $this->access->connection->getFromCache($cacheKey); |
|
81 | - if(!is_null($inGroup)) { |
|
82 | - return (bool)$inGroup; |
|
83 | - } |
|
84 | - |
|
85 | - $userDN = $this->access->username2dn($uid); |
|
86 | - |
|
87 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
88 | - $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
|
89 | - return $isInGroup; |
|
90 | - } |
|
91 | - |
|
92 | - $cacheKeyMembers = 'inGroup-members:'.$gid; |
|
93 | - $members = $this->access->connection->getFromCache($cacheKeyMembers); |
|
94 | - if(!is_null($members)) { |
|
95 | - $this->cachedGroupMembers[$gid] = $members; |
|
96 | - $isInGroup = in_array($userDN, $members); |
|
97 | - $this->access->connection->writeToCache($cacheKey, $isInGroup); |
|
98 | - return $isInGroup; |
|
99 | - } |
|
100 | - |
|
101 | - $groupDN = $this->access->groupname2dn($gid); |
|
102 | - // just in case |
|
103 | - if(!$groupDN || !$userDN) { |
|
104 | - $this->access->connection->writeToCache($cacheKey, false); |
|
105 | - return false; |
|
106 | - } |
|
107 | - |
|
108 | - //check primary group first |
|
109 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
110 | - $this->access->connection->writeToCache($cacheKey, true); |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
|
115 | - $members = $this->_groupMembers($groupDN); |
|
116 | - $members = array_keys($members); // uids are returned as keys |
|
117 | - if(!is_array($members) || count($members) === 0) { |
|
118 | - $this->access->connection->writeToCache($cacheKey, false); |
|
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - //extra work if we don't get back user DNs |
|
123 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
124 | - $dns = array(); |
|
125 | - $filterParts = array(); |
|
126 | - $bytes = 0; |
|
127 | - foreach($members as $mid) { |
|
128 | - $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
|
129 | - $filterParts[] = $filter; |
|
130 | - $bytes += strlen($filter); |
|
131 | - if($bytes >= 9000000) { |
|
132 | - // AD has a default input buffer of 10 MB, we do not want |
|
133 | - // to take even the chance to exceed it |
|
134 | - $filter = $this->access->combineFilterWithOr($filterParts); |
|
135 | - $bytes = 0; |
|
136 | - $filterParts = array(); |
|
137 | - $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
|
138 | - $dns = array_merge($dns, $users); |
|
139 | - } |
|
140 | - } |
|
141 | - if(count($filterParts) > 0) { |
|
142 | - $filter = $this->access->combineFilterWithOr($filterParts); |
|
143 | - $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
|
144 | - $dns = array_merge($dns, $users); |
|
145 | - } |
|
146 | - $members = $dns; |
|
147 | - } |
|
148 | - |
|
149 | - $isInGroup = in_array($userDN, $members); |
|
150 | - $this->access->connection->writeToCache($cacheKey, $isInGroup); |
|
151 | - $this->access->connection->writeToCache($cacheKeyMembers, $members); |
|
152 | - $this->cachedGroupMembers[$gid] = $members; |
|
153 | - |
|
154 | - return $isInGroup; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param string $dnGroup |
|
159 | - * @return array |
|
160 | - * |
|
161 | - * For a group that has user membership defined by an LDAP search url attribute returns the users |
|
162 | - * that match the search url otherwise returns an empty array. |
|
163 | - */ |
|
164 | - public function getDynamicGroupMembers($dnGroup) { |
|
165 | - $dynamicGroupMemberURL = strtolower($this->access->connection->ldapDynamicGroupMemberURL); |
|
166 | - |
|
167 | - if (empty($dynamicGroupMemberURL)) { |
|
168 | - return array(); |
|
169 | - } |
|
170 | - |
|
171 | - $dynamicMembers = array(); |
|
172 | - $memberURLs = $this->access->readAttribute( |
|
173 | - $dnGroup, |
|
174 | - $dynamicGroupMemberURL, |
|
175 | - $this->access->connection->ldapGroupFilter |
|
176 | - ); |
|
177 | - if ($memberURLs !== false) { |
|
178 | - // this group has the 'memberURL' attribute so this is a dynamic group |
|
179 | - // example 1: ldap:///cn=users,cn=accounts,dc=dcsubbase,dc=dcbase??one?(o=HeadOffice) |
|
180 | - // example 2: ldap:///cn=users,cn=accounts,dc=dcsubbase,dc=dcbase??one?(&(o=HeadOffice)(uidNumber>=500)) |
|
181 | - $pos = strpos($memberURLs[0], '('); |
|
182 | - if ($pos !== false) { |
|
183 | - $memberUrlFilter = substr($memberURLs[0], $pos); |
|
184 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
185 | - $dynamicMembers = array(); |
|
186 | - foreach($foundMembers as $value) { |
|
187 | - $dynamicMembers[$value['dn'][0]] = 1; |
|
188 | - } |
|
189 | - } else { |
|
190 | - \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
|
191 | - 'of group ' . $dnGroup, \OCP\Util::DEBUG); |
|
192 | - } |
|
193 | - } |
|
194 | - return $dynamicMembers; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param string $dnGroup |
|
199 | - * @param array|null &$seen |
|
200 | - * @return array|mixed|null |
|
201 | - */ |
|
202 | - private function _groupMembers($dnGroup, &$seen = null) { |
|
203 | - if ($seen === null) { |
|
204 | - $seen = array(); |
|
205 | - } |
|
206 | - $allMembers = array(); |
|
207 | - if (array_key_exists($dnGroup, $seen)) { |
|
208 | - // avoid loops |
|
209 | - return array(); |
|
210 | - } |
|
211 | - // used extensively in cron job, caching makes sense for nested groups |
|
212 | - $cacheKey = '_groupMembers'.$dnGroup; |
|
213 | - $groupMembers = $this->access->connection->getFromCache($cacheKey); |
|
214 | - if(!is_null($groupMembers)) { |
|
215 | - return $groupMembers; |
|
216 | - } |
|
217 | - $seen[$dnGroup] = 1; |
|
218 | - $members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr, |
|
219 | - $this->access->connection->ldapGroupFilter); |
|
220 | - if (is_array($members)) { |
|
221 | - foreach ($members as $memberDN) { |
|
222 | - $allMembers[$memberDN] = 1; |
|
223 | - $nestedGroups = $this->access->connection->ldapNestedGroups; |
|
224 | - if (!empty($nestedGroups)) { |
|
225 | - $subMembers = $this->_groupMembers($memberDN, $seen); |
|
226 | - if ($subMembers) { |
|
227 | - $allMembers = array_merge($allMembers, $subMembers); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
43 | + protected $enabled = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string[] $cachedGroupMembers array of users with gid as key |
|
47 | + */ |
|
48 | + protected $cachedGroupMembers; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string[] $cachedGroupsByMember array of groups with uid as key |
|
52 | + */ |
|
53 | + protected $cachedGroupsByMember; |
|
54 | + |
|
55 | + public function __construct(Access $access) { |
|
56 | + parent::__construct($access); |
|
57 | + $filter = $this->access->connection->ldapGroupFilter; |
|
58 | + $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
|
59 | + if(!empty($filter) && !empty($gassoc)) { |
|
60 | + $this->enabled = true; |
|
61 | + } |
|
62 | + |
|
63 | + $this->cachedGroupMembers = new CappedMemoryCache(); |
|
64 | + $this->cachedGroupsByMember = new CappedMemoryCache(); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * is user in group? |
|
69 | + * @param string $uid uid of the user |
|
70 | + * @param string $gid gid of the group |
|
71 | + * @return bool |
|
72 | + * |
|
73 | + * Checks whether the user is member of a group or not. |
|
74 | + */ |
|
75 | + public function inGroup($uid, $gid) { |
|
76 | + if(!$this->enabled) { |
|
77 | + return false; |
|
78 | + } |
|
79 | + $cacheKey = 'inGroup'.$uid.':'.$gid; |
|
80 | + $inGroup = $this->access->connection->getFromCache($cacheKey); |
|
81 | + if(!is_null($inGroup)) { |
|
82 | + return (bool)$inGroup; |
|
83 | + } |
|
84 | + |
|
85 | + $userDN = $this->access->username2dn($uid); |
|
86 | + |
|
87 | + if(isset($this->cachedGroupMembers[$gid])) { |
|
88 | + $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
|
89 | + return $isInGroup; |
|
90 | + } |
|
91 | + |
|
92 | + $cacheKeyMembers = 'inGroup-members:'.$gid; |
|
93 | + $members = $this->access->connection->getFromCache($cacheKeyMembers); |
|
94 | + if(!is_null($members)) { |
|
95 | + $this->cachedGroupMembers[$gid] = $members; |
|
96 | + $isInGroup = in_array($userDN, $members); |
|
97 | + $this->access->connection->writeToCache($cacheKey, $isInGroup); |
|
98 | + return $isInGroup; |
|
99 | + } |
|
100 | + |
|
101 | + $groupDN = $this->access->groupname2dn($gid); |
|
102 | + // just in case |
|
103 | + if(!$groupDN || !$userDN) { |
|
104 | + $this->access->connection->writeToCache($cacheKey, false); |
|
105 | + return false; |
|
106 | + } |
|
107 | + |
|
108 | + //check primary group first |
|
109 | + if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
110 | + $this->access->connection->writeToCache($cacheKey, true); |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
|
115 | + $members = $this->_groupMembers($groupDN); |
|
116 | + $members = array_keys($members); // uids are returned as keys |
|
117 | + if(!is_array($members) || count($members) === 0) { |
|
118 | + $this->access->connection->writeToCache($cacheKey, false); |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + //extra work if we don't get back user DNs |
|
123 | + if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
124 | + $dns = array(); |
|
125 | + $filterParts = array(); |
|
126 | + $bytes = 0; |
|
127 | + foreach($members as $mid) { |
|
128 | + $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
|
129 | + $filterParts[] = $filter; |
|
130 | + $bytes += strlen($filter); |
|
131 | + if($bytes >= 9000000) { |
|
132 | + // AD has a default input buffer of 10 MB, we do not want |
|
133 | + // to take even the chance to exceed it |
|
134 | + $filter = $this->access->combineFilterWithOr($filterParts); |
|
135 | + $bytes = 0; |
|
136 | + $filterParts = array(); |
|
137 | + $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
|
138 | + $dns = array_merge($dns, $users); |
|
139 | + } |
|
140 | + } |
|
141 | + if(count($filterParts) > 0) { |
|
142 | + $filter = $this->access->combineFilterWithOr($filterParts); |
|
143 | + $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
|
144 | + $dns = array_merge($dns, $users); |
|
145 | + } |
|
146 | + $members = $dns; |
|
147 | + } |
|
148 | + |
|
149 | + $isInGroup = in_array($userDN, $members); |
|
150 | + $this->access->connection->writeToCache($cacheKey, $isInGroup); |
|
151 | + $this->access->connection->writeToCache($cacheKeyMembers, $members); |
|
152 | + $this->cachedGroupMembers[$gid] = $members; |
|
153 | + |
|
154 | + return $isInGroup; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param string $dnGroup |
|
159 | + * @return array |
|
160 | + * |
|
161 | + * For a group that has user membership defined by an LDAP search url attribute returns the users |
|
162 | + * that match the search url otherwise returns an empty array. |
|
163 | + */ |
|
164 | + public function getDynamicGroupMembers($dnGroup) { |
|
165 | + $dynamicGroupMemberURL = strtolower($this->access->connection->ldapDynamicGroupMemberURL); |
|
166 | + |
|
167 | + if (empty($dynamicGroupMemberURL)) { |
|
168 | + return array(); |
|
169 | + } |
|
170 | + |
|
171 | + $dynamicMembers = array(); |
|
172 | + $memberURLs = $this->access->readAttribute( |
|
173 | + $dnGroup, |
|
174 | + $dynamicGroupMemberURL, |
|
175 | + $this->access->connection->ldapGroupFilter |
|
176 | + ); |
|
177 | + if ($memberURLs !== false) { |
|
178 | + // this group has the 'memberURL' attribute so this is a dynamic group |
|
179 | + // example 1: ldap:///cn=users,cn=accounts,dc=dcsubbase,dc=dcbase??one?(o=HeadOffice) |
|
180 | + // example 2: ldap:///cn=users,cn=accounts,dc=dcsubbase,dc=dcbase??one?(&(o=HeadOffice)(uidNumber>=500)) |
|
181 | + $pos = strpos($memberURLs[0], '('); |
|
182 | + if ($pos !== false) { |
|
183 | + $memberUrlFilter = substr($memberURLs[0], $pos); |
|
184 | + $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
185 | + $dynamicMembers = array(); |
|
186 | + foreach($foundMembers as $value) { |
|
187 | + $dynamicMembers[$value['dn'][0]] = 1; |
|
188 | + } |
|
189 | + } else { |
|
190 | + \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
|
191 | + 'of group ' . $dnGroup, \OCP\Util::DEBUG); |
|
192 | + } |
|
193 | + } |
|
194 | + return $dynamicMembers; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param string $dnGroup |
|
199 | + * @param array|null &$seen |
|
200 | + * @return array|mixed|null |
|
201 | + */ |
|
202 | + private function _groupMembers($dnGroup, &$seen = null) { |
|
203 | + if ($seen === null) { |
|
204 | + $seen = array(); |
|
205 | + } |
|
206 | + $allMembers = array(); |
|
207 | + if (array_key_exists($dnGroup, $seen)) { |
|
208 | + // avoid loops |
|
209 | + return array(); |
|
210 | + } |
|
211 | + // used extensively in cron job, caching makes sense for nested groups |
|
212 | + $cacheKey = '_groupMembers'.$dnGroup; |
|
213 | + $groupMembers = $this->access->connection->getFromCache($cacheKey); |
|
214 | + if(!is_null($groupMembers)) { |
|
215 | + return $groupMembers; |
|
216 | + } |
|
217 | + $seen[$dnGroup] = 1; |
|
218 | + $members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr, |
|
219 | + $this->access->connection->ldapGroupFilter); |
|
220 | + if (is_array($members)) { |
|
221 | + foreach ($members as $memberDN) { |
|
222 | + $allMembers[$memberDN] = 1; |
|
223 | + $nestedGroups = $this->access->connection->ldapNestedGroups; |
|
224 | + if (!empty($nestedGroups)) { |
|
225 | + $subMembers = $this->_groupMembers($memberDN, $seen); |
|
226 | + if ($subMembers) { |
|
227 | + $allMembers = array_merge($allMembers, $subMembers); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - $allMembers = array_merge($allMembers, $this->getDynamicGroupMembers($dnGroup)); |
|
233 | + $allMembers = array_merge($allMembers, $this->getDynamicGroupMembers($dnGroup)); |
|
234 | 234 | |
235 | - $this->access->connection->writeToCache($cacheKey, $allMembers); |
|
236 | - return $allMembers; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * @param string $DN |
|
241 | - * @param array|null &$seen |
|
242 | - * @return array |
|
243 | - */ |
|
244 | - private function _getGroupDNsFromMemberOf($DN, &$seen = null) { |
|
245 | - if ($seen === null) { |
|
246 | - $seen = array(); |
|
247 | - } |
|
248 | - if (array_key_exists($DN, $seen)) { |
|
249 | - // avoid loops |
|
250 | - return array(); |
|
251 | - } |
|
252 | - $seen[$DN] = 1; |
|
253 | - $groups = $this->access->readAttribute($DN, 'memberOf'); |
|
254 | - if (!is_array($groups)) { |
|
255 | - return array(); |
|
256 | - } |
|
257 | - $groups = $this->access->groupsMatchFilter($groups); |
|
258 | - $allGroups = $groups; |
|
259 | - $nestedGroups = $this->access->connection->ldapNestedGroups; |
|
260 | - if (intval($nestedGroups) === 1) { |
|
261 | - foreach ($groups as $group) { |
|
262 | - $subGroups = $this->_getGroupDNsFromMemberOf($group, $seen); |
|
263 | - $allGroups = array_merge($allGroups, $subGroups); |
|
264 | - } |
|
265 | - } |
|
266 | - return $allGroups; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * translates a primary group ID into an ownCloud internal name |
|
271 | - * @param string $gid as given by primaryGroupID on AD |
|
272 | - * @param string $dn a DN that belongs to the same domain as the group |
|
273 | - * @return string|bool |
|
274 | - */ |
|
275 | - public function primaryGroupID2Name($gid, $dn) { |
|
276 | - $cacheKey = 'primaryGroupIDtoName'; |
|
277 | - $groupNames = $this->access->connection->getFromCache($cacheKey); |
|
278 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
279 | - return $groupNames[$gid]; |
|
280 | - } |
|
281 | - |
|
282 | - $domainObjectSid = $this->access->getSID($dn); |
|
283 | - if($domainObjectSid === false) { |
|
284 | - return false; |
|
285 | - } |
|
286 | - |
|
287 | - //we need to get the DN from LDAP |
|
288 | - $filter = $this->access->combineFilterWithAnd(array( |
|
289 | - $this->access->connection->ldapGroupFilter, |
|
290 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
291 | - )); |
|
292 | - $result = $this->access->searchGroups($filter, array('dn'), 1); |
|
293 | - if(empty($result)) { |
|
294 | - return false; |
|
295 | - } |
|
296 | - $dn = $result[0]['dn'][0]; |
|
297 | - |
|
298 | - //and now the group name |
|
299 | - //NOTE once we have separate ownCloud group IDs and group names we can |
|
300 | - //directly read the display name attribute instead of the DN |
|
301 | - $name = $this->access->dn2groupname($dn); |
|
302 | - |
|
303 | - $this->access->connection->writeToCache($cacheKey, $name); |
|
304 | - |
|
305 | - return $name; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * returns the entry's primary group ID |
|
310 | - * @param string $dn |
|
311 | - * @param string $attribute |
|
312 | - * @return string|bool |
|
313 | - */ |
|
314 | - private function getEntryGroupID($dn, $attribute) { |
|
315 | - $value = $this->access->readAttribute($dn, $attribute); |
|
316 | - if(is_array($value) && !empty($value)) { |
|
317 | - return $value[0]; |
|
318 | - } |
|
319 | - return false; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * returns the group's primary ID |
|
324 | - * @param string $dn |
|
325 | - * @return string|bool |
|
326 | - */ |
|
327 | - public function getGroupPrimaryGroupID($dn) { |
|
328 | - return $this->getEntryGroupID($dn, 'primaryGroupToken'); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * returns the user's primary group ID |
|
333 | - * @param string $dn |
|
334 | - * @return string|bool |
|
335 | - */ |
|
336 | - public function getUserPrimaryGroupIDs($dn) { |
|
337 | - $primaryGroupID = false; |
|
338 | - if($this->access->connection->hasPrimaryGroups) { |
|
339 | - $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
|
340 | - if($primaryGroupID === false) { |
|
341 | - $this->access->connection->hasPrimaryGroups = false; |
|
342 | - } |
|
343 | - } |
|
344 | - return $primaryGroupID; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * returns a filter for a "users in primary group" search or count operation |
|
349 | - * |
|
350 | - * @param string $groupDN |
|
351 | - * @param string $search |
|
352 | - * @return string |
|
353 | - * @throws \Exception |
|
354 | - */ |
|
355 | - private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
|
356 | - $groupID = $this->getGroupPrimaryGroupID($groupDN); |
|
357 | - if($groupID === false) { |
|
358 | - throw new \Exception('Not a valid group'); |
|
359 | - } |
|
360 | - |
|
361 | - $filterParts = []; |
|
362 | - $filterParts[] = $this->access->getFilterForUserCount(); |
|
363 | - if ($search !== '') { |
|
364 | - $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
|
365 | - } |
|
366 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
367 | - |
|
368 | - $filter = $this->access->combineFilterWithAnd($filterParts); |
|
369 | - |
|
370 | - return $filter; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * returns a list of users that have the given group as primary group |
|
375 | - * |
|
376 | - * @param string $groupDN |
|
377 | - * @param string $search |
|
378 | - * @param int $limit |
|
379 | - * @param int $offset |
|
380 | - * @return string[] |
|
381 | - */ |
|
382 | - public function getUsersInPrimaryGroup($groupDN, $search = '', $limit = -1, $offset = 0) { |
|
383 | - try { |
|
384 | - $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
|
385 | - $users = $this->access->fetchListOfUsers( |
|
386 | - $filter, |
|
387 | - array($this->access->connection->ldapUserDisplayName, 'dn'), |
|
388 | - $limit, |
|
389 | - $offset |
|
390 | - ); |
|
391 | - return $this->access->ownCloudUserNames($users); |
|
392 | - } catch (\Exception $e) { |
|
393 | - return array(); |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * returns the number of users that have the given group as primary group |
|
399 | - * |
|
400 | - * @param string $groupDN |
|
401 | - * @param string $search |
|
402 | - * @param int $limit |
|
403 | - * @param int $offset |
|
404 | - * @return int |
|
405 | - */ |
|
406 | - public function countUsersInPrimaryGroup($groupDN, $search = '', $limit = -1, $offset = 0) { |
|
407 | - try { |
|
408 | - $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
|
409 | - $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
|
410 | - return (int)$users; |
|
411 | - } catch (\Exception $e) { |
|
412 | - return 0; |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * gets the primary group of a user |
|
418 | - * @param string $dn |
|
419 | - * @return string |
|
420 | - */ |
|
421 | - public function getUserPrimaryGroup($dn) { |
|
422 | - $groupID = $this->getUserPrimaryGroupIDs($dn); |
|
423 | - if($groupID !== false) { |
|
424 | - $groupName = $this->primaryGroupID2Name($groupID, $dn); |
|
425 | - if($groupName !== false) { |
|
426 | - return $groupName; |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - return false; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Get all groups a user belongs to |
|
435 | - * @param string $uid Name of the user |
|
436 | - * @return array with group names |
|
437 | - * |
|
438 | - * This function fetches all groups a user belongs to. It does not check |
|
439 | - * if the user exists at all. |
|
440 | - * |
|
441 | - * This function includes groups based on dynamic group membership. |
|
442 | - */ |
|
443 | - public function getUserGroups($uid) { |
|
444 | - if(!$this->enabled) { |
|
445 | - return array(); |
|
446 | - } |
|
447 | - $cacheKey = 'getUserGroups'.$uid; |
|
448 | - $userGroups = $this->access->connection->getFromCache($cacheKey); |
|
449 | - if(!is_null($userGroups)) { |
|
450 | - return $userGroups; |
|
451 | - } |
|
452 | - $userDN = $this->access->username2dn($uid); |
|
453 | - if(!$userDN) { |
|
454 | - $this->access->connection->writeToCache($cacheKey, array()); |
|
455 | - return array(); |
|
456 | - } |
|
457 | - |
|
458 | - $groups = []; |
|
459 | - $primaryGroup = $this->getUserPrimaryGroup($userDN); |
|
460 | - |
|
461 | - $dynamicGroupMemberURL = strtolower($this->access->connection->ldapDynamicGroupMemberURL); |
|
462 | - |
|
463 | - if (!empty($dynamicGroupMemberURL)) { |
|
464 | - // look through dynamic groups to add them to the result array if needed |
|
465 | - $groupsToMatch = $this->access->fetchListOfGroups( |
|
466 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
467 | - foreach($groupsToMatch as $dynamicGroup) { |
|
468 | - if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
|
469 | - continue; |
|
470 | - } |
|
471 | - $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
|
472 | - if ($pos !== false) { |
|
473 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
474 | - // apply filter via ldap search to see if this user is in this |
|
475 | - // dynamic group |
|
476 | - $userMatch = $this->access->readAttribute( |
|
477 | - $userDN, |
|
478 | - $this->access->connection->ldapUserDisplayName, |
|
479 | - $memberUrlFilter |
|
480 | - ); |
|
481 | - if ($userMatch !== false) { |
|
482 | - // match found so this user is in this group |
|
483 | - $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
|
484 | - if(is_string($groupName)) { |
|
485 | - // be sure to never return false if the dn could not be |
|
486 | - // resolved to a name, for whatever reason. |
|
487 | - $groups[] = $groupName; |
|
488 | - } |
|
489 | - } |
|
490 | - } else { |
|
491 | - \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
|
492 | - 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
493 | - } |
|
494 | - } |
|
495 | - } |
|
496 | - |
|
497 | - // if possible, read out membership via memberOf. It's far faster than |
|
498 | - // performing a search, which still is a fallback later. |
|
499 | - if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
500 | - && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
|
501 | - ) { |
|
502 | - $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
|
503 | - if (is_array($groupDNs)) { |
|
504 | - foreach ($groupDNs as $dn) { |
|
505 | - $groupName = $this->access->dn2groupname($dn); |
|
506 | - if(is_string($groupName)) { |
|
507 | - // be sure to never return false if the dn could not be |
|
508 | - // resolved to a name, for whatever reason. |
|
509 | - $groups[] = $groupName; |
|
510 | - } |
|
511 | - } |
|
512 | - } |
|
235 | + $this->access->connection->writeToCache($cacheKey, $allMembers); |
|
236 | + return $allMembers; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * @param string $DN |
|
241 | + * @param array|null &$seen |
|
242 | + * @return array |
|
243 | + */ |
|
244 | + private function _getGroupDNsFromMemberOf($DN, &$seen = null) { |
|
245 | + if ($seen === null) { |
|
246 | + $seen = array(); |
|
247 | + } |
|
248 | + if (array_key_exists($DN, $seen)) { |
|
249 | + // avoid loops |
|
250 | + return array(); |
|
251 | + } |
|
252 | + $seen[$DN] = 1; |
|
253 | + $groups = $this->access->readAttribute($DN, 'memberOf'); |
|
254 | + if (!is_array($groups)) { |
|
255 | + return array(); |
|
256 | + } |
|
257 | + $groups = $this->access->groupsMatchFilter($groups); |
|
258 | + $allGroups = $groups; |
|
259 | + $nestedGroups = $this->access->connection->ldapNestedGroups; |
|
260 | + if (intval($nestedGroups) === 1) { |
|
261 | + foreach ($groups as $group) { |
|
262 | + $subGroups = $this->_getGroupDNsFromMemberOf($group, $seen); |
|
263 | + $allGroups = array_merge($allGroups, $subGroups); |
|
264 | + } |
|
265 | + } |
|
266 | + return $allGroups; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * translates a primary group ID into an ownCloud internal name |
|
271 | + * @param string $gid as given by primaryGroupID on AD |
|
272 | + * @param string $dn a DN that belongs to the same domain as the group |
|
273 | + * @return string|bool |
|
274 | + */ |
|
275 | + public function primaryGroupID2Name($gid, $dn) { |
|
276 | + $cacheKey = 'primaryGroupIDtoName'; |
|
277 | + $groupNames = $this->access->connection->getFromCache($cacheKey); |
|
278 | + if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
279 | + return $groupNames[$gid]; |
|
280 | + } |
|
281 | + |
|
282 | + $domainObjectSid = $this->access->getSID($dn); |
|
283 | + if($domainObjectSid === false) { |
|
284 | + return false; |
|
285 | + } |
|
286 | + |
|
287 | + //we need to get the DN from LDAP |
|
288 | + $filter = $this->access->combineFilterWithAnd(array( |
|
289 | + $this->access->connection->ldapGroupFilter, |
|
290 | + 'objectsid=' . $domainObjectSid . '-' . $gid |
|
291 | + )); |
|
292 | + $result = $this->access->searchGroups($filter, array('dn'), 1); |
|
293 | + if(empty($result)) { |
|
294 | + return false; |
|
295 | + } |
|
296 | + $dn = $result[0]['dn'][0]; |
|
297 | + |
|
298 | + //and now the group name |
|
299 | + //NOTE once we have separate ownCloud group IDs and group names we can |
|
300 | + //directly read the display name attribute instead of the DN |
|
301 | + $name = $this->access->dn2groupname($dn); |
|
302 | + |
|
303 | + $this->access->connection->writeToCache($cacheKey, $name); |
|
304 | + |
|
305 | + return $name; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * returns the entry's primary group ID |
|
310 | + * @param string $dn |
|
311 | + * @param string $attribute |
|
312 | + * @return string|bool |
|
313 | + */ |
|
314 | + private function getEntryGroupID($dn, $attribute) { |
|
315 | + $value = $this->access->readAttribute($dn, $attribute); |
|
316 | + if(is_array($value) && !empty($value)) { |
|
317 | + return $value[0]; |
|
318 | + } |
|
319 | + return false; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * returns the group's primary ID |
|
324 | + * @param string $dn |
|
325 | + * @return string|bool |
|
326 | + */ |
|
327 | + public function getGroupPrimaryGroupID($dn) { |
|
328 | + return $this->getEntryGroupID($dn, 'primaryGroupToken'); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * returns the user's primary group ID |
|
333 | + * @param string $dn |
|
334 | + * @return string|bool |
|
335 | + */ |
|
336 | + public function getUserPrimaryGroupIDs($dn) { |
|
337 | + $primaryGroupID = false; |
|
338 | + if($this->access->connection->hasPrimaryGroups) { |
|
339 | + $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
|
340 | + if($primaryGroupID === false) { |
|
341 | + $this->access->connection->hasPrimaryGroups = false; |
|
342 | + } |
|
343 | + } |
|
344 | + return $primaryGroupID; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * returns a filter for a "users in primary group" search or count operation |
|
349 | + * |
|
350 | + * @param string $groupDN |
|
351 | + * @param string $search |
|
352 | + * @return string |
|
353 | + * @throws \Exception |
|
354 | + */ |
|
355 | + private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
|
356 | + $groupID = $this->getGroupPrimaryGroupID($groupDN); |
|
357 | + if($groupID === false) { |
|
358 | + throw new \Exception('Not a valid group'); |
|
359 | + } |
|
360 | + |
|
361 | + $filterParts = []; |
|
362 | + $filterParts[] = $this->access->getFilterForUserCount(); |
|
363 | + if ($search !== '') { |
|
364 | + $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
|
365 | + } |
|
366 | + $filterParts[] = 'primaryGroupID=' . $groupID; |
|
367 | + |
|
368 | + $filter = $this->access->combineFilterWithAnd($filterParts); |
|
369 | + |
|
370 | + return $filter; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * returns a list of users that have the given group as primary group |
|
375 | + * |
|
376 | + * @param string $groupDN |
|
377 | + * @param string $search |
|
378 | + * @param int $limit |
|
379 | + * @param int $offset |
|
380 | + * @return string[] |
|
381 | + */ |
|
382 | + public function getUsersInPrimaryGroup($groupDN, $search = '', $limit = -1, $offset = 0) { |
|
383 | + try { |
|
384 | + $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
|
385 | + $users = $this->access->fetchListOfUsers( |
|
386 | + $filter, |
|
387 | + array($this->access->connection->ldapUserDisplayName, 'dn'), |
|
388 | + $limit, |
|
389 | + $offset |
|
390 | + ); |
|
391 | + return $this->access->ownCloudUserNames($users); |
|
392 | + } catch (\Exception $e) { |
|
393 | + return array(); |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * returns the number of users that have the given group as primary group |
|
399 | + * |
|
400 | + * @param string $groupDN |
|
401 | + * @param string $search |
|
402 | + * @param int $limit |
|
403 | + * @param int $offset |
|
404 | + * @return int |
|
405 | + */ |
|
406 | + public function countUsersInPrimaryGroup($groupDN, $search = '', $limit = -1, $offset = 0) { |
|
407 | + try { |
|
408 | + $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
|
409 | + $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
|
410 | + return (int)$users; |
|
411 | + } catch (\Exception $e) { |
|
412 | + return 0; |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * gets the primary group of a user |
|
418 | + * @param string $dn |
|
419 | + * @return string |
|
420 | + */ |
|
421 | + public function getUserPrimaryGroup($dn) { |
|
422 | + $groupID = $this->getUserPrimaryGroupIDs($dn); |
|
423 | + if($groupID !== false) { |
|
424 | + $groupName = $this->primaryGroupID2Name($groupID, $dn); |
|
425 | + if($groupName !== false) { |
|
426 | + return $groupName; |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + return false; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Get all groups a user belongs to |
|
435 | + * @param string $uid Name of the user |
|
436 | + * @return array with group names |
|
437 | + * |
|
438 | + * This function fetches all groups a user belongs to. It does not check |
|
439 | + * if the user exists at all. |
|
440 | + * |
|
441 | + * This function includes groups based on dynamic group membership. |
|
442 | + */ |
|
443 | + public function getUserGroups($uid) { |
|
444 | + if(!$this->enabled) { |
|
445 | + return array(); |
|
446 | + } |
|
447 | + $cacheKey = 'getUserGroups'.$uid; |
|
448 | + $userGroups = $this->access->connection->getFromCache($cacheKey); |
|
449 | + if(!is_null($userGroups)) { |
|
450 | + return $userGroups; |
|
451 | + } |
|
452 | + $userDN = $this->access->username2dn($uid); |
|
453 | + if(!$userDN) { |
|
454 | + $this->access->connection->writeToCache($cacheKey, array()); |
|
455 | + return array(); |
|
456 | + } |
|
457 | + |
|
458 | + $groups = []; |
|
459 | + $primaryGroup = $this->getUserPrimaryGroup($userDN); |
|
460 | + |
|
461 | + $dynamicGroupMemberURL = strtolower($this->access->connection->ldapDynamicGroupMemberURL); |
|
462 | + |
|
463 | + if (!empty($dynamicGroupMemberURL)) { |
|
464 | + // look through dynamic groups to add them to the result array if needed |
|
465 | + $groupsToMatch = $this->access->fetchListOfGroups( |
|
466 | + $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
467 | + foreach($groupsToMatch as $dynamicGroup) { |
|
468 | + if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
|
469 | + continue; |
|
470 | + } |
|
471 | + $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
|
472 | + if ($pos !== false) { |
|
473 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
474 | + // apply filter via ldap search to see if this user is in this |
|
475 | + // dynamic group |
|
476 | + $userMatch = $this->access->readAttribute( |
|
477 | + $userDN, |
|
478 | + $this->access->connection->ldapUserDisplayName, |
|
479 | + $memberUrlFilter |
|
480 | + ); |
|
481 | + if ($userMatch !== false) { |
|
482 | + // match found so this user is in this group |
|
483 | + $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
|
484 | + if(is_string($groupName)) { |
|
485 | + // be sure to never return false if the dn could not be |
|
486 | + // resolved to a name, for whatever reason. |
|
487 | + $groups[] = $groupName; |
|
488 | + } |
|
489 | + } |
|
490 | + } else { |
|
491 | + \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
|
492 | + 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
493 | + } |
|
494 | + } |
|
495 | + } |
|
496 | + |
|
497 | + // if possible, read out membership via memberOf. It's far faster than |
|
498 | + // performing a search, which still is a fallback later. |
|
499 | + if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
500 | + && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
|
501 | + ) { |
|
502 | + $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
|
503 | + if (is_array($groupDNs)) { |
|
504 | + foreach ($groupDNs as $dn) { |
|
505 | + $groupName = $this->access->dn2groupname($dn); |
|
506 | + if(is_string($groupName)) { |
|
507 | + // be sure to never return false if the dn could not be |
|
508 | + // resolved to a name, for whatever reason. |
|
509 | + $groups[] = $groupName; |
|
510 | + } |
|
511 | + } |
|
512 | + } |
|
513 | 513 | |
514 | - if($primaryGroup !== false) { |
|
515 | - $groups[] = $primaryGroup; |
|
516 | - } |
|
517 | - $this->access->connection->writeToCache($cacheKey, $groups); |
|
518 | - return $groups; |
|
519 | - } |
|
520 | - |
|
521 | - //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
|
522 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
523 | - || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
|
524 | - ) { |
|
525 | - $uid = $userDN; |
|
526 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
527 | - $result = $this->access->readAttribute($userDN, 'uid'); |
|
528 | - if ($result === false) { |
|
529 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
530 | - $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
|
531 | - } |
|
532 | - $uid = $result[0]; |
|
533 | - } else { |
|
534 | - // just in case |
|
535 | - $uid = $userDN; |
|
536 | - } |
|
537 | - |
|
538 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
539 | - $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
|
540 | - } else { |
|
541 | - $groupsByMember = array_values($this->getGroupsByMember($uid)); |
|
542 | - $groupsByMember = $this->access->ownCloudGroupNames($groupsByMember); |
|
543 | - $this->cachedGroupsByMember[$uid] = $groupsByMember; |
|
544 | - $groups = array_merge($groups, $groupsByMember); |
|
545 | - } |
|
546 | - |
|
547 | - if($primaryGroup !== false) { |
|
548 | - $groups[] = $primaryGroup; |
|
549 | - } |
|
550 | - |
|
551 | - $groups = array_unique($groups, SORT_LOCALE_STRING); |
|
552 | - $this->access->connection->writeToCache($cacheKey, $groups); |
|
553 | - |
|
554 | - return $groups; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * @param string $dn |
|
559 | - * @param array|null &$seen |
|
560 | - * @return array |
|
561 | - */ |
|
562 | - private function getGroupsByMember($dn, &$seen = null) { |
|
563 | - if ($seen === null) { |
|
564 | - $seen = array(); |
|
565 | - } |
|
566 | - $allGroups = array(); |
|
567 | - if (array_key_exists($dn, $seen)) { |
|
568 | - // avoid loops |
|
569 | - return array(); |
|
570 | - } |
|
571 | - $seen[$dn] = true; |
|
572 | - $filter = $this->access->combineFilterWithAnd(array( |
|
573 | - $this->access->connection->ldapGroupFilter, |
|
574 | - $this->access->connection->ldapGroupMemberAssocAttr.'='.$dn |
|
575 | - )); |
|
576 | - $groups = $this->access->fetchListOfGroups($filter, |
|
577 | - array($this->access->connection->ldapGroupDisplayName, 'dn')); |
|
578 | - if (is_array($groups)) { |
|
579 | - foreach ($groups as $groupobj) { |
|
580 | - $groupDN = $groupobj['dn'][0]; |
|
581 | - $allGroups[$groupDN] = $groupobj; |
|
582 | - $nestedGroups = $this->access->connection->ldapNestedGroups; |
|
583 | - if (!empty($nestedGroups)) { |
|
584 | - $supergroups = $this->getGroupsByMember($groupDN, $seen); |
|
585 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
586 | - $allGroups = array_merge($allGroups, $supergroups); |
|
587 | - } |
|
588 | - } |
|
589 | - } |
|
590 | - } |
|
591 | - return $allGroups; |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * get a list of all users in a group |
|
596 | - * |
|
597 | - * @param string $gid |
|
598 | - * @param string $search |
|
599 | - * @param int $limit |
|
600 | - * @param int $offset |
|
601 | - * @return array with user ids |
|
602 | - */ |
|
603 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
604 | - if(!$this->enabled) { |
|
605 | - return array(); |
|
606 | - } |
|
607 | - if(!$this->groupExists($gid)) { |
|
608 | - return array(); |
|
609 | - } |
|
610 | - $search = $this->access->escapeFilterPart($search, true); |
|
611 | - $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
|
612 | - // check for cache of the exact query |
|
613 | - $groupUsers = $this->access->connection->getFromCache($cacheKey); |
|
614 | - if(!is_null($groupUsers)) { |
|
615 | - return $groupUsers; |
|
616 | - } |
|
617 | - |
|
618 | - // check for cache of the query without limit and offset |
|
619 | - $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
|
620 | - if(!is_null($groupUsers)) { |
|
621 | - $groupUsers = array_slice($groupUsers, $offset, $limit); |
|
622 | - $this->access->connection->writeToCache($cacheKey, $groupUsers); |
|
623 | - return $groupUsers; |
|
624 | - } |
|
625 | - |
|
626 | - if($limit === -1) { |
|
627 | - $limit = null; |
|
628 | - } |
|
629 | - $groupDN = $this->access->groupname2dn($gid); |
|
630 | - if(!$groupDN) { |
|
631 | - // group couldn't be found, return empty resultset |
|
632 | - $this->access->connection->writeToCache($cacheKey, array()); |
|
633 | - return array(); |
|
634 | - } |
|
635 | - |
|
636 | - $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
|
637 | - $members = array_keys($this->_groupMembers($groupDN)); |
|
638 | - if(!$members && empty($primaryUsers)) { |
|
639 | - //in case users could not be retrieved, return empty result set |
|
640 | - $this->access->connection->writeToCache($cacheKey, array()); |
|
641 | - return array(); |
|
642 | - } |
|
643 | - |
|
644 | - $groupUsers = array(); |
|
645 | - $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
|
646 | - $attrs = $this->access->userManager->getAttributes(true); |
|
647 | - foreach($members as $member) { |
|
648 | - if($isMemberUid) { |
|
649 | - //we got uids, need to get their DNs to 'translate' them to user names |
|
650 | - $filter = $this->access->combineFilterWithAnd(array( |
|
651 | - str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
|
652 | - $this->access->getFilterPartForUserSearch($search) |
|
653 | - )); |
|
654 | - $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
|
655 | - if(count($ldap_users) < 1) { |
|
656 | - continue; |
|
657 | - } |
|
658 | - $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
|
659 | - } else { |
|
660 | - //we got DNs, check if we need to filter by search or we can give back all of them |
|
661 | - if ($search !== '') { |
|
662 | - if(!$this->access->readAttribute($member, |
|
663 | - $this->access->connection->ldapUserDisplayName, |
|
664 | - $this->access->getFilterPartForUserSearch($search))) { |
|
665 | - continue; |
|
666 | - } |
|
667 | - } |
|
668 | - // dn2username will also check if the users belong to the allowed base |
|
669 | - if($ocname = $this->access->dn2username($member)) { |
|
670 | - $groupUsers[] = $ocname; |
|
671 | - } |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - $groupUsers = array_unique(array_merge($groupUsers, $primaryUsers)); |
|
676 | - natsort($groupUsers); |
|
677 | - $this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers); |
|
678 | - $groupUsers = array_slice($groupUsers, $offset, $limit); |
|
679 | - |
|
680 | - |
|
681 | - $this->access->connection->writeToCache($cacheKey, $groupUsers); |
|
682 | - |
|
683 | - return $groupUsers; |
|
684 | - } |
|
685 | - |
|
686 | - /** |
|
687 | - * returns the number of users in a group, who match the search term |
|
688 | - * @param string $gid the internal group name |
|
689 | - * @param string $search optional, a search string |
|
690 | - * @return int|bool |
|
691 | - */ |
|
692 | - public function countUsersInGroup($gid, $search = '') { |
|
693 | - $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
|
694 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
695 | - return false; |
|
696 | - } |
|
697 | - $groupUsers = $this->access->connection->getFromCache($cacheKey); |
|
698 | - if(!is_null($groupUsers)) { |
|
699 | - return $groupUsers; |
|
700 | - } |
|
701 | - |
|
702 | - $groupDN = $this->access->groupname2dn($gid); |
|
703 | - if(!$groupDN) { |
|
704 | - // group couldn't be found, return empty result set |
|
705 | - $this->access->connection->writeToCache($cacheKey, false); |
|
706 | - return false; |
|
707 | - } |
|
708 | - |
|
709 | - $members = array_keys($this->_groupMembers($groupDN)); |
|
710 | - $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
|
711 | - if(!$members && $primaryUserCount === 0) { |
|
712 | - //in case users could not be retrieved, return empty result set |
|
713 | - $this->access->connection->writeToCache($cacheKey, false); |
|
714 | - return false; |
|
715 | - } |
|
716 | - |
|
717 | - if ($search === '') { |
|
718 | - $groupUsers = count($members) + $primaryUserCount; |
|
719 | - $this->access->connection->writeToCache($cacheKey, $groupUsers); |
|
720 | - return $groupUsers; |
|
721 | - } |
|
722 | - $search = $this->access->escapeFilterPart($search, true); |
|
723 | - $isMemberUid = |
|
724 | - (strtolower($this->access->connection->ldapGroupMemberAssocAttr) |
|
725 | - === 'memberuid'); |
|
726 | - |
|
727 | - //we need to apply the search filter |
|
728 | - //alternatives that need to be checked: |
|
729 | - //a) get all users by search filter and array_intersect them |
|
730 | - //b) a, but only when less than 1k 10k ?k users like it is |
|
731 | - //c) put all DNs|uids in a LDAP filter, combine with the search string |
|
732 | - // and let it count. |
|
733 | - //For now this is not important, because the only use of this method |
|
734 | - //does not supply a search string |
|
735 | - $groupUsers = array(); |
|
736 | - foreach($members as $member) { |
|
737 | - if($isMemberUid) { |
|
738 | - //we got uids, need to get their DNs to 'translate' them to user names |
|
739 | - $filter = $this->access->combineFilterWithAnd(array( |
|
740 | - str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
|
741 | - $this->access->getFilterPartForUserSearch($search) |
|
742 | - )); |
|
743 | - $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
|
744 | - if(count($ldap_users) < 1) { |
|
745 | - continue; |
|
746 | - } |
|
747 | - $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
|
748 | - } else { |
|
749 | - //we need to apply the search filter now |
|
750 | - if(!$this->access->readAttribute($member, |
|
751 | - $this->access->connection->ldapUserDisplayName, |
|
752 | - $this->access->getFilterPartForUserSearch($search))) { |
|
753 | - continue; |
|
754 | - } |
|
755 | - // dn2username will also check if the users belong to the allowed base |
|
756 | - if($ocname = $this->access->dn2username($member)) { |
|
757 | - $groupUsers[] = $ocname; |
|
758 | - } |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - //and get users that have the group as primary |
|
763 | - $primaryUsers = $this->countUsersInPrimaryGroup($groupDN, $search); |
|
764 | - |
|
765 | - return count($groupUsers) + $primaryUsers; |
|
766 | - } |
|
767 | - |
|
768 | - /** |
|
769 | - * get a list of all groups |
|
770 | - * |
|
771 | - * @param string $search |
|
772 | - * @param $limit |
|
773 | - * @param int $offset |
|
774 | - * @return array with group names |
|
775 | - * |
|
776 | - * Returns a list with all groups (used by getGroups) |
|
777 | - */ |
|
778 | - protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
|
779 | - if(!$this->enabled) { |
|
780 | - return array(); |
|
781 | - } |
|
782 | - $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
|
783 | - |
|
784 | - //Check cache before driving unnecessary searches |
|
785 | - \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
|
786 | - $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
|
787 | - if(!is_null($ldap_groups)) { |
|
788 | - return $ldap_groups; |
|
789 | - } |
|
790 | - |
|
791 | - // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
|
792 | - // error. With a limit of 0, we get 0 results. So we pass null. |
|
793 | - if($limit <= 0) { |
|
794 | - $limit = null; |
|
795 | - } |
|
796 | - $filter = $this->access->combineFilterWithAnd(array( |
|
797 | - $this->access->connection->ldapGroupFilter, |
|
798 | - $this->access->getFilterPartForGroupSearch($search) |
|
799 | - )); |
|
800 | - \OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, \OCP\Util::DEBUG); |
|
801 | - $ldap_groups = $this->access->fetchListOfGroups($filter, |
|
802 | - array($this->access->connection->ldapGroupDisplayName, 'dn'), |
|
803 | - $limit, |
|
804 | - $offset); |
|
805 | - $ldap_groups = $this->access->ownCloudGroupNames($ldap_groups); |
|
806 | - |
|
807 | - $this->access->connection->writeToCache($cacheKey, $ldap_groups); |
|
808 | - return $ldap_groups; |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * get a list of all groups using a paged search |
|
813 | - * |
|
814 | - * @param string $search |
|
815 | - * @param int $limit |
|
816 | - * @param int $offset |
|
817 | - * @return array with group names |
|
818 | - * |
|
819 | - * Returns a list with all groups |
|
820 | - * Uses a paged search if available to override a |
|
821 | - * server side search limit. |
|
822 | - * (active directory has a limit of 1000 by default) |
|
823 | - */ |
|
824 | - public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
825 | - if(!$this->enabled) { |
|
826 | - return array(); |
|
827 | - } |
|
828 | - $search = $this->access->escapeFilterPart($search, true); |
|
829 | - $pagingSize = intval($this->access->connection->ldapPagingSize); |
|
830 | - if (!$this->access->connection->hasPagedResultSupport || $pagingSize <= 0) { |
|
831 | - return $this->getGroupsChunk($search, $limit, $offset); |
|
832 | - } |
|
833 | - $maxGroups = 100000; // limit max results (just for safety reasons) |
|
834 | - if ($limit > -1) { |
|
835 | - $overallLimit = min($limit + $offset, $maxGroups); |
|
836 | - } else { |
|
837 | - $overallLimit = $maxGroups; |
|
838 | - } |
|
839 | - $chunkOffset = $offset; |
|
840 | - $allGroups = array(); |
|
841 | - while ($chunkOffset < $overallLimit) { |
|
842 | - $chunkLimit = min($pagingSize, $overallLimit - $chunkOffset); |
|
843 | - $ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset); |
|
844 | - $nread = count($ldapGroups); |
|
845 | - \OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', \OCP\Util::DEBUG); |
|
846 | - if ($nread) { |
|
847 | - $allGroups = array_merge($allGroups, $ldapGroups); |
|
848 | - $chunkOffset += $nread; |
|
849 | - } |
|
850 | - if ($nread < $chunkLimit) { |
|
851 | - break; |
|
852 | - } |
|
853 | - } |
|
854 | - return $allGroups; |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * @param string $group |
|
859 | - * @return bool |
|
860 | - */ |
|
861 | - public function groupMatchesFilter($group) { |
|
862 | - return (strripos($group, $this->groupSearch) !== false); |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * check if a group exists |
|
867 | - * @param string $gid |
|
868 | - * @return bool |
|
869 | - */ |
|
870 | - public function groupExists($gid) { |
|
871 | - $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
|
872 | - if(!is_null($groupExists)) { |
|
873 | - return (bool)$groupExists; |
|
874 | - } |
|
875 | - |
|
876 | - //getting dn, if false the group does not exist. If dn, it may be mapped |
|
877 | - //only, requires more checking. |
|
878 | - $dn = $this->access->groupname2dn($gid); |
|
879 | - if(!$dn) { |
|
880 | - $this->access->connection->writeToCache('groupExists'.$gid, false); |
|
881 | - return false; |
|
882 | - } |
|
883 | - |
|
884 | - //if group really still exists, we will be able to read its objectclass |
|
885 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
886 | - $this->access->connection->writeToCache('groupExists'.$gid, false); |
|
887 | - return false; |
|
888 | - } |
|
889 | - |
|
890 | - $this->access->connection->writeToCache('groupExists'.$gid, true); |
|
891 | - return true; |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Check if backend implements actions |
|
896 | - * @param int $actions bitwise-or'ed actions |
|
897 | - * @return boolean |
|
898 | - * |
|
899 | - * Returns the supported actions as int to be |
|
900 | - * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
901 | - */ |
|
902 | - public function implementsActions($actions) { |
|
903 | - return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Return access for LDAP interaction. |
|
908 | - * @return Access instance of Access for LDAP interaction |
|
909 | - */ |
|
910 | - public function getLDAPAccess() { |
|
911 | - return $this->access; |
|
912 | - } |
|
514 | + if($primaryGroup !== false) { |
|
515 | + $groups[] = $primaryGroup; |
|
516 | + } |
|
517 | + $this->access->connection->writeToCache($cacheKey, $groups); |
|
518 | + return $groups; |
|
519 | + } |
|
520 | + |
|
521 | + //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
|
522 | + if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
523 | + || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
|
524 | + ) { |
|
525 | + $uid = $userDN; |
|
526 | + } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
527 | + $result = $this->access->readAttribute($userDN, 'uid'); |
|
528 | + if ($result === false) { |
|
529 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
530 | + $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
|
531 | + } |
|
532 | + $uid = $result[0]; |
|
533 | + } else { |
|
534 | + // just in case |
|
535 | + $uid = $userDN; |
|
536 | + } |
|
537 | + |
|
538 | + if(isset($this->cachedGroupsByMember[$uid])) { |
|
539 | + $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
|
540 | + } else { |
|
541 | + $groupsByMember = array_values($this->getGroupsByMember($uid)); |
|
542 | + $groupsByMember = $this->access->ownCloudGroupNames($groupsByMember); |
|
543 | + $this->cachedGroupsByMember[$uid] = $groupsByMember; |
|
544 | + $groups = array_merge($groups, $groupsByMember); |
|
545 | + } |
|
546 | + |
|
547 | + if($primaryGroup !== false) { |
|
548 | + $groups[] = $primaryGroup; |
|
549 | + } |
|
550 | + |
|
551 | + $groups = array_unique($groups, SORT_LOCALE_STRING); |
|
552 | + $this->access->connection->writeToCache($cacheKey, $groups); |
|
553 | + |
|
554 | + return $groups; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * @param string $dn |
|
559 | + * @param array|null &$seen |
|
560 | + * @return array |
|
561 | + */ |
|
562 | + private function getGroupsByMember($dn, &$seen = null) { |
|
563 | + if ($seen === null) { |
|
564 | + $seen = array(); |
|
565 | + } |
|
566 | + $allGroups = array(); |
|
567 | + if (array_key_exists($dn, $seen)) { |
|
568 | + // avoid loops |
|
569 | + return array(); |
|
570 | + } |
|
571 | + $seen[$dn] = true; |
|
572 | + $filter = $this->access->combineFilterWithAnd(array( |
|
573 | + $this->access->connection->ldapGroupFilter, |
|
574 | + $this->access->connection->ldapGroupMemberAssocAttr.'='.$dn |
|
575 | + )); |
|
576 | + $groups = $this->access->fetchListOfGroups($filter, |
|
577 | + array($this->access->connection->ldapGroupDisplayName, 'dn')); |
|
578 | + if (is_array($groups)) { |
|
579 | + foreach ($groups as $groupobj) { |
|
580 | + $groupDN = $groupobj['dn'][0]; |
|
581 | + $allGroups[$groupDN] = $groupobj; |
|
582 | + $nestedGroups = $this->access->connection->ldapNestedGroups; |
|
583 | + if (!empty($nestedGroups)) { |
|
584 | + $supergroups = $this->getGroupsByMember($groupDN, $seen); |
|
585 | + if (is_array($supergroups) && (count($supergroups)>0)) { |
|
586 | + $allGroups = array_merge($allGroups, $supergroups); |
|
587 | + } |
|
588 | + } |
|
589 | + } |
|
590 | + } |
|
591 | + return $allGroups; |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * get a list of all users in a group |
|
596 | + * |
|
597 | + * @param string $gid |
|
598 | + * @param string $search |
|
599 | + * @param int $limit |
|
600 | + * @param int $offset |
|
601 | + * @return array with user ids |
|
602 | + */ |
|
603 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
604 | + if(!$this->enabled) { |
|
605 | + return array(); |
|
606 | + } |
|
607 | + if(!$this->groupExists($gid)) { |
|
608 | + return array(); |
|
609 | + } |
|
610 | + $search = $this->access->escapeFilterPart($search, true); |
|
611 | + $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
|
612 | + // check for cache of the exact query |
|
613 | + $groupUsers = $this->access->connection->getFromCache($cacheKey); |
|
614 | + if(!is_null($groupUsers)) { |
|
615 | + return $groupUsers; |
|
616 | + } |
|
617 | + |
|
618 | + // check for cache of the query without limit and offset |
|
619 | + $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
|
620 | + if(!is_null($groupUsers)) { |
|
621 | + $groupUsers = array_slice($groupUsers, $offset, $limit); |
|
622 | + $this->access->connection->writeToCache($cacheKey, $groupUsers); |
|
623 | + return $groupUsers; |
|
624 | + } |
|
625 | + |
|
626 | + if($limit === -1) { |
|
627 | + $limit = null; |
|
628 | + } |
|
629 | + $groupDN = $this->access->groupname2dn($gid); |
|
630 | + if(!$groupDN) { |
|
631 | + // group couldn't be found, return empty resultset |
|
632 | + $this->access->connection->writeToCache($cacheKey, array()); |
|
633 | + return array(); |
|
634 | + } |
|
635 | + |
|
636 | + $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
|
637 | + $members = array_keys($this->_groupMembers($groupDN)); |
|
638 | + if(!$members && empty($primaryUsers)) { |
|
639 | + //in case users could not be retrieved, return empty result set |
|
640 | + $this->access->connection->writeToCache($cacheKey, array()); |
|
641 | + return array(); |
|
642 | + } |
|
643 | + |
|
644 | + $groupUsers = array(); |
|
645 | + $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
|
646 | + $attrs = $this->access->userManager->getAttributes(true); |
|
647 | + foreach($members as $member) { |
|
648 | + if($isMemberUid) { |
|
649 | + //we got uids, need to get their DNs to 'translate' them to user names |
|
650 | + $filter = $this->access->combineFilterWithAnd(array( |
|
651 | + str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
|
652 | + $this->access->getFilterPartForUserSearch($search) |
|
653 | + )); |
|
654 | + $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
|
655 | + if(count($ldap_users) < 1) { |
|
656 | + continue; |
|
657 | + } |
|
658 | + $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
|
659 | + } else { |
|
660 | + //we got DNs, check if we need to filter by search or we can give back all of them |
|
661 | + if ($search !== '') { |
|
662 | + if(!$this->access->readAttribute($member, |
|
663 | + $this->access->connection->ldapUserDisplayName, |
|
664 | + $this->access->getFilterPartForUserSearch($search))) { |
|
665 | + continue; |
|
666 | + } |
|
667 | + } |
|
668 | + // dn2username will also check if the users belong to the allowed base |
|
669 | + if($ocname = $this->access->dn2username($member)) { |
|
670 | + $groupUsers[] = $ocname; |
|
671 | + } |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + $groupUsers = array_unique(array_merge($groupUsers, $primaryUsers)); |
|
676 | + natsort($groupUsers); |
|
677 | + $this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers); |
|
678 | + $groupUsers = array_slice($groupUsers, $offset, $limit); |
|
679 | + |
|
680 | + |
|
681 | + $this->access->connection->writeToCache($cacheKey, $groupUsers); |
|
682 | + |
|
683 | + return $groupUsers; |
|
684 | + } |
|
685 | + |
|
686 | + /** |
|
687 | + * returns the number of users in a group, who match the search term |
|
688 | + * @param string $gid the internal group name |
|
689 | + * @param string $search optional, a search string |
|
690 | + * @return int|bool |
|
691 | + */ |
|
692 | + public function countUsersInGroup($gid, $search = '') { |
|
693 | + $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
|
694 | + if(!$this->enabled || !$this->groupExists($gid)) { |
|
695 | + return false; |
|
696 | + } |
|
697 | + $groupUsers = $this->access->connection->getFromCache($cacheKey); |
|
698 | + if(!is_null($groupUsers)) { |
|
699 | + return $groupUsers; |
|
700 | + } |
|
701 | + |
|
702 | + $groupDN = $this->access->groupname2dn($gid); |
|
703 | + if(!$groupDN) { |
|
704 | + // group couldn't be found, return empty result set |
|
705 | + $this->access->connection->writeToCache($cacheKey, false); |
|
706 | + return false; |
|
707 | + } |
|
708 | + |
|
709 | + $members = array_keys($this->_groupMembers($groupDN)); |
|
710 | + $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
|
711 | + if(!$members && $primaryUserCount === 0) { |
|
712 | + //in case users could not be retrieved, return empty result set |
|
713 | + $this->access->connection->writeToCache($cacheKey, false); |
|
714 | + return false; |
|
715 | + } |
|
716 | + |
|
717 | + if ($search === '') { |
|
718 | + $groupUsers = count($members) + $primaryUserCount; |
|
719 | + $this->access->connection->writeToCache($cacheKey, $groupUsers); |
|
720 | + return $groupUsers; |
|
721 | + } |
|
722 | + $search = $this->access->escapeFilterPart($search, true); |
|
723 | + $isMemberUid = |
|
724 | + (strtolower($this->access->connection->ldapGroupMemberAssocAttr) |
|
725 | + === 'memberuid'); |
|
726 | + |
|
727 | + //we need to apply the search filter |
|
728 | + //alternatives that need to be checked: |
|
729 | + //a) get all users by search filter and array_intersect them |
|
730 | + //b) a, but only when less than 1k 10k ?k users like it is |
|
731 | + //c) put all DNs|uids in a LDAP filter, combine with the search string |
|
732 | + // and let it count. |
|
733 | + //For now this is not important, because the only use of this method |
|
734 | + //does not supply a search string |
|
735 | + $groupUsers = array(); |
|
736 | + foreach($members as $member) { |
|
737 | + if($isMemberUid) { |
|
738 | + //we got uids, need to get their DNs to 'translate' them to user names |
|
739 | + $filter = $this->access->combineFilterWithAnd(array( |
|
740 | + str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
|
741 | + $this->access->getFilterPartForUserSearch($search) |
|
742 | + )); |
|
743 | + $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
|
744 | + if(count($ldap_users) < 1) { |
|
745 | + continue; |
|
746 | + } |
|
747 | + $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
|
748 | + } else { |
|
749 | + //we need to apply the search filter now |
|
750 | + if(!$this->access->readAttribute($member, |
|
751 | + $this->access->connection->ldapUserDisplayName, |
|
752 | + $this->access->getFilterPartForUserSearch($search))) { |
|
753 | + continue; |
|
754 | + } |
|
755 | + // dn2username will also check if the users belong to the allowed base |
|
756 | + if($ocname = $this->access->dn2username($member)) { |
|
757 | + $groupUsers[] = $ocname; |
|
758 | + } |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + //and get users that have the group as primary |
|
763 | + $primaryUsers = $this->countUsersInPrimaryGroup($groupDN, $search); |
|
764 | + |
|
765 | + return count($groupUsers) + $primaryUsers; |
|
766 | + } |
|
767 | + |
|
768 | + /** |
|
769 | + * get a list of all groups |
|
770 | + * |
|
771 | + * @param string $search |
|
772 | + * @param $limit |
|
773 | + * @param int $offset |
|
774 | + * @return array with group names |
|
775 | + * |
|
776 | + * Returns a list with all groups (used by getGroups) |
|
777 | + */ |
|
778 | + protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
|
779 | + if(!$this->enabled) { |
|
780 | + return array(); |
|
781 | + } |
|
782 | + $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
|
783 | + |
|
784 | + //Check cache before driving unnecessary searches |
|
785 | + \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
|
786 | + $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
|
787 | + if(!is_null($ldap_groups)) { |
|
788 | + return $ldap_groups; |
|
789 | + } |
|
790 | + |
|
791 | + // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
|
792 | + // error. With a limit of 0, we get 0 results. So we pass null. |
|
793 | + if($limit <= 0) { |
|
794 | + $limit = null; |
|
795 | + } |
|
796 | + $filter = $this->access->combineFilterWithAnd(array( |
|
797 | + $this->access->connection->ldapGroupFilter, |
|
798 | + $this->access->getFilterPartForGroupSearch($search) |
|
799 | + )); |
|
800 | + \OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, \OCP\Util::DEBUG); |
|
801 | + $ldap_groups = $this->access->fetchListOfGroups($filter, |
|
802 | + array($this->access->connection->ldapGroupDisplayName, 'dn'), |
|
803 | + $limit, |
|
804 | + $offset); |
|
805 | + $ldap_groups = $this->access->ownCloudGroupNames($ldap_groups); |
|
806 | + |
|
807 | + $this->access->connection->writeToCache($cacheKey, $ldap_groups); |
|
808 | + return $ldap_groups; |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * get a list of all groups using a paged search |
|
813 | + * |
|
814 | + * @param string $search |
|
815 | + * @param int $limit |
|
816 | + * @param int $offset |
|
817 | + * @return array with group names |
|
818 | + * |
|
819 | + * Returns a list with all groups |
|
820 | + * Uses a paged search if available to override a |
|
821 | + * server side search limit. |
|
822 | + * (active directory has a limit of 1000 by default) |
|
823 | + */ |
|
824 | + public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
825 | + if(!$this->enabled) { |
|
826 | + return array(); |
|
827 | + } |
|
828 | + $search = $this->access->escapeFilterPart($search, true); |
|
829 | + $pagingSize = intval($this->access->connection->ldapPagingSize); |
|
830 | + if (!$this->access->connection->hasPagedResultSupport || $pagingSize <= 0) { |
|
831 | + return $this->getGroupsChunk($search, $limit, $offset); |
|
832 | + } |
|
833 | + $maxGroups = 100000; // limit max results (just for safety reasons) |
|
834 | + if ($limit > -1) { |
|
835 | + $overallLimit = min($limit + $offset, $maxGroups); |
|
836 | + } else { |
|
837 | + $overallLimit = $maxGroups; |
|
838 | + } |
|
839 | + $chunkOffset = $offset; |
|
840 | + $allGroups = array(); |
|
841 | + while ($chunkOffset < $overallLimit) { |
|
842 | + $chunkLimit = min($pagingSize, $overallLimit - $chunkOffset); |
|
843 | + $ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset); |
|
844 | + $nread = count($ldapGroups); |
|
845 | + \OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', \OCP\Util::DEBUG); |
|
846 | + if ($nread) { |
|
847 | + $allGroups = array_merge($allGroups, $ldapGroups); |
|
848 | + $chunkOffset += $nread; |
|
849 | + } |
|
850 | + if ($nread < $chunkLimit) { |
|
851 | + break; |
|
852 | + } |
|
853 | + } |
|
854 | + return $allGroups; |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * @param string $group |
|
859 | + * @return bool |
|
860 | + */ |
|
861 | + public function groupMatchesFilter($group) { |
|
862 | + return (strripos($group, $this->groupSearch) !== false); |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * check if a group exists |
|
867 | + * @param string $gid |
|
868 | + * @return bool |
|
869 | + */ |
|
870 | + public function groupExists($gid) { |
|
871 | + $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
|
872 | + if(!is_null($groupExists)) { |
|
873 | + return (bool)$groupExists; |
|
874 | + } |
|
875 | + |
|
876 | + //getting dn, if false the group does not exist. If dn, it may be mapped |
|
877 | + //only, requires more checking. |
|
878 | + $dn = $this->access->groupname2dn($gid); |
|
879 | + if(!$dn) { |
|
880 | + $this->access->connection->writeToCache('groupExists'.$gid, false); |
|
881 | + return false; |
|
882 | + } |
|
883 | + |
|
884 | + //if group really still exists, we will be able to read its objectclass |
|
885 | + if(!is_array($this->access->readAttribute($dn, ''))) { |
|
886 | + $this->access->connection->writeToCache('groupExists'.$gid, false); |
|
887 | + return false; |
|
888 | + } |
|
889 | + |
|
890 | + $this->access->connection->writeToCache('groupExists'.$gid, true); |
|
891 | + return true; |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Check if backend implements actions |
|
896 | + * @param int $actions bitwise-or'ed actions |
|
897 | + * @return boolean |
|
898 | + * |
|
899 | + * Returns the supported actions as int to be |
|
900 | + * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
901 | + */ |
|
902 | + public function implementsActions($actions) { |
|
903 | + return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Return access for LDAP interaction. |
|
908 | + * @return Access instance of Access for LDAP interaction |
|
909 | + */ |
|
910 | + public function getLDAPAccess() { |
|
911 | + return $this->access; |
|
912 | + } |
|
913 | 913 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | parent::__construct($access); |
57 | 57 | $filter = $this->access->connection->ldapGroupFilter; |
58 | 58 | $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
59 | - if(!empty($filter) && !empty($gassoc)) { |
|
59 | + if (!empty($filter) && !empty($gassoc)) { |
|
60 | 60 | $this->enabled = true; |
61 | 61 | } |
62 | 62 | |
@@ -73,25 +73,25 @@ discard block |
||
73 | 73 | * Checks whether the user is member of a group or not. |
74 | 74 | */ |
75 | 75 | public function inGroup($uid, $gid) { |
76 | - if(!$this->enabled) { |
|
76 | + if (!$this->enabled) { |
|
77 | 77 | return false; |
78 | 78 | } |
79 | 79 | $cacheKey = 'inGroup'.$uid.':'.$gid; |
80 | 80 | $inGroup = $this->access->connection->getFromCache($cacheKey); |
81 | - if(!is_null($inGroup)) { |
|
82 | - return (bool)$inGroup; |
|
81 | + if (!is_null($inGroup)) { |
|
82 | + return (bool) $inGroup; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | $userDN = $this->access->username2dn($uid); |
86 | 86 | |
87 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
87 | + if (isset($this->cachedGroupMembers[$gid])) { |
|
88 | 88 | $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
89 | 89 | return $isInGroup; |
90 | 90 | } |
91 | 91 | |
92 | 92 | $cacheKeyMembers = 'inGroup-members:'.$gid; |
93 | 93 | $members = $this->access->connection->getFromCache($cacheKeyMembers); |
94 | - if(!is_null($members)) { |
|
94 | + if (!is_null($members)) { |
|
95 | 95 | $this->cachedGroupMembers[$gid] = $members; |
96 | 96 | $isInGroup = in_array($userDN, $members); |
97 | 97 | $this->access->connection->writeToCache($cacheKey, $isInGroup); |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | |
101 | 101 | $groupDN = $this->access->groupname2dn($gid); |
102 | 102 | // just in case |
103 | - if(!$groupDN || !$userDN) { |
|
103 | + if (!$groupDN || !$userDN) { |
|
104 | 104 | $this->access->connection->writeToCache($cacheKey, false); |
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | 108 | //check primary group first |
109 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
109 | + if ($gid === $this->getUserPrimaryGroup($userDN)) { |
|
110 | 110 | $this->access->connection->writeToCache($cacheKey, true); |
111 | 111 | return true; |
112 | 112 | } |
@@ -114,21 +114,21 @@ discard block |
||
114 | 114 | //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
115 | 115 | $members = $this->_groupMembers($groupDN); |
116 | 116 | $members = array_keys($members); // uids are returned as keys |
117 | - if(!is_array($members) || count($members) === 0) { |
|
117 | + if (!is_array($members) || count($members) === 0) { |
|
118 | 118 | $this->access->connection->writeToCache($cacheKey, false); |
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
122 | 122 | //extra work if we don't get back user DNs |
123 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
123 | + if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
124 | 124 | $dns = array(); |
125 | 125 | $filterParts = array(); |
126 | 126 | $bytes = 0; |
127 | - foreach($members as $mid) { |
|
127 | + foreach ($members as $mid) { |
|
128 | 128 | $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
129 | 129 | $filterParts[] = $filter; |
130 | 130 | $bytes += strlen($filter); |
131 | - if($bytes >= 9000000) { |
|
131 | + if ($bytes >= 9000000) { |
|
132 | 132 | // AD has a default input buffer of 10 MB, we do not want |
133 | 133 | // to take even the chance to exceed it |
134 | 134 | $filter = $this->access->combineFilterWithOr($filterParts); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $dns = array_merge($dns, $users); |
139 | 139 | } |
140 | 140 | } |
141 | - if(count($filterParts) > 0) { |
|
141 | + if (count($filterParts) > 0) { |
|
142 | 142 | $filter = $this->access->combineFilterWithOr($filterParts); |
143 | 143 | $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
144 | 144 | $dns = array_merge($dns, $users); |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | $pos = strpos($memberURLs[0], '('); |
182 | 182 | if ($pos !== false) { |
183 | 183 | $memberUrlFilter = substr($memberURLs[0], $pos); |
184 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
184 | + $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn'); |
|
185 | 185 | $dynamicMembers = array(); |
186 | - foreach($foundMembers as $value) { |
|
186 | + foreach ($foundMembers as $value) { |
|
187 | 187 | $dynamicMembers[$value['dn'][0]] = 1; |
188 | 188 | } |
189 | 189 | } else { |
190 | 190 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
191 | - 'of group ' . $dnGroup, \OCP\Util::DEBUG); |
|
191 | + 'of group '.$dnGroup, \OCP\Util::DEBUG); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | return $dynamicMembers; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | // used extensively in cron job, caching makes sense for nested groups |
212 | 212 | $cacheKey = '_groupMembers'.$dnGroup; |
213 | 213 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
214 | - if(!is_null($groupMembers)) { |
|
214 | + if (!is_null($groupMembers)) { |
|
215 | 215 | return $groupMembers; |
216 | 216 | } |
217 | 217 | $seen[$dnGroup] = 1; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | return array(); |
256 | 256 | } |
257 | 257 | $groups = $this->access->groupsMatchFilter($groups); |
258 | - $allGroups = $groups; |
|
258 | + $allGroups = $groups; |
|
259 | 259 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
260 | 260 | if (intval($nestedGroups) === 1) { |
261 | 261 | foreach ($groups as $group) { |
@@ -275,22 +275,22 @@ discard block |
||
275 | 275 | public function primaryGroupID2Name($gid, $dn) { |
276 | 276 | $cacheKey = 'primaryGroupIDtoName'; |
277 | 277 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
278 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
278 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
279 | 279 | return $groupNames[$gid]; |
280 | 280 | } |
281 | 281 | |
282 | 282 | $domainObjectSid = $this->access->getSID($dn); |
283 | - if($domainObjectSid === false) { |
|
283 | + if ($domainObjectSid === false) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | |
287 | 287 | //we need to get the DN from LDAP |
288 | 288 | $filter = $this->access->combineFilterWithAnd(array( |
289 | 289 | $this->access->connection->ldapGroupFilter, |
290 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
290 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
291 | 291 | )); |
292 | 292 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
293 | - if(empty($result)) { |
|
293 | + if (empty($result)) { |
|
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | $dn = $result[0]['dn'][0]; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | private function getEntryGroupID($dn, $attribute) { |
315 | 315 | $value = $this->access->readAttribute($dn, $attribute); |
316 | - if(is_array($value) && !empty($value)) { |
|
316 | + if (is_array($value) && !empty($value)) { |
|
317 | 317 | return $value[0]; |
318 | 318 | } |
319 | 319 | return false; |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function getUserPrimaryGroupIDs($dn) { |
337 | 337 | $primaryGroupID = false; |
338 | - if($this->access->connection->hasPrimaryGroups) { |
|
338 | + if ($this->access->connection->hasPrimaryGroups) { |
|
339 | 339 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
340 | - if($primaryGroupID === false) { |
|
340 | + if ($primaryGroupID === false) { |
|
341 | 341 | $this->access->connection->hasPrimaryGroups = false; |
342 | 342 | } |
343 | 343 | } |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
356 | 356 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
357 | - if($groupID === false) { |
|
357 | + if ($groupID === false) { |
|
358 | 358 | throw new \Exception('Not a valid group'); |
359 | 359 | } |
360 | 360 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | if ($search !== '') { |
364 | 364 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
365 | 365 | } |
366 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
366 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
367 | 367 | |
368 | 368 | $filter = $this->access->combineFilterWithAnd($filterParts); |
369 | 369 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | try { |
408 | 408 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
409 | 409 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
410 | - return (int)$users; |
|
410 | + return (int) $users; |
|
411 | 411 | } catch (\Exception $e) { |
412 | 412 | return 0; |
413 | 413 | } |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public function getUserPrimaryGroup($dn) { |
422 | 422 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
423 | - if($groupID !== false) { |
|
423 | + if ($groupID !== false) { |
|
424 | 424 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
425 | - if($groupName !== false) { |
|
425 | + if ($groupName !== false) { |
|
426 | 426 | return $groupName; |
427 | 427 | } |
428 | 428 | } |
@@ -441,16 +441,16 @@ discard block |
||
441 | 441 | * This function includes groups based on dynamic group membership. |
442 | 442 | */ |
443 | 443 | public function getUserGroups($uid) { |
444 | - if(!$this->enabled) { |
|
444 | + if (!$this->enabled) { |
|
445 | 445 | return array(); |
446 | 446 | } |
447 | 447 | $cacheKey = 'getUserGroups'.$uid; |
448 | 448 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
449 | - if(!is_null($userGroups)) { |
|
449 | + if (!is_null($userGroups)) { |
|
450 | 450 | return $userGroups; |
451 | 451 | } |
452 | 452 | $userDN = $this->access->username2dn($uid); |
453 | - if(!$userDN) { |
|
453 | + if (!$userDN) { |
|
454 | 454 | $this->access->connection->writeToCache($cacheKey, array()); |
455 | 455 | return array(); |
456 | 456 | } |
@@ -463,14 +463,14 @@ discard block |
||
463 | 463 | if (!empty($dynamicGroupMemberURL)) { |
464 | 464 | // look through dynamic groups to add them to the result array if needed |
465 | 465 | $groupsToMatch = $this->access->fetchListOfGroups( |
466 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
467 | - foreach($groupsToMatch as $dynamicGroup) { |
|
466 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
467 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
468 | 468 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
469 | 469 | continue; |
470 | 470 | } |
471 | 471 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
472 | 472 | if ($pos !== false) { |
473 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
473 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
474 | 474 | // apply filter via ldap search to see if this user is in this |
475 | 475 | // dynamic group |
476 | 476 | $userMatch = $this->access->readAttribute( |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | if ($userMatch !== false) { |
482 | 482 | // match found so this user is in this group |
483 | 483 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
484 | - if(is_string($groupName)) { |
|
484 | + if (is_string($groupName)) { |
|
485 | 485 | // be sure to never return false if the dn could not be |
486 | 486 | // resolved to a name, for whatever reason. |
487 | 487 | $groups[] = $groupName; |
@@ -489,21 +489,21 @@ discard block |
||
489 | 489 | } |
490 | 490 | } else { |
491 | 491 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
492 | - 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
492 | + 'of group '.print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | // if possible, read out membership via memberOf. It's far faster than |
498 | 498 | // performing a search, which still is a fallback later. |
499 | - if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
499 | + if (intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
500 | 500 | && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
501 | 501 | ) { |
502 | 502 | $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
503 | 503 | if (is_array($groupDNs)) { |
504 | 504 | foreach ($groupDNs as $dn) { |
505 | 505 | $groupName = $this->access->dn2groupname($dn); |
506 | - if(is_string($groupName)) { |
|
506 | + if (is_string($groupName)) { |
|
507 | 507 | // be sure to never return false if the dn could not be |
508 | 508 | // resolved to a name, for whatever reason. |
509 | 509 | $groups[] = $groupName; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | - if($primaryGroup !== false) { |
|
514 | + if ($primaryGroup !== false) { |
|
515 | 515 | $groups[] = $primaryGroup; |
516 | 516 | } |
517 | 517 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -519,14 +519,14 @@ discard block |
||
519 | 519 | } |
520 | 520 | |
521 | 521 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
522 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
522 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
523 | 523 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
524 | 524 | ) { |
525 | 525 | $uid = $userDN; |
526 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
526 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
527 | 527 | $result = $this->access->readAttribute($userDN, 'uid'); |
528 | 528 | if ($result === false) { |
529 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
529 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
530 | 530 | $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
531 | 531 | } |
532 | 532 | $uid = $result[0]; |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | $uid = $userDN; |
536 | 536 | } |
537 | 537 | |
538 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
538 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
539 | 539 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
540 | 540 | } else { |
541 | 541 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | $groups = array_merge($groups, $groupsByMember); |
545 | 545 | } |
546 | 546 | |
547 | - if($primaryGroup !== false) { |
|
547 | + if ($primaryGroup !== false) { |
|
548 | 548 | $groups[] = $primaryGroup; |
549 | 549 | } |
550 | 550 | |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
583 | 583 | if (!empty($nestedGroups)) { |
584 | 584 | $supergroups = $this->getGroupsByMember($groupDN, $seen); |
585 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
585 | + if (is_array($supergroups) && (count($supergroups) > 0)) { |
|
586 | 586 | $allGroups = array_merge($allGroups, $supergroups); |
587 | 587 | } |
588 | 588 | } |
@@ -601,33 +601,33 @@ discard block |
||
601 | 601 | * @return array with user ids |
602 | 602 | */ |
603 | 603 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
604 | - if(!$this->enabled) { |
|
604 | + if (!$this->enabled) { |
|
605 | 605 | return array(); |
606 | 606 | } |
607 | - if(!$this->groupExists($gid)) { |
|
607 | + if (!$this->groupExists($gid)) { |
|
608 | 608 | return array(); |
609 | 609 | } |
610 | 610 | $search = $this->access->escapeFilterPart($search, true); |
611 | 611 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
612 | 612 | // check for cache of the exact query |
613 | 613 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
614 | - if(!is_null($groupUsers)) { |
|
614 | + if (!is_null($groupUsers)) { |
|
615 | 615 | return $groupUsers; |
616 | 616 | } |
617 | 617 | |
618 | 618 | // check for cache of the query without limit and offset |
619 | 619 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
620 | - if(!is_null($groupUsers)) { |
|
620 | + if (!is_null($groupUsers)) { |
|
621 | 621 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
622 | 622 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
623 | 623 | return $groupUsers; |
624 | 624 | } |
625 | 625 | |
626 | - if($limit === -1) { |
|
626 | + if ($limit === -1) { |
|
627 | 627 | $limit = null; |
628 | 628 | } |
629 | 629 | $groupDN = $this->access->groupname2dn($gid); |
630 | - if(!$groupDN) { |
|
630 | + if (!$groupDN) { |
|
631 | 631 | // group couldn't be found, return empty resultset |
632 | 632 | $this->access->connection->writeToCache($cacheKey, array()); |
633 | 633 | return array(); |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | |
636 | 636 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
637 | 637 | $members = array_keys($this->_groupMembers($groupDN)); |
638 | - if(!$members && empty($primaryUsers)) { |
|
638 | + if (!$members && empty($primaryUsers)) { |
|
639 | 639 | //in case users could not be retrieved, return empty result set |
640 | 640 | $this->access->connection->writeToCache($cacheKey, array()); |
641 | 641 | return array(); |
@@ -644,29 +644,29 @@ discard block |
||
644 | 644 | $groupUsers = array(); |
645 | 645 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
646 | 646 | $attrs = $this->access->userManager->getAttributes(true); |
647 | - foreach($members as $member) { |
|
648 | - if($isMemberUid) { |
|
647 | + foreach ($members as $member) { |
|
648 | + if ($isMemberUid) { |
|
649 | 649 | //we got uids, need to get their DNs to 'translate' them to user names |
650 | 650 | $filter = $this->access->combineFilterWithAnd(array( |
651 | 651 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
652 | 652 | $this->access->getFilterPartForUserSearch($search) |
653 | 653 | )); |
654 | 654 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
655 | - if(count($ldap_users) < 1) { |
|
655 | + if (count($ldap_users) < 1) { |
|
656 | 656 | continue; |
657 | 657 | } |
658 | 658 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
659 | 659 | } else { |
660 | 660 | //we got DNs, check if we need to filter by search or we can give back all of them |
661 | 661 | if ($search !== '') { |
662 | - if(!$this->access->readAttribute($member, |
|
662 | + if (!$this->access->readAttribute($member, |
|
663 | 663 | $this->access->connection->ldapUserDisplayName, |
664 | 664 | $this->access->getFilterPartForUserSearch($search))) { |
665 | 665 | continue; |
666 | 666 | } |
667 | 667 | } |
668 | 668 | // dn2username will also check if the users belong to the allowed base |
669 | - if($ocname = $this->access->dn2username($member)) { |
|
669 | + if ($ocname = $this->access->dn2username($member)) { |
|
670 | 670 | $groupUsers[] = $ocname; |
671 | 671 | } |
672 | 672 | } |
@@ -691,16 +691,16 @@ discard block |
||
691 | 691 | */ |
692 | 692 | public function countUsersInGroup($gid, $search = '') { |
693 | 693 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
694 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
694 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
695 | 695 | return false; |
696 | 696 | } |
697 | 697 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
698 | - if(!is_null($groupUsers)) { |
|
698 | + if (!is_null($groupUsers)) { |
|
699 | 699 | return $groupUsers; |
700 | 700 | } |
701 | 701 | |
702 | 702 | $groupDN = $this->access->groupname2dn($gid); |
703 | - if(!$groupDN) { |
|
703 | + if (!$groupDN) { |
|
704 | 704 | // group couldn't be found, return empty result set |
705 | 705 | $this->access->connection->writeToCache($cacheKey, false); |
706 | 706 | return false; |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | |
709 | 709 | $members = array_keys($this->_groupMembers($groupDN)); |
710 | 710 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
711 | - if(!$members && $primaryUserCount === 0) { |
|
711 | + if (!$members && $primaryUserCount === 0) { |
|
712 | 712 | //in case users could not be retrieved, return empty result set |
713 | 713 | $this->access->connection->writeToCache($cacheKey, false); |
714 | 714 | return false; |
@@ -733,27 +733,27 @@ discard block |
||
733 | 733 | //For now this is not important, because the only use of this method |
734 | 734 | //does not supply a search string |
735 | 735 | $groupUsers = array(); |
736 | - foreach($members as $member) { |
|
737 | - if($isMemberUid) { |
|
736 | + foreach ($members as $member) { |
|
737 | + if ($isMemberUid) { |
|
738 | 738 | //we got uids, need to get their DNs to 'translate' them to user names |
739 | 739 | $filter = $this->access->combineFilterWithAnd(array( |
740 | 740 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
741 | 741 | $this->access->getFilterPartForUserSearch($search) |
742 | 742 | )); |
743 | 743 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
744 | - if(count($ldap_users) < 1) { |
|
744 | + if (count($ldap_users) < 1) { |
|
745 | 745 | continue; |
746 | 746 | } |
747 | 747 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
748 | 748 | } else { |
749 | 749 | //we need to apply the search filter now |
750 | - if(!$this->access->readAttribute($member, |
|
750 | + if (!$this->access->readAttribute($member, |
|
751 | 751 | $this->access->connection->ldapUserDisplayName, |
752 | 752 | $this->access->getFilterPartForUserSearch($search))) { |
753 | 753 | continue; |
754 | 754 | } |
755 | 755 | // dn2username will also check if the users belong to the allowed base |
756 | - if($ocname = $this->access->dn2username($member)) { |
|
756 | + if ($ocname = $this->access->dn2username($member)) { |
|
757 | 757 | $groupUsers[] = $ocname; |
758 | 758 | } |
759 | 759 | } |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | * Returns a list with all groups (used by getGroups) |
777 | 777 | */ |
778 | 778 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
779 | - if(!$this->enabled) { |
|
779 | + if (!$this->enabled) { |
|
780 | 780 | return array(); |
781 | 781 | } |
782 | 782 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -784,13 +784,13 @@ discard block |
||
784 | 784 | //Check cache before driving unnecessary searches |
785 | 785 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
786 | 786 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
787 | - if(!is_null($ldap_groups)) { |
|
787 | + if (!is_null($ldap_groups)) { |
|
788 | 788 | return $ldap_groups; |
789 | 789 | } |
790 | 790 | |
791 | 791 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
792 | 792 | // error. With a limit of 0, we get 0 results. So we pass null. |
793 | - if($limit <= 0) { |
|
793 | + if ($limit <= 0) { |
|
794 | 794 | $limit = null; |
795 | 795 | } |
796 | 796 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | * (active directory has a limit of 1000 by default) |
823 | 823 | */ |
824 | 824 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
825 | - if(!$this->enabled) { |
|
825 | + if (!$this->enabled) { |
|
826 | 826 | return array(); |
827 | 827 | } |
828 | 828 | $search = $this->access->escapeFilterPart($search, true); |
@@ -869,20 +869,20 @@ discard block |
||
869 | 869 | */ |
870 | 870 | public function groupExists($gid) { |
871 | 871 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
872 | - if(!is_null($groupExists)) { |
|
873 | - return (bool)$groupExists; |
|
872 | + if (!is_null($groupExists)) { |
|
873 | + return (bool) $groupExists; |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | //getting dn, if false the group does not exist. If dn, it may be mapped |
877 | 877 | //only, requires more checking. |
878 | 878 | $dn = $this->access->groupname2dn($gid); |
879 | - if(!$dn) { |
|
879 | + if (!$dn) { |
|
880 | 880 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
881 | 881 | return false; |
882 | 882 | } |
883 | 883 | |
884 | 884 | //if group really still exists, we will be able to read its objectclass |
885 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
885 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
886 | 886 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
887 | 887 | return false; |
888 | 888 | } |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
901 | 901 | */ |
902 | 902 | public function implementsActions($actions) { |
903 | - return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); |
|
903 | + return (bool) (\OC\Group\Backend::COUNT_USERS & $actions); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -36,101 +36,101 @@ |
||
36 | 36 | use OCA\User_LDAP\User_Proxy; |
37 | 37 | |
38 | 38 | class CheckUser extends Command { |
39 | - /** @var \OCA\User_LDAP\User_Proxy */ |
|
40 | - protected $backend; |
|
41 | - |
|
42 | - /** @var \OCA\User_LDAP\Helper */ |
|
43 | - protected $helper; |
|
44 | - |
|
45 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
46 | - protected $dui; |
|
47 | - |
|
48 | - /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
49 | - protected $mapping; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param User_Proxy $uBackend |
|
53 | - * @param LDAPHelper $helper |
|
54 | - * @param DeletedUsersIndex $dui |
|
55 | - * @param UserMapping $mapping |
|
56 | - */ |
|
57 | - public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
58 | - $this->backend = $uBackend; |
|
59 | - $this->helper = $helper; |
|
60 | - $this->dui = $dui; |
|
61 | - $this->mapping = $mapping; |
|
62 | - parent::__construct(); |
|
63 | - } |
|
64 | - |
|
65 | - protected function configure() { |
|
66 | - $this |
|
67 | - ->setName('ldap:check-user') |
|
68 | - ->setDescription('checks whether a user exists on LDAP.') |
|
69 | - ->addArgument( |
|
70 | - 'ocName', |
|
71 | - InputArgument::REQUIRED, |
|
72 | - 'the user name as used in ownCloud' |
|
73 | - ) |
|
74 | - ->addOption( |
|
75 | - 'force', |
|
76 | - null, |
|
77 | - InputOption::VALUE_NONE, |
|
78 | - 'ignores disabled LDAP configuration' |
|
79 | - ) |
|
80 | - ; |
|
81 | - } |
|
82 | - |
|
83 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | - try { |
|
85 | - $uid = $input->getArgument('ocName'); |
|
86 | - $this->isAllowed($input->getOption('force')); |
|
87 | - $this->confirmUserIsMapped($uid); |
|
88 | - $exists = $this->backend->userExistsOnLDAP($uid); |
|
89 | - if($exists === true) { |
|
90 | - $output->writeln('The user is still available on LDAP.'); |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - $this->dui->markUser($uid); |
|
95 | - $output->writeln('The user does not exists on LDAP anymore.'); |
|
96 | - $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
97 | - . $uid . '"'); |
|
98 | - } catch (\Exception $e) { |
|
99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * checks whether a user is actually mapped |
|
105 | - * @param string $ocName the username as used in ownCloud |
|
106 | - * @throws \Exception |
|
107 | - * @return true |
|
108 | - */ |
|
109 | - protected function confirmUserIsMapped($ocName) { |
|
110 | - $dn = $this->mapping->getDNByName($ocName); |
|
111 | - if ($dn === false) { |
|
112 | - throw new \Exception('The given user is not a recognized LDAP user.'); |
|
113 | - } |
|
114 | - |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * checks whether the setup allows reliable checking of LDAP user existence |
|
120 | - * @throws \Exception |
|
121 | - * @return true |
|
122 | - */ |
|
123 | - protected function isAllowed($force) { |
|
124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | - throw new \Exception('Cannot check user existence, because ' |
|
126 | - . 'disabled LDAP configurations are present.'); |
|
127 | - } |
|
128 | - |
|
129 | - // we don't check ldapUserCleanupInterval from config.php because this |
|
130 | - // action is triggered manually, while the setting only controls the |
|
131 | - // background job. |
|
132 | - |
|
133 | - return true; |
|
134 | - } |
|
39 | + /** @var \OCA\User_LDAP\User_Proxy */ |
|
40 | + protected $backend; |
|
41 | + |
|
42 | + /** @var \OCA\User_LDAP\Helper */ |
|
43 | + protected $helper; |
|
44 | + |
|
45 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
46 | + protected $dui; |
|
47 | + |
|
48 | + /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
49 | + protected $mapping; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param User_Proxy $uBackend |
|
53 | + * @param LDAPHelper $helper |
|
54 | + * @param DeletedUsersIndex $dui |
|
55 | + * @param UserMapping $mapping |
|
56 | + */ |
|
57 | + public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
58 | + $this->backend = $uBackend; |
|
59 | + $this->helper = $helper; |
|
60 | + $this->dui = $dui; |
|
61 | + $this->mapping = $mapping; |
|
62 | + parent::__construct(); |
|
63 | + } |
|
64 | + |
|
65 | + protected function configure() { |
|
66 | + $this |
|
67 | + ->setName('ldap:check-user') |
|
68 | + ->setDescription('checks whether a user exists on LDAP.') |
|
69 | + ->addArgument( |
|
70 | + 'ocName', |
|
71 | + InputArgument::REQUIRED, |
|
72 | + 'the user name as used in ownCloud' |
|
73 | + ) |
|
74 | + ->addOption( |
|
75 | + 'force', |
|
76 | + null, |
|
77 | + InputOption::VALUE_NONE, |
|
78 | + 'ignores disabled LDAP configuration' |
|
79 | + ) |
|
80 | + ; |
|
81 | + } |
|
82 | + |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | + try { |
|
85 | + $uid = $input->getArgument('ocName'); |
|
86 | + $this->isAllowed($input->getOption('force')); |
|
87 | + $this->confirmUserIsMapped($uid); |
|
88 | + $exists = $this->backend->userExistsOnLDAP($uid); |
|
89 | + if($exists === true) { |
|
90 | + $output->writeln('The user is still available on LDAP.'); |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + $this->dui->markUser($uid); |
|
95 | + $output->writeln('The user does not exists on LDAP anymore.'); |
|
96 | + $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
97 | + . $uid . '"'); |
|
98 | + } catch (\Exception $e) { |
|
99 | + $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * checks whether a user is actually mapped |
|
105 | + * @param string $ocName the username as used in ownCloud |
|
106 | + * @throws \Exception |
|
107 | + * @return true |
|
108 | + */ |
|
109 | + protected function confirmUserIsMapped($ocName) { |
|
110 | + $dn = $this->mapping->getDNByName($ocName); |
|
111 | + if ($dn === false) { |
|
112 | + throw new \Exception('The given user is not a recognized LDAP user.'); |
|
113 | + } |
|
114 | + |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * checks whether the setup allows reliable checking of LDAP user existence |
|
120 | + * @throws \Exception |
|
121 | + * @return true |
|
122 | + */ |
|
123 | + protected function isAllowed($force) { |
|
124 | + if($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | + throw new \Exception('Cannot check user existence, because ' |
|
126 | + . 'disabled LDAP configurations are present.'); |
|
127 | + } |
|
128 | + |
|
129 | + // we don't check ldapUserCleanupInterval from config.php because this |
|
130 | + // action is triggered manually, while the setting only controls the |
|
131 | + // background job. |
|
132 | + |
|
133 | + return true; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $this->isAllowed($input->getOption('force')); |
87 | 87 | $this->confirmUserIsMapped($uid); |
88 | 88 | $exists = $this->backend->userExistsOnLDAP($uid); |
89 | - if($exists === true) { |
|
89 | + if ($exists === true) { |
|
90 | 90 | $output->writeln('The user is still available on LDAP.'); |
91 | 91 | return; |
92 | 92 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | $this->dui->markUser($uid); |
95 | 95 | $output->writeln('The user does not exists on LDAP anymore.'); |
96 | 96 | $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
97 | - . $uid . '"'); |
|
97 | + . $uid.'"'); |
|
98 | 98 | } catch (\Exception $e) { |
99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
99 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return true |
122 | 122 | */ |
123 | 123 | protected function isAllowed($force) { |
124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
124 | + if ($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | 125 | throw new \Exception('Cannot check user existence, because ' |
126 | 126 | . 'disabled LDAP configurations are present.'); |
127 | 127 | } |
@@ -37,93 +37,93 @@ |
||
37 | 37 | use OCP\IConfig; |
38 | 38 | |
39 | 39 | class Search extends Command { |
40 | - /** @var \OCP\IConfig */ |
|
41 | - protected $ocConfig; |
|
40 | + /** @var \OCP\IConfig */ |
|
41 | + protected $ocConfig; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param \OCP\IConfig $ocConfig |
|
45 | - */ |
|
46 | - public function __construct(IConfig $ocConfig) { |
|
47 | - $this->ocConfig = $ocConfig; |
|
48 | - parent::__construct(); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @param \OCP\IConfig $ocConfig |
|
45 | + */ |
|
46 | + public function __construct(IConfig $ocConfig) { |
|
47 | + $this->ocConfig = $ocConfig; |
|
48 | + parent::__construct(); |
|
49 | + } |
|
50 | 50 | |
51 | - protected function configure() { |
|
52 | - $this |
|
53 | - ->setName('ldap:search') |
|
54 | - ->setDescription('executes a user or group search') |
|
55 | - ->addArgument( |
|
56 | - 'search', |
|
57 | - InputArgument::REQUIRED, |
|
58 | - 'the search string (can be empty)' |
|
59 | - ) |
|
60 | - ->addOption( |
|
61 | - 'group', |
|
62 | - null, |
|
63 | - InputOption::VALUE_NONE, |
|
64 | - 'searches groups instead of users' |
|
65 | - ) |
|
66 | - ->addOption( |
|
67 | - 'offset', |
|
68 | - null, |
|
69 | - InputOption::VALUE_REQUIRED, |
|
70 | - 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
71 | - 0 |
|
72 | - ) |
|
73 | - ->addOption( |
|
74 | - 'limit', |
|
75 | - null, |
|
76 | - InputOption::VALUE_REQUIRED, |
|
77 | - 'limit the results. 0 means no limit, defaults to 15', |
|
78 | - 15 |
|
79 | - ) |
|
80 | - ; |
|
81 | - } |
|
51 | + protected function configure() { |
|
52 | + $this |
|
53 | + ->setName('ldap:search') |
|
54 | + ->setDescription('executes a user or group search') |
|
55 | + ->addArgument( |
|
56 | + 'search', |
|
57 | + InputArgument::REQUIRED, |
|
58 | + 'the search string (can be empty)' |
|
59 | + ) |
|
60 | + ->addOption( |
|
61 | + 'group', |
|
62 | + null, |
|
63 | + InputOption::VALUE_NONE, |
|
64 | + 'searches groups instead of users' |
|
65 | + ) |
|
66 | + ->addOption( |
|
67 | + 'offset', |
|
68 | + null, |
|
69 | + InputOption::VALUE_REQUIRED, |
|
70 | + 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
71 | + 0 |
|
72 | + ) |
|
73 | + ->addOption( |
|
74 | + 'limit', |
|
75 | + null, |
|
76 | + InputOption::VALUE_REQUIRED, |
|
77 | + 'limit the results. 0 means no limit, defaults to 15', |
|
78 | + 15 |
|
79 | + ) |
|
80 | + ; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Tests whether the offset and limit options are valid |
|
85 | - * @param int $offset |
|
86 | - * @param int $limit |
|
87 | - * @throws \InvalidArgumentException |
|
88 | - */ |
|
89 | - protected function validateOffsetAndLimit($offset, $limit) { |
|
90 | - if($limit < 0) { |
|
91 | - throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
92 | - } |
|
93 | - if($offset < 0) { |
|
94 | - throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
95 | - } |
|
96 | - if($limit === 0 && $offset !== 0) { |
|
97 | - throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
98 | - } |
|
99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | - throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
101 | - } |
|
102 | - } |
|
83 | + /** |
|
84 | + * Tests whether the offset and limit options are valid |
|
85 | + * @param int $offset |
|
86 | + * @param int $limit |
|
87 | + * @throws \InvalidArgumentException |
|
88 | + */ |
|
89 | + protected function validateOffsetAndLimit($offset, $limit) { |
|
90 | + if($limit < 0) { |
|
91 | + throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
92 | + } |
|
93 | + if($offset < 0) { |
|
94 | + throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
95 | + } |
|
96 | + if($limit === 0 && $offset !== 0) { |
|
97 | + throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
98 | + } |
|
99 | + if($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | + throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
105 | - $helper = new Helper($this->ocConfig); |
|
106 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
107 | - $ldapWrapper = new LDAP(); |
|
104 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
105 | + $helper = new Helper($this->ocConfig); |
|
106 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
107 | + $ldapWrapper = new LDAP(); |
|
108 | 108 | |
109 | - $offset = intval($input->getOption('offset')); |
|
110 | - $limit = intval($input->getOption('limit')); |
|
111 | - $this->validateOffsetAndLimit($offset, $limit); |
|
109 | + $offset = intval($input->getOption('offset')); |
|
110 | + $limit = intval($input->getOption('limit')); |
|
111 | + $this->validateOffsetAndLimit($offset, $limit); |
|
112 | 112 | |
113 | - if($input->getOption('group')) { |
|
114 | - $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
115 | - $getMethod = 'getGroups'; |
|
116 | - $printID = false; |
|
117 | - } else { |
|
118 | - $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); |
|
119 | - $getMethod = 'getDisplayNames'; |
|
120 | - $printID = true; |
|
121 | - } |
|
113 | + if($input->getOption('group')) { |
|
114 | + $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
115 | + $getMethod = 'getGroups'; |
|
116 | + $printID = false; |
|
117 | + } else { |
|
118 | + $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); |
|
119 | + $getMethod = 'getDisplayNames'; |
|
120 | + $printID = true; |
|
121 | + } |
|
122 | 122 | |
123 | - $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
124 | - foreach($result as $id => $name) { |
|
125 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
126 | - $output->writeln($line); |
|
127 | - } |
|
128 | - } |
|
123 | + $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
124 | + foreach($result as $id => $name) { |
|
125 | + $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
126 | + $output->writeln($line); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | } |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | * @throws \InvalidArgumentException |
88 | 88 | */ |
89 | 89 | protected function validateOffsetAndLimit($offset, $limit) { |
90 | - if($limit < 0) { |
|
90 | + if ($limit < 0) { |
|
91 | 91 | throw new \InvalidArgumentException('limit must be 0 or greater'); |
92 | 92 | } |
93 | - if($offset < 0) { |
|
93 | + if ($offset < 0) { |
|
94 | 94 | throw new \InvalidArgumentException('offset must be 0 or greater'); |
95 | 95 | } |
96 | - if($limit === 0 && $offset !== 0) { |
|
96 | + if ($limit === 0 && $offset !== 0) { |
|
97 | 97 | throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
98 | 98 | } |
99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
99 | + if ($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | 100 | throw new \InvalidArgumentException('offset must be a multiple of limit'); |
101 | 101 | } |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $limit = intval($input->getOption('limit')); |
111 | 111 | $this->validateOffsetAndLimit($offset, $limit); |
112 | 112 | |
113 | - if($input->getOption('group')) { |
|
113 | + if ($input->getOption('group')) { |
|
114 | 114 | $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
115 | 115 | $getMethod = 'getGroups'; |
116 | 116 | $printID = false; |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
124 | - foreach($result as $id => $name) { |
|
125 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
124 | + foreach ($result as $id => $name) { |
|
125 | + $line = $name.($printID ? ' ('.$id.')' : ''); |
|
126 | 126 | $output->writeln($line); |
127 | 127 | } |
128 | 128 | } |
@@ -33,39 +33,39 @@ |
||
33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
34 | 34 | |
35 | 35 | class DeleteConfig extends Command { |
36 | - /** @var \OCA\User_LDAP\Helper */ |
|
37 | - protected $helper; |
|
36 | + /** @var \OCA\User_LDAP\Helper */ |
|
37 | + protected $helper; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Helper $helper |
|
41 | - */ |
|
42 | - public function __construct(Helper $helper) { |
|
43 | - $this->helper = $helper; |
|
44 | - parent::__construct(); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @param Helper $helper |
|
41 | + */ |
|
42 | + public function __construct(Helper $helper) { |
|
43 | + $this->helper = $helper; |
|
44 | + parent::__construct(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function configure() { |
|
48 | - $this |
|
49 | - ->setName('ldap:delete-config') |
|
50 | - ->setDescription('deletes an existing LDAP configuration') |
|
51 | - ->addArgument( |
|
52 | - 'configID', |
|
53 | - InputArgument::REQUIRED, |
|
54 | - 'the configuration ID' |
|
55 | - ) |
|
56 | - ; |
|
57 | - } |
|
47 | + protected function configure() { |
|
48 | + $this |
|
49 | + ->setName('ldap:delete-config') |
|
50 | + ->setDescription('deletes an existing LDAP configuration') |
|
51 | + ->addArgument( |
|
52 | + 'configID', |
|
53 | + InputArgument::REQUIRED, |
|
54 | + 'the configuration ID' |
|
55 | + ) |
|
56 | + ; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | - $configPrefix = $input->getArgument('configID'); |
|
60 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | + $configPrefix = $input->getArgument('configID'); |
|
62 | 62 | |
63 | - $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
63 | + $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
64 | 64 | |
65 | - if($success) { |
|
66 | - $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
67 | - } else { |
|
68 | - $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
69 | - } |
|
70 | - } |
|
65 | + if($success) { |
|
66 | + $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
67 | + } else { |
|
68 | + $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | $success = $this->helper->deleteServerConfiguration($configPrefix); |
64 | 64 | |
65 | - if($success) { |
|
65 | + if ($success) { |
|
66 | 66 | $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
67 | 67 | } else { |
68 | 68 | $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
@@ -34,59 +34,59 @@ |
||
34 | 34 | |
35 | 35 | class TestConfig extends Command { |
36 | 36 | |
37 | - protected function configure() { |
|
38 | - $this |
|
39 | - ->setName('ldap:test-config') |
|
40 | - ->setDescription('tests an LDAP configuration') |
|
41 | - ->addArgument( |
|
42 | - 'configID', |
|
43 | - InputArgument::REQUIRED, |
|
44 | - 'the configuration ID' |
|
45 | - ) |
|
46 | - ; |
|
47 | - } |
|
37 | + protected function configure() { |
|
38 | + $this |
|
39 | + ->setName('ldap:test-config') |
|
40 | + ->setDescription('tests an LDAP configuration') |
|
41 | + ->addArgument( |
|
42 | + 'configID', |
|
43 | + InputArgument::REQUIRED, |
|
44 | + 'the configuration ID' |
|
45 | + ) |
|
46 | + ; |
|
47 | + } |
|
48 | 48 | |
49 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
50 | - $helper = new Helper(\OC::$server->getConfig()); |
|
51 | - $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
52 | - $configID = $input->getArgument('configID'); |
|
53 | - if(!in_array($configID, $availableConfigs)) { |
|
54 | - $output->writeln("Invalid configID"); |
|
55 | - return; |
|
56 | - } |
|
49 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
50 | + $helper = new Helper(\OC::$server->getConfig()); |
|
51 | + $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
52 | + $configID = $input->getArgument('configID'); |
|
53 | + if(!in_array($configID, $availableConfigs)) { |
|
54 | + $output->writeln("Invalid configID"); |
|
55 | + return; |
|
56 | + } |
|
57 | 57 | |
58 | - $result = $this->testConfig($configID); |
|
59 | - if($result === 0) { |
|
60 | - $output->writeln('The configuration is valid and the connection could be established!'); |
|
61 | - } else if($result === 1) { |
|
62 | - $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
63 | - } else if($result === 2) { |
|
64 | - $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
|
65 | - } else { |
|
66 | - $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
67 | - } |
|
68 | - } |
|
58 | + $result = $this->testConfig($configID); |
|
59 | + if($result === 0) { |
|
60 | + $output->writeln('The configuration is valid and the connection could be established!'); |
|
61 | + } else if($result === 1) { |
|
62 | + $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
63 | + } else if($result === 2) { |
|
64 | + $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
|
65 | + } else { |
|
66 | + $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * tests the specified connection |
|
72 | - * @param string $configID |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - protected function testConfig($configID) { |
|
76 | - $lw = new \OCA\User_LDAP\LDAP(); |
|
77 | - $connection = new Connection($lw, $configID); |
|
70 | + /** |
|
71 | + * tests the specified connection |
|
72 | + * @param string $configID |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + protected function testConfig($configID) { |
|
76 | + $lw = new \OCA\User_LDAP\LDAP(); |
|
77 | + $connection = new Connection($lw, $configID); |
|
78 | 78 | |
79 | - //ensure validation is run before we attempt the bind |
|
80 | - $connection->getConfiguration(); |
|
79 | + //ensure validation is run before we attempt the bind |
|
80 | + $connection->getConfiguration(); |
|
81 | 81 | |
82 | - if(!$connection->setConfiguration(array( |
|
83 | - 'ldap_configuration_active' => 1, |
|
84 | - ))) { |
|
85 | - return 1; |
|
86 | - } |
|
87 | - if($connection->bind()) { |
|
88 | - return 0; |
|
89 | - } |
|
90 | - return 2; |
|
91 | - } |
|
82 | + if(!$connection->setConfiguration(array( |
|
83 | + 'ldap_configuration_active' => 1, |
|
84 | + ))) { |
|
85 | + return 1; |
|
86 | + } |
|
87 | + if($connection->bind()) { |
|
88 | + return 0; |
|
89 | + } |
|
90 | + return 2; |
|
91 | + } |
|
92 | 92 | } |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | $helper = new Helper(\OC::$server->getConfig()); |
51 | 51 | $availableConfigs = $helper->getServerConfigurationPrefixes(); |
52 | 52 | $configID = $input->getArgument('configID'); |
53 | - if(!in_array($configID, $availableConfigs)) { |
|
53 | + if (!in_array($configID, $availableConfigs)) { |
|
54 | 54 | $output->writeln("Invalid configID"); |
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $result = $this->testConfig($configID); |
59 | - if($result === 0) { |
|
59 | + if ($result === 0) { |
|
60 | 60 | $output->writeln('The configuration is valid and the connection could be established!'); |
61 | - } else if($result === 1) { |
|
61 | + } else if ($result === 1) { |
|
62 | 62 | $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
63 | - } else if($result === 2) { |
|
63 | + } else if ($result === 2) { |
|
64 | 64 | $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
65 | 65 | } else { |
66 | 66 | $output->writeln('Your LDAP server was kidnapped by aliens.'); |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | //ensure validation is run before we attempt the bind |
80 | 80 | $connection->getConfiguration(); |
81 | 81 | |
82 | - if(!$connection->setConfiguration(array( |
|
82 | + if (!$connection->setConfiguration(array( |
|
83 | 83 | 'ldap_configuration_active' => 1, |
84 | 84 | ))) { |
85 | 85 | return 1; |
86 | 86 | } |
87 | - if($connection->bind()) { |
|
87 | + if ($connection->bind()) { |
|
88 | 88 | return 0; |
89 | 89 | } |
90 | 90 | return 2; |
@@ -35,61 +35,61 @@ |
||
35 | 35 | use OCP\IDateTimeFormatter; |
36 | 36 | |
37 | 37 | class ShowRemnants extends Command { |
38 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
39 | - protected $dui; |
|
38 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
39 | + protected $dui; |
|
40 | 40 | |
41 | - /** @var \OCP\IDateTimeFormatter */ |
|
42 | - protected $dateFormatter; |
|
41 | + /** @var \OCP\IDateTimeFormatter */ |
|
42 | + protected $dateFormatter; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param DeletedUsersIndex $dui |
|
46 | - * @param IDateTimeFormatter $dateFormatter |
|
47 | - */ |
|
48 | - public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
49 | - $this->dui = $dui; |
|
50 | - $this->dateFormatter = $dateFormatter; |
|
51 | - parent::__construct(); |
|
52 | - } |
|
44 | + /** |
|
45 | + * @param DeletedUsersIndex $dui |
|
46 | + * @param IDateTimeFormatter $dateFormatter |
|
47 | + */ |
|
48 | + public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
49 | + $this->dui = $dui; |
|
50 | + $this->dateFormatter = $dateFormatter; |
|
51 | + parent::__construct(); |
|
52 | + } |
|
53 | 53 | |
54 | - protected function configure() { |
|
55 | - $this |
|
56 | - ->setName('ldap:show-remnants') |
|
57 | - ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.') |
|
58 | - ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.'); |
|
59 | - } |
|
54 | + protected function configure() { |
|
55 | + $this |
|
56 | + ->setName('ldap:show-remnants') |
|
57 | + ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.') |
|
58 | + ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted |
|
63 | - * |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
67 | - /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
68 | - $table = new Table($output); |
|
69 | - $table->setHeaders(array( |
|
70 | - 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
71 | - 'Dir', 'Sharer')); |
|
72 | - $rows = array(); |
|
73 | - $resultSet = $this->dui->getUsers(); |
|
74 | - foreach($resultSet as $user) { |
|
75 | - $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
|
76 | - $lastLogin = ($user->getLastLogin() > 0) ? |
|
77 | - $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
|
78 | - $rows[] = array('ocName' => $user->getOCName(), |
|
79 | - 'displayName' => $user->getDisplayName(), |
|
80 | - 'uid' => $user->getUID(), |
|
81 | - 'dn' => $user->getDN(), |
|
82 | - 'lastLogin' => $lastLogin, |
|
83 | - 'homePath' => $user->getHomePath(), |
|
84 | - 'sharer' => $hAS |
|
85 | - ); |
|
86 | - } |
|
61 | + /** |
|
62 | + * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted |
|
63 | + * |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
67 | + /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
68 | + $table = new Table($output); |
|
69 | + $table->setHeaders(array( |
|
70 | + 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
71 | + 'Dir', 'Sharer')); |
|
72 | + $rows = array(); |
|
73 | + $resultSet = $this->dui->getUsers(); |
|
74 | + foreach($resultSet as $user) { |
|
75 | + $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
|
76 | + $lastLogin = ($user->getLastLogin() > 0) ? |
|
77 | + $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
|
78 | + $rows[] = array('ocName' => $user->getOCName(), |
|
79 | + 'displayName' => $user->getDisplayName(), |
|
80 | + 'uid' => $user->getUID(), |
|
81 | + 'dn' => $user->getDN(), |
|
82 | + 'lastLogin' => $lastLogin, |
|
83 | + 'homePath' => $user->getHomePath(), |
|
84 | + 'sharer' => $hAS |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | |
88 | - if ($input->getOption('json')) { |
|
89 | - $output->writeln(json_encode($rows)); |
|
90 | - } else { |
|
91 | - $table->setRows($rows); |
|
92 | - $table->render($output); |
|
93 | - } |
|
94 | - } |
|
88 | + if ($input->getOption('json')) { |
|
89 | + $output->writeln(json_encode($rows)); |
|
90 | + } else { |
|
91 | + $table->setRows($rows); |
|
92 | + $table->render($output); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | 'Dir', 'Sharer')); |
72 | 72 | $rows = array(); |
73 | 73 | $resultSet = $this->dui->getUsers(); |
74 | - foreach($resultSet as $user) { |
|
74 | + foreach ($resultSet as $user) { |
|
75 | 75 | $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
76 | 76 | $lastLogin = ($user->getLastLogin() > 0) ? |
77 | 77 | $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
@@ -33,39 +33,39 @@ |
||
33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
34 | 34 | |
35 | 35 | class CreateEmptyConfig extends Command { |
36 | - /** @var \OCA\User_LDAP\Helper */ |
|
37 | - protected $helper; |
|
36 | + /** @var \OCA\User_LDAP\Helper */ |
|
37 | + protected $helper; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Helper $helper |
|
41 | - */ |
|
42 | - public function __construct(Helper $helper) { |
|
43 | - $this->helper = $helper; |
|
44 | - parent::__construct(); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @param Helper $helper |
|
41 | + */ |
|
42 | + public function __construct(Helper $helper) { |
|
43 | + $this->helper = $helper; |
|
44 | + parent::__construct(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function configure() { |
|
48 | - $this |
|
49 | - ->setName('ldap:create-empty-config') |
|
50 | - ->setDescription('creates an empty LDAP configuration') |
|
51 | - ->addOption( |
|
52 | - 'only-print-prefix', |
|
53 | - 'p', |
|
54 | - InputOption::VALUE_NONE, |
|
55 | - 'outputs only the prefix' |
|
56 | - ) |
|
57 | - ; |
|
58 | - } |
|
47 | + protected function configure() { |
|
48 | + $this |
|
49 | + ->setName('ldap:create-empty-config') |
|
50 | + ->setDescription('creates an empty LDAP configuration') |
|
51 | + ->addOption( |
|
52 | + 'only-print-prefix', |
|
53 | + 'p', |
|
54 | + InputOption::VALUE_NONE, |
|
55 | + 'outputs only the prefix' |
|
56 | + ) |
|
57 | + ; |
|
58 | + } |
|
59 | 59 | |
60 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | - $configPrefix = $this->helper->getNextServerConfigurationPrefix(); |
|
62 | - $configHolder = new Configuration($configPrefix); |
|
63 | - $configHolder->saveConfiguration(); |
|
60 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | + $configPrefix = $this->helper->getNextServerConfigurationPrefix(); |
|
62 | + $configHolder = new Configuration($configPrefix); |
|
63 | + $configHolder->saveConfiguration(); |
|
64 | 64 | |
65 | - $prose = ''; |
|
66 | - if(!$input->getOption('only-print-prefix')) { |
|
67 | - $prose = 'Created new configuration with configID '; |
|
68 | - } |
|
69 | - $output->writeln($prose . "{$configPrefix}"); |
|
70 | - } |
|
65 | + $prose = ''; |
|
66 | + if(!$input->getOption('only-print-prefix')) { |
|
67 | + $prose = 'Created new configuration with configID '; |
|
68 | + } |
|
69 | + $output->writeln($prose . "{$configPrefix}"); |
|
70 | + } |
|
71 | 71 | } |
@@ -63,9 +63,9 @@ |
||
63 | 63 | $configHolder->saveConfiguration(); |
64 | 64 | |
65 | 65 | $prose = ''; |
66 | - if(!$input->getOption('only-print-prefix')) { |
|
66 | + if (!$input->getOption('only-print-prefix')) { |
|
67 | 67 | $prose = 'Created new configuration with configID '; |
68 | 68 | } |
69 | - $output->writeln($prose . "{$configPrefix}"); |
|
69 | + $output->writeln($prose."{$configPrefix}"); |
|
70 | 70 | } |
71 | 71 | } |
@@ -35,77 +35,77 @@ |
||
35 | 35 | use OCA\User_LDAP\Configuration; |
36 | 36 | |
37 | 37 | class ShowConfig extends Command { |
38 | - /** @var \OCA\User_LDAP\Helper */ |
|
39 | - protected $helper; |
|
38 | + /** @var \OCA\User_LDAP\Helper */ |
|
39 | + protected $helper; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param Helper $helper |
|
43 | - */ |
|
44 | - public function __construct(Helper $helper) { |
|
45 | - $this->helper = $helper; |
|
46 | - parent::__construct(); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param Helper $helper |
|
43 | + */ |
|
44 | + public function __construct(Helper $helper) { |
|
45 | + $this->helper = $helper; |
|
46 | + parent::__construct(); |
|
47 | + } |
|
48 | 48 | |
49 | - protected function configure() { |
|
50 | - $this |
|
51 | - ->setName('ldap:show-config') |
|
52 | - ->setDescription('shows the LDAP configuration') |
|
53 | - ->addArgument( |
|
54 | - 'configID', |
|
55 | - InputArgument::OPTIONAL, |
|
56 | - 'will show the configuration of the specified id' |
|
57 | - ) |
|
58 | - ->addOption( |
|
59 | - 'show-password', |
|
60 | - null, |
|
61 | - InputOption::VALUE_NONE, |
|
62 | - 'show ldap bind password' |
|
63 | - ) |
|
64 | - ; |
|
65 | - } |
|
49 | + protected function configure() { |
|
50 | + $this |
|
51 | + ->setName('ldap:show-config') |
|
52 | + ->setDescription('shows the LDAP configuration') |
|
53 | + ->addArgument( |
|
54 | + 'configID', |
|
55 | + InputArgument::OPTIONAL, |
|
56 | + 'will show the configuration of the specified id' |
|
57 | + ) |
|
58 | + ->addOption( |
|
59 | + 'show-password', |
|
60 | + null, |
|
61 | + InputOption::VALUE_NONE, |
|
62 | + 'show ldap bind password' |
|
63 | + ) |
|
64 | + ; |
|
65 | + } |
|
66 | 66 | |
67 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
68 | - $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
|
69 | - $configID = $input->getArgument('configID'); |
|
70 | - if(!is_null($configID)) { |
|
71 | - $configIDs[] = $configID; |
|
72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
73 | - $output->writeln("Invalid configID"); |
|
74 | - return; |
|
75 | - } |
|
76 | - } else { |
|
77 | - $configIDs = $availableConfigs; |
|
78 | - } |
|
67 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
68 | + $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
|
69 | + $configID = $input->getArgument('configID'); |
|
70 | + if(!is_null($configID)) { |
|
71 | + $configIDs[] = $configID; |
|
72 | + if(!in_array($configIDs[0], $availableConfigs)) { |
|
73 | + $output->writeln("Invalid configID"); |
|
74 | + return; |
|
75 | + } |
|
76 | + } else { |
|
77 | + $configIDs = $availableConfigs; |
|
78 | + } |
|
79 | 79 | |
80 | - $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); |
|
81 | - } |
|
80 | + $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * prints the LDAP configuration(s) |
|
85 | - * @param string[] configID(s) |
|
86 | - * @param OutputInterface $output |
|
87 | - * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
|
88 | - */ |
|
89 | - protected function renderConfigs($configIDs, $output, $withPassword) { |
|
90 | - foreach($configIDs as $id) { |
|
91 | - $configHolder = new Configuration($id); |
|
92 | - $configuration = $configHolder->getConfiguration(); |
|
93 | - ksort($configuration); |
|
83 | + /** |
|
84 | + * prints the LDAP configuration(s) |
|
85 | + * @param string[] configID(s) |
|
86 | + * @param OutputInterface $output |
|
87 | + * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
|
88 | + */ |
|
89 | + protected function renderConfigs($configIDs, $output, $withPassword) { |
|
90 | + foreach($configIDs as $id) { |
|
91 | + $configHolder = new Configuration($id); |
|
92 | + $configuration = $configHolder->getConfiguration(); |
|
93 | + ksort($configuration); |
|
94 | 94 | |
95 | - $table = new Table($output); |
|
96 | - $table->setHeaders(array('Configuration', $id)); |
|
97 | - $rows = array(); |
|
98 | - foreach($configuration as $key => $value) { |
|
99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
100 | - $value = '***'; |
|
101 | - } |
|
102 | - if(is_array($value)) { |
|
103 | - $value = implode(';', $value); |
|
104 | - } |
|
105 | - $rows[] = array($key, $value); |
|
106 | - } |
|
107 | - $table->setRows($rows); |
|
108 | - $table->render($output); |
|
109 | - } |
|
110 | - } |
|
95 | + $table = new Table($output); |
|
96 | + $table->setHeaders(array('Configuration', $id)); |
|
97 | + $rows = array(); |
|
98 | + foreach($configuration as $key => $value) { |
|
99 | + if($key === 'ldapAgentPassword' && !$withPassword) { |
|
100 | + $value = '***'; |
|
101 | + } |
|
102 | + if(is_array($value)) { |
|
103 | + $value = implode(';', $value); |
|
104 | + } |
|
105 | + $rows[] = array($key, $value); |
|
106 | + } |
|
107 | + $table->setRows($rows); |
|
108 | + $table->render($output); |
|
109 | + } |
|
110 | + } |
|
111 | 111 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | protected function execute(InputInterface $input, OutputInterface $output) { |
68 | 68 | $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
69 | 69 | $configID = $input->getArgument('configID'); |
70 | - if(!is_null($configID)) { |
|
70 | + if (!is_null($configID)) { |
|
71 | 71 | $configIDs[] = $configID; |
72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
72 | + if (!in_array($configIDs[0], $availableConfigs)) { |
|
73 | 73 | $output->writeln("Invalid configID"); |
74 | 74 | return; |
75 | 75 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
88 | 88 | */ |
89 | 89 | protected function renderConfigs($configIDs, $output, $withPassword) { |
90 | - foreach($configIDs as $id) { |
|
90 | + foreach ($configIDs as $id) { |
|
91 | 91 | $configHolder = new Configuration($id); |
92 | 92 | $configuration = $configHolder->getConfiguration(); |
93 | 93 | ksort($configuration); |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | $table = new Table($output); |
96 | 96 | $table->setHeaders(array('Configuration', $id)); |
97 | 97 | $rows = array(); |
98 | - foreach($configuration as $key => $value) { |
|
99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
98 | + foreach ($configuration as $key => $value) { |
|
99 | + if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
100 | 100 | $value = '***'; |
101 | 101 | } |
102 | - if(is_array($value)) { |
|
102 | + if (is_array($value)) { |
|
103 | 103 | $value = implode(';', $value); |
104 | 104 | } |
105 | 105 | $rows[] = array($key, $value); |
@@ -36,486 +36,486 @@ |
||
36 | 36 | */ |
37 | 37 | class Configuration { |
38 | 38 | |
39 | - protected $configPrefix = null; |
|
40 | - protected $configRead = false; |
|
39 | + protected $configPrefix = null; |
|
40 | + protected $configRead = false; |
|
41 | 41 | |
42 | - //settings |
|
43 | - protected $config = array( |
|
44 | - 'ldapHost' => null, |
|
45 | - 'ldapPort' => null, |
|
46 | - 'ldapBackupHost' => null, |
|
47 | - 'ldapBackupPort' => null, |
|
48 | - 'ldapBase' => null, |
|
49 | - 'ldapBaseUsers' => null, |
|
50 | - 'ldapBaseGroups' => null, |
|
51 | - 'ldapAgentName' => null, |
|
52 | - 'ldapAgentPassword' => null, |
|
53 | - 'ldapTLS' => null, |
|
54 | - 'turnOffCertCheck' => null, |
|
55 | - 'ldapIgnoreNamingRules' => null, |
|
56 | - 'ldapUserDisplayName' => null, |
|
57 | - 'ldapUserDisplayName2' => null, |
|
58 | - 'ldapUserFilterObjectclass' => null, |
|
59 | - 'ldapUserFilterGroups' => null, |
|
60 | - 'ldapUserFilter' => null, |
|
61 | - 'ldapUserFilterMode' => null, |
|
62 | - 'ldapGroupFilter' => null, |
|
63 | - 'ldapGroupFilterMode' => null, |
|
64 | - 'ldapGroupFilterObjectclass' => null, |
|
65 | - 'ldapGroupFilterGroups' => null, |
|
66 | - 'ldapGroupDisplayName' => null, |
|
67 | - 'ldapGroupMemberAssocAttr' => null, |
|
68 | - 'ldapLoginFilter' => null, |
|
69 | - 'ldapLoginFilterMode' => null, |
|
70 | - 'ldapLoginFilterEmail' => null, |
|
71 | - 'ldapLoginFilterUsername' => null, |
|
72 | - 'ldapLoginFilterAttributes' => null, |
|
73 | - 'ldapQuotaAttribute' => null, |
|
74 | - 'ldapQuotaDefault' => null, |
|
75 | - 'ldapEmailAttribute' => null, |
|
76 | - 'ldapCacheTTL' => null, |
|
77 | - 'ldapUuidUserAttribute' => 'auto', |
|
78 | - 'ldapUuidGroupAttribute' => 'auto', |
|
79 | - 'ldapOverrideMainServer' => false, |
|
80 | - 'ldapConfigurationActive' => false, |
|
81 | - 'ldapAttributesForUserSearch' => null, |
|
82 | - 'ldapAttributesForGroupSearch' => null, |
|
83 | - 'ldapExperiencedAdmin' => false, |
|
84 | - 'homeFolderNamingRule' => null, |
|
85 | - 'hasPagedResultSupport' => false, |
|
86 | - 'hasMemberOfFilterSupport' => false, |
|
87 | - 'useMemberOfToDetectMembership' => true, |
|
88 | - 'ldapExpertUsernameAttr' => null, |
|
89 | - 'ldapExpertUUIDUserAttr' => null, |
|
90 | - 'ldapExpertUUIDGroupAttr' => null, |
|
91 | - 'lastJpegPhotoLookup' => null, |
|
92 | - 'ldapNestedGroups' => false, |
|
93 | - 'ldapPagingSize' => null, |
|
94 | - 'turnOnPasswordChange' => false, |
|
95 | - 'ldapDynamicGroupMemberURL' => null, |
|
96 | - ); |
|
42 | + //settings |
|
43 | + protected $config = array( |
|
44 | + 'ldapHost' => null, |
|
45 | + 'ldapPort' => null, |
|
46 | + 'ldapBackupHost' => null, |
|
47 | + 'ldapBackupPort' => null, |
|
48 | + 'ldapBase' => null, |
|
49 | + 'ldapBaseUsers' => null, |
|
50 | + 'ldapBaseGroups' => null, |
|
51 | + 'ldapAgentName' => null, |
|
52 | + 'ldapAgentPassword' => null, |
|
53 | + 'ldapTLS' => null, |
|
54 | + 'turnOffCertCheck' => null, |
|
55 | + 'ldapIgnoreNamingRules' => null, |
|
56 | + 'ldapUserDisplayName' => null, |
|
57 | + 'ldapUserDisplayName2' => null, |
|
58 | + 'ldapUserFilterObjectclass' => null, |
|
59 | + 'ldapUserFilterGroups' => null, |
|
60 | + 'ldapUserFilter' => null, |
|
61 | + 'ldapUserFilterMode' => null, |
|
62 | + 'ldapGroupFilter' => null, |
|
63 | + 'ldapGroupFilterMode' => null, |
|
64 | + 'ldapGroupFilterObjectclass' => null, |
|
65 | + 'ldapGroupFilterGroups' => null, |
|
66 | + 'ldapGroupDisplayName' => null, |
|
67 | + 'ldapGroupMemberAssocAttr' => null, |
|
68 | + 'ldapLoginFilter' => null, |
|
69 | + 'ldapLoginFilterMode' => null, |
|
70 | + 'ldapLoginFilterEmail' => null, |
|
71 | + 'ldapLoginFilterUsername' => null, |
|
72 | + 'ldapLoginFilterAttributes' => null, |
|
73 | + 'ldapQuotaAttribute' => null, |
|
74 | + 'ldapQuotaDefault' => null, |
|
75 | + 'ldapEmailAttribute' => null, |
|
76 | + 'ldapCacheTTL' => null, |
|
77 | + 'ldapUuidUserAttribute' => 'auto', |
|
78 | + 'ldapUuidGroupAttribute' => 'auto', |
|
79 | + 'ldapOverrideMainServer' => false, |
|
80 | + 'ldapConfigurationActive' => false, |
|
81 | + 'ldapAttributesForUserSearch' => null, |
|
82 | + 'ldapAttributesForGroupSearch' => null, |
|
83 | + 'ldapExperiencedAdmin' => false, |
|
84 | + 'homeFolderNamingRule' => null, |
|
85 | + 'hasPagedResultSupport' => false, |
|
86 | + 'hasMemberOfFilterSupport' => false, |
|
87 | + 'useMemberOfToDetectMembership' => true, |
|
88 | + 'ldapExpertUsernameAttr' => null, |
|
89 | + 'ldapExpertUUIDUserAttr' => null, |
|
90 | + 'ldapExpertUUIDGroupAttr' => null, |
|
91 | + 'lastJpegPhotoLookup' => null, |
|
92 | + 'ldapNestedGroups' => false, |
|
93 | + 'ldapPagingSize' => null, |
|
94 | + 'turnOnPasswordChange' => false, |
|
95 | + 'ldapDynamicGroupMemberURL' => null, |
|
96 | + ); |
|
97 | 97 | |
98 | - /** |
|
99 | - * @param string $configPrefix |
|
100 | - * @param bool $autoRead |
|
101 | - */ |
|
102 | - public function __construct($configPrefix, $autoRead = true) { |
|
103 | - $this->configPrefix = $configPrefix; |
|
104 | - if($autoRead) { |
|
105 | - $this->readConfiguration(); |
|
106 | - } |
|
107 | - } |
|
98 | + /** |
|
99 | + * @param string $configPrefix |
|
100 | + * @param bool $autoRead |
|
101 | + */ |
|
102 | + public function __construct($configPrefix, $autoRead = true) { |
|
103 | + $this->configPrefix = $configPrefix; |
|
104 | + if($autoRead) { |
|
105 | + $this->readConfiguration(); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $name |
|
111 | - * @return mixed|null |
|
112 | - */ |
|
113 | - public function __get($name) { |
|
114 | - if(isset($this->config[$name])) { |
|
115 | - return $this->config[$name]; |
|
116 | - } |
|
117 | - return null; |
|
118 | - } |
|
109 | + /** |
|
110 | + * @param string $name |
|
111 | + * @return mixed|null |
|
112 | + */ |
|
113 | + public function __get($name) { |
|
114 | + if(isset($this->config[$name])) { |
|
115 | + return $this->config[$name]; |
|
116 | + } |
|
117 | + return null; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param string $name |
|
122 | - * @param mixed $value |
|
123 | - */ |
|
124 | - public function __set($name, $value) { |
|
125 | - $this->setConfiguration(array($name => $value)); |
|
126 | - } |
|
120 | + /** |
|
121 | + * @param string $name |
|
122 | + * @param mixed $value |
|
123 | + */ |
|
124 | + public function __set($name, $value) { |
|
125 | + $this->setConfiguration(array($name => $value)); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public function getConfiguration() { |
|
132 | - return $this->config; |
|
133 | - } |
|
128 | + /** |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public function getConfiguration() { |
|
132 | + return $this->config; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * set LDAP configuration with values delivered by an array, not read |
|
137 | - * from configuration. It does not save the configuration! To do so, you |
|
138 | - * must call saveConfiguration afterwards. |
|
139 | - * @param array $config array that holds the config parameters in an associated |
|
140 | - * array |
|
141 | - * @param array &$applied optional; array where the set fields will be given to |
|
142 | - * @return false|null |
|
143 | - */ |
|
144 | - public function setConfiguration($config, &$applied = null) { |
|
145 | - if(!is_array($config)) { |
|
146 | - return false; |
|
147 | - } |
|
135 | + /** |
|
136 | + * set LDAP configuration with values delivered by an array, not read |
|
137 | + * from configuration. It does not save the configuration! To do so, you |
|
138 | + * must call saveConfiguration afterwards. |
|
139 | + * @param array $config array that holds the config parameters in an associated |
|
140 | + * array |
|
141 | + * @param array &$applied optional; array where the set fields will be given to |
|
142 | + * @return false|null |
|
143 | + */ |
|
144 | + public function setConfiguration($config, &$applied = null) { |
|
145 | + if(!is_array($config)) { |
|
146 | + return false; |
|
147 | + } |
|
148 | 148 | |
149 | - $cta = $this->getConfigTranslationArray(); |
|
150 | - foreach($config as $inputKey => $val) { |
|
151 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
152 | - $key = $cta[$inputKey]; |
|
153 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
154 | - $key = $inputKey; |
|
155 | - } else { |
|
156 | - continue; |
|
157 | - } |
|
149 | + $cta = $this->getConfigTranslationArray(); |
|
150 | + foreach($config as $inputKey => $val) { |
|
151 | + if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
152 | + $key = $cta[$inputKey]; |
|
153 | + } elseif(array_key_exists($inputKey, $this->config)) { |
|
154 | + $key = $inputKey; |
|
155 | + } else { |
|
156 | + continue; |
|
157 | + } |
|
158 | 158 | |
159 | - $setMethod = 'setValue'; |
|
160 | - switch($key) { |
|
161 | - case 'ldapAgentPassword': |
|
162 | - $setMethod = 'setRawValue'; |
|
163 | - break; |
|
164 | - case 'homeFolderNamingRule': |
|
165 | - $trimmedVal = trim($val); |
|
166 | - if ($trimmedVal !== '' && strpos($val, 'attr:') === false) { |
|
167 | - $val = 'attr:'.$trimmedVal; |
|
168 | - } |
|
169 | - break; |
|
170 | - case 'ldapBase': |
|
171 | - case 'ldapBaseUsers': |
|
172 | - case 'ldapBaseGroups': |
|
173 | - case 'ldapAttributesForUserSearch': |
|
174 | - case 'ldapAttributesForGroupSearch': |
|
175 | - case 'ldapUserFilterObjectclass': |
|
176 | - case 'ldapUserFilterGroups': |
|
177 | - case 'ldapGroupFilterObjectclass': |
|
178 | - case 'ldapGroupFilterGroups': |
|
179 | - case 'ldapLoginFilterAttributes': |
|
180 | - $setMethod = 'setMultiLine'; |
|
181 | - break; |
|
182 | - } |
|
183 | - $this->$setMethod($key, $val); |
|
184 | - if(is_array($applied)) { |
|
185 | - $applied[] = $inputKey; |
|
186 | - } |
|
187 | - } |
|
188 | - return null; |
|
189 | - } |
|
159 | + $setMethod = 'setValue'; |
|
160 | + switch($key) { |
|
161 | + case 'ldapAgentPassword': |
|
162 | + $setMethod = 'setRawValue'; |
|
163 | + break; |
|
164 | + case 'homeFolderNamingRule': |
|
165 | + $trimmedVal = trim($val); |
|
166 | + if ($trimmedVal !== '' && strpos($val, 'attr:') === false) { |
|
167 | + $val = 'attr:'.$trimmedVal; |
|
168 | + } |
|
169 | + break; |
|
170 | + case 'ldapBase': |
|
171 | + case 'ldapBaseUsers': |
|
172 | + case 'ldapBaseGroups': |
|
173 | + case 'ldapAttributesForUserSearch': |
|
174 | + case 'ldapAttributesForGroupSearch': |
|
175 | + case 'ldapUserFilterObjectclass': |
|
176 | + case 'ldapUserFilterGroups': |
|
177 | + case 'ldapGroupFilterObjectclass': |
|
178 | + case 'ldapGroupFilterGroups': |
|
179 | + case 'ldapLoginFilterAttributes': |
|
180 | + $setMethod = 'setMultiLine'; |
|
181 | + break; |
|
182 | + } |
|
183 | + $this->$setMethod($key, $val); |
|
184 | + if(is_array($applied)) { |
|
185 | + $applied[] = $inputKey; |
|
186 | + } |
|
187 | + } |
|
188 | + return null; |
|
189 | + } |
|
190 | 190 | |
191 | - public function readConfiguration() { |
|
192 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
193 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
194 | - foreach($this->config as $key => $val) { |
|
195 | - if(!isset($cta[$key])) { |
|
196 | - //some are determined |
|
197 | - continue; |
|
198 | - } |
|
199 | - $dbKey = $cta[$key]; |
|
200 | - switch($key) { |
|
201 | - case 'ldapBase': |
|
202 | - case 'ldapBaseUsers': |
|
203 | - case 'ldapBaseGroups': |
|
204 | - case 'ldapAttributesForUserSearch': |
|
205 | - case 'ldapAttributesForGroupSearch': |
|
206 | - case 'ldapUserFilterObjectclass': |
|
207 | - case 'ldapUserFilterGroups': |
|
208 | - case 'ldapGroupFilterObjectclass': |
|
209 | - case 'ldapGroupFilterGroups': |
|
210 | - case 'ldapLoginFilterAttributes': |
|
211 | - $readMethod = 'getMultiLine'; |
|
212 | - break; |
|
213 | - case 'ldapIgnoreNamingRules': |
|
214 | - $readMethod = 'getSystemValue'; |
|
215 | - $dbKey = $key; |
|
216 | - break; |
|
217 | - case 'ldapAgentPassword': |
|
218 | - $readMethod = 'getPwd'; |
|
219 | - break; |
|
220 | - case 'ldapUserDisplayName2': |
|
221 | - case 'ldapGroupDisplayName': |
|
222 | - $readMethod = 'getLcValue'; |
|
223 | - break; |
|
224 | - case 'ldapUserDisplayName': |
|
225 | - default: |
|
226 | - // user display name does not lower case because |
|
227 | - // we rely on an upper case N as indicator whether to |
|
228 | - // auto-detect it or not. FIXME |
|
229 | - $readMethod = 'getValue'; |
|
230 | - break; |
|
231 | - } |
|
232 | - $this->config[$key] = $this->$readMethod($dbKey); |
|
233 | - } |
|
234 | - $this->configRead = true; |
|
235 | - } |
|
236 | - } |
|
191 | + public function readConfiguration() { |
|
192 | + if(!$this->configRead && !is_null($this->configPrefix)) { |
|
193 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
194 | + foreach($this->config as $key => $val) { |
|
195 | + if(!isset($cta[$key])) { |
|
196 | + //some are determined |
|
197 | + continue; |
|
198 | + } |
|
199 | + $dbKey = $cta[$key]; |
|
200 | + switch($key) { |
|
201 | + case 'ldapBase': |
|
202 | + case 'ldapBaseUsers': |
|
203 | + case 'ldapBaseGroups': |
|
204 | + case 'ldapAttributesForUserSearch': |
|
205 | + case 'ldapAttributesForGroupSearch': |
|
206 | + case 'ldapUserFilterObjectclass': |
|
207 | + case 'ldapUserFilterGroups': |
|
208 | + case 'ldapGroupFilterObjectclass': |
|
209 | + case 'ldapGroupFilterGroups': |
|
210 | + case 'ldapLoginFilterAttributes': |
|
211 | + $readMethod = 'getMultiLine'; |
|
212 | + break; |
|
213 | + case 'ldapIgnoreNamingRules': |
|
214 | + $readMethod = 'getSystemValue'; |
|
215 | + $dbKey = $key; |
|
216 | + break; |
|
217 | + case 'ldapAgentPassword': |
|
218 | + $readMethod = 'getPwd'; |
|
219 | + break; |
|
220 | + case 'ldapUserDisplayName2': |
|
221 | + case 'ldapGroupDisplayName': |
|
222 | + $readMethod = 'getLcValue'; |
|
223 | + break; |
|
224 | + case 'ldapUserDisplayName': |
|
225 | + default: |
|
226 | + // user display name does not lower case because |
|
227 | + // we rely on an upper case N as indicator whether to |
|
228 | + // auto-detect it or not. FIXME |
|
229 | + $readMethod = 'getValue'; |
|
230 | + break; |
|
231 | + } |
|
232 | + $this->config[$key] = $this->$readMethod($dbKey); |
|
233 | + } |
|
234 | + $this->configRead = true; |
|
235 | + } |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * saves the current Configuration in the database |
|
240 | - */ |
|
241 | - public function saveConfiguration() { |
|
242 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
243 | - foreach($this->config as $key => $value) { |
|
244 | - switch ($key) { |
|
245 | - case 'ldapAgentPassword': |
|
246 | - $value = base64_encode($value); |
|
247 | - break; |
|
248 | - case 'ldapBase': |
|
249 | - case 'ldapBaseUsers': |
|
250 | - case 'ldapBaseGroups': |
|
251 | - case 'ldapAttributesForUserSearch': |
|
252 | - case 'ldapAttributesForGroupSearch': |
|
253 | - case 'ldapUserFilterObjectclass': |
|
254 | - case 'ldapUserFilterGroups': |
|
255 | - case 'ldapGroupFilterObjectclass': |
|
256 | - case 'ldapGroupFilterGroups': |
|
257 | - case 'ldapLoginFilterAttributes': |
|
258 | - if(is_array($value)) { |
|
259 | - $value = implode("\n", $value); |
|
260 | - } |
|
261 | - break; |
|
262 | - //following options are not stored but detected, skip them |
|
263 | - case 'ldapIgnoreNamingRules': |
|
264 | - case 'hasPagedResultSupport': |
|
265 | - case 'ldapUuidUserAttribute': |
|
266 | - case 'ldapUuidGroupAttribute': |
|
267 | - continue 2; |
|
268 | - } |
|
269 | - if(is_null($value)) { |
|
270 | - $value = ''; |
|
271 | - } |
|
272 | - $this->saveValue($cta[$key], $value); |
|
273 | - } |
|
274 | - } |
|
238 | + /** |
|
239 | + * saves the current Configuration in the database |
|
240 | + */ |
|
241 | + public function saveConfiguration() { |
|
242 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
243 | + foreach($this->config as $key => $value) { |
|
244 | + switch ($key) { |
|
245 | + case 'ldapAgentPassword': |
|
246 | + $value = base64_encode($value); |
|
247 | + break; |
|
248 | + case 'ldapBase': |
|
249 | + case 'ldapBaseUsers': |
|
250 | + case 'ldapBaseGroups': |
|
251 | + case 'ldapAttributesForUserSearch': |
|
252 | + case 'ldapAttributesForGroupSearch': |
|
253 | + case 'ldapUserFilterObjectclass': |
|
254 | + case 'ldapUserFilterGroups': |
|
255 | + case 'ldapGroupFilterObjectclass': |
|
256 | + case 'ldapGroupFilterGroups': |
|
257 | + case 'ldapLoginFilterAttributes': |
|
258 | + if(is_array($value)) { |
|
259 | + $value = implode("\n", $value); |
|
260 | + } |
|
261 | + break; |
|
262 | + //following options are not stored but detected, skip them |
|
263 | + case 'ldapIgnoreNamingRules': |
|
264 | + case 'hasPagedResultSupport': |
|
265 | + case 'ldapUuidUserAttribute': |
|
266 | + case 'ldapUuidGroupAttribute': |
|
267 | + continue 2; |
|
268 | + } |
|
269 | + if(is_null($value)) { |
|
270 | + $value = ''; |
|
271 | + } |
|
272 | + $this->saveValue($cta[$key], $value); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * @param string $varName |
|
278 | - * @return array|string |
|
279 | - */ |
|
280 | - protected function getMultiLine($varName) { |
|
281 | - $value = $this->getValue($varName); |
|
282 | - if(empty($value)) { |
|
283 | - $value = ''; |
|
284 | - } else { |
|
285 | - $value = preg_split('/\r\n|\r|\n/', $value); |
|
286 | - } |
|
276 | + /** |
|
277 | + * @param string $varName |
|
278 | + * @return array|string |
|
279 | + */ |
|
280 | + protected function getMultiLine($varName) { |
|
281 | + $value = $this->getValue($varName); |
|
282 | + if(empty($value)) { |
|
283 | + $value = ''; |
|
284 | + } else { |
|
285 | + $value = preg_split('/\r\n|\r|\n/', $value); |
|
286 | + } |
|
287 | 287 | |
288 | - return $value; |
|
289 | - } |
|
288 | + return $value; |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Sets multi-line values as arrays |
|
293 | - * |
|
294 | - * @param string $varName name of config-key |
|
295 | - * @param array|string $value to set |
|
296 | - */ |
|
297 | - protected function setMultiLine($varName, $value) { |
|
298 | - if(empty($value)) { |
|
299 | - $value = ''; |
|
300 | - } else if (!is_array($value)) { |
|
301 | - $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
302 | - if($value === false) { |
|
303 | - $value = ''; |
|
304 | - } |
|
305 | - } |
|
291 | + /** |
|
292 | + * Sets multi-line values as arrays |
|
293 | + * |
|
294 | + * @param string $varName name of config-key |
|
295 | + * @param array|string $value to set |
|
296 | + */ |
|
297 | + protected function setMultiLine($varName, $value) { |
|
298 | + if(empty($value)) { |
|
299 | + $value = ''; |
|
300 | + } else if (!is_array($value)) { |
|
301 | + $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
302 | + if($value === false) { |
|
303 | + $value = ''; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | - if(!is_array($value)) { |
|
308 | - $finalValue = trim($value); |
|
309 | - } else { |
|
310 | - $finalValue = []; |
|
311 | - foreach($value as $key => $val) { |
|
312 | - if(is_string($val)) { |
|
313 | - $val = trim($val); |
|
314 | - if ($val !== '') { |
|
315 | - //accidental line breaks are not wanted and can cause |
|
316 | - // odd behaviour. Thus, away with them. |
|
317 | - $finalValue[] = $val; |
|
318 | - } |
|
319 | - } else { |
|
320 | - $finalValue[] = $val; |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
307 | + if(!is_array($value)) { |
|
308 | + $finalValue = trim($value); |
|
309 | + } else { |
|
310 | + $finalValue = []; |
|
311 | + foreach($value as $key => $val) { |
|
312 | + if(is_string($val)) { |
|
313 | + $val = trim($val); |
|
314 | + if ($val !== '') { |
|
315 | + //accidental line breaks are not wanted and can cause |
|
316 | + // odd behaviour. Thus, away with them. |
|
317 | + $finalValue[] = $val; |
|
318 | + } |
|
319 | + } else { |
|
320 | + $finalValue[] = $val; |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | 324 | |
325 | - $this->setRawValue($varName, $finalValue); |
|
326 | - } |
|
325 | + $this->setRawValue($varName, $finalValue); |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * @param string $varName |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - protected function getPwd($varName) { |
|
333 | - return base64_decode($this->getValue($varName)); |
|
334 | - } |
|
328 | + /** |
|
329 | + * @param string $varName |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + protected function getPwd($varName) { |
|
333 | + return base64_decode($this->getValue($varName)); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * @param string $varName |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - protected function getLcValue($varName) { |
|
341 | - return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
342 | - } |
|
336 | + /** |
|
337 | + * @param string $varName |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + protected function getLcValue($varName) { |
|
341 | + return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * @param string $varName |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - protected function getSystemValue($varName) { |
|
349 | - //FIXME: if another system value is added, softcode the default value |
|
350 | - return \OCP\Config::getSystemValue($varName, false); |
|
351 | - } |
|
344 | + /** |
|
345 | + * @param string $varName |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + protected function getSystemValue($varName) { |
|
349 | + //FIXME: if another system value is added, softcode the default value |
|
350 | + return \OCP\Config::getSystemValue($varName, false); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * @param string $varName |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - protected function getValue($varName) { |
|
358 | - static $defaults; |
|
359 | - if(is_null($defaults)) { |
|
360 | - $defaults = $this->getDefaults(); |
|
361 | - } |
|
362 | - return \OCP\Config::getAppValue('user_ldap', |
|
363 | - $this->configPrefix.$varName, |
|
364 | - $defaults[$varName]); |
|
365 | - } |
|
353 | + /** |
|
354 | + * @param string $varName |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + protected function getValue($varName) { |
|
358 | + static $defaults; |
|
359 | + if(is_null($defaults)) { |
|
360 | + $defaults = $this->getDefaults(); |
|
361 | + } |
|
362 | + return \OCP\Config::getAppValue('user_ldap', |
|
363 | + $this->configPrefix.$varName, |
|
364 | + $defaults[$varName]); |
|
365 | + } |
|
366 | 366 | |
367 | - /** |
|
368 | - * Sets a scalar value. |
|
369 | - * |
|
370 | - * @param string $varName name of config key |
|
371 | - * @param mixed $value to set |
|
372 | - */ |
|
373 | - protected function setValue($varName, $value) { |
|
374 | - if(is_string($value)) { |
|
375 | - $value = trim($value); |
|
376 | - } |
|
377 | - $this->config[$varName] = $value; |
|
378 | - } |
|
367 | + /** |
|
368 | + * Sets a scalar value. |
|
369 | + * |
|
370 | + * @param string $varName name of config key |
|
371 | + * @param mixed $value to set |
|
372 | + */ |
|
373 | + protected function setValue($varName, $value) { |
|
374 | + if(is_string($value)) { |
|
375 | + $value = trim($value); |
|
376 | + } |
|
377 | + $this->config[$varName] = $value; |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Sets a scalar value without trimming. |
|
382 | - * |
|
383 | - * @param string $varName name of config key |
|
384 | - * @param mixed $value to set |
|
385 | - */ |
|
386 | - protected function setRawValue($varName, $value) { |
|
387 | - $this->config[$varName] = $value; |
|
388 | - } |
|
380 | + /** |
|
381 | + * Sets a scalar value without trimming. |
|
382 | + * |
|
383 | + * @param string $varName name of config key |
|
384 | + * @param mixed $value to set |
|
385 | + */ |
|
386 | + protected function setRawValue($varName, $value) { |
|
387 | + $this->config[$varName] = $value; |
|
388 | + } |
|
389 | 389 | |
390 | - /** |
|
391 | - * @param string $varName |
|
392 | - * @param string $value |
|
393 | - * @return bool |
|
394 | - */ |
|
395 | - protected function saveValue($varName, $value) { |
|
396 | - \OC::$server->getConfig()->setAppValue( |
|
397 | - 'user_ldap', |
|
398 | - $this->configPrefix.$varName, |
|
399 | - $value |
|
400 | - ); |
|
401 | - return true; |
|
402 | - } |
|
390 | + /** |
|
391 | + * @param string $varName |
|
392 | + * @param string $value |
|
393 | + * @return bool |
|
394 | + */ |
|
395 | + protected function saveValue($varName, $value) { |
|
396 | + \OC::$server->getConfig()->setAppValue( |
|
397 | + 'user_ldap', |
|
398 | + $this->configPrefix.$varName, |
|
399 | + $value |
|
400 | + ); |
|
401 | + return true; |
|
402 | + } |
|
403 | 403 | |
404 | - /** |
|
405 | - * @return array an associative array with the default values. Keys are correspond |
|
406 | - * to config-value entries in the database table |
|
407 | - */ |
|
408 | - public function getDefaults() { |
|
409 | - return array( |
|
410 | - 'ldap_host' => '', |
|
411 | - 'ldap_port' => '', |
|
412 | - 'ldap_backup_host' => '', |
|
413 | - 'ldap_backup_port' => '', |
|
414 | - 'ldap_override_main_server' => '', |
|
415 | - 'ldap_dn' => '', |
|
416 | - 'ldap_agent_password' => '', |
|
417 | - 'ldap_base' => '', |
|
418 | - 'ldap_base_users' => '', |
|
419 | - 'ldap_base_groups' => '', |
|
420 | - 'ldap_userlist_filter' => '', |
|
421 | - 'ldap_user_filter_mode' => 0, |
|
422 | - 'ldap_userfilter_objectclass' => '', |
|
423 | - 'ldap_userfilter_groups' => '', |
|
424 | - 'ldap_login_filter' => '', |
|
425 | - 'ldap_login_filter_mode' => 0, |
|
426 | - 'ldap_loginfilter_email' => 0, |
|
427 | - 'ldap_loginfilter_username' => 1, |
|
428 | - 'ldap_loginfilter_attributes' => '', |
|
429 | - 'ldap_group_filter' => '', |
|
430 | - 'ldap_group_filter_mode' => 0, |
|
431 | - 'ldap_groupfilter_objectclass' => '', |
|
432 | - 'ldap_groupfilter_groups' => '', |
|
433 | - 'ldap_display_name' => 'displayName', |
|
434 | - 'ldap_user_display_name_2' => '', |
|
435 | - 'ldap_group_display_name' => 'cn', |
|
436 | - 'ldap_tls' => 0, |
|
437 | - 'ldap_quota_def' => '', |
|
438 | - 'ldap_quota_attr' => '', |
|
439 | - 'ldap_email_attr' => '', |
|
440 | - 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
441 | - 'ldap_cache_ttl' => 600, |
|
442 | - 'ldap_uuid_user_attribute' => 'auto', |
|
443 | - 'ldap_uuid_group_attribute' => 'auto', |
|
444 | - 'home_folder_naming_rule' => '', |
|
445 | - 'ldap_turn_off_cert_check' => 0, |
|
446 | - 'ldap_configuration_active' => 0, |
|
447 | - 'ldap_attributes_for_user_search' => '', |
|
448 | - 'ldap_attributes_for_group_search' => '', |
|
449 | - 'ldap_expert_username_attr' => '', |
|
450 | - 'ldap_expert_uuid_user_attr' => '', |
|
451 | - 'ldap_expert_uuid_group_attr' => '', |
|
452 | - 'has_memberof_filter_support' => 0, |
|
453 | - 'use_memberof_to_detect_membership' => 1, |
|
454 | - 'last_jpegPhoto_lookup' => 0, |
|
455 | - 'ldap_nested_groups' => 0, |
|
456 | - 'ldap_paging_size' => 500, |
|
457 | - 'ldap_turn_on_pwd_change' => 0, |
|
458 | - 'ldap_experienced_admin' => 0, |
|
459 | - 'ldap_dynamic_group_member_url' => '', |
|
460 | - ); |
|
461 | - } |
|
404 | + /** |
|
405 | + * @return array an associative array with the default values. Keys are correspond |
|
406 | + * to config-value entries in the database table |
|
407 | + */ |
|
408 | + public function getDefaults() { |
|
409 | + return array( |
|
410 | + 'ldap_host' => '', |
|
411 | + 'ldap_port' => '', |
|
412 | + 'ldap_backup_host' => '', |
|
413 | + 'ldap_backup_port' => '', |
|
414 | + 'ldap_override_main_server' => '', |
|
415 | + 'ldap_dn' => '', |
|
416 | + 'ldap_agent_password' => '', |
|
417 | + 'ldap_base' => '', |
|
418 | + 'ldap_base_users' => '', |
|
419 | + 'ldap_base_groups' => '', |
|
420 | + 'ldap_userlist_filter' => '', |
|
421 | + 'ldap_user_filter_mode' => 0, |
|
422 | + 'ldap_userfilter_objectclass' => '', |
|
423 | + 'ldap_userfilter_groups' => '', |
|
424 | + 'ldap_login_filter' => '', |
|
425 | + 'ldap_login_filter_mode' => 0, |
|
426 | + 'ldap_loginfilter_email' => 0, |
|
427 | + 'ldap_loginfilter_username' => 1, |
|
428 | + 'ldap_loginfilter_attributes' => '', |
|
429 | + 'ldap_group_filter' => '', |
|
430 | + 'ldap_group_filter_mode' => 0, |
|
431 | + 'ldap_groupfilter_objectclass' => '', |
|
432 | + 'ldap_groupfilter_groups' => '', |
|
433 | + 'ldap_display_name' => 'displayName', |
|
434 | + 'ldap_user_display_name_2' => '', |
|
435 | + 'ldap_group_display_name' => 'cn', |
|
436 | + 'ldap_tls' => 0, |
|
437 | + 'ldap_quota_def' => '', |
|
438 | + 'ldap_quota_attr' => '', |
|
439 | + 'ldap_email_attr' => '', |
|
440 | + 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
441 | + 'ldap_cache_ttl' => 600, |
|
442 | + 'ldap_uuid_user_attribute' => 'auto', |
|
443 | + 'ldap_uuid_group_attribute' => 'auto', |
|
444 | + 'home_folder_naming_rule' => '', |
|
445 | + 'ldap_turn_off_cert_check' => 0, |
|
446 | + 'ldap_configuration_active' => 0, |
|
447 | + 'ldap_attributes_for_user_search' => '', |
|
448 | + 'ldap_attributes_for_group_search' => '', |
|
449 | + 'ldap_expert_username_attr' => '', |
|
450 | + 'ldap_expert_uuid_user_attr' => '', |
|
451 | + 'ldap_expert_uuid_group_attr' => '', |
|
452 | + 'has_memberof_filter_support' => 0, |
|
453 | + 'use_memberof_to_detect_membership' => 1, |
|
454 | + 'last_jpegPhoto_lookup' => 0, |
|
455 | + 'ldap_nested_groups' => 0, |
|
456 | + 'ldap_paging_size' => 500, |
|
457 | + 'ldap_turn_on_pwd_change' => 0, |
|
458 | + 'ldap_experienced_admin' => 0, |
|
459 | + 'ldap_dynamic_group_member_url' => '', |
|
460 | + ); |
|
461 | + } |
|
462 | 462 | |
463 | - /** |
|
464 | - * @return array that maps internal variable names to database fields |
|
465 | - */ |
|
466 | - public function getConfigTranslationArray() { |
|
467 | - //TODO: merge them into one representation |
|
468 | - static $array = array( |
|
469 | - 'ldap_host' => 'ldapHost', |
|
470 | - 'ldap_port' => 'ldapPort', |
|
471 | - 'ldap_backup_host' => 'ldapBackupHost', |
|
472 | - 'ldap_backup_port' => 'ldapBackupPort', |
|
473 | - 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
474 | - 'ldap_dn' => 'ldapAgentName', |
|
475 | - 'ldap_agent_password' => 'ldapAgentPassword', |
|
476 | - 'ldap_base' => 'ldapBase', |
|
477 | - 'ldap_base_users' => 'ldapBaseUsers', |
|
478 | - 'ldap_base_groups' => 'ldapBaseGroups', |
|
479 | - 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
480 | - 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
481 | - 'ldap_userlist_filter' => 'ldapUserFilter', |
|
482 | - 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
483 | - 'ldap_login_filter' => 'ldapLoginFilter', |
|
484 | - 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
485 | - 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
486 | - 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
487 | - 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
488 | - 'ldap_group_filter' => 'ldapGroupFilter', |
|
489 | - 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
490 | - 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
491 | - 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
492 | - 'ldap_display_name' => 'ldapUserDisplayName', |
|
493 | - 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
494 | - 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
495 | - 'ldap_tls' => 'ldapTLS', |
|
496 | - 'ldap_quota_def' => 'ldapQuotaDefault', |
|
497 | - 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
498 | - 'ldap_email_attr' => 'ldapEmailAttribute', |
|
499 | - 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
500 | - 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
501 | - 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
502 | - 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
503 | - 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
504 | - 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
505 | - 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
506 | - 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
507 | - 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
508 | - 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
509 | - 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
510 | - 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
511 | - 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
512 | - 'ldap_nested_groups' => 'ldapNestedGroups', |
|
513 | - 'ldap_paging_size' => 'ldapPagingSize', |
|
514 | - 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
515 | - 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
516 | - 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
517 | - ); |
|
518 | - return $array; |
|
519 | - } |
|
463 | + /** |
|
464 | + * @return array that maps internal variable names to database fields |
|
465 | + */ |
|
466 | + public function getConfigTranslationArray() { |
|
467 | + //TODO: merge them into one representation |
|
468 | + static $array = array( |
|
469 | + 'ldap_host' => 'ldapHost', |
|
470 | + 'ldap_port' => 'ldapPort', |
|
471 | + 'ldap_backup_host' => 'ldapBackupHost', |
|
472 | + 'ldap_backup_port' => 'ldapBackupPort', |
|
473 | + 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
474 | + 'ldap_dn' => 'ldapAgentName', |
|
475 | + 'ldap_agent_password' => 'ldapAgentPassword', |
|
476 | + 'ldap_base' => 'ldapBase', |
|
477 | + 'ldap_base_users' => 'ldapBaseUsers', |
|
478 | + 'ldap_base_groups' => 'ldapBaseGroups', |
|
479 | + 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
480 | + 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
481 | + 'ldap_userlist_filter' => 'ldapUserFilter', |
|
482 | + 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
483 | + 'ldap_login_filter' => 'ldapLoginFilter', |
|
484 | + 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
485 | + 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
486 | + 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
487 | + 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
488 | + 'ldap_group_filter' => 'ldapGroupFilter', |
|
489 | + 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
490 | + 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
491 | + 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
492 | + 'ldap_display_name' => 'ldapUserDisplayName', |
|
493 | + 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
494 | + 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
495 | + 'ldap_tls' => 'ldapTLS', |
|
496 | + 'ldap_quota_def' => 'ldapQuotaDefault', |
|
497 | + 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
498 | + 'ldap_email_attr' => 'ldapEmailAttribute', |
|
499 | + 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
500 | + 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
501 | + 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
502 | + 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
503 | + 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
504 | + 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
505 | + 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
506 | + 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
507 | + 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
508 | + 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
509 | + 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
510 | + 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
511 | + 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
512 | + 'ldap_nested_groups' => 'ldapNestedGroups', |
|
513 | + 'ldap_paging_size' => 'ldapPagingSize', |
|
514 | + 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
515 | + 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
516 | + 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
517 | + ); |
|
518 | + return $array; |
|
519 | + } |
|
520 | 520 | |
521 | 521 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function __construct($configPrefix, $autoRead = true) { |
103 | 103 | $this->configPrefix = $configPrefix; |
104 | - if($autoRead) { |
|
104 | + if ($autoRead) { |
|
105 | 105 | $this->readConfiguration(); |
106 | 106 | } |
107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return mixed|null |
112 | 112 | */ |
113 | 113 | public function __get($name) { |
114 | - if(isset($this->config[$name])) { |
|
114 | + if (isset($this->config[$name])) { |
|
115 | 115 | return $this->config[$name]; |
116 | 116 | } |
117 | 117 | return null; |
@@ -142,22 +142,22 @@ discard block |
||
142 | 142 | * @return false|null |
143 | 143 | */ |
144 | 144 | public function setConfiguration($config, &$applied = null) { |
145 | - if(!is_array($config)) { |
|
145 | + if (!is_array($config)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $cta = $this->getConfigTranslationArray(); |
150 | - foreach($config as $inputKey => $val) { |
|
151 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
150 | + foreach ($config as $inputKey => $val) { |
|
151 | + if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
152 | 152 | $key = $cta[$inputKey]; |
153 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
153 | + } elseif (array_key_exists($inputKey, $this->config)) { |
|
154 | 154 | $key = $inputKey; |
155 | 155 | } else { |
156 | 156 | continue; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $setMethod = 'setValue'; |
160 | - switch($key) { |
|
160 | + switch ($key) { |
|
161 | 161 | case 'ldapAgentPassword': |
162 | 162 | $setMethod = 'setRawValue'; |
163 | 163 | break; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | break; |
182 | 182 | } |
183 | 183 | $this->$setMethod($key, $val); |
184 | - if(is_array($applied)) { |
|
184 | + if (is_array($applied)) { |
|
185 | 185 | $applied[] = $inputKey; |
186 | 186 | } |
187 | 187 | } |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | public function readConfiguration() { |
192 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
192 | + if (!$this->configRead && !is_null($this->configPrefix)) { |
|
193 | 193 | $cta = array_flip($this->getConfigTranslationArray()); |
194 | - foreach($this->config as $key => $val) { |
|
195 | - if(!isset($cta[$key])) { |
|
194 | + foreach ($this->config as $key => $val) { |
|
195 | + if (!isset($cta[$key])) { |
|
196 | 196 | //some are determined |
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | $dbKey = $cta[$key]; |
200 | - switch($key) { |
|
200 | + switch ($key) { |
|
201 | 201 | case 'ldapBase': |
202 | 202 | case 'ldapBaseUsers': |
203 | 203 | case 'ldapBaseGroups': |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function saveConfiguration() { |
242 | 242 | $cta = array_flip($this->getConfigTranslationArray()); |
243 | - foreach($this->config as $key => $value) { |
|
243 | + foreach ($this->config as $key => $value) { |
|
244 | 244 | switch ($key) { |
245 | 245 | case 'ldapAgentPassword': |
246 | 246 | $value = base64_encode($value); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | case 'ldapGroupFilterObjectclass': |
256 | 256 | case 'ldapGroupFilterGroups': |
257 | 257 | case 'ldapLoginFilterAttributes': |
258 | - if(is_array($value)) { |
|
258 | + if (is_array($value)) { |
|
259 | 259 | $value = implode("\n", $value); |
260 | 260 | } |
261 | 261 | break; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | case 'ldapUuidGroupAttribute': |
267 | 267 | continue 2; |
268 | 268 | } |
269 | - if(is_null($value)) { |
|
269 | + if (is_null($value)) { |
|
270 | 270 | $value = ''; |
271 | 271 | } |
272 | 272 | $this->saveValue($cta[$key], $value); |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function getMultiLine($varName) { |
281 | 281 | $value = $this->getValue($varName); |
282 | - if(empty($value)) { |
|
282 | + if (empty($value)) { |
|
283 | 283 | $value = ''; |
284 | 284 | } else { |
285 | 285 | $value = preg_split('/\r\n|\r|\n/', $value); |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | * @param array|string $value to set |
296 | 296 | */ |
297 | 297 | protected function setMultiLine($varName, $value) { |
298 | - if(empty($value)) { |
|
298 | + if (empty($value)) { |
|
299 | 299 | $value = ''; |
300 | 300 | } else if (!is_array($value)) { |
301 | 301 | $value = preg_split('/\r\n|\r|\n|;/', $value); |
302 | - if($value === false) { |
|
302 | + if ($value === false) { |
|
303 | 303 | $value = ''; |
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - if(!is_array($value)) { |
|
307 | + if (!is_array($value)) { |
|
308 | 308 | $finalValue = trim($value); |
309 | 309 | } else { |
310 | 310 | $finalValue = []; |
311 | - foreach($value as $key => $val) { |
|
312 | - if(is_string($val)) { |
|
311 | + foreach ($value as $key => $val) { |
|
312 | + if (is_string($val)) { |
|
313 | 313 | $val = trim($val); |
314 | 314 | if ($val !== '') { |
315 | 315 | //accidental line breaks are not wanted and can cause |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | protected function getValue($varName) { |
358 | 358 | static $defaults; |
359 | - if(is_null($defaults)) { |
|
359 | + if (is_null($defaults)) { |
|
360 | 360 | $defaults = $this->getDefaults(); |
361 | 361 | } |
362 | 362 | return \OCP\Config::getAppValue('user_ldap', |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @param mixed $value to set |
372 | 372 | */ |
373 | 373 | protected function setValue($varName, $value) { |
374 | - if(is_string($value)) { |
|
374 | + if (is_string($value)) { |
|
375 | 375 | $value = trim($value); |
376 | 376 | } |
377 | 377 | $this->config[$varName] = $value; |