140 Commits

Author SHA1 Message Date
Andrew Ruthven
fcbd72e310 Fix an exception if a LDAP group mentions a user that doesn't exist
This tickles a bug as reported by Thorsten Marquardt in
https://sourceforge.net/p/davical/mailman/message/58766531/ with this
error message reported:

    Exception [0] ldap_get_attributes(): Argument #2 ($entry) must be of
    type LDAP\ResultEntry, false given
    At line 718 of /usr/share/davical-master/inc/drivers_ldap.php

You need to look in 3da860e5d5e732c2dedb62a73c76608a2b7098a4 for that line
number as I've just made some improvements to the code the last few commits.
2024-05-01 22:32:33 +12:00
Andrew Ruthven
629789612e Prevent using undefined or non-existant variables 2024-05-01 22:32:33 +12:00
Andrew Ruthven
a50e3eae90 Be a bit more verbose in the logging 2024-05-01 22:32:33 +12:00
Andrew Ruthven
d2a93643bc Don't be afraid of whitespace 2024-05-01 22:32:33 +12:00
Stonewall Jackson
d3a0c89eca Retain original i_use_mode_kerberos behavior, add fallback option
Add a new value for i_use_mode_kerberos: "allow_fallback_ldap_auth",
which will fallback to username/password authentication when the
REMOTE_USER value is unset.
2024-04-10 14:25:23 -04:00
Stonewall Jackson
0ba94e91de Support fallback to LDAP password with i_use_mode_kerberos
Currently, when `i_use_mode_kerberos` is enabled in the LDAP driver,
Davical checks the `REMOTE_USER` server variable, followed by the
`REDIRECT_REMOTE_USER` variable, for a matching username. If a matching
username is not found, authentication fails immediately.

This commit modifies the LDAP driver to fallback to standard LDAP
password authentication when `i_use_mode_kerberos` is enabled and
neither of these server variables are set. This allows
non-kerberos-enabled clients to authenticate as well.

Fixes #323
2024-04-10 14:25:23 -04:00
Stonewall Jackson
fa44a257e9 allow specifying all sasl bind options in config.php 2024-02-28 16:29:56 -05:00
Stonewall Jackson
c8424ae5d5 Update LDAP driver to support SASL binds
Add a new 'sasl' option to the LDAP driver, which invokes
ldap_sasl_bind() instead of ldap_bind().

This allows authenticating to LDAP using the GSSAPI (kerberos) or
EXTERNAL mechanisms, rather than a bindDN and password.

Note that for GSSAPI binds, PHP needs access to valid kerberos
credentials (for example, by setting the KRB5CCNAME environment variable
for the PHP process).

Tested with OpenLDAP/Heimdal kerberos, but should also work with Active
Directory.
2024-02-28 16:29:56 -05:00
Stonewall Jackson
3a08e80d5a Fix scope=onelevel in LDAP driver
When `scope` is set to 'onelevel', the LDAP driver actually does a full
subtree search instead.

Should be `ldap_list` instead. Fixed.
2024-02-27 13:32:15 -05:00
Andrew Ruthven
eb4d120bbf Honour do_not_sync_from_ldap when sync'ing group members
This had been working as a side effect of the way the SQL insert
statement was working, but better to be explict about skipping them.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
8a6274e6cf Rather than look for a flag, if a member is a DN, modify/fetch the record.
This changes 48c6512a70740c403027b66e9d609e9b871d29c0, in Eric's commit it
needs a flag to go fetch the record and apply the mapping to find the
username field. This approach looks for a telltale that this is DN (naively
an "=") and then either grabs the first element from the DN if the username
attr matches or fetches the entry from LDAP.

There have also been attempts in the past to special case uniqueMember and
to add a group_member_dnfix config option.

This should handle the cases where people use uid/cn/whatever for the
username.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
03d0e66b39 Handle there being no one in the group in the database 2024-02-17 02:25:25 +00:00
Andrew Ruthven
ef6bd9a7e9 fullname is a better default than group 2024-02-17 02:25:25 +00:00
Andrew Ruthven
98d9925241 Always update groups from LDAP
The logic actually handled updated group details, but only new groups were
being passed in. This will cause changes to what is being used for the
fullname to flow through.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
b77b2640f8 The displayname can be unset, test for that 2024-02-17 02:25:25 +00:00
Andrew Ruthven
cb287c5abf Use filterUsers from the config 2024-02-17 02:25:25 +00:00
Andrew Ruthven
56d7d22d86 Rename mapping_field to user_mapping_field
This is to be consistent with group_mapping_field. The code is backwards
compatible with mapping_field.

In sync_LDAP_groups assign user_mapping once, not for every group.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
3d28433b5b Fix the comments 2024-02-17 02:25:25 +00:00
Andrew Ruthven
9d40ae1aa7 Simplify the code by assigning the array after we've cleaned it up.
This allows shorter lines which means easier to understand code.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
2a30a9646c Have some sane defaults for LDAP group mappings 2024-02-17 02:25:25 +00:00
Andrew Ruthven
13083b07e8 Rename username to name in group mappings, drop unused fullname from example
Usinger "username" for the group name is confusing and misleading. Just
use name, but support our users who still have username.

