summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-08-07 01:33:14 +0200
committerLennart Poettering <lennart@poettering.net>2009-10-17 00:28:31 +0200
commit1f179e0f27f656ed3c5d1ee2ac5e1bbfe26d9d94 (patch)
treef239fdaf9e72954e153d33b88e0c1fd2a04d90bf
parent2ed34f69d4400f863835c4149be4ecb82ffe1c72 (diff)
desktop-file: fix stat() race
_dbus_desktop_file_load() used to stat the desktop file before reading it, to verify its size. This is both racy and unnecessary since _dbus_file_get_contents() which it uses stats the file anyway -- does that however in a race-free fashion with fstat() instead of stat(). This patch gets rid of the redundant stat(). Also, since the desktop file change logic requires the mtime of the file it read we now export that in _dbus_file_get_contents(). This patch probably breaks Win32 builds, but afaik those are broken anyway.
-rw-r--r--bus/config-loader-expat.c8
-rw-r--r--dbus/dbus-auth-script.c76
-rw-r--r--dbus/dbus-desktop-file.c19
-rw-r--r--dbus/dbus-internals.c90
-rw-r--r--dbus/dbus-keyring.c136
-rw-r--r--dbus/dbus-message-util.c34
-rw-r--r--dbus/dbus-sha.c64
-rw-r--r--dbus/dbus-sysdeps-unix.c385
-rw-r--r--dbus/dbus-sysdeps.h29
9 files changed, 415 insertions, 426 deletions
diff --git a/bus/config-loader-expat.c b/bus/config-loader-expat.c
index c0620aed..b6c92451 100644
--- a/bus/config-loader-expat.c
+++ b/bus/config-loader-expat.c
@@ -173,7 +173,7 @@ bus_config_load (const DBusString *file,
BusConfigParser *parser;
ExpatParseContext context;
DBusString dirname;
-
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
parser = NULL;
@@ -195,7 +195,7 @@ bus_config_load (const DBusString *file,
_dbus_string_free (&context.content);
return NULL;
}
-
+
expat = XML_ParserCreate_MM ("UTF-8", &memsuite, NULL);
if (expat == NULL)
{
@@ -208,7 +208,7 @@ bus_config_load (const DBusString *file,
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed;
}
-
+
parser = bus_config_parser_new (&dirname, is_toplevel, parent);
if (parser == NULL)
{
@@ -234,7 +234,7 @@ bus_config_load (const DBusString *file,
goto failed;
}
- if (!_dbus_file_get_contents (&data, file, error))
+ if (!_dbus_file_get_contents (&data, file, NULL, error))
{
_dbus_string_free (&data);
goto failed;
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c
index 6285e3ba..8bf7e78a 100644
--- a/dbus/dbus-auth-script.c
+++ b/dbus/dbus-auth-script.c
@@ -1,10 +1,10 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-auth-script.c Test DBusAuth using a special script file (internal to D-Bus implementation)
- *
+ *
* Copyright (C) 2003 Red Hat, Inc.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
@@ -14,7 +14,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -63,7 +63,7 @@ append_quoted_string (DBusString *dest,
if (in_backslash)
{
unsigned char a;
-
+
if (b == 'r')
a = '\r';
else if (b == 'n')
@@ -78,7 +78,7 @@ append_quoted_string (DBusString *dest,
if (!_dbus_string_append_byte (dest, a))
return FALSE;
-
+
in_backslash = FALSE;
}
else if (b == '\\')
@@ -107,7 +107,7 @@ append_quoted_string (DBusString *dest,
return FALSE;
}
}
-
+
++i;
}
@@ -131,7 +131,7 @@ same_first_word (const DBusString *a,
static DBusAuthState
auth_state_from_string (const DBusString *str)
-{
+{
if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_INPUT"))
return DBUS_AUTH_STATE_WAITING_FOR_INPUT;
else if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_MEMORY"))
@@ -253,13 +253,13 @@ _dbus_auth_script_run (const DBusString *filename)
DBusAuthState state;
DBusString context;
DBusString guid;
-
+
retval = FALSE;
auth = NULL;
_dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00");
_dbus_string_init_const (&context, "org_freedesktop_test");
-
+
if (!_dbus_string_init (&file))
return FALSE;
@@ -276,7 +276,7 @@ _dbus_auth_script_run (const DBusString *filename)
return FALSE;
}
- if (!_dbus_file_get_contents (&file, filename, &error)) {
+ if (!_dbus_file_get_contents (&file, filename, NULL, &error)) {
_dbus_warn ("Getting contents of %s failed: %s\n",
_dbus_string_get_const_data (filename), error.message);
dbus_error_free (&error);
@@ -288,11 +288,11 @@ _dbus_auth_script_run (const DBusString *filename)
next_iteration:
while (_dbus_string_pop_line (&file, &line))
- {
+ {
line_no += 1;
/* _dbus_warn ("%s\n", _dbus_string_get_const_data (&line)); */
-
+
_dbus_string_delete_leading_blanks (&line);
if (auth != NULL)
@@ -311,7 +311,7 @@ _dbus_auth_script_run (const DBusString *filename)
}
}
}
-
+
if (_dbus_string_get_length (&line) == 0)
{
/* empty line */
@@ -359,7 +359,7 @@ _dbus_auth_script_run (const DBusString *filename)
"CLIENT"))
{
DBusCredentials *creds;
-
+
if (auth != NULL)
{
_dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n");
@@ -385,7 +385,7 @@ _dbus_auth_script_run (const DBusString *filename)
auth = NULL;
goto out;
}
-
+
if (!_dbus_auth_set_credentials (auth, creds))
{
_dbus_warn ("no memory for setting credentials\n");
@@ -394,14 +394,14 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_credentials_unref (creds);
goto out;
}
-
+
_dbus_credentials_unref (creds);
}
else if (_dbus_string_starts_with_c_str (&line,
"SERVER"))
{
DBusCredentials *creds;
-
+
if (auth != NULL)
{
_dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n");
@@ -427,7 +427,7 @@ _dbus_auth_script_run (const DBusString *filename)
auth = NULL;
goto out;
}
-
+
if (!_dbus_auth_set_credentials (auth, creds))
{
_dbus_warn ("no memory for setting credentials\n");
@@ -436,7 +436,7 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_credentials_unref (creds);
goto out;
}
-
+
_dbus_credentials_unref (creds);
_dbus_auth_set_context (auth, &context);
@@ -476,7 +476,7 @@ _dbus_auth_script_run (const DBusString *filename)
"SEND"))
{
DBusString to_send;
-
+
_dbus_string_delete_first_word (&line);
if (!_dbus_string_init (&to_send))
@@ -494,7 +494,7 @@ _dbus_auth_script_run (const DBusString *filename)
}
_dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send));
-
+
if (!_dbus_string_append (&to_send, "\r\n"))
{
_dbus_warn ("failed to append \r\n from line %d\n",
@@ -506,7 +506,7 @@ _dbus_auth_script_run (const DBusString *filename)
/* Replace USERID_HEX with our username in hex */
{
int where;
-
+
if (_dbus_string_find (&to_send, 0,
"USERID_HEX", &where))
{
@@ -528,7 +528,7 @@ _dbus_auth_script_run (const DBusString *filename)
}
_dbus_string_delete (&to_send, where, strlen ("USERID_HEX"));
-
+
if (!_dbus_string_hex_encode (&username, 0,
&to_send, where))
{
@@ -544,7 +544,7 @@ _dbus_auth_script_run (const DBusString *filename)
"USERNAME_HEX", &where))
{
DBusString username;
-
+
if (!_dbus_string_init (&username))
{
_dbus_warn ("no memory for username\n");
@@ -561,7 +561,7 @@ _dbus_auth_script_run (const DBusString *filename)
}
_dbus_string_delete (&to_send, where, strlen ("USERNAME_HEX"));
-
+
if (!_dbus_string_hex_encode (&username, 0,
&to_send, where))
{
@@ -590,14 +590,14 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_auth_return_buffer (auth, buffer, _dbus_string_get_length (&to_send));
}
-
+
_dbus_string_free (&to_send);
}
else if (_dbus_string_starts_with_c_str (&line,
"EXPECT_STATE"))
{
DBusAuthState expected;
-
+
_dbus_string_delete_first_word (&line);
expected = auth_state_from_string (&line);
@@ -620,7 +620,7 @@ _dbus_auth_script_run (const DBusString *filename)
"EXPECT_COMMAND"))
{
DBusString received;
-
+
_dbus_string_delete_first_word (&line);
if (!_dbus_string_init (&received))
@@ -646,7 +646,7 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_string_free (&received);
goto out;
}
-
+
_dbus_string_free (&received);
}
else if (_dbus_string_starts_with_c_str (&line,
@@ -654,7 +654,7 @@ _dbus_auth_script_run (const DBusString *filename)
{
DBusString expected;
const DBusString *unused;
-
+
_dbus_string_delete_first_word (&line);
if (!_dbus_string_init (&expected))
@@ -672,7 +672,7 @@ _dbus_auth_script_run (const DBusString *filename)
}
_dbus_auth_get_unused_bytes (auth, &unused);
-
+
if (_dbus_string_equal (&expected, unused))
{
_dbus_auth_delete_unused_bytes (auth);
@@ -691,7 +691,7 @@ _dbus_auth_script_run (const DBusString *filename)
"EXPECT_HAVE_NO_CREDENTIALS"))
{
DBusCredentials *authorized_identity;
-
+
authorized_identity = _dbus_auth_get_identity (auth);
if (!_dbus_credentials_are_anonymous (authorized_identity))
{
@@ -703,7 +703,7 @@ _dbus_auth_script_run (const DBusString *filename)
"EXPECT_HAVE_SOME_CREDENTIALS"))
{
DBusCredentials *authorized_identity;
-
+
authorized_identity = _dbus_auth_get_identity (auth);
if (_dbus_credentials_are_anonymous (authorized_identity))
{
@@ -715,7 +715,7 @@ _dbus_auth_script_run (const DBusString *filename)
"EXPECT"))
{
DBusString expected;
-
+
_dbus_string_delete_first_word (&line);
if (!_dbus_string_init (&expected))
@@ -752,7 +752,7 @@ _dbus_auth_script_run (const DBusString *filename)
goto parse_failed;
goto next_iteration; /* skip parse_failed */
-
+
parse_failed:
{
_dbus_warn ("couldn't process line %d \"%s\"\n",
@@ -785,9 +785,9 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_warn ("Leftover data: %s\n", _dbus_string_get_const_data (&from_auth));
goto out;
}
-
+
retval = TRUE;
-
+
out:
if (auth)
_dbus_auth_unref (auth);
@@ -795,7 +795,7 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_string_free (&file);
_dbus_string_free (&line);
_dbus_string_free (&from_auth);
-
+
return retval;
}
diff --git a/dbus/dbus-desktop-file.c b/dbus/dbus-desktop-file.c
index 4f17b93f..8994c4b6 100644
--- a/dbus/dbus-desktop-file.c
+++ b/dbus/dbus-desktop-file.c
@@ -625,30 +625,17 @@ _dbus_desktop_file_load (DBusString *filename,
{
DBusString str;
DBusDesktopFileParser parser;
- DBusStat sb;
+ unsigned long mtime;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- /* Clearly there's a race here, but it's just to make it unlikely
- * that we do something silly, we still handle doing it below.
- */
- if (!_dbus_stat (filename, &sb, error))
- return NULL;
-
- if (sb.size > _DBUS_ONE_KILOBYTE * 128)
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Desktop file size (%ld bytes) is too large", (long) sb.size);
- return NULL;
- }
-
if (!_dbus_string_init (&str))
{
_DBUS_SET_OOM (error);
return NULL;
}
- if (!_dbus_file_get_contents (&str, filename, error))
+ if (!_dbus_file_get_contents (&str, filename, &mtime, error))
{
_dbus_string_free (&str);
return NULL;
@@ -670,7 +657,7 @@ _dbus_desktop_file_load (DBusString *filename,
return NULL;
}
- parser.desktop_file->mtime = sb.mtime;
+ parser.desktop_file->mtime = mtime;
parser.data = str;
parser.line_num = 1;
parser.pos = 0;
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c
index c5885eae..56b1eec0 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -4,7 +4,7 @@
* Copyright (C) 2002, 2003 Red Hat, Inc.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
@@ -14,7 +14,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -32,7 +32,7 @@
/**
* @defgroup DBusInternals D-Bus secret internal implementation details
* @brief Documentation useful when developing or debugging D-Bus itself.
- *
+ *
*/
/**
@@ -46,7 +46,7 @@
* @def _dbus_assert
*
* Aborts with an error message if the condition is false.
- *
+ *
* @param condition condition which must be true.
*/
@@ -55,7 +55,7 @@
*
* Aborts with an error message if called.
* The given explanation will be printed.
- *
+ *
* @param explanation explanation of what happened if the code was reached.
*/
@@ -144,7 +144,7 @@
/**
* @typedef DBusForeachFunction
- *
+ *
* Used to iterate over each item in a collection, such as
* a DBusList.
*/
@@ -242,7 +242,7 @@ _dbus_warn (const char *format,
if (!warn_initted)
init_warnings ();
-
+
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
@@ -267,12 +267,12 @@ _dbus_warn_check_failed(const char *format,
...)
{
va_list args;
-
+
if (!warn_initted)
init_warnings ();
fprintf (stderr, "process %lu: ", _dbus_pid_for_log ());
-
+
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
@@ -304,7 +304,7 @@ _dbus_verbose_init (void)
{
if (!verbose_initted)
{
- const char *p = _dbus_getenv ("DBUS_VERBOSE");
+ const char *p = _dbus_getenv ("DBUS_VERBOSE");
verbose = p != NULL && *p == '1';
verbose_initted = TRUE;
}
@@ -337,7 +337,7 @@ _dbus_verbose_real (const char *format,
va_list args;
static dbus_bool_t need_pid = TRUE;
int len;
-
+
/* things are written a bit oddly here so that
* in the non-verbose case we just have the one
* conditional and return immediately.
@@ -354,7 +354,7 @@ _dbus_verbose_real (const char *format,
fprintf (stderr, "%lu: ", _dbus_pid_for_log ());
#endif
}
-
+
/* Only print pid again if the next line is a new line */
len = strlen (format);
@@ -362,7 +362,7 @@ _dbus_verbose_real (const char *format,
need_pid = TRUE;
else
need_pid = FALSE;
-
+
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
@@ -388,7 +388,7 @@ _dbus_verbose_reset_real (void)
* Duplicates a string. Result must be freed with
* dbus_free(). Returns #NULL if memory allocation fails.
* If the string to be duplicated is #NULL, returns #NULL.
- *
+ *
* @param str string to duplicate.
* @returns newly-allocated copy.
*/
@@ -397,10 +397,10 @@ _dbus_strdup (const char *str)
{
size_t len;
char *copy;
-
+
if (str == NULL)
return NULL;
-
+
len = strlen (str);
copy = dbus_malloc (len + 1);
@@ -408,7 +408,7 @@ _dbus_strdup (const char *str)
return NULL;
memcpy (copy, str, len + 1);
-
+
return copy;
}
@@ -431,7 +431,7 @@ _dbus_memdup (const void *mem,
return NULL;
memcpy (copy, mem, n_bytes);
-
+
return copy;
}
@@ -439,7 +439,7 @@ _dbus_memdup (const void *mem,
* Duplicates a string array. Result may be freed with
* dbus_free_string_array(). Returns #NULL if memory allocation fails.
* If the array to be duplicated is #NULL, returns #NULL.
- *
+ *
* @param array array to duplicate.
* @returns newly-allocated copy.
*/
@@ -449,7 +449,7 @@ _dbus_dup_string_array (const char **array)
int len;
int i;
char **copy;
-
+
if (array == NULL)
return NULL;
@@ -478,7 +478,7 @@ _dbus_dup_string_array (const char **array)
/**
* Checks whether a string array contains the given string.
- *
+ *
* @param array array to search.
* @param str string to look for
* @returns #TRUE if array contains string
@@ -514,7 +514,7 @@ _dbus_generate_uuid (DBusGUID *uuid)
_dbus_get_current_time (&now, NULL);
uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
-
+
_dbus_generate_random_bytes_buffer (uuid->as_bytes, DBUS_UUID_LENGTH_BYTES - 4);
}
@@ -542,7 +542,7 @@ _dbus_read_uuid_file_without_creating (const DBusString *filename,
DBusString contents;
DBusString decoded;
int end;
-
+
if (!_dbus_string_init (&contents))
{
_DBUS_SET_OOM (error);
@@ -555,8 +555,8 @@ _dbus_read_uuid_file_without_creating (const DBusString *filename,
_DBUS_SET_OOM (error);
return FALSE;
}
-
- if (!_dbus_file_get_contents (&contents, filename, error))
+
+ if (!_dbus_file_get_contents (&contents, filename, NULL, error))
goto error;
_dbus_string_chop_white (&contents);
@@ -603,7 +603,7 @@ _dbus_read_uuid_file_without_creating (const DBusString *filename,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return TRUE;
-
+
error:
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_string_free (&contents);
@@ -625,13 +625,13 @@ _dbus_create_uuid_file_exclusively (const DBusString *filename,
}
_dbus_generate_uuid (uuid);
-
+
if (!_dbus_uuid_encode (uuid, &encoded))
{
_DBUS_SET_OOM (error);
goto error;
}
-
+
/* FIXME this is racy; we need a save_file_exclusively
* function. But in practice this should be fine for now.
*
@@ -648,7 +648,7 @@ _dbus_create_uuid_file_exclusively (const DBusString *filename,
_DBUS_SET_OOM (error);
goto error;
}
-
+
if (!_dbus_string_save_to_file (&encoded, filename, error))
goto error;
@@ -659,11 +659,11 @@ _dbus_create_uuid_file_exclusively (const DBusString *filename,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return TRUE;
-
+
error:
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_string_free (&encoded);
- return FALSE;
+ return FALSE;
}
/**
@@ -719,7 +719,7 @@ static DBusGUID machine_uuid;
* machine at least until it next reboots, though it also
* makes some effort to be the same forever, it may change if the
* machine is reconfigured or its hardware is modified.
- *
+ *
* @param uuid_str string to append hex-encoded machine uuid to
* @returns #FALSE if no memory
*/
@@ -727,7 +727,7 @@ dbus_bool_t
_dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
{
dbus_bool_t ok;
-
+
_DBUS_LOCK (machine_uuid);
if (machine_uuid_initialized_generation != _dbus_current_generation)
{
@@ -735,7 +735,7 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE,
&error))
- {
+ {
#ifndef DBUS_BUILD_TESTS
/* For the test suite, we may not be installed so just continue silently
* here. But in a production build, we want to be nice and loud about
@@ -745,9 +745,9 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
"See the manual page for dbus-uuidgen to correct this issue.\n",
error.message);
#endif
-
+
dbus_error_free (&error);
-
+
_dbus_generate_uuid (&machine_uuid);
}
}
@@ -850,7 +850,7 @@ _dbus_real_assert_not_reached (const char *explanation,
_dbus_abort ();
}
#endif /* DBUS_DISABLE_ASSERT */
-
+
#ifdef DBUS_BUILD_TESTS
static dbus_bool_t
run_failing_each_malloc (int n_mallocs,
@@ -859,9 +859,9 @@ run_failing_each_malloc (int n_mallocs,
void *data)
{
n_mallocs += 10; /* fudge factor to ensure reallocs etc. are covered */
-
+
while (n_mallocs >= 0)
- {
+ {
_dbus_set_fail_alloc_counter (n_mallocs);
_dbus_verbose ("\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
@@ -870,14 +870,14 @@ run_failing_each_malloc (int n_mallocs,
if (!(* func) (data))
return FALSE;
-
+
n_mallocs -= 1;
}
_dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
return TRUE;
-}
+}
/**
* Tests how well the given function responds to out-of-memory
@@ -903,14 +903,14 @@ _dbus_test_oom_handling (const char *description,
int i;
/* Run once to see about how many mallocs are involved */
-
+
_dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
_dbus_verbose ("Running once to count mallocs\n");
-
+
if (!(* func) (data))
return FALSE;
-
+
approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
_dbus_verbose ("\n=================\n%s: about %d mallocs total\n=================\n",
@@ -940,7 +940,7 @@ _dbus_test_oom_handling (const char *description,
return FALSE;
++i;
}
-
+
_dbus_verbose ("\n=================\n%s: all iterations passed\n=================\n",
description);
diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c
index 6dc1e129..21bde3a5 100644
--- a/dbus/dbus-keyring.c
+++ b/dbus/dbus-keyring.c
@@ -4,7 +4,7 @@
* Copyright (C) 2003, 2004 Red Hat Inc.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
@@ -14,7 +14,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -96,14 +96,14 @@ typedef struct
* as unix timestamp. signed long
* matches struct timeval.
*/
-
+
DBusString secret; /**< the actual key */
} DBusKey;
/**
* @brief Internals of DBusKeyring.
- *
+ *
* DBusKeyring internals. DBusKeyring is an opaque object, it must be
* used via accessor functions.
*/
@@ -126,7 +126,7 @@ _dbus_keyring_new (void)
keyring = dbus_new0 (DBusKeyring, 1);
if (keyring == NULL)
goto out_0;
-
+
if (!_dbus_string_init (&keyring->directory))
goto out_1;
@@ -135,7 +135,7 @@ _dbus_keyring_new (void)
if (!_dbus_string_init (&keyring->filename_lock))
goto out_3;
-
+
keyring->refcount = 1;
keyring->keys = NULL;
keyring->n_keys = 0;
@@ -161,7 +161,7 @@ free_keys (DBusKey *keys,
int i;
/* should be safe for args NULL, 0 */
-
+
i = 0;
while (i < n_keys)
{
@@ -197,7 +197,7 @@ static dbus_bool_t
_dbus_keyring_lock (DBusKeyring *keyring)
{
int n_timeouts;
-
+
n_timeouts = 0;
while (n_timeouts < MAX_LOCK_TIMEOUTS)
{
@@ -212,7 +212,7 @@ _dbus_keyring_lock (DBusKeyring *keyring)
dbus_error_free (&error);
_dbus_sleep_milliseconds (LOCK_TIMEOUT_MILLISECONDS);
-
+
++n_timeouts;
}
@@ -240,7 +240,7 @@ _dbus_keyring_lock (DBusKeyring *keyring)
return FALSE;
}
}
-
+
return TRUE;
}
@@ -269,7 +269,7 @@ find_key_by_id (DBusKey *keys,
{
if (keys[i].id == id)
return &keys[i];
-
+
++i;
}
@@ -291,7 +291,7 @@ add_new_key (DBusKey **keys_p,
int n_keys;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
if (!_dbus_string_init (&bytes))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -301,10 +301,10 @@ add_new_key (DBusKey **keys_p,
keys = *keys_p;
n_keys = *n_keys_p;
retval = FALSE;
-
+
/* Generate an integer ID and then the actual key. */
retry:
-
+
if (!_dbus_generate_random_bytes (&bytes, 4))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -312,7 +312,7 @@ add_new_key (DBusKey **keys_p,
}
s = (const unsigned char*) _dbus_string_get_const_data (&bytes);
-
+
id = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24);
if (id < 0)
id = - id;
@@ -327,7 +327,7 @@ add_new_key (DBusKey **keys_p,
}
_dbus_verbose ("Creating key with ID %d\n", id);
-
+
#define KEY_LENGTH_BYTES 24
_dbus_string_set_length (&bytes, 0);
if (!_dbus_generate_random_bytes (&bytes, KEY_LENGTH_BYTES))
@@ -355,7 +355,7 @@ add_new_key (DBusKey **keys_p,
}
_dbus_get_current_time (&timestamp, NULL);
-
+
keys[n_keys-1].id = id;
keys[n_keys-1].creation_time = timestamp;
if (!_dbus_string_move (&bytes, 0,
@@ -367,12 +367,12 @@ add_new_key (DBusKey **keys_p,
n_keys -= 1;
goto out;
}
-
+
retval = TRUE;
-
+
out:
*n_keys_p = n_keys;
-
+
_dbus_string_free (&bytes);
return retval;
}
@@ -407,10 +407,10 @@ _dbus_keyring_reload (DBusKeyring *keyring,
DBusError tmp_error;
_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);
@@ -423,14 +423,14 @@ _dbus_keyring_reload (DBusKeyring *keyring,
_dbus_string_free (&contents);
return FALSE;
}
-
+
keys = NULL;
n_keys = 0;
retval = FALSE;
have_lock = FALSE;
_dbus_get_current_time (&now, NULL);
-
+
if (add_new)
{
if (!_dbus_keyring_lock (keyring))
@@ -444,8 +444,9 @@ _dbus_keyring_reload (DBusKeyring *keyring,
}
dbus_error_init (&tmp_error);
- if (!_dbus_file_get_contents (&contents,
+ if (!_dbus_file_get_contents (&contents,
&keyring->filename,
+ NULL,
&tmp_error))
{
_dbus_verbose ("Failed to load keyring file: %s\n",
@@ -477,7 +478,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
/* Don't load more than the max. */
if (n_keys >= (add_new ? MAX_KEYS_IN_FILE - 1 : MAX_KEYS_IN_FILE))
break;
-
+
next = 0;
if (!_dbus_string_parse_int (&line, 0, &val, &next))
{
@@ -490,11 +491,11 @@ _dbus_keyring_reload (DBusKeyring *keyring,
_dbus_verbose ("invalid secret key ID at start of line\n");
continue;
}
-
+
id = val;
_dbus_string_skip_blank (&line, next, &next);
-
+
if (!_dbus_string_parse_int (&line, next, &timestamp, &next))
{
_dbus_verbose ("could not parse secret key timestamp\n");
@@ -509,7 +510,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
now - timestamp, timestamp, now);
continue;
}
-
+
_dbus_string_skip_blank (&line, next, &next);
len = _dbus_string_get_length (&line);
@@ -519,7 +520,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
_dbus_verbose ("no secret key after ID and timestamp\n");
continue;
}
-
+
/* We have all three parts */
new = dbus_realloc (keys, sizeof (DBusKey) * (n_keys + 1));
if (new == NULL)
@@ -537,7 +538,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto out;
}
-
+
keys[n_keys-1].id = id;
keys[n_keys-1].creation_time = timestamp;
if (!_dbus_string_hex_decode (&line, next, &end,
@@ -593,8 +594,8 @@ _dbus_keyring_reload (DBusKeyring *keyring,
goto nomem;
if (!_dbus_string_append_byte (&contents, '\n'))
- goto nomem;
-
+ goto nomem;
+
++i;
continue;
@@ -602,7 +603,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto out;
}
-
+
if (!_dbus_string_save_to_file (&contents, &keyring->filename,
error))
goto out;
@@ -614,13 +615,13 @@ _dbus_keyring_reload (DBusKeyring *keyring,
keyring->n_keys = n_keys;
keys = NULL;
n_keys = 0;
-
- retval = TRUE;
-
+
+ retval = TRUE;
+
out:
if (have_lock)
_dbus_keyring_unlock (keyring);
-
+
if (! ((retval == TRUE && (error == NULL || error->name == NULL)) ||
(retval == FALSE && (error == NULL || error->name != NULL))))
{
@@ -630,7 +631,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
retval, error, error->name ? error->name : "(none)");
_dbus_assert_not_reached ("didn't handle errors properly");
}
-
+
if (keys != NULL)
{
i = 0;
@@ -643,7 +644,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
dbus_free (keys);
}
-
+
_dbus_string_free (&contents);
_dbus_string_free (&line);
@@ -692,7 +693,7 @@ _dbus_keyring_unref (DBusKeyring *keyring)
_dbus_string_free (&keyring->filename_lock);
_dbus_string_free (&keyring->directory);
free_keys (keyring->keys, keyring->n_keys);
- dbus_free (keyring);
+ dbus_free (keyring);
}
}
@@ -716,13 +717,13 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
dbus_bool_t error_set;
DBusError tmp_error;
DBusCredentials *our_credentials;
-
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
keyring = NULL;
error_set = FALSE;
our_credentials = NULL;
-
+
if (!_dbus_string_init (&ringdir))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -737,7 +738,7 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
{
our_credentials = _dbus_credentials_new_from_current_process ();
}
-
+
if (our_credentials == NULL)
goto failed;
@@ -746,11 +747,11 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
if (!_dbus_credentials_add_from_current_process (our_credentials))
goto failed;
}
-
+
if (!_dbus_append_keyring_directory_for_credentials (&ringdir,
our_credentials))
goto failed;
-
+
keyring = _dbus_keyring_new ();
if (keyring == NULL)
goto failed;
@@ -758,7 +759,7 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
_dbus_assert (keyring->credentials == NULL);
keyring->credentials = our_credentials;
our_credentials = NULL; /* so we don't unref it again later */
-
+
/* should have been validated already, but paranoia check here */
if (!_dbus_keyring_validate_context (context))
{
@@ -772,7 +773,7 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
/* Save keyring dir in the keyring object */
if (!_dbus_string_copy (&ringdir, 0,
&keyring->directory, 0))
- goto failed;
+ goto failed;
/* Create keyring->filename based on keyring dir and context */
if (!_dbus_string_copy (&keyring->directory, 0,
@@ -799,7 +800,7 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
tmp_error.message);
dbus_error_free (&tmp_error);
}
-
+
/* We don't fail fatally if we can't create the directory,
* but the keyring will probably always be empty
* unless someone else manages to create it
@@ -814,9 +815,9 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
}
_dbus_string_free (&ringdir);
-
+
return keyring;
-
+
failed:
if (!error_set)
dbus_set_error_const (error,
@@ -858,8 +859,8 @@ _dbus_keyring_validate_context (const DBusString *context)
_dbus_verbose ("context not valid ascii\n");
return FALSE;
}
-
- /* no directory separators */
+
+ /* no directory separators */
if (_dbus_string_find (context, 0, "/", NULL))
{
_dbus_verbose ("context contains a slash\n");
@@ -899,7 +900,7 @@ _dbus_keyring_validate_context (const DBusString *context)
_dbus_verbose ("context contains a carriage return\n");
return FALSE;
}
-
+
return TRUE;
}
@@ -910,7 +911,7 @@ find_recent_key (DBusKeyring *keyring)
long tv_sec, tv_usec;
_dbus_get_current_time (&tv_sec, &tv_usec);
-
+
i = 0;
while (i < keyring->n_keys)
{
@@ -918,10 +919,10 @@ find_recent_key (DBusKeyring *keyring)
_dbus_verbose ("Key %d is %ld seconds old\n",
i, tv_sec - key->creation_time);
-
+
if ((tv_sec - NEW_KEY_TIMEOUT_SECONDS) < key->creation_time)
return key;
-
+
++i;
}
@@ -946,7 +947,7 @@ _dbus_keyring_get_best_key (DBusKeyring *keyring,
DBusKey *key;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
key = find_recent_key (keyring);
if (key)
return key->id;
@@ -1033,14 +1034,14 @@ _dbus_keyring_test (void)
ring1 = NULL;
ring2 = NULL;
-
+
/* Context validation */
-
+
_dbus_string_init_const (&context, "foo");
_dbus_assert (_dbus_keyring_validate_context (&context));
_dbus_string_init_const (&context, "org_freedesktop_blah");
_dbus_assert (_dbus_keyring_validate_context (&context));
-
+
_dbus_string_init_const (&context, "");
_dbus_assert (!_dbus_keyring_validate_context (&context));
_dbus_string_init_const (&context, ".foo");
@@ -1059,7 +1060,7 @@ _dbus_keyring_test (void)
_dbus_assert (_dbus_keyring_validate_context (&context));
_dbus_string_init_const (&context, "foo bar");
_dbus_assert (!_dbus_keyring_validate_context (&context));
-
+
if (!_dbus_string_init (&context))
_dbus_assert_not_reached ("no memory");
if (!_dbus_string_append_byte (&context, '\0'))
@@ -1089,7 +1090,7 @@ _dbus_keyring_test (void)
ring2 = _dbus_keyring_new_for_credentials (NULL, &context, &error);
_dbus_assert (ring2 != NULL);
_dbus_assert (error.name == NULL);
-
+
if (ring1->n_keys != ring2->n_keys)
{
fprintf (stderr, "Different number of keys in keyrings\n");
@@ -1107,7 +1108,7 @@ _dbus_keyring_test (void)
fprintf (stderr, "Keyring 1 has first key ID %d and keyring 2 has %d\n",
ring1->keys[i].id, ring2->keys[i].id);
goto failure;
- }
+ }
if (ring1->keys[i].creation_time != ring2->keys[i].creation_time)
{
@@ -1122,7 +1123,7 @@ _dbus_keyring_test (void)
fprintf (stderr, "Keyrings 1 and 2 have different secrets for same ID/timestamp\n");
goto failure;
}
-
+
++i;
}
@@ -1138,7 +1139,7 @@ _dbus_keyring_test (void)
/* really unref */
_dbus_keyring_unref (ring1);
_dbus_keyring_unref (ring2);
-
+
return TRUE;
failure:
@@ -1151,4 +1152,3 @@ _dbus_keyring_test (void)
}
#endif /* DBUS_BUILD_TESTS */
-
diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c
index a56fcc49..df371e4c 100644
--- a/dbus/dbus-message-util.c
+++ b/dbus/dbus-message-util.c
@@ -221,7 +221,7 @@ check_have_valid_message (DBusMessageLoader *loader)
#endif
record_validity_seen (DBUS_VALID);
-
+
retval = TRUE;
failed:
@@ -246,7 +246,7 @@ check_invalid_message (DBusMessageLoader *loader,
}
record_validity_seen (loader->corruption_reason);
-
+
if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON &&
loader->corruption_reason != expected_validity)
{
@@ -312,7 +312,7 @@ check_loader_results (DBusMessageLoader *loader,
*/
if (_dbus_message_loader_get_is_corrupted (loader))
record_validity_seen (loader->corruption_reason);
-
+
return TRUE;
}
else
@@ -336,7 +336,7 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename,
retval = FALSE;
_dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename));
- if (!_dbus_file_get_contents (data, filename, &error))
+ if (!_dbus_file_get_contents (data, filename, NULL, &error))
{
_dbus_warn ("Could not load message file %s: %s\n",
_dbus_string_get_const_data (filename),
@@ -560,7 +560,7 @@ process_test_subdir (const DBusString *test_base_dir,
_dbus_warn ("Could not load %s, message builder language no longer supported\n",
_dbus_string_get_const_data (&filename));
}
-
+
_dbus_verbose ("Skipping non-.message file %s\n",
_dbus_string_get_const_data (&filename));
_dbus_string_free (&full_path);
@@ -621,27 +621,27 @@ dbus_internal_do_not_use_foreach_message_file (const char *test_d
retval = FALSE;
_dbus_string_init_const (&test_directory, test_data_dir);
-
+
if (!process_test_subdir (&test_directory, "valid-messages",
DBUS_VALID, func, user_data))
goto failed;
check_memleaks ();
-
+
if (!process_test_subdir (&test_directory, "invalid-messages",
DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
goto failed;
check_memleaks ();
-
+
if (!process_test_subdir (&test_directory, "incomplete-messages",
DBUS_VALID_BUT_INCOMPLETE, func, user_data))
goto failed;
check_memleaks ();
-
+
retval = TRUE;
-
+
failed:
_dbus_string_free (&test_directory);
@@ -831,7 +831,7 @@ verify_test_message (DBusMessage *message)
if (our_uint16 != 0x123)
_dbus_assert_not_reached ("16-bit uints differ!");
-
+
if (our_int != -0x12345678)
_dbus_assert_not_reached ("integers differ!");
@@ -936,7 +936,7 @@ verify_test_message (DBusMessage *message)
_dbus_assert_not_reached ("string array had wrong values");
dbus_free_string_array (our_string_array);
-
+
if (dbus_message_iter_next (&iter))
_dbus_assert_not_reached ("Didn't reach end of arguments");
}
@@ -1246,7 +1246,7 @@ _dbus_message_test (const char *test_data_dir)
/* Message loader test */
dbus_message_lock (message);
loader = _dbus_message_loader_new ();
-
+
/* check ref/unref */
_dbus_message_loader_ref (loader);
_dbus_message_loader_unref (loader);
@@ -1354,7 +1354,7 @@ _dbus_message_test (const char *test_data_dir)
/* Bytes needed to demarshal empty message: 0 (more) */
_dbus_assert (dbus_message_demarshal_bytes_needed ("", 0) == 0);
-
+
/* Bytes needed to demarshal invalid message: -1 (error). */
_dbus_assert (dbus_message_demarshal_bytes_needed (garbage_header, DBUS_MINIMUM_HEADER_SIZE) == -1);
@@ -1401,10 +1401,10 @@ _dbus_message_test (const char *test_data_dir)
int count;
reset_validities_seen ();
-
+
count = 0;
_dbus_message_data_iter_init (&diter);
-
+
while (_dbus_message_data_iter_get_and_next (&diter,
&mdata))
{
@@ -1437,7 +1437,7 @@ _dbus_message_test (const char *test_data_dir)
return dbus_internal_do_not_use_foreach_message_file (test_data_dir,
(DBusForeachMessageFileFunc)
dbus_internal_do_not_use_try_message_file,
- NULL);
+ NULL);
}
#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c
index 04e353a0..03b098ba 100644
--- a/dbus/dbus-sha.c
+++ b/dbus/dbus-sha.c
@@ -500,7 +500,7 @@ _dbus_sha_compute (const DBusString *data,
goto error;
_dbus_string_free (&digest);
-
+
return TRUE;
error:
@@ -562,7 +562,7 @@ decode_compact_string (const DBusString *line,
int next;
long val;
int length_bytes;
-
+
offset = 0;
next = 0;
@@ -574,7 +574,7 @@ decode_compact_string (const DBusString *line,
}
_dbus_string_skip_blank (line, next, &next);
-
+
offset = next;
if (!_dbus_string_parse_int (line, offset, &val, &next))
{
@@ -582,7 +582,7 @@ decode_compact_string (const DBusString *line,
_dbus_string_get_const_data (line));
return FALSE;
}
-
+
if (!(val == 0 || val == 1))
{
fprintf (stderr, "the value 'b' must be 0 or 1, see sha-1/Readme.txt\n");
@@ -590,19 +590,19 @@ decode_compact_string (const DBusString *line,
}
_dbus_string_skip_blank (line, next, &next);
-
+
current_b = val;
n_bits = 0;
-
+
while (next < _dbus_string_get_length (line))
{
int total_bits;
-
+
offset = next;
if (_dbus_string_get_byte (line, offset) == '^')
break;
-
+
if (!_dbus_string_parse_int (line, offset, &val, &next))
{
fprintf (stderr, "could not parse bit count in compact string\n");
@@ -616,7 +616,7 @@ decode_compact_string (const DBusString *line,
int byte_containing_next_bit = n_bits / 8;
int bit_containing_next_bit = 7 - (n_bits % 8);
unsigned char old_byte;
-
+
if (byte_containing_next_bit >= _dbus_string_get_length (decoded))
{
if (!_dbus_string_set_length (decoded, byte_containing_next_bit + 1))
@@ -631,19 +631,19 @@ decode_compact_string (const DBusString *line,
current_b, byte_containing_next_bit,
bit_containing_next_bit, old_byte);
#endif
-
+
_dbus_string_set_byte (decoded, byte_containing_next_bit, old_byte);
-
+
++n_bits;
}
_dbus_string_skip_blank (line, next, &next);
-
+
current_b = !current_b;
}
length_bytes = (n_bits / 8 + ((n_bits % 8) ? 1 : 0));
-
+
if (_dbus_string_get_length (decoded) != length_bytes)
{
fprintf (stderr, "Expected length %d bytes %d bits for compact string, got %d bytes\n",
@@ -662,10 +662,10 @@ get_next_expected_result (DBusString *results,
dbus_bool_t retval;
retval = FALSE;
-
+
if (!_dbus_string_init (&line))
_dbus_assert_not_reached ("no memory");
-
+
next_iteration:
while (_dbus_string_pop_line (results, &line))
{
@@ -685,7 +685,7 @@ get_next_expected_result (DBusString *results,
else
{
int i;
-
+
if (!_dbus_string_move (&line, 0, result, 0))
_dbus_assert_not_reached ("no memory");
@@ -721,13 +721,13 @@ get_next_expected_result (DBusString *results,
++i;
}
-
+
break;
}
}
-
+
retval = TRUE;
-
+
/* out: */
_dbus_string_free (&line);
return retval;
@@ -748,7 +748,7 @@ process_test_data (const char *test_data_dir)
DBusError error = DBUS_ERROR_INIT;
retval = FALSE;
-
+
if (!_dbus_string_init (&tests_file))
_dbus_assert_not_reached ("no memory");
@@ -763,7 +763,7 @@ process_test_data (const char *test_data_dir)
if (!_dbus_string_init (&line))
_dbus_assert_not_reached ("no memory");
-
+
if (!_dbus_string_append (&tests_file, test_data_dir))
_dbus_assert_not_reached ("no memory");
@@ -778,7 +778,7 @@ process_test_data (const char *test_data_dir)
if (!_dbus_concat_dir_and_file (&results_file, &tmp))
_dbus_assert_not_reached ("no memory");
- if (!_dbus_file_get_contents (&tests, &tests_file, &error))
+ if (!_dbus_file_get_contents (&tests, &tests_file, NULL, &error))
{
fprintf (stderr, "could not load test data file %s: %s\n",
_dbus_string_get_const_data (&tests_file),
@@ -787,7 +787,7 @@ process_test_data (const char *test_data_dir)
goto out;
}
- if (!_dbus_file_get_contents (&results, &results_file, &error))
+ if (!_dbus_file_get_contents (&results, &results_file, NULL, &error))
{
fprintf (stderr, "could not load results data file %s: %s\n",
_dbus_string_get_const_data (&results_file), error.message);
@@ -819,7 +819,7 @@ process_test_data (const char *test_data_dir)
* we'd have to do a little bit more implementation
* to use those tests.
*/
-
+
printf (" (ending tests due to Type 3 tests seen - this is normal)\n");
break;
}
@@ -836,13 +836,13 @@ process_test_data (const char *test_data_dir)
dbus_bool_t success;
success = FALSE;
-
+
if (!_dbus_string_init (&next_line))
_dbus_assert_not_reached ("no memory");
if (!_dbus_string_init (&expected))
_dbus_assert_not_reached ("no memory");
-
+
if (!_dbus_string_init (&test))
_dbus_assert_not_reached ("no memory");
@@ -861,14 +861,14 @@ process_test_data (const char *test_data_dir)
_dbus_string_get_length (&line)))
_dbus_assert_not_reached ("no memory");
}
-
+
if (!decode_compact_string (&line, &test))
{
fprintf (stderr, "Failed to decode line %d as a compact string\n",
line_no);
goto failure;
}
-
+
if (!_dbus_sha_compute (&test, &result))
_dbus_assert_not_reached ("no memory for SHA-1 result");
@@ -877,9 +877,9 @@ process_test_data (const char *test_data_dir)
fprintf (stderr, "Failed to read an expected result\n");
goto failure;
}
-
+
if (!_dbus_string_equal (&result, &expected))
- {
+ {
fprintf (stderr, " for line %d got hash %s expected %s\n",
line_no,
_dbus_string_get_const_data (&result),
@@ -908,7 +908,7 @@ process_test_data (const char *test_data_dir)
printf ("Passed the %d SHA-1 tests in the test file\n",
success_count);
-
+
out:
_dbus_string_free (&tests_file);
_dbus_string_free (&results_file);
@@ -938,7 +938,7 @@ _dbus_sha_test (const char *test_data_dir)
}
else
printf ("No test data dir\n");
-
+
i = 0;
while (i < 256)
{
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index e60e6144..1b834beb 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -1,11 +1,11 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-sysdeps-unix.c Wrappers around UNIX system/libc features (internal to D-Bus implementation)
- *
+ *
* Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
* Copyright (C) 2003 CodeFactory AB
*
* 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
* the Free Software Foundation; either version 2 of the License, or
@@ -15,7 +15,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -161,7 +161,7 @@ _dbus_open_unix_socket (int *fd,
* @param error return location for an error
* @returns #FALSE if error is set
*/
-dbus_bool_t
+dbus_bool_t
_dbus_close_socket (int fd,
DBusError *error)
{
@@ -474,7 +474,7 @@ _dbus_pipe_write (DBusPipe *pipe,
DBusError *error)
{
int written;
-
+
written = _dbus_write (pipe->fd_or_handle, buffer, start, len);
if (written < 0)
{
@@ -510,7 +510,7 @@ _dbus_pipe_close (DBusPipe *pipe,
/**
* Like _dbus_write_two() but only works on sockets and is thus
* available on Windows.
- *
+ *
* @param fd the file descriptor
* @param buffer1 first buffer
* @param start1 first byte to write in first buffer
@@ -588,7 +588,7 @@ _dbus_write_socket_two (int fd,
*
* Unlike _dbus_read_socket(), _dbus_read() is not available
* on Windows.
- *
+ *
* @param fd the file descriptor to read from
* @param buffer the buffer to append data to
* @param count the amount of data to read
@@ -604,7 +604,7 @@ _dbus_read (int fd,
char *data;
_dbus_assert (count >= 0);
-
+
start = _dbus_string_get_length (buffer);
if (!_dbus_string_lengthen (buffer, count))
@@ -616,7 +616,7 @@ _dbus_read (int fd,
data = _dbus_string_get_data_len (buffer, start, count);
again:
-
+
bytes_read = read (fd, data, count);
if (bytes_read < 0)
@@ -639,7 +639,7 @@ _dbus_read (int fd,
if (bytes_read > 0)
_dbus_verbose_bytes_of_string (buffer, start, bytes_read);
#endif
-
+
return bytes_read;
}
}
@@ -647,7 +647,7 @@ _dbus_read (int fd,
/**
* Thin wrapper around the write() system call that writes a part of a
* DBusString and handles EINTR for you.
- *
+ *
* @param fd the file descriptor to write
* @param buffer the buffer to write data from
* @param start the first byte in the buffer to write
@@ -662,9 +662,9 @@ _dbus_write (int fd,
{
const char *data;
int bytes_written;
-
+
data = _dbus_string_get_const_data_len (buffer, start, len);
-
+
again:
bytes_written = write (fd, data, len);
@@ -676,7 +676,7 @@ _dbus_write (int fd,
if (bytes_written > 0)
_dbus_verbose_bytes_of_string (buffer, start, bytes_written);
#endif
-
+
return bytes_written;
}
@@ -714,7 +714,7 @@ _dbus_write_two (int fd,
_dbus_assert (start2 >= 0);
_dbus_assert (len1 >= 0);
_dbus_assert (len2 >= 0);
-
+
#ifdef HAVE_WRITEV
{
struct iovec vectors[2];
@@ -732,40 +732,40 @@ _dbus_write_two (int fd,
start2 = 0;
len2 = 0;
}
-
+
vectors[0].iov_base = (char*) data1;
vectors[0].iov_len = len1;
vectors[1].iov_base = (char*) data2;
vectors[1].iov_len = len2;
again:
-
+
bytes_written = writev (fd,
vectors,
data2 ? 2 : 1);
if (bytes_written < 0 && errno == EINTR)
goto again;
-
+
return bytes_written;
}
#else /* HAVE_WRITEV */
{
int ret1;
-
+
ret1 = _dbus_write (fd, buffer1, start1, len1);
if (ret1 == len1 && buffer2 != NULL)
{
ret2 = _dbus_write (fd, buffer2, start2, len2);
if (ret2 < 0)
ret2 = 0; /* we can't report an error as the first write was OK */
-
+
return ret1 + ret2;
}
else
return ret1;
}
-#endif /* !HAVE_WRITEV */
+#endif /* !HAVE_WRITEV */
}
#define _DBUS_MAX_SUN_PATH_LENGTH 99
@@ -787,7 +787,7 @@ _dbus_write_two (int fd,
* Creates a socket and connects it to the UNIX domain socket at the
* given path. The connection fd is returned, and is set up as
* nonblocking.
- *
+ *
* Uses abstract sockets instead of filesystem-linked sockets if
* requested (it's possible only on Linux; see "man 7 unix" on Linux).
* On non-Linux abstract socket usage always fails.
@@ -806,14 +806,14 @@ _dbus_connect_unix_socket (const char *path,
{
int fd;
size_t path_len;
- struct sockaddr_un addr;
+ struct sockaddr_un addr;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("connecting to unix socket %s abstract=%d\n",
path, abstract);
-
-
+
+
if (!_dbus_open_unix_socket (&fd, error))
{
_DBUS_ASSERT_ERROR_IS_SET(error);
@@ -838,7 +838,7 @@ _dbus_connect_unix_socket (const char *path,
_dbus_close (fd, NULL);
return -1;
}
-
+
strncpy (&addr.sun_path[1], path, path_len);
/* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
#else /* HAVE_ABSTRACT_SOCKETS */
@@ -860,9 +860,9 @@ _dbus_connect_unix_socket (const char *path,
strncpy (addr.sun_path, path, path_len);
}
-
+
if (connect (fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
- {
+ {
dbus_set_error (error,
_dbus_error_from_errno (errno),
"Failed to connect to socket %s: %s",
@@ -870,14 +870,14 @@ _dbus_connect_unix_socket (const char *path,
_dbus_close (fd, NULL);
fd = -1;
-
+
return -1;
}
if (!_dbus_set_fd_nonblocking (fd, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
-
+
_dbus_close (fd, NULL);
fd = -1;
@@ -902,10 +902,10 @@ _dbus_set_local_creds (int fd, dbus_bool_t on)
dbus_bool_t retval = TRUE;
#if defined(HAVE_CMSGCRED)
- /* NOOP just to make sure only one codepath is used
+ /* NOOP just to make sure only one codepath is used
* and to prefer CMSGCRED
*/
-#elif defined(LOCAL_CREDS)
+#elif defined(LOCAL_CREDS)
int val = on ? 1 : 0;
if (setsockopt (fd, 0, LOCAL_CREDS, &val, sizeof (val)) < 0)
{
@@ -950,7 +950,7 @@ _dbus_listen_unix_socket (const char *path,
_dbus_verbose ("listening on unix socket %s abstract=%d\n",
path, abstract);
-
+
if (!_dbus_open_unix_socket (&listen_fd, error))
{
_DBUS_ASSERT_ERROR_IS_SET(error);
@@ -961,7 +961,7 @@ _dbus_listen_unix_socket (const char *path,
_DBUS_ZERO (addr);
addr.sun_family = AF_UNIX;
path_len = strlen (path);
-
+
if (abstract)
{
#ifdef HAVE_ABSTRACT_SOCKETS
@@ -978,7 +978,7 @@ _dbus_listen_unix_socket (const char *path,
_dbus_close (listen_fd, NULL);
return -1;
}
-
+
strncpy (&addr.sun_path[1], path, path_len);
/* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
#else /* HAVE_ABSTRACT_SOCKETS */
@@ -1015,10 +1015,10 @@ _dbus_listen_unix_socket (const char *path,
_dbus_close (listen_fd, NULL);
return -1;
}
-
+
strncpy (addr.sun_path, path, path_len);
}
-
+
if (bind (listen_fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
@@ -1052,19 +1052,19 @@ _dbus_listen_unix_socket (const char *path,
_dbus_close (listen_fd, NULL);
return -1;
}
-
+
/* Try opening up the permissions, but if we can't, just go ahead
* and continue, maybe it will be good enough.
*/
if (!abstract && chmod (path, 0777) < 0)
_dbus_warn ("Could not set mode 0777 on socket %s\n",
path);
-
+
return listen_fd;
}
/**
- * Creates a socket and connects to a socket at the given host
+ * Creates a socket and connects to a socket at the given host
* and port. The connection fd is returned, and is set up as
* nonblocking.
*
@@ -1372,7 +1372,7 @@ write_credentials_byte (int server_fd,
{
int bytes_written;
char buf[1] = { '\0' };
-#if defined(HAVE_CMSGCRED)
+#if defined(HAVE_CMSGCRED)
union {
struct cmsghdr hdr;
char cred[CMSG_SPACE (sizeof (struct cmsgcred))];
@@ -1395,10 +1395,10 @@ write_credentials_byte (int server_fd,
#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
again:
-#if defined(HAVE_CMSGCRED)
+#if defined(HAVE_CMSGCRED)
bytes_written = sendmsg (server_fd, &msg, 0);
#else
bytes_written = write (server_fd, buf, 1);
@@ -1438,7 +1438,7 @@ write_credentials_byte (int server_fd,
* we got valid credentials. On some systems, such as Linux,
* reading/writing the byte isn't actually required, but we do it
* anyway just to avoid multiple codepaths.
- *
+ *
* Fails if no byte is available, so you must select() first.
*
* The point of the byte is that on some systems we have to
@@ -1460,8 +1460,8 @@ _dbus_read_credentials_socket (int client_fd,
dbus_uid_t uid_read;
dbus_pid_t pid_read;
int bytes_read;
-
-#ifdef HAVE_CMSGCRED
+
+#ifdef HAVE_CMSGCRED
union {
struct cmsghdr hdr;
char cred[CMSG_SPACE (sizeof (struct cmsgcred))];
@@ -1478,7 +1478,7 @@ _dbus_read_credentials_socket (int client_fd,
pid_read = DBUS_PID_UNSET;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
/* The POSIX spec certainly doesn't promise this, but
* we need these assertions to fail as soon as we're wrong about
* it so we can do the porting fixups
@@ -1520,7 +1520,7 @@ _dbus_read_credentials_socket (int client_fd,
* normally only call read_credentials if the socket was ready
* for reading
*/
-
+
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to read credentials byte: %s",
_dbus_strerror (errno));
@@ -1556,9 +1556,9 @@ _dbus_read_credentials_socket (int client_fd,
{
#ifdef SO_PEERCRED
- struct ucred cr;
+ struct ucred cr;
int cr_len = sizeof (cr);
-
+
if (getsockopt (client_fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) == 0 &&
cr_len == sizeof (cr))
{
@@ -1608,9 +1608,9 @@ _dbus_read_credentials_socket (int client_fd,
{
_dbus_verbose ("Failed to adt_start_session(): %s\n", _dbus_strerror (errno));
}
- else
+ else
{
- if (adt_set_from_ucred (adth, ucred, ADT_NEW))
+ if (adt_set_from_ucred (adth, ucred, ADT_NEW))
{
_dbus_verbose ("Failed to adt_set_from_ucred(): %s\n", _dbus_strerror (errno));
}
@@ -1666,7 +1666,7 @@ _dbus_read_credentials_socket (int client_fd,
return FALSE;
}
}
-
+
return TRUE;
}
@@ -1692,7 +1692,7 @@ _dbus_send_credentials_socket (int server_fd,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
if (write_credentials_byte (server_fd, error))
return TRUE;
else
@@ -1752,8 +1752,8 @@ _dbus_accept (int listen_fd)
}
/**
- * Checks to make sure the given directory is
- * private to the user
+ * Checks to make sure the given directory is
+ * private to the user
*
* @param dir the name of the directory
* @param error error return
@@ -1764,19 +1764,19 @@ _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
{
const char *directory;
struct stat sb;
-
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
directory = _dbus_string_get_const_data (dir);
-
+
if (stat (directory, &sb) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"%s", _dbus_strerror (errno));
-
+
return FALSE;
}
-
+
if ((S_IROTH & sb.st_mode) || (S_IWOTH & sb.st_mode) ||
(S_IRGRP & sb.st_mode) || (S_IWGRP & sb.st_mode))
{
@@ -1784,7 +1784,7 @@ _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
"%s directory is not private to the user", directory);
return FALSE;
}
-
+
return TRUE;
}
@@ -1795,12 +1795,12 @@ fill_user_info_from_passwd (struct passwd *p,
{
_dbus_assert (p->pw_name != NULL);
_dbus_assert (p->pw_dir != NULL);
-
+
info->uid = p->pw_uid;
info->primary_gid = p->pw_gid;
info->username = _dbus_strdup (p->pw_name);
info->homedir = _dbus_strdup (p->pw_dir);
-
+
if (info->username == NULL ||
info->homedir == NULL)
{
@@ -1818,7 +1818,7 @@ fill_user_info (DBusUserInfo *info,
DBusError *error)
{
const char *username_c;
-
+
/* exactly one of username/uid provided */
_dbus_assert (username != NULL || uid != DBUS_UID_UNSET);
_dbus_assert (username == NULL || uid == DBUS_UID_UNSET);
@@ -1829,7 +1829,7 @@ fill_user_info (DBusUserInfo *info,
info->n_group_ids = 0;
info->username = NULL;
info->homedir = NULL;
-
+
if (username != NULL)
username_c = _dbus_string_get_const_data (username);
else
@@ -1839,7 +1839,7 @@ fill_user_info (DBusUserInfo *info,
* are always symmetrical, if not we have to add more configure
* checks
*/
-
+
#if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
{
struct passwd *p;
@@ -1943,7 +1943,7 @@ fill_user_info (DBusUserInfo *info,
/* Fill this in so we can use it to get groups */
username_c = info->username;
-
+
#ifdef HAVE_GETGROUPLIST
{
gid_t *buf;
@@ -1959,7 +1959,7 @@ fill_user_info (DBusUserInfo *info,
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed;
}
-
+
if (getgrouplist (username_c,
info->primary_gid,
buf, &buf_count) < 0)
@@ -1976,10 +1976,10 @@ fill_user_info (DBusUserInfo *info,
for the "id" command, and it turns out that they use an
undocumented library function getgrouplist_2 (!) which is not
declared in any header in /usr/include (!!). That did not seem
- like the way to go here.
+ like the way to go here.
*/
- if (buf_count == initial_buf_count)
- {
+ if (buf_count == initial_buf_count)
+ {
buf_count *= 16; /* Retry with an arbitrarily scaled-up array */
}
new = dbus_realloc (buf, buf_count * sizeof (buf[0]));
@@ -1989,7 +1989,7 @@ fill_user_info (DBusUserInfo *info,
dbus_free (buf);
goto failed;
}
-
+
buf = new;
errno = 0;
@@ -1999,7 +1999,7 @@ fill_user_info (DBusUserInfo *info,
{
_dbus_warn ("It appears that username \"%s\" is in more than %d groups.\nProceeding with just the first %d groups.",
username_c, buf_count, buf_count);
- }
+ }
else
{
dbus_set_error (error,
@@ -2021,12 +2021,12 @@ fill_user_info (DBusUserInfo *info,
dbus_free (buf);
goto failed;
}
-
+
for (i = 0; i < buf_count; ++i)
info->group_ids[i] = buf[i];
info->n_group_ids = buf_count;
-
+
dbus_free (buf);
}
#else /* HAVE_GETGROUPLIST */
@@ -2046,9 +2046,9 @@ fill_user_info (DBusUserInfo *info,
#endif /* HAVE_GETGROUPLIST */
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
return TRUE;
-
+
failed:
_DBUS_ASSERT_ERROR_IS_SET (error);
return FALSE;
@@ -2121,7 +2121,7 @@ _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
* is required, that is done in dbus-auth.c. The username here
* need not be anything human-readable, it can be the machine-readable
* form i.e. a user id.
- *
+ *
* @param str the string to append to
* @returns #FALSE on no memory
*/
@@ -2163,7 +2163,7 @@ _dbus_geteuid (void)
/**
* The only reason this is separate from _dbus_getpid() is to allow it
* on Windows for logging but not for other purposes.
- *
+ *
* @returns process ID to put in log messages
*/
unsigned long
@@ -2185,7 +2185,7 @@ _dbus_parse_uid (const DBusString *uid_str,
{
int end;
long val;
-
+
if (_dbus_string_get_length (uid_str) == 0)
{
_dbus_verbose ("UID string was zero length\n");
@@ -2200,7 +2200,7 @@ _dbus_parse_uid (const DBusString *uid_str,
_dbus_verbose ("could not parse string as a UID\n");
return FALSE;
}
-
+
if (end != _dbus_string_get_length (uid_str))
{
_dbus_verbose ("string contained trailing stuff after UID\n");
@@ -2250,7 +2250,7 @@ _dbus_atomic_dec (DBusAtomic *atomic)
return __sync_sub_and_fetch(&atomic->value, 1)+1;
#else
dbus_int32_t res;
-
+
_DBUS_LOCK (atomic);
res = atomic->value;
atomic->value -= 1;
@@ -2303,7 +2303,7 @@ _dbus_poll (DBusPollFD *fds,
_DBUS_STRUCT_OFFSET (struct pollfd, revents))
{
return poll ((struct pollfd*) fds,
- n_fds,
+ n_fds,
timeout_milliseconds);
}
else
@@ -2321,7 +2321,7 @@ _dbus_poll (DBusPollFD *fds,
int i;
struct timeval tv;
int ready;
-
+
FD_ZERO (&read_set);
FD_ZERO (&write_set);
FD_ZERO (&err_set);
@@ -2340,7 +2340,7 @@ _dbus_poll (DBusPollFD *fds,
max_fd = MAX (max_fd, fdp->fd);
}
-
+
tv.tv_sec = timeout_milliseconds / 1000;
tv.tv_usec = (timeout_milliseconds % 1000) * 1000;
@@ -2397,12 +2397,14 @@ _dbus_get_current_time (long *tv_sec,
*
* @param str the string to append to
* @param filename filename to load
+ * @param mtime if not NULL the modification time will be stored here
* @param error place to set an error
* @returns #FALSE if error was set
*/
dbus_bool_t
_dbus_file_get_contents (DBusString *str,
const DBusString *filename,
+ unsigned long *mtime,
DBusError *error)
{
int fd;
@@ -2412,9 +2414,9 @@ _dbus_file_get_contents (DBusString *str,
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
filename_c = _dbus_string_get_const_data (filename);
-
+
/* O_BINARY useful on Cygwin */
fd = open (filename_c, O_RDONLY | O_BINARY);
if (fd < 0)
@@ -2427,7 +2429,7 @@ _dbus_file_get_contents (DBusString *str,
}
_dbus_verbose ("file fd %d opened\n", fd);
-
+
if (fstat (fd, &sb) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
@@ -2437,9 +2439,9 @@ _dbus_file_get_contents (DBusString *str,
_dbus_verbose ("fstat() failed: %s",
_dbus_strerror (errno));
-
+
_dbus_close (fd, NULL);
-
+
return FALSE;
}
@@ -2451,7 +2453,7 @@ _dbus_file_get_contents (DBusString *str,
_dbus_close (fd, NULL);
return FALSE;
}
-
+
total = 0;
orig_len = _dbus_string_get_length (str);
if (sb.st_size > 0 && S_ISREG (sb.st_mode))
@@ -2471,7 +2473,7 @@ _dbus_file_get_contents (DBusString *str,
_dbus_verbose ("read() failed: %s",
_dbus_strerror (errno));
-
+
_dbus_close (fd, NULL);
_dbus_string_set_length (str, orig_len);
return FALSE;
@@ -2479,9 +2481,6 @@ _dbus_file_get_contents (DBusString *str,
else
total += bytes_read;
}
-
- _dbus_close (fd, NULL);
- return TRUE;
}
else if (sb.st_size != 0)
{
@@ -2492,11 +2491,13 @@ _dbus_file_get_contents (DBusString *str,
_dbus_close (fd, NULL);
return FALSE;
}
- else
- {
- _dbus_close (fd, NULL);
- return TRUE;
- }
+
+
+ if (mtime)
+ *mtime = (unsigned long) sb.st_mtime;
+
+ _dbus_close (fd, NULL);
+ return TRUE;
}
/**
@@ -2523,11 +2524,11 @@ _dbus_string_save_to_file (const DBusString *str,
dbus_bool_t retval;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
fd = -1;
retval = FALSE;
need_unlink = FALSE;
-
+
if (!_dbus_string_init (&tmp_filename))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -2540,7 +2541,7 @@ _dbus_string_save_to_file (const DBusString *str,
_dbus_string_free (&tmp_filename);
return FALSE;
}
-
+
if (!_dbus_string_append (&tmp_filename, "."))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -2555,7 +2556,7 @@ _dbus_string_save_to_file (const DBusString *str,
_dbus_string_free (&tmp_filename);
return FALSE;
}
-
+
filename_c = _dbus_string_get_const_data (filename);
tmp_filename_c = _dbus_string_get_const_data (&tmp_filename);
@@ -2570,9 +2571,9 @@ _dbus_string_save_to_file (const DBusString *str,
}
_dbus_verbose ("tmp file fd %d opened\n", fd);
-
+
need_unlink = TRUE;
-
+
total = 0;
bytes_to_write = _dbus_string_get_length (str);
@@ -2588,7 +2589,7 @@ _dbus_string_save_to_file (const DBusString *str,
dbus_set_error (error, _dbus_error_from_errno (errno),
"Could not write to %s: %s", tmp_filename_c,
_dbus_strerror (errno));
-
+
goto out;
}
@@ -2614,7 +2615,7 @@ _dbus_string_save_to_file (const DBusString *str,
}
fd = -1;
-
+
if (rename (tmp_filename_c, filename_c) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
@@ -2626,9 +2627,9 @@ _dbus_string_save_to_file (const DBusString *str,
}
need_unlink = FALSE;
-
+
retval = TRUE;
-
+
out:
/* close first, then unlink, to prevent ".nfs34234235" garbage
* files
@@ -2636,7 +2637,7 @@ _dbus_string_save_to_file (const DBusString *str,
if (fd >= 0)
_dbus_close (fd, NULL);
-
+
if (need_unlink && unlink (tmp_filename_c) < 0)
_dbus_verbose ("Failed to unlink temp file %s: %s\n",
tmp_filename_c, _dbus_strerror (errno));
@@ -2645,7 +2646,7 @@ _dbus_string_save_to_file (const DBusString *str,
if (!retval)
_DBUS_ASSERT_ERROR_IS_SET (error);
-
+
return retval;
}
@@ -2690,9 +2691,9 @@ _dbus_create_file_exclusively (const DBusString *filename,
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
filename_c = _dbus_string_get_const_data (filename);
-
+
fd = open (filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
0600);
if (fd < 0)
@@ -2706,7 +2707,7 @@ _dbus_create_file_exclusively (const DBusString *filename,
}
_dbus_verbose ("exclusive file fd %d opened\n", fd);
-
+
if (!_dbus_close (fd, NULL))
{
dbus_set_error (error,
@@ -2716,7 +2717,7 @@ _dbus_create_file_exclusively (const DBusString *filename,
_dbus_strerror (errno));
return FALSE;
}
-
+
return TRUE;
}
@@ -2725,7 +2726,7 @@ _dbus_create_file_exclusively (const DBusString *filename,
*
* @param filename the filename
* @param error error location
- *
+ *
* @returns #TRUE if unlink() succeeded
*/
dbus_bool_t
@@ -2735,7 +2736,7 @@ _dbus_delete_file (const DBusString *filename,
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
filename_c = _dbus_string_get_const_data (filename);
if (unlink (filename_c) < 0)
@@ -2764,14 +2765,14 @@ _dbus_create_directory (const DBusString *filename,
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
filename_c = _dbus_string_get_const_data (filename);
if (mkdir (filename_c, 0700) < 0)
{
if (errno == EEXIST)
return TRUE;
-
+
dbus_set_error (error, DBUS_ERROR_FAILED,
"Failed to create directory %s: %s\n",
filename_c, _dbus_strerror (errno));
@@ -2801,7 +2802,7 @@ _dbus_concat_dir_and_file (DBusString *dir,
if (_dbus_string_get_length (dir) == 0 ||
_dbus_string_get_length (next_component) == 0)
return TRUE;
-
+
dir_ends_in_slash = '/' == _dbus_string_get_byte (dir,
_dbus_string_get_length (dir) - 1);
@@ -2863,7 +2864,7 @@ _dbus_generate_pseudorandom_bytes (DBusString *str,
{
int old_len;
char *p;
-
+
old_len = _dbus_string_get_length (str);
if (!_dbus_string_lengthen (str, n_bytes))
@@ -2896,7 +2897,7 @@ _dbus_generate_random_bytes (DBusString *str,
* a DBusError. So we always fall back to pseudorandom
* if the I/O fails.
*/
-
+
old_len = _dbus_string_get_length (str);
fd = -1;
@@ -2906,7 +2907,7 @@ _dbus_generate_random_bytes (DBusString *str,
return _dbus_generate_pseudorandom_bytes (str, n_bytes);
_dbus_verbose ("/dev/urandom fd %d opened\n", fd);
-
+
if (_dbus_read (fd, str, n_bytes) != n_bytes)
{
_dbus_close (fd, NULL);
@@ -2916,9 +2917,9 @@ _dbus_generate_random_bytes (DBusString *str,
_dbus_verbose ("Read %d bytes from /dev/urandom\n",
n_bytes);
-
+
_dbus_close (fd, NULL);
-
+
return TRUE;
}
@@ -2945,7 +2946,7 @@ const char*
_dbus_strerror (int error_number)
{
const char *msg;
-
+
msg = strerror (error_number);
if (msg == NULL)
msg = "unknown";
@@ -2973,14 +2974,14 @@ void
_dbus_fd_set_close_on_exec (int fd)
{
int val;
-
+
val = fcntl (fd, F_GETFD, 0);
-
+
if (val < 0)
return;
val |= FD_CLOEXEC;
-
+
fcntl (fd, F_SETFD, val);
}
@@ -2996,7 +2997,7 @@ _dbus_close (int fd,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
again:
if (close (fd) < 0)
{
@@ -3067,7 +3068,7 @@ _dbus_set_fd_nonblocking (int fd,
int val;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
val = fcntl (fd, F_GETFL, 0);
if (val < 0)
{
@@ -3100,17 +3101,17 @@ _dbus_set_fd_nonblocking (int fd,
*/
void
_dbus_print_backtrace (void)
-{
+{
#if defined (HAVE_BACKTRACE) && defined (DBUS_BUILT_R_DYNAMIC)
void *bt[500];
int bt_size;
int i;
char **syms;
-
+
bt_size = backtrace (bt, 500);
syms = backtrace_symbols (bt, bt_size);
-
+
i = 0;
while (i < bt_size)
{
@@ -3138,7 +3139,7 @@ _dbus_print_backtrace (void)
* principle it could be in dbus-sysdeps-util.c, except that
* dbus-sysdeps-util.c isn't in libdbus when tests are enabled and the
* debug-pipe server is used.
- *
+ *
* @param fd1 return location for one end
* @param fd2 return location for the other end
* @param blocking #TRUE if pipe should be blocking
@@ -3190,20 +3191,20 @@ _dbus_full_duplex_pipe (int *fd1,
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Could not set full-duplex pipe nonblocking");
-
+
_dbus_close (fds[0], NULL);
_dbus_close (fds[1], NULL);
-
+
return FALSE;
}
-
+
*fd1 = fds[0];
*fd2 = fds[1];
_dbus_verbose ("full-duplex pipe %d <-> %d\n",
*fd1, *fd2);
-
- return TRUE;
+
+ return TRUE;
#else
_dbus_warn ("_dbus_full_duplex_pipe() not implemented on this OS\n");
dbus_set_error (error, DBUS_ERROR_FAILED,
@@ -3229,7 +3230,7 @@ _dbus_printf_string_upper_bound (const char *format,
}
/**
- * Gets the temporary files directory by inspecting the environment variables
+ * Gets the temporary files directory by inspecting the environment variables
* TMPDIR, TMP, and TEMP in that order. If none of those are set "/tmp" is returned
*
* @returns location of temp directory
@@ -3260,9 +3261,9 @@ _dbus_get_tmpdir(void)
if (tmpdir == NULL)
tmpdir = "/tmp";
}
-
+
_dbus_assert(tmpdir != NULL);
-
+
return tmpdir;
}
@@ -3302,7 +3303,7 @@ _read_subprocess_line_argv (const char *progpath,
dbus_bool_t retval;
sigset_t new_set, old_set;
-
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
retval = FALSE;
@@ -3313,9 +3314,9 @@ _read_subprocess_line_argv (const char *progpath,
sigemptyset (&new_set);
sigaddset (&new_set, SIGCHLD);
sigprocmask (SIG_BLOCK, &new_set, &old_set);
-
+
orig_len = _dbus_string_get_length (result);
-
+
#define READ_END 0
#define WRITE_END 1
if (pipe (result_pipe) < 0)
@@ -3360,7 +3361,7 @@ _read_subprocess_line_argv (const char *progpath,
_exit (1);
_dbus_verbose ("/dev/null fd %d opened\n", fd);
-
+
/* set-up stdXXX */
close (result_pipe[READ_END]);
close (errors_pipe[READ_END]);
@@ -3415,7 +3416,7 @@ _read_subprocess_line_argv (const char *progpath,
errors_pipe[WRITE_END] = -1;
ret = 0;
- do
+ do
{
ret = _dbus_read (result_pipe[READ_END], result, 1024);
}
@@ -3455,7 +3456,7 @@ _read_subprocess_line_argv (const char *progpath,
}
retval = TRUE;
-
+
out:
sigprocmask (SIG_SETMASK, &old_set, NULL);
@@ -3473,7 +3474,7 @@ _read_subprocess_line_argv (const char *progpath,
if (errors_pipe[1] != -1)
close (errors_pipe[1]);
- return retval;
+ return retval;
}
/**
@@ -3495,7 +3496,7 @@ _dbus_get_autolaunch_address (DBusString *address,
int i;
DBusString uuid;
dbus_bool_t retval;
-
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
retval = FALSE;
@@ -3504,13 +3505,13 @@ _dbus_get_autolaunch_address (DBusString *address,
_DBUS_SET_OOM (error);
return FALSE;
}
-
+
if (!_dbus_get_local_machine_uuid_encoded (&uuid))
{
_DBUS_SET_OOM (error);
goto out;
}
-
+
i = 0;
argv[i] = "dbus-launch";
++i;
@@ -3569,14 +3570,14 @@ _dbus_read_local_machine_uuid (DBusGUID *machine_id,
/**
* Determines the address of the session bus by querying a
- * platform-specific method.
+ * platform-specific method.
*
* The first parameter will be a boolean specifying whether
* or not a dynamic session lookup is supported on this platform.
- *
+ *
* If supported is TRUE and the return value is #TRUE, the
* address will be appended to @p address.
- * If a failure happens, returns #FALSE and sets an error in
+ * If a failure happens, returns #FALSE and sets an error in
* @p error.
*
* If supported is FALSE, ignore the return value.
@@ -3593,15 +3594,15 @@ _dbus_lookup_session_address (dbus_bool_t *supported,
{
/* On non-Mac Unix platforms, if the session address isn't already
* set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and
- * fall back to the autolaunch: global default; see
+ * fall back to the autolaunch: global default; see
* init_session_address in dbus/dbus-bus.c. */
*supported = FALSE;
return TRUE;
}
/**
- * Returns the standard directories for a session bus to look for service
- * activation files
+ * Returns the standard directories for a session bus to look for service
+ * activation files
*
* On UNIX this should be the standard xdg freedesktop.org data directories:
*
@@ -3613,10 +3614,10 @@ _dbus_lookup_session_address (dbus_bool_t *supported,
* DBUS_DATADIR
*
* @param dirs the directory list we are returning
- * @returns #FALSE on OOM
+ * @returns #FALSE on OOM
*/
-dbus_bool_t
+dbus_bool_t
_dbus_get_standard_session_servicedirs (DBusList **dirs)
{
const char *xdg_data_home;
@@ -3643,11 +3644,11 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs)
goto oom;
}
- /*
+ /*
* add configured datadir to defaults
* this may be the same as an xdg dir
- * however the config parser should take
- * care of duplicates
+ * however the config parser should take
+ * care of duplicates
*/
if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR":"))
goto oom;
@@ -3664,7 +3665,7 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs)
if (!_dbus_homedir_from_current_process (&homedir))
goto oom;
-
+
if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
goto oom;
@@ -3673,12 +3674,12 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs)
goto oom;
}
- if (!_dbus_split_paths_and_append (&servicedir_path,
- DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
+ if (!_dbus_split_paths_and_append (&servicedir_path,
+ DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
dirs))
goto oom;
- _dbus_string_free (&servicedir_path);
+ _dbus_string_free (&servicedir_path);
return TRUE;
oom:
@@ -3688,8 +3689,8 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs)
/**
- * Returns the standard directories for a system bus to look for service
- * activation files
+ * Returns the standard directories for a system bus to look for service
+ * activation files
*
* On UNIX this should be the standard xdg freedesktop.org data directories:
*
@@ -3702,10 +3703,10 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs)
* On Windows there is no system bus and this function can return nothing.
*
* @param dirs the directory list we are returning
- * @returns #FALSE on OOM
+ * @returns #FALSE on OOM
*/
-dbus_bool_t
+dbus_bool_t
_dbus_get_standard_system_servicedirs (DBusList **dirs)
{
const char *xdg_data_dirs;
@@ -3730,21 +3731,21 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs)
goto oom;
}
- /*
+ /*
* add configured datadir to defaults
* this may be the same as an xdg dir
- * however the config parser should take
- * care of duplicates
+ * however the config parser should take
+ * care of duplicates
*/
if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR":"))
goto oom;
- if (!_dbus_split_paths_and_append (&servicedir_path,
- DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
+ if (!_dbus_split_paths_and_append (&servicedir_path,
+ DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
dirs))
goto oom;
- _dbus_string_free (&servicedir_path);
+ _dbus_string_free (&servicedir_path);
return TRUE;
oom:
@@ -3756,7 +3757,7 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs)
* Append the absolute path of the system.conf file
* (there is no system bus on Windows so this can just
* return FALSE and print a warning or something)
- *
+ *
* @param str the string to append to
* @returns #FALSE if no memory
*/
@@ -3768,7 +3769,7 @@ _dbus_append_system_config_file (DBusString *str)
/**
* Append the absolute path of the session.conf file.
- *
+ *
* @param str the string to append to
* @returns #FALSE if no memory
*/
@@ -3783,7 +3784,7 @@ _dbus_append_session_config_file (DBusString *str)
* caches should be nuked. Of course any caches that need explicit reload
* are probably broken, but c'est la vie.
*
- *
+ *
*/
void
_dbus_flush_caches (void)
@@ -3798,10 +3799,10 @@ _dbus_flush_caches (void)
*
* On UNIX the directory is ~/.dbus-keyrings while on Windows it should probably
* be something else, since the dotfile convention is not normal on Windows.
- *
+ *
* @param directory string to append directory to
* @param credentials credentials the directory should be for
- *
+ *
* @returns #FALSE on no memory
*/
dbus_bool_t
@@ -3811,10 +3812,10 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
DBusString homedir;
DBusString dotdir;
dbus_uid_t uid;
-
+
_dbus_assert (credentials != NULL);
_dbus_assert (!_dbus_credentials_are_anonymous (credentials));
-
+
if (!_dbus_string_init (&homedir))
return FALSE;
@@ -3823,11 +3824,11 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
if (!_dbus_homedir_from_uid (uid, &homedir))
goto failed;
-
+
#ifdef DBUS_BUILD_TESTS
{
const char *override;
-
+
override = _dbus_getenv ("DBUS_TEST_HOMEDIR");
if (override != NULL && *override != '\0')
{
@@ -3854,7 +3855,7 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
if (!_dbus_concat_dir_and_file (&homedir,
&dotdir))
goto failed;
-
+
if (!_dbus_string_copy (&homedir, 0,
directory, _dbus_string_get_length (directory))) {
goto failed;
@@ -3862,8 +3863,8 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
_dbus_string_free (&homedir);
return TRUE;
-
- failed:
+
+ failed:
_dbus_string_free (&homedir);
return FALSE;
}
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 739a4546..76a9a81e 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -1,11 +1,11 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-sysdeps.h Wrappers around system/libc features (internal to D-Bus implementation)
- *
+ *
* Copyright (C) 2002, 2003 Red Hat, Inc.
* Copyright (C) 2003 CodeFactory AB
*
* 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
* the Free Software Foundation; either version 2 of the License, or
@@ -15,7 +15,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -35,11 +35,11 @@
#include <string.h>
#include <stdarg.h>
-
+
/* AIX sys/poll.h does #define events reqevents, and other
* wonderousness, so must include sys/poll before declaring
* DBusPollFD
- */
+ */
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
@@ -130,9 +130,9 @@ typedef unsigned long dbus_gid_t;
*
* @todo Use for the file descriptors a struct
* - struct DBusSocket{ int d; }; -
- * instead of int to get type-safety which
+ * instead of int to get type-safety which
* will be checked by the compiler.
- *
+ *
*/
dbus_bool_t _dbus_open_tcp_socket (int *fd,
@@ -291,7 +291,7 @@ dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
#endif
/**
- * A portable struct pollfd wrapper.
+ * A portable struct pollfd wrapper.
*/
typedef struct
{
@@ -315,6 +315,7 @@ void _dbus_get_current_time (long *tv_sec,
dbus_bool_t _dbus_file_exists (const char *file);
dbus_bool_t _dbus_file_get_contents (DBusString *str,
const DBusString *filename,
+ unsigned long *mtime,
DBusError *error);
dbus_bool_t _dbus_string_save_to_file (const DBusString *str,
const DBusString *filename,
@@ -381,7 +382,7 @@ void _dbus_fd_set_close_on_exec (int fd);
const char* _dbus_get_tmpdir (void);
/**
- * Random numbers
+ * Random numbers
*/
void _dbus_generate_pseudorandom_bytes_buffer (char *buffer,
int n_bytes);
@@ -468,8 +469,8 @@ void _dbus_init_system_log (void);
void _dbus_log_info (const char *msg, va_list args);
void _dbus_log_security (const char *msg, va_list args);
-/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
- * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
+/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
+ * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
*/
#if !defined (DBUS_VA_COPY)
# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
@@ -503,7 +504,7 @@ void _dbus_log_security (const char *msg, va_list args);
_DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \
_DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7))
-dbus_bool_t _dbus_get_autolaunch_address (DBusString *address,
+dbus_bool_t _dbus_get_autolaunch_address (DBusString *address,
DBusError *error);
dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported,
@@ -526,8 +527,8 @@ dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id,
*/
dbus_bool_t _dbus_threads_init_platform_specific (void);
-dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs,
- const char *suffix,
+dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs,
+ const char *suffix,
DBusList **dir_list);
unsigned long _dbus_pid_for_log (void);