26#include "dbus-nonce.h"
27#include "dbus-internals.h"
28#include "dbus-protocol.h"
29#include "dbus-sysdeps.h"
48 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
79 saved_errno = _dbus_save_socket_errno ();
137 buffer[
sizeof buffer - 1] =
'\0';
139 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
141 _dbus_verbose (
"reading nonce from file: %s\n", _dbus_string_get_const_data (fname));
144 fp = fopen (_dbus_string_get_const_data (fname),
"rb");
149 "Failed to open %s for read: %s",
150 _dbus_string_get_const_data (fname),
155 nread = fread (buffer, 1,
sizeof buffer - 1, fp);
187 if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce,
NULL) !=
TRUE)
192 if (!_dbus_socket_is_valid (fd))
195 if (do_check_nonce(fd, &nonce,
NULL) !=
TRUE) {
196 _dbus_verbose (
"nonce check failed. Closing socket.\n");
198 _dbus_socket_invalidate (&fd);
213 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
252 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
254 if (_dbus_string_get_length (noncefile) == 0)
263 read_result = _dbus_read_nonce (noncefile, &nonce, error);
266 _DBUS_ASSERT_ERROR_IS_SET (error);
270 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
276 if (send_result == -1)
280 "Failed to send nonce (fd=%" DBUS_SOCKET_FORMAT
"): %s",
281 _dbus_socket_printable (fd),
298 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
304 if (noncefile ==
NULL)
353 _DBUS_ASSERT_ERROR_IS_SET (error);
356 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
372 if (!generate_and_write_nonce (&noncefile->path, error))
374 _DBUS_ASSERT_ERROR_IS_SET (error);
379 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
381 *noncefile_out = noncefile;
386 if (use_subdir && _dbus_string_get_length (&noncefile->dir) != 0)
407 return do_noncefile_create (noncefile_out, error,
FALSE);
426 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
429 noncefile = *noncefile_location;
430 *noncefile_location =
NULL;
432 if (noncefile ==
NULL)
458 return do_noncefile_create (noncefile_out, error,
TRUE);
477 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
480 noncefile = *noncefile_location;
481 *noncefile_location =
NULL;
483 if (noncefile ==
NULL)
508 return &noncefile->path;
526 return do_check_nonce (fd, _dbus_noncefile_get_path (noncefile), error);
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
dbus_bool_t _dbus_string_save_to_file(const DBusString *str, const DBusString *filename, dbus_bool_t world_readable, DBusError *error)
Writes a string out to a file.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_generate_random_ascii(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
dbus_bool_t _dbus_get_is_errno_eintr(int e)
See if errno is EINTR.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
#define DBUS_ERROR_IO_ERROR
Something went wrong reading or writing to a socket, for example.
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don't allow doing what you're trying to do.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
dbus_bool_t _dbus_string_append_len(DBusString *str, const char *buffer, int len)
Appends block of bytes with the given length to a DBusString.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
dbus_bool_t _dbus_string_equal_len(const DBusString *a, const DBusString *b, int len)
Tests two DBusString for equality up to the given length.
dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock(int e)
See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted)
int _dbus_read_socket(DBusSocket fd, DBusString *buffer, int count)
Like _dbus_read(), but only works on sockets so is available on Windows.
int _dbus_write_socket(DBusSocket fd, const DBusString *buffer, int start, int len)
Like _dbus_write(), but only supports sockets and is thus available on Windows.
dbus_bool_t _dbus_close_socket(DBusSocket fd, DBusError *error)
Closes a socket.
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
dbus_bool_t _dbus_generate_random_bytes(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of securely random bytes, using the best mechanism we can come up with.
dbus_bool_t _dbus_delete_directory(const DBusString *filename, DBusError *error)
Removes a directory; Directory must be empty.
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket.
const char * _dbus_get_tmpdir(void)
Gets the temporary files directory by inspecting the environment variables TMPDIR,...
dbus_bool_t _dbus_create_directory(const DBusString *filename, DBusError *error)
Creates a directory.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Object representing an exception.