You are here

function ldap_servers_settings_submit in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_servers/ldap_servers.settings.inc \ldap_servers_settings_submit()
  2. 7.2 ldap_servers/ldap_servers.settings.inc \ldap_servers_settings_submit()
1 string reference to 'ldap_servers_settings_submit'
ldap_servers_settings in ldap_servers/ldap_servers.settings.inc
@file admin interface for general ldap api settings

File

ldap_servers/ldap_servers.settings.inc, line 66
admin interface for general ldap api settings

Code

function ldap_servers_settings_submit($form, &$form_state) {
  if ($form_state['submitted']) {
    $new_encyption = $form_state['values']['ldap_servers_encryption'];
    $old_encyption = $form_state['values']['previous_encryption'];

    // use db instead of functions to avoid classes encryption and decryption
    if ($new_encyption != $old_encyption) {
      $servers = db_query("SELECT sid, bindpw FROM {ldap_servers} WHERE bindpw is not NULL AND bindpw <> ''")
        ->fetchAllAssoc('sid');
      foreach ($servers as $sid => $server) {
        $decrypted_bind_pwd = ldap_servers_decrypt($server->bindpw, $old_encyption);
        $rencrypted = ldap_servers_encrypt($decrypted_bind_pwd, $new_encyption);
        db_query("UPDATE {ldap_servers} SET bindpw = :bindpw WHERE sid = :sid", array(
          ':bindpw' => $rencrypted,
          ':sid' => $sid,
        ));
      }
    }
  }
}