--- pubcookie.module	2006-12-18 13:22:19.000000000 -0800
+++ pubcookie.module	2006-12-18 17:07:56.000000000 -0800
@@ -174,7 +174,7 @@ function pubcookie_auth($username, $pass
  *
  * Fill in profile field(s) from LDAP for pubcookie-authenticated users.
  */
-function pubcookie_user($type, $edit, &$user, $category = NULL) {
+function pubcookie_user($type, $edit, &$account, $category = NULL) {
   if ($type == 'insert') {
     global $pubcookie_username;
     // abort if a local (nonpubcookie) user is being added
@@ -183,14 +183,14 @@ function pubcookie_user($type, $edit, &$
     }
 
     if (PUBCOOKIE_VERBOSE_LOGGING) {
-      watchdog('pubcookie', t('User callback received for user %uid', array('%uid' => $user->uid)));
+      watchdog('pubcookie', t('User callback received for user %uid', array('%uid' => $account->uid)));
     }
 
     // set the mail column of the user table (which is typically blank for users with external auth) only if
     // username@server is also an email address
     if (variable_get('pubcookie_id_is_email', 1)) {
       global $pubcookie_server;
-      db_query("UPDATE {users} SET mail = '%s' WHERE uid = %d", "$pubcookie_username@$pubcookie_server", $user->uid);
+      db_query("UPDATE {users} SET mail = '%s' WHERE uid = %d", "$pubcookie_username@$pubcookie_server", $account->uid);
     }
 
     // return if LDAP is not enabled
@@ -203,7 +203,7 @@ function pubcookie_user($type, $edit, &$
     if (isset($pubcookie_record[variable_get('pubcookie_ldap_usernamefield', '')])) {
       $name = $pubcookie_record[variable_get('pubcookie_ldap_usernamefield', '')];
       if ($name) {
-        db_query("UPDATE {users} SET name = '%s' WHERE uid = %d", $name, $user->uid);
+        db_query("UPDATE {users} SET name = '%s' WHERE uid = %d", $name, $account->uid);
       }
     }
 
@@ -211,7 +211,7 @@ function pubcookie_user($type, $edit, &$
       return;
     }
     // insert the value(s) into profile field(s)
-    // we can't modify $user before it gets to the profile's user hook because modules
+    // we can't modify $account before it gets to the profile's user hook because modules
     // run alphabetically; we're 'pubcookie' and 'profile' has already run; so we do this ourselves
 
     // get list of profile fields
@@ -223,7 +223,16 @@ function pubcookie_user($type, $edit, &$
         if (PUBCOOKIE_VERBOSE_LOGGING) {
           watchdog('pubcookie', t('Inserting value %val into profile field %field', array('%val' => check_plain($pubcookie_record[$key]), '%field' => check_plain($data->name))));
         }
-        db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $data->fid, $user->uid, $pubcookie_record[$key]);
+        db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $data->fid, $account->uid, $pubcookie_record[$key]);
+      }
+    }
+  } else if ($type == 'logout' && variable_get('pubcookie_redirect_on_logout', FALSE)) {
+    $result = db_query("SELECT module FROM {authmap} WHERE uid = '%d'", $account->uid);
+    while ($row = db_fetch_object($result)) { 
+      if ($row->module == 'pubcookie') {
+        setcookie(session_name(), '', time()-42000, '/');
+        header('Location: '. variable_get('pubcookie_logout_url', ''), TRUE, 302);
+        exit();
       }
     }
   }
@@ -347,6 +356,20 @@ function pubcookie_settings() {
     '#size' => '40',
     '#maxlength' => '255'
     );
+  $form['pubcookie_redirect_on_logout'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Redirect on logout'),
+    '#default_value' => variable_get('pubcookie_redirect_on_logout', 0),
+    '#description' => t("Redirect pubcookie users to auth server logout after local logout.")
+    );
+  $form['pubcookie_logout_url'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Logout URL'),
+    '#default_value' => variable_get('pubcookie_logout_url', ''),
+    '#description' => t("URL to send users to in order to log them out of the authentication service (eg: https://authserv/logout."),
+    '#size' => '40',
+    '#maxlength' => '255',
+    );
 
   return system_settings_form($form);
 }
