Index: services.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/Attic/services.module,v
retrieving revision 1.8.2.88
diff -u -r1.8.2.88 services.module
--- services.module	19 May 2009 02:13:51 -0000	1.8.2.88
+++ services.module	29 May 2009 23:16:34 -0000
@@ -246,8 +246,12 @@
       return call_user_func_array($func, $args);
     }
   }
-  else{
-    return TRUE;
+}
+
+function services_init() {
+  if (variable_get('services_auth_module', '') == '' && user_access('administer services')) {
+    drupal_set_message(t('You do not have any authenciation modules enabled. Your site allows free access to the server.'), 'error'); 
+    drupal_set_message(t('Please enable an authenciation module or visit the !here and confirm this is correct.', array('!here' => l('here', 'admin/build/services/settings'))), 'error');
   }
 }
 
@@ -266,9 +270,6 @@
       return call_user_func_array($func, $args);
     }
   }
-  else{
-    return TRUE;
-  }
 }
 
 /**
@@ -513,4 +514,23 @@
  */
 function services_access_menu() {
   return TRUE;
-} 
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_authentication_info().
+ *
+ * @return array
+ *  The configuration array for the authentication scheme
+ */
+function services_authentication_info() {
+  return array(
+    '#title' => t('No authentication'),
+    '#description' => t('No authenication for clients using the site'),
+    'authenticate_call' => '_services_no_authenticate_call',
+  );
+}
+
+function _services_no_authenticate_call() {
+  // Always return false so as we pass auth check.
+  return FALSE;
+}
\ No newline at end of file
Index: services_admin_browse.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/Attic/services_admin_browse.inc,v
retrieving revision 1.5.2.45
diff -u -r1.5.2.45 services_admin_browse.inc
--- services_admin_browse.inc	20 May 2009 02:05:31 -0000	1.5.2.45
+++ services_admin_browse.inc	29 May 2009 23:16:35 -0000
@@ -344,7 +344,7 @@
     $settings = services_auth_invoke_custom($_POST['auth_module'], 'security_settings');
   }
 
