Completed
Pull Request — master (#4060)
by Georg
11:09
created
apps/user_ldap/lib/Command/ShowRemnants.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -35,61 +35,61 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Command/CreateEmptyConfig.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -33,39 +33,39 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Command/ShowConfig.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -35,77 +35,77 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Configuration.php 1 patch
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -36,486 +36,486 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAPUtility.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@
 block discarded – undo
26 26
 namespace OCA\User_LDAP;
27 27
 
28 28
 abstract class LDAPUtility {
29
-	protected $ldap;
29
+    protected $ldap;
30 30
 
31
-	/**
32
-	 * constructor, make sure the subclasses call this one!
33
-	 * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper
34
-	 */
35
-	public function __construct(ILDAPWrapper $ldapWrapper) {
36
-		$this->ldap = $ldapWrapper;
37
-	}
31
+    /**
32
+     * constructor, make sure the subclasses call this one!
33
+     * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper
34
+     */
35
+    public function __construct(ILDAPWrapper $ldapWrapper) {
36
+        $this->ldap = $ldapWrapper;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Settings/Section.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -28,55 +28,55 @@
 block discarded – undo
28 28
 use OCP\Settings\IIconSection;
29 29
 
30 30
 class Section implements IIconSection {
31
-	/** @var IL10N */
32
-	private $l;
33
-	/** @var IURLGenerator */
34
-	private $url;
31
+    /** @var IL10N */
32
+    private $l;
33
+    /** @var IURLGenerator */
34
+    private $url;
35 35
 
36
-	/**
37
-	 * @param IURLGenerator $url
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IURLGenerator $url, IL10N $l) {
41
-		$this->url = $url;
42
-		$this->l = $l;
43
-	}
36
+    /**
37
+     * @param IURLGenerator $url
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IURLGenerator $url, IL10N $l) {
41
+        $this->url = $url;
42
+        $this->l = $l;
43
+    }
44 44
 
45
-	/**
46
-	 * returns the ID of the section. It is supposed to be a lower case string,
47
-	 * e.g. 'ldap'
48
-	 *
49
-	 * @returns string
50
-	 */
51
-	public function getID() {
52
-		return 'ldap';
53
-	}
45
+    /**
46
+     * returns the ID of the section. It is supposed to be a lower case string,
47
+     * e.g. 'ldap'
48
+     *
49
+     * @returns string
50
+     */
51
+    public function getID() {
52
+        return 'ldap';
53
+    }
54 54
 
55
-	/**
56
-	 * returns the translated name as it should be displayed, e.g. 'LDAP / AD
57
-	 * integration'. Use the L10N service to translate it.
58
-	 *
59
-	 * @return string
60
-	 */
61
-	public function getName() {
62
-		return $this->l->t('LDAP / AD integration');
63
-	}
55
+    /**
56
+     * returns the translated name as it should be displayed, e.g. 'LDAP / AD
57
+     * integration'. Use the L10N service to translate it.
58
+     *
59
+     * @return string
60
+     */
61
+    public function getName() {
62
+        return $this->l->t('LDAP / AD integration');
63
+    }
64 64
 
65
-	/**
66
-	 * @return int whether the form should be rather on the top or bottom of
67
-	 * the settings navigation. The sections are arranged in ascending order of
68
-	 * the priority values. It is required to return a value between 0 and 99.
69
-	 *
70
-	 * E.g.: 70
71
-	 */
72
-	public function getPriority() {
73
-		return 25;
74
-	}
65
+    /**
66
+     * @return int whether the form should be rather on the top or bottom of
67
+     * the settings navigation. The sections are arranged in ascending order of
68
+     * the priority values. It is required to return a value between 0 and 99.
69
+     *
70
+     * E.g.: 70
71
+     */
72
+    public function getPriority() {
73
+        return 25;
74
+    }
75 75
 
76
-	/**
77
-	 * {@inheritdoc}
78
-	 */
79
-	public function getIcon() {
80
-		return $this->url->imagePath('user_ldap', 'app-dark.svg');
81
-	}
76
+    /**
77
+     * {@inheritdoc}
78
+     */
79
+    public function getIcon() {
80
+        return $this->url->imagePath('user_ldap', 'app-dark.svg');
81
+    }
82 82
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Settings/Admin.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -31,59 +31,59 @@
 block discarded – undo
31 31
 use OCP\Template;
32 32
 
33 33
 class Admin implements ISettings {
34
-	/** @var IL10N */
35
-	private $l;
34
+    /** @var IL10N */
35
+    private $l;
36 36
 
37
-	/**
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IL10N $l) {
41
-		$this->l = $l;
42
-	}
37
+    /**
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IL10N $l) {
41
+        $this->l = $l;
42
+    }
43 43
 
44
-	/**
45
-	 * @return TemplateResponse
46
-	 */
47
-	public function getForm() {
48
-		$helper = new Helper(\OC::$server->getConfig());
49
-		$prefixes = $helper->getServerConfigurationPrefixes();
50
-		$hosts = $helper->getServerConfigurationHosts();
44
+    /**
45
+     * @return TemplateResponse
46
+     */
47
+    public function getForm() {
48
+        $helper = new Helper(\OC::$server->getConfig());
49
+        $prefixes = $helper->getServerConfigurationPrefixes();
50
+        $hosts = $helper->getServerConfigurationHosts();
51 51
 
52
-		$wControls = new Template('user_ldap', 'part.wizardcontrols');
53
-		$wControls = $wControls->fetchPage();
54
-		$sControls = new Template('user_ldap', 'part.settingcontrols');
55
-		$sControls = $sControls->fetchPage();
52
+        $wControls = new Template('user_ldap', 'part.wizardcontrols');
53
+        $wControls = $wControls->fetchPage();
54
+        $sControls = new Template('user_ldap', 'part.settingcontrols');
55
+        $sControls = $sControls->fetchPage();
56 56
 
57
-		$parameters['serverConfigurationPrefixes'] = $prefixes;
58
-		$parameters['serverConfigurationHosts'] = $hosts;
59
-		$parameters['settingControls'] = $sControls;
60
-		$parameters['wizardControls'] = $wControls;
57
+        $parameters['serverConfigurationPrefixes'] = $prefixes;
58
+        $parameters['serverConfigurationHosts'] = $hosts;
59
+        $parameters['settingControls'] = $sControls;
60
+        $parameters['wizardControls'] = $wControls;
61 61
 
62
-		// assign default values
63
-		$config = new Configuration('', false);
64
-		$defaults = $config->getDefaults();
65
-		foreach($defaults as $key => $default) {
66
-			$parameters[$key.'_default'] = $default;
67
-		}
62
+        // assign default values
63
+        $config = new Configuration('', false);
64
+        $defaults = $config->getDefaults();
65
+        foreach($defaults as $key => $default) {
66
+            $parameters[$key.'_default'] = $default;
67
+        }
68 68
 
69
-		return new TemplateResponse('user_ldap', 'settings', $parameters);
70
-	}
69
+        return new TemplateResponse('user_ldap', 'settings', $parameters);
70
+    }
71 71
 
72
-	/**
73
-	 * @return string the section ID, e.g. 'sharing'
74
-	 */
75
-	public function getSection() {
76
-		return 'ldap';
77
-	}
72
+    /**
73
+     * @return string the section ID, e.g. 'sharing'
74
+     */
75
+    public function getSection() {
76
+        return 'ldap';
77
+    }
78 78
 
79
-	/**
80
-	 * @return int whether the form should be rather on the top or bottom of
81
-	 * the admin section. The forms are arranged in ascending order of the
82
-	 * priority values. It is required to return a value between 0 and 100.
83
-	 *
84
-	 * E.g.: 70
85
-	 */
86
-	public function getPriority() {
87
-		return 5;
88
-	}
79
+    /**
80
+     * @return int whether the form should be rather on the top or bottom of
81
+     * the admin section. The forms are arranged in ascending order of the
82
+     * priority values. It is required to return a value between 0 and 100.
83
+     *
84
+     * E.g.: 70
85
+     */
86
+    public function getPriority() {
87
+        return 5;
88
+    }
89 89
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_Proxy.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -33,285 +33,285 @@
 block discarded – undo
33 33
 use OCP\IConfig;
34 34
 
35 35
 class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
36
-	private $backends = array();
37
-	private $refBackend = null;
36
+    private $backends = array();
37
+    private $refBackend = null;
38 38
 
39
-	/**
40
-	 * Constructor
41
-	 * @param array $serverConfigPrefixes array containing the config Prefixes
42
-	 */
43
-	public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) {
44
-		parent::__construct($ldap);
45
-		foreach($serverConfigPrefixes as $configPrefix) {
46
-			$this->backends[$configPrefix] =
47
-				new User_LDAP($this->getAccess($configPrefix), $ocConfig);
48
-			if(is_null($this->refBackend)) {
49
-				$this->refBackend = &$this->backends[$configPrefix];
50
-			}
51
-		}
52
-	}
39
+    /**
40
+     * Constructor
41
+     * @param array $serverConfigPrefixes array containing the config Prefixes
42
+     */
43
+    public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) {
44
+        parent::__construct($ldap);
45
+        foreach($serverConfigPrefixes as $configPrefix) {
46
+            $this->backends[$configPrefix] =
47
+                new User_LDAP($this->getAccess($configPrefix), $ocConfig);
48
+            if(is_null($this->refBackend)) {
49
+                $this->refBackend = &$this->backends[$configPrefix];
50
+            }
51
+        }
52
+    }
53 53
 
54
-	/**
55
-	 * Tries the backends one after the other until a positive result is returned from the specified method
56
-	 * @param string $uid the uid connected to the request
57
-	 * @param string $method the method of the user backend that shall be called
58
-	 * @param array $parameters an array of parameters to be passed
59
-	 * @return mixed the result of the method or false
60
-	 */
61
-	protected function walkBackends($uid, $method, $parameters) {
62
-		$cacheKey = $this->getUserCacheKey($uid);
63
-		foreach($this->backends as $configPrefix => $backend) {
64
-			$instance = $backend;
65
-			if(!method_exists($instance, $method)
66
-				&& method_exists($this->getAccess($configPrefix), $method)) {
67
-				$instance = $this->getAccess($configPrefix);
68
-			}
69
-			if($result = call_user_func_array(array($instance, $method), $parameters)) {
70
-				$this->writeToCache($cacheKey, $configPrefix);
71
-				return $result;
72
-			}
73
-		}
74
-		return false;
75
-	}
54
+    /**
55
+     * Tries the backends one after the other until a positive result is returned from the specified method
56
+     * @param string $uid the uid connected to the request
57
+     * @param string $method the method of the user backend that shall be called
58
+     * @param array $parameters an array of parameters to be passed
59
+     * @return mixed the result of the method or false
60
+     */
61
+    protected function walkBackends($uid, $method, $parameters) {
62
+        $cacheKey = $this->getUserCacheKey($uid);
63
+        foreach($this->backends as $configPrefix => $backend) {
64
+            $instance = $backend;
65
+            if(!method_exists($instance, $method)
66
+                && method_exists($this->getAccess($configPrefix), $method)) {
67
+                $instance = $this->getAccess($configPrefix);
68
+            }
69
+            if($result = call_user_func_array(array($instance, $method), $parameters)) {
70
+                $this->writeToCache($cacheKey, $configPrefix);
71
+                return $result;
72
+            }
73
+        }
74
+        return false;
75
+    }
76 76
 
77
-	/**
78
-	 * Asks the backend connected to the server that supposely takes care of the uid from the request.
79
-	 * @param string $uid the uid connected to the request
80
-	 * @param string $method the method of the user backend that shall be called
81
-	 * @param array $parameters an array of parameters to be passed
82
-	 * @param mixed $passOnWhen the result matches this variable
83
-	 * @return mixed the result of the method or false
84
-	 */
85
-	protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) {
86
-		$cacheKey = $this->getUserCacheKey($uid);
87
-		$prefix = $this->getFromCache($cacheKey);
88
-		//in case the uid has been found in the past, try this stored connection first
89
-		if(!is_null($prefix)) {
90
-			if(isset($this->backends[$prefix])) {
91
-				$instance = $this->backends[$prefix];
92
-				if(!method_exists($instance, $method)
93
-					&& method_exists($this->getAccess($prefix), $method)) {
94
-					$instance = $this->getAccess($prefix);
95
-				}
96
-				$result = call_user_func_array(array($instance, $method), $parameters);
97
-				if($result === $passOnWhen) {
98
-					//not found here, reset cache to null if user vanished
99
-					//because sometimes methods return false with a reason
100
-					$userExists = call_user_func_array(
101
-						array($this->backends[$prefix], 'userExists'),
102
-						array($uid)
103
-					);
104
-					if(!$userExists) {
105
-						$this->writeToCache($cacheKey, null);
106
-					}
107
-				}
108
-				return $result;
109
-			}
110
-		}
111
-		return false;
112
-	}
77
+    /**
78
+     * Asks the backend connected to the server that supposely takes care of the uid from the request.
79
+     * @param string $uid the uid connected to the request
80
+     * @param string $method the method of the user backend that shall be called
81
+     * @param array $parameters an array of parameters to be passed
82
+     * @param mixed $passOnWhen the result matches this variable
83
+     * @return mixed the result of the method or false
84
+     */
85
+    protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) {
86
+        $cacheKey = $this->getUserCacheKey($uid);
87
+        $prefix = $this->getFromCache($cacheKey);
88
+        //in case the uid has been found in the past, try this stored connection first
89
+        if(!is_null($prefix)) {
90
+            if(isset($this->backends[$prefix])) {
91
+                $instance = $this->backends[$prefix];
92
+                if(!method_exists($instance, $method)
93
+                    && method_exists($this->getAccess($prefix), $method)) {
94
+                    $instance = $this->getAccess($prefix);
95
+                }
96
+                $result = call_user_func_array(array($instance, $method), $parameters);
97
+                if($result === $passOnWhen) {
98
+                    //not found here, reset cache to null if user vanished
99
+                    //because sometimes methods return false with a reason
100
+                    $userExists = call_user_func_array(
101
+                        array($this->backends[$prefix], 'userExists'),
102
+                        array($uid)
103
+                    );
104
+                    if(!$userExists) {
105
+                        $this->writeToCache($cacheKey, null);
106
+                    }
107
+                }
108
+                return $result;
109
+            }
110
+        }
111
+        return false;
112
+    }
113 113
 
114
-	/**
115
-	 * Check if backend implements actions
116
-	 * @param int $actions bitwise-or'ed actions
117
-	 * @return boolean
118
-	 *
119
-	 * Returns the supported actions as int to be
120
-	 * compared with OC_USER_BACKEND_CREATE_USER etc.
121
-	 */
122
-	public function implementsActions($actions) {
123
-		//it's the same across all our user backends obviously
124
-		return $this->refBackend->implementsActions($actions);
125
-	}
114
+    /**
115
+     * Check if backend implements actions
116
+     * @param int $actions bitwise-or'ed actions
117
+     * @return boolean
118
+     *
119
+     * Returns the supported actions as int to be
120
+     * compared with OC_USER_BACKEND_CREATE_USER etc.
121
+     */
122
+    public function implementsActions($actions) {
123
+        //it's the same across all our user backends obviously
124
+        return $this->refBackend->implementsActions($actions);
125
+    }
126 126
 
127
-	/**
128
-	 * Backend name to be shown in user management
129
-	 * @return string the name of the backend to be shown
130
-	 */
131
-	public function getBackendName() {
132
-		return $this->refBackend->getBackendName();
133
-	}
127
+    /**
128
+     * Backend name to be shown in user management
129
+     * @return string the name of the backend to be shown
130
+     */
131
+    public function getBackendName() {
132
+        return $this->refBackend->getBackendName();
133
+    }
134 134
 
135
-	/**
136
-	 * Get a list of all users
137
-	 *
138
-	 * @param string $search
139
-	 * @param null|int $limit
140
-	 * @param null|int $offset
141
-	 * @return string[] an array of all uids
142
-	 */
143
-	public function getUsers($search = '', $limit = 10, $offset = 0) {
144
-		//we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
145
-		$users = array();
146
-		foreach($this->backends as $backend) {
147
-			$backendUsers = $backend->getUsers($search, $limit, $offset);
148
-			if (is_array($backendUsers)) {
149
-				$users = array_merge($users, $backendUsers);
150
-			}
151
-		}
152
-		return $users;
153
-	}
135
+    /**
136
+     * Get a list of all users
137
+     *
138
+     * @param string $search
139
+     * @param null|int $limit
140
+     * @param null|int $offset
141
+     * @return string[] an array of all uids
142
+     */
143
+    public function getUsers($search = '', $limit = 10, $offset = 0) {
144
+        //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
145
+        $users = array();
146
+        foreach($this->backends as $backend) {
147
+            $backendUsers = $backend->getUsers($search, $limit, $offset);
148
+            if (is_array($backendUsers)) {
149
+                $users = array_merge($users, $backendUsers);
150
+            }
151
+        }
152
+        return $users;
153
+    }
154 154
 
155
-	/**
156
-	 * check if a user exists
157
-	 * @param string $uid the username
158
-	 * @return boolean
159
-	 */
160
-	public function userExists($uid) {
161
-		return $this->handleRequest($uid, 'userExists', array($uid));
162
-	}
155
+    /**
156
+     * check if a user exists
157
+     * @param string $uid the username
158
+     * @return boolean
159
+     */
160
+    public function userExists($uid) {
161
+        return $this->handleRequest($uid, 'userExists', array($uid));
162
+    }
163 163
 
164
-	/**
165
-	 * check if a user exists on LDAP
166
-	 * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user
167
-	 * name or an instance of that user
168
-	 * @return boolean
169
-	 */
170
-	public function userExistsOnLDAP($user) {
171
-		$id = ($user instanceof User) ? $user->getUsername() : $user;
172
-		return $this->handleRequest($id, 'userExistsOnLDAP', array($user));
173
-	}
164
+    /**
165
+     * check if a user exists on LDAP
166
+     * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user
167
+     * name or an instance of that user
168
+     * @return boolean
169
+     */
170
+    public function userExistsOnLDAP($user) {
171
+        $id = ($user instanceof User) ? $user->getUsername() : $user;
172
+        return $this->handleRequest($id, 'userExistsOnLDAP', array($user));
173
+    }
174 174
 
175
-	/**
176
-	 * Check if the password is correct
177
-	 * @param string $uid The username
178
-	 * @param string $password The password
179
-	 * @return bool
180
-	 *
181
-	 * Check if the password is correct without logging in the user
182
-	 */
183
-	public function checkPassword($uid, $password) {
184
-		return $this->handleRequest($uid, 'checkPassword', array($uid, $password));
185
-	}
175
+    /**
176
+     * Check if the password is correct
177
+     * @param string $uid The username
178
+     * @param string $password The password
179
+     * @return bool
180
+     *
181
+     * Check if the password is correct without logging in the user
182
+     */
183
+    public function checkPassword($uid, $password) {
184
+        return $this->handleRequest($uid, 'checkPassword', array($uid, $password));
185
+    }
186 186
 
187
-	/**
188
-	 * returns the username for the given login name, if available
189
-	 *
190
-	 * @param string $loginName
191
-	 * @return string|false
192
-	 */
193
-	public function loginName2UserName($loginName) {
194
-		$id = 'LOGINNAME,' . $loginName;
195
-		return $this->handleRequest($id, 'loginName2UserName', array($loginName));
196
-	}
187
+    /**
188
+     * returns the username for the given login name, if available
189
+     *
190
+     * @param string $loginName
191
+     * @return string|false
192
+     */
193
+    public function loginName2UserName($loginName) {
194
+        $id = 'LOGINNAME,' . $loginName;
195
+        return $this->handleRequest($id, 'loginName2UserName', array($loginName));
196
+    }
197 197
 	
198
-	/**
199
-	 * returns the username for the given LDAP DN, if available
200
-	 *
201
-	 * @param string $dn
202
-	 * @return string|false with the username
203
-	 */
204
-	public function dn2UserName($dn) {
205
-		$id = 'DN,' . $dn;
206
-		return $this->handleRequest($id, 'dn2UserName', array($dn));
207
-	}
198
+    /**
199
+     * returns the username for the given LDAP DN, if available
200
+     *
201
+     * @param string $dn
202
+     * @return string|false with the username
203
+     */
204
+    public function dn2UserName($dn) {
205
+        $id = 'DN,' . $dn;
206
+        return $this->handleRequest($id, 'dn2UserName', array($dn));
207
+    }
208 208
 
209
-	/**
210
-	 * get the user's home directory
211
-	 * @param string $uid the username
212
-	 * @return boolean
213
-	 */
214
-	public function getHome($uid) {
215
-		return $this->handleRequest($uid, 'getHome', array($uid));
216
-	}
209
+    /**
210
+     * get the user's home directory
211
+     * @param string $uid the username
212
+     * @return boolean
213
+     */
214
+    public function getHome($uid) {
215
+        return $this->handleRequest($uid, 'getHome', array($uid));
216
+    }
217 217
 
218
-	/**
219
-	 * get display name of the user
220
-	 * @param string $uid user ID of the user
221
-	 * @return string display name
222
-	 */
223
-	public function getDisplayName($uid) {
224
-		return $this->handleRequest($uid, 'getDisplayName', array($uid));
225
-	}
218
+    /**
219
+     * get display name of the user
220
+     * @param string $uid user ID of the user
221
+     * @return string display name
222
+     */
223
+    public function getDisplayName($uid) {
224
+        return $this->handleRequest($uid, 'getDisplayName', array($uid));
225
+    }
226 226
 
227
-	/**
228
-	 * checks whether the user is allowed to change his avatar in ownCloud
229
-	 * @param string $uid the ownCloud user name
230
-	 * @return boolean either the user can or cannot
231
-	 */
232
-	public function canChangeAvatar($uid) {
233
-		return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true);
234
-	}
227
+    /**
228
+     * checks whether the user is allowed to change his avatar in ownCloud
229
+     * @param string $uid the ownCloud user name
230
+     * @return boolean either the user can or cannot
231
+     */
232
+    public function canChangeAvatar($uid) {
233
+        return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true);
234
+    }
235 235
 
