26 #include "dbus-nonce.h"
27 #include "dbus-internals.h"
28 #include "dbus-protocol.h"
29 #include "dbus-sysdeps.h"
42 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
59 saved_errno = _dbus_save_socket_errno ();
117 buffer[
sizeof buffer - 1] =
'\0';
119 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
121 _dbus_verbose (
"reading nonce from file: %s\n", _dbus_string_get_const_data (fname));
124 fp = fopen (_dbus_string_get_const_data (fname),
"rb");
129 "Failed to open %s for read: %s",
130 _dbus_string_get_const_data (fname),
135 nread = fread (buffer, 1,
sizeof buffer - 1, fp);
159 return _dbus_socket_get_invalid ();
161 if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce,
NULL) !=
TRUE)
162 return _dbus_socket_get_invalid ();
164 if (!_dbus_socket_is_valid (fd))
166 if (do_check_nonce(fd, &nonce,
NULL) !=
TRUE) {
167 _dbus_verbose (
"nonce check failed. Closing socket.\n");
169 return _dbus_socket_get_invalid ();
181 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
220 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
222 if (_dbus_string_get_length (noncefile) == 0)
231 read_result = _dbus_read_nonce (noncefile, &nonce, error);
234 _DBUS_ASSERT_ERROR_IS_SET (error);
238 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
244 if (send_result == -1)
248 "Failed to send nonce (fd=%d): %s",
264 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
305 _DBUS_ASSERT_ERROR_IS_SET (error);
308 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
324 if (!generate_and_write_nonce (&noncefile->path, error))
326 _DBUS_ASSERT_ERROR_IS_SET (error);
331 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
357 return do_noncefile_create (noncefile, error,
FALSE);
371 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
392 return do_noncefile_create (noncefile, error,
TRUE);
406 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
426 return &noncefile->path;
444 return do_check_nonce (fd, _dbus_noncefile_get_path (noncefile), error);
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
#define NULL
A null pointer, defined appropriately for C or C++.
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.
int _dbus_read_socket(DBusSocket fd, DBusString *buffer, int count)
Like _dbus_read(), but only works on sockets so is available on Windows.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
#define DBUS_ERROR_IO_ERROR
Something went wrong reading or writing to a socket, for example.
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_close_socket(DBusSocket fd, DBusError *error)
Closes a socket.
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
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) ...
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and 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...
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket.
dbus_bool_t _dbus_create_directory(const DBusString *filename, DBusError *error)
Creates a directory.
dbus_bool_t _dbus_delete_directory(const DBusString *filename, DBusError *error)
Removes a directory; Directory must be empty.
dbus_bool_t _dbus_get_is_errno_eintr(int e)
See if errno is EINTR.
Object representing an exception.
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_string_equal_len(const DBusString *a, const DBusString *b, int len)
Tests two DBusString for equality up to the given length.
const char * _dbus_get_tmpdir(void)
Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don't allow doing what you're trying to do.
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.
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...
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
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.