? secure-site-d7-first-pass.patch
? theme/securesite-user-login-form.tpl.php
Index: securesite.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/securesite/securesite.admin.inc,v
retrieving revision 1.13.2.11.2.1
diff -u -p -r1.13.2.11.2.1 securesite.admin.inc
--- securesite.admin.inc	9 Jan 2011 05:14:16 -0000	1.13.2.11.2.1
+++ securesite.admin.inc	9 Jan 2011 15:02:37 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: securesite.admin.inc,v 1.13.2.11.2.1 2011/01/09 05:14:16 sime Exp $
+// $Id: securesite.admin.inc,v 1.13.2.11 2009/03/09 14:48:26 darrenoh Exp $
 
 /**
  * @file
@@ -244,8 +244,10 @@ function securesite_admin_settings_valid
     }
   }
   sort($form_state['values']['securesite_type']);
-  if (db_result(db_query_range("SELECT uid FROM {users} WHERE name = '%s'", $form_state['values']['securesite_guest_name'], 0, 1)) != 0) {
-    form_set_error('securesite_guest_name', t('The name %name belongs to a registered user.', array('%name' => $form_state['values']['securesite_guest_name'])));
+
+  $name = $form_state['values']['securesite_guest_name'];
+  if ($name && db_query_range("SELECT name FROM {users} WHERE name = :name", 0, 1, array(':name' => $name))->fetchField() == $name) {
+    form_set_error('securesite_guest_name', t('The name %name belongs to a registered user.', array('%name' => $name)));
   }
 }
 
Index: securesite.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/securesite/securesite.inc,v
retrieving revision 1.30.2.13.2.1
diff -u -p -r1.30.2.13.2.1 securesite.inc
--- securesite.inc	9 Jan 2011 05:21:48 -0000	1.30.2.13.2.1
+++ securesite.inc	9 Jan 2011 15:02:37 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: securesite.inc,v 1.30.2.13.2.1 2011/01/09 05:21:48 sime Exp $
+// $Id: securesite.inc,v 1.30.2.13 2009/03/09 14:48:27 darrenoh Exp $
 
 /**
  * @file
@@ -54,7 +54,7 @@ function _securesite_parse_directives($f
  */
 function _securesite_403() {
   global $user;
-  if (empty($user->uid) && !isset($_SESSION['securesite_guest']) && $_GET['q'] != 'logout') {
+  if (empty($user->uid) && !isset($_SESSION['securesite_guest']) && $_GET['q'] != 'user/logout') {
     _securesite_dialog(array_pop(variable_get('securesite_type', array(SECURESITE_BASIC))));
   }
   else {
@@ -76,12 +76,12 @@ function _securesite_digest_auth($edit) 
     // Not a registered user. See if we have guest user credentials.
     switch ($status) {
       case 1:
-        drupal_set_header('HTTP/1.1 400 Bad Request');
+        drupal_add_http_header('Status', '400 Bad Request');
         _securesite_dialog(array_pop(variable_get('securesite_type', array(SECURESITE_BASIC))));
         break;
       case 0:
         // Password is correct. Log user in.
-        drupal_set_header($header);
+        drupal_add_http_header($header['name'], $header['value']);
         $edit['pass'] = variable_get('securesite_guest_pass', '');
       default:
         _securesite_guest_login($edit);
@@ -92,7 +92,7 @@ function _securesite_digest_auth($edit) 
     switch ($status) {
       case 0:
         // Password is correct. Log user in.
-        drupal_set_header($header);
+        drupal_add_http_header($header['name'], $header['value']);
         _securesite_user_login($edit, $account);
         break;
       case 2:
@@ -110,7 +110,7 @@ function _securesite_digest_auth($edit) 
         _securesite_dialog($type);
         break;
       case 1:
-        drupal_set_header('HTTP/1.1 400 Bad Request');
+        drupal_add_http_header('Status', '400 Bad Request');
       default:
         // Authentication failed. Request credentials using most secure authentication method.
         watchdog('user', 'Log-in attempt failed for %user.', array('%user' => $edit['name']));
@@ -140,11 +140,19 @@ function _securesite_digest_validate(&$s
     }
     $script = variable_get('securesite_digest_script', drupal_get_path('module', 'securesite') . '/digest_md5/digest_md5.php');
     $response = exec($script . ' ' . implode(' ', $args), $output, $status);
+
+    // drupal_set_header() is now drupal_add_http_header() and requires headers passed as name, value in an array.
+    // The script returns a string, so we shall break it up as best we can. The existing code doesn't seem
+    // to worry about correct data to append to 'WWW-Authenticate: ' etc so I won't add any for the D7 conversion.
+    $response = explode('=', $response);
+    $name = array_shift($response);
+    $value = implode('=', $response);
+
     if (isset($edit['data']) && empty($status)) {
-      $header = "Authentication-Info: $response";
+      $header = array('name' => "Authentication-Info: " . $name, 'value' => $value);
     }
     else {
-      $header = "WWW-Authenticate: Digest $response";
+      $header = array('name' => "WWW-Authenticate: Digest " . $name, 'value' => $value);
     }
   }
   return $header;
@@ -190,7 +198,7 @@ function _securesite_user_login($edit, $
     // Mark the session so Secure Site will be triggered on log-out.
     $_SESSION['securesite_login'] = TRUE;
     // Prevent a log-in/log-out loop by redirecting off the log-out page.
-    if ($_GET['q'] == 'logout') {
+    if ($_GET['q'] == 'user/logout') {
       drupal_goto();
     }
   }
@@ -213,7 +221,7 @@ function _securesite_guest_login($edit) 
     $_SESSION['securesite_guest'] = $edit['name'];
     $_SESSION['securesite_login'] = TRUE;
     // Prevent a 403 error by redirecting off the logout page.
-    if ($_GET['q'] == 'logout') {
+    if ($_GET['q'] == 'user/logout') {
       drupal_goto();
     }
   }
@@ -239,7 +247,7 @@ function _securesite_denied($message) {
     unset($_SESSION['messages']);
     // Set a session variable so that the log-in dialog will be displayed when the page is reloaded.
     $_SESSION['securesite_denied'] = TRUE;
-    drupal_set_header('HTTP/1.1 403 Forbidden');
+    drupal_add_http_header('Status', '403 Forbidden');
     drupal_set_title(t('Access denied'));
     drupal_set_message($message, 'error');
     print theme('securesite_page');
@@ -334,19 +342,18 @@ function _securesite_dialog($type) {
           $header = _securesite_digest_validate($status, array('realm' => $realm, 'fakerealm' => _securesite_fake_realm()));
         }
         if (strpos($header, 'WWW-Authenticate') === 0) {
-          drupal_set_header($header);
-          drupal_set_header('HTTP/1.1 401 Unauthorized');
+          drupal_add_http_header('Status', '401 Unauthorized');
         }
         else {
-          drupal_set_header($header);
+          drupal_add_http_header($header['name'], $header['value']);
         }
         break;
       case SECURESITE_BASIC:
-        drupal_set_header('WWW-Authenticate: Basic realm="' . _securesite_fake_realm() . '"');
-        drupal_set_header('HTTP/1.1 401 Unauthorized');
+        drupal_add_http_header('WWW-Authenticate: Basic realm', _securesite_fake_realm());
+        drupal_add_http_header('Status', '401 Unauthorized');
         break;
       case SECURESITE_FORM:
-        drupal_set_header('HTTP/1.1 200 OK');
+        drupal_add_http_header('Status', '200 OK');
         break;
     }
     // Form authentication doesn't work for cron, so allow cron.php to run
@@ -385,7 +392,7 @@ function _securesite_fake_realm() {
 function _securesite_dialog_page() {
   $reset = variable_get('securesite_reset_form', t('Enter your user name or e-mail address.'));
   if (in_array(SECURESITE_FORM, variable_get('securesite_type', array(SECURESITE_BASIC)))) {
-    $output = drupal_get_form('securesite_user_login');
+    $output = drupal_get_form('securesite_user_login_form');
     $output .= empty($reset) ? '' : "<hr />\n" . drupal_get_form('securesite_user_pass');
   }
   else {
@@ -406,7 +413,7 @@ function _securesite_dialog_page() {
  * @ingroup forms
  * @see user_login()
  */
-function securesite_user_login(&$form_state) {
+function securesite_user_login_form(&$form_state) {
   $form['name'] = array(
     '#type' => 'textfield',
     '#title' => t('User name'),
@@ -433,7 +440,10 @@ function securesite_user_login(&$form_st
              '</style>';
     drupal_set_html_head($style);
   }
-  drupal_alter('form', $form, $form_state, 'user_login');
+
+  // drupal_alter takes this variable by reference so can't be a literal.
+  $form_id = 'user_login';
+  drupal_alter('form', $form, $form_state, $form_id);
   return $form;
 }
 
@@ -448,7 +458,8 @@ function securesite_user_pass(&$form_sta
   module_load_include('inc', 'user', 'user.pages');
   $form = user_pass();
   $form['name']['#title'] = t('User name or e-mail address');
-  drupal_alter('form', $form, $form_state, 'user_pass');
+  $form_id = 'user_pass';
+  drupal_alter('form', $form, $form_state, $form_id);
   $form['#redirect'] = FALSE;
   $form['#validate'][] = 'user_pass_validate';
   $form['#submit'][] = 'user_pass_submit';
Index: securesite.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/securesite/securesite.info,v
retrieving revision 1.4.2.1
diff -u -p -r1.4.2.1 securesite.info
--- securesite.info	9 Mar 2009 14:48:27 -0000	1.4.2.1
+++ securesite.info	9 Jan 2011 15:02:37 -0000
@@ -1,4 +1,8 @@
 ; $Id: securesite.info,v 1.4.2.1 2009/03/09 14:48:27 darrenoh Exp $
 name = Secure Site
 description = Enables HTTP Auth security or an HTML form to restrict site access.
-core = 6.x
+core = 7.x
+
+files[] = "securesite.test"
+
+configure = "admin/config/securesite"
Index: securesite.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/securesite/securesite.module,v
retrieving revision 1.43.2.12.2.1
diff -u -p -r1.43.2.12.2.1 securesite.module
--- securesite.module	9 Jan 2011 05:21:48 -0000	1.43.2.12.2.1
+++ securesite.module	9 Jan 2011 15:02:38 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: securesite.module,v 1.43.2.12.2.1 2011/01/09 05:21:48 sime Exp $
+// $Id: securesite.module,v 1.43.2.12 2009/07/15 18:17:32 darrenoh Exp $
 
 /**
  * @file
@@ -55,8 +55,13 @@ function securesite_help($path, $arg) {
 /**
  * Implementation of hook_perm().
  */
-function securesite_perm() {
-  return array('access secured pages');
+function securesite_permission() {
+  return array(
+    'access secured pages' => array(
+      'title' => t('Access secure pages'),
+      'description' => t('Allow the user to access pages after entering their credentials in the Secure Site log-ing form.'),
+    ),
+  );
 }
 
 /**
@@ -69,7 +74,7 @@ function securesite_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'securesite.inc',
   );
-  $items['admin/settings/securesite'] = array(
+  $items['admin/config/securesite'] = array(
     'title' => 'Secure Site',
     'description' => 'Enables HTTP Auth security or an HTML form to restrict site access.',
     'page callback' => 'drupal_get_form',
@@ -130,7 +135,7 @@ function _securesite_mechanism() {
       $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
     }
     if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
-      require_once './includes/unicode.inc';
+      require_once DRUPAL_ROOT . '/includes/unicode.inc';
       list($type, $authorization) = explode(' ', $_SERVER['HTTP_AUTHORIZATION'], 2);
       switch (drupal_strtolower($type)) {
         case 'digest':
@@ -159,7 +164,7 @@ function _securesite_mechanism() {
           }
           break;
         case SECURESITE_FORM:
-          if (isset($_POST['form_id']) && $_POST['form_id'] == 'securesite_user_login') {
+          if (isset($_POST['form_id']) && $_POST['form_id'] == 'securesite_user_login_form') {
             $mechanism = SECURESITE_FORM;
             break 2;
           }
@@ -171,12 +176,114 @@ function _securesite_mechanism() {
 }
 
 /**
+ * Implements hook_form_alter().
+ *
+ * Prevent a new user being created with the same name as the site's guest name.
+ */
+function securesite_form_alter(&$form, $form_state, $form_id) {
+  dpm(__FUNCTION__ . $form_id);
+  if (!array_key_exists('name', form_set_error()) && isset($edit['name']) && $edit['name'] == variable_get('securesite_guest_name', '')) {
+    form_set_error('name', t('The name %name is being used as the %site guest name.', array('%name' => $edit['name'], '%site' => variable_get('site_name', 'Drupal'))));
+  }
+}
+
+/**
+ * Implements hook_user_insert().
+ */
+function securesite_user_insert(&$edit, $account, $category) {
+  _securesite_user_digest_cleanup($edit);
+}
+
+/**
+ * Implements hook_user_update().
+ */
+function securesite_user_update(&$edit, $account, $category) {
+  _securesite_user_digest_cleanup($edit);
+}
+
+/**
+ * Implements hook_user_load().
+ */
+function securesite_user_load($users) {
+  foreach ($users as $user) {
+    _securesite_user_digest_cleanup((array)$user);
+  }
+}
+
+/**
+ * Manage a users stored password.
+ *
+ * @see secure_user_insert
+ * @see secure_user_update
+ * @see secure_user_load
+ *
+ * @todo more documentation would be useful.
+ */
+function _securesite_user_digest_cleanup($account) {
+  if (in_array(SECURESITE_DIGEST, variable_get('securesite_type', array(SECURESITE_BASIC))) && isset($edit['pass'])) {
+    $edit['name'] = isset($edit['name']) ? $edit['name'] : $user->name;
+    $script = variable_get('securesite_password_script', drupal_get_path('module', 'securesite') . '/digest_md5/stored_passwords.php');
+    $values = array(
+      'username=' . escapeshellarg($edit['name']),
+      'realm=' . escapeshellarg(variable_get('securesite_realm', variable_get('site_name', 'Drupal'))),
+      'pass=' . escapeshellarg($edit['pass']),
+      'op=create',
+    );
+    exec($script . ' ' . implode(' ', $values), $output, $status);
+    if ($user->name != $edit['name']) {
+      securesite_user_delete($edit, $user);
+    }
+  }
+}
+
+/**
+ * Implements hook_user_delete().
+ */
+function securesite_user_delete($account) {
+  if (in_array(SECURESITE_DIGEST, variable_get('securesite_type', array(SECURESITE_BASIC)))) {
+    $script = variable_get('securesite_password_script', drupal_get_path('module', 'securesite') . '/digest_md5/stored_passwords.php');
+    $values = array(
+      'username=' . escapeshellarg($user->name),
+      'realm=' . escapeshellarg(variable_get('securesite_realm', variable_get('site_name', 'Drupal'))),
+      'op=delete',
+    );
+    exec($script . ' ' . implode(' ', $values));
+  }
+}
+
+/**
+ * Implements hook_user_logout().
+ *
+ * When users logout, show the HTTP Auth dialog to make sure the HTTP Auth
+ * credentials are cleared
+ */
+function securesite_user_logout($account) {
+  $types = variable_get('securesite_type', array(SECURESITE_BASIC));
+  if ((in_array(SECURESITE_BASIC, $types) || in_array(SECURESITE_DIGEST, $types)) && !empty($_SESSION['securesite_login'])) {
+    module_load_include('inc', 'securesite');
+    // Load the anonymous user.
+    $user = drupal_anonymous_user();
+    // Safari will attempt to use old credentials before requesting new credentials
+    // from the user. Logging out requires that the WWW-Authenticate header be sent
+    // twice.
+    $user_agent = (isset($_SERVER['HTTP_USER_AGENT']) ? drupal_strtolower($_SERVER['HTTP_USER_AGENT']) : '');
+    if ($user_agent != str_replace('safari', '', $user_agent)) {
+      session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc');
+      session_start();
+      $_SESSION['securesite_repeat'] = TRUE;
+    }
+    // Clear stored credentials.
+    _securesite_dialog(array_pop($types));
+  }
+}
+
+/**
  * Implementation of hook_user().
  *
  * When users logout, show the HTTP Auth dialog to make sure the HTTP Auth
  * credentials are cleared
  */
-function securesite_user($op, &$edit, &$user) {
+function SECURESITE_USER($op, &$edit, &$user) {
   switch ($op) {
     case 'validate':
       if (!array_key_exists('name', form_set_error()) && isset($edit['name']) && $edit['name'] == variable_get('securesite_guest_name', '')) {
@@ -238,14 +345,13 @@ function securesite_user($op, &$edit, &$
  * Implementation of hook_theme().
  */
 function securesite_theme() {
-  $themes = theme_get_registry();
   return array(
     'securesite_page' => array(
       'template' => 'securesite-page',
       'arguments' => array('content' => NULL, 'show_blocks' => FALSE, 'show_messages' => TRUE),
       'path' => drupal_get_path('module', 'securesite') . '/theme',
     ),
-    'securesite_user_login' => array(
+    'securesite_user_login_form' => array(
       'template' => 'securesite-user-login',
       'arguments' => array('form' => NULL),
       'file' => 'securesite.theme.inc',
Index: securesite.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/securesite/Attic/securesite.test,v
retrieving revision 1.1.2.9.2.1
diff -u -p -r1.1.2.9.2.1 securesite.test
--- securesite.test	9 Jan 2011 05:39:09 -0000	1.1.2.9.2.1
+++ securesite.test	9 Jan 2011 15:02:38 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: securesite.test,v 1.1.2.9.2.1 2011/01/09 05:39:09 sime Exp $
+// $Id: securesite.test,v 1.1.2.9 2009/03/09 14:48:26 darrenoh Exp $
 
 /**
  * @file
@@ -277,7 +277,7 @@ class SecureSiteScriptDigestMD5UnitTest 
     $response = md5($ha1 . ':' . $this->challenge['nonce'] . ':' . md5('GET:/'));
     $this->data[] = 'nonce="' . $this->challenge['nonce'] . '"';
     $this->data[] = 'response="' . $response . '"';
-    $command = $this->digest_md5 .' data=' . escapeshellarg(implode(', ', $this->data)) . ' method=GET';
+    $command = $this->digest_md5 . ' data=' . escapeshellarg(implode(', ', $this->data)) . ' method=GET';
     $authentication = _securesite_parse_directives(exec($command, $output, $status));
     $rspauth = md5($ha1 . ':' . $this->challenge['nonce'] . ':' . md5(':/'));
     $this->assertTrue($status == 0 && isset($authentication['rspauth']) && $authentication['rspauth'] == $rspauth, t('Checking response to stored password.'));
@@ -464,7 +464,18 @@ class SecureSiteFunctionUserLoadUnitTest
    * Load user without password.
    */
   function testSecureSiteUserLoadUID() {
-    user_load($this->user->uid);
+    // Added by sime in D7 upgrade.
+    // @todo Coder module instructs that we should convert "user_load" to "user_load_multiple" if "$this->user->uid" is other than a uid.  To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent. Example: array_shift(user_load_multiple(array(), $this->user->uid)) -- HOWEVER I'm not sure how to do this yet since this is not appararently returning anything.
+    // @todo Look at how user tests work in D7.
+
+    // Old test
+    // user_load($this->user->uid);
+    // $command = "$this->stored_passwords $this->name_arg $this->pass_arg $this->realm_arg";
+    // $this->assertTrue(exec($command) == $this->user->name . " not found in $this->realm.", t('Loading user without password.'));
+
+    // New test
+    $accounts = user_load_multiple(array(), array('uid' => $this->user->uid));
+    // $new_user = reset($accounts); // Needed?
     $command = "$this->stored_passwords $this->name_arg $this->pass_arg $this->realm_arg";
     $this->assertTrue(exec($command) == $this->user->name . " not found in $this->realm.", t('Loading user without password.'));
   }
@@ -473,7 +484,9 @@ class SecureSiteFunctionUserLoadUnitTest
    * Load user with password.
    */
   function testSecureSiteUserLoadPass() {
-    user_load(array('uid' => $this->user->uid, 'pass' => $this->user->pass_raw));
+    // D6: user_load(array('uid' => $this->user->uid, 'pass' => $this->user->pass_raw));
+    // sime: D6 code doesn't return anything so I assume no array shifting or reset() is needed for D7 code.
+    user_load_multiple(array($this->user->uid), array('pass' => $this->user->pass_raw));
     $command = "$this->stored_passwords $this->name_arg $this->pass_arg $this->realm_arg";
     $this->assertTrue(exec($command) == 'Updated ' . $this->user->name . " in $this->realm.", t('Loading user with password.'));
   }
@@ -520,7 +533,7 @@ class SecureSiteFunctionUserDeleteUnitTe
    * Remove user.
    */
   function testSecureSiteFunctionUserDelete() {
-    user_delete(array(), $this->user->uid);
+    user_cancel(array(), $this->user->uid, $method = 'user_cancel_delete');
     $command = "$this->stored_passwords $this->name_arg $this->pass_arg $this->realm_arg";
     $this->assertTrue(exec($command) == $this->user->name . " not found in $this->realm.", t('Removing user.'));
   }
@@ -800,6 +813,7 @@ class SecureSiteFunctionDialogPageUnitTe
     variable_del('securesite_type');
     variable_del('securesite_reset_form');
     form_clean_id(NULL, TRUE);
+    drupal_clean_css_identifier(NULL, TRUE);
     parent::tearDown();
   }
 }
@@ -824,8 +838,7 @@ class SecureSiteNameConflictFunctionalTe
    */
   function setUp() {
     parent::setUp('securesite');
-    $perm = db_result(db_query_range("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID, 0, 1));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->guest = $this->randomName();
     variable_set('securesite_guest_name', $this->guest);
     $this->user = $this->drupalCreateUser(array('administer site configuration', 'administer users', 'change own username'));
@@ -837,7 +850,7 @@ class SecureSiteNameConflictFunctionalTe
   function testSecureSiteNameConflictUserRegister() {
     $this->drupalPost('user/register', array('name' => $this->guest, 'mail' => $this->guest . '@example.com'), 'Create new account');
     $this->assertText("The name $this->guest is being used as the " . variable_get('site_name', 'Drupal') . " guest name.", t('Registering user with guest name.'));
-    $this->assertTrue(db_result(db_query_range("SELECT uid FROM {users} WHERE name = '%s'", $this->guest, 0, 1)) === FALSE, t('Checking for user with guest name.'));
+    $this->assertTrue(db_query_range("SELECT uid FROM {users} WHERE name = :name", array(':name' => $this->guest))->fetchField() === FALSE, t('Checking for user with guest name.'));
   }
 
   /**
@@ -847,7 +860,7 @@ class SecureSiteNameConflictFunctionalTe
     $this->drupalLogin($this->user);
     $this->drupalPost('admin/user/user/create', array('name' => $this->guest, 'mail' => $this->guest . '@example.com', 'pass[pass1]' => $this->user->pass_raw, 'pass[pass2]' => $this->user->pass_raw), 'Create new account');
     $this->assertText("The name $this->guest is being used as the " . variable_get('site_name', 'Drupal') . " guest name.", t('Creating user with guest name.'));
-    $this->assertTrue(db_result(db_query_range("SELECT uid FROM {users} WHERE name = '%s'", $this->guest, 0, 1)) === FALSE, t('Checking for user with guest name.'));
+    $this->assertTrue(db_query_range("SELECT uid FROM {users} WHERE name = :name", array(':name' => $this->guest))->fetchField() === FALSE, t('Checking for user with guest name.'));
   }
 
   /**
@@ -857,7 +870,7 @@ class SecureSiteNameConflictFunctionalTe
     $this->drupalLogin($this->user);
     $this->drupalPost('user/' . $this->user->uid . '/edit', array('name' => $this->guest), 'Save');
     $this->assertText("The name $this->guest is being used as the " . variable_get('site_name', 'Drupal') . " guest name.", t('Setting user name to guest name.'));
-    $this->assertTrue(db_result(db_query_range("SELECT uid FROM {users} WHERE name = '%s'", $this->guest, 0, 1)) === FALSE, t('Checking for user with guest name.'));
+    $this->assertTrue(db_query_range("SELECT uid FROM {users} WHERE name = :name", array(':name' => $this->guest))->fetchField() === FALSE, t('Checking for user with guest name.'));
   }
 
   /**
@@ -865,7 +878,7 @@ class SecureSiteNameConflictFunctionalTe
    */
   function testSecureSiteNameConflictGuest() {
     $this->drupalLogin($this->user);
-    $this->drupalPost('admin/settings/securesite', array('securesite_guest_name' => $this->user->name), 'Save configuration');
+    $this->drupalPost('admin/config/securesite', array('securesite_guest_name' => $this->user->name), 'Save configuration');
     $this->assertText('The name ' . $this->user->name . ' belongs to a registered user.', t('Setting guest name to user name.'));
     $this->assertNotEqual(variable_get('securesite_guest_name', ''), $this->user->name, t('Checking for guest with user name.'));
   }
@@ -923,8 +936,7 @@ class SecureSiteForceAlwaysFunctionalTes
   function setUp() {
     parent::setUp('securesite');
     $this->user = $this->drupalCreateUser();
-    $perm = db_result(db_query_range("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID, 0, 1));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     variable_set('securesite_enabled', SECURESITE_ALWAYS);
   }
 
@@ -965,7 +977,7 @@ class SecureSiteForceAlwaysFunctionalTes
    */
   function testSecureSiteForceAlwaysResetValid() {
     sleep(1); // Password reset URL must be created at least one second after last log-in.
-    $reset = user_pass_reset_url(user_load($this->user->uid));
+    $reset = user_pass_reset_url(array_shift(user_load_multiple(array(), $this->user->uid)));
     sleep(1); // Password reset URL must be used at least one second after it is created.
     $this->drupalGet($reset);
     $this->assertResponse(200, t('Trying valid password reset URL.'));
@@ -1140,7 +1152,7 @@ class SecureSiteConfig403FunctionalTest 
    * Check access denied page when setting forced authentication on restricted pages.
    */
   function testSecureSiteConfig403Save() {
-    $this->drupalPost('admin/settings/securesite', array('securesite_enabled' => SECURESITE_403), 'Save configuration');
+    $this->drupalPost('admin/config/securesite', array('securesite_enabled' => SECURESITE_403), 'Save configuration');
     $this->assertTrue(variable_get('site_403', '') == 'securesite_403', t('Checking access denied page when setting forced authentication on restricted pages.'));
   }
 
@@ -1149,7 +1161,7 @@ class SecureSiteConfig403FunctionalTest 
    */
   function testSecureSiteConfig403ResetCurrent() {
     variable_set('site_403', 'site_403');
-    $this->drupalPost('admin/settings/securesite', array(), 'Reset to defaults');
+    $this->drupalPost('admin/config/securesite', array(), 'Reset to defaults');
     $this->assertTrue(variable_get('site_403', '') == 'site_403', t('Keeping current access denied page when no previous setting exists.'));
   }
 
@@ -1157,9 +1169,9 @@ class SecureSiteConfig403FunctionalTest 
    * Save previous access denied page.
    */
   function testSecureSiteConfig403Page() {
-    $this->drupalPost('admin/settings/error-reporting', array('site_403' => 'site_403'), 'Save configuration');
+    $this->drupalPost('admin/config/development/logging', array('site_403' => 'site_403'), 'Save configuration');
     variable_set('securesite_enabled', SECURESITE_403);
-    $this->drupalPost('admin/settings/error-reporting', array(), 'Save configuration');
+    $this->drupalPost('admin/config/development/logging', array(), 'Save configuration');
     $this->assertTrue(variable_get('securesite_403', '') == 'site_403', t('Saving previous access denied page.'));
   }
 
@@ -1168,7 +1180,7 @@ class SecureSiteConfig403FunctionalTest 
    */
   function testSecureSiteConfig403ResetPrevious() {
     variable_set('securesite_403', 'site_403');
-    $this->drupalPost('admin/settings/securesite', array(), 'Reset to defaults');
+    $this->drupalPost('admin/config/development/logging', array(), 'Reset to defaults');
     $this->assertTrue(variable_get('site_403', '') == 'site_403', t('Restoring previous access denied page.'));
   }
 
@@ -1240,8 +1252,7 @@ class SecureSiteTypeBasicUserFunctionalT
    */
   function setUp() {
     parent::setUp('securesite');
-    $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->normal_user = $this->drupalCreateUser();
     $this->access_user = $this->drupalCreateUser(array('access secured pages'));
     // Should work with all authentication methods enabled.
@@ -1278,7 +1289,7 @@ class SecureSiteTypeBasicUserFunctionalT
     $this->assertText($this->access_user->name, t('Checking for user name when password is correct and access is enabled.'));
     $this->assertText('My account', t('Checking for account link when password is correct and access is enabled.'));
     $this->assertText('Log out', t('Checking for log-out link when password is correct and access is enabled.'));
-    $this->drupalHead('logout');
+    $this->drupalHead('user/logout');
     $this->assertResponse(401, t('Requesting log-out page.'));
   }
 
@@ -1322,8 +1333,7 @@ class SecureSiteTypeBasicGuestUnsetFunct
    */
   function setUp() {
     parent::setUp('securesite');
-    $this->perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $this->perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     // Should work with all authentication methods enabled.
     variable_set('securesite_type', array(SECURESITE_FORM, SECURESITE_BASIC, SECURESITE_DIGEST));
     $this->curl_options[CURLOPT_USERPWD] = ':';
@@ -1333,7 +1343,7 @@ class SecureSiteTypeBasicGuestUnsetFunct
    * Request home page with empty credentials and access disabled.
    */
   function testSecureSiteTypeBasicGuestUnsetEmptyNoAccess() {
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $this->perm, DRUPAL_ANONYMOUS_RID);
+    user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->drupalGet(NULL);
     $this->assertResponse(403, t('Requesting home page with empty credentials and guest access disabled.'));
     $this->drupalHead(NULL);
@@ -1352,7 +1362,7 @@ class SecureSiteTypeBasicGuestUnsetFunct
    * Request home page with random credentials and access disabled.
    */
   function testSecureSiteTypeBasicGuestUnsetRandomNoAccess() {
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $this->perm, DRUPAL_ANONYMOUS_RID);
+    user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->curl_options[CURLOPT_USERPWD] = $this->randomName() . ':' . user_password();
     $this->drupalGet(NULL);
     $this->assertResponse(401, t('Requesting home page with random credentials and guest access disabled.'));
@@ -1407,8 +1417,7 @@ class SecureSiteTypeBasicGuestSetFunctio
    */
   function setUp() {
     parent::setUp('securesite');
-    $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->name = $this->randomName();
     $this->pass = user_password();
     variable_set('securesite_guest_name', $this->name);
@@ -1509,8 +1518,7 @@ class SecureSiteTypeFormUserFunctionalTe
    */
   function setUp() {
     parent::setUp('securesite');
-    $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->normal_user = $this->drupalCreateUser();
     $this->access_user = $this->drupalCreateUser(array('access secured pages'));
     variable_set('securesite_enabled', SECURESITE_ALWAYS);
@@ -1595,8 +1603,7 @@ class SecureSiteTypeFormGuestFunctionalT
    * Request home page with random credentials and access enabled.
    */
   function testSecureSiteTypeFormGuestUnsetRandomAccess() {
-    $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     $this->drupalPost('', array('name' => $this->randomName(), 'pass' => user_password()), 'Log in');
     $this->assertNoFieldByXPath('//form[@id="securesite-user-login"]', '', t('Requesting home page with random credentials and guest access enabled.'));
     $this->assertFieldByXPath('//form[@id="user-login-form"]', '', t('Checking for user log-in form when guest access is enabled and random password is given.'));
@@ -1713,7 +1720,7 @@ class SecureSiteTypeDigestUserUnstoredFu
    * Implementation of tearDown().
    */
   function tearDown() {
-    user_delete(array(), $this->user->uid);
+    user_cancel(array(), $this->user->uid, $method = 'user_cancel_delete');
     parent::tearDown();
   }
 }
@@ -1764,7 +1771,7 @@ class SecureSiteTypeDigestUserStoredFunc
     $this->assertResponse(200, t('Requesting home page with correct password.'));
     $directives = _securesite_parse_directives($this->drupalGetHeader('Authentication-Info'));
     $this->assertTrue(isset($directives['rspauth']), t('Checking correct password authentication info.'));
-    $this->drupalHead('logout');
+    $this->drupalHead('user/logout');
     $this->assertResponse(401, t('Requesting log-out page'));
   }
 
@@ -1772,7 +1779,7 @@ class SecureSiteTypeDigestUserStoredFunc
    * Implementation of tearDown().
    */
   function tearDown() {
-    user_delete(array(), $this->user->uid);
+    user_cancel(array(), $this->user->uid, $method = 'user_cancel_delete');
     parent::tearDown();
   }
 }
@@ -1798,8 +1805,7 @@ class SecureSiteTypeDigestGuestUnsetFunc
   function setUp() {
     parent::setUp('securesite');
     _securesite_copy_script_config($this);
-    $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     variable_set('securesite_enabled', SECURESITE_ALWAYS);
     // Should work with all authentication methods enabled.
     variable_set('securesite_type', array(SECURESITE_FORM, SECURESITE_BASIC, SECURESITE_DIGEST));
@@ -1848,8 +1854,7 @@ class SecureSiteTypeDigestGuestSetFuncti
   function setUp() {
     parent::setUp('securesite');
     _securesite_copy_script_config($this);
-    $perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID));
-    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm . ', access secured pages', DRUPAL_ANONYMOUS_RID);
+    user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access secured pages'));
     variable_set('securesite_enabled', SECURESITE_ALWAYS);
     // Should work with all authentication methods enabled.
     variable_set('securesite_type', array(SECURESITE_FORM, SECURESITE_BASIC, SECURESITE_DIGEST));
@@ -1897,10 +1902,10 @@ class SecureSiteTypeDigestGuestSetFuncti
    */
   function tearDown() {
     $this->curl_options[CURLOPT_USERPWD] = $this->user->name . ':' . $this->user->pass_raw;
-    $this->drupalPost('admin/settings/securesite', array(), 'Reset to defaults');
+    $this->drupalPost('admin/config/securesite', array(), 'Reset to defaults');
     _securesite_copy_script_config($this);
     variable_set('securesite_type', array(SECURESITE_DIGEST));
-    user_delete(array(), $this->user->uid);
+    user_cancel(array(), $this->user->uid, $method = 'user_cancel_delete');
     parent::tearDown();
   }
 }
Index: theme/securesite.theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/securesite/theme/Attic/securesite.theme.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 securesite.theme.inc
--- theme/securesite.theme.inc	9 Mar 2009 14:48:27 -0000	1.1.2.1
+++ theme/securesite.theme.inc	9 Jan 2011 15:02:38 -0000
@@ -12,7 +12,7 @@
  * @param $variables
  *   An array of variables from the theme system.
  */
-function template_preprocess_securesite_user_login(&$variables) {
+function template_preprocess_securesite_user_login_form(&$variables) {
   $variables['title'] = variable_get('securesite_login_form', t('Enter your user name and password.'));
   $variables['messages'] = theme('status_messages');
 }