236
-	/**
237
-	 * Get a list of all display names and user ids.
238
-	 * @param string $search
239
-	 * @param string|null $limit
240
-	 * @param string|null $offset
241
-	 * @return array an array of all displayNames (value) and the corresponding uids (key)
242
-	 */
243
-	public function getDisplayNames($search = '', $limit = null, $offset = null) {
244
-		//we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
245
-		$users = array();
246
-		foreach($this->backends as $backend) {
247
-			$backendUsers = $backend->getDisplayNames($search, $limit, $offset);
248
-			if (is_array($backendUsers)) {
249
-				$users = $users + $backendUsers;
250
-			}
251
-		}
252
-		return $users;
253
-	}
236
+    /**
237
+     * Get a list of all display names and user ids.
238
+     * @param string $search
239
+     * @param string|null $limit
240
+     * @param string|null $offset
241
+     * @return array an array of all displayNames (value) and the corresponding uids (key)
242
+     */
243
+    public function getDisplayNames($search = '', $limit = null, $offset = null) {
244
+        //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
245
+        $users = array();
246
+        foreach($this->backends as $backend) {
247
+            $backendUsers = $backend->getDisplayNames($search, $limit, $offset);
248
+            if (is_array($backendUsers)) {
249
+                $users = $users + $backendUsers;
250
+            }
251
+        }
252
+        return $users;
253
+    }
254 254
 
