function ldapAssociateDrupalAccount($drupal_username) {

    if ($this->drupalAcctProvisionServer) {
      $prov_events = array(LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT);
      $ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, 'enabled', TRUE);  // $ldap_user['sid']
      $account = user_load_by_name($drupal_username);
      $ldap_user = ldap_servers_get_user_ldap_data($drupal_username, $this->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
      if (!$account) {
        watchdog(
          'ldap_user',
          'Failed to LDAP associate drupal account %drupal_username because account not found',
          array('%drupal_username' => $drupal_username),
          WATCHDOG_ERROR
        );
        return FALSE;
      }
      elseif (!$ldap_user) {
        watchdog(
          'ldap_user',
          'Failed to LDAP associate drupal account %drupal_username because corresponding LDAP entry not found',
          array('%drupal_username' => $drupal_username),
          WATCHDOG_ERROR
        );
        return FALSE;
      }
      else {
        $user_edit = array();
        $user_edit['data']['ldap_user']['init'] = array(
          'sid'  => $ldap_user['sid'],
          'dn'   => $ldap_user['dn'],
          'mail'   => $account->mail,
        );
        $ldap_user_puid = $ldap_server->userPuidFromLdapEntry($ldap_user['attr']);
        if ($ldap_user_puid) {
          $user_edit['ldap_user_puid'][LANGUAGE_NONE][0]['value'] = $ldap_user_puid; //
        }
        $user_edit['ldap_user_puid_property'][LANGUAGE_NONE][0]['value'] = $ldap_server->unique_persistent_attr;
        $user_edit['ldap_user_puid_sid'][LANGUAGE_NONE][0]['value'] = $ldap_server->sid;
        $user_edit['ldap_user_current_dn'][LANGUAGE_NONE][0]['value'] = $ldap_user['dn'];
        $account = user_save($account, $user_edit, 'ldap_user');
        return (boolean)$account;
      }
    }
    else {
      return FALSE;
    }
  }
function ldapAssociateDrupalAccount($drupal_username) {

    if ($this->drupalAcctProvisionServer) {
      $prov_events = array(LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT);
      $ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, 'enabled', TRUE);  // $ldap_user['sid']
      $account = user_load_by_name($drupal_username);
      $ldap_user = ldap_servers_get_user_ldap_data($drupal_username, $this->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
      if (!$account) {
        watchdog(
          'ldap_user',
          'Failed to LDAP associate drupal account %drupal_username because account not found',
          array('%drupal_username' => $drupal_username),
          WATCHDOG_ERROR
        );
        return FALSE;
      }
      elseif (!$ldap_user) {
        watchdog(
          'ldap_user',
          'Failed to LDAP associate drupal account %drupal_username because corresponding LDAP entry not found',
          array('%drupal_username' => $drupal_username),
          WATCHDOG_ERROR
        );
        return FALSE;
      }
      else {
        $user_edit = array();
        $user_edit['data']['ldap_user']['init'] = array(
          'sid'  => $ldap_user['sid'],
          'dn'   => $ldap_user['dn'],
          'mail'   => $account->mail,
        );
        $ldap_user_puid = $ldap_server->userPuidFromLdapEntry($ldap_user['attr']);
        if ($ldap_user_puid) {
          $user_edit['ldap_user_puid'][LANGUAGE_NONE][0]['value'] = $ldap_user_puid; //
        }
        $user_edit['ldap_user_puid_property'][LANGUAGE_NONE][0]['value'] = $ldap_server->unique_persistent_attr;
        $user_edit['ldap_user_puid_sid'][LANGUAGE_NONE][0]['value'] = $ldap_server->sid;
        $user_edit['ldap_user_current_dn'][LANGUAGE_NONE][0]['value'] = $ldap_user['dn'];
        $account = user_save($account, $user_edit, 'ldap_user');
        return (boolean)$account;
      }
    }
    else {
      return FALSE;
    }
  }
function ldapAssociateDrupalAccount ( $ drupal_username ) { if ( $ this -> drupalAcctProvisionServer ) { $ prov_events = array ( LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT ) ; $ ldap_server = ldap_servers_get_servers ( $ this -> drupalAcctProvisionServer , 'enabled' , TRUE ) ; // $ldap_user['sid'] $ account = user_load_by_name ( $ drupal_username ) ; $ ldap_user = ldap_servers_get_user_ldap_data ( $ drupal_username , $ this -> drupalAcctProvisionServer , 'ldap_user_prov_to_drupal' ) ; if ( ! $ account ) { watchdog ( 'ldap_user' , 'Failed to LDAP associate drupal account %drupal_username because account not found' , array ( '%drupal_username' => $ drupal_username ) , WATCHDOG_ERROR ) ; return FALSE ; } elseif ( ! $ ldap_user ) { watchdog ( 'ldap_user' , 'Failed to LDAP associate drupal account %drupal_username because corresponding LDAP entry not found' , array ( '%drupal_username' => $ drupal_username ) , WATCHDOG_ERROR ) ; return FALSE ; } else { $ user_edit = array ( ) ; $ user_edit [ 'data' ] [ 'ldap_user' ] [ 'init' ] = array ( 'sid' => $ ldap_user [ 'sid' ] , 'dn' => $ ldap_user [ 'dn' ] , 'mail' => $ account -> mail , ) ; $ ldap_user_puid = $ ldap_server -> userPuidFromLdapEntry ( $ ldap_user [ 'attr' ] ) ; if ( $ ldap_user_puid ) { $ user_edit [ 'ldap_user_puid' ] [ LANGUAGE_NONE ] [ 0 ] [ 'value' ] = $ ldap_user_puid ; // } $ user_edit [ 'ldap_user_puid_property' ] [ LANGUAGE_NONE ] [ 0 ] [ 'value' ] = $ ldap_server -> unique_persistent_attr ; $ user_edit [ 'ldap_user_puid_sid' ] [ LANGUAGE_NONE ] [ 0 ] [ 'value' ] = $ ldap_server -> sid ; $ user_edit [ 'ldap_user_current_dn' ] [ LANGUAGE_NONE ] [ 0 ] [ 'value' ] = $ ldap_user [ 'dn' ] ; $ account = user_save ( $ account , $ user_edit , 'ldap_user' ) ; return ( boolean ) $ account ; } } else { return FALSE ; } }
set ldap associations of a drupal account by altering user fields

@param string $drupal_username

@return boolean TRUE on success, FALSE on error or failure because of invalid user or ldap accounts
set ldap associations of a drupal account by altering user fields