We don't use fullname, drop it from the example.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
bb713137fd memberUid is deprecated, make member default 2024-02-17 02:25:25 +00:00
Andrew Ruthven
a7fc46a848 Add whitespace to sync_LDAP_groups
Make the function more readable.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
dc2991666a Allow the LDAP group to have no members 2024-02-17 02:25:25 +00:00
Andrew Ruthven
3846d31664 Handle there being no group members in the DB 2024-02-17 02:25:25 +00:00
Andrew Ruthven
1db3663302 We're using a baseDN, not querying a DN 2024-02-17 02:25:25 +00:00
Andrew Ruthven
775ecb8f3b Ensure that users_nothing_done is created as an array
This is likely only going to generate an error on the first time you
sync from LDAP, but still, let's not spit an unncessary error out.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
ed7f308b87 Add default filters for users and groups
Some (all?) LDAP servers will just not respond if there is no filter,
provide a sensible default.
2024-02-17 02:25:25 +00:00
Andrew Ruthven
702fc05b57 Bail out early to prevent bogus errors if baseDNGroups isn't set 2024-02-17 02:25:25 +00:00
Andrew Ruthven
e73f2d73d4 Better handle when we can't talk to the server, log that 2024-02-17 02:25:25 +00:00
Andrew Ruthven
15e5a89675 Log better information about the connection to the server 2024-02-17 02:25:25 +00:00
Eric Wagner
016e51b4ac use username attr for matching group members 2024-02-17 02:25:25 +00:00
Scott Savarese
0059d0dcdb Support ldap connections via URI to handle ldaps and redundant ldap servers 2023-04-27 11:00:50 +00:00
Andrew Ruthven
0041577fc8 Handle baseDNGroups being unset. 2023-02-04 19:03:50 +13:00
Andrew Ruthven
444a098130 Ensure that groups_nothing_done is defined
Closes #278.
2023-02-04 05:48:09 +00:00
Florian Schlichting
75f62a81f6 fix PHP8 deprecation warnings: "Required parameter X follows optional parameter Y"
Deprecated: Required parameter $username follows optional parameter $attributes in inc/drivers_ldap.php on line 190
Deprecated: Required parameter $passwd follows optional parameter $attributes in inc/drivers_ldap.php on line 190
Deprecated: Required parameter $ua_string follows optional parameter $min_age in inc/external-fetch.php on line 42

As explained in https://www.php.net/manual/en/migration80.deprecated.php,
    If a parameter with a default value is followed by a required
    parameter, the default value has no effect. This is deprecated as of
    PHP 8.0.0 and can generally be resolved by dropping the default
    value, without a change in functionality
2021-02-03 23:25:51 +08:00
Florian Schlichting
9bc94556b4 add users to new groups in the "update groups" step
do not maintain the same code twice
2019-01-30 22:28:58 +01:00
Florian Schlichting
8d622df3e5 honour do_not_sync_group_from_ldap when creating groups, correctly display all results
same for groups
2019-01-30 22:18:43 +01:00
Florian Schlichting
eb0e9a8aec honour do_not_sync_from_ldap when creating users, correctly display all results
despite its name, $c->do_not_sync_from_ldap did not stop accounts in
LDAP from being created in Davical, it only stopped accounts not in LDAP
from being deactived in Davical (like a local admin account)
2019-01-30 21:57:24 +01:00
Florian Schlichting
afcaacaf2a do_not_sync_from_ldap for groups (fixes #158) 2019-01-30 21:42:01 +01:00
Florian Schlichting
db709ddebd Merge branch 'ldap-uid-vs-cn' into 'master'
LDAP: any 'dn' compatibility

See merge request davical-project/davical!43
2018-01-10 21:39:21 +00:00
Jean-Baptiste Guerraz
79acc80eb7 use php ldap explode in order to be compatible with any dn 2018-01-10 17:00:13 +01:00
Jean-Baptiste Guerraz
0fa38c8580 sync ldap user - reactivate 2018-01-10 15:55:26 +01:00
Rik Theys
e0b8ecada5 Fix modified mapping (fix #108)
The checks to test if a "modified" attribute was found in the
$valid array used in_array, which fails.

Replace this with array_key_exists calls.

This fixes https://gitlab.com/davical-project/davical/issues/108

[ $mapping['modified'] is a key in $valid, not a value. This is a
regression introduced in 970b61ac, for 1.1.5 ]
2017-04-08 00:09:50 +02:00
Florian Schlichting
f1ca12bbe9 Fix display of deactivated users after LDAP sync to not include those in $c->do_not_sync_from_ldap
...thus reducing the rate of heart attacks in DAViCal admins.

Also: ignore empty user objects that my LDAP server seems to generate.
2017-03-27 16:56:34 +02:00
Florian Schlichting
6edd828803 Fix ldapDriver instantiation 2017-01-17 23:36:05 +01:00
Marc
364bbd1df5 allow admins to manually toggle the uniqueMember fix via config (fix #102) 2017-01-17 23:30:59 +01:00
Florian Schlichting
701feb6143 drivers_*: brush up apidoc 2016-12-30 08:54:05 +01:00
Florian Schlichting
eb7f2edc0c eliminate trailing whitespace, expand tabs 2016-12-30 08:52:44 +01:00
Émile Morel
af5cdfd46d ldap group import: unset group after import 2016-12-08 15:08:38 +01:00