255
-	/**
256
-	 * delete a user
257
-	 * @param string $uid The username of the user to delete
258
-	 * @return bool
259
-	 *
260
-	 * Deletes a user
261
-	 */
262
-	public function deleteUser($uid) {
263
-		return $this->handleRequest($uid, 'deleteUser', array($uid));
264
-	}
255
+    /**
256
+     * delete a user
257
+     * @param string $uid The username of the user to delete
258
+     * @return bool
259
+     *
260
+     * Deletes a user
261
+     */
262
+    public function deleteUser($uid) {
263
+        return $this->handleRequest($uid, 'deleteUser', array($uid));
264
+    }
265 265
 	
266
-	/**
267
-	 * Set password
268
-	 * @param string $uid The username
269
-	 * @param string $password The new password
270
-	 * @return bool
271
-	 *
272
-	 */
273
-	public function setPassword($uid, $password) {
274
-		return $this->handleRequest($uid, 'setPassword', array($uid, $password));
275
-	}
266
+    /**
267
+     * Set password
268
+     * @param string $uid The username
269
+     * @param string $password The new password
270
+     * @return bool
271
+     *
272
+     */
273
+    public function setPassword($uid, $password) {
274
+        return $this->handleRequest($uid, 'setPassword', array($uid, $password));
275
+    }
276 276
 
