1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
require_once('functions.inc');
|
12
|
|
13
|
$config = ldap_help_config();
|
14
|
|
15
|
ldap_help_display(NULL, "------------------------------------------\n");
|
16
|
ldap_help_display(NULL, LDAP_SCRIPTS_COMMAND_LINE_WARNING . "\n");
|
17
|
|
18
|
ldap_help_display(NULL, "------------------------------------------\nldap extension test\n------------------------------------------");
|
19
|
ldap_help_display("PHP Version", phpversion());
|
20
|
ldap_help_display('LDAP Extension Loaded', (extension_loaded('ldap')) ? 'yes' : 'no');
|
21
|
ldap_help_display(NULL, ldap_help_parsePHPModules());
|
22
|
|
23
|
if (!extension_loaded('ldap')) {
|
24
|
die('PHP LDAP extension not loaded. Can not run tests. Check your php.ini and make sure ldap extension is avaialable.');
|
25
|
}
|
26
|
|
27
|
foreach ($config['servers'] as $sid => $server) {
|
28
|
|
29
|
|
30
|
|
31
|
|
32
|
$results = ldap_help_connect($server['server_address'], $server['server_port'], $server['server_tls'], TRUE);
|
33
|
$test_name = "\"" . $sid . "\"";
|
34
|
|
35
|
ldap_help_display(NULL, "------------------------------------------\n$test_name connect\n------------------------------------------");
|
36
|
$tls = ($server['server_tls']) ? 'yes' : 'no';
|
37
|
ldap_help_display('tls', $tls);
|
38
|
|
39
|
$anon_bind = ($server['server_bind_method'] == LDAP_SERVERS_BIND_METHOD_ANON);
|
40
|
$anon_bind_text = ($anon_bind) ? 'yes' : 'no';
|
41
|
ldap_help_display('anonymous bind', $anon_bind_text);
|
42
|
|
43
|
ldap_help_display('connect result', $results[1]);
|
44
|
ldap_help_display('connect context', join("", array("server: ", $server['server_address'], ", port: ", $server['server_port'], ", tls= $tls")));
|
45
|
$con = FALSE;
|
46
|
if ($results[0] == LDAP_SUCCESS) {
|
47
|
$con = $results[2];
|
48
|
}
|
49
|
elseif ($results[0] == LDAP_OTHER) {
|
50
|
$con = $results[2];
|
51
|
}
|
52
|
else {
|
53
|
ldap_help_disconnect($con);
|
54
|
continue;
|
55
|
}
|
56
|
|
57
|
|
58
|
|
59
|
|
60
|
|
61
|
ldap_help_display(NULL, "------------------------------------------\n$test_name bind\n------------------------------------------");
|
62
|
|
63
|
if ($anon_bind) {
|
64
|
if (@!ldap_bind($con)) {
|
65
|
$results = array(ldap_errno($con), "LDAP anonymous bind error." . ldap_help_show_error($con));
|
66
|
}
|
67
|
}
|
68
|
else {
|
69
|
$bind_result = @ldap_bind($con, $server['server_bind_dn'], $server['server_bind_pw']);
|
70
|
if (!$bind_result) {
|
71
|
$results = array(ldap_errno($con), "LDAP bind failure for user " . $server['server_bind_dn'] . "." . ldap_help_show_error($con));
|
72
|
}
|
73
|
else {
|
74
|
$results = array(LDAP_SUCCESS, "LDAP bind success.");
|
75
|
}
|
76
|
}
|
77
|
|
78
|
ldap_help_display('bind result', $results[1]);
|
79
|
ldap_help_display('bind dn', $server['server_bind_dn']);
|
80
|
if ($results[0] != LDAP_SUCCESS) {
|
81
|
continue;
|
82
|
}
|
83
|
|
84
|
|
85
|
|
86
|
|
87
|
foreach ($server['test_queries'] as $query_id => $query) {
|
88
|
ldap_help_display(NULL, "------------------------------------------\n$test_name query \"$query_id\" \n------------------------------------------");
|
89
|
|
90
|
$filter = $query['filter'];
|
91
|
ldap_help_display('search base_dn', $server['server_base_dn']);
|
92
|
ldap_help_display('search filter', $filter);
|
93
|
ldap_help_display('server_address', $server['server_address']);
|
94
|
ldap_help_display('server_port', $server['server_port']);
|
95
|
ldap_help_display('tls', $tls);
|
96
|
|
97
|
$query_result = @ldap_search($con, $server['server_base_dn'], $filter);
|
98
|
if (!$query_result) {
|
99
|
ldap_help_display(ldap_errno($con), "LDAP search failure for user $filter." . ldap_help_show_error($con));
|
100
|
}
|
101
|
else {
|
102
|
$entries = ldap_get_entries($con, $query_result);
|
103
|
|
104
|
ldap_help_display('search result');
|
105
|
if (is_array($entries)) {
|
106
|
$entry_count = $entries['count'];
|
107
|
if ($entry_count == 0) {
|
108
|
ldap_help_display('no entries found');
|
109
|
}
|
110
|
else {
|
111
|
for ($j=0; $j<$entry_count; $j++) {
|
112
|
$entry = $entries[$j];
|
113
|
$attr_count = $entry['count'];
|
114
|
ldap_help_display(NULL, "\nsearch results, entry[$j]:");
|
115
|
ldap_help_display(' dn[' . $j . ']', $entry['dn']);
|
116
|
for ($i=0; $i<$attr_count; $i++) {
|
117
|
$attr_name = $entry[$i];
|
118
|
if (in_array($attr_name, $query['show_attr'])) {
|
119
|
$values_count = $entry[$attr_name]['count'];
|
120
|
for ($k=0; $k<$values_count; $k++) {
|
121
|
ldap_help_display(' ' . $attr_name . '[' . $k . ']', $entry[$attr_name][$k]);
|
122
|
}
|
123
|
}
|
124
|
}
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
}
|
129
|
}
|
130
|
|
131
|
|
132
|
|
133
|
|
134
|
foreach ($server['test_provisions'] as $provision_id => $provision) {
|
135
|
ldap_help_display(NULL, "------------------------------------------\n$test_name provision \"$provision_id\"\n------------------------------------------");
|
136
|
|
137
|
$dn = $provision['dn'];
|
138
|
|
139
|
ldap_help_display(NULL, "\nprovision, entry[$dn]:");
|
140
|
if ($provision['delete_if_exists']) {
|
141
|
$query_result = @ldap_search($con, $server['server_base_dn'], $provision['find_filter']);
|
142
|
if ($query_result) {
|
143
|
$entries = ldap_get_entries($con, $query_result);
|
144
|
if ($entries['count'] == 1) {
|
145
|
$result = @ldap_delete($con, $dn);
|
146
|
if ($result) {
|
147
|
ldap_help_display('deleted existing entry', $dn);
|
148
|
}
|
149
|
else {
|
150
|
ldap_help_display('failed to delete existing entry in provision', $dn);
|
151
|
continue;
|
152
|
}
|
153
|
}
|
154
|
else {
|
155
|
|
156
|
}
|
157
|
}
|
158
|
}
|
159
|
|
160
|
|
161
|
$result = @ldap_add($con, $dn, $provision['attr']);
|
162
|
$show_result = $result ? 'success' : 'fail';
|
163
|
ldap_help_display('provision result', $show_result);
|
164
|
if (!$result) {
|
165
|
ldap_help_display('provision error', ldap_help_show_error($con));
|
166
|
}
|
167
|
}
|
168
|
|
169
|
}
|