1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Install, update and uninstall functions for the LDAP User module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Implements hook_requirements().
|
11 |
|
|
*/
|
12 |
|
|
function ldap_user_requirements($phase) {
|
13 |
|
|
|
14 |
|
|
$requirements = array();
|
15 |
|
|
|
16 |
|
|
if ($phase == 'runtime') {
|
17 |
|
|
|
18 |
|
|
// check for all $user->* fields created
|
19 |
|
|
$missing_fields = ldap_user_update_check_user_fields(TRUE);
|
20 |
|
|
if (count($missing_fields)) {
|
21 |
|
|
$requirements['ldap_user']['title'] = t('User Fields for LDAP User Module Missing');
|
22 |
|
|
$requirements['ldap_user']['severity'] = REQUIREMENT_ERROR;
|
23 |
|
|
$requirements['ldap_user']['value'] = NULL;
|
24 |
|
|
|
25 |
|
|
$requirements['ldap_user']['description'] = t('Fields are added to the
|
26 |
|
|
Drupal User entity for LDAP User module functionality. These fields should
|
27 |
|
|
have been created in LDAP User update 7203. The following userfields are missing:') .
|
28 |
|
|
theme('item_list', array(
|
29 |
|
|
'items' => $missing_fields,
|
30 |
|
|
'type' => 'ul',
|
31 |
|
|
'title' => NULL,
|
32 |
|
|
)) .
|
33 |
|
|
t('Rerun update 7203 to correct this; it will not write over destroy existing fields.');
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
// check that ldapauth not installed.
|
39 |
|
|
return $requirements;
|
40 |
|
|
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* Implements hook_install().
|
45 |
|
|
*/
|
46 |
|
|
function ldap_user_install() {
|
47 |
|
|
|
48 |
|
|
foreach (ldap_user_user_entity_fields() as $field_id => $field_conf) {
|
49 |
|
|
$field_info = field_info_field($field_id);
|
50 |
|
|
if (!$field_info) {
|
51 |
|
|
field_create_field($field_conf['field']);
|
52 |
|
|
field_create_instance($field_conf['instance']);
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
// make ldap user weight slightly less than other ldap modules so it can load
|
57 |
|
|
// user's associated ldap data first and save on ldap queries.
|
58 |
|
|
|
59 |
|
|
db_query("UPDATE {system} SET weight = -1 WHERE name = 'ldap_user'");
|
60 |
|
|
|
61 |
|
|
_ldap_user_install_update_authmap();
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
function _ldap_user_install_update_authmap() {
|
68 |
|
|
db_update('authmap')
|
69 |
|
|
->fields(
|
70 |
|
|
array(
|
71 |
|
|
'module' => 'ldap_user',
|
72 |
|
|
)
|
73 |
|
|
)
|
74 |
|
|
->condition('module', 'ldap_authentication')
|
75 |
|
|
->execute();
|
76 |
|
|
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Implements hook_uninstall().
|
81 |
|
|
*/
|
82 |
|
|
function ldap_user_uninstall() {
|
83 |
|
|
|
84 |
|
|
foreach (ldap_user_user_entity_fields() as $field_id => $field_conf) {
|
85 |
|
|
|
86 |
|
|
$instance = field_info_instance($field_conf['instance']['entity_type'], $field_conf['instance']['field_name'], $field_conf['instance']['bundle']);
|
87 |
|
|
if ($instance) {
|
88 |
|
|
field_delete_instance($instance);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
$field_info = field_info_field($field_conf['field']['field_name']);
|
92 |
|
|
if ($field_info) {
|
93 |
|
|
field_delete_field($field_conf['field']['field_name']);
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
variable_del('ldap_user_conf');
|
98 |
|
|
variable_del('ldap_user_cron_last_orphan_checked');
|
99 |
|
|
variable_del('ldap_user_cron_last_uid_checked');
|
100 |
|
|
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Implements hook_schema().
|
105 |
|
|
*/
|
106 |
|
|
function ldap_user_schema() {
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
// see http://api.drupal.org/api/drupal/modules%21field%21field.module/group/field/7
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
function ldap_user_user_entity_fields() {
|
116 |
|
|
|
117 |
|
|
$fields = array();
|
118 |
|
|
|
119 |
|
|
$field_name = 'ldap_user_puid_sid';
|
120 |
|
|
$fields[$field_name]['field'] = array(
|
121 |
|
|
'field_name' => $field_name,
|
122 |
|
|
'type' => 'text',
|
123 |
|
|
'entity_types' => array('user'),
|
124 |
|
|
'cardinality' => 1,
|
125 |
|
|
'translatable' => 0,
|
126 |
|
|
'locked' => 1,
|
127 |
|
|
'module' => 'text',
|
128 |
|
|
'no_ui' => 1,
|
129 |
|
|
'settings' => array(),
|
130 |
|
|
);
|
131 |
|
|
|
132 |
|
|
$fields[$field_name]['instance'] = array(
|
133 |
|
|
'field_name' => $field_name,
|
134 |
|
|
'entity_type' => 'user',
|
135 |
|
|
'bundle' => 'user',
|
136 |
|
|
'label' => 'LDAP Server ID that puid was derived from. NULL if puid is independent of server configuration instance.',
|
137 |
|
|
'description' => 'This field should not be edited.',
|
138 |
|
|
'required' => 0,
|
139 |
|
|
'default_value_function' => 'ldap_user_provisioned_sid_default',
|
140 |
|
|
'settings' => array(
|
141 |
|
|
'text_processing' => 0,
|
142 |
|
|
),
|
143 |
|
|
'widget' => array(
|
144 |
|
|
'type' => 'ldap_user_hidden',
|
145 |
|
|
'settings' => array(),
|
146 |
|
|
'module' => 'ldap_user',
|
147 |
|
|
),
|
148 |
|
|
'display' => array(
|
149 |
|
|
'default' => array(
|
150 |
|
|
'label' => 'hidden',
|
151 |
|
|
'type' => 'hidden',
|
152 |
|
|
),
|
153 |
|
|
'full' => array(
|
154 |
|
|
'label' => 'hidden',
|
155 |
|
|
'type' => 'hidden',
|
156 |
|
|
),
|
157 |
|
|
'teaser' => array(
|
158 |
|
|
'label' => 'hidden',
|
159 |
|
|
'type' => 'hidden',
|
160 |
|
|
),
|
161 |
|
|
));
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
$field_name = 'ldap_user_puid';
|
165 |
|
|
$fields[$field_name]['field'] = array(
|
166 |
|
|
'field_name' => $field_name,
|
167 |
|
|
'type' => 'text',
|
168 |
|
|
'entity_types' => array('user'),
|
169 |
|
|
'cardinality' => 1,
|
170 |
|
|
'translatable' => 0,
|
171 |
|
|
'locked' => 1,
|
172 |
|
|
'module' => 'text',
|
173 |
|
|
'no_ui' => 1,
|
174 |
|
|
'settings' => array(),
|
175 |
|
|
);
|
176 |
|
|
|
177 |
|
|
$fields[$field_name]['instance'] = array(
|
178 |
|
|
'field_name' => $field_name,
|
179 |
|
|
'entity_type' => 'user',
|
180 |
|
|
'bundle' => 'user',
|
181 |
|
|
'label' => 'Value of user\'s permanent unique id. This should never change for a given ldap identified user.',
|
182 |
|
|
'description' => 'This field should not be edited.',
|
183 |
|
|
'required' => 0,
|
184 |
|
|
'default_value_function' => 'ldap_user_puid_default',
|
185 |
|
|
'settings' => array(
|
186 |
|
|
'text_processing' => 0,
|
187 |
|
|
),
|
188 |
|
|
'widget' => array(
|
189 |
|
|
'type' => 'ldap_user_hidden',
|
190 |
|
|
'settings' => array(),
|
191 |
|
|
'module' => 'ldap_user',
|
192 |
|
|
),
|
193 |
|
|
'display' => array(
|
194 |
|
|
'default' => array(
|
195 |
|
|
'label' => 'hidden',
|
196 |
|
|
'type' => 'hidden',
|
197 |
|
|
),
|
198 |
|
|
'full' => array(
|
199 |
|
|
'label' => 'hidden',
|
200 |
|
|
'type' => 'hidden',
|
201 |
|
|
),
|
202 |
|
|
'teaser' => array(
|
203 |
|
|
'label' => 'hidden',
|
204 |
|
|
'type' => 'hidden',
|
205 |
|
|
),
|
206 |
|
|
));
|
207 |
|
|
|
208 |
|
|
$field_name = 'ldap_user_puid_property';
|
209 |
|
|
$fields[$field_name]['field'] = array(
|
210 |
|
|
'field_name' => $field_name,
|
211 |
|
|
'type' => 'text',
|
212 |
|
|
'entity_types' => array('user'),
|
213 |
|
|
'cardinality' => 1,
|
214 |
|
|
'translatable' => 0,
|
215 |
|
|
'locked' => 1,
|
216 |
|
|
'module' => 'text',
|
217 |
|
|
'no_ui' => 1,
|
218 |
|
|
'settings' => array(),
|
219 |
|
|
);
|
220 |
|
|
|
221 |
|
|
$fields[$field_name]['instance'] = array(
|
222 |
|
|
'field_name' => $field_name,
|
223 |
|
|
'entity_type' => 'user',
|
224 |
|
|
'bundle' => 'user',
|
225 |
|
|
'label' => 'Property specified as user\'s puid.',
|
226 |
|
|
'description' => 'This field should not be edited.',
|
227 |
|
|
'required' => 0,
|
228 |
|
|
'default_value_function' => 'ldap_user_puid_property_default',
|
229 |
|
|
'settings' => array(
|
230 |
|
|
'text_processing' => 0,
|
231 |
|
|
),
|
232 |
|
|
'widget' => array(
|
233 |
|
|
'type' => 'ldap_user_hidden',
|
234 |
|
|
'settings' => array(),
|
235 |
|
|
'module' => 'ldap_user',
|
236 |
|
|
),
|
237 |
|
|
'display' => array(
|
238 |
|
|
'default' => array(
|
239 |
|
|
'label' => 'hidden',
|
240 |
|
|
'type' => 'hidden',
|
241 |
|
|
),
|
242 |
|
|
'full' => array(
|
243 |
|
|
'label' => 'hidden',
|
244 |
|
|
'type' => 'hidden',
|
245 |
|
|
),
|
246 |
|
|
'teaser' => array(
|
247 |
|
|
'label' => 'hidden',
|
248 |
|
|
'type' => 'hidden',
|
249 |
|
|
),
|
250 |
|
|
));
|
251 |
|
|
|
252 |
|
|
$field_name = 'ldap_user_current_dn';
|
253 |
|
|
$fields[$field_name]['field'] = array(
|
254 |
|
|
'field_name' => $field_name,
|
255 |
|
|
'type' => 'text',
|
256 |
|
|
'entity_types' => array('user'),
|
257 |
|
|
'cardinality' => 1,
|
258 |
|
|
'translatable' => 0,
|
259 |
|
|
'locked' => 1,
|
260 |
|
|
'module' => 'text',
|
261 |
|
|
'no_ui' => 1,
|
262 |
|
|
'settings' => array(),
|
263 |
|
|
);
|
264 |
|
|
|
265 |
|
|
$fields[$field_name]['instance'] = array(
|
266 |
|
|
'field_name' => $field_name,
|
267 |
|
|
'entity_type' => 'user',
|
268 |
|
|
'bundle' => 'user',
|
269 |
|
|
'label' => 'User LDAP DN',
|
270 |
|
|
'description' => 'May change when user\'s DN changes. This field should not be edited.',
|
271 |
|
|
'required' => 0,
|
272 |
|
|
'default_value_function' => 'ldap_user_dn_default',
|
273 |
|
|
'settings' => array(
|
274 |
|
|
'text_processing' => 0,
|
275 |
|
|
),
|
276 |
|
|
'widget' => array(
|
277 |
|
|
'type' => 'ldap_user_hidden',
|
278 |
|
|
'settings' => array(),
|
279 |
|
|
'module' => 'ldap_user',
|
280 |
|
|
),
|
281 |
|
|
'display' => array(
|
282 |
|
|
'default' => array(
|
283 |
|
|
'label' => 'hidden',
|
284 |
|
|
'type' => 'hidden',
|
285 |
|
|
),
|
286 |
|
|
'full' => array(
|
287 |
|
|
'label' => 'hidden',
|
288 |
|
|
'type' => 'hidden',
|
289 |
|
|
),
|
290 |
|
|
'teaser' => array(
|
291 |
|
|
'label' => 'hidden',
|
292 |
|
|
'type' => 'hidden',
|
293 |
|
|
),
|
294 |
|
|
));
|
295 |
|
|
|
296 |
|
|
$field_name = 'ldap_user_prov_entries';
|
297 |
|
|
$fields[$field_name]['field'] = array(
|
298 |
|
|
'field_name' => $field_name,
|
299 |
|
|
'type' => 'text',
|
300 |
|
|
'entity_types' => array('user'),
|
301 |
|
|
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
302 |
|
|
'translatable' => 0,
|
303 |
|
|
'locked' => 1,
|
304 |
|
|
'module' => 'text',
|
305 |
|
|
'no_ui' => 1,
|
306 |
|
|
'settings' => array(),
|
307 |
|
|
);
|
308 |
|
|
|
309 |
|
|
$fields[$field_name]['instance'] = array(
|
310 |
|
|
'field_name' => $field_name,
|
311 |
|
|
'entity_type' => 'user',
|
312 |
|
|
'bundle' => 'user',
|
313 |
|
|
'label' => 'LDAP Entries that have been provisioned from this Drupal user.',
|
314 |
|
|
'description' => 'This field should not be edited.',
|
315 |
|
|
'required' => 0,
|
316 |
|
|
'default_value' => NULL,
|
317 |
|
|
'settings' => array(
|
318 |
|
|
'text_processing' => 0,
|
319 |
|
|
),
|
320 |
|
|
'widget' => array(
|
321 |
|
|
'type' => 'ldap_user_hidden',
|
322 |
|
|
'settings' => array(),
|
323 |
|
|
'module' => 'ldap_user',
|
324 |
|
|
),
|
325 |
|
|
'display' => array(
|
326 |
|
|
'default' => array(
|
327 |
|
|
'label' => 'hidden',
|
328 |
|
|
'type' => 'hidden',
|
329 |
|
|
),
|
330 |
|
|
'full' => array(
|
331 |
|
|
'label' => 'hidden',
|
332 |
|
|
'type' => 'hidden',
|
333 |
|
|
),
|
334 |
|
|
'teaser' => array(
|
335 |
|
|
'label' => 'hidden',
|
336 |
|
|
'type' => 'hidden',
|
337 |
|
|
),
|
338 |
|
|
));
|
339 |
|
|
|
340 |
|
|
$field_name = 'ldap_user_last_checked';
|
341 |
|
|
$fields[$field_name]['field'] = array(
|
342 |
|
|
'field_name' => $field_name,
|
343 |
|
|
'type' => 'number_integer',
|
344 |
|
|
'entity_types' => array('user'),
|
345 |
|
|
'cardinality' => 1,
|
346 |
|
|
'translatable' => 0,
|
347 |
|
|
'locked' => 1,
|
348 |
|
|
'module' => 'number',
|
349 |
|
|
'no_ui' => 1,
|
350 |
|
|
'settings' => array(),
|
351 |
|
|
);
|
352 |
|
|
|
353 |
|
|
$fields[$field_name]['instance'] = array(
|
354 |
|
|
'field_name' => $field_name,
|
355 |
|
|
'entity_type' => 'user',
|
356 |
|
|
'bundle' => 'user',
|
357 |
|
|
'label' => 'Unix timestamp of when Drupal user was compard to ldap entry. This could be for purposes of synching, deleteing drupal account, etc.',
|
358 |
|
|
'description' => 'This field should not be edited.',
|
359 |
|
|
'required' => 0,
|
360 |
|
|
'default_value' => NULL,
|
361 |
|
|
'settings' => array(
|
362 |
|
|
),
|
363 |
|
|
'widget' => array(
|
364 |
|
|
'type' => 'ldap_user_hidden',
|
365 |
|
|
'settings' => array(),
|
366 |
|
|
'module' => 'ldap_user',
|
367 |
|
|
),
|
368 |
|
|
'display' => array(
|
369 |
|
|
'default' => array(
|
370 |
|
|
'label' => 'hidden',
|
371 |
|
|
'type' => 'hidden',
|
372 |
|
|
),
|
373 |
|
|
'full' => array(
|
374 |
|
|
'label' => 'hidden',
|
375 |
|
|
'type' => 'hidden',
|
376 |
|
|
),
|
377 |
|
|
'teaser' => array(
|
378 |
|
|
'label' => 'hidden',
|
379 |
|
|
'type' => 'hidden',
|
380 |
|
|
),
|
381 |
|
|
));
|
382 |
|
|
|
383 |
|
|
$field_name = 'ldap_user_ldap_exclude';
|
384 |
|
|
$fields[$field_name]['field'] = array(
|
385 |
|
|
'field_name' => $field_name,
|
386 |
|
|
'type' => 'number_integer',
|
387 |
|
|
'entity_types' => array('user'),
|
388 |
|
|
'cardinality' => 1,
|
389 |
|
|
'translatable' => 0,
|
390 |
|
|
'locked' => 1,
|
391 |
|
|
'module' => 'number',
|
392 |
|
|
'no_ui' => 1,
|
393 |
|
|
'settings' => array(),
|
394 |
|
|
);
|
395 |
|
|
|
396 |
|
|
$fields[$field_name]['instance'] = array(
|
397 |
|
|
'field_name' => $field_name,
|
398 |
|
|
'entity_type' => 'user',
|
399 |
|
|
'bundle' => 'user',
|
400 |
|
|
'label' => 'Whether to exclude the user from LDAP functionality',
|
401 |
|
|
'description' => 'This field should not be edited.',
|
402 |
|
|
'required' => 0,
|
403 |
|
|
'default_value' => 0,
|
404 |
|
|
'settings' => array(
|
405 |
|
|
),
|
406 |
|
|
'widget' => array(
|
407 |
|
|
'type' => 'ldap_user_hidden',
|
408 |
|
|
'settings' => array(),
|
409 |
|
|
'module' => 'ldap_user',
|
410 |
|
|
),
|
411 |
|
|
'display' => array(
|
412 |
|
|
'default' => array(
|
413 |
|
|
'label' => 'hidden',
|
414 |
|
|
'type' => 'hidden',
|
415 |
|
|
),
|
416 |
|
|
'full' => array(
|
417 |
|
|
'label' => 'hidden',
|
418 |
|
|
'type' => 'hidden',
|
419 |
|
|
),
|
420 |
|
|
'teaser' => array(
|
421 |
|
|
'label' => 'hidden',
|
422 |
|
|
'type' => 'hidden',
|
423 |
|
|
),
|
424 |
|
|
));
|
425 |
|
|
|
426 |
|
|
return $fields;
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
/**
|
431 |
|
|
* update authmap table, changing ldap_authentication to ldap_user, disable ldap_profile
|
432 |
|
|
*/
|
433 |
|
|
|
434 |
|
|
function ldap_user_update_7201() {
|
435 |
|
|
if (module_exists('ldap_profile')) {
|
436 |
|
|
module_disable(array('ldap_profile', TRUE));
|
437 |
|
|
}
|
438 |
|
|
_ldap_user_install_update_authmap();
|
439 |
|
|
}
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
/**
|
443 |
|
|
* attach ldap_user_last_checked field to user entity to track reconciliation of ldap and drupal accounts
|
444 |
|
|
*/
|
445 |
|
|
|
446 |
|
|
function ldap_user_update_7202() {
|
447 |
|
|
|
448 |
|
|
return t('ldap_user_last_checked field added to user entity.');
|
449 |
|
|
|
450 |
|
|
}
|
451 |
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
/**
|
455 |
|
|
* make sure all user entity fields are created
|
456 |
|
|
*/
|
457 |
|
|
function ldap_user_update_7203() {
|
458 |
|
|
|
459 |
|
|
if (module_exists('ldap_groups')) {
|
460 |
|
|
module_disable(array('ldap_groups', TRUE));
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
$fields_added = ldap_user_update_check_user_fields();
|
464 |
|
|
|
465 |
|
|
if (count($fields_added)) {
|
466 |
|
|
$fields = join(', ', $fields_added);
|
467 |
|
|
return t('%fields added to user entity.', array('%fields' => $fields));
|
468 |
|
|
}
|
469 |
|
|
else {
|
470 |
|
|
return t('no fields needed to be added to user entity.');
|
471 |
|
|
}
|
472 |
|
|
|
473 |
|
|
}
|
474 |
|
|
|
475 |
|
|
/**
|
476 |
|
|
* make sure all user entity field instances are created
|
477 |
|
|
*/
|
478 |
|
|
function ldap_user_update_7204() {
|
479 |
|
|
|
480 |
|
|
$fields_added = ldap_user_update_check_user_fields();
|
481 |
|
|
|
482 |
|
|
if (count($fields_added)) {
|
483 |
|
|
$fields = join(', ', $fields_added);
|
484 |
|
|
return t('%fields added to user entity.', array('%fields' => $fields));
|
485 |
|
|
}
|
486 |
|
|
else {
|
487 |
|
|
return t('no fields needed to be added to user entity.');
|
488 |
|
|
}
|
489 |
|
|
|
490 |
|
|
}
|
491 |
|
|
|
492 |
|
|
/**
|
493 |
|
|
* make sure all user entity field instances are created
|
494 |
|
|
*/
|
495 |
|
|
function ldap_user_update_7205() {
|
496 |
|
|
|
497 |
|
|
return ldap_user_update_7204();
|
498 |
|
|
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
function ldap_user_update_check_user_fields($query = FALSE) {
|
502 |
|
|
if (!$query) {
|
503 |
|
|
module_enable(array('number'));
|
504 |
|
|
}
|
505 |
|
|
$fields_added = array();
|
506 |
|
|
foreach (ldap_user_user_entity_fields() as $field_id => $field_conf) {
|
507 |
|
|
$field_info = field_info_field($field_id);
|
508 |
|
|
if (!$field_info) {
|
509 |
|
|
$fields_added[] = $field_id;
|
510 |
|
|
if (!$query) {
|
511 |
|
|
field_create_field($field_conf['field']);
|
512 |
|
|
}
|
513 |
|
|
}
|
514 |
|
|
$field_instance_info = field_info_instance('user', $field_id, 'user');
|
515 |
|
|
if (!$field_instance_info) {
|
516 |
|
|
$fields_added[] = $field_id . " instance";
|
517 |
|
|
if (!$query) {
|
518 |
|
|
field_create_instance($field_conf['instance']);
|
519 |
|
|
}
|
520 |
|
|
}
|
521 |
|
|
}
|
522 |
|
|
return $fields_added;
|
523 |
|
|
|
524 |
|
|
} |