277
-	/**
278
-	 * @return bool
279
-	 */
280
-	public function hasUserListings() {
281
-		return $this->refBackend->hasUserListings();
282
-	}
277
+    /**
278
+     * @return bool
279
+     */
280
+    public function hasUserListings() {
281
+        return $this->refBackend->hasUserListings();
282
+    }
283 283
 
284
-	/**
285
-	 * Count the number of users
286
-	 * @return int|bool
287
-	 */
288
-	public function countUsers() {
289
-		$users = false;
290
-		foreach($this->backends as $backend) {
291
-			$backendUsers = $backend->countUsers();
292
-			if ($backendUsers !== false) {
293
-				$users += $backendUsers;
294
-			}
295
-		}
296
-		return $users;
297
-	}
284
+    /**
285
+     * Count the number of users
286
+     * @return int|bool
287
+     */
288
+    public function countUsers() {
289
+        $users = false;
290
+        foreach($this->backends as $backend) {
291
+            $backendUsers = $backend->countUsers();
292
+            if ($backendUsers !== false) {
293
+                $users += $backendUsers;
294
+            }
295
+        }
296
+        return $users;
297
+    }
298 298
 
299
-	/**
300
-	 * Return access for LDAP interaction.
301
-	 * @param string $uid
302
-	 * @return Access instance of Access for LDAP interaction
303
-	 */
304
-	public function getLDAPAccess($uid) {
305
-		return $this->handleRequest($uid, 'getLDAPAccess', array($uid));
306
-	}
299
+    /**
300
+     * Return access for LDAP interaction.
301
+     * @param string $uid
302
+     * @return Access instance of Access for LDAP interaction
303
+     */
304
+    public function getLDAPAccess($uid) {
305
+        return $this->handleRequest($uid, 'getLDAPAccess', array($uid));
306
+    }
307 307
 	
308
-	/**
309
-	 * Return a new LDAP connection for the specified user.
310
-	 * The connection needs to be closed manually.
311
-	 * @param string $uid
312
-	 * @return resource of the LDAP connection
313
-	 */
314
-	public function getNewLDAPConnection($uid) {
315
-		return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid));
316
-	}
308
+    /**
309
+     * Return a new LDAP connection for the specified user.
310
+     * The connection needs to be closed manually.
311
+     * @param string $uid
312
+     * @return resource of the LDAP connection
313
+     */
314
+    public function getNewLDAPConnection($uid) {
315
+        return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid));
316
+    }
317 317
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Connection.php 1 patch
Indentation   +564 added lines, -564 removed lines patch added patch discarded remove patch
@@ -51,569 +51,569 @@
 block discarded – undo
51 51
  * @property string ldapUuidGroupAttribute
52 52
  */
