2006-10-21 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-keyring.c
index dd22fb6..018f45a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2003, 2004  Red Hat Inc.
  *
- * Licensed under the Academic Free License version 2.0
+ * Licensed under the Academic Free License version 2.1
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -291,7 +291,7 @@ add_new_key (DBusKey  **keys_p,
   DBusKey *new;
   DBusString bytes;
   int id;
-  unsigned long timestamp;
+  long timestamp;
   const unsigned char *s;
   dbus_bool_t retval;
   DBusKey *keys;
@@ -415,6 +415,9 @@ _dbus_keyring_reload (DBusKeyring *keyring,
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   
+  if (!_dbus_check_dir_is_private_to_user (&keyring->directory, error))
+    return FALSE;
+    
   if (!_dbus_string_init (&contents))
     {
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -427,7 +430,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
       _dbus_string_free (&contents);
       return FALSE;
     }
-
+   
   keys = NULL;
   n_keys = 0;
   retval = FALSE;
@@ -479,7 +482,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
       DBusKey *new;
 
       /* Don't load more than the max. */
-      if (n_keys >= (add_new ? MAX_KEYS_IN_FILE : MAX_KEYS_IN_FILE - 1))
+      if (n_keys >= (add_new ? MAX_KEYS_IN_FILE - 1 : MAX_KEYS_IN_FILE))
         break;
       
       next = 0;
@@ -489,7 +492,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
           continue;
         }
 
-      if (val > _DBUS_INT_MAX || val < 0)
+      if (val > _DBUS_INT32_MAX || val < 0)
         {
           _dbus_verbose ("invalid secret key ID at start of line\n");
           continue;
@@ -568,7 +571,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
       if (!add_new_key (&keys, &n_keys, error))
         {
           _dbus_verbose ("Failed to generate new key: %s\n",
-                         error ? "(unknown)" : error->message);
+                         error ? error->message : "(unknown)");
           goto out;
         }
 
@@ -727,7 +730,7 @@ _dbus_keyring_new_homedir (const DBusString *username,
   if (!_dbus_string_init (&homedir))
     {
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-      return FALSE;
+      return NULL;
     }
 
   _dbus_string_init_const (&dotdir, ".dbus-keyrings");
@@ -759,7 +762,7 @@ _dbus_keyring_new_homedir (const DBusString *username,
      {
        _dbus_string_set_length (&homedir, 0);
        if (!_dbus_string_append (&homedir, override))
-         _dbus_assert_not_reached ("no memory");
+         goto failed;
 
        _dbus_verbose ("Using fake homedir for testing: %s\n",
                       _dbus_string_get_const_data (&homedir));
@@ -852,7 +855,7 @@ _dbus_keyring_new_homedir (const DBusString *username,
   if (keyring)
     _dbus_keyring_unref (keyring);
   _dbus_string_free (&homedir);
-  return FALSE;
+  return NULL;
 
 }