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);
107 buffer[
sizeof buffer - 1] =
'\0';
109 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
111 _dbus_verbose (
"reading nonce from file: %s\n", _dbus_string_get_const_data (fname));
114 fp = fopen (_dbus_string_get_const_data (fname),
"rb");
119 "Failed to open %s for read: %s",
120 _dbus_string_get_const_data (fname),
125 nread = fread (buffer, 1,
sizeof buffer - 1, fp);
142 _dbus_accept_with_noncefile (
int listen_fd,
const DBusNonceFile *noncefile)
151 if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce,
NULL) !=
TRUE)
154 if (_dbus_socket_is_invalid (fd))
156 if (do_check_nonce(fd, &nonce,
NULL) !=
TRUE) {
157 _dbus_verbose (
"nonce check failed. Closing socket.\n");
171 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
209 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
211 if (_dbus_string_get_length (noncefile) == 0)
220 read_result = _dbus_read_nonce (noncefile, &nonce, error);
223 _DBUS_ASSERT_ERROR_IS_SET (error);
227 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
233 if (send_result == -1)
237 "Failed to send nonce (fd=%d): %s",
253 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
295 _DBUS_ASSERT_ERROR_IS_SET (error);
298 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
314 if (!generate_and_write_nonce (&noncefile->path, error))
316 _DBUS_ASSERT_ERROR_IS_SET (error);
321 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
347 return do_noncefile_create (noncefile, error,
FALSE);
361 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
382 return do_noncefile_create (noncefile, error,
TRUE);
396 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
416 return &noncefile->path;
430 _dbus_noncefile_check_nonce (
int fd,
434 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_delete_directory(const DBusString *filename, DBusError *error)
Removes a directory; Directory must be empty.
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_accept(int listen_fd)
Accepts a connection on a listening socket.
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_generate_random_ascii(DBusString *str, int n_bytes)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
int _dbus_read_socket(int fd, DBusString *buffer, int count)
Like _dbus_read(), but only works on sockets so is available on Windows.
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.
dbus_bool_t _dbus_create_directory(const DBusString *filename, DBusError *error)
Creates a directory; succeeds if the directory is created or already existed.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
const char * _dbus_get_tmpdir(void)
Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.
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.
int _dbus_write_socket(int 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_get_is_errno_eintr(void)
See if errno is EINTR.
#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_get_is_errno_eagain_or_ewouldblock(void)
See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted) ...
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
dbus_bool_t _dbus_close_socket(int fd, DBusError *error)
Closes a socket.
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
dbus_bool_t _dbus_generate_random_bytes(DBusString *str, int n_bytes)
Generates the given number of random bytes, using the best mechanism we can come up with...