53 53
 class Connection extends LDAPUtility {
54
-	private $ldapConnectionRes = null;
55
-	private $configPrefix;
56
-	private $configID;
57
-	private $configured = false;
58
-	private $hasPagedResultSupport = true;
59
-	//whether connection should be kept on __destruct
60
-	private $dontDestruct = false;
61
-
62
-	/**
63
-	 * @var bool runtime flag that indicates whether supported primary groups are available
64
-	 */
65
-	public $hasPrimaryGroups = true;
66
-
67
-	//cache handler
68
-	protected $cache;
69
-
70
-	/** @var Configuration settings handler **/
71
-	protected $configuration;
72
-
73
-	protected $doNotValidate = false;
74
-
75
-	protected $ignoreValidation = false;
76
-
77
-	/**
78
-	 * Constructor
79
-	 * @param ILDAPWrapper $ldap
80
-	 * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
81
-	 * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
82
-	 */
83
-	public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
84
-		parent::__construct($ldap);
85
-		$this->configPrefix = $configPrefix;
86
-		$this->configID = $configID;
87
-		$this->configuration = new Configuration($configPrefix,
88
-												 !is_null($configID));
89
-		$memcache = \OC::$server->getMemCacheFactory();
90
-		if($memcache->isAvailable()) {
91
-			$this->cache = $memcache->create();
92
-		}
93
-		$helper = new Helper(\OC::$server->getConfig());
94
-		$this->doNotValidate = !in_array($this->configPrefix,
95
-			$helper->getServerConfigurationPrefixes());
96
-		$this->hasPagedResultSupport =
97
-			intval($this->configuration->ldapPagingSize) !== 0
98
-			|| $this->ldap->hasPagedResultSupport();
99
-	}
100
-
101
-	public function __destruct() {
102
-		if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
103
-			@$this->ldap->unbind($this->ldapConnectionRes);
104
-		};
105
-	}
106
-
107
-	/**
108
-	 * defines behaviour when the instance is cloned
109
-	 */
110
-	public function __clone() {
111
-		$this->configuration = new Configuration($this->configPrefix,
112
-												 !is_null($this->configID));
113
-		$this->ldapConnectionRes = null;
114
-		$this->dontDestruct = true;
115
-	}
116
-
117
-	/**
118
-	 * @param string $name
119
-	 * @return bool|mixed|void
120
-	 */
121
-	public function __get($name) {
122
-		if(!$this->configured) {
123
-			$this->readConfiguration();
124
-		}
125
-
126
-		if($name === 'hasPagedResultSupport') {
127
-			return $this->hasPagedResultSupport;
128
-		}
129
-
130
-		return $this->configuration->$name;
131
-	}
132
-
133
-	/**
134
-	 * @param string $name
135
-	 * @param mixed $value
136
-	 */
137
-	public function __set($name, $value) {
138
-		$this->doNotValidate = false;
139
-		$before = $this->configuration->$name;
140
-		$this->configuration->$name = $value;
141
-		$after = $this->configuration->$name;
142
-		if($before !== $after) {
143
-			if ($this->configID !== '') {
144
-				$this->configuration->saveConfiguration();
145
-			}
146
-			$this->validateConfiguration();
147
-		}
148
-	}
149
-
150
-	/**
151
-	 * sets whether the result of the configuration validation shall
152
-	 * be ignored when establishing the connection. Used by the Wizard
153
-	 * in early configuration state.
154
-	 * @param bool $state
155
-	 */
156
-	public function setIgnoreValidation($state) {
157
-		$this->ignoreValidation = (bool)$state;
158
-	}
159
-
160
-	/**
161
-	 * initializes the LDAP backend
162
-	 * @param bool $force read the config settings no matter what
163
-	 */
164
-	public function init($force = false) {
165
-		$this->readConfiguration($force);
166
-		$this->establishConnection();
167
-	}
168
-
169
-	/**
170
-	 * Returns the LDAP handler
171
-	 */
172
-	public function getConnectionResource() {
173
-		if(!$this->ldapConnectionRes) {
174
-			$this->init();
175
-		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
176
-			$this->ldapConnectionRes = null;
177
-			$this->establishConnection();
178
-		}
179
-		if(is_null($this->ldapConnectionRes)) {
180
-			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR);
181
-			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
182
-		}
183
-		return $this->ldapConnectionRes;
184
-	}
185
-
186
-	/**
187
-	 * resets the connection resource
188
-	 */
189
-	public function resetConnectionResource() {
190
-		if(!is_null($this->ldapConnectionRes)) {
191
-			@$this->ldap->unbind($this->ldapConnectionRes);
192
-			$this->ldapConnectionRes = null;
193
-		}
194
-	}
195
-
196
-	/**
197
-	 * @param string|null $key
198
-	 * @return string
199
-	 */
200
-	private function getCacheKey($key) {
201
-		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
202
-		if(is_null($key)) {
203
-			return $prefix;
204
-		}
205
-		return $prefix.md5($key);
206
-	}
207
-
208
-	/**
209
-	 * @param string $key
210
-	 * @return mixed|null
211
-	 */
212
-	public function getFromCache($key) {
213
-		if(!$this->configured) {
214
-			$this->readConfiguration();
215
-		}
216
-		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
217
-			return null;
218
-		}
219
-		$key = $this->getCacheKey($key);
220
-
221
-		return json_decode(base64_decode($this->cache->get($key)), true);
222
-	}
223
-
224
-	/**
225
-	 * @param string $key
226
-	 * @param mixed $value
227
-	 *
228
-	 * @return string
229
-	 */
230
-	public function writeToCache($key, $value) {
231
-		if(!$this->configured) {
232
-			$this->readConfiguration();
233
-		}
234
-		if(is_null($this->cache)
235
-			|| !$this->configuration->ldapCacheTTL
236
-			|| !$this->configuration->ldapConfigurationActive) {
237
-			return null;
238
-		}
239
-		$key   = $this->getCacheKey($key);
240
-		$value = base64_encode(json_encode($value));
241
-		$this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
242
-	}
243
-
244
-	public function clearCache() {
245
-		if(!is_null($this->cache)) {
246
-			$this->cache->clear($this->getCacheKey(null));
247
-		}
248
-	}
249
-
250
-	/**
251
-	 * Caches the general LDAP configuration.
252
-	 * @param bool $force optional. true, if the re-read should be forced. defaults
253
-	 * to false.
254
-	 * @return null
255
-	 */
256
-	private function readConfiguration($force = false) {
257
-		if((!$this->configured || $force) && !is_null($this->configID)) {
258
-			$this->configuration->readConfiguration();
259
-			$this->configured = $this->validateConfiguration();
260
-		}
261
-	}
262
-
263
-	/**
264
-	 * set LDAP configuration with values delivered by an array, not read from configuration
265
-	 * @param array $config array that holds the config parameters in an associated array
266
-	 * @param array &$setParameters optional; array where the set fields will be given to
267
-	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
268
-	 */
269
-	public function setConfiguration($config, &$setParameters = null) {
270
-		if(is_null($setParameters)) {
271
-			$setParameters = array();
272
-		}
273
-		$this->doNotValidate = false;
274
-		$this->configuration->setConfiguration($config, $setParameters);
275
-		if(count($setParameters) > 0) {
276
-			$this->configured = $this->validateConfiguration();
277
-		}
278
-
279
-
280
-		return $this->configured;
281
-	}
282
-
283
-	/**
284
-	 * saves the current Configuration in the database and empties the
285
-	 * cache
286
-	 * @return null
287
-	 */
288
-	public function saveConfiguration() {
289
-		$this->configuration->saveConfiguration();
290
-		$this->clearCache();
291
-	}
292
-
293
-	/**
294
-	 * get the current LDAP configuration
295
-	 * @return array
296
-	 */
297
-	public function getConfiguration() {
298
-		$this->readConfiguration();
299
-		$config = $this->configuration->getConfiguration();
300
-		$cta = $this->configuration->getConfigTranslationArray();
301
-		$result = array();
302
-		foreach($cta as $dbkey => $configkey) {
303
-			switch($configkey) {
304
-				case 'homeFolderNamingRule':
305
-					if(strpos($config[$configkey], 'attr:') === 0) {
306
-						$result[$dbkey] = substr($config[$configkey], 5);
307
-					} else {
308
-						$result[$dbkey] = '';
309
-					}
310
-					break;
311
-				case 'ldapBase':
312
-				case 'ldapBaseUsers':
313
-				case 'ldapBaseGroups':
314
-				case 'ldapAttributesForUserSearch':
315
-				case 'ldapAttributesForGroupSearch':
316
-					if(is_array($config[$configkey])) {
317
-						$result[$dbkey] = implode("\n", $config[$configkey]);
318
-						break;
319
-					} //else follows default
320
-				default:
321
-					$result[$dbkey] = $config[$configkey];
322
-			}
323
-		}
324
-		return $result;
325
-	}
326
-
327
-	private function doSoftValidation() {
328
-		//if User or Group Base are not set, take over Base DN setting
329
-		foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
330
-			$val = $this->configuration->$keyBase;
331
-			if(empty($val)) {
332
-				$this->configuration->$keyBase = $this->configuration->ldapBase;
333
-			}
334
-		}
335
-
336
-		foreach(array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
337
-					  'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
338
-				as $expertSetting => $effectiveSetting) {
339
-			$uuidOverride = $this->configuration->$expertSetting;
340
-			if(!empty($uuidOverride)) {
341
-				$this->configuration->$effectiveSetting = $uuidOverride;
342
-			} else {
343
-				$uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid',
344
-										'objectguid', 'guid', 'ipauniqueid');
345
-				if(!in_array($this->configuration->$effectiveSetting,
346
-							$uuidAttributes)
347
-					&& (!is_null($this->configID))) {
348
-					$this->configuration->$effectiveSetting = 'auto';
349
-					$this->configuration->saveConfiguration();
350
-					\OCP\Util::writeLog('user_ldap',
351
-										'Illegal value for the '.
352
-										$effectiveSetting.', '.'reset to '.
353
-										'autodetect.', \OCP\Util::INFO);
354
-				}
355
-
356
-			}
357
-		}
358
-
359
-		$backupPort = intval($this->configuration->ldapBackupPort);
360
-		if ($backupPort <= 0) {
361
-			$this->configuration->backupPort = $this->configuration->ldapPort;
362
-		}
363
-
364
-		//make sure empty search attributes are saved as simple, empty array
365
-		$saKeys = array('ldapAttributesForUserSearch',
366
-						'ldapAttributesForGroupSearch');
367
-		foreach($saKeys as $key) {
368
-			$val = $this->configuration->$key;
369
-			if(is_array($val) && count($val) === 1 && empty($val[0])) {
370
-				$this->configuration->$key = array();
371
-			}
372
-		}
373
-
374
-		if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
375
-			&& $this->configuration->ldapTLS) {
376
-			$this->configuration->ldapTLS = false;
377
-			\OCP\Util::writeLog('user_ldap',
378
-								'LDAPS (already using secure connection) and '.
379
-								'TLS do not work together. Switched off TLS.',
380
-								\OCP\Util::INFO);
381
-		}
382
-	}
383
-
384
-	/**
385
-	 * @return bool
386
-	 */
387
-	private function doCriticalValidation() {
388
-		$configurationOK = true;
389
-		$errorStr = 'Configuration Error (prefix '.
390
-					strval($this->configPrefix).'): ';
391
-
392
-		//options that shall not be empty
393
-		$options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
394
-						 'ldapGroupDisplayName', 'ldapLoginFilter');
395
-		foreach($options as $key) {
396
-			$val = $this->configuration->$key;
397
-			if(empty($val)) {
398
-				switch($key) {
399
-					case 'ldapHost':
400
-						$subj = 'LDAP Host';
401
-						break;
402
-					case 'ldapPort':
403
-						$subj = 'LDAP Port';
404
-						break;
405
-					case 'ldapUserDisplayName':
406
-						$subj = 'LDAP User Display Name';
407
-						break;
408
-					case 'ldapGroupDisplayName':
409
-						$subj = 'LDAP Group Display Name';
410
-						break;
411
-					case 'ldapLoginFilter':
412
-						$subj = 'LDAP Login Filter';
413
-						break;
414
-					default:
415
-						$subj = $key;
416
-						break;
417
-				}
418
-				$configurationOK = false;
419
-				\OCP\Util::writeLog('user_ldap',
420
-									$errorStr.'No '.$subj.' given!',
421
-									\OCP\Util::WARN);
422
-			}
423
-		}
424
-
425
-		//combinations
426
-		$agent = $this->configuration->ldapAgentName;
427
-		$pwd = $this->configuration->ldapAgentPassword;
428
-		if (
429
-			($agent === ''  && $pwd !== '')
430
-			|| ($agent !== '' && $pwd === '')
431
-		) {
432
-			\OCP\Util::writeLog('user_ldap',
433
-								$errorStr.'either no password is given for the'.
434
-								'user agent or a password is given, but not an'.
435
-								'LDAP agent.',
436
-				\OCP\Util::WARN);
437
-			$configurationOK = false;
438
-		}
439
-
440
-		$base = $this->configuration->ldapBase;
441
-		$baseUsers = $this->configuration->ldapBaseUsers;
442
-		$baseGroups = $this->configuration->ldapBaseGroups;
443
-
444
-		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
445
-			\OCP\Util::writeLog('user_ldap',
446
-								$errorStr.'Not a single Base DN given.',
447
-								\OCP\Util::WARN);
448
-			$configurationOK = false;
449
-		}
450
-
451
-		if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
452
-		   === false) {
453
-			\OCP\Util::writeLog('user_ldap',
454
-								$errorStr.'login filter does not contain %uid '.
455
-								'place holder.',
456
-								\OCP\Util::WARN);
457
-			$configurationOK = false;
458
-		}
459
-
460
-		return $configurationOK;
461
-	}
462
-
463
-	/**
464
-	 * Validates the user specified configuration
465
-	 * @return bool true if configuration seems OK, false otherwise
466
-	 */
467
-	private function validateConfiguration() {
468
-
469
-		if($this->doNotValidate) {
470
-			//don't do a validation if it is a new configuration with pure
471
-			//default values. Will be allowed on changes via __set or
472
-			//setConfiguration
473
-			return false;
474
-		}
475
-
476
-		// first step: "soft" checks: settings that are not really
477
-		// necessary, but advisable. If left empty, give an info message
478
-		$this->doSoftValidation();
479
-
480
-		//second step: critical checks. If left empty or filled wrong, mark as
481
-		//not configured and give a warning.
482
-		return $this->doCriticalValidation();
483
-	}
484
-
485
-
486
-	/**
487
-	 * Connects and Binds to LDAP
488
-	 */
489
-	private function establishConnection() {
490
-		if(!$this->configuration->ldapConfigurationActive) {
491
-			return null;
492
-		}
493
-		static $phpLDAPinstalled = true;
494
-		if(!$phpLDAPinstalled) {
495
-			return false;
496
-		}
497
-		if(!$this->ignoreValidation && !$this->configured) {
498
-			\OCP\Util::writeLog('user_ldap',
499
-								'Configuration is invalid, cannot connect',
500
-								\OCP\Util::WARN);
501
-			return false;
502
-		}
503
-		if(!$this->ldapConnectionRes) {
504
-			if(!$this->ldap->areLDAPFunctionsAvailable()) {
505
-				$phpLDAPinstalled = false;
506
-				\OCP\Util::writeLog('user_ldap',
507
-									'function ldap_connect is not available. Make '.
508
-									'sure that the PHP ldap module is installed.',
509
-									\OCP\Util::ERROR);
510
-
511
-				return false;
512
-			}
513
-			if($this->configuration->turnOffCertCheck) {
514
-				if(putenv('LDAPTLS_REQCERT=never')) {
515
-					\OCP\Util::writeLog('user_ldap',
516
-						'Turned off SSL certificate validation successfully.',
517
-						\OCP\Util::DEBUG);
518
-				} else {
519
-					\OCP\Util::writeLog('user_ldap',
520
-										'Could not turn off SSL certificate validation.',
521
-										\OCP\Util::WARN);
522
-				}
523
-			}
524
-
525
-			$bindStatus = false;
526
-			$error = -1;
527
-			try {
528
-				if (!$this->configuration->ldapOverrideMainServer
529
-					&& !$this->getFromCache('overrideMainServer')
530
-				) {
531
-					$this->doConnect($this->configuration->ldapHost,
532
-						$this->configuration->ldapPort);
533
-					$bindStatus = $this->bind();
534
-					$error = $this->ldap->isResource($this->ldapConnectionRes) ?
535
-						$this->ldap->errno($this->ldapConnectionRes) : -1;
536
-				}
537
-				if($bindStatus === true) {
538
-					return $bindStatus;
539
-				}
540
-			} catch (\OC\ServerNotAvailableException $e) {
541
-				if(trim($this->configuration->ldapBackupHost) === "") {
542
-					throw $e;
543
-				}
544
-			}
545
-
546
-			//if LDAP server is not reachable, try the Backup (Replica!) Server
547
-			if(    $error !== 0
548
-				|| $this->configuration->ldapOverrideMainServer
549
-				|| $this->getFromCache('overrideMainServer'))
550
-			{
551
-				$this->doConnect($this->configuration->ldapBackupHost,
552
-								 $this->configuration->ldapBackupPort);
553
-				$bindStatus = $this->bind();
554
-				if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) {
555
-					//when bind to backup server succeeded and failed to main server,
556
-					//skip contacting him until next cache refresh
557
-					$this->writeToCache('overrideMainServer', true);
558
-				}
559
-			}
560
-			return $bindStatus;
561
-		}
562
-		return null;
563
-	}
564
-
565
-	/**
566
-	 * @param string $host
567
-	 * @param string $port
568
-	 * @return bool
569
-	 * @throws \OC\ServerNotAvailableException
570
-	 */
571
-	private function doConnect($host, $port) {
572
-		if ($host === '') {
573
-			return false;
574
-		}
575
-		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
576
-		if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
577
-			if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
578
-				if($this->configuration->ldapTLS) {
579
-					$this->ldap->startTls($this->ldapConnectionRes);
580
-				}
581
-			}
582
-		} else {
583
-			throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.');
584
-		}
585
-		return true;
586
-	}
587
-
588
-	/**
589
-	 * Binds to LDAP
590
-	 */
591
-	public function bind() {
592
-		static $getConnectionResourceAttempt = false;
593
-		if(!$this->configuration->ldapConfigurationActive) {
594
-			return false;
595
-		}
596
-		if($getConnectionResourceAttempt) {
597
-			$getConnectionResourceAttempt = false;
598
-			return false;
599
-		}
600
-		$getConnectionResourceAttempt = true;
601
-		$cr = $this->getConnectionResource();
602
-		$getConnectionResourceAttempt = false;
603
-		if(!$this->ldap->isResource($cr)) {
604
-			return false;
605
-		}
606
-		$ldapLogin = @$this->ldap->bind($cr,
607
-										$this->configuration->ldapAgentName,
608
-										$this->configuration->ldapAgentPassword);
609
-		if(!$ldapLogin) {
610
-			\OCP\Util::writeLog('user_ldap',
611
-				'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr),
612
-				\OCP\Util::WARN);
613
-			$this->ldapConnectionRes = null;
614
-			return false;
615
-		}
616
-		return true;
617
-	}
54
+    private $ldapConnectionRes = null;
55
+    private $configPrefix;
56
+    private $configID;
57
+    private $configured = false;
58
+    private $hasPagedResultSupport = true;
59
+    //whether connection should be kept on __destruct
60
+    private $dontDestruct = false;
61
+
62
+    /**
63
+     * @var bool runtime flag that indicates whether supported primary groups are available
64
+     */
65
+    public $hasPrimaryGroups = true;
66
+
67
+    //cache handler
68
+    protected $cache;
69
+
70
+    /** @var Configuration settings handler **/
71
+    protected $configuration;
72
+
73
+    protected $doNotValidate = false;
74
+
75
+    protected $ignoreValidation = false;
76
+
77
+    /**
78
+     * Constructor
79
+     * @param ILDAPWrapper $ldap
80
+     * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
81
+     * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
82
+     */
83
+    public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
84
+        parent::__construct($ldap);
85
+        $this->configPrefix = $configPrefix;
86
+        $this->configID = $configID;
87
+        $this->configuration = new Configuration($configPrefix,
88
+                                                    !is_null($configID));
89
+        $memcache = \OC::$server->getMemCacheFactory();
90
+        if($memcache->isAvailable()) {
91
+            $this->cache = $memcache->create();
92
+        }
93
+        $helper = new Helper(\OC::$server->getConfig());
94
+        $this->doNotValidate = !in_array($this->configPrefix,
95
+            $helper->getServerConfigurationPrefixes());
96
+        $this->hasPagedResultSupport =
97
+            intval($this->configuration->ldapPagingSize) !== 0
98
+            || $this->ldap->hasPagedResultSupport();
99
+    }
100
+
101
+    public function __destruct() {
102
+        if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
103
+            @$this->ldap->unbind($this->ldapConnectionRes);
104
+        };
105
+    }
106
+
107
+    /**
108
+     * defines behaviour when the instance is cloned
109
+     */
110
+    public function __clone() {
111
+        $this->configuration = new Configuration($this->configPrefix,
112
+                                                    !is_null($this->configID));
113
+        $this->ldapConnectionRes = null;
114
+        $this->dontDestruct = true;
115
+    }
116
+
117
+    /**
118
+     * @param string $name
119
+     * @return bool|mixed|void
120
+     */
121
+    public function __get($name) {
122
+        if(!$this->configured) {
123
+            $this->readConfiguration();
124
+        }
125
+
126
+        if($name === 'hasPagedResultSupport') {
127
+            return $this->hasPagedResultSupport;
128
+        }
129
+
130
+        return $this->configuration->$name;
131
+    }
132
+
133
+    /**
134
+     * @param string $name
135
+     * @param mixed $value
136
+     */
137
+    public function __set($name, $value) {
138
+        $this->doNotValidate = false;
139
+        $before = $this->configuration->$name;
140
+        $this->configuration->$name = $value;
141
+        $after = $this->configuration->$name;
142
+        if($before !== $after) {
143
+            if ($this->configID !== '') {
144
+                $this->configuration->saveConfiguration();
145
+            }
146
+            $this->validateConfiguration();
147
+        }
148
+    }
149
+
150
+    /**
151
+     * sets whether the result of the configuration validation shall
152
+     * be ignored when establishing the connection. Used by the Wizard
153
+     * in early configuration state.
154
+     * @param bool $state
155
+     */
156
+    public function setIgnoreValidation($state) {
157
+        $this->ignoreValidation = (bool)$state;
158
+    }
159
+
160
+    /**
161
+     * initializes the LDAP backend
162
+     * @param bool $force read the config settings no matter what
163
+     */
164
+    public function init($force = false) {
165
+        $this->readConfiguration($force);
166
+        $this->establishConnection();
167
+    }
168
+
169
+    /**
170
+     * Returns the LDAP handler
171
+     */
172
+    public function getConnectionResource() {
173
+        if(!$this->ldapConnectionRes) {
174
+            $this->init();
175
+        } else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
176
+            $this->ldapConnectionRes = null;
177
+            $this->establishConnection();
178
+        }
179
+        if(is_null($this->ldapConnectionRes)) {
180
+            \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR);
181
+            throw new ServerNotAvailableException('Connection to LDAP server could not be established');
182
+        }
183
+        return $this->ldapConnectionRes;
184
+    }
185
+
186
+    /**
187
+     * resets the connection resource
188
+     */
189
+    public function resetConnectionResource() {
190
+        if(!is_null($this->ldapConnectionRes)) {
191
+            @$this->ldap->unbind($this->ldapConnectionRes);
192
+            $this->ldapConnectionRes = null;
193
+        }
194
+    }
195
+
196
+    /**
197
+     * @param string|null $key
198
+     * @return string
199
+     */
200
+    private function getCacheKey($key) {
201
+        $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
202
+        if(is_null($key)) {
203
+            return $prefix;
204
+        }
205
+        return $prefix.md5($key);
206
+    }
207
+
208
+    /**
209
+     * @param string $key
210
+     * @return mixed|null
211
+     */
212
+    public function getFromCache($key) {
213
+        if(!$this->configured) {
214
+            $this->readConfiguration();
215
+        }
216
+        if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
217
+            return null;
218
+        }
219
+        $key = $this->getCacheKey($key);
220
+
221
+        return json_decode(base64_decode($this->cache->get($key)), true);
222
+    }
223
+
224
+    /**
225
+     * @param string $key
226
+     * @param mixed $value
227
+     *
228
+     * @return string
229
+     */
230
+    public function writeToCache($key, $value) {
231
+        if(!$this->configured) {
232
+            $this->readConfiguration();
233
+        }
234
+        if(is_null($this->cache)
235
+            || !$this->configuration->ldapCacheTTL
236
+            || !$this->configuration->ldapConfigurationActive) {
237
+            return null;
238
+        }
239
+        $key   = $this->getCacheKey($key);
240
+        $value = base64_encode(json_encode($value));
241
+        $this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
242
+    }
243
+
244
+    public function clearCache() {
245
+        if(!is_null($this->cache)) {
246
+            $this->cache->clear($this->getCacheKey(null));
247
+        }
248
+    }
249
+
250
+    /**
251
+     * Caches the general LDAP configuration.
252
+     * @param bool $force optional. true, if the re-read should be forced. defaults
253
+     * to false.
254
+     * @return null
255
+     */
256
+    private function readConfiguration($force = false) {
257
+        if((!$this->configured || $force) && !is_null($this->configID)) {
258
+            $this->configuration->readConfiguration();
259
+            $this->configured = $this->validateConfiguration();
260
+        }
261
+    }
262
+
263
+    /**
264
+     * set LDAP configuration with values delivered by an array, not read from configuration
265
+     * @param array $config array that holds the config parameters in an associated array
266
+     * @param array &$setParameters optional; array where the set fields will be given to
267
+     * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
268
+     */
269
+    public function setConfiguration($config, &$setParameters = null) {
270
+        if(is_null($setParameters)) {
271
+            $setParameters = array();
272
+        }
273
+        $this->doNotValidate = false;
274
+        $this->configuration->setConfiguration($config, $setParameters);
275
+        if(count($setParameters) > 0) {
276
+            $this->configured = $this->validateConfiguration();
277
+        }
278
+
279
+
280
+        return $this->configured;
281
+    }
282
+
283
+    /**
284
+     * saves the current Configuration in the database and empties the
285
+     * cache
286
+     * @return null
287
+     */
288
+    public function saveConfiguration() {
289
+        $this->configuration->saveConfiguration();
290
+        $this->clearCache();
291
+    }
292
+
293
+    /**
294
+     * get the current LDAP configuration
295
+     * @return array
296
+     */
297
+    public function getConfiguration() {
298
+        $this->readConfiguration();
299
+        $config = $this->configuration->getConfiguration();
300
+        $cta = $this->configuration->getConfigTranslationArray();
301
+        $result = array();
302
+        foreach($cta as $dbkey => $configkey) {
303
+            switch($configkey) {
304
+                case 'homeFolderNamingRule':
305
+                    if(strpos($config[$configkey], 'attr:') === 0) {
306
+                        $result[$dbkey] = substr($config[$configkey], 5);
307
+                    } else {
308
+                        $result[$dbkey] = '';
309
+                    }
310
+                    break;
311
+                case 'ldapBase':
312
+                case 'ldapBaseUsers':
313
+                case 'ldapBaseGroups':
314
+                case 'ldapAttributesForUserSearch':
315
+                case 'ldapAttributesForGroupSearch':
316
+                    if(is_array($config[$configkey])) {
317
+                        $result[$dbkey] = implode("\n", $config[$configkey]);
318
+                        break;
319
+                    } //else follows default
320
+                default:
321
+                    $result[$dbkey] = $config[$configkey];
322
+            }
323
+        }
324
+        return $result;
325
+    }
326
+
327
+    private function doSoftValidation() {
328
+        //if User or Group Base are not set, take over Base DN setting
329
+        foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
330
+            $val = $this->configuration->$keyBase;
331
+            if(empty($val)) {
332
+                $this->configuration->$keyBase = $this->configuration->ldapBase;
333
+            }
334
+        }
335
+
336
+        foreach(array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
337
+                        'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
338
+                as $expertSetting => $effectiveSetting) {
339
+            $uuidOverride = $this->configuration->$expertSetting;
340
+            if(!empty($uuidOverride)) {
341
+                $this->configuration->$effectiveSetting = $uuidOverride;
342
+            } else {
343
+                $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid',
344
+                                        'objectguid', 'guid', 'ipauniqueid');
345
+                if(!in_array($this->configuration->$effectiveSetting,
346
+                            $uuidAttributes)
347
+                    && (!is_null($this->configID))) {
348
+                    $this->configuration->$effectiveSetting = 'auto';
349
+                    $this->configuration->saveConfiguration();
350
+                    \OCP\Util::writeLog('user_ldap',
351
+                                        'Illegal value for the '.
352
+                                        $effectiveSetting.', '.'reset to '.
353
+                                        'autodetect.', \OCP\Util::INFO);
354
+                }
355
+
356
+            }
357
+        }
358
+
359
+        $backupPort = intval($this->configuration->ldapBackupPort);
360
+        if ($backupPort <= 0) {
361
+            $this->configuration->backupPort = $this->configuration->ldapPort;
362
+        }
363
+
364
+        //make sure empty search attributes are saved as simple, empty array
365
+        $saKeys = array('ldapAttributesForUserSearch',
366
+                        'ldapAttributesForGroupSearch');
367
+        foreach($saKeys as $key) {
368
+            $val = $this->configuration->$key;
369
+            if(is_array($val) && count($val) === 1 && empty($val[0])) {
370
+                $this->configuration->$key = array();
371
+            }
372
+        }
373
+
374
+        if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
375
+            && $this->configuration->ldapTLS) {
376
+            $this->configuration->ldapTLS = false;
377
+            \OCP\Util::writeLog('user_ldap',
378
+                                'LDAPS (already using secure connection) and '.
379
+                                'TLS do not work together. Switched off TLS.',
380
+                                \OCP\Util::INFO);
381
+        }
382
+    }
383
+
384
+    /**
385
+     * @return bool
386
+     */
387
+    private function doCriticalValidation() {
388
+        $configurationOK = true;
389
+        $errorStr = 'Configuration Error (prefix '.
390
+                    strval($this->configPrefix).'): ';
391
+
392
+        //options that shall not be empty
393
+        $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
394
+                            'ldapGroupDisplayName', 'ldapLoginFilter');
395
+        foreach($options as $key) {
396
+            $val = $this->configuration->$key;
397
+            if(empty($val)) {
398
+                switch($key) {
399
+                    case 'ldapHost':
400
+                        $subj = 'LDAP Host';
401
+                        break;
402
+                    case 'ldapPort':
403
+                        $subj = 'LDAP Port';
404
+                        break;
405
+                    case 'ldapUserDisplayName':
406
+                        $subj = 'LDAP User Display Name';
407
+                        break;
408
+                    case 'ldapGroupDisplayName':
409
+                        $subj = 'LDAP Group Display Name';
410
+                        break;
411
+                    case 'ldapLoginFilter':
412
+                        $subj = 'LDAP Login Filter';
413
+                        break;
414
+                    default:
415
+                        $subj = $key;
416
+                        break;
417
+                }
418
+                $configurationOK = false;
419
+                \OCP\Util::writeLog('user_ldap',
420
+                                    $errorStr.'No '.$subj.' given!',
421
+                                    \OCP\Util::WARN);
422
+            }
423
+        }
424
+
425
+        //combinations
426
+        $agent = $this->configuration->ldapAgentName;
427
+        $pwd = $this->configuration->ldapAgentPassword;
428
+        if (
429
+            ($agent === ''  && $pwd !== '')
430
+            || ($agent !== '' && $pwd === '')
431
+        ) {
432
+            \OCP\Util::writeLog('user_ldap',
433
+                                $errorStr.'either no password is given for the'.
434
+                                'user agent or a password is given, but not an'.
435
+                                'LDAP agent.',
436
+                \OCP\Util::WARN);
437
+            $configurationOK = false;
438
+        }
439
+
440
+        $base = $this->configuration->ldapBase;
441
+        $baseUsers = $this->configuration->ldapBaseUsers;
442
+        $baseGroups = $this->configuration->ldapBaseGroups;
443
+
444
+        if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
445
+            \OCP\Util::writeLog('user_ldap',
446
+                                $errorStr.'Not a single Base DN given.',
447
+                                \OCP\Util::WARN);
448
+            $configurationOK = false;
449
+        }
450
+
451
+        if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
452
+            === false) {
453
+            \OCP\Util::writeLog('user_ldap',
454
+                                $errorStr.'login filter does not contain %uid '.
455
+                                'place holder.',
456
+                                \OCP\Util::WARN);
457
+            $configurationOK = false;
458
+        }
459
+
460
+        return $configurationOK;
461
+    }
462
+
463
+    /**
464
+     * Validates the user specified configuration
465
+     * @return bool true if configuration seems OK, false otherwise
466
+     */
467
+    private function validateConfiguration() {
468
+
469
+        if($this->doNotValidate) {
470
+            //don't do a validation if it is a new configuration with pure
471
+            //default values. Will be allowed on changes via __set or
472
+            //setConfiguration
473
+            return false;
474
+        }
475
+
476
+        // first step: "soft" checks: settings that are not really
477
+        // necessary, but advisable. If left empty, give an info message
478
+        $this->doSoftValidation();
479
+
480
+        //second step: critical checks. If left empty or filled wrong, mark as
481
+        //not configured and give a warning.
482
+        return $this->doCriticalValidation();
483
+    }
484
+
485
+
486
+    /**
487
+     * Connects and Binds to LDAP
488
+     */
489
+    private function establishConnection() {
490
+        if(!$this->configuration->ldapConfigurationActive) {
491
+            return null;
492
+        }
493
+        static $phpLDAPinstalled = true;
494
+        if(!$phpLDAPinstalled) {
495
+            return false;
496
+        }
497
+        if(!$this->ignoreValidation && !$this->configured) {
498
+            \OCP\Util::writeLog('user_ldap',
499
+                                'Configuration is invalid, cannot connect',
500
+                                \OCP\Util::WARN);
501
+            return false;
502
+        }
503
+        if(!$this->ldapConnectionRes) {
504
+            if(!$this->ldap->areLDAPFunctionsAvailable()) {
505
+                $phpLDAPinstalled = false;
506
+                \OCP\Util::writeLog('user_ldap',
507
+                                    'function ldap_connect is not available. Make '.
508
+                                    'sure that the PHP ldap module is installed.',
509
+                                    \OCP\Util::ERROR);
510
+
511
+                return false;
512
+            }
513
+            if($this->configuration->turnOffCertCheck) {
514
+                if(putenv('LDAPTLS_REQCERT=never')) {
515
+                    \OCP\Util::writeLog('user_ldap',
516
+                        'Turned off SSL certificate validation successfully.',
517
+                        \OCP\Util::DEBUG);
518
+                } else {
519
+                    \OCP\Util::writeLog('user_ldap',
520
+                                        'Could not turn off SSL certificate validation.',
521
+                                        \OCP\Util::WARN);
522
+                }
523
+            }
524
+
525
+            $bindStatus = false;
526
+            $error = -1;
527
+            try {
528
+                if (!$this->configuration->ldapOverrideMainServer
529
+                    && !$this->getFromCache('overrideMainServer')
530
+                ) {
531
+                    $this->doConnect($this->configuration->ldapHost,
532
+                        $this->configuration->ldapPort);
533
+                    $bindStatus = $this->bind();
534
+                    $error = $this->ldap->isResource($this->ldapConnectionRes) ?
535
+                        $this->ldap->errno($this->ldapConnectionRes) : -1;
536
+                }
537
+                if($bindStatus === true) {
538
+                    return $bindStatus;
539
+                }
540
+            } catch (\OC\ServerNotAvailableException $e) {
541
+                if(trim($this->configuration->ldapBackupHost) === "") {
542
+                    throw $e;
543
+                }
544
+            }
545
+
546
+            //if LDAP server is not reachable, try the Backup (Replica!) Server
547
+            if(    $error !== 0
548
+                || $this->configuration->ldapOverrideMainServer
549
+                || $this->getFromCache('overrideMainServer'))
550
+            {
551
+                $this->doConnect($this->configuration->ldapBackupHost,
552
+                                    $this->configuration->ldapBackupPort);
553
+                $bindStatus = $this->bind();
554
+                if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) {
555
+                    //when bind to backup server succeeded and failed to main server,
556
+                    //skip contacting him until next cache refresh
557
+                    $this->writeToCache('overrideMainServer', true);
558
+                }
559
+            }
560
+            return $bindStatus;
561
+        }
562
+        return null;
563
+    }
564
+
565
+    /**
566
+     * @param string $host
567
+     * @param string $port
568
+     * @return bool
569
+     * @throws \OC\ServerNotAvailableException
570
+     */
571
+    private function doConnect($host, $port) {
572
+        if ($host === '') {
573
+            return false;
574
+        }
575
+        $this->ldapConnectionRes = $this->ldap->connect($host, $port);
576
+        if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
577
+            if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
578
+                if($this->configuration->ldapTLS) {
579
+                    $this->ldap->startTls($this->ldapConnectionRes);
580
+                }
581
+            }
582
+        } else {
583
+            throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.');
584
+        }
585
+        return true;
586
+    }
587
+
588
+    /**
589
+     * Binds to LDAP
590
+     */
591
+    public function bind() {
592
+        static $getConnectionResourceAttempt = false;
593
+        if(!$this->configuration->ldapConfigurationActive) {
594
+            return false;
595
+        }
596
+        if($getConnectionResourceAttempt) {
597
+            $getConnectionResourceAttempt = false;
598
+            return false;
599
+        }
600
+        $getConnectionResourceAttempt = true;
601
+        $cr = $this->getConnectionResource();
602
+        $getConnectionResourceAttempt = false;
603
+        if(!$this->ldap->isResource($cr)) {
604
+            return false;
605
+        }
606
+        $ldapLogin = @$this->ldap->bind($cr,
607
+                                        $this->configuration->ldapAgentName,
608
+                                        $this->configuration->ldapAgentPassword);
609
+        if(!$ldapLogin) {
610
+            \OCP\Util::writeLog('user_ldap',
611
+                'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr),
612
+                \OCP\Util::WARN);
613
+            $this->ldapConnectionRes = null;
614
+            return false;
615
+        }
616
+        return true;
617
+    }
618 618
 
619 619
 }
Please login to merge, or discard this patch.