Merge "[lib-fix] Fixed return value of kdbus_write_msg Change-Id: Ia3a45a6a79b4078929...
[platform/upstream/dbus.git] / dbus / dbus-transport.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-transport.c DBusTransport object (internal to D-Bus implementation)
3  *
4  * Copyright (C) 2002, 2003  Red Hat Inc.
5  * Copyright (C) 2013  Samsung Electronics
6  *
7  * Licensed under the Academic Free License version 2.1
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25
26 #include <../config.h>
27 #include "dbus-transport-protected.h"
28 #include "dbus-transport-unix.h"
29 #include "dbus-transport-socket.h"
30 #include "dbus-connection-internal.h"
31 #include "dbus-watch.h"
32 #include "dbus-auth.h"
33 #include "dbus-address.h"
34 #include "dbus-credentials.h"
35 #include "dbus-mainloop.h"
36 #include "dbus-message.h"
37 #ifdef ENABLE_KDBUS_TRANSPORT
38 #include "dbus-transport-kdbus.h"
39 #endif
40 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
41 #include "dbus-server-debug-pipe.h"
42 #endif
43
44 /**
45  * @defgroup DBusTransport DBusTransport object
46  * @ingroup  DBusInternals
47  * @brief "Backend" for a DBusConnection.
48  *
49  * Types and functions related to DBusTransport.  A transport is an
50  * abstraction that can send and receive data via various kinds of
51  * network connections or other IPC mechanisms.
52  * 
53  * @{
54  */
55
56 /**
57  * @typedef DBusTransport
58  *
59  * Opaque object representing a way message stream.
60  * DBusTransport abstracts various kinds of actual
61  * transport mechanism, such as different network protocols,
62  * or encryption schemes.
63  */
64
65 static void
66 live_messages_notify (DBusCounter *counter,
67                            void        *user_data)
68 {
69   DBusTransport *transport = user_data;
70
71   _dbus_transport_ref (transport);
72
73 #if 0
74   _dbus_verbose ("Size counter value is now %d\n",
75                  (int) _dbus_counter_get_size_value (counter));
76   _dbus_verbose ("Unix FD counter value is now %d\n",
77                  (int) _dbus_counter_get_unix_fd_value (counter));
78 #endif
79
80   /* disable or re-enable the read watch for the transport if
81    * required.
82    */
83   if (transport->vtable->live_messages_changed)
84     {
85       _dbus_connection_lock (transport->connection);
86       (* transport->vtable->live_messages_changed) (transport);
87       _dbus_connection_unlock (transport->connection);
88     }
89
90   _dbus_transport_unref (transport);
91 }
92
93 /**
94  * Initializes the base class members of DBusTransport.  Chained up to
95  * by subclasses in their constructor.  The server GUID is the
96  * globally unique ID for the server creating this connection
97  * and will be #NULL for the client side of a connection. The GUID
98  * is in hex format.
99  *
100  * @param transport the transport being created.
101  * @param vtable the subclass vtable.
102  * @param server_guid non-#NULL if this transport is on the server side of a connection
103  * @param address the address of the transport
104  * @returns #TRUE on success.
105  */
106 dbus_bool_t
107 _dbus_transport_init_base (DBusTransport             *transport,
108                            const DBusTransportVTable *vtable,
109                            const DBusString          *server_guid,
110                            const DBusString          *address)
111 {
112   DBusMessageLoader *loader;
113   DBusAuth *auth;
114   DBusCounter *counter;
115   char *address_copy = NULL;
116   DBusCredentials *creds;
117   
118   loader = _dbus_message_loader_new ();
119   if (loader == NULL)
120     return FALSE;
121   
122   if (server_guid)
123     auth = _dbus_auth_server_new (server_guid);
124   else
125   {
126           _dbus_assert (address != NULL);
127           if (!_dbus_string_copy_data (address, &address_copy))
128         {
129           _dbus_message_loader_unref (loader);
130           return FALSE;
131         }
132 #ifdef ENABLE_KDBUS_TRANSPORT
133       if(address_copy == strstr(address_copy, "kdbus:path="))
134           auth = _dbus_auth_client_new_kdbus();
135           else
136 #endif
137                   auth = _dbus_auth_client_new ();
138   }
139
140   if (auth == NULL)
141     {
142       _dbus_message_loader_unref (loader);
143       
144       if (address_copy != NULL)
145         dbus_free(address_copy);
146       
147       return FALSE;
148     }
149
150   counter = _dbus_counter_new ();
151   if (counter == NULL)
152     {
153       _dbus_auth_unref (auth);
154       _dbus_message_loader_unref (loader);
155       
156       if (address_copy != NULL)
157         dbus_free(address_copy);
158       
159       return FALSE;
160     }  
161
162   creds = _dbus_credentials_new ();
163   if (creds == NULL)
164     {
165       _dbus_counter_unref (counter);
166       _dbus_auth_unref (auth);
167       _dbus_message_loader_unref (loader);
168       
169       if (address_copy != NULL)
170         dbus_free(address_copy);
171       
172       return FALSE;
173     }
174   
175   if (server_guid)
176     {
177       _dbus_assert (address == NULL);
178       address_copy = NULL;
179     }
180   
181   transport->refcount = 1;
182   transport->vtable = vtable;
183   transport->loader = loader;
184   transport->auth = auth;
185   transport->live_messages = counter;
186   transport->authenticated = FALSE;
187   transport->disconnected = FALSE;
188   transport->is_server = (server_guid != NULL);
189   transport->send_credentials_pending = !transport->is_server;
190   transport->receive_credentials_pending = transport->is_server;
191   transport->address = address_copy;
192   
193   transport->unix_user_function = NULL;
194   transport->unix_user_data = NULL;
195   transport->free_unix_user_data = NULL;
196
197   transport->windows_user_function = NULL;
198   transport->windows_user_data = NULL;
199   transport->free_windows_user_data = NULL;
200   
201   transport->expected_guid = NULL;
202   
203   /* Try to default to something that won't totally hose the system,
204    * but doesn't impose too much of a limitation.
205    */
206   transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
207
208   /* On Linux RLIMIT_NOFILE defaults to 1024, so allowing 4096 fds live
209      should be more than enough */
210   transport->max_live_messages_unix_fds = 4096;
211
212   /* credentials read from socket if any */
213   transport->credentials = creds;
214
215   _dbus_counter_set_notify (transport->live_messages,
216                             transport->max_live_messages_size,
217                             transport->max_live_messages_unix_fds,
218                             live_messages_notify,
219                             transport);
220
221   if (transport->address)
222     _dbus_verbose ("Initialized transport on address %s\n", transport->address);
223
224   return TRUE;
225 }
226
227 /**
228  * Finalizes base class members of DBusTransport.
229  * Chained up to from subclass finalizers.
230  *
231  * @param transport the transport.
232  */
233 void
234 _dbus_transport_finalize_base (DBusTransport *transport)
235 {
236   if (!transport->disconnected)
237     _dbus_transport_disconnect (transport);
238
239   if (transport->free_unix_user_data != NULL)
240     (* transport->free_unix_user_data) (transport->unix_user_data);
241
242   if (transport->free_windows_user_data != NULL)
243     (* transport->free_windows_user_data) (transport->windows_user_data);
244   
245   _dbus_message_loader_unref (transport->loader);
246   _dbus_auth_unref (transport->auth);
247   _dbus_counter_set_notify (transport->live_messages,
248                             0, 0, NULL, NULL);
249   _dbus_counter_unref (transport->live_messages);
250   dbus_free (transport->address);
251   dbus_free (transport->expected_guid);
252   if (transport->credentials)
253     _dbus_credentials_unref (transport->credentials);
254 }
255
256
257 /**
258  * Verifies if a given D-Bus address is a valid address
259  * by attempting to connect to it. If it is, returns the
260  * opened DBusTransport object. If it isn't, returns #NULL
261  * and sets @p error.
262  *
263  * @param address the address to be checked.
264  * @param error address where an error can be returned.
265  * @returns a new transport, or #NULL on failure.
266  */
267 static DBusTransport*
268 check_address (const char *address, DBusError *error)
269 {
270   DBusAddressEntry **entries;
271   DBusTransport *transport = NULL;
272   int len, i;
273
274   _dbus_assert (address != NULL);
275
276   if (!dbus_parse_address (address, &entries, &len, error))
277     return NULL;              /* not a valid address */
278
279   for (i = 0; i < len; i++)
280     {
281       transport = _dbus_transport_open (entries[i], error);
282       if (transport != NULL)
283         break;
284     }
285
286   dbus_address_entries_free (entries);
287   return transport;
288 }
289
290 /**
291  * Creates a new transport for the "autostart" method.
292  * This creates a client-side of a transport.
293  *
294  * @param scope scope of autolaunch (Windows only)
295  * @param error address where an error can be returned.
296  * @returns a new transport, or #NULL on failure.
297  */
298 static DBusTransport*
299 _dbus_transport_new_for_autolaunch (const char *scope, DBusError *error)
300 {
301   DBusString address;
302   DBusTransport *result = NULL;
303
304   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
305
306   if (!_dbus_string_init (&address))
307     {
308       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
309       return NULL;
310     }
311
312   if (!_dbus_get_autolaunch_address (scope, &address, error))
313     {
314       _DBUS_ASSERT_ERROR_IS_SET (error);
315       goto out;
316     }
317
318   result = check_address (_dbus_string_get_const_data (&address), error);
319   if (result == NULL)
320     _DBUS_ASSERT_ERROR_IS_SET (error);
321   else
322     _DBUS_ASSERT_ERROR_IS_CLEAR (error);
323
324  out:
325   _dbus_string_free (&address);
326   return result;
327 }
328
329 static DBusTransportOpenResult
330 _dbus_transport_open_autolaunch (DBusAddressEntry  *entry,
331                                  DBusTransport    **transport_p,
332                                  DBusError         *error)
333 {
334   const char *method;
335   
336   method = dbus_address_entry_get_method (entry);
337   _dbus_assert (method != NULL);
338
339   if (strcmp (method, "autolaunch") == 0)
340     {
341       const char *scope = dbus_address_entry_get_value (entry, "scope");
342
343       *transport_p = _dbus_transport_new_for_autolaunch (scope, error);
344
345       if (*transport_p == NULL)
346         {
347           _DBUS_ASSERT_ERROR_IS_SET (error);
348           return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
349         }
350       else
351         {
352           _DBUS_ASSERT_ERROR_IS_CLEAR (error);
353           return DBUS_TRANSPORT_OPEN_OK;
354         }      
355     }
356   else
357     {
358       _DBUS_ASSERT_ERROR_IS_CLEAR (error);
359       return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
360     }
361 }
362
363 static const struct {
364   DBusTransportOpenResult (* func) (DBusAddressEntry *entry,
365                                     DBusTransport   **transport_p,
366                                     DBusError        *error);
367 } open_funcs[] = {
368 #ifdef ENABLE_KDBUS_TRANSPORT
369   { _dbus_transport_open_kdbus },
370 #endif
371   { _dbus_transport_open_socket },
372   { _dbus_transport_open_platform_specific },
373   { _dbus_transport_open_autolaunch }
374 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
375   , { _dbus_transport_open_debug_pipe }
376 #endif
377 };
378
379 /**
380  * Try to open a new transport for the given address entry.  (This
381  * opens a client-side-of-the-connection transport.)
382  * 
383  * @param entry the address entry
384  * @param error location to store reason for failure.
385  * @returns new transport of #NULL on failure.
386  */
387 DBusTransport*
388 _dbus_transport_open (DBusAddressEntry *entry,
389                       DBusError        *error)
390 {
391   DBusTransport *transport;
392   const char *expected_guid_orig;
393   char *expected_guid;
394   int i;
395   DBusError tmp_error = DBUS_ERROR_INIT;
396
397   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
398   
399   transport = NULL;
400   expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
401   expected_guid = _dbus_strdup (expected_guid_orig);
402
403   if (expected_guid_orig != NULL && expected_guid == NULL)
404     {
405       _DBUS_SET_OOM (error);
406       return NULL;
407     }
408
409   for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
410     {
411       DBusTransportOpenResult result;
412
413       _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
414       result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
415
416       switch (result)
417         {
418         case DBUS_TRANSPORT_OPEN_OK:
419           _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
420           goto out;
421           break;
422         case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
423           _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
424           /* keep going through the loop of open funcs */
425           break;
426         case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
427           _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
428           goto out;
429           break;
430         case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
431           _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
432           goto out;
433           break;
434         }
435     }
436
437  out:
438   
439   if (transport == NULL)
440     {
441       if (!dbus_error_is_set (&tmp_error))
442         _dbus_set_bad_address (&tmp_error,
443                                NULL, NULL,
444                                "Unknown address type (examples of valid types are \"tcp\" and on UNIX \"unix\")");
445       
446       _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
447       dbus_move_error(&tmp_error, error);
448       dbus_free (expected_guid);
449     }
450   else
451     {
452       _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
453
454       /* In the case of autostart the initial guid is NULL
455        * and the autostart transport recursively calls
456        * _dbus_open_transport wich returns a transport
457        * with a guid.  That guid is the definitive one.
458        *
459        * FIXME: if more transports are added they may have
460        * an effect on the expected_guid semantics (i.e. 
461        * expected_guid and transport->expected_guid may
462        * both have values).  This is very unlikely though
463        * we should either throw asserts here for those 
464        * corner cases or refactor the code so it is 
465        * clearer on what is expected and what is not
466        */
467       if(expected_guid)
468         transport->expected_guid = expected_guid;
469     }
470
471   return transport;
472 }
473
474 /**
475  * Increments the reference count for the transport.
476  *
477  * @param transport the transport.
478  * @returns the transport.
479  */
480 DBusTransport *
481 _dbus_transport_ref (DBusTransport *transport)
482 {
483   _dbus_assert (transport->refcount > 0);
484   
485   transport->refcount += 1;
486
487   return transport;
488 }
489
490 /**
491  * Decrements the reference count for the transport.
492  * Disconnects and finalizes the transport if
493  * the reference count reaches zero.
494  *
495  * @param transport the transport.
496  */
497 void
498 _dbus_transport_unref (DBusTransport *transport)
499 {
500   _dbus_assert (transport != NULL);
501   _dbus_assert (transport->refcount > 0);
502   
503   transport->refcount -= 1;
504   if (transport->refcount == 0)
505     {
506       _dbus_verbose ("finalizing\n");
507       
508       _dbus_assert (transport->vtable->finalize != NULL);
509       
510       (* transport->vtable->finalize) (transport);
511     }
512 }
513
514 /**
515  * Closes our end of the connection to a remote application. Further
516  * attempts to use this transport will fail. Only the first call to
517  * _dbus_transport_disconnect() will have an effect.
518  *
519  * @param transport the transport.
520  * 
521  */
522 void
523 _dbus_transport_disconnect (DBusTransport *transport)
524 {
525   _dbus_verbose ("start\n");
526   
527   _dbus_assert (transport->vtable->disconnect != NULL);
528   
529   if (transport->disconnected)
530     return;
531
532   (* transport->vtable->disconnect) (transport);
533   
534   transport->disconnected = TRUE;
535
536   _dbus_verbose ("end\n");
537 }
538
539 /**
540  * Returns #TRUE if the transport has not been disconnected.
541  * Disconnection can result from _dbus_transport_disconnect()
542  * or because the server drops its end of the connection.
543  *
544  * @param transport the transport.
545  * @returns whether we're connected
546  */
547 dbus_bool_t
548 _dbus_transport_get_is_connected (DBusTransport *transport)
549 {
550   return !transport->disconnected;
551 }
552
553 static dbus_bool_t
554 auth_via_unix_user_function (DBusTransport *transport)
555 {
556   DBusCredentials *auth_identity;
557   dbus_bool_t allow;
558   DBusConnection *connection;
559   DBusAllowUnixUserFunction unix_user_function;
560   void *unix_user_data;
561   dbus_uid_t uid;
562
563   /* Dropping the lock here probably isn't that safe. */
564   
565   auth_identity = _dbus_auth_get_identity (transport->auth);
566   _dbus_assert (auth_identity != NULL);
567
568   connection = transport->connection;
569   unix_user_function = transport->unix_user_function;
570   unix_user_data = transport->unix_user_data;
571   uid = _dbus_credentials_get_unix_uid (auth_identity);
572               
573   _dbus_verbose ("unlock\n");
574   _dbus_connection_unlock (connection);
575
576   allow = (* unix_user_function) (connection,
577                                   uid,
578                                   unix_user_data);
579               
580   _dbus_verbose ("lock post unix user function\n");
581   _dbus_connection_lock (connection);
582
583   if (allow)
584     {
585       _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", uid);
586     }
587   else
588     {
589       _dbus_verbose ("Client UID "DBUS_UID_FORMAT
590                      " was rejected, disconnecting\n",
591                      _dbus_credentials_get_unix_uid (auth_identity));
592       _dbus_transport_disconnect (transport);
593     }
594
595   return allow;
596 }
597
598 static dbus_bool_t
599 auth_via_windows_user_function (DBusTransport *transport)
600 {
601   DBusCredentials *auth_identity;  
602   dbus_bool_t allow;
603   DBusConnection *connection;
604   DBusAllowWindowsUserFunction windows_user_function;
605   void *windows_user_data;
606   char *windows_sid;
607
608   /* Dropping the lock here probably isn't that safe. */
609   
610   auth_identity = _dbus_auth_get_identity (transport->auth);
611   _dbus_assert (auth_identity != NULL);
612
613   connection = transport->connection;
614   windows_user_function = transport->windows_user_function;
615   windows_user_data = transport->unix_user_data;
616   windows_sid = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
617
618   if (windows_sid == NULL)
619     {
620       /* OOM */
621       return FALSE;
622     }
623                 
624   _dbus_verbose ("unlock\n");
625   _dbus_connection_unlock (connection);
626
627   allow = (* windows_user_function) (connection,
628                                      windows_sid,
629                                      windows_user_data);
630               
631   _dbus_verbose ("lock post windows user function\n");
632   _dbus_connection_lock (connection);
633
634   if (allow)
635     {
636       _dbus_verbose ("Client SID '%s' authorized\n", windows_sid);
637     }
638   else
639     {
640       _dbus_verbose ("Client SID '%s' was rejected, disconnecting\n",
641                      _dbus_credentials_get_windows_sid (auth_identity));
642       _dbus_transport_disconnect (transport);
643     }
644
645   return allow;
646 }
647
648 static dbus_bool_t
649 auth_via_default_rules (DBusTransport *transport)
650 {
651   DBusCredentials *auth_identity;
652   DBusCredentials *our_identity;
653   dbus_bool_t allow;
654   
655   auth_identity = _dbus_auth_get_identity (transport->auth);
656   _dbus_assert (auth_identity != NULL);
657
658   /* By default, connection is allowed if the client is 1) root or 2)
659    * has the same UID as us or 3) anonymous is allowed.
660    */
661   
662   our_identity = _dbus_credentials_new_from_current_process ();
663   if (our_identity == NULL)
664     {
665       /* OOM */
666       return FALSE;
667     }
668               
669   if (transport->allow_anonymous ||
670       _dbus_credentials_get_unix_uid (auth_identity) == 0 ||
671       _dbus_credentials_same_user (our_identity,
672                                    auth_identity))
673     {
674       if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
675           _dbus_verbose ("Client authorized as SID '%s'"
676                          "matching our SID '%s'\n",
677                          _dbus_credentials_get_windows_sid(auth_identity),
678                          _dbus_credentials_get_windows_sid(our_identity));
679       else
680           _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
681                          " matching our UID "DBUS_UID_FORMAT"\n",
682                          _dbus_credentials_get_unix_uid(auth_identity),
683                          _dbus_credentials_get_unix_uid(our_identity));
684       /* We have authenticated! */
685       allow = TRUE;
686     }
687   else
688     {
689       if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
690           _dbus_verbose ("Client authorized as SID '%s'"
691                          " but our SID is '%s', disconnecting\n",
692                          (_dbus_credentials_get_windows_sid(auth_identity) ?
693                           _dbus_credentials_get_windows_sid(auth_identity) : "<null>"),
694                          (_dbus_credentials_get_windows_sid(our_identity) ?
695                           _dbus_credentials_get_windows_sid(our_identity) : "<null>"));
696       else
697           _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
698                          " but our UID is "DBUS_UID_FORMAT", disconnecting\n",
699                          _dbus_credentials_get_unix_uid(auth_identity),
700                          _dbus_credentials_get_unix_uid(our_identity));
701       _dbus_transport_disconnect (transport);
702       allow = FALSE;
703     }  
704
705   _dbus_credentials_unref (our_identity);
706   
707   return allow;
708 }
709
710 /**
711  * Returns #TRUE if we have been authenticated. It will return #TRUE even if
712  * the transport is now disconnected, but was ever authenticated before
713  * disconnecting.
714  *
715  * This replaces the older _dbus_transport_get_is_authenticated() which
716  * had side-effects.
717  *
718  * @param transport the transport
719  * @returns whether we're authenticated
720  */
721 dbus_bool_t
722 _dbus_transport_peek_is_authenticated (DBusTransport *transport)
723 {
724   return transport->authenticated;
725 }
726
727 /**
728  * Returns #TRUE if we have been authenticated. It will return #TRUE even if
729  * the transport is now disconnected, but was ever authenticated before
730  * disconnecting.
731  *
732  * If we have not finished authenticating, but we have enough buffered input
733  * to finish the job, then this function will do so before it returns.
734  *
735  * This used to be called _dbus_transport_get_is_authenticated(), but that
736  * name seems inappropriate for a function with side-effects.
737  *
738  * @todo we drop connection->mutex when calling the unix_user_function,
739  * and windows_user_function, which may not be safe really.
740  *
741  * @param transport the transport
742  * @returns whether we're authenticated
743  */
744 dbus_bool_t
745 _dbus_transport_try_to_authenticate (DBusTransport *transport)
746 {  
747   if (transport->authenticated)
748     return TRUE;
749   else
750     {
751       dbus_bool_t maybe_authenticated;
752       
753       if (transport->disconnected)
754         return FALSE;
755
756       /* paranoia ref since we call user callbacks sometimes */
757       _dbus_connection_ref_unlocked (transport->connection);
758       
759       maybe_authenticated =
760         (!(transport->send_credentials_pending ||
761            transport->receive_credentials_pending));
762
763       if (maybe_authenticated)
764         {
765           switch (_dbus_auth_do_work (transport->auth))
766             {
767             case DBUS_AUTH_STATE_AUTHENTICATED:
768               /* leave as maybe_authenticated */
769               break;
770             default:
771               maybe_authenticated = FALSE;
772             }
773         }
774
775       /* If we're the client, verify the GUID
776        */
777       if (maybe_authenticated && !transport->is_server)
778         {
779           const char *server_guid;
780
781           server_guid = _dbus_auth_get_guid_from_server (transport->auth);
782           _dbus_assert (server_guid != NULL);
783
784           if (transport->expected_guid &&
785               strcmp (transport->expected_guid, server_guid) != 0)
786             {
787               _dbus_verbose ("Client expected GUID '%s' and we got '%s' from the server\n",
788                              transport->expected_guid, server_guid);
789               _dbus_transport_disconnect (transport);
790               _dbus_connection_unref_unlocked (transport->connection);
791               return FALSE;
792             }
793         }
794
795       /* If we're the server, see if we want to allow this identity to proceed.
796        */
797       if (maybe_authenticated && transport->is_server)
798         {
799           dbus_bool_t allow;
800           DBusCredentials *auth_identity;
801           
802           auth_identity = _dbus_auth_get_identity (transport->auth);
803           _dbus_assert (auth_identity != NULL);
804           
805           /* If we have an auth'd user and a user function, delegate
806            * deciding whether auth credentials are good enough to the
807            * app; otherwise, use our default decision process.
808            */
809           if (transport->unix_user_function != NULL &&
810               _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_UNIX_USER_ID))
811             {
812               allow = auth_via_unix_user_function (transport);
813             }
814           else if (transport->windows_user_function != NULL &&
815                    _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_WINDOWS_SID))
816             {
817               allow = auth_via_windows_user_function (transport);
818             }      
819           else
820             {
821               allow = auth_via_default_rules (transport);
822             }
823           
824           if (!allow)
825             maybe_authenticated = FALSE;
826         }
827
828       transport->authenticated = maybe_authenticated;
829
830       _dbus_connection_unref_unlocked (transport->connection);
831       return maybe_authenticated;
832     }
833 }
834
835 /**
836  * See dbus_connection_get_is_anonymous().
837  *
838  * @param transport the transport
839  * @returns #TRUE if not authenticated or authenticated as anonymous
840  */
841 dbus_bool_t
842 _dbus_transport_get_is_anonymous (DBusTransport *transport)
843 {
844   DBusCredentials *auth_identity;
845   
846   if (!transport->authenticated)
847     return TRUE;
848   
849   auth_identity = _dbus_auth_get_identity (transport->auth);
850
851   if (_dbus_credentials_are_anonymous (auth_identity))
852     return TRUE;
853   else
854     return FALSE;
855 }
856
857 /**
858  * Returns TRUE if the transport supports sending unix fds.
859  *
860  * @param transport the transport
861  * @returns #TRUE if TRUE it is possible to send unix fds across the transport.
862  */
863 dbus_bool_t
864 _dbus_transport_can_pass_unix_fd(DBusTransport *transport)
865 {
866   return DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport);
867 }
868
869 /**
870  * Gets the address of a transport. It will be
871  * #NULL for a server-side transport.
872  *
873  * @param transport the transport
874  * @returns transport's address
875  */
876 const char*
877 _dbus_transport_get_address (DBusTransport *transport)
878 {
879   return transport->address;
880 }
881
882 /**
883  * Gets the id of the server we are connected to (see
884  * dbus_server_get_id()). Only works on client side.
885  *
886  * @param transport the transport
887  * @returns transport's server's id or #NULL if we are the server side
888  */
889 const char*
890 _dbus_transport_get_server_id (DBusTransport *transport)
891 {
892   if (transport->is_server)
893     return NULL;
894   else if (transport->authenticated)
895     return _dbus_auth_get_guid_from_server (transport->auth);
896   else
897     return transport->expected_guid;
898 }
899
900 /**
901  * Handles a watch by reading data, writing data, or disconnecting
902  * the transport, as appropriate for the given condition.
903  *
904  * @param transport the transport.
905  * @param watch the watch.
906  * @param condition the current state of the watched file descriptor.
907  * @returns #FALSE if not enough memory to fully handle the watch
908  */
909 dbus_bool_t
910 _dbus_transport_handle_watch (DBusTransport           *transport,
911                               DBusWatch               *watch,
912                               unsigned int             condition)
913 {
914   dbus_bool_t retval;
915   
916   _dbus_assert (transport->vtable->handle_watch != NULL);
917
918   if (transport->disconnected)
919     return TRUE;
920
921   if (dbus_watch_get_socket (watch) < 0)
922     {
923       _dbus_warn_check_failed ("Tried to handle an invalidated watch; this watch should have been removed\n");
924       return TRUE;
925     }
926   
927   _dbus_watch_sanitize_condition (watch, &condition);
928
929   _dbus_transport_ref (transport);
930   _dbus_watch_ref (watch);
931   retval = (* transport->vtable->handle_watch) (transport, watch, condition);
932   _dbus_watch_unref (watch);
933   _dbus_transport_unref (transport);
934
935   return retval;
936 }
937
938 /**
939  * Sets the connection using this transport. Allows the transport
940  * to add watches to the connection, queue incoming messages,
941  * and pull outgoing messages.
942  *
943  * @param transport the transport.
944  * @param connection the connection.
945  * @returns #FALSE if not enough memory
946  */
947 dbus_bool_t
948 _dbus_transport_set_connection (DBusTransport  *transport,
949                                 DBusConnection *connection)
950 {
951   _dbus_assert (transport->vtable->connection_set != NULL);
952   _dbus_assert (transport->connection == NULL);
953   
954   transport->connection = connection;
955
956   _dbus_transport_ref (transport);
957   if (!(* transport->vtable->connection_set) (transport))
958     transport->connection = NULL;
959   _dbus_transport_unref (transport);
960
961   return transport->connection != NULL;
962 }
963
964 /**
965  * Get the socket file descriptor, if any.
966  *
967  * @param transport the transport
968  * @param fd_p pointer to fill in with the descriptor
969  * @returns #TRUE if a descriptor was available
970  */
971 dbus_bool_t
972 _dbus_transport_get_socket_fd (DBusTransport *transport,
973                                int           *fd_p)
974 {
975   dbus_bool_t retval;
976   
977   if (transport->vtable->get_socket_fd == NULL)
978     return FALSE;
979
980   if (transport->disconnected)
981     return FALSE;
982
983   _dbus_transport_ref (transport);
984
985   retval = (* transport->vtable->get_socket_fd) (transport,
986                                                  fd_p);
987   
988   _dbus_transport_unref (transport);
989
990   return retval;
991 }
992
993 /**
994  * Performs a single poll()/select() on the transport's file
995  * descriptors and then reads/writes data as appropriate,
996  * queueing incoming messages and sending outgoing messages.
997  * This is the backend for _dbus_connection_do_iteration().
998  * See _dbus_connection_do_iteration() for full details.
999  *
1000  * @param transport the transport.
1001  * @param flags indicates whether to read or write, and whether to block.
1002  * @param timeout_milliseconds if blocking, timeout or -1 for no timeout.
1003  */
1004 void
1005 _dbus_transport_do_iteration (DBusTransport  *transport,
1006                               unsigned int    flags,
1007                               int             timeout_milliseconds)
1008 {
1009   _dbus_assert (transport->vtable->do_iteration != NULL);
1010
1011   _dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
1012                  flags, timeout_milliseconds, !transport->disconnected);
1013   
1014   if ((flags & (DBUS_ITERATION_DO_WRITING |
1015                 DBUS_ITERATION_DO_READING)) == 0)
1016     return; /* Nothing to do */
1017
1018   if (transport->disconnected)
1019     return;
1020
1021   _dbus_transport_ref (transport);
1022   (* transport->vtable->do_iteration) (transport, flags,
1023                                        timeout_milliseconds);
1024   _dbus_transport_unref (transport);
1025
1026   _dbus_verbose ("end\n");
1027 }
1028
1029 static dbus_bool_t
1030 recover_unused_bytes (DBusTransport *transport)
1031 {
1032   if (_dbus_auth_needs_decoding (transport->auth))
1033     {
1034       DBusString plaintext;
1035       const DBusString *encoded;
1036       DBusString *buffer;
1037       int orig_len;
1038
1039       if (!_dbus_string_init (&plaintext))
1040         goto nomem;
1041       
1042       _dbus_auth_get_unused_bytes (transport->auth,
1043                                    &encoded);
1044
1045       if (!_dbus_auth_decode_data (transport->auth,
1046                                    encoded, &plaintext))
1047         {
1048           _dbus_string_free (&plaintext);
1049           goto nomem;
1050         }
1051
1052       _dbus_message_loader_get_buffer (transport->loader,
1053                                        &buffer);
1054       
1055       orig_len = _dbus_string_get_length (buffer);
1056
1057       if (!_dbus_string_move (&plaintext, 0, buffer,
1058                               orig_len))
1059         {
1060           _dbus_string_free (&plaintext);
1061           goto nomem;
1062         }
1063       
1064       _dbus_verbose (" %d unused bytes sent to message loader\n", 
1065                      _dbus_string_get_length (buffer) -
1066                      orig_len);
1067       
1068       _dbus_message_loader_return_buffer (transport->loader,
1069                                           buffer,
1070                                           _dbus_string_get_length (buffer) -
1071                                           orig_len);
1072
1073       _dbus_auth_delete_unused_bytes (transport->auth);
1074       
1075       _dbus_string_free (&plaintext);
1076     }
1077   else
1078     {
1079       const DBusString *bytes;
1080       DBusString *buffer;
1081       int orig_len;
1082       dbus_bool_t succeeded;
1083
1084       _dbus_message_loader_get_buffer (transport->loader,
1085                                        &buffer);
1086                 
1087       orig_len = _dbus_string_get_length (buffer);
1088
1089       _dbus_auth_get_unused_bytes (transport->auth,
1090                                    &bytes);
1091
1092       succeeded = TRUE;
1093       if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
1094         succeeded = FALSE;
1095       
1096       _dbus_verbose (" %d unused bytes sent to message loader\n", 
1097                      _dbus_string_get_length (buffer) -
1098                      orig_len);
1099       
1100       _dbus_message_loader_return_buffer (transport->loader,
1101                                           buffer,
1102                                           _dbus_string_get_length (buffer) -
1103                                           orig_len);
1104
1105       if (succeeded)
1106         _dbus_auth_delete_unused_bytes (transport->auth);
1107       else
1108         goto nomem;
1109     }
1110
1111   return TRUE;
1112
1113  nomem:
1114   _dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
1115   return FALSE;
1116 }
1117
1118 /**
1119  * Reports our current dispatch status (whether there's buffered
1120  * data to be queued as messages, or not, or we need memory).
1121  *
1122  * @param transport the transport
1123  * @returns current status
1124  */
1125 DBusDispatchStatus
1126 _dbus_transport_get_dispatch_status (DBusTransport *transport)
1127 {
1128   if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size ||
1129       _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds)
1130     return DBUS_DISPATCH_COMPLETE; /* complete for now */
1131
1132   if (!_dbus_transport_try_to_authenticate (transport))
1133     {
1134       if (_dbus_auth_do_work (transport->auth) ==
1135           DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
1136         return DBUS_DISPATCH_NEED_MEMORY;
1137       else if (!_dbus_transport_try_to_authenticate (transport))
1138         return DBUS_DISPATCH_COMPLETE;
1139     }
1140
1141   if (!transport->unused_bytes_recovered &&
1142       !recover_unused_bytes (transport))
1143     return DBUS_DISPATCH_NEED_MEMORY;
1144
1145   transport->unused_bytes_recovered = TRUE;
1146   
1147   if (!_dbus_message_loader_queue_messages (transport->loader))
1148     return DBUS_DISPATCH_NEED_MEMORY;
1149
1150   if (_dbus_message_loader_peek_message (transport->loader) != NULL)
1151     return DBUS_DISPATCH_DATA_REMAINS;
1152   else
1153     return DBUS_DISPATCH_COMPLETE;
1154 }
1155
1156 /**
1157  * Processes data we've read while handling a watch, potentially
1158  * converting some of it to messages and queueing those messages on
1159  * the connection.
1160  *
1161  * @param transport the transport
1162  * @returns #TRUE if we had enough memory to queue all messages
1163  */
1164 dbus_bool_t
1165 _dbus_transport_queue_messages (DBusTransport *transport)
1166 {
1167   DBusDispatchStatus status;
1168
1169 #if 0
1170   _dbus_verbose ("_dbus_transport_queue_messages()\n");
1171 #endif
1172   
1173   /* Queue any messages */
1174   while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
1175     {
1176       DBusMessage *message;
1177       DBusList *link;
1178
1179       link = _dbus_message_loader_pop_message_link (transport->loader);
1180       _dbus_assert (link != NULL);
1181       
1182       message = link->data;
1183       
1184       _dbus_verbose ("queueing received message %p\n", message);
1185
1186       if (!_dbus_message_add_counter (message, transport->live_messages))
1187         {
1188           _dbus_message_loader_putback_message_link (transport->loader,
1189                                                      link);
1190           status = DBUS_DISPATCH_NEED_MEMORY;
1191           break;
1192         }
1193       else
1194         {
1195           /* We didn't call the notify function when we added the counter, so
1196            * catch up now. Since we have the connection's lock, it's desirable
1197            * that we bypass the notify function and call this virtual method
1198            * directly. */
1199           if (transport->vtable->live_messages_changed)
1200             (* transport->vtable->live_messages_changed) (transport);
1201
1202           /* pass ownership of link and message ref to connection */
1203           _dbus_connection_queue_received_message_link (transport->connection,
1204                                                         link);
1205         }
1206     }
1207
1208   if (_dbus_message_loader_get_is_corrupted (transport->loader))
1209     {
1210       _dbus_verbose ("Corrupted message stream, disconnecting\n");
1211       _dbus_transport_disconnect (transport);
1212     }
1213
1214   return status != DBUS_DISPATCH_NEED_MEMORY;
1215 }
1216
1217 /**
1218  * See dbus_connection_set_max_message_size().
1219  *
1220  * @param transport the transport
1221  * @param size the max size of a single message
1222  */
1223 void
1224 _dbus_transport_set_max_message_size (DBusTransport  *transport,
1225                                       long            size)
1226 {
1227   _dbus_message_loader_set_max_message_size (transport->loader, size);
1228 }
1229
1230 /**
1231  * See dbus_connection_set_max_message_unix_fds().
1232  *
1233  * @param transport the transport
1234  * @param n the max number of unix fds of a single message
1235  */
1236 void
1237 _dbus_transport_set_max_message_unix_fds (DBusTransport  *transport,
1238                                           long            n)
1239 {
1240   _dbus_message_loader_set_max_message_unix_fds (transport->loader, n);
1241 }
1242
1243 /**
1244  * See dbus_connection_get_max_message_size().
1245  *
1246  * @param transport the transport
1247  * @returns max message size
1248  */
1249 long
1250 _dbus_transport_get_max_message_size (DBusTransport  *transport)
1251 {
1252   return _dbus_message_loader_get_max_message_size (transport->loader);
1253 }
1254
1255 /**
1256  * See dbus_connection_get_max_message_unix_fds().
1257  *
1258  * @param transport the transport
1259  * @returns max message unix fds
1260  */
1261 long
1262 _dbus_transport_get_max_message_unix_fds (DBusTransport  *transport)
1263 {
1264   return _dbus_message_loader_get_max_message_unix_fds (transport->loader);
1265 }
1266
1267 /**
1268  * See dbus_connection_set_max_received_size().
1269  *
1270  * @param transport the transport
1271  * @param size the max size of all incoming messages
1272  */
1273 void
1274 _dbus_transport_set_max_received_size (DBusTransport  *transport,
1275                                        long            size)
1276 {
1277   transport->max_live_messages_size = size;
1278   _dbus_counter_set_notify (transport->live_messages,
1279                             transport->max_live_messages_size,
1280                             transport->max_live_messages_unix_fds,
1281                             live_messages_notify,
1282                             transport);
1283 }
1284
1285 /**
1286  * See dbus_connection_set_max_received_unix_fds().
1287  *
1288  * @param transport the transport
1289  * @param n the max unix fds of all incoming messages
1290  */
1291 void
1292 _dbus_transport_set_max_received_unix_fds (DBusTransport  *transport,
1293                                            long            n)
1294 {
1295   transport->max_live_messages_unix_fds = n;
1296   _dbus_counter_set_notify (transport->live_messages,
1297                             transport->max_live_messages_size,
1298                             transport->max_live_messages_unix_fds,
1299                             live_messages_notify,
1300                             transport);
1301 }
1302
1303 /**
1304  * See dbus_connection_get_max_received_size().
1305  *
1306  * @param transport the transport
1307  * @returns max bytes for all live messages
1308  */
1309 long
1310 _dbus_transport_get_max_received_size (DBusTransport  *transport)
1311 {
1312   return transport->max_live_messages_size;
1313 }
1314
1315 /**
1316  * See dbus_connection_set_max_received_unix_fds().
1317  *
1318  * @param transport the transport
1319  * @returns max unix fds for all live messages
1320  */
1321 long
1322 _dbus_transport_get_max_received_unix_fds (DBusTransport  *transport)
1323 {
1324   return transport->max_live_messages_unix_fds;
1325 }
1326
1327 /**
1328  * See dbus_connection_get_unix_user().
1329  *
1330  * @param transport the transport
1331  * @param uid return location for the user ID
1332  * @returns #TRUE if uid is filled in with a valid user ID
1333  */
1334 dbus_bool_t
1335 _dbus_transport_get_unix_user (DBusTransport *transport,
1336                                unsigned long *uid)
1337 {
1338   DBusCredentials *auth_identity;
1339
1340   *uid = _DBUS_INT32_MAX; /* better than some root or system user in
1341                            * case of bugs in the caller. Caller should
1342                            * never use this value on purpose, however.
1343                            */
1344   
1345   if (!transport->authenticated)
1346     return FALSE;
1347   
1348   auth_identity = _dbus_auth_get_identity (transport->auth);
1349
1350   if (_dbus_credentials_include (auth_identity,
1351                                  DBUS_CREDENTIAL_UNIX_USER_ID))
1352     {
1353       *uid = _dbus_credentials_get_unix_uid (auth_identity);
1354       return TRUE;
1355     }
1356   else
1357     return FALSE;
1358 }
1359
1360 /**
1361  * See dbus_connection_get_unix_process_id().
1362  *
1363  * @param transport the transport
1364  * @param pid return location for the process ID
1365  * @returns #TRUE if uid is filled in with a valid process ID
1366  */
1367 dbus_bool_t
1368 _dbus_transport_get_unix_process_id (DBusTransport *transport,
1369                                      unsigned long *pid)
1370 {
1371   DBusCredentials *auth_identity;
1372
1373   *pid = DBUS_PID_UNSET; /* Caller should never use this value on purpose,
1374                           * but we set it to a safe number, INT_MAX,
1375                           * just to root out possible bugs in bad callers.
1376                           */
1377   
1378   if (!transport->authenticated)
1379     return FALSE;
1380   
1381   auth_identity = _dbus_auth_get_identity (transport->auth);
1382
1383   if (_dbus_credentials_include (auth_identity,
1384                                  DBUS_CREDENTIAL_UNIX_PROCESS_ID))
1385     {
1386       *pid = _dbus_credentials_get_pid (auth_identity);
1387       return TRUE;
1388     }
1389   else
1390     return FALSE;
1391 }
1392
1393 /**
1394  * See dbus_connection_get_adt_audit_session_data().
1395  *
1396  * @param transport the transport
1397  * @param data return location for the ADT audit data 
1398  * @param data_size return length of audit data
1399  * @returns #TRUE if audit data is filled in with a valid ucred
1400  */
1401 dbus_bool_t
1402 _dbus_transport_get_adt_audit_session_data (DBusTransport      *transport,
1403                                             void              **data,
1404                                             int                *data_size)
1405 {
1406   DBusCredentials *auth_identity;
1407
1408   *data = NULL;
1409   *data_size = 0;
1410   
1411   if (!transport->authenticated)
1412     return FALSE;
1413   
1414   auth_identity = _dbus_auth_get_identity (transport->auth);
1415
1416   if (_dbus_credentials_include (auth_identity,
1417                                  DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID))
1418     {
1419       *data = (void *) _dbus_credentials_get_adt_audit_data (auth_identity);
1420       *data_size = _dbus_credentials_get_adt_audit_data_size (auth_identity);
1421       return TRUE;
1422     }
1423   else
1424     return FALSE;
1425 }
1426
1427 /**
1428  * See dbus_connection_set_unix_user_function().
1429  *
1430  * @param transport the transport
1431  * @param function the predicate
1432  * @param data data to pass to the predicate
1433  * @param free_data_function function to free the data
1434  * @param old_data the old user data to be freed
1435  * @param old_free_data_function old free data function to free it with
1436  */
1437 void
1438 _dbus_transport_set_unix_user_function (DBusTransport             *transport,
1439                                         DBusAllowUnixUserFunction  function,
1440                                         void                      *data,
1441                                         DBusFreeFunction           free_data_function,
1442                                         void                     **old_data,
1443                                         DBusFreeFunction          *old_free_data_function)
1444 {  
1445   *old_data = transport->unix_user_data;
1446   *old_free_data_function = transport->free_unix_user_data;
1447
1448   transport->unix_user_function = function;
1449   transport->unix_user_data = data;
1450   transport->free_unix_user_data = free_data_function;
1451 }
1452
1453 /**
1454  * See dbus_connection_get_windows_user().
1455  *
1456  * @param transport the transport
1457  * @param windows_sid_p return location for the user ID
1458  * @returns #TRUE if user is available; the returned value may still be #NULL if no memory to copy it
1459  */
1460 dbus_bool_t
1461 _dbus_transport_get_windows_user (DBusTransport              *transport,
1462                                   char                      **windows_sid_p)
1463 {
1464   DBusCredentials *auth_identity;
1465
1466   *windows_sid_p = NULL;
1467   
1468   if (!transport->authenticated)
1469     return FALSE;
1470   
1471   auth_identity = _dbus_auth_get_identity (transport->auth);
1472
1473   if (_dbus_credentials_include (auth_identity,
1474                                  DBUS_CREDENTIAL_WINDOWS_SID))
1475     {
1476       /* If no memory, we are supposed to return TRUE and set NULL */
1477       *windows_sid_p = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
1478
1479       return TRUE;
1480     }
1481   else
1482     return FALSE;
1483 }
1484
1485 /**
1486  * See dbus_connection_set_windows_user_function().
1487  *
1488  * @param transport the transport
1489  * @param function the predicate
1490  * @param data data to pass to the predicate
1491  * @param free_data_function function to free the data
1492  * @param old_data the old user data to be freed
1493  * @param old_free_data_function old free data function to free it with
1494  */
1495
1496 void
1497 _dbus_transport_set_windows_user_function (DBusTransport              *transport,
1498                                            DBusAllowWindowsUserFunction   function,
1499                                            void                       *data,
1500                                            DBusFreeFunction            free_data_function,
1501                                            void                      **old_data,
1502                                            DBusFreeFunction           *old_free_data_function)
1503 {
1504   *old_data = transport->windows_user_data;
1505   *old_free_data_function = transport->free_windows_user_data;
1506
1507   transport->windows_user_function = function;
1508   transport->windows_user_data = data;
1509   transport->free_windows_user_data = free_data_function;
1510 }
1511
1512 /**
1513  * Sets the SASL authentication mechanisms supported by this transport.
1514  *
1515  * @param transport the transport
1516  * @param mechanisms the #NULL-terminated array of mechanisms
1517  *
1518  * @returns #FALSE if no memory
1519  */
1520 dbus_bool_t
1521 _dbus_transport_set_auth_mechanisms (DBusTransport  *transport,
1522                                      const char    **mechanisms)
1523 {
1524   return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
1525 }
1526
1527 /**
1528  * See dbus_connection_set_allow_anonymous()
1529  *
1530  * @param transport the transport
1531  * @param value #TRUE to allow anonymous connection
1532  */
1533 void
1534 _dbus_transport_set_allow_anonymous (DBusTransport              *transport,
1535                                      dbus_bool_t                 value)
1536 {
1537   transport->allow_anonymous = value != FALSE;
1538 }
1539
1540 #ifdef DBUS_ENABLE_STATS
1541 void
1542 _dbus_transport_get_stats (DBusTransport  *transport,
1543                            dbus_uint32_t  *queue_bytes,
1544                            dbus_uint32_t  *queue_fds,
1545                            dbus_uint32_t  *peak_queue_bytes,
1546                            dbus_uint32_t  *peak_queue_fds)
1547 {
1548   if (queue_bytes != NULL)
1549     *queue_bytes = _dbus_counter_get_size_value (transport->live_messages);
1550
1551   if (queue_fds != NULL)
1552     *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages);
1553
1554   if (peak_queue_bytes != NULL)
1555     *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages);
1556
1557   if (peak_queue_fds != NULL)
1558     *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages);
1559 }
1560 #endif /* DBUS_ENABLE_STATS */
1561
1562 /** @} */