Skip to content

Commit 3789302

Browse files
committed
# This is a combination of 9 commits.
# This is the 1st commit message: Patch from PR 24574 to view.js Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#2: Patch from PR 24574 to lib/Connection.php Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#3: Patch from PR 24574 to lib/Wizard.php Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#4: Patch from PR 24574 to lib/LDAP.php (manually) Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#5: Added a function usesLdapi() in Configuration.php and referenced that function throughout the PR Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#6: Removed the questions I added in comments - https://github.com/nextcloud/server/pull/24574/files#r825732903 Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#7: Changed the test as requested - https://github.com/nextcloud/server/pull/24574/files#r825726282 Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#8: Changing return type from bool to int Signed-off-by: Vincent Van Houtte <[email protected]> # This is the commit message nextcloud#9: Changing return type of usesLdapi() to bool and adapting references Signed-off-by: Vincent Van Houtte <[email protected]>
1 parent f167fe0 commit 3789302

File tree

5 files changed

+98
-67
lines changed

5 files changed

+98
-67
lines changed

apps/user_ldap/js/wizard/view.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ OCA = OCA || {};
8686
var agent = view.configModel.configuration.ldap_dn;
8787
var pwd = view.configModel.configuration.ldap_agent_password;
8888

89-
if((host && port && base) && ((!agent && !pwd) || (agent && pwd))) {
89+
if(((host && port && base) || (host && base && host.indexOf('ldapi://') > -1 ))
90+
&& ((!agent && !pwd) || (agent && pwd))) {
9091
view.enableTabs();
9192
} else {
9293
view.disableTabs();
@@ -107,7 +108,8 @@ OCA = OCA || {};
107108
var userFilter = this.configModel.configuration.ldap_userlist_filter;
108109
var loginFilter = this.configModel.configuration.ldap_login_filter;
109110

110-
if(host && port && base && userFilter && loginFilter) {
111+
if((host && port && base && userFilter && loginFilter) ||
112+
(host && base && host.indexOf('ldapi://') > -1 && userFilter && loginFilter)) {
111113
this.configModel.requestConfigurationTest();
112114
} else {
113115
this._updateStatusIndicator(this.STATUS_INCOMPLETE);

apps/user_ldap/lib/Configuration.php

+8
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ public function getDefaults(): array {
463463
'ldap_user_avatar_rule' => 'default',
464464
'ldap_ext_storage_home_attribute' => '',
465465
'ldap_matching_rule_in_chain_state' => self::LDAP_SERVER_FEATURE_UNKNOWN,
466+
'uses_ldapi' => 0,
466467
];
467468
}
468469

@@ -559,4 +560,11 @@ public function getAvatarAttributes(): array {
559560
}
560561
return $defaultAttributes;
561562
}
563+
564+
/**
565+
* Returns TRUE if the ldapHost variable starts with 'ldapi://'
566+
*/
567+
public function usesLdapi(): bool {
568+
return (substr($this->config['ldapHost'], 0, strlen('ldapi://')) != 'ldapi://') ? false : true;
569+
}
562570
}

apps/user_ldap/lib/Connection.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @author root <[email protected]>
1919
* @author Victor Dubiniuk <[email protected]>
2020
* @author Xuanwo <[email protected]>
21+
* @author Vincent Van Houtte <[email protected]>
2122
*
2223
* @license AGPL-3.0
2324
*
@@ -454,8 +455,14 @@ private function doCriticalValidation() {
454455
(string)$this->configPrefix .'): ';
455456

456457
//options that shall not be empty
457-
$options = ['ldapHost', 'ldapPort', 'ldapUserDisplayName',
458+
$options = ['ldapHost', 'ldapUserDisplayName',
458459
'ldapGroupDisplayName', 'ldapLoginFilter'];
460+
461+
//ldapPort should not be empty either unless ldapHost is pointing to a socket
462+
if ($this->configuration->usesLdapi() === false) {
463+
$options[] = 'ldapPort';
464+
}
465+
459466
foreach ($options as $key) {
460467
$val = $this->configuration->$key;
461468
if (empty($val)) {

apps/user_ldap/lib/LDAP.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function connect($host, $port) {
7676
if (strpos($host, '://') === false) {
7777
$host = 'ldap://' . $host;
7878
}
79-
if (strpos($host, ':', strpos($host, '://') + 1) === false) {
79+
if (strpos($host, ':', strpos($host, '://') + 1) === false && !empty($port)) {
8080
//ldap_connect ignores port parameter when URLs are passed
8181
$host .= ':' . $port;
8282
}

apps/user_ldap/lib/Wizard.php

+77-63
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* @author Tobias Perschon <[email protected]>
2020
* @author Victor Dubiniuk <[email protected]>
2121
* @author Xuanwo <[email protected]>
22+
* @author Vincent Van Houtte <[email protected]>
2223
*
2324
* @license AGPL-3.0
2425
*
@@ -97,7 +98,10 @@ public function __destruct() {
9798
* @throws \Exception
9899
*/
99100
public function countEntries(string $filter, string $type): int {
100-
$reqs = ['ldapHost', 'ldapPort', 'ldapBase'];
101+
$reqs = ['ldapHost', 'ldapBase'];
102+
if ($this->configuration->usesLdapi() === false) {
103+
$reqs[] = 'ldapPort';
104+
}
101105
if ($type === 'users') {
102106
$reqs[] = 'ldapUserFilter';
103107
}
@@ -196,11 +200,11 @@ public function countInBaseDN() {
196200
* @return int|bool
197201
*/
198202
public function countUsersWithAttribute($attr, $existsCheck = false) {
199-
if (!$this->checkRequirements(['ldapHost',
200-
'ldapPort',
201-
'ldapBase',
202-
'ldapUserFilter',
203-
])) {
203+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
204+
if ($this->configuration->usesLdapi() === false) {
205+
$reqs[] = 'ldapPort';
206+
}
207+
if (!$this->checkRequirements($reqs)) {
204208
return false;
205209
}
206210

@@ -221,11 +225,11 @@ public function countUsersWithAttribute($attr, $existsCheck = false) {
221225
* @throws \Exception
222226
*/
223227
public function detectUserDisplayNameAttribute() {
224-
if (!$this->checkRequirements(['ldapHost',
225-
'ldapPort',
226-
'ldapBase',
227-
'ldapUserFilter',
228-
])) {
228+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
229+
if ($this->configuration->usesLdapi() === false) {
230+
$reqs[] = 'ldapPort';
231+
}
232+
if (!$this->checkRequirements($reqs)) {
229233
return false;
230234
}
231235

@@ -263,11 +267,11 @@ public function detectUserDisplayNameAttribute() {
263267
* @return WizardResult|bool
264268
*/
265269
public function detectEmailAttribute() {
266-
if (!$this->checkRequirements(['ldapHost',
267-
'ldapPort',
268-
'ldapBase',
269-
'ldapUserFilter',
270-
])) {
270+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
271+
if ($this->configuration->usesLdapi() === false) {
272+
$reqs[] = 'ldapPort';
273+
}
274+
if (!$this->checkRequirements($reqs)) {
271275
return false;
272276
}
273277

@@ -312,11 +316,11 @@ public function detectEmailAttribute() {
312316
* @throws \Exception
313317
*/
314318
public function determineAttributes() {
315-
if (!$this->checkRequirements(['ldapHost',
316-
'ldapPort',
317-
'ldapBase',
318-
'ldapUserFilter',
319-
])) {
319+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
320+
if ($this->configuration->usesLdapi() === false) {
321+
$reqs[] = 'ldapPort';
322+
}
323+
if (!$this->checkRequirements($reqs)) {
320324
return false;
321325
}
322326

@@ -341,11 +345,11 @@ public function determineAttributes() {
341345
* @throws \Exception
342346
*/
343347
private function getUserAttributes() {
344-
if (!$this->checkRequirements(['ldapHost',
345-
'ldapPort',
346-
'ldapBase',
347-
'ldapUserFilter',
348-
])) {
348+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
349+
if ($this->configuration->usesLdapi() === false) {
350+
$reqs[] = 'ldapPort';
351+
}
352+
if (!$this->checkRequirements($reqs)) {
349353
return false;
350354
}
351355
$cr = $this->getConnection();
@@ -397,10 +401,11 @@ public function determineGroupsForUsers() {
397401
* @throws \Exception
398402
*/
399403
private function determineGroups($dbKey, $confKey, $testMemberOf = true) {
400-
if (!$this->checkRequirements(['ldapHost',
401-
'ldapPort',
402-
'ldapBase',
403-
])) {
404+
$reqs = ['ldapHost', 'ldapBase'];
405+
if ($this->configuration->usesLdapi() === false) {
406+
$reqs[] = 'ldapPort';
407+
}
408+
if (!$this->checkRequirements($reqs)) {
404409
return false;
405410
}
406411
$cr = $this->getConnection();
@@ -477,10 +482,11 @@ public function fetchGroups($dbKey, $confKey) {
477482
}
478483

479484
public function determineGroupMemberAssoc() {
480-
if (!$this->checkRequirements(['ldapHost',
481-
'ldapPort',
482-
'ldapGroupFilter',
483-
])) {
485+
$reqs = ['ldapHost', 'ldapGroupFilter'];
486+
if ($this->configuration->usesLdapi() === false) {
487+
$reqs[] = 'ldapPort';
488+
}
489+
if (!$this->checkRequirements($reqs)) {
484490
return false;
485491
}
486492
$attribute = $this->detectGroupMemberAssoc();
@@ -499,10 +505,11 @@ public function determineGroupMemberAssoc() {
499505
* @throws \Exception
500506
*/
501507
public function determineGroupObjectClasses() {
502-
if (!$this->checkRequirements(['ldapHost',
503-
'ldapPort',
504-
'ldapBase',
505-
])) {
508+
$reqs = ['ldapHost', 'ldapBase'];
509+
if ($this->configuration->usesLdapi() === false) {
510+
$reqs[] = 'ldapPort';
511+
}
512+
if (!$this->checkRequirements($reqs)) {
506513
return false;
507514
}
508515
$cr = $this->getConnection();
@@ -526,10 +533,11 @@ public function determineGroupObjectClasses() {
526533
* @throws \Exception
527534
*/
528535
public function determineUserObjectClasses() {
529-
if (!$this->checkRequirements(['ldapHost',
530-
'ldapPort',
531-
'ldapBase',
532-
])) {
536+
$reqs = ['ldapHost', 'ldapBase'];
537+
if ($this->configuration->usesLdapi() === false) {
538+
$reqs[] = 'ldapPort';
539+
}
540+
if (!$this->checkRequirements($reqs)) {
533541
return false;
534542
}
535543
$cr = $this->getConnection();
@@ -556,10 +564,11 @@ public function determineUserObjectClasses() {
556564
* @throws \Exception
557565
*/
558566
public function getGroupFilter() {
559-
if (!$this->checkRequirements(['ldapHost',
560-
'ldapPort',
561-
'ldapBase',
562-
])) {
567+
$reqs = ['ldapHost', 'ldapBase'];
568+
if ($this->configuration->usesLdapi() === false) {
569+
$reqs[] = 'ldapPort';
570+
}
571+
if (!$this->checkRequirements($reqs)) {
563572
return false;
564573
}
565574
//make sure the use display name is set
@@ -580,10 +589,11 @@ public function getGroupFilter() {
580589
* @throws \Exception
581590
*/
582591
public function getUserListFilter() {
583-
if (!$this->checkRequirements(['ldapHost',
584-
'ldapPort',
585-
'ldapBase',
586-
])) {
592+
$reqs = ['ldapHost', 'ldapBase'];
593+
if ($this->configuration->usesLdapi() === false) {
594+
$reqs[] = 'ldapPort';
595+
}
596+
if (!$this->checkRequirements($reqs)) {
587597
return false;
588598
}
589599
//make sure the use display name is set
@@ -606,11 +616,11 @@ public function getUserListFilter() {
606616
* @throws \Exception
607617
*/
608618
public function getUserLoginFilter() {
609-
if (!$this->checkRequirements(['ldapHost',
610-
'ldapPort',
611-
'ldapBase',
612-
'ldapUserFilter',
613-
])) {
619+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
620+
if ($this->configuration->usesLdapi() === false) {
621+
$reqs[] = 'ldapPort';
622+
}
623+
if (!$this->checkRequirements($reqs)) {
614624
return false;
615625
}
616626

@@ -629,11 +639,11 @@ public function getUserLoginFilter() {
629639
* @throws \Exception
630640
*/
631641
public function testLoginName($loginName) {
632-
if (!$this->checkRequirements(['ldapHost',
633-
'ldapPort',
634-
'ldapBase',
635-
'ldapLoginFilter',
636-
])) {
642+
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
643+
if ($this->configuration->usesLdapi() === false) {
644+
$reqs[] = 'ldapPort';
645+
}
646+
if (!$this->checkRequirements($reqs)) {
637647
return false;
638648
}
639649

@@ -722,9 +732,11 @@ public function guessPortAndTLS() {
722732
* @return WizardResult|false WizardResult on success, false otherwise
723733
*/
724734
public function guessBaseDN() {
725-
if (!$this->checkRequirements(['ldapHost',
726-
'ldapPort',
727-
])) {
735+
$reqs = ['ldapHost'];
736+
if ($this->configuration->usesLdapi() === false) {
737+
$reqs[] = 'ldapPort';
738+
}
739+
if (!$this->checkRequirements($reqs)) {
728740
return false;
729741
}
730742

@@ -1366,6 +1378,8 @@ private function getPortSettingsToTry() {
13661378
$portSettings[] = ['port' => $port, 'tls' => true];
13671379
}
13681380
$portSettings[] = ['port' => $port, 'tls' => false];
1381+
} elseif ($this->configuration->usesLdapi()) {
1382+
$portSettings[] = ['port' => '', 'tls' => false];
13691383
}
13701384

13711385
//default ports

0 commit comments

Comments
 (0)