if (WIN32)
- set (DBUS_SESSION_BUS_DEFAULT_ADDRESS "tcp:host=localhost,port=0")
- set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "tcp:host=localhost,port=0")
+ set (DBUS_SESSION_BUS_DEFAULT_ADDRESS "nonce-tcp:host=localhost,port=0")
+ set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "nonce-tcp:host=localhost,port=0")
set (DBUS_SYSTEM_CONFIG_FILE "etc/system.conf")
set (DBUS_SESSION_CONFIG_FILE "etc/session.conf")
# bus-test expects a non empty string
${DBUS_DIR}/dbus-marshal-validate.c
${DBUS_DIR}/dbus-message.c
${DBUS_DIR}/dbus-misc.c
+ ${DBUS_DIR}/dbus-nonce.c
${DBUS_DIR}/dbus-object-tree.c
${DBUS_DIR}/dbus-pending-call.c
${DBUS_DIR}/dbus-resources.c
dbus-message-internal.h \
dbus-message-private.h \
dbus-misc.c \
+ dbus-nonce.c \
dbus-object-tree.c \
dbus-object-tree.h \
dbus-pending-call.c \
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-nonce.c Nonce handling functions used by nonce-tcp (internal to D-Bus implementation)
+ *
+ * Copyright (C) 2009 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+// major sections of this file are modified code from libassuan, (C) FSF
+#include "dbus-nonce.h"
+#include "dbus-internals.h"
+#include "dbus-protocol.h"
+#include "dbus-sysdeps.h"
+
+#include <stdio.h>
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#ifndef ENOFILE
+# define ENOFILE ENOENT
+#endif
+
+dbus_bool_t
+_dbus_check_nonce (int fd, const DBusString *nonce)
+{
+ DBusString buffer;
+ DBusString p;
+ size_t nleft;
+ dbus_bool_t result;
+ int n;
+
+ nleft = 16;
+
+ _dbus_string_init (&buffer);
+ _dbus_string_init (&p);
+//PENDING(kdab) replace errno by DBusError
+ while (nleft)
+ {
+ n = _dbus_read_socket (fd, &p, nleft);
+ if (n == -1 && _dbus_get_is_errno_eintr())
+ ;
+ else if (n == -1 && _dbus_get_is_errno_eagain_or_ewouldblock())
+ _dbus_sleep_milliseconds (100);
+ else if (n==-1)
+ {
+ _dbus_string_free (&p);
+ _dbus_string_free (&buffer);
+ return FALSE;
+ }
+ else if (!n)
+ {
+ _dbus_string_free (&p);
+ _dbus_string_free (&buffer);
+ errno = EIO;
+ return FALSE;
+ }
+ else
+ {
+ _dbus_string_append_len(&buffer, _dbus_string_get_const_data (&p), n);
+ nleft -= n;
+ }
+ }
+
+ result = _dbus_string_equal_len (&buffer, nonce, 16);
+ if (!result)
+ errno = EACCES;
+
+ _dbus_string_free (&p);
+ _dbus_string_free (&buffer);
+
+ return result;
+}
+
+//PENDING(kdab) document
+dbus_bool_t
+_dbus_read_nonce (const DBusString *fname, DBusString *nonce)
+{
+ //PENDING(kdab) replace errno by DBusError
+ FILE *fp;
+ char buffer[17];
+ buffer[sizeof buffer - 1] = '\0';
+ size_t nread;
+ _dbus_verbose ("reading nonce from file: %s\n", _dbus_string_get_const_data (fname));
+
+
+ fp = fopen (_dbus_string_get_const_data (fname), "rb");
+ if (!fp)
+ return FALSE;
+ nread = fread (buffer, 1, sizeof buffer - 1, fp);
+ fclose (fp);
+ if (!nread)
+ {
+ errno = ENOFILE;
+ return FALSE;
+ }
+
+ if (!_dbus_string_append_len (nonce, buffer, sizeof buffer - 1 ))
+ {
+ errno = ENOMEM;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+int
+_dbus_accept_with_nonce (int listen_fd, const DBusString *nonce)
+{
+ _dbus_assert (nonce != NULL);
+ int fd;
+ fd = _dbus_accept (listen_fd);
+ if (_dbus_socket_is_invalid (fd))
+ return fd;
+ if (_dbus_check_nonce(fd, nonce) != TRUE) {
+ _dbus_verbose ("nonce check failed. Closing socket.\n");
+ _dbus_close_socket(fd, NULL);
+ return -1;
+ }
+
+ return fd;
+}
+
+int
+_dbus_accept_with_noncefile (int listen_fd, const DBusString *noncefile)
+{
+ _dbus_assert (noncefile != NULL);
+ DBusString nonce;
+ _dbus_string_init (&nonce);
+ //PENDING(kdab): set better errors
+ if (_dbus_read_nonce (noncefile, &nonce) != TRUE)
+ return -1;
+ return _dbus_accept_with_nonce (listen_fd, &nonce);
+}
+
+dbus_bool_t
+_dbus_generate_noncefilename (DBusString *buf)
+{
+ dbus_bool_t ret;
+ DBusString randomStr;
+ ret = _dbus_string_init (&randomStr);
+ if (!ret)
+ return FALSE;
+ ret = _dbus_generate_random_ascii (&randomStr, 8);
+ if (!ret)
+ goto oom;
+ if (!_dbus_string_append (buf, _dbus_get_tmpdir())
+ || !_dbus_string_append (buf, DBUS_DIR_SEPARATOR "dbus_nonce-")
+ || !_dbus_string_append (buf, _dbus_string_get_const_data (&randomStr)) )
+ goto oom;
+
+ _dbus_string_free (&randomStr);
+ return TRUE;
+oom:
+ _dbus_string_free (&randomStr);
+ return FALSE;
+}
+
+int
+_dbus_generate_and_write_nonce (const DBusString *filename)
+{
+ DBusString nonce;
+ int ret;
+
+ _dbus_string_init (&nonce);
+
+ if (!_dbus_generate_random_bytes (&nonce, 16))
+ return -1;
+
+ ret = _dbus_write_to_file (_dbus_string_get_const_data (filename), _dbus_string_get_const_data (&nonce), 16);
+
+ _dbus_string_free (&nonce);
+
+ return ret;
+}
+
+dbus_bool_t
+_dbus_send_nonce(int fd, const DBusString *noncefile, DBusError *error)
+{
+ dbus_bool_t read_result;
+ int send_result;
+ size_t sendLen;
+ DBusString nonce;
+
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (_dbus_string_get_length (noncefile) == 0)
+ return FALSE;
+
+ if ( !_dbus_string_init (&nonce) )
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return FALSE;
+ }
+
+ read_result = _dbus_read_nonce (noncefile, &nonce);
+
+ if (!read_result)
+ {
+ dbus_set_error (error,
+ _dbus_error_from_errno (errno),
+ "Could not read nonce from file %s (%s)",
+ _dbus_string_get_const_data (noncefile), _dbus_strerror(errno));
+ _dbus_string_free (&nonce);
+ return FALSE;
+ }
+
+ send_result = _dbus_write_socket (fd, &nonce, 0, _dbus_string_get_length (&nonce));
+
+ _dbus_string_free (&nonce);
+
+ if (send_result == -1)
+ {
+ dbus_set_error (error,
+ _dbus_error_from_errno (errno),
+ "Failed to send nonce (fd=%d): %s",
+ fd, _dbus_strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/** @} end of nonce */
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-nonce.h Nonce handling functions used by nonce-tcp (internal to D-Bus implementation)
+ *
+ * Copyright (C) 2009 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef DBUS_NONCE_H
+#define DBUS_NONCE_H
+
+#include <dbus/dbus-macros.h>
+#include <dbus/dbus-types.h>
+#include <dbus/dbus-errors.h>
+#include <dbus/dbus-string.h>
+
+DBUS_BEGIN_DECLS
+
+dbus_bool_t _dbus_check_nonce (int fd,
+ const DBusString *nonce);
+
+dbus_bool_t _dbus_read_nonce (const DBusString *fname,
+ DBusString *nonce);
+
+int _dbus_accept_with_nonce (int listen_fd,
+ const DBusString *nonce);
+
+int _dbus_accept_with_noncefile (int listen_fd,
+ const DBusString *noncefile);
+
+dbus_bool_t _dbus_generate_noncefilename (DBusString *buf);
+
+int _dbus_generate_and_write_nonce (const DBusString *filename);
+
+dbus_bool_t _dbus_send_nonce (int fd,
+ const DBusString *noncefile,
+ DBusError *error);
+
+DBUS_END_DECLS
+
+#endif /* DBUS_NONCE_H */
int *fds; /**< File descriptor or -1 if disconnected. */
DBusWatch **watch; /**< File descriptor watch. */
char *socket_name; /**< Name of domain socket, to unlink if appropriate */
+ DBusString noncefile; /**< Nonce file used to authenticate clients */
};
static void
dbus_free (socket_server->fds);
dbus_free (socket_server->watch);
dbus_free (socket_server->socket_name);
+ if (_dbus_string_get_length(&socket_server->noncefile) > 0)
+ {
+ _dbus_delete_file(&socket_server->noncefile, NULL);
+ }
+ _dbus_string_free (&socket_server->noncefile);
dbus_free (server);
}
DBusConnection *connection;
DBusTransport *transport;
DBusNewConnectionFunction new_connection_function;
+ DBusServerSocket* socket_server;
void *new_connection_data;
+ socket_server = (DBusServerSocket*)server;
_dbus_verbose ("Creating new client connection with fd %d\n", client_fd);
HAVE_LOCK_CHECK (server);
listen_fd = dbus_watch_get_socket (watch);
- client_fd = _dbus_accept (listen_fd);
+ client_fd = _dbus_accept_with_noncefile (listen_fd, &socket_server->noncefile);
if (client_fd < 0)
{
* @param fds list of file descriptors.
* @param n_fds number of file descriptors
* @param address the server's address
+ * @param noncefile the noncefile to use, NULL if without nonce
* @returns the new server, or #NULL if no memory.
*
*/
DBusServer*
_dbus_server_new_for_socket (int *fds,
int n_fds,
- const DBusString *address)
+ const DBusString *address,
+ const DBusString *noncefile)
{
DBusServerSocket *socket_server;
DBusServer *server;
&socket_vtable, address))
goto failed_2;
+ if (!_dbus_string_init (&socket_server->noncefile))
+ goto failed_2;
+
+ if (noncefile && !_dbus_string_copy (noncefile, 0, &socket_server->noncefile, 0))
+ goto failed_3;
+
server = (DBusServer*)socket_server;
SERVER_LOCK (server);
return (DBusServer*) socket_server;
+ failed_3:
+ _dbus_string_free (&socket_server->noncefile);
failed_2:
for (i = 0 ; i < n_fds ; i++)
{
const char *bind,
const char *port,
const char *family,
- DBusError *error)
+ DBusError *error,
+ dbus_bool_t use_nonce)
{
DBusServer *server;
int *listen_fds = NULL;
DBusString address;
DBusString host_str;
DBusString port_str;
+ DBusString noncefile;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
}
_dbus_string_init_const (&host_str, host);
- if (!_dbus_string_append (&address, "tcp:host=") ||
+ if (!_dbus_string_append (&address, use_nonce ? "nonce-tcp:host=" : "tcp:host=") ||
!_dbus_address_append_escaped (&address, &host_str) ||
!_dbus_string_append (&address, ",port=") ||
!_dbus_string_append (&address, _dbus_string_get_const_data(&port_str)))
goto failed_2;
}
- server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address);
+ if (!_dbus_string_init (&noncefile))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto failed_2;
+ }
+
+ if (use_nonce)
+ {
+ if (!_dbus_generate_noncefilename (&noncefile))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto failed_2;
+ }
+
+ if (_dbus_string_get_length(&noncefile) == 0 ||
+ !_dbus_string_append (&address, ",noncefile=") ||
+ !_dbus_address_append_escaped (&address, &noncefile))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto failed_2;
+ }
+
+ if (_dbus_generate_and_write_nonce (&noncefile) != 0)
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto failed_2;
+ }
+ }
+
+ server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, &noncefile);
if (server == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
for (i = 0 ; i < nlisten_fds ; i++)
_dbus_close_socket (listen_fds[i], NULL);
dbus_free(listen_fds);
+ _dbus_string_free (&noncefile);
failed_1:
_dbus_string_free (&port_str);
/**
* Tries to interpret the address entry for various socket-related
- * addresses (well, currently only tcp).
+ * addresses (well, currently only tcp and nonce-tcp).
*
* Sets error if the result is not OK.
*
method = dbus_address_entry_get_method (entry);
- if (strcmp (method, "tcp") == 0)
+ if (strcmp (method, "tcp") == 0 || strcmp (method, "nonce-tcp") == 0)
{
const char *host;
const char *port;
family = dbus_address_entry_get_value (entry, "family");
*server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
- family, error);
+ family, error, strcmp (method, "nonce-tcp") == 0 ? TRUE : FALSE);
if (*server_p)
{
DBusServer* _dbus_server_new_for_socket (int *fds,
int n_fds,
- const DBusString *address);
+ const DBusString *address,
+ const DBusString *noncefile);
DBusServer* _dbus_server_new_for_tcp_socket (const char *host,
const char *bind,
const char *port,
const char *family,
- DBusError *error);
+ DBusError *error,
+ dbus_bool_t use_nonce);
DBusServerListenResult _dbus_server_listen_socket (DBusAddressEntry *entry,
DBusServer **server_p,
DBusError *error);
goto failed_1;
}
- server = _dbus_server_new_for_socket (&listen_fd, 1, &address);
+ server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0);
if (server == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
#include "dbus-internals.h"
#include "dbus-server-win.h"
#include "dbus-server-socket.h"
-#include "dbus-connection-internal.h"
-#include "dbus-sysdeps-win.h"
/**
* @defgroup DBusServerWin DBusServer implementations for Windows
DBusServer **server_p,
DBusError *error)
{
- /* don't handle any method yet, return NULL with the error unset,
- ** for a sample implementation see dbus-server-unix.c
- */
+ const char *method;
+
*server_p = NULL;
+
+ method = dbus_address_entry_get_method (entry);
+
+ if (strcmp (method, "nonce-tcp") == 0)
+ {
+ const char *host;
+ const char *port;
+ const char *bind;
+ const char *family;
+
+ host = dbus_address_entry_get_value (entry, "host");
+ bind = dbus_address_entry_get_value (entry, "bind");
+ port = dbus_address_entry_get_value (entry, "port");
+ family = dbus_address_entry_get_value (entry, "family");
+
+ *server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
+ family, error, TRUE);
+
+ if (*server_p)
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR(error);
+ return DBUS_SERVER_LISTEN_OK;
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_SET(error);
+ return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
+ }
+ }
+ else
+ {
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
return DBUS_SERVER_LISTEN_NOT_HANDLED;
}
+}
/** @} */
#endif
}
+dbus_bool_t
+_dbus_socket_is_invalid (int fd)
+{
+ return fd < 0 ? TRUE : FALSE;
+}
/**
* Thin wrapper around the read() system call that appends
const char *family,
DBusError *error)
{
+ return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
+}
+
+int
+_dbus_connect_tcp_socket_with_nonce (const char *host,
+ const char *port,
+ const char *family,
+ const char *noncefile,
+ DBusError *error)
+{
int saved_errno = 0;
int fd = -1, res;
struct addrinfo hints;
return -1;
}
+ if (noncefile != NULL)
+ {
+ DBusString noncefileStr;
+ dbus_bool_t ret;
+ _dbus_string_init_const (&noncefileStr, noncefile);
+ ret = _dbus_send_nonce (fd, &noncefileStr, error);
+ _dbus_string_free (&noncefileStr);
- if (!_dbus_set_fd_nonblocking (fd, error))
+ if (!ret)
{
_dbus_close (fd, NULL);
- fd = -1;
+ return -1;
+ }
+ }
+ if (!_dbus_set_fd_nonblocking (fd, error))
+ {
+ _dbus_close (fd, NULL);
return -1;
}
return errno == EAGAIN || errno == EWOULDBLOCK;
}
+int
+_dbus_write_to_file (const char* filename, const char* buf, size_t len)
+{
+ int filefd;
+ FILE *fp;
+ size_t written;
+
+ filefd = open (filename,
+ (O_WRONLY|O_CREAT|O_EXCL|O_BINARY),
+ (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP));
+ if (filefd == -1)
+ {
+ return -1;
+ }
+ fp = fdopen (filefd, "wb");
+ if (!fp)
+ {
+ int save_e = errno;
+ close (filefd);
+ errno = save_e;
+ return -1;
+ }
+
+ written = fwrite (buf, len, 1, fp);
+ fclose (fp);
+
+ return written == 1 ? 0 : -1;
+}
+
/**
* Checks whether file descriptors may be passed via the socket
*
* @param count the amount of data to read
* @returns the number of bytes read or -1
*/
+
int
_dbus_read_socket (int fd,
DBusString *buffer,
if (bytes_read == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO();
- _dbus_verbose ("recv: failed: %s\n", _dbus_strerror (errno));
+ _dbus_verbose ("recv: failed: %s (%d)\n", _dbus_strerror (errno), errno);
bytes_read = -1;
}
else
return bytes_written;
}
+dbus_bool_t
+_dbus_socket_is_invalid (int fd)
+{
+ return fd == INVALID_SOCKET ? TRUE : FALSE;
+}
+
#if 0
/**
const char *family,
DBusError *error)
{
+ return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
+}
+
+int
+_dbus_connect_tcp_socket_with_nonce (const char *host,
+ const char *port,
+ const char *family,
+ const char *noncefile,
+ DBusError *error)
+{
int fd = -1, res;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
- if (connect (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
+ if (connect (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) != 0)
{
closesocket(fd);
fd = -1;
return -1;
}
+ if ( noncefile != NULL )
+ {
+ DBusString noncefileStr;
+ dbus_bool_t ret;
+ if (!_dbus_string_init (&noncefileStr) ||
+ !_dbus_string_append(&noncefileStr, noncefile))
+ {
+ closesocket (fd);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return -1;
+ }
+
+ ret = _dbus_send_nonce (fd, &noncefileStr, error);
- if (!_dbus_set_fd_nonblocking (fd, error))
+ _dbus_string_free (&noncefileStr);
+
+ if (!ret)
{
closesocket (fd);
- fd = -1;
+ return -1;
+ }
+ }
+ if (!_dbus_set_fd_nonblocking (fd, error) )
+ {
+ closesocket (fd);
return -1;
}
_dbus_warn ("%s: %s\n", message, error.message);
dbus_error_free (&error);
}
+
/** @} end of sysdeps-win */
/* tests in dbus-sysdeps-util.c */
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 */
-
-
const int *fds,
int n_fds);
+dbus_bool_t _dbus_socket_is_invalid (int fd);
+
int _dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
void _dbus_flush_caches (void);
+dbus_bool_t _dbus_generate_noncefilename (DBusString *buf);
+
+int _dbus_generate_and_write_nonce (const DBusString *filename);
+
+int _dbus_generate_nonce (char *buffer, size_t nbytes);
+
+dbus_bool_t _dbus_check_nonce (int fd, const DBusString *nonce);
+
+dbus_bool_t dbus_read_nonce (const DBusString *noncefile, DBusString *nonce);
+
+int _dbus_accept_with_nonce (int listen_fd, const DBusString *nonce);
+
+int _dbus_accept_with_noncefile (int listen_fd, const DBusString *noncefile);
+
+dbus_bool_t _dbus_send_nonce (int fd, const DBusString *noncefile, DBusError* error);
+
+int _dbus_write_to_file (const char *filename, const char *buf, size_t len);
+
/** @} */
DBUS_END_DECLS
* @param host the host to connect to
* @param port the port to connect to
* @param family the address family to connect to
+ * @param path to nonce file
* @param error location to store reason for failure.
* @returns a new transport, or #NULL on failure.
*/
_dbus_transport_new_for_tcp_socket (const char *host,
const char *port,
const char *family,
+ const char *noncefile,
DBusError *error)
{
int fd;
if (host == NULL)
host = "localhost";
- if (!_dbus_string_append (&address, "tcp:"))
+ if (!_dbus_string_append (&address, noncefile ? "nonce-tcp:" : "tcp:"))
goto error;
if (!_dbus_string_append (&address, "host=") ||
!_dbus_string_append (&address, family)))
goto error;
- fd = _dbus_connect_tcp_socket (host, port, family, error);
+ if (noncefile != NULL &&
+ (!_dbus_string_append (&address, "noncefile=") ||
+ !_dbus_string_append (&address, noncefile)))
+ goto error;
+
+ fd = _dbus_connect_tcp_socket_with_nonce (host, port, family, noncefile, error);
if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
DBusError *error)
{
const char *method;
+ dbus_bool_t isTcp;
+ dbus_bool_t isNonceTcp;
method = dbus_address_entry_get_method (entry);
_dbus_assert (method != NULL);
- if (strcmp (method, "tcp") == 0)
+ isTcp = strcmp (method, "tcp") == 0;
+ isNonceTcp = strcmp (method, "nonce-tcp") == 0;
+
+ if (isTcp || isNonceTcp)
{
const char *host = dbus_address_entry_get_value (entry, "host");
const char *port = dbus_address_entry_get_value (entry, "port");
const char *family = dbus_address_entry_get_value (entry, "family");
+ const char *noncefile = dbus_address_entry_get_value (entry, "noncefile");
+
+ if ((isNonceTcp == TRUE) != (noncefile != NULL)) {
+ _dbus_set_bad_address (error, method, "noncefile", NULL);
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
if (port == NULL)
{
- _dbus_set_bad_address (error, "tcp", "port", NULL);
+ _dbus_set_bad_address (error, method, "port", NULL);
return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
}
- *transport_p = _dbus_transport_new_for_tcp_socket (host, port, family, error);
+ *transport_p = _dbus_transport_new_for_tcp_socket (host, port, family, noncefile, error);
if (*transport_p == NULL)
{
- _DBUS_ASSERT_ERROR_IS_SET (error);
+ //PENDING(kdab)
+ //_DBUS_ASSERT_ERROR_IS_SET (error);
return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
}
else
DBusTransport* _dbus_transport_new_for_tcp_socket (const char *host,
const char *port,
const char *family,
+ const char *noncefile,
DBusError *error);
DBusTransportOpenResult _dbus_transport_open_socket (DBusAddressEntry *entry,
DBusTransport **transport_p,
DBusTransport **transport_p,
DBusError *error)
{
+ const char *method;
+
+ method = dbus_address_entry_get_method (entry);
+ _dbus_assert (method != NULL);
+
+ if (strcmp (method, "nonce-tcp") != 0)
+ {
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
}
+ const char *host = dbus_address_entry_get_value (entry, "host");
+ const char *port = dbus_address_entry_get_value (entry, "port");
+ const char *family = dbus_address_entry_get_value (entry, "family");
+ const char *noncefile = dbus_address_entry_get_value (entry, "noncefile");
+
+ if (port == NULL)
+ {
+ _dbus_set_bad_address (error, "nonce-tcp", "port", NULL);
+ return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+ }
+
+ *transport_p = _dbus_transport_new_for_tcp_socket (host, port, family, noncefile, error);
+ if (*transport_p == NULL)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
+ }
+ else
+ {
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ return DBUS_TRANSPORT_OPEN_OK;
+ }
+}
+
/** @} */