--- /webserver_auth.module	Mon Sep 22 14:33:00 2008
+++ /webserver_auth.module	Mon Sep 22 14:00:44 2008
@@ -17,6 +17,19 @@
 }
 
 /**
+ * Implementation of hook_menu_alter().
+ */
+function webserver_auth_menu_alter(&$items) {
+//
+  if (variable_get('webserver_auth_hide_logout', FALSE)) {
+    $items['logout']['type'] = MENU_CALLBACK;
+  }
+  else {
+    $items['logout']['type'] = MENU_NORMAL_ITEM;
+  }
+}
+
+/**
  * Implementation of hook_init().
  */
 function webserver_auth_init() {
@@ -24,6 +37,11 @@
 
   $authname = '';
 
+  $q = arg(0);
+  // Bypass webserver_auth in the appropriate cases
+  if (($q == 'logout') || ($q == 'user') || ($user->uid == 1))
+    return;
+
   // Make sure we get the remote user whichever way it is available.
   if (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
     $authname = $_SERVER['REDIRECT_REMOTE_USER'];
@@ -47,7 +65,7 @@
   else {
     if (!empty($authname)) {
       // User is logged into webserver via HTTP authentication.
-      // Try to log into Drupal. 
+      // Try to log into Drupal.
       $user = user_external_load($authname);
 
       if (!$user) {
@@ -90,6 +108,7 @@
     global $base_url;
     // kick user out of a secure session so they aren't automatically logged back in
     $base_url = str_replace('https://', 'http://', $base_url);
+    drupal_goto('user');
   }
 }
 
@@ -105,6 +124,12 @@
     '#maxlength' => 55,
     '#description' => t('Append this domain name to each new user in order generate his email address.'),
   );
+  $form['webserver_auth_hide_logout'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Hide Log out menu'),
+    '#default_value' => variable_get('webserver_auth_hide_logout', FALSE),
+    '#description' => t("Hide the Log out menu item.  The url @url will still work.", array('@url' => url('logout', array('absolute' => TRUE)))),
+  );
   $form['advanced'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced settings'),
@@ -129,5 +154,19 @@
       '#description' => t("Modify user accounts at the time of creation. Use PHP code (enclosed in <code>&lt;?php</code> and <code>?&gt;</code>). The variable <code>\$account</code> is available as in <a href=\"http://api.drupal.org/api/function/hook_user/6\">hook_user('insert',...)</a>. Changes to the user object must be explicitly saved to the database to be made permanent."),
     ),
   );
-  return system_settings_form($form);
+  // Add standard settings form elements
+  $form = system_settings_form($form);
+  // Remove submit element so the webserver_auth_settings_submit is used
+  unset($form['#submit']);
+  return $form;
 }
+
+/**
+ * Implementation of hook_settings_submit().
+ */
+function webserver_auth_settings_submit($form, &$form_state){
+  // Save all settings using the standard settings_form_submit function
+  system_settings_form_submit($form, $form_state);
+  // Rebuild the menu so the logout menu item setting is applied
+  menu_rebuild();
+}
\ No newline at end of file
