28#include "dbus-nonce.h"
29#include "dbus-internals.h"
30#include "dbus-protocol.h"
31#include "dbus-sysdeps.h"
50 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
81 saved_errno = _dbus_save_socket_errno ();
139 buffer[
sizeof buffer - 1] =
'\0';
141 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
151 "Failed to open %s for read: %s",
157 nread = fread (buffer, 1,
sizeof buffer - 1, fp);
189 if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce,
NULL) !=
TRUE)
194 if (!_dbus_socket_is_valid (fd))
197 if (do_check_nonce(fd, &nonce,
NULL) !=
TRUE) {
198 _dbus_verbose (
"nonce check failed. Closing socket.\n");
214 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
249 dbus_bool_t read_result;
253 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
264 read_result = _dbus_read_nonce (noncefile, &nonce, error);
267 _DBUS_ASSERT_ERROR_IS_SET (error);
271 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
277 if (send_result == -1)
281 "Failed to send nonce (fd=%" DBUS_SOCKET_FORMAT
"): %s",
282 _dbus_socket_printable (fd),
293 dbus_bool_t use_subdir)
299 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
305 if (noncefile ==
NULL)
354 _DBUS_ASSERT_ERROR_IS_SET (error);
357 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
373 if (!generate_and_write_nonce (&noncefile->path, error))
375 _DBUS_ASSERT_ERROR_IS_SET (error);
380 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
382 *noncefile_out = noncefile;
408 return do_noncefile_create (noncefile_out, error,
FALSE);
427 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
430 noncefile = *noncefile_location;
431 *noncefile_location =
NULL;
433 if (noncefile ==
NULL)
459 return do_noncefile_create (noncefile_out, error,
TRUE);
478 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
481 noncefile = *noncefile_location;
482 *noncefile_location =
NULL;
484 if (noncefile ==
NULL)
509 return &noncefile->path;
527 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_IN...
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
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.
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
dbus_bool_t _dbus_close_socket(DBusSocket *fd, DBusError *error)
Closes a socket and invalidates it.
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.
Object representing an exception.