Commit 0617102b authored by Frank Osterfeld's avatar Frank Osterfeld Committed by Ralf Habacker
Browse files

Fixes to the nonce code

Cherry-picked from commit f9bc0f4bd036f6ede5d9850fb0f8587178c85f44 in
the dbus4win repository, slightly massaged to apply by tml@iki.fi.
parent 9d27253f
......@@ -186,20 +186,20 @@ if (WIN32)
set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES}
${DBUS_DIR}/dbus-sysdeps-win.c
${DBUS_DIR}/dbus-sysdeps-thread-win.c
${DBUS_DIR}/dbus-sysdeps-util-win.c
${DBUS_DIR}/dbus-spawn-win.c
)
set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS}
${DBUS_DIR}/dbus-sockets-win.h
${DBUS_DIR}/dbus-sysdeps-win.h
)
set (DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES}
${DBUS_DIR}/dbus-sysdeps-util-win.c
)
set (LIBS ${LIBS} ws2_32 advapi32 netapi32)
else (WIN32)
set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES}
${DBUS_DIR}/dbus-sysdeps-unix.c
${DBUS_DIR}/dbus-sysdeps-pthread.c
${DBUS_DIR}/dbus-sysdeps-util-unix.c
${DBUS_DIR}/dbus-spawn.c
${DBUS_DIR}/dbus-userdb.c
)
......@@ -211,6 +211,7 @@ else (WIN32)
)
set (DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES}
${DBUS_DIR}/dbus-userdb-util.c
${DBUS_DIR}/dbus-sysdeps-util-unix.c
)
endif (WIN32)
......
......@@ -51,7 +51,7 @@ do_check_nonce (int fd, const DBusString *nonce, DBusError *error)
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_string_free (&p);
_dbus_string_free (&buffer);
return;
return FALSE;
}
while (nleft)
......@@ -105,9 +105,10 @@ _dbus_read_nonce (const DBusString *fname, DBusString *nonce, DBusError* error)
{
FILE *fp;
char buffer[17];
buffer[sizeof buffer - 1] = '\0';
size_t nread;
buffer[sizeof buffer - 1] = '\0';
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("reading nonce from file: %s\n", _dbus_string_get_const_data (fname));
......@@ -355,6 +356,7 @@ _dbus_noncefile_delete (DBusNonceFile *noncefile,
_dbus_delete_file (&noncefile->path, error);
_dbus_string_free (&noncefile->dir);
_dbus_string_free (&noncefile->path);
return TRUE;
}
#else
......@@ -389,6 +391,7 @@ _dbus_noncefile_delete (DBusNonceFile *noncefile,
_dbus_delete_directory (&noncefile->dir, error);
_dbus_string_free (&noncefile->dir);
_dbus_string_free (&noncefile->path);
return TRUE;
}
#endif
......
......@@ -25,6 +25,7 @@
#include "dbus-server-socket.h"
#include "dbus-transport-socket.h"
#include "dbus-connection-internal.h"
#include "dbus-memory.h"
#include "dbus-nonce.h"
#include "dbus-string.h"
......@@ -339,7 +340,7 @@ _dbus_server_new_for_socket (int *fds,
failed_3:
_dbus_noncefile_delete (socket_server->noncefile, NULL);
_dbus_free (socket_server->noncefile );
dbus_free (socket_server->noncefile );
failed_2:
for (i = 0 ; i < n_fds ; i++)
{
......
......@@ -34,6 +34,7 @@
#include "dbus-userdb.h"
#include "dbus-list.h"
#include "dbus-credentials.h"
#include "dbus-nonce.h"
#include <sys/types.h>
#include <stdlib.h>
......@@ -3908,6 +3909,34 @@ _dbus_get_is_errno_eagain_or_ewouldblock (void)
return errno == EAGAIN || errno == EWOULDBLOCK;
}
/**
* Removes a directory; Directory must be empty
*
* @param filename directory filename
* @param error initialized error object
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_delete_directory (const DBusString *filename,
DBusError *error)
{
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
filename_c = _dbus_string_get_const_data (filename);
if (rmdir (filename_c) != 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Failed to remove directory %s: %s\n",
filename_c, _dbus_strerror (errno));
return FALSE;
}
return TRUE;
}
/**
* Checks whether file descriptors may be passed via the socket
*
......
......@@ -509,35 +509,6 @@ _dbus_set_signal_handler (int sig,
sigaction (sig, &act, NULL);
}
/**
* Removes a directory; Directory must be empty
*
* @param filename directory filename
* @param error initialized error object
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_delete_directory (const DBusString *filename,
DBusError *error)
{
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
filename_c = _dbus_string_get_const_data (filename);
if (rmdir (filename_c) != 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Failed to remove directory %s: %s\n",
filename_c, _dbus_strerror (errno));
return FALSE;
}
return TRUE;
}
/** Checks if a file exists
*
* @param file full path to the file
......
......@@ -326,34 +326,6 @@ out0:
#endif //DBUS_WINCE
}
/**
* Removes a directory; Directory must be empty
*
* @param filename directory filename
* @param error initialized error object
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_delete_directory (const DBusString *filename,
DBusError *error)
{
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
filename_c = _dbus_string_get_const_data (filename);
if (_rmdir (filename_c) != 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Failed to remove directory %s: %s\n",
filename_c, strerror (errno));
return FALSE;
}
return TRUE;
}
void
_dbus_init_system_log (void)
{
......
......@@ -3681,6 +3681,34 @@ _dbus_win_warn_win_error (const char *message,
dbus_error_free (&error);
}
/**
* Removes a directory; Directory must be empty
*
* @param filename directory filename
* @param error initialized error object
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_delete_directory (const DBusString *filename,
DBusError *error)
{
const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
filename_c = _dbus_string_get_const_data (filename);
if (_rmdir (filename_c) != 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Failed to remove directory %s: %s\n",
filename_c, strerror (errno));
return FALSE;
}
return TRUE;
}
/** @} end of sysdeps-win */
/* tests in dbus-sysdeps-util.c */
......@@ -91,12 +91,6 @@ dbus_bool_t _dbus_file_exists (const char *filename);
dbus_bool_t _dbus_get_config_file_name(DBusString *config_file,
char *s);
int _dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
const char *noncefile,
DBusError *error);
#endif
/** @} end of sysdeps-win.h */
......@@ -181,6 +181,11 @@ int _dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
DBusError *error);
int _dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
const char *noncefile,
DBusError *error);
int _dbus_listen_tcp_socket (const char *host,
const char *port,
const char *family,
......
......@@ -23,6 +23,7 @@
#include "dbus-internals.h"
#include "dbus-connection-internal.h"
#include "dbus-nonce.h"
#include "dbus-transport-socket.h"
#include "dbus-transport-protected.h"
#include "dbus-watch.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment