*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <config.h>
#include "dbus-transport-protected.h"
#include "dbus-transport-unix.h"
#include "dbus-transport-socket.h"
#include "dbus-auth.h"
#include "dbus-address.h"
#include "dbus-credentials.h"
+#include "dbus-message-private.h"
+#include "dbus-marshal-header.h"
#ifdef DBUS_BUILD_TESTS
#include "dbus-server-debug-pipe.h"
#endif
*/
static void
-live_messages_size_notify (DBusCounter *counter,
+live_messages_notify (DBusCounter *counter,
void *user_data)
{
DBusTransport *transport = user_data;
_dbus_transport_ref (transport);
#if 0
- _dbus_verbose ("Counter value is now %d\n",
- (int) _dbus_counter_get_value (counter));
+ _dbus_verbose ("Size counter value is now %d\n",
+ (int) _dbus_counter_get_size_value (counter));
+ _dbus_verbose ("Unix FD counter value is now %d\n",
+ (int) _dbus_counter_get_unix_fd_value (counter));
#endif
/* disable or re-enable the read watch for the transport if
transport->vtable = vtable;
transport->loader = loader;
transport->auth = auth;
- transport->live_messages_size = counter;
+ transport->live_messages = counter;
transport->authenticated = FALSE;
transport->disconnected = FALSE;
transport->is_server = (server_guid != NULL);
*/
transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
+ /* On Linux RLIMIT_NOFILE defaults to 1024, so allowing 4096 fds live
+ should be more than enough */
+ transport->max_live_messages_unix_fds = 4096;
+
/* credentials read from socket if any */
transport->credentials = creds;
-
- _dbus_counter_set_notify (transport->live_messages_size,
+
+ _dbus_counter_set_notify (transport->live_messages,
transport->max_live_messages_size,
- live_messages_size_notify,
+ transport->max_live_messages_unix_fds,
+ live_messages_notify,
transport);
if (transport->address)
_dbus_verbose ("Initialized transport on address %s\n", transport->address);
-
+
return TRUE;
}
_dbus_message_loader_unref (transport->loader);
_dbus_auth_unref (transport->auth);
- _dbus_counter_set_notify (transport->live_messages_size,
- 0, NULL, NULL);
- _dbus_counter_unref (transport->live_messages_size);
+ _dbus_counter_set_notify (transport->live_messages,
+ 0, 0, NULL, NULL);
+ _dbus_counter_unref (transport->live_messages);
dbus_free (transport->address);
dbus_free (transport->expected_guid);
if (transport->credentials)
if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
_dbus_verbose ("Client authorized as SID '%s'"
" but our SID is '%s', disconnecting\n",
- _dbus_credentials_get_windows_sid(our_identity),
- _dbus_credentials_get_windows_sid(our_identity));
+ (_dbus_credentials_get_windows_sid(auth_identity) ?
+ _dbus_credentials_get_windows_sid(auth_identity) : "<null>"),
+ (_dbus_credentials_get_windows_sid(our_identity) ?
+ _dbus_credentials_get_windows_sid(our_identity) : "<null>"));
else
_dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
" but our UID is "DBUS_UID_FORMAT", disconnecting\n",
- _dbus_credentials_get_unix_uid(our_identity),
+ _dbus_credentials_get_unix_uid(auth_identity),
_dbus_credentials_get_unix_uid(our_identity));
_dbus_transport_disconnect (transport);
allow = FALSE;
}
/**
+ * Returns TRUE if the transport supports sending unix fds.
+ *
+ * @param transport the transport
+ * @returns #TRUE if TRUE it is possible to send unix fds across the transport.
+ */
+dbus_bool_t
+_dbus_transport_can_pass_unix_fd(DBusTransport *transport)
+{
+ return DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport);
+}
+
+/**
* Gets the address of a transport. It will be
* #NULL for a server-side transport.
*
DBusDispatchStatus
_dbus_transport_get_dispatch_status (DBusTransport *transport)
{
- if (_dbus_counter_get_value (transport->live_messages_size) >= transport->max_live_messages_size)
+ if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size ||
+ _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds)
return DBUS_DISPATCH_COMPLETE; /* complete for now */
if (!_dbus_transport_get_is_authenticated (transport))
_dbus_verbose ("queueing received message %p\n", message);
- if (!_dbus_message_add_size_counter (message, transport->live_messages_size))
+ if (!_dbus_message_add_counter (message, transport->live_messages))
{
_dbus_message_loader_putback_message_link (transport->loader,
link);
}
/**
+ * See dbus_connection_set_max_message_unix_fds().
+ *
+ * @param transport the transport
+ * @param n the max number of unix fds of a single message
+ */
+void
+_dbus_transport_set_max_message_unix_fds (DBusTransport *transport,
+ long n)
+{
+ _dbus_message_loader_set_max_message_unix_fds (transport->loader, n);
+}
+
+/**
* See dbus_connection_get_max_message_size().
*
* @param transport the transport
}
/**
+ * See dbus_connection_get_max_message_unix_fds().
+ *
+ * @param transport the transport
+ * @returns max message unix fds
+ */
+long
+_dbus_transport_get_max_message_unix_fds (DBusTransport *transport)
+{
+ return _dbus_message_loader_get_max_message_unix_fds (transport->loader);
+}
+
+/**
* See dbus_connection_set_max_received_size().
*
* @param transport the transport
long size)
{
transport->max_live_messages_size = size;
- _dbus_counter_set_notify (transport->live_messages_size,
+ _dbus_counter_set_notify (transport->live_messages,
transport->max_live_messages_size,
- live_messages_size_notify,
+ transport->max_live_messages_unix_fds,
+ live_messages_notify,
transport);
}
+/**
+ * See dbus_connection_set_max_received_unix_fds().
+ *
+ * @param transport the transport
+ * @param n the max unix fds of all incoming messages
+ */
+void
+_dbus_transport_set_max_received_unix_fds (DBusTransport *transport,
+ long n)
+{
+ transport->max_live_messages_unix_fds = n;
+ _dbus_counter_set_notify (transport->live_messages,
+ transport->max_live_messages_size,
+ transport->max_live_messages_unix_fds,
+ live_messages_notify,
+ transport);
+}
/**
* See dbus_connection_get_max_received_size().
}
/**
+ * See dbus_connection_set_max_received_unix_fds().
+ *
+ * @param transport the transport
+ * @returns max unix fds for all live messages
+ */
+long
+_dbus_transport_get_max_received_unix_fds (DBusTransport *transport)
+{
+ return transport->max_live_messages_unix_fds;
+}
+
+/**
* See dbus_connection_get_unix_user().
*
* @param transport the transport