Index: webserver_auth.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webserver_auth/Attic/webserver_auth.module,v
retrieving revision 1.22.2.1
diff -u -d -F^\s*function -r1.22.2.1 webserver_auth.module
--- webserver_auth.module	7 Aug 2008 16:38:49 -0000	1.22.2.1
+++ webserver_auth.module	15 Aug 2008 15:51:02 -0000
@@ -13,9 +13,46 @@ function webserver_auth_menu() {
     'page arguments' => array('webserver_auth_settings'),
     'access arguments' => array('administer site configuration'),
   );
+
+  $items['authenticate'] = array(
+    'title' => t('Authentication'),
+    'page callback' => 'webserver_auth_verify',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
+function webserver_auth_verify() {
+  global $user;
+
+  $segment = drupal_get_normal_path(parse_url(substr(request_uri(), drupal_strlen(base_path())), PHP_URL_PATH));
+  if (($position = strpos($segment, '/')) !== FALSE) {
+    $segment = substr($segment, 0, $position);
+  }
+
+  if (!$user->uid && $segment != arg(0)) {
+    // The user is not logged in and hasn't visited the authentication URL.
+    $destination = 'destination=';
+
+    if (isset($_REQUEST['destination'])) {
+      $destination .= $_REQUEST['destination'];
+      unset($_REQUEST['destination']);
+    }
+
+    drupal_goto('authenticate', $destination);
+  }
+  elseif ($user->uid && $segment == arg(0)) {
+    // The user managed to authenticate with this URL; send him to his destination.
+    drupal_goto();
+  }
+
+  // In all other cases, deny the access.
+  // Poison the cache so that drupal_access_denied() doesn't go in a loop.
+  $GLOBALS['conf']['site_403'] = '';
+}
+
 /**
  * Implementation of hook_init().
  */
