Skip to content

Commit

Permalink
Adding support for ldapi:/// socket connections to the user_ldap fron…
Browse files Browse the repository at this point in the history
…tend
  • Loading branch information
zenlord committed Dec 6, 2020
1 parent 7a22cc0 commit 2cde33e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 65 deletions.
6 changes: 4 additions & 2 deletions apps/user_ldap/js/wizard/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ OCA = OCA || {};
var agent = view.configModel.configuration.ldap_dn;
var pwd = view.configModel.configuration.ldap_agent_password;

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

if(host && port && base && userFilter && loginFilter) {
if((host && port && base && userFilter && loginFilter) ||
(host && base && host.indexOf('ldapi://') > -1 && userFilter && loginFilter)) {
this.configModel.requestConfigurationTest();
} else {
this._updateStatusIndicator(this.STATUS_INCOMPLETE);
Expand Down
142 changes: 79 additions & 63 deletions apps/user_ldap/lib/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @author Tobias Perschon <tobias@perschon.at>
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
* @author Xuanwo <xuanwo@yunify.com>
* @author Vincent Van Houtte <vvh@aplusv.be>
*
* @license AGPL-3.0
*
Expand Down Expand Up @@ -95,7 +96,10 @@ public function __destruct() {
* @throws \Exception
*/
public function countEntries(string $filter, string $type): int {
$reqs = ['ldapHost', 'ldapPort', 'ldapBase'];
$reqs = ['ldapHost', 'ldapBase'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if ($type === 'users') {
$reqs[] = 'ldapUserFilter';
}
Expand Down Expand Up @@ -201,11 +205,11 @@ public function countInBaseDN() {
* @return int|bool
*/
public function countUsersWithAttribute($attr, $existsCheck = false) {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapUserFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand All @@ -226,11 +230,11 @@ public function countUsersWithAttribute($attr, $existsCheck = false) {
* @throws \Exception
*/
public function detectUserDisplayNameAttribute() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapUserFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand Down Expand Up @@ -268,11 +272,11 @@ public function detectUserDisplayNameAttribute() {
* @return WizardResult|bool
*/
public function detectEmailAttribute() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapUserFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand Down Expand Up @@ -315,11 +319,11 @@ public function detectEmailAttribute() {
* @throws \Exception
*/
public function determineAttributes() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapUserFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand All @@ -344,11 +348,11 @@ public function determineAttributes() {
* @throws \Exception
*/
private function getUserAttributes() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapUserFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
$cr = $this->getConnection();
Expand Down Expand Up @@ -400,10 +404,11 @@ public function determineGroupsForUsers() {
* @throws \Exception
*/
private function determineGroups($dbKey, $confKey, $testMemberOf = true) {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
])) {
$reqs = ['ldapHost', 'ldapBase'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
$cr = $this->getConnection();
Expand Down Expand Up @@ -480,10 +485,11 @@ public function fetchGroups($dbKey, $confKey) {
}

public function determineGroupMemberAssoc() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapGroupFilter',
])) {
$reqs = ['ldapHost', 'ldapGroupFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
$attribute = $this->detectGroupMemberAssoc();
Expand All @@ -502,10 +508,11 @@ public function determineGroupMemberAssoc() {
* @throws \Exception
*/
public function determineGroupObjectClasses() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
])) {
$reqs = ['ldapHost', 'ldapBase'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
$cr = $this->getConnection();
Expand All @@ -529,10 +536,11 @@ public function determineGroupObjectClasses() {
* @throws \Exception
*/
public function determineUserObjectClasses() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
])) {
$reqs = ['ldapHost', 'ldapBase'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
$cr = $this->getConnection();
Expand All @@ -559,10 +567,11 @@ public function determineUserObjectClasses() {
* @throws \Exception
*/
public function getGroupFilter() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
])) {
$reqs = ['ldapHost', 'ldapBase'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
//make sure the use display name is set
Expand All @@ -583,10 +592,11 @@ public function getGroupFilter() {
* @throws \Exception
*/
public function getUserListFilter() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
])) {
$reqs = ['ldapHost', 'ldapBase'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}
//make sure the use display name is set
Expand All @@ -609,11 +619,11 @@ public function getUserListFilter() {
* @throws \Exception
*/
public function getUserLoginFilter() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapUserFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand All @@ -632,11 +642,11 @@ public function getUserLoginFilter() {
* @throws \Exception
*/
public function testLoginName($loginName) {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
'ldapBase',
'ldapLoginFilter',
])) {
$reqs = ['ldapHost', 'ldapBase', 'ldapUserFilter'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand Down Expand Up @@ -719,9 +729,11 @@ public function guessPortAndTLS() {
* @return WizardResult|false WizardResult on success, false otherwise
*/
public function guessBaseDN() {
if (!$this->checkRequirements(['ldapHost',
'ldapPort',
])) {
$reqs = ['ldapHost'];
if(substr($this->configuration->ldapHost, 0, strlen('ldapi://')) != 'ldapi://') {
$reqs[] = 'ldapPort';
}
if (!$this->checkRequirements($reqs)) {
return false;
}

Expand Down Expand Up @@ -1318,6 +1330,8 @@ private function getConnection() {
* @return array
*/
private function getDefaultLdapPortSettings() {
// LDAPI unix socket support: why are ports 7389 and 389 duplicated here?
// LDAPI unix socket support: why are tls values wrong here?
static $settings = [
['port' => 7636, 'tls' => false],
['port' => 636, 'tls' => false],
Expand Down Expand Up @@ -1349,6 +1363,8 @@ private function getPortSettingsToTry() {
$portSettings[] = ['port' => $port, 'tls' => true];
}
$portSettings[] = ['port' => $port, 'tls' => false];
} elseif ($port === 0) {
$portSettings[] = ['port' => '', 'tls' => false];
}

//default ports
Expand Down

0 comments on commit 2cde33e

Please sign in to comment.