Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_help/ldap_test_script/functions.inc
1 1
<?php
2 2

  
3

  
4 3
/**
5 4
 * @file
6
 * test script functions for testing ldap functionality outside of Drupal
7
 *
5
 * Test script functions for testing ldap functionality outside of Drupal.
8 6
 */
9 7

  
10 8
error_reporting(E_ALL | E_STRICT);
11
set_time_limit (0);
9
set_time_limit(0);
12 10
ini_set("display_errors", 1);
13 11
ini_set("max_execution_time", 0);
14 12

  
......
26 24
define('LDAP_COMPARE_TRUE', 0x06);
27 25
define('LDAP_AUTH_METHOD_NOT_SUPPORTED', 0x07);
28 26
define('LDAP_STRONG_AUTH_REQUIRED', 0x08);
29
//NotusedinLDAPv3);
27

  
28
// Not used in LDAPv3.
30 29
define('LDAP_PARTIAL_RESULTS', 0x09);
31 30

  
32
//Next5newinLDAPv3);
31
// Next 5 new in LDAPv3.
33 32
define('LDAP_REFERRAL', 0x0a);
34 33
define('LDAP_ADMINLIMIT_EXCEEDED', 0x0b);
35 34
define('LDAP_UNAVAILABLE_CRITICAL_EXTENSION', 0x0c);
......
68 67
define('LDAP_ALREADY_EXISTS', 0x44);
69 68
define('LDAP_NO_OBJECT_CLASS_MODS', 0x45);
70 69
define('LDAP_RESULTS_TOO_LARGE', 0x46);
71
//NexttwoforLDAPv3);
70

  
71
// Next two for LDAPv3.
72 72
define('LDAP_AFFECTS_MULTIPLE_DSAS', 0x47);
73 73
define('LDAP_OTHER', 0x50);
74 74

  
75
//UsedbysomeAPIs);
75
// Used by some APIs.
76 76
define('LDAP_SERVER_DOWN', 0x51);
77 77
define('LDAP_LOCAL_ERROR', 0x52);
78 78
define('LDAP_ENCODING_ERROR', 0x53);
......
84 84
define('LDAP_PARAM_ERROR', 0x59);
85 85
define('LDAP_NO_MEMORY', 0x5a);
86 86

  
87
//PreliminaryLDAPv3codes);
87
// Preliminary LDAPv3 codes.
88 88
define('LDAP_CONNECT_ERROR', 0x5b);
89 89
define('LDAP_NOT_SUPPORTED', 0x5c);
90 90
define('LDAP_CONTROL_NOT_FOUND', 0x5d);
......
93 93
define('LDAP_CLIENT_LOOP', 0x60);
94 94
define('LDAP_REFERRAL_LIMIT_EXCEEDED', 0x61);
95 95

  
96

  
97
//error_reporting(E_ALL  &  ~E_NOTICE);
98

  
99 96
define('LDAP_SCRIPTS_COMMAND_LINE_WARNING', "Warning: PHP from the command line may have different PHP versions, php.ini files, and security context than running in a webserver context. This may produce false test results since Drupal LDAP Modules are run in the web server context.");
100 97

  
101
require_once('config.inc');
98
require_once 'config.inc';
102 99

  
100
/**
101
 *
102
 */
