| 1 |
<?php
|
| 2 |
// $Id: ldapauth.install,v 1.19 2009/07/20 19:35:40 miglius Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* ldapauth module installation and upgrade code.
|
| 7 |
*/
|
| 8 |
|
| 9 |
//////////////////////////////////////////////////////////////////////////////
|
| 10 |
// Core API hooks
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_install().
|
| 14 |
*/
|
| 15 |
function ldapauth_install() {
|
| 16 |
drupal_install_schema('ldapauth');
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_uninstall().
|
| 21 |
*/
|
| 22 |
function ldapauth_uninstall() {
|
| 23 |
// Remove tables.
|
| 24 |
drupal_uninstall_schema('ldapauth');
|
| 25 |
|
| 26 |
// Remove variables
|
| 27 |
variable_del('ldapauth_login_process');
|
| 28 |
variable_del('ldapauth_login_conflict');
|
| 29 |
variable_del('ldapauth_forget_passwords');
|
| 30 |
variable_del('ldapauth_sync_passwords');
|
| 31 |
variable_del('ldapauth_disable_pass_change');
|
| 32 |
variable_del('ldapauth_alter_email_field');
|
| 33 |
}
|
| 34 |
|
| 35 |
//////////////////////////////////////////////////////////////////////////////
|
| 36 |
// Schema API hooks
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_schema().
|
| 40 |
*/
|
| 41 |
function ldapauth_schema() {
|
| 42 |
$schema['ldapauth'] = array(
|
| 43 |
'fields' => array(
|
| 44 |
'sid' => array(
|
| 45 |
'type' => 'serial',
|
| 46 |
'size' => 'tiny',
|
| 47 |
'not null' => TRUE,
|
| 48 |
),
|
| 49 |
'name' => array(
|
| 50 |
'type' => 'varchar',
|
| 51 |
'length' => 255,
|
| 52 |
'not null' => TRUE,
|
| 53 |
),
|
| 54 |
'status' => array(
|
| 55 |
'type' => 'int',
|
| 56 |
'size' => 'tiny',
|
| 57 |
'not null' => TRUE,
|
| 58 |
'default' => 0,
|
| 59 |
),
|
| 60 |
'server' => array(
|
| 61 |
'type' => 'varchar',
|
| 62 |
'length' => 255,
|
| 63 |
'not null' => TRUE,
|
| 64 |
),
|
| 65 |
'port' => array(
|
| 66 |
'type' => 'int',
|
| 67 |
'not null' => TRUE,
|
| 68 |
'default' => 389,
|
| 69 |
),
|
| 70 |
'tls' => array(
|
| 71 |
'type' => 'int',
|
| 72 |
'size' => 'tiny',
|
| 73 |
'not null' => TRUE,
|
| 74 |
'default' => 0,
|
| 75 |
),
|
| 76 |
'encrypted' => array(
|
| 77 |
'type' => 'int',
|
| 78 |
'size' => 'tiny',
|
| 79 |
'not null' => TRUE,
|
| 80 |
'default' => 0,
|
| 81 |
),
|
| 82 |
'basedn' => array(
|
| 83 |
'type' => 'text',
|
| 84 |
),
|
| 85 |
'user_attr' => array(
|
| 86 |
'type' => 'varchar',
|
| 87 |
'length' => 255,
|
| 88 |
),
|
| 89 |
'mail_attr' => array(
|
| 90 |
'type' => 'varchar',
|
| 91 |
'length' => 255,
|
| 92 |
),
|
| 93 |
'binddn' => array(
|
| 94 |
'type' => 'varchar',
|
| 95 |
'length' => 255,
|
| 96 |
),
|
| 97 |
'bindpw' => array(
|
| 98 |
'type' => 'varchar',
|
| 99 |
'length' => 255,
|
| 100 |
),
|
| 101 |
'login_php' => array(
|
| 102 |
'type' => 'text',
|
| 103 |
'not null' => FALSE,
|
| 104 |
),
|
| 105 |
'filter_php' => array(
|
| 106 |
'type' => 'text',
|
| 107 |
'not null' => FALSE,
|
| 108 |
),
|
| 109 |
'weight' => array(
|
| 110 |
'type' => 'int',
|
| 111 |
'not null' => TRUE,
|
| 112 |
'default' => 0,
|
| 113 |
),
|
| 114 |
),
|
| 115 |
'primary key' => array('sid'),
|
| 116 |
'unique keys' => array('name' => array('name')),
|
| 117 |
);
|
| 118 |
return $schema;
|
| 119 |
}
|
| 120 |
|
| 121 |
//////////////////////////////////////////////////////////////////////////////
|
| 122 |
// Upgrades
|
| 123 |
|
| 124 |
function ldapauth_update_6000() {
|
| 125 |
$ret = array();
|
| 126 |
$result = db_query("SELECT * FROM {ldapauth}");
|
| 127 |
while ($row = db_fetch_object($result)) {
|
| 128 |
$servers[$row->name] = $row->sid;
|
| 129 |
}
|
| 130 |
if (!empty($servers)) {
|
| 131 |
$result = db_query("SELECT uid FROM {users} WHERE uid > '1'");
|
| 132 |
while ($row = db_fetch_object($result)) {
|
| 133 |
$account = user_load($row->uid);
|
| 134 |
if ($account->ldap_config && in_array($account->ldap_config, array_keys($servers))) {
|
| 135 |
user_save($account, array('ldap_config' => $servers[$account->ldap_config]));
|
| 136 |
}
|
| 137 |
}
|
| 138 |
}
|
| 139 |
return $ret;
|
| 140 |
}
|
| 141 |
|
| 142 |
function ldapauth_update_6001() {
|
| 143 |
$ret = array();
|
| 144 |
db_add_field($ret, 'ldapauth', 'login_php', array(
|
| 145 |
'type' => 'text',
|
| 146 |
'not null' => FALSE,
|
| 147 |
));
|
| 148 |
db_add_field($ret, 'ldapauth', 'filter_php', array(
|
| 149 |
'type' => 'text',
|
| 150 |
'not null' => FALSE,
|
| 151 |
));
|
| 152 |
db_add_field($ret, 'ldapauth', 'weight', array(
|
| 153 |
'type' => 'int',
|
| 154 |
'not null' => TRUE,
|
| 155 |
'default' => 0,
|
| 156 |
));
|
| 157 |
return $ret;
|
| 158 |
}
|
| 159 |
|
| 160 |
function ldapauth_update_6002() {
|
| 161 |
$ret = array();
|
| 162 |
db_change_field($ret, 'ldapauth', 'basedn', 'basedn', array(
|
| 163 |
'type' => 'text',
|
| 164 |
));
|
| 165 |
return $ret;
|
| 166 |
}
|
| 167 |
|
| 168 |
function ldapauth_update_6003() {
|
| 169 |
$ret = array();
|
| 170 |
db_drop_primary_key($ret, 'ldapauth');
|
| 171 |
db_change_field($ret, 'ldapauth', 'sid', 'sid', array('type' => 'serial', 'size' => 'tiny', 'not null' => TRUE), array('primary key' => array('sid')));
|
| 172 |
db_drop_index($ret, 'ldapauth', 'sid');
|
| 173 |
db_add_unique_key($ret, 'ldapauth', 'name', array('name'));
|
| 174 |
return $ret;
|
| 175 |
}
|
| 176 |
|