D-Bus 1.15.2
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 *
6 * Licensed under the Academic Free License version 2.1
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#include <config.h>
25#include "dbus-transport-protected.h"
26#include "dbus-transport-unix.h"
27#include "dbus-transport-socket.h"
28#include "dbus-connection-internal.h"
29#include "dbus-watch.h"
30#include "dbus-auth.h"
31#include "dbus-address.h"
32#include "dbus-credentials.h"
33#include "dbus-mainloop.h"
34#include "dbus-message.h"
35#ifdef DBUS_ENABLE_EMBEDDED_TESTS
36#include "dbus-server-debug-pipe.h"
37#endif
38
60static void
61live_messages_notify (DBusCounter *counter,
62 void *user_data)
63{
64 DBusTransport *transport = user_data;
65
67 _dbus_transport_ref (transport);
68
69#if 0
70 _dbus_verbose ("Size counter value is now %d\n",
71 (int) _dbus_counter_get_size_value (counter));
72 _dbus_verbose ("Unix FD counter value is now %d\n",
73 (int) _dbus_counter_get_unix_fd_value (counter));
74#endif
75
76 /* disable or re-enable the read watch for the transport if
77 * required.
78 */
79 if (transport->vtable->live_messages_changed)
80 {
81 (* transport->vtable->live_messages_changed) (transport);
82 }
83
84 _dbus_transport_unref (transport);
86}
87
103 const DBusTransportVTable *vtable,
104 const DBusString *server_guid,
105 const DBusString *address)
106{
107 DBusMessageLoader *loader;
108 DBusAuth *auth;
109 DBusCounter *counter;
110 char *address_copy;
111 DBusCredentials *creds;
112
113 loader = _dbus_message_loader_new ();
114 if (loader == NULL)
115 return FALSE;
116
117 if (server_guid)
118 auth = _dbus_auth_server_new (server_guid);
119 else
120 auth = _dbus_auth_client_new ();
121 if (auth == NULL)
122 {
124 return FALSE;
125 }
126
127 counter = _dbus_counter_new ();
128 if (counter == NULL)
129 {
130 _dbus_auth_unref (auth);
132 return FALSE;
133 }
134
135 creds = _dbus_credentials_new ();
136 if (creds == NULL)
137 {
138 _dbus_counter_unref (counter);
139 _dbus_auth_unref (auth);
141 return FALSE;
142 }
143
144 if (server_guid)
145 {
146 _dbus_assert (address == NULL);
147 address_copy = NULL;
148 }
149 else
150 {
151 _dbus_assert (address != NULL);
152
153 if (!_dbus_string_copy_data (address, &address_copy))
154 {
156 _dbus_counter_unref (counter);
157 _dbus_auth_unref (auth);
159 return FALSE;
160 }
161 }
162
163 transport->refcount = 1;
164 transport->vtable = vtable;
165 transport->loader = loader;
166 transport->auth = auth;
167 transport->live_messages = counter;
168 transport->authenticated = FALSE;
169 transport->disconnected = FALSE;
170 transport->is_server = (server_guid != NULL);
171 transport->send_credentials_pending = !transport->is_server;
172 transport->receive_credentials_pending = transport->is_server;
173 transport->address = address_copy;
174
175 transport->unix_user_function = NULL;
176 transport->unix_user_data = NULL;
177 transport->free_unix_user_data = NULL;
178
179 transport->windows_user_function = NULL;
180 transport->windows_user_data = NULL;
181 transport->free_windows_user_data = NULL;
182
183 transport->expected_guid = NULL;
184
185 /* Try to default to something that won't totally hose the system,
186 * but doesn't impose too much of a limitation.
187 */
188 transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
189
190 /* On Linux RLIMIT_NOFILE defaults to 1024, so allowing 4096 fds live
191 should be more than enough */
192 transport->max_live_messages_unix_fds = 4096;
193
194 /* credentials read from socket if any */
195 transport->credentials = creds;
196
198 transport->max_live_messages_size,
200 live_messages_notify,
201 transport);
202
203 if (transport->address)
204 _dbus_verbose ("Initialized transport on address %s\n", transport->address);
205
206 return TRUE;
207}
208
215void
217{
218 if (!transport->disconnected)
219 _dbus_transport_disconnect (transport);
220
221 if (transport->free_unix_user_data != NULL)
222 (* transport->free_unix_user_data) (transport->unix_user_data);
223
224 if (transport->free_windows_user_data != NULL)
225 (* transport->free_windows_user_data) (transport->windows_user_data);
226
228 _dbus_auth_unref (transport->auth);
230 0, 0, NULL, NULL);
232 dbus_free (transport->address);
233 dbus_free (transport->expected_guid);
234 if (transport->credentials)
236}
237
238
249static DBusTransport*
250check_address (const char *address, DBusError *error)
251{
252 DBusAddressEntry **entries;
253 DBusTransport *transport = NULL;
254 int len, i;
255
256 _dbus_assert (address != NULL);
257 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
258
259 if (!dbus_parse_address (address, &entries, &len, error))
260 return NULL; /* not a valid address */
261
262 for (i = 0; i < len; i++)
263 {
264 dbus_error_free (error);
265 transport = _dbus_transport_open (entries[i], error);
266
267 if (transport != NULL)
268 break;
269 }
270
272 return transport;
273}
274
283static DBusTransport*
284_dbus_transport_new_for_autolaunch (const char *scope, DBusError *error)
285{
286 DBusString address;
287 DBusTransport *result = NULL;
288
289 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
290
291 if (!_dbus_string_init (&address))
292 {
294 return NULL;
295 }
296
297 if (!_dbus_get_autolaunch_address (scope, &address, error))
298 {
299 _DBUS_ASSERT_ERROR_IS_SET (error);
300 goto out;
301 }
302
303 result = check_address (_dbus_string_get_const_data (&address), error);
304 _DBUS_ASSERT_ERROR_XOR_BOOL (error, result != NULL);
305
306 out:
307 _dbus_string_free (&address);
308 return result;
309}
310
311static DBusTransportOpenResult
312_dbus_transport_open_autolaunch (DBusAddressEntry *entry,
313 DBusTransport **transport_p,
314 DBusError *error)
315{
316 const char *method;
317
318 method = dbus_address_entry_get_method (entry);
319 _dbus_assert (method != NULL);
320
321 if (strcmp (method, "autolaunch") == 0)
322 {
323 const char *scope = dbus_address_entry_get_value (entry, "scope");
324
325 *transport_p = _dbus_transport_new_for_autolaunch (scope, error);
326
327 if (*transport_p == NULL)
328 {
329 _DBUS_ASSERT_ERROR_IS_SET (error);
330 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
331 }
332 else
333 {
334 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
335 return DBUS_TRANSPORT_OPEN_OK;
336 }
337 }
338 else
339 {
340 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
341 return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
342 }
343}
344
345static const struct {
346 DBusTransportOpenResult (* func) (DBusAddressEntry *entry,
347 DBusTransport **transport_p,
348 DBusError *error);
349} open_funcs[] = {
352#ifndef _WIN32
353 { _dbus_transport_open_unixexec },
354#endif
356 { _dbus_transport_open_autolaunch }
357#ifdef DBUS_ENABLE_EMBEDDED_TESTS
358 , { _dbus_transport_open_debug_pipe }
359#endif
360};
361
372 DBusError *error)
373{
374 DBusTransport *transport;
375 const char *expected_guid_orig;
376 char *expected_guid;
377 int i;
378 DBusError tmp_error = DBUS_ERROR_INIT;
379
380 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
381
382 transport = NULL;
383 expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
384 expected_guid = _dbus_strdup (expected_guid_orig);
385
386 if (expected_guid_orig != NULL && expected_guid == NULL)
387 {
388 _DBUS_SET_OOM (error);
389 return NULL;
390 }
391
392 for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
393 {
394 DBusTransportOpenResult result;
395
396 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
397 result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
398
399 switch (result)
400 {
401 case DBUS_TRANSPORT_OPEN_OK:
402 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
403 goto out;
404 break;
405 case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
406 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
407 /* keep going through the loop of open funcs */
408 break;
409 case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
410 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
411 goto out;
412 break;
413 case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
414 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
415 goto out;
416 break;
417 default:
418 _dbus_assert_not_reached ("invalid transport open result");
419 break;
420 }
421 }
422
423 out:
424
425 if (transport == NULL)
426 {
427 if (!dbus_error_is_set (&tmp_error))
428 _dbus_set_bad_address (&tmp_error,
429 NULL, NULL,
430 "Unknown address type (examples of valid types are \"tcp\" and on UNIX \"unix\")");
431
432 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
433 dbus_move_error(&tmp_error, error);
434 dbus_free (expected_guid);
435 }
436 else
437 {
438 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
439
440 /* In the case of autostart the initial guid is NULL
441 * and the autostart transport recursively calls
442 * _dbus_open_transport wich returns a transport
443 * with a guid. That guid is the definitive one.
444 *
445 * FIXME: if more transports are added they may have
446 * an effect on the expected_guid semantics (i.e.
447 * expected_guid and transport->expected_guid may
448 * both have values). This is very unlikely though
449 * we should either throw asserts here for those
450 * corner cases or refactor the code so it is
451 * clearer on what is expected and what is not
452 */
453 if(expected_guid)
454 transport->expected_guid = expected_guid;
455 }
456
457 return transport;
458}
459
468{
469 _dbus_assert (transport->refcount > 0);
470
471 transport->refcount += 1;
472
473 return transport;
474}
475
483void
485{
486 _dbus_assert (transport != NULL);
487 _dbus_assert (transport->refcount > 0);
488
489 transport->refcount -= 1;
490 if (transport->refcount == 0)
491 {
492 _dbus_verbose ("finalizing\n");
493
494 _dbus_assert (transport->vtable->finalize != NULL);
495
496 (* transport->vtable->finalize) (transport);
497 }
498}
499
508void
510{
511 _dbus_verbose ("start\n");
512
513 _dbus_assert (transport->vtable->disconnect != NULL);
514
515 if (transport->disconnected)
516 return;
517
518 (* transport->vtable->disconnect) (transport);
519
520 transport->disconnected = TRUE;
521
522 _dbus_verbose ("end\n");
523}
524
535{
536 return !transport->disconnected;
537}
538
539static dbus_bool_t
540auth_via_unix_user_function (DBusTransport *transport)
541{
542 DBusCredentials *auth_identity;
543 dbus_bool_t allow;
544 DBusConnection *connection;
545 DBusAllowUnixUserFunction unix_user_function;
546 void *unix_user_data;
547 dbus_uid_t uid;
548
549 /* Dropping the lock here probably isn't that safe. */
550
551 auth_identity = _dbus_auth_get_identity (transport->auth);
552 _dbus_assert (auth_identity != NULL);
553
554 connection = transport->connection;
555 unix_user_function = transport->unix_user_function;
556 unix_user_data = transport->unix_user_data;
557 uid = _dbus_credentials_get_unix_uid (auth_identity);
558
559 _dbus_verbose ("unlock\n");
560 _dbus_connection_unlock (connection);
561
562 allow = (* unix_user_function) (connection,
563 uid,
564 unix_user_data);
565
566 _dbus_verbose ("lock post unix user function\n");
567 _dbus_connection_lock (connection);
568
569 if (allow)
570 {
571 _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", uid);
572 }
573 else
574 {
575 _dbus_verbose ("Client UID "DBUS_UID_FORMAT
576 " was rejected, disconnecting\n",
577 _dbus_credentials_get_unix_uid (auth_identity));
578 _dbus_transport_disconnect (transport);
579 }
580
581 return allow;
582}
583
584static dbus_bool_t
585auth_via_windows_user_function (DBusTransport *transport)
586{
587 DBusCredentials *auth_identity;
588 dbus_bool_t allow;
589 DBusConnection *connection;
590 DBusAllowWindowsUserFunction windows_user_function;
591 void *windows_user_data;
592 char *windows_sid;
593
594 /* Dropping the lock here probably isn't that safe. */
595
596 auth_identity = _dbus_auth_get_identity (transport->auth);
597 _dbus_assert (auth_identity != NULL);
598
599 connection = transport->connection;
600 windows_user_function = transport->windows_user_function;
601 windows_user_data = transport->unix_user_data;
602 windows_sid = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
603
604 if (windows_sid == NULL)
605 {
606 /* OOM */
607 return FALSE;
608 }
609
610 _dbus_verbose ("unlock\n");
611 _dbus_connection_unlock (connection);
612
613 allow = (* windows_user_function) (connection,
614 windows_sid,
615 windows_user_data);
616
617 _dbus_verbose ("lock post windows user function\n");
618 _dbus_connection_lock (connection);
619
620 if (allow)
621 {
622 _dbus_verbose ("Client SID '%s' authorized\n", windows_sid);
623 }
624 else
625 {
626 _dbus_verbose ("Client SID '%s' was rejected, disconnecting\n",
627 _dbus_credentials_get_windows_sid (auth_identity));
628 _dbus_transport_disconnect (transport);
629 }
630
631 return allow;
632}
633
634static dbus_bool_t
635auth_via_default_rules (DBusTransport *transport)
636{
637 DBusCredentials *auth_identity;
638 DBusCredentials *our_identity;
639 dbus_bool_t allow;
640
641 auth_identity = _dbus_auth_get_identity (transport->auth);
642 _dbus_assert (auth_identity != NULL);
643
644 /* By default, connection is allowed if the client is 1) root or 2)
645 * has the same UID as us or 3) anonymous is allowed.
646 */
647
649 if (our_identity == NULL)
650 {
651 /* OOM */
652 return FALSE;
653 }
654
655 if (transport->allow_anonymous ||
656 _dbus_credentials_get_unix_uid (auth_identity) == 0 ||
657 _dbus_credentials_same_user (our_identity,
658 auth_identity))
659 {
660 if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
661 _dbus_verbose ("Client authorized as SID '%s'"
662 "matching our SID '%s'\n",
665 else
666 _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
667 " matching our UID "DBUS_UID_FORMAT"\n",
668 _dbus_credentials_get_unix_uid(auth_identity),
669 _dbus_credentials_get_unix_uid(our_identity));
670 /* We have authenticated! */
671 allow = TRUE;
672 }
673 else
674 {
675 if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
676 _dbus_verbose ("Client authorized as SID '%s'"
677 " but our SID is '%s', disconnecting\n",
678 (_dbus_credentials_get_windows_sid(auth_identity) ?
679 _dbus_credentials_get_windows_sid(auth_identity) : "<null>"),
680 (_dbus_credentials_get_windows_sid(our_identity) ?
681 _dbus_credentials_get_windows_sid(our_identity) : "<null>"));
682 else
683 _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
684 " but our UID is "DBUS_UID_FORMAT", disconnecting\n",
685 _dbus_credentials_get_unix_uid(auth_identity),
686 _dbus_credentials_get_unix_uid(our_identity));
687 _dbus_transport_disconnect (transport);
688 allow = FALSE;
689 }
690
691 _dbus_credentials_unref (our_identity);
692
693 return allow;
694}
695
709{
710 return transport->authenticated;
711}
712
732{
733 if (transport->authenticated)
734 return TRUE;
735 else
736 {
737 dbus_bool_t maybe_authenticated;
738
739 if (transport->disconnected)
740 return FALSE;
741
742 /* paranoia ref since we call user callbacks sometimes */
744
745 maybe_authenticated =
746 (!(transport->send_credentials_pending ||
747 transport->receive_credentials_pending));
748
749 if (maybe_authenticated)
750 {
751 switch (_dbus_auth_do_work (transport->auth))
752 {
753 case DBUS_AUTH_STATE_AUTHENTICATED:
754 /* leave as maybe_authenticated */
755 break;
756
757 case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
758 case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
759 case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
760 case DBUS_AUTH_STATE_NEED_DISCONNECT:
761 maybe_authenticated = FALSE;
762 break;
763
764 case DBUS_AUTH_STATE_INVALID:
765 default:
766 _dbus_assert_not_reached ("invalid authentication state");
767 }
768 }
769
770 /* If we're the client, verify the GUID
771 */
772 if (maybe_authenticated && !transport->is_server)
773 {
774 const char *server_guid;
775
776 server_guid = _dbus_auth_get_guid_from_server (transport->auth);
777 _dbus_assert (server_guid != NULL);
778
779 if (transport->expected_guid &&
780 strcmp (transport->expected_guid, server_guid) != 0)
781 {
782 _dbus_verbose ("Client expected GUID '%s' and we got '%s' from the server\n",
783 transport->expected_guid, server_guid);
784 _dbus_transport_disconnect (transport);
786 return FALSE;
787 }
788 }
789
790 /* If we're the server, see if we want to allow this identity to proceed.
791 */
792 if (maybe_authenticated && transport->is_server)
793 {
794 dbus_bool_t allow;
795 DBusCredentials *auth_identity;
796
797 auth_identity = _dbus_auth_get_identity (transport->auth);
798 _dbus_assert (auth_identity != NULL);
799
800 /* If we have an auth'd user and a user function, delegate
801 * deciding whether auth credentials are good enough to the
802 * app; otherwise, use our default decision process.
803 */
804 if (transport->unix_user_function != NULL &&
805 _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_UNIX_USER_ID))
806 {
807 allow = auth_via_unix_user_function (transport);
808 }
809 else if (transport->windows_user_function != NULL &&
810 _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_WINDOWS_SID))
811 {
812 allow = auth_via_windows_user_function (transport);
813 }
814 else
815 {
816 allow = auth_via_default_rules (transport);
817 }
818
819 if (!allow)
820 maybe_authenticated = FALSE;
821 }
822
823 transport->authenticated = maybe_authenticated;
824
826 return maybe_authenticated;
827 }
828}
829
838{
839 DBusCredentials *auth_identity;
840
841 if (!transport->authenticated)
842 return TRUE;
843
844 auth_identity = _dbus_auth_get_identity (transport->auth);
845
846 if (_dbus_credentials_are_anonymous (auth_identity))
847 return TRUE;
848 else
849 return FALSE;
850}
851
860{
861 return DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport);
862}
863
871const char*
873{
874 return transport->address;
875}
876
884const char*
886{
887 if (transport->is_server)
888 return NULL;
889 else if (transport->authenticated)
890 return _dbus_auth_get_guid_from_server (transport->auth);
891 else
892 return transport->expected_guid;
893}
894
906 DBusWatch *watch,
907 unsigned int condition)
908{
909 dbus_bool_t retval;
910
911 _dbus_assert (transport->vtable->handle_watch != NULL);
912
913 if (transport->disconnected)
914 return TRUE;
915
916 if (dbus_watch_get_socket (watch) < 0)
917 {
918 _dbus_warn_check_failed ("Tried to handle an invalidated watch; this watch should have been removed");
919 return TRUE;
920 }
921
922 _dbus_watch_sanitize_condition (watch, &condition);
923
924 _dbus_transport_ref (transport);
925 _dbus_watch_ref (watch);
926 retval = (* transport->vtable->handle_watch) (transport, watch, condition);
927 _dbus_watch_unref (watch);
928 _dbus_transport_unref (transport);
929
930 return retval;
931}
932
944 DBusConnection *connection)
945{
946 _dbus_assert (transport->vtable->connection_set != NULL);
947 _dbus_assert (transport->connection == NULL);
948
949 transport->connection = connection;
950
951 _dbus_transport_ref (transport);
952 if (!(* transport->vtable->connection_set) (transport))
953 transport->connection = NULL;
954 _dbus_transport_unref (transport);
955
956 return transport->connection != NULL;
957}
958
968 DBusSocket *fd_p)
969{
970 dbus_bool_t retval;
971
972 if (transport->vtable->get_socket_fd == NULL)
973 return FALSE;
974
975 if (transport->disconnected)
976 return FALSE;
977
978 _dbus_transport_ref (transport);
979
980 retval = (* transport->vtable->get_socket_fd) (transport,
981 fd_p);
982
983 _dbus_transport_unref (transport);
984
985 return retval;
986}
987
999void
1001 unsigned int flags,
1002 int timeout_milliseconds)
1003{
1004 _dbus_assert (transport->vtable->do_iteration != NULL);
1005
1006 _dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
1007 flags, timeout_milliseconds, !transport->disconnected);
1008
1009 if ((flags & (DBUS_ITERATION_DO_WRITING |
1010 DBUS_ITERATION_DO_READING)) == 0)
1011 return; /* Nothing to do */
1012
1013 if (transport->disconnected)
1014 return;
1015
1016 _dbus_transport_ref (transport);
1017 (* transport->vtable->do_iteration) (transport, flags,
1018 timeout_milliseconds);
1019 _dbus_transport_unref (transport);
1020
1021 _dbus_verbose ("end\n");
1022}
1023
1024static dbus_bool_t
1025recover_unused_bytes (DBusTransport *transport)
1026{
1027 if (_dbus_auth_needs_decoding (transport->auth))
1028 {
1029 DBusString plaintext;
1030 const DBusString *encoded;
1031 DBusString *buffer;
1032 int orig_len;
1033
1034 if (!_dbus_string_init (&plaintext))
1035 goto nomem;
1036
1038 &encoded);
1039
1040 if (!_dbus_auth_decode_data (transport->auth,
1041 encoded, &plaintext))
1042 {
1043 _dbus_string_free (&plaintext);
1044 goto nomem;
1045 }
1046
1048 &buffer,
1049 NULL,
1050 NULL);
1051
1052 orig_len = _dbus_string_get_length (buffer);
1053
1054 if (!_dbus_string_move (&plaintext, 0, buffer,
1055 orig_len))
1056 {
1057 _dbus_string_free (&plaintext);
1058 goto nomem;
1059 }
1060
1061 _dbus_verbose (" %d unused bytes sent to message loader\n",
1062 _dbus_string_get_length (buffer) -
1063 orig_len);
1064
1066 buffer);
1067
1069
1070 _dbus_string_free (&plaintext);
1071 }
1072 else
1073 {
1074 const DBusString *bytes;
1075 DBusString *buffer;
1076#ifdef DBUS_ENABLE_VERBOSE_MODE
1077 int orig_len;
1078#endif
1079 dbus_bool_t succeeded;
1080
1082 &buffer,
1083 NULL,
1084 NULL);
1085
1086#ifdef DBUS_ENABLE_VERBOSE_MODE
1087 orig_len = _dbus_string_get_length (buffer);
1088#endif
1089
1091 &bytes);
1092
1093 succeeded = TRUE;
1094 if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
1095 succeeded = FALSE;
1096
1097 _dbus_verbose (" %d unused bytes sent to message loader\n",
1098 _dbus_string_get_length (buffer) -
1099 orig_len);
1100
1102 buffer);
1103
1104 if (succeeded)
1106 else
1107 goto nomem;
1108 }
1109
1110 return TRUE;
1111
1112 nomem:
1113 _dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
1114 return FALSE;
1115}
1116
1126{
1127 if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size ||
1129 return DBUS_DISPATCH_COMPLETE; /* complete for now */
1130
1131 if (!_dbus_transport_try_to_authenticate (transport))
1132 {
1133 if (_dbus_auth_do_work (transport->auth) ==
1134 DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
1136 else if (!_dbus_transport_try_to_authenticate (transport))
1138 }
1139
1140 if (!transport->unused_bytes_recovered &&
1141 !recover_unused_bytes (transport))
1143
1144 transport->unused_bytes_recovered = TRUE;
1145
1148
1149 if (_dbus_message_loader_peek_message (transport->loader) != NULL)
1151 else
1153}
1154
1165{
1166 DBusDispatchStatus status;
1167
1168#if 0
1169 _dbus_verbose ("enter\n");
1170#endif
1171
1172 /* Queue any messages */
1173 while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
1174 {
1175 DBusMessage *message;
1176 DBusList *link;
1177
1179 _dbus_assert (link != NULL);
1180
1181 message = link->data;
1182
1183 _dbus_verbose ("queueing received message %p\n", message);
1184
1185 if (!_dbus_message_add_counter (message, transport->live_messages))
1186 {
1188 link);
1190 break;
1191 }
1192 else
1193 {
1194 /* We didn't call the notify function when we added the counter, so
1195 * catch up now. Since we have the connection's lock, it's desirable
1196 * that we bypass the notify function and call this virtual method
1197 * directly. */
1198 if (transport->vtable->live_messages_changed)
1199 (* transport->vtable->live_messages_changed) (transport);
1200
1201 /* pass ownership of link and message ref to connection */
1203 link);
1204 }
1205 }
1206
1208 {
1209 _dbus_verbose ("Corrupted message stream, disconnecting\n");
1210 _dbus_transport_disconnect (transport);
1211 }
1212
1213 return status != DBUS_DISPATCH_NEED_MEMORY;
1214}
1215
1222void
1224 long size)
1225{
1227}
1228
1235void
1237 long n)
1238{
1240}
1241
1248long
1250{
1252}
1253
1260long
1262{
1264}
1265
1272void
1274 long size)
1275{
1276 transport->max_live_messages_size = size;
1278 transport->max_live_messages_size,
1279 transport->max_live_messages_unix_fds,
1280 live_messages_notify,
1281 transport);
1282}
1283
1290void
1292 long n)
1293{
1294 transport->max_live_messages_unix_fds = n;
1296 transport->max_live_messages_size,
1297 transport->max_live_messages_unix_fds,
1298 live_messages_notify,
1299 transport);
1300}
1301
1308long
1310{
1311 return transport->max_live_messages_size;
1312}
1313
1320long
1322{
1323 return transport->max_live_messages_unix_fds;
1324}
1325
1335 unsigned long *uid)
1336{
1337 DBusCredentials *auth_identity;
1338
1339 *uid = _DBUS_INT32_MAX; /* better than some root or system user in
1340 * case of bugs in the caller. Caller should
1341 * never use this value on purpose, however.
1342 */
1343
1344 if (!transport->authenticated)
1345 return FALSE;
1346
1347 auth_identity = _dbus_auth_get_identity (transport->auth);
1348
1349 if (_dbus_credentials_include (auth_identity,
1350 DBUS_CREDENTIAL_UNIX_USER_ID))
1351 {
1352 *uid = _dbus_credentials_get_unix_uid (auth_identity);
1353 return TRUE;
1354 }
1355 else
1356 return FALSE;
1357}
1358
1368 unsigned long *pid)
1369{
1370 DBusCredentials *auth_identity;
1371
1372 *pid = DBUS_PID_UNSET; /* Caller should never use this value on purpose,
1373 * but we set it to a safe number, INT_MAX,
1374 * just to root out possible bugs in bad callers.
1375 */
1376
1377 if (!transport->authenticated)
1378 return FALSE;
1379
1380 auth_identity = _dbus_auth_get_identity (transport->auth);
1381
1382 if (_dbus_credentials_include (auth_identity,
1383 DBUS_CREDENTIAL_UNIX_PROCESS_ID))
1384 {
1385 *pid = _dbus_credentials_get_pid (auth_identity);
1386 return TRUE;
1387 }
1388 else
1389 return FALSE;
1390}
1391
1402 void **data,
1403 int *data_size)
1404{
1405 DBusCredentials *auth_identity;
1406
1407 *data = NULL;
1408 *data_size = 0;
1409
1410 if (!transport->authenticated)
1411 return FALSE;
1412
1413 auth_identity = _dbus_auth_get_identity (transport->auth);
1414
1415 if (_dbus_credentials_include (auth_identity,
1416 DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID))
1417 {
1418 *data = (void *) _dbus_credentials_get_adt_audit_data (auth_identity);
1419 *data_size = _dbus_credentials_get_adt_audit_data_size (auth_identity);
1420 return TRUE;
1421 }
1422 else
1423 return FALSE;
1424}
1425
1436void
1439 void *data,
1440 DBusFreeFunction free_data_function,
1441 void **old_data,
1442 DBusFreeFunction *old_free_data_function)
1443{
1444 *old_data = transport->unix_user_data;
1445 *old_free_data_function = transport->free_unix_user_data;
1446
1447 transport->unix_user_function = function;
1448 transport->unix_user_data = data;
1449 transport->free_unix_user_data = free_data_function;
1450}
1451
1453_dbus_transport_get_linux_security_label (DBusTransport *transport,
1454 char **label_p)
1455{
1456 DBusCredentials *auth_identity;
1457
1458 *label_p = NULL;
1459
1460 if (!transport->authenticated)
1461 return FALSE;
1462
1463 auth_identity = _dbus_auth_get_identity (transport->auth);
1464
1465 if (_dbus_credentials_include (auth_identity,
1466 DBUS_CREDENTIAL_LINUX_SECURITY_LABEL))
1467 {
1468 /* If no memory, we are supposed to return TRUE and set NULL */
1469 *label_p = _dbus_strdup (_dbus_credentials_get_linux_security_label (auth_identity));
1470
1471 return TRUE;
1472 }
1473 else
1474 {
1475 return FALSE;
1476 }
1477}
1478
1488{
1489 if (!transport->authenticated)
1490 return FALSE;
1491
1492 return _dbus_auth_get_identity (transport->auth);
1493}
1494
1504 char **windows_sid_p)
1505{
1506 DBusCredentials *auth_identity;
1507
1508 *windows_sid_p = NULL;
1509
1510 if (!transport->authenticated)
1511 return FALSE;
1512
1513 auth_identity = _dbus_auth_get_identity (transport->auth);
1514
1515 if (_dbus_credentials_include (auth_identity,
1516 DBUS_CREDENTIAL_WINDOWS_SID))
1517 {
1518 /* If no memory, we are supposed to return TRUE and set NULL */
1519 *windows_sid_p = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
1520
1521 return TRUE;
1522 }
1523 else
1524 return FALSE;
1525}
1526
1538void
1541 void *data,
1542 DBusFreeFunction free_data_function,
1543 void **old_data,
1544 DBusFreeFunction *old_free_data_function)
1545{
1546 *old_data = transport->windows_user_data;
1547 *old_free_data_function = transport->free_windows_user_data;
1548
1549 transport->windows_user_function = function;
1550 transport->windows_user_data = data;
1551 transport->free_windows_user_data = free_data_function;
1552}
1553
1564 const char **mechanisms)
1565{
1566 return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
1567}
1568
1575void
1577 dbus_bool_t value)
1578{
1579 transport->allow_anonymous = value != FALSE;
1580}
1581
1587int
1589{
1591}
1592
1600void
1602 void (* callback) (void *),
1603 void *data)
1604{
1606 callback, data);
1607}
1608
1609#ifdef DBUS_ENABLE_STATS
1610void
1611_dbus_transport_get_stats (DBusTransport *transport,
1612 dbus_uint32_t *queue_bytes,
1613 dbus_uint32_t *queue_fds,
1614 dbus_uint32_t *peak_queue_bytes,
1615 dbus_uint32_t *peak_queue_fds)
1616{
1617 if (queue_bytes != NULL)
1618 *queue_bytes = _dbus_counter_get_size_value (transport->live_messages);
1619
1620 if (queue_fds != NULL)
1621 *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages);
1622
1623 if (peak_queue_bytes != NULL)
1624 *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages);
1625
1626 if (peak_queue_fds != NULL)
1627 *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages);
1628}
1629#endif /* DBUS_ENABLE_STATS */
1630
void _dbus_set_bad_address(DBusError *error, const char *address_problem_type, const char *address_problem_field, const char *address_problem_other)
Sets DBUS_ERROR_BAD_ADDRESS.
Definition: dbus-address.c:68
void dbus_address_entries_free(DBusAddressEntry **entries)
Frees a NULL-terminated array of address entries.
Definition: dbus-address.c:192
dbus_bool_t dbus_parse_address(const char *address, DBusAddressEntry ***entry_result, int *array_len, DBusError *error)
Parses an address string of the form:
Definition: dbus-address.c:366
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
Definition: dbus-address.c:230
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
Definition: dbus-address.c:247
DBusAuthState _dbus_auth_do_work(DBusAuth *auth)
Analyzes buffered input and moves the auth conversation forward, returning the new state of the auth ...
Definition: dbus-auth.c:2538
DBusCredentials * _dbus_auth_get_identity(DBusAuth *auth)
Gets the identity we authorized the client as.
Definition: dbus-auth.c:2838
dbus_bool_t _dbus_auth_decode_data(DBusAuth *auth, const DBusString *encoded, DBusString *plaintext)
Called post-authentication, decodes a block of bytes received from the peer.
Definition: dbus-auth.c:2788
void _dbus_auth_unref(DBusAuth *auth)
Decrements the refcount of an auth object.
Definition: dbus-auth.c:2453
dbus_bool_t _dbus_auth_set_mechanisms(DBusAuth *auth, const char **mechanisms)
Sets an array of authentication mechanism names that we are willing to use.
Definition: dbus-auth.c:2503
void _dbus_auth_delete_unused_bytes(DBusAuth *auth)
Gets rid of unused bytes returned by _dbus_auth_get_unused_bytes() after we've gotten them and succes...
Definition: dbus-auth.c:2681
const char * _dbus_auth_get_guid_from_server(DBusAuth *auth)
Gets the GUID from the server if we've authenticated; gets NULL otherwise.
Definition: dbus-auth.c:2862
dbus_bool_t _dbus_auth_needs_decoding(DBusAuth *auth)
Called post-authentication, indicates whether we need to decode the message stream with _dbus_auth_de...
Definition: dbus-auth.c:2757
DBusAuth * _dbus_auth_client_new(void)
Creates a new auth conversation object for the client side.
Definition: dbus-auth.c:2400
DBusAuth * _dbus_auth_server_new(const DBusString *guid)
Creates a new auth conversation object for the server side.
Definition: dbus-auth.c:2354
void _dbus_auth_get_unused_bytes(DBusAuth *auth, const DBusString **str)
Returns leftover bytes that were not used as part of the auth conversation.
Definition: dbus-auth.c:2664
DBUS_PRIVATE_EXPORT void _dbus_connection_unlock(DBusConnection *connection)
Releases the connection lock.
DBUS_PRIVATE_EXPORT void _dbus_connection_lock(DBusConnection *connection)
Acquires the connection lock.
DBUS_PRIVATE_EXPORT void _dbus_connection_unref_unlocked(DBusConnection *connection)
Decrements the reference count of a DBusConnection.
void _dbus_connection_queue_received_message_link(DBusConnection *connection, DBusList *link)
Adds a message-containing list link to the incoming message queue, taking ownership of the link and t...
DBUS_PRIVATE_EXPORT DBusConnection * _dbus_connection_ref_unlocked(DBusConnection *connection)
Increments the reference count of a DBusConnection.
dbus_bool_t(* DBusAllowUnixUserFunction)(DBusConnection *connection, unsigned long uid, void *data)
Called during authentication to check whether the given UNIX user ID is allowed to connect,...
DBusDispatchStatus
Indicates the status of incoming data on a DBusConnection.
dbus_bool_t(* DBusAllowWindowsUserFunction)(DBusConnection *connection, const char *user_sid, void *data)
Called during authentication to check whether the given Windows user ID is allowed to connect,...
@ DBUS_DISPATCH_NEED_MEMORY
More memory is needed to continue.
@ DBUS_DISPATCH_COMPLETE
All currently available data has been processed.
@ DBUS_DISPATCH_DATA_REMAINS
There is more data to potentially convert to messages.
dbus_bool_t _dbus_credentials_include(DBusCredentials *credentials, DBusCredentialType type)
Checks whether the given credential is present.
dbus_bool_t _dbus_credentials_same_user(DBusCredentials *credentials, DBusCredentials *other_credentials)
Check whether the user-identifying credentials in two credentials objects are identical.
dbus_uid_t _dbus_credentials_get_unix_uid(DBusCredentials *credentials)
Gets the UNIX user ID in the credentials, or DBUS_UID_UNSET if the credentials object doesn't contain...
DBusCredentials * _dbus_credentials_new_from_current_process(void)
Creates a new object with the most important credentials (user ID and process ID) from the current pr...
DBusCredentials * _dbus_credentials_new(void)
Creates a new credentials object.
void * _dbus_credentials_get_adt_audit_data(DBusCredentials *credentials)
Gets the ADT audit data in the credentials, or NULL if the credentials object doesn't contain ADT aud...
const char * _dbus_credentials_get_linux_security_label(DBusCredentials *credentials)
Gets the Linux security label (as used by LSMs) from the credentials, or NULL if the credentials obje...
void _dbus_credentials_unref(DBusCredentials *credentials)
Decrement refcount on credentials.
dbus_pid_t _dbus_credentials_get_pid(DBusCredentials *credentials)
Gets the UNIX process ID in the credentials, or DBUS_PID_UNSET if the credentials object doesn't cont...
dbus_int32_t _dbus_credentials_get_adt_audit_data_size(DBusCredentials *credentials)
Gets the ADT audit data size in the credentials, or 0 if the credentials object doesn't contain ADT a...
const char * _dbus_credentials_get_windows_sid(DBusCredentials *credentials)
Gets the Windows user SID in the credentials, or NULL if the credentials object doesn't contain a Win...
dbus_bool_t _dbus_credentials_are_anonymous(DBusCredentials *credentials)
Checks whether a credentials object contains a user identity.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:279
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
char * _dbus_strdup(const char *str)
Duplicates a string.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
#define _DBUS_INT32_MAX
Maximum value of type "int32".
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
Definition: dbus-memory.h:63
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:692
void _dbus_message_loader_set_max_message_size(DBusMessageLoader *loader, long size)
Sets the maximum size message we allow.
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_unref(DBusMessageLoader *loader)
Decrements the reference count of the loader and finalizes the loader when the count reaches zero.
void _dbus_message_loader_set_pending_fds_function(DBusMessageLoader *loader, void(*callback)(void *), void *data)
Register a function to be called whenever the number of pending file descriptors in the loader change...
void _dbus_message_loader_putback_message_link(DBusMessageLoader *loader, DBusList *link)
Returns a popped message link, used to undo a pop.
int _dbus_message_loader_get_pending_fds_count(DBusMessageLoader *loader)
Return how many file descriptors are pending in the loader.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer, int *max_to_read, dbus_bool_t *may_read_unix_fds)
Gets the buffer to use for reading data from the network.
dbus_bool_t _dbus_message_add_counter(DBusMessage *message, DBusCounter *counter)
Adds a counter to be incremented immediately with the size/unix fds of this message,...
Definition: dbus-message.c:374
DBusMessage * _dbus_message_loader_peek_message(DBusMessageLoader *loader)
Peeks at first loaded message, returns NULL if no messages have been queued.
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader, long n)
Sets the maximum unix fds per message we allow.
DBUS_PRIVATE_EXPORT long _dbus_message_loader_get_max_message_size(DBusMessageLoader *loader)
Gets the maximum allowed message size in bytes.
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
DBusList * _dbus_message_loader_pop_message_link(DBusMessageLoader *loader)
Pops a loaded message inside a list link (passing ownership of the message and link to the caller).
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_return_buffer(DBusMessageLoader *loader, DBusString *buffer)
Returns a buffer obtained from _dbus_message_loader_get_buffer(), indicating to the loader how many b...
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader)
Gets the maximum allowed number of unix fds per message.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
void _dbus_counter_set_notify(DBusCounter *counter, long size_guard_value, long unix_fd_guard_value, DBusCounterNotifyFunction function, void *user_data)
Sets the notify function for this counter; the notify function is called whenever the counter's value...
DBusCounter * _dbus_counter_new(void)
Creates a new DBusCounter.
long _dbus_counter_get_unix_fd_value(DBusCounter *counter)
Gets the current value of the unix fd counter.
void _dbus_counter_unref(DBusCounter *counter)
Decrements refcount of the counter and possibly finalizes the counter.
long _dbus_counter_get_size_value(DBusCounter *counter)
Gets the current value of the size counter.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:180
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...
Definition: dbus-string.c:1343
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:276
dbus_bool_t _dbus_string_copy_data(const DBusString *str, char **data_return)
Copies the data from the string into a char*.
Definition: dbus-string.c:715
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
Definition: dbus-string.c:782
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
Definition: dbus-string.c:511
dbus_bool_t _dbus_string_move(DBusString *source, int start, DBusString *dest, int insert_at)
Moves the end of one string into another string.
Definition: dbus-string.c:1319
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:135
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
Definition: dbus-sysdeps.h:140
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
Definition: dbus-sysdeps.h:149
dbus_bool_t _dbus_get_autolaunch_address(const char *scope, DBusString *address, DBusError *error)
Returns the address of a new session bus.
DBusTransportOpenResult _dbus_transport_open_socket(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens a TCP socket transport.
DBusTransportOpenResult _dbus_transport_open_unix_socket(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens a UNIX socket transport.
DBusTransportOpenResult _dbus_transport_open_platform_specific(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens platform specific transport types.
void _dbus_transport_set_max_message_size(DBusTransport *transport, long size)
See dbus_connection_set_max_message_size().
void _dbus_transport_set_max_received_size(DBusTransport *transport, long size)
See dbus_connection_set_max_received_size().
DBusDispatchStatus _dbus_transport_get_dispatch_status(DBusTransport *transport)
Reports our current dispatch status (whether there's buffered data to be queued as messages,...
dbus_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
int _dbus_transport_get_pending_fds_count(DBusTransport *transport)
Return how many file descriptors are pending in the loader.
dbus_bool_t _dbus_transport_get_adt_audit_session_data(DBusTransport *transport, void **data, int *data_size)
See dbus_connection_get_adt_audit_session_data().
dbus_bool_t _dbus_transport_get_windows_user(DBusTransport *transport, char **windows_sid_p)
See dbus_connection_get_windows_user().
dbus_bool_t _dbus_transport_queue_messages(DBusTransport *transport)
Processes data we've read while handling a watch, potentially converting some of it to messages and q...
dbus_bool_t _dbus_transport_get_socket_fd(DBusTransport *transport, DBusSocket *fd_p)
Get the socket file descriptor, if any.
const char * _dbus_transport_get_address(DBusTransport *transport)
Gets the address of a transport.
dbus_bool_t _dbus_transport_handle_watch(DBusTransport *transport, DBusWatch *watch, unsigned int condition)
Handles a watch by reading data, writing data, or disconnecting the transport, as appropriate for the...
DBusTransport * _dbus_transport_ref(DBusTransport *transport)
Increments the reference count for the transport.
dbus_bool_t _dbus_transport_peek_is_authenticated(DBusTransport *transport)
Returns TRUE if we have been authenticated.
void _dbus_transport_set_allow_anonymous(DBusTransport *transport, dbus_bool_t value)
See dbus_connection_set_allow_anonymous()
void _dbus_transport_disconnect(DBusTransport *transport)
Closes our end of the connection to a remote application.
long _dbus_transport_get_max_received_size(DBusTransport *transport)
See dbus_connection_get_max_received_size().
DBusCredentials * _dbus_transport_get_credentials(DBusTransport *transport)
If the transport has already been authenticated, return its credentials.
dbus_bool_t _dbus_transport_set_connection(DBusTransport *transport, DBusConnection *connection)
Sets the connection using this transport.
void _dbus_transport_set_unix_user_function(DBusTransport *transport, DBusAllowUnixUserFunction function, void *data, DBusFreeFunction free_data_function, void **old_data, DBusFreeFunction *old_free_data_function)
See dbus_connection_set_unix_user_function().
long _dbus_transport_get_max_message_unix_fds(DBusTransport *transport)
See dbus_connection_get_max_message_unix_fds().
dbus_bool_t _dbus_transport_init_base(DBusTransport *transport, const DBusTransportVTable *vtable, const DBusString *server_guid, const DBusString *address)
Initializes the base class members of DBusTransport.
void _dbus_transport_set_max_received_unix_fds(DBusTransport *transport, long n)
See dbus_connection_set_max_received_unix_fds().
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
dbus_bool_t _dbus_transport_can_pass_unix_fd(DBusTransport *transport)
Returns TRUE if the transport supports sending unix fds.
dbus_bool_t _dbus_transport_try_to_authenticate(DBusTransport *transport)
Returns TRUE if we have been authenticated.
void _dbus_transport_do_iteration(DBusTransport *transport, unsigned int flags, int timeout_milliseconds)
Performs a single poll()/select() on the transport's file descriptors and then reads/writes data as a...
long _dbus_transport_get_max_received_unix_fds(DBusTransport *transport)
See dbus_connection_set_max_received_unix_fds().
dbus_bool_t _dbus_transport_get_is_connected(DBusTransport *transport)
Returns TRUE if the transport has not been disconnected.
void _dbus_transport_set_max_message_unix_fds(DBusTransport *transport, long n)
See dbus_connection_set_max_message_unix_fds().
void _dbus_transport_set_pending_fds_function(DBusTransport *transport, void(*callback)(void *), void *data)
Register a function to be called whenever the number of pending file descriptors in the loader change...
void _dbus_transport_set_windows_user_function(DBusTransport *transport, DBusAllowWindowsUserFunction function, void *data, DBusFreeFunction free_data_function, void **old_data, DBusFreeFunction *old_free_data_function)
See dbus_connection_set_windows_user_function().
long _dbus_transport_get_max_message_size(DBusTransport *transport)
See dbus_connection_get_max_message_size().
dbus_bool_t _dbus_transport_get_unix_process_id(DBusTransport *transport, unsigned long *pid)
See dbus_connection_get_unix_process_id().
DBusTransport * _dbus_transport_open(DBusAddressEntry *entry, DBusError *error)
Try to open a new transport for the given address entry.
const char * _dbus_transport_get_server_id(DBusTransport *transport)
Gets the id of the server we are connected to (see dbus_server_get_id()).
dbus_bool_t _dbus_transport_get_is_anonymous(DBusTransport *transport)
See dbus_connection_get_is_anonymous().
void _dbus_transport_finalize_base(DBusTransport *transport)
Finalizes base class members of DBusTransport.
dbus_bool_t _dbus_transport_get_unix_user(DBusTransport *transport, unsigned long *uid)
See dbus_connection_get_unix_user().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
void _dbus_watch_sanitize_condition(DBusWatch *watch, unsigned int *condition)
Sanitizes the given condition so that it only contains flags that the DBusWatch requested.
Definition: dbus-watch.c:185
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
Definition: dbus-watch.c:124
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
Definition: dbus-watch.c:138
DBUS_EXPORT int dbus_watch_get_socket(DBusWatch *watch)
Returns a socket to be watched, on UNIX this will return -1 if our transport is not socket-based so d...
Definition: dbus-watch.c:593
Internals of DBusAddressEntry.
Definition: dbus-address.c:47
Internal members of DBusAuth.
Definition: dbus-auth.c:154
Implementation details of DBusConnection.
Internals of DBusCounter.
Object representing an exception.
Definition: dbus-errors.h:49
A node in a linked list.
Definition: dbus-list.h:35
void * data
Data stored at this element.
Definition: dbus-list.h:38
Implementation details of DBusMessageLoader.
Internals of DBusMessage.
Socket interface.
Definition: dbus-sysdeps.h:179
The virtual table that must be implemented to create a new kind of transport.
dbus_bool_t(* get_socket_fd)(DBusTransport *transport, DBusSocket *fd_p)
Get socket file descriptor.
void(* disconnect)(DBusTransport *transport)
Disconnect this transport.
void(* live_messages_changed)(DBusTransport *transport)
Outstanding messages counter changed.
void(* do_iteration)(DBusTransport *transport, unsigned int flags, int timeout_milliseconds)
Called to do a single "iteration" (block on select/poll followed by reading or writing data).
dbus_bool_t(* handle_watch)(DBusTransport *transport, DBusWatch *watch, unsigned int flags)
The handle_watch method handles reading/writing data as indicated by the flags.
void(* finalize)(DBusTransport *transport)
The finalize method must free the transport.
dbus_bool_t(* connection_set)(DBusTransport *transport)
Called when transport->connection has been filled in.
Object representing a transport such as a socket.
unsigned int authenticated
Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value.
DBusAllowWindowsUserFunction windows_user_function
Function for checking whether a user is authorized.
int refcount
Reference count.
long max_live_messages_size
Max total size of received messages.
long max_live_messages_unix_fds
Max total unix fds of received messages.
unsigned int allow_anonymous
TRUE if an anonymous client can connect
void * windows_user_data
Data for windows_user_function.
unsigned int is_server
TRUE if on the server side
unsigned int disconnected
TRUE if we are disconnected.
char * address
Address of the server we are connecting to (NULL for the server side of a transport)
unsigned int unused_bytes_recovered
TRUE if we've recovered unused bytes from auth
const DBusTransportVTable * vtable
Virtual methods for this instance.
DBusFreeFunction free_unix_user_data
Function to free unix_user_data.
unsigned int send_credentials_pending
TRUE if we need to send credentials
void * unix_user_data
Data for unix_user_function.
DBusConnection * connection
Connection owning this transport.
unsigned int receive_credentials_pending
TRUE if we need to receive credentials
DBusMessageLoader * loader
Message-loading buffer.
char * expected_guid
GUID we expect the server to have, NULL on server side or if we don't have an expectation.
DBusFreeFunction free_windows_user_data
Function to free windows_user_data.
DBusAllowUnixUserFunction unix_user_function
Function for checking whether a user is authorized.
DBusCredentials * credentials
Credentials of other end read from the socket.
DBusAuth * auth
Authentication conversation.
DBusCounter * live_messages
Counter for size/unix fds of all live messages.
Implementation of DBusWatch.
Definition: dbus-watch.c:41