103 103
function ldap_help_connect($address, $port, $tls, $test = FALSE) {
104 104

  
105 105
  if ($test) {
106
    $false_con = ldap_connect("fakehostname.sdfserewerdfsdf.com", 389); // test for ldap extensions that don't actually connect until bind
106
    // Test for ldap extensions that don't actually connect until bind.
107
    $false_con = ldap_connect("fakehostname.sdfserewerdfsdf.com", 389);
107 108
    if (ldap_errno($false_con) == LDAP_SUCCESS) {
108 109
      $con = ldap_connect($address, $port);
109
      return array(LDAP_OTHER, "ldap_connect does not actually connect until bind with installed extension, so connect is not a valid test.", $con);
110
      return [LDAP_OTHER, "ldap_connect does not actually connect until bind with installed extension, so connect is not a valid test.", $con];
110 111
    }
111 112
  }
112 113

  
......
114 115

  
115 116
  if (!$con || ldap_errno($con) != LDAP_SUCCESS) {
116 117
    $err = ldap_errno($con) . ":" . ldap_error($con) . ":" . ldap_err2str(ldap_errno($con)) . "!";
117
    return array(LDAP_CONNECT_ERROR, "LDAP Connect failure to  $address : $port. $err");
118
    return [LDAP_CONNECT_ERROR, "LDAP Connect failure to  $address : $port. $err"];
118 119
  }
119 120

  
120 121
  // Use TLS if we are configured and able to.
121 122
  if ($tls) {
122 123
    ldap_get_option($con, LDAP_OPT_PROTOCOL_VERSION, $vers);
123 124
    if ($vers == -1) {
124
      return array(LDAP_PROTOCOL_ERROR, "Could not get LDAP protocol version.");
125
      return [LDAP_PROTOCOL_ERROR, "Could not get LDAP protocol version."];
125 126
    }
126 127
    if ($vers != 3) {
127
      return array(LDAP_CONNECT_ERROR, 'Could not start TLS, only supported by LDAP v3.');
128
      return [LDAP_CONNECT_ERROR, 'Could not start TLS, only supported by LDAP v3.'];
128 129
    }
129 130
    elseif (!function_exists('ldap_start_tls')) {
130
      return array(LDAP_CONNECT_ERROR, 'Could not start TLS. It does not seem to be supported by this PHP setup.');
131
      return [LDAP_CONNECT_ERROR, 'Could not start TLS. It does not seem to be supported by this PHP setup.'];
131 132
    }
132 133
    elseif (!ldap_start_tls($con)) {
133
      return array(LDAP_CONNECT_ERROR, "Could not start TLS. (Error " . ldap_errno($con) . ":" . ldap_error($con) . ").");
134
      return [LDAP_CONNECT_ERROR, "Could not start TLS. (Error " . ldap_errno($con) . ":" . ldap_error($con) . ")."];
134 135
    }
135 136
  }
136 137

  
137
  return array(LDAP_SUCCESS, "Successful Connection!", $con);
138
  return [LDAP_SUCCESS, "Successful Connection!", $con];
138 139
}
139 140

  
141
/**
142
 *
143
 */
140 144
function ldap_help_show_error($con) {
141 145
  return "\nLDAP Error Number: " . ldap_errno($con) . "\nLDAP Error Description: " . ldap_error($con);
142 146
}
143 147

  
148
/**
149
 *
150
 */
144 151
function ldap_help_display($title, $value = NULL) {
145 152
  if (is_array($value)) {
146 153
    echo "\n" . $title;
......
151 158
  if (!$title && $value) {
152 159
    echo "\n" . $value;
153 160
  }
154
  elseif ((int)$title === $title) {
161
  elseif ((int) $title === $title) {
155 162
    echo "\n" . $value;
156 163
  }
157 164
  else {
......
159 166
  }
160 167

  
161 168
}
169

  
162 170
/**
163 171
 * Disconnect (unbind) from an active LDAP server.
164 172
 */
165 173
function ldap_help_disconnect(&$con) {
166 174
  if (!$con) {
167
    // never bound or not currently bound, so no need to disconnect
175
    // Never bound or not currently bound, so no need to disconnect.
168 176
  }
169 177
  else {
170 178
    ldap_help_disconnect($con);
......
172 180
  }
173 181
}
174 182

  
175
/** parse php modules from phpinfo */
183
/**
184
 * Parse php modules from phpinfo .*/
176 185
function ldap_help_parsePHPModules() {
177 186
  ob_start();
178 187
  phpinfo(INFO_MODULES);
179 188
  $s = ob_get_contents();
180 189
  ob_end_clean();
181
  $matches = array();
190
  $matches = [];
182 191
  preg_match_all("/(\nLDAP Support.*Vendor Version[^\n]*?).*$/iDsU", $s, $matches);
183 192
  return isset($matches[1][0]) ? "\nphpinfo() LDAP Info:" . $matches[1][0] : '';
184 193
}
185 194

  
195
/**
196
 *
197
 */
186 198
function ldap_help_encodePassword($password) {
187 199
  $password = "\"" . $password . "\"";
188 200
  $encoded = "";

Formats disponibles : Unified diff