Skip to content

Commit 08a37ee

Browse files
authored
Add dynamic Group Attribute. (wheelybird#119)
* Add dynamic Group Attribute. * Update ldap_functions.inc.php * Update show_group.php * Update run_checks.php
1 parent 7753eb4 commit 08a37ee

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

www/account_manager/show_group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
$new_group = FALSE;
5151
$initialise_group = TRUE;
5252
$current_members = array();
53-
$full_dn = "cn=$group_cn,${LDAP['group_dn']}";
53+
$full_dn = "${LDAP['group_attribute']}=$group_cn,${LDAP['group_dn']}";
5454
$has_been = "created";
5555
}
5656
else {

www/includes/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#Optional
2525

2626
$LDAP['account_attribute'] = (getenv('LDAP_ACCOUNT_ATTRIBUTE') ? getenv('LDAP_ACCOUNT_ATTRIBUTE') : 'uid');
27+
$LDAP['group_attribute'] = (getenv('LDAP_GROUP_ATTRIBUTE') ? getenv('LDAP_GROUP_ATTRIBUTE') : 'cn');
2728
$LDAP['group_ou'] = (getenv('LDAP_GROUP_OU') ? getenv('LDAP_GROUP_OU') : 'groups');
2829
$LDAP['user_ou'] = (getenv('LDAP_USER_OU') ? getenv('LDAP_USER_OU') : 'people');
2930

www/includes/ldap_functions.inc.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ function ldap_get_group_list($ldap_connection,$start=0,$entries=NULL,$sort="asc"
420420
$records = array();
421421
foreach ($result as $record) {
422422

423-
if (isset($record['cn'][0])) {
423+
if (isset($record[$LDAP['group_attribute']][0])) {
424424

425-
array_push($records, $record['cn'][0]);
425+
array_push($records, $record[$LDAP['group_attribute']][0]);
426426

427427
}
428428
}
@@ -444,7 +444,7 @@ function ldap_get_dn_of_group($ldap_connection,$group_name) {
444444

445445
if (isset($group_name)) {
446446

447-
$ldap_search_query = "(cn=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
447+
$ldap_search_query = "(${LDAP['group_attribute']}=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
448448
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query , array("dn"));
449449
$result = @ ldap_get_entries($ldap_connection, $ldap_search);
450450

@@ -466,7 +466,7 @@ function ldap_get_group_members($ldap_connection,$group_name,$start=0,$entries=N
466466

467467
if ($LDAP['rfc2307bis_check_run'] != TRUE) { $rfc2307bis_available = ldap_detect_rfc2307bis($ldap_connection); }
468468

469-
$ldap_search_query = "(cn=". ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
469+
$ldap_search_query = "(${LDAP['group_attribute']}=". ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
470470
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query, array($LDAP['group_membership_attribute']));
471471

472472
$result = @ ldap_get_entries($ldap_connection, $ldap_search);
@@ -513,7 +513,7 @@ function ldap_is_group_member($ldap_connection,$group_name,$username) {
513513

514514
if ($LDAP['rfc2307bis_check_run'] != TRUE) { $rfc2307bis_available = ldap_detect_rfc2307bis($ldap_connection); }
515515

516-
$ldap_search_query = "(cn=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
516+
$ldap_search_query = "(${LDAP['group_attribute']}=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
517517
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query);
518518

519519
if ($ldap_search) {
@@ -550,13 +550,13 @@ function ldap_user_group_membership($ldap_connection,$username) {
550550
}
551551

552552
$ldap_search_query = "(&(objectClass=posixGroup)(${LDAP['group_membership_attribute']}=${username}))";
553-
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query, array('cn'));
553+
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query, array($LDAP['group_attribute']));
554554
$result = ldap_get_entries($ldap_connection, $ldap_search);
555555

556556
$groups = array();
557557
foreach ($result as $record) {
558-
if (isset($record['cn'][0])) {
559-
array_push($groups, $record['cn'][0]);
558+
if (isset($record[$LDAP['group_attribute']][0])) {
559+
array_push($groups, $record[$LDAP['group_attribute']][0]);
560560
}
561561
}
562562
sort($groups);
@@ -578,7 +578,7 @@ function ldap_new_group($ldap_connection,$group_name,$initial_member="") {
578578
$new_group = ldap_escape($group_name, "", LDAP_ESCAPE_FILTER);
579579
$initial_member = ldap_escape($initial_member, "", LDAP_ESCAPE_FILTER);
580580

581-
$ldap_search_query = "(cn=$new_group,${LDAP['group_dn']})";
581+
$ldap_search_query = "(${LDAP['group_attribute']}=$new_group,${LDAP['group_dn']})";
582582
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query);
583583
$result = @ ldap_get_entries($ldap_connection, $ldap_search);
584584

@@ -643,7 +643,7 @@ function ldap_delete_group($ldap_connection,$group_name) {
643643

644644
if (isset($group_name)) {
645645

646-
$delete_query = "cn=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ",${LDAP['group_dn']}";
646+
$delete_query = "${LDAP['group_attribute']}=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ",${LDAP['group_dn']}";
647647
$delete = @ ldap_delete($ldap_connection, $delete_query);
648648

649649
if ($delete) {
@@ -668,7 +668,7 @@ function ldap_get_gid_of_group($ldap_connection,$group_name) {
668668

669669
if (isset($group_name)) {
670670

671-
$ldap_search_query = "(cn=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
671+
$ldap_search_query = "(${LDAP['group_attribute']}=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ")";
672672
$ldap_search = @ ldap_search($ldap_connection, "${LDAP['group_dn']}", $ldap_search_query , array("gidNumber"));
673673
$result = @ ldap_get_entries($ldap_connection, $ldap_search);
674674

@@ -865,7 +865,7 @@ function ldap_add_member_to_group($ldap_connection,$group_name,$username) {
865865

866866
if ($LDAP['rfc2307bis_check_run'] != TRUE) { $rfc2307bis_available = ldap_detect_rfc2307bis($ldap_connection); }
867867

868-
$group_dn = "cn=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ",${LDAP['group_dn']}";
868+
$group_dn = "${LDAP['group_attribute']}=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ",${LDAP['group_dn']}";
869869

870870
if ($LDAP['group_membership_uses_uid'] == FALSE) {
871871
$username = "${LDAP['account_attribute']}=$username,${LDAP['user_dn']}";
@@ -900,7 +900,7 @@ function ldap_delete_member_from_group($ldap_connection,$group_name,$username) {
900900
else {
901901
if ($LDAP['rfc2307bis_check_run'] != TRUE) { $rfc2307bis_available = ldap_detect_rfc2307bis($ldap_connection); }
902902

903-
$group_dn = "cn=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ",${LDAP['group_dn']}";
903+
$group_dn = "${LDAP['group_attribute']}=" . ldap_escape($group_name, "", LDAP_ESCAPE_FILTER) . ",${LDAP['group_dn']}";
904904

905905
if ($LDAP['group_membership_uses_uid'] == FALSE and $username != "") {
906906
$username = "${LDAP['account_attribute']}=$username,${LDAP['user_dn']}";

www/setup/run_checks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
}
188188

189189

190-
$defgroup_filter = "(&(objectclass=posixGroup)(cn=${DEFAULT_USER_GROUP}))";
190+
$defgroup_filter = "(&(objectclass=posixGroup)(${LDAP['group_attribute']}=${DEFAULT_USER_GROUP}))";
191191
$ldap_defgroup_search = ldap_search($ldap_connection, "${LDAP['base_dn']}", $defgroup_filter);
192192
$defgroup_result = ldap_get_entries($ldap_connection, $ldap_defgroup_search);
193193

@@ -207,7 +207,7 @@
207207
}
208208

209209

210-
$adminsgroup_filter = "(&(objectclass=posixGroup)(cn=${LDAP['admins_group']}))";
210+
$adminsgroup_filter = "(&(objectclass=posixGroup)(${LDAP['group_attribute']}=${LDAP['admins_group']}))";
211211
$ldap_adminsgroup_search = ldap_search($ldap_connection, "${LDAP['base_dn']}", $adminsgroup_filter);
212212
$adminsgroup_result = ldap_get_entries($ldap_connection, $ldap_adminsgroup_search);
213213

0 commit comments

Comments
 (0)