Index: cas.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cas/cas.module,v
retrieving revision 1.61
diff -u -r1.61 cas.module
--- cas.module	10 Nov 2009 16:17:48 -0000	1.61
+++ cas.module	16 Feb 2010 18:18:52 -0000
@@ -11,6 +11,7 @@
 define('CAS_NO_VERIFY', 'none');
 define('CAS_VERIFY', 'verify');
 define('CAS_CA_VERIFY', 'ca_verify');
+define('CAS_EXCLUDE','services/*'); 
 
 /**
  * Invokes hook_auth_transform() in every module.
@@ -109,13 +110,10 @@
     return; 
   }
   
-  // Determine whether we should check for long
-  $cas_check_first = variable_get('cas_check_first',1); 
-  
-  if ($_COOKIE['cas_login_checked']) { 
-    $cas_check_first = 0; 
-  }
   
+  // Determine whether we should check for long
+  $cas_check_first = _cas_allow_check_for_login(); 
+    
   $cas_force_login = _cas_force_login(); 
   
   if ($cas_force_login || $cas_check_first) {
@@ -232,6 +230,7 @@
       drupal_set_message("The username $cas_name has been blocked.", "error");
       return;
     }
+    
     if (drupal_is_denied('user', $cas_name)) {
       // denied by access controls
       drupal_set_message("The name $cas_name is a reserved username.", "error");
@@ -604,6 +603,16 @@
     '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page."),
   );
   
+  $form['pages']['cas_exclude'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Excluded Pages'),
+    '#default_value' => variable_get('cas_exclude', CAS_EXCLUDE),
+    '#cols' => 40,
+    '#rows' => 5,
+    '#description' => t("Indicates which pages will be ignored (no login checks). Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page."),
+  );
+  
+  
   // Settings for redirection upon first login
   $form['pages']['cas_first_login'] = array(
     '#type' => 'checkbox',
@@ -851,6 +860,55 @@
   $form_state['redirect'] = 'cas';
 }
 
+
+function _cas_allow_check_for_login() {
+
+    // Determine whether we should check for long
+  $cas_check_first = variable_get('cas_check_first',1);
+  if (!$cas_check_first) { 
+    return FALSE; 
+  }
+  
+  // Check to see if we already have. 
+  if ($_COOKIE['cas_login_checked']) { 
+    return FALSE; 
+  }
+
+  // No need if we're on the cas login page. 
+  list($arg0) = split('/', $_GET['q']);
+  // Don't even do the test if we're hitting the cas page
+  if ($arg0 == "cas") {
+    return FALSE;
+  }
+  
+  // Don't even do the test if cron.php or xmlrpc.php is invoked.  Don't check for logins.
+  if (base_path() .'cron.php' == $_SERVER['PHP_SELF'] || base_path() .'xmlrpc.php' == $_SERVER['PHP_SELF']) return FALSE;
+ // Drush
+  if (stristr($_SERVER['SCRIPT_FILENAME'], 'drush')) {
+    return FALSE;
+  }
+  // Drush
+  if (stristr($_SERVER['argv'][0], 'drush')) {
+    return FALSE;
+  }
+  
+  $pages = variable_get('cas_exclude', CAS_EXCLUDE);
+  
+  // Test against exclude pages. 
+  if ($pages) {
+    $path       = drupal_get_path_alias($_GET['q']);
+    $regexp     = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/';
+    $path_match = preg_match($regexp, $path);
+    
+    // Alter the default
+    if ($path_match) {
+      return FALSE; 
+    }
+  }
+  
+  return $cas_check_first; 
+}
+
 /**
  * Determines whether cas login should be enforced for this page load.
  * This is done based on the redirection settings for this module.
@@ -866,6 +924,15 @@
   // Don't even do the test if cron.php or xmlrpc.php is invoked.  Don't require login.
   if (base_path() .'cron.php' == $_SERVER['PHP_SELF'] || base_path() .'xmlrpc.php' == $_SERVER['PHP_SELF']) return FALSE;
   
+ // Drush
+  if (stristr($_SERVER['SCRIPT_FILENAME'], 'drush')) {
+    return FALSE;
+  }
+  // Drush
+  if (stristr($_SERVER['argv'][0], 'drush')) {
+    return FALSE;
+  }
+  
   // set the default behavior
   if (variable_get('cas_access', 0) == 1) {
     $force_login = TRUE;
@@ -874,6 +941,20 @@
     $force_login = FALSE;
   }
   
+  
+  // Test against exclude pages. 
+  $pages = variable_get('cas_exclude', CAS_EXCLUDE);
+  if ($pages) {
+    $path       = drupal_get_path_alias($_GET['q']);
+    $regexp     = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/';
+    $path_match = preg_match($regexp, $path);
+    
+    // Alter the default
+    if ($path_match) {
+      return FALSE; 
+    }
+  }
+  
   $pages = variable_get('cas_pages', '');
   // This common page matching logic used throughout drupal.
   if ($pages) {
