Index: cas.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cas/cas.module,v
retrieving revision 1.50
diff -u -r1.50 cas.module
--- cas.module	29 May 2009 18:02:12 -0000	1.50
+++ cas.module	29 May 2009 21:09:23 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: cas.module,v 1.50 2009/05/29 18:02:12 metzlerd Exp $
+// $Id: cas.module,v 1.48 2009/05/29 16:56:37 metzlerd Exp $
 
 /**
  * @file Enables users to authenticate via a Central Authentication Service (CAS)
@@ -160,7 +160,7 @@
     }
     
     $cas_name = phpCAS::getUser();
-
+    
     /*
      * Invoke hook_auth_transform($op, &$username)
      *
@@ -185,16 +185,23 @@
     }
     
     // blocked user check
-    if (user_is_blocked($cas_name)) {
+    
+    if ($cas_authmap && user_is_blocked($cas_name)) {
+      // blocked in user administration
+      drupal_set_message("The username $cas_name has been blocked.", "error");
+      return;
+    }
+    // this is because users can change their name. 
+    if (!$cas_authmap && _cas_external_user_is_blocked($cas_name)) {
       // blocked in user administration
       drupal_set_message("The username $cas_name has been blocked.", "error");
       return;
     }
-    else if (drupal_is_denied('user', $cas_name)) {
+    if (drupal_is_denied('user', $cas_name)) {
       // denied by access controls
       drupal_set_message("The name $cas_name is a reserved username.", "error");
       return;
-    }
+    } 
     
     // try to log into Drupal
     if ($cas_authmap) {
@@ -824,12 +831,12 @@
           if (!$form['account']['mail']['#default_value']) {
             $form['account']['mail']['#value'] = $form['account']['name']['#default_value'] .'@'. variable_get('cas_domain', '');
           }
+          
         }
         
         /*
         ** LDAPAuth interfacing - BEGIN
         */
-        
         if (variable_get('cas_useldap', '')) {
           global $ldapauth_ldap, $user;
           if ($ldap_config_name = _get_ldap_config_name($user->name)) {
@@ -840,7 +847,7 @@
             if ($ldap_entries['count'] == 1 && isset($ldap_entries[0][$cas_ldap_email_attribute][0])) if (trim($ldap_entries[0][$cas_ldap_email_attribute][0]) != '') {
               $form['account']['mail']['#type'] = 'hidden';
               $form['account']['mail']['#value'] = $ldap_entries[0][$cas_ldap_email_attribute][0];
-            }
+              }
           }
         }
         
@@ -932,4 +939,10 @@
 
 /*
 ** CAS Sigle Sign Out - END
-*/
\ No newline at end of file
+*/
+
+function _cas_external_user_is_blocked($name) {
+  $deny = db_fetch_object(db_query("SELECT u.name FROM {users} u JOIN {authmap} m ON u.uid=m.uid WHERE status = 0 AND m.authname = LOWER('%s')", $name));
+  return $deny;
+}
+
