#include <stdio.h>
-#ifdef HAVE_ERRNO_H
-# include <errno.h>
-#endif
-
static dbus_bool_t
do_check_nonce (int fd, const DBusString *nonce, DBusError *error)
{
DBusString nonce;
_dbus_assert (noncefile != NULL);
- _dbus_string_init (&nonce);
+ if (!_dbus_string_init (&nonce))
+ return -1;
//PENDING(kdab): set better errors
if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
return -1;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- _dbus_string_init (&nonce);
+ if (!_dbus_string_init (&nonce))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return FALSE;
+ }
if (!_dbus_generate_random_bytes (&nonce, 16))
{
return FALSE;
}
- ret = _dbus_string_save_to_file (&nonce, filename, error);
+ ret = _dbus_string_save_to_file (&nonce, filename, FALSE, error);
_dbus_string_free (&nonce);
* indicate whether the server accepted the nonce.
*/
dbus_bool_t
-_dbus_send_nonce(int fd, const DBusString *noncefile, DBusError *error)
+_dbus_send_nonce (int fd, const DBusString *noncefile, DBusError *error)
{
dbus_bool_t read_result;
int send_result;
- size_t sendLen;
DBusString nonce;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (_dbus_string_get_length (noncefile) == 0)
return FALSE;
- if ( !_dbus_string_init (&nonce) )
+ if (!_dbus_string_init (&nonce))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return FALSE;
- }
-
- read_result = _dbus_read_nonce (noncefile, &nonce, NULL);
+ }
+ read_result = _dbus_read_nonce (noncefile, &nonce, error);
if (!read_result)
{
- dbus_set_error (error,
- _dbus_error_from_errno (errno),
- "Could not read nonce from file %s (%s)",
- _dbus_string_get_const_data (noncefile), _dbus_strerror(errno));
+ _DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_string_free (&nonce);
return FALSE;
}
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
send_result = _dbus_write_socket (fd, &nonce, 0, _dbus_string_get_length (&nonce));
_dbus_string_free (&nonce);
if (send_result == -1)
- {
- dbus_set_error (error,
- _dbus_error_from_errno (errno),
- "Failed to send nonce (fd=%d): %s",
- fd, _dbus_strerror(errno));
- return FALSE;
- }
+ {
+ dbus_set_error (error,
+ _dbus_error_from_system_errno (),
+ "Failed to send nonce (fd=%d): %s",
+ fd, _dbus_strerror_from_errno ());
+ return FALSE;
+ }
return TRUE;
}
DBusError *error,
dbus_bool_t use_subdir)
{
- dbus_bool_t ret;
DBusString randomStr;
+ const char *tmp;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
goto on_error;
}
+ tmp = _dbus_get_tmpdir ();
+
if (!_dbus_string_init (&noncefile->dir)
- || !_dbus_string_append (&noncefile->dir, _dbus_get_tmpdir()))
+ || tmp == NULL
+ || !_dbus_string_append (&noncefile->dir, tmp))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto on_error;
}
if (!_dbus_string_init (&noncefile->path)
|| !_dbus_string_copy (&noncefile->dir, 0, &noncefile->path, 0)
- || !_dbus_string_append (&noncefile->dir, "/nonce"))
+ || !_dbus_string_append (&noncefile->path, "/nonce"))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto on_error;
}
if (!_dbus_create_directory (&noncefile->dir, error))
{
+ _DBUS_ASSERT_ERROR_IS_SET (error);
goto on_error;
}
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
}
else
if (!generate_and_write_nonce (&noncefile->path, error))
{
+ _DBUS_ASSERT_ERROR_IS_SET (error);
if (use_subdir)
_dbus_delete_directory (&noncefile->dir, NULL); //we ignore possible errors deleting the dir and return the write error instead
goto on_error;
}
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_string_free (&randomStr);