-  if ($settings) {
+  if (is_array($settings)) {
     $cached_form['security']['options']['settings'] = $settings;
   }
   else {
Index: services.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/Attic/services.install,v
retrieving revision 1.3.2.20
diff -u -r1.3.2.20 services.install
--- services.install	18 May 2009 00:19:40 -0000	1.3.2.20
+++ services.install	29 May 2009 23:16:33 -0000
@@ -86,3 +86,21 @@
   menu_rebuild();
   return $ret;
 }
+
+function services_update_6003() {
+  $ret = array();
+  if (variable_get('services_use_key', FALSE)) {
+    drupal_install_modules(array('services_keyauth'));
+    variable_set('services_auth_module', 'services_keyauth');
+  }
+  else{
+    if (variable_get('services_use_sessid', FALSE)) {
+      drupal_install_modules(array('services_sessauth'));
+      variable_set('services_auth_module', 'services_sessauth');
+    }
+    else{
+      variable_set('services_auth_module', 'services');
+    }
+  }
+  return $ret;
+}
Index: auth/services_keyauth/services_keyauth.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/auth/services_keyauth/Attic/services_keyauth.inc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 services_keyauth.inc
--- auth/services_keyauth/services_keyauth.inc	20 May 2009 01:53:12 -0000	1.1.2.6
+++ auth/services_keyauth/services_keyauth.inc	29 May 2009 23:16:35 -0000
@@ -7,12 +7,6 @@
  */
 
 function _services_keyauth_security_settings() {
-  $form['services_use_key'] = array(
-    '#type'           => 'checkbox',
-    '#title'          => t('Use keys'),
-    '#default_value'  => variable_get('services_use_key', TRUE),
-    '#description'    => t('When enabled all method calls need to provide a validation token to autheciate themselves with the server.'),
-  );
   $form['services_key_expiry'] = array(
     '#type'           => 'textfield',
     '#prefix'         => "<div id='services-key-expiry'>",
@@ -97,11 +91,11 @@
         $method['#auth'] = TRUE;
     }
     
-    if ($method['#auth'] and variable_get('services_use_sessid', TRUE)) {
+    if ($method['#auth'] && variable_get('services_use_sessid', TRUE)) {
       array_unshift($method['#args'], $arg_sessid);
     }
 
-    if ($method['#key'] and variable_get('services_use_key', TRUE)) {
+    if ($method['#key']) {
       array_unshift($method['#args'], $arg_nonce);
       array_unshift($method['#args'], $arg_domain_time_stamp);
       array_unshift($method['#args'], $arg_domain_name);
@@ -110,16 +104,7 @@
   }
 }
 
-function _services_keyauth_get_first_key() {
-  $keys = services_keyauth_get_keys();
-  foreach ($keys as $kid => $key) {
-    return $kid;
-  }
-}
-
 function _services_keyauth_alter_browse_form(&$form, $method) {
-  //$timestamp = time();
-  //$nonce = user_password();
 
   foreach ($method['#args'] as $key => $arg) {
     switch ($arg['#name']) {
@@ -153,7 +138,7 @@
 }
 
 function _services_keyauth_authenticate_call($method, $method_name, &$args) {
-  if ($method['#key'] and variable_get('services_use_key', TRUE)) {
+  if ($method['#key']) {
     $hash = array_shift($args);
     $domain = array_shift($args);
     $timestamp = array_shift($args);
@@ -201,10 +186,12 @@
 }
 
 function _services_keyauth_alter_browse_form_submit($method, &$args) {
-  $args_stripped = $args;
-  for ($i = 1; $i <= 4; $i++) {
-    array_shift($args_stripped);
+  if ($method['#key']) {
+    $args_stripped = $args;
+    for ($i = 1; $i <= 4; $i++) {
+      array_shift($args_stripped);
+    }
+    $args[2] = time();
+    $args[0] = services_get_hash($args[2], $args[1], $args[3], $method, $args_stripped);
   }
-  $args[2] = time();
-  $args[0] = services_get_hash($args[2], $args[1], $args[3], $method, $args_stripped);
 }
\ No newline at end of file
Index: auth/services_keyauth/services_keyauth.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/auth/services_keyauth/Attic/services_keyauth.module,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 services_keyauth.module
--- auth/services_keyauth/services_keyauth.module	18 May 2009 20:55:14 -0000	1.1.2.5
+++ auth/services_keyauth/services_keyauth.module	29 May 2009 23:16:36 -0000
@@ -48,8 +48,7 @@
     'title'             => 'Keys',
     'description'       => 'Manage application access to site services.',
     'page callback'     => 'services_keyauth_admin_keys_list',
-    'access callback'   => 'variable_get',
-    'access arguments'  => array('services_use_key', TRUE),
+    'access callback'   => 'services_keyauth_access',
     'type'              => MENU_LOCAL_TASK,
     'file'              => 'services_keyauth.admin.inc',
   );
@@ -71,16 +70,14 @@
   $items['admin/build/services/keys/list'] = array(
     'title'             => 'List',
     'type'              => MENU_DEFAULT_LOCAL_TASK,
-    'access callback'   => 'variable_get',
-    'access arguments'  => array('services_use_key', TRUE),
+    'access callback'   => 'services_keyauth_access',
     'weight'            => -10,
   );
   $items['admin/build/services/keys/add'] = array(
     'title'             => 'Create key',
     'page callback'     => 'drupal_get_form',
     'page arguments'    => array('services_keyauth_admin_keys_form'),
-    'access callback'   => 'variable_get',
-    'access arguments'  => array('services_use_key', TRUE),
+    'access callback'   => 'services_keyauth_access',
     'type'              => MENU_LOCAL_TASK,
     'file'              => 'services_keyauth.admin.inc',
   );
@@ -88,11 +85,9 @@
   return $items;
 }
 
-/*function services_keyauth_validate_key($kid, $timestamp, $domain, $nonce, $method_name, $hash_parameters, $hash) {
-  $hash_parameters = array_merge(array($timestamp, $domain, $nonce, $method_name), $hash_parameters);
-  $rehash = hash_hmac("sha256", implode(';', $hash_parameters), $kid);
-  return ($rehash == $hash) ? TRUE : FALSE;
-}*/
+function services_keyauth_access() {
+  return variable_get('services_auth_module','') == 'services_keyauth' ? TRUE : FALSE;
+}
 
 function services_get_hash($timestamp, $domain, $nonce, $method, $args) {
   $hash_parameters = array($timestamp, $domain, $nonce, $method['#method']);
Index: auth/services_sessauth/services_sessauth.module
===================================================================
RCS file: auth/services_sessauth/services_sessauth.module
diff -N auth/services_sessauth/services_sessauth.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ auth/services_sessauth/services_sessauth.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,33 @@
+<?php
+// $Id: $
+/**
+ * @author Services Dev Team
+ * @file
+ *  Provides a key based validation system.
+ */
+
+/**
+ * Implementation of hook_authentication_info().
+ *
+ * @return array
+ *  The configuration array for the authentication scheme
+ */
+function services_sessauth_authentication_info() {
+  return array(
+    '#file' => 'services_sessauth.inc',
+    '#title' => t('Session authentication'),
+    '#description' => t('The default session based authentication'),
+    'alter_methods' => '_services_sessauth_alter_methods',
+    'alter_browse_form' => '_services_sessauth_alter_browse_form',
+    'authenticate_call' => '_services_sessauth_authenticate_call',
+  );
+}
+
+
+function services_sessauth_disable() {
+  cache_clear_all('services:methods', 'cache');
+}
+
+function services_sessauth_enable() {
+  cache_clear_all('services:methods', 'cache');
+}
Index: auth/services_sessauth/services_sessauth.info
===================================================================
RCS file: auth/services_sessauth/services_sessauth.info
diff -N auth/services_sessauth/services_sessauth.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ auth/services_sessauth/services_sessauth.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,6 @@
+; $Id: $
+name = Session Authentication
+description = Provides session authentication for the services module
+package = Services - authentication
+dependencies[] = services
+core = 6.x
Index: auth/services_sessauth/services_sessauth.inc
===================================================================
RCS file: auth/services_sessauth/services_sessauth.inc
diff -N auth/services_sessauth/services_sessauth.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ auth/services_sessauth/services_sessauth.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,59 @@
+<?php
+// $Id: $
+
+/**
+ * @file
+ *  The implementation of the session authentication scheme
+ */
+function _services_sessauth_alter_methods(&$methods) {
+  // Skip this if no services have been activated
+  if (!is_array($methods) || empty($methods)) {
+    return;
+  }
+
+  // sessid arg
+  $arg_sessid = array(
+    '#name' => 'sessid',
+    '#type' => 'string',
+    '#description' => t('A valid sessid.'),
+  );
+
+  foreach ($methods as $key => &$method) {
+    // set method defaults
+    switch ($method['#method']) {
+      case 'system.connect':
+      case 'search.nodes':
+      case 'search.content':
+      case 'search.users':
+        $method['#auth'] = FALSE;
+        break;
+      default:
+        $method['#auth'] = TRUE;
+        array_unshift($method['#args'], $arg_sessid);
+    }
+  }
+}
+
+function _services_sessauth_alter_browse_form(&$form, $method) {
+  if ($method['#auth']) {
+    foreach ($method['#args'] as $key => $arg) {
+      switch ($arg['#name']) {
+        case 'sessid':
+          $form['arg'][$key]['#default_value']  = session_id();
+          break;
+      }
+    }
+  }
+}
+
+function _services_sessauth_authenticate_call($method, $method_name, &$args) {
+  // Add additonal processing for methods requiring session
+  $session_backup = NULL;
+  if ($method['#auth']) {
+    $sessid = array_shift($args);
+    if (empty($sessid)) {
+      return t('Invalid sessid.');
+    }
+    $session_backup = services_session_load($sessid);
+  }
+}
