D-Bus: dbus-transport.c Source File

D-Bus 1.10.22

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
60 static void
61 live_messages_notify (DBusCounter *counter,
62 void *user_data)
63 {
64 DBusTransport *transport = user_data;
65
66 _dbus_connection_lock (transport->connection);
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);
85 _dbus_connection_unlock (transport->connection);
86 }
87
101 dbus_bool_t
102 _dbus_transport_init_base (DBusTransport *transport,
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 {
123 _dbus_message_loader_unref (loader);
124 return FALSE;
125 }
126
127 counter = _dbus_counter_new ();
128 if (counter == NULL)
129 {
130 _dbus_auth_unref (auth);
131 _dbus_message_loader_unref (loader);
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);
140 _dbus_message_loader_unref (loader);
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 {
155 _dbus_credentials_unref (creds);
156 _dbus_counter_unref (counter);
157 _dbus_auth_unref (auth);
158 _dbus_message_loader_unref (loader);
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
197 _dbus_counter_set_notify (transport->live_messages,
198 transport->max_live_messages_size,
199 transport->max_live_messages_unix_fds,
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
215 void
216 _dbus_transport_finalize_base (DBusTransport *transport)
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
227 _dbus_message_loader_unref (transport->loader);
228 _dbus_auth_unref (transport->auth);
229 _dbus_counter_set_notify (transport->live_messages,
230 0, 0, NULL, NULL);
231 _dbus_counter_unref (transport->live_messages);
232 dbus_free (transport->address);
233 dbus_free (transport->expected_guid);
234 if (transport->credentials)
235 _dbus_credentials_unref (transport->credentials);
236 }
237
238
249 static DBusTransport*
250 check_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
271 dbus_address_entries_free (entries);
272 return transport;
273 }
274
283 static 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 {
293 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
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 if (result == NULL)
305 _DBUS_ASSERT_ERROR_IS_SET (error);
306 else
307 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
308
309 out:
310 _dbus_string_free (&address);
311 return result;
312 }
313
314 static DBusTransportOpenResult
315 _dbus_transport_open_autolaunch (DBusAddressEntry *entry,
316 DBusTransport **transport_p,
317 DBusError *error)
318 {
319 const char *method;
320
321 method = dbus_address_entry_get_method (entry);
322 _dbus_assert (method != NULL);
323
324 if (strcmp (method, "autolaunch") == 0)
325 {
326 const char *scope = dbus_address_entry_get_value (entry, "scope");
327
328 *transport_p = _dbus_transport_new_for_autolaunch (scope, error);
329
330 if (*transport_p == NULL)
331 {
332 _DBUS_ASSERT_ERROR_IS_SET (error);
333 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
334 }
335 else
336 {
337 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
338 return DBUS_TRANSPORT_OPEN_OK;
339 }
340 }
341 else
342 {
343 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
344 return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
345 }
346 }
347
348 static const struct {
349 DBusTransportOpenResult (* func) (DBusAddressEntry *entry,
350 DBusTransport **transport_p,
351 DBusError *error);
352 } open_funcs[] = {
353 { _dbus_transport_open_socket },
354 { _dbus_transport_open_platform_specific },
355 { _dbus_transport_open_autolaunch }
356 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
357 , { _dbus_transport_open_debug_pipe }
358 #endif
359 };
360
369 DBusTransport*
370 _dbus_transport_open (DBusAddressEntry *entry,
371 DBusError *error)
372 {
373 DBusTransport *transport;
374 const char *expected_guid_orig;
375 char *expected_guid;
376 int i;
377 DBusError tmp_error = DBUS_ERROR_INIT;
378
379 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
380
381 transport = NULL;
382 expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
383 expected_guid = _dbus_strdup (expected_guid_orig);
384
385 if (expected_guid_orig != NULL && expected_guid == NULL)
386 {
387 _DBUS_SET_OOM (error);
388 return NULL;
389 }
390
391 for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
392 {
393 DBusTransportOpenResult result;
394
395 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
396 result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
397
398 switch (result)
399 {
400 case DBUS_TRANSPORT_OPEN_OK:
401 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
402 goto out;
403 break;
404 case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
405 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
406 /* keep going through the loop of open funcs */
407 break;
408 case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
409 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
410 goto out;
411 break;
412 case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
413 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
414 goto out;
415 break;
416 }
417 }
418
419 out:
420
421 if (transport == NULL)
422 {
423 if (!dbus_error_is_set (&tmp_error))
424 _dbus_set_bad_address (&tmp_error,
425 NULL, NULL,
426 "Unknown address type (examples of valid types are \"tcp\" and on UNIX \"unix\")");
427
428 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
429 dbus_move_error(&tmp_error, error);
430 dbus_free (expected_guid);
431 }
432 else
433 {
434 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
435
436 /* In the case of autostart the initial guid is NULL
437 * and the autostart transport recursively calls
438 * _dbus_open_transport wich returns a transport
439 * with a guid. That guid is the definitive one.
440 *
441 * FIXME: if more transports are added they may have
442 * an effect on the expected_guid semantics (i.e.
443 * expected_guid and transport->expected_guid may
444 * both have values). This is very unlikely though
445 * we should either throw asserts here for those
446 * corner cases or refactor the code so it is
447 * clearer on what is expected and what is not
448 */
449 if(expected_guid)
450 transport->expected_guid = expected_guid;
451 }
452
453 return transport;
454 }
455
462 DBusTransport *
463 _dbus_transport_ref (DBusTransport *transport)
464 {
465 _dbus_assert (transport->refcount > 0);
466
467 transport->refcount += 1;
468
469 return transport;
470 }
471
479 void
480 _dbus_transport_unref (DBusTransport *transport)
481 {
482 _dbus_assert (transport != NULL);
483 _dbus_assert (transport->refcount > 0);
484
485 transport->refcount -= 1;
486 if (transport->refcount == 0)
487 {
488 _dbus_verbose ("finalizing\n");
489
490 _dbus_assert (transport->vtable->finalize != NULL);
491
492 (* transport->vtable->finalize) (transport);
493 }
494 }
495
504 void
505 _dbus_transport_disconnect (DBusTransport *transport)
506 {
507 _dbus_verbose ("start\n");
508
509 _dbus_assert (transport->vtable->disconnect != NULL);
510
511 if (transport->disconnected)
512 return;
513
514 (* transport->vtable->disconnect) (transport);
515
516 transport->disconnected = TRUE;
517
518 _dbus_verbose ("end\n");
519 }
520
529 dbus_bool_t
530 _dbus_transport_get_is_connected (DBusTransport *transport)
531 {
532 return !transport->disconnected;
533 }
534
535 static dbus_bool_t
536 auth_via_unix_user_function (DBusTransport *transport)
537 {
538 DBusCredentials *auth_identity;
539 dbus_bool_t allow;
540 DBusConnection *connection;
541 DBusAllowUnixUserFunction unix_user_function;
542 void *unix_user_data;
543 dbus_uid_t uid;
544
545 /* Dropping the lock here probably isn't that safe. */
546
547 auth_identity = _dbus_auth_get_identity (transport->auth);
548 _dbus_assert (auth_identity != NULL);
549
550 connection = transport->connection;
551 unix_user_function = transport->unix_user_function;
552 unix_user_data = transport->unix_user_data;
553 uid = _dbus_credentials_get_unix_uid (auth_identity);
554
555 _dbus_verbose ("unlock\n");
556 _dbus_connection_unlock (connection);
557
558 allow = (* unix_user_function) (connection,
559 uid,
560 unix_user_data);
561
562 _dbus_verbose ("lock post unix user function\n");
563 _dbus_connection_lock (connection);
564
565 if (allow)
566 {
567 _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", uid);
568 }
569 else
570 {
571 _dbus_verbose ("Client UID "DBUS_UID_FORMAT
572 " was rejected, disconnecting\n",
573 _dbus_credentials_get_unix_uid (auth_identity));
574 _dbus_transport_disconnect (transport);
575 }
576
577 return allow;
578 }
579
580 static dbus_bool_t
581 auth_via_windows_user_function (DBusTransport *transport)
582 {
583 DBusCredentials *auth_identity;
584 dbus_bool_t allow;
585 DBusConnection *connection;
586 DBusAllowWindowsUserFunction windows_user_function;
587 void *windows_user_data;
588 char *windows_sid;
589
590 /* Dropping the lock here probably isn't that safe. */
591
592 auth_identity = _dbus_auth_get_identity (transport->auth);
593 _dbus_assert (auth_identity != NULL);
594
595 connection = transport->connection;
596 windows_user_function = transport->windows_user_function;
597 windows_user_data = transport->unix_user_data;
598 windows_sid = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
599
600 if (windows_sid == NULL)
601 {
602 /* OOM */
603 return FALSE;
604 }
605
606 _dbus_verbose ("unlock\n");
607 _dbus_connection_unlock (connection);
608
609 allow = (* windows_user_function) (connection,
610 windows_sid,
611 windows_user_data);
612
613 _dbus_verbose ("lock post windows user function\n");
614 _dbus_connection_lock (connection);
615
616 if (allow)
617 {
618 _dbus_verbose ("Client SID '%s' authorized\n", windows_sid);
619 }
620 else
621 {
622 _dbus_verbose ("Client SID '%s' was rejected, disconnecting\n",
623 _dbus_credentials_get_windows_sid (auth_identity));
624 _dbus_transport_disconnect (transport);
625 }
626
627 return allow;
628 }
629
630 static dbus_bool_t
631 auth_via_default_rules (DBusTransport *transport)
632 {
633 DBusCredentials *auth_identity;
634 DBusCredentials *our_identity;
635 dbus_bool_t allow;
636
637 auth_identity = _dbus_auth_get_identity (transport->auth);
638 _dbus_assert (auth_identity != NULL);
639
640 /* By default, connection is allowed if the client is 1) root or 2)
641 * has the same UID as us or 3) anonymous is allowed.
642 */
643
644 our_identity = _dbus_credentials_new_from_current_process ();
645 if (our_identity == NULL)
646 {
647 /* OOM */
648 return FALSE;
649 }
650
651 if (transport->allow_anonymous ||
652 _dbus_credentials_get_unix_uid (auth_identity) == 0 ||
653 _dbus_credentials_same_user (our_identity,
654 auth_identity))
655 {
656 if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
657 _dbus_verbose ("Client authorized as SID '%s'"
658 "matching our SID '%s'\n",
659 _dbus_credentials_get_windows_sid(auth_identity),
660 _dbus_credentials_get_windows_sid(our_identity));
661 else
662 _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
663 " matching our UID "DBUS_UID_FORMAT"\n",
664 _dbus_credentials_get_unix_uid(auth_identity),
665 _dbus_credentials_get_unix_uid(our_identity));
666 /* We have authenticated! */
667 allow = TRUE;
668 }
669 else
670 {
671 if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
672 _dbus_verbose ("Client authorized as SID '%s'"
673 " but our SID is '%s', disconnecting\n",
674 (_dbus_credentials_get_windows_sid(auth_identity) ?
675 _dbus_credentials_get_windows_sid(auth_identity) : "<null>"),
676 (_dbus_credentials_get_windows_sid(our_identity) ?
677 _dbus_credentials_get_windows_sid(our_identity) : "<null>"));
678 else
679 _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
680 " but our UID is "DBUS_UID_FORMAT", disconnecting\n",
681 _dbus_credentials_get_unix_uid(auth_identity),
682 _dbus_credentials_get_unix_uid(our_identity));
683 _dbus_transport_disconnect (transport);
684 allow = FALSE;
685 }
686
687 _dbus_credentials_unref (our_identity);
688
689 return allow;
690 }
691
703 dbus_bool_t
704 _dbus_transport_peek_is_authenticated (DBusTransport *transport)
705 {
706 return transport->authenticated;
707 }
708
726 dbus_bool_t
727 _dbus_transport_try_to_authenticate (DBusTransport *transport)
728 {
729 if (transport->authenticated)
730 return TRUE;
731 else
732 {
733 dbus_bool_t maybe_authenticated;
734
735 if (transport->disconnected)
736 return FALSE;
737
738 /* paranoia ref since we call user callbacks sometimes */
739 _dbus_connection_ref_unlocked (transport->connection);
740
741 maybe_authenticated =
742 (!(transport->send_credentials_pending ||
743 transport->receive_credentials_pending));
744
745 if (maybe_authenticated)
746 {
747 switch (_dbus_auth_do_work (transport->auth))
748 {
749 case DBUS_AUTH_STATE_AUTHENTICATED:
750 /* leave as maybe_authenticated */
751 break;
752 default:
753 maybe_authenticated = FALSE;
754 }
755 }
756
757 /* If we're the client, verify the GUID
758 */
759 if (maybe_authenticated && !transport->is_server)
760 {
761 const char *server_guid;
762
763 server_guid = _dbus_auth_get_guid_from_server (transport->auth);
764 _dbus_assert (server_guid != NULL);
765
766 if (transport->expected_guid &&
767 strcmp (transport->expected_guid, server_guid) != 0)
768 {
769 _dbus_verbose ("Client expected GUID '%s' and we got '%s' from the server\n",
770 transport->expected_guid, server_guid);
771 _dbus_transport_disconnect (transport);
772 _dbus_connection_unref_unlocked (transport->connection);
773 return FALSE;
774 }
775 }
776
777 /* If we're the server, see if we want to allow this identity to proceed.
778 */
779 if (maybe_authenticated && transport->is_server)
780 {
781 dbus_bool_t allow;
782 DBusCredentials *auth_identity;
783
784 auth_identity = _dbus_auth_get_identity (transport->auth);
785 _dbus_assert (auth_identity != NULL);
786
787 /* If we have an auth'd user and a user function, delegate
788 * deciding whether auth credentials are good enough to the
789 * app; otherwise, use our default decision process.
790 */
791 if (transport->unix_user_function != NULL &&
792 _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_UNIX_USER_ID))
793 {
794 allow = auth_via_unix_user_function (transport);
795 }
796 else if (transport->windows_user_function != NULL &&
797 _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_WINDOWS_SID))
798 {
799 allow = auth_via_windows_user_function (transport);
800 }
801 else
802 {
803 allow = auth_via_default_rules (transport);
804 }
805
806 if (!allow)
807 maybe_authenticated = FALSE;
808 }
809
810 transport->authenticated = maybe_authenticated;
811
812 _dbus_connection_unref_unlocked (transport->connection);
813 return maybe_authenticated;
814 }
815 }
816
823 dbus_bool_t
824 _dbus_transport_get_is_anonymous (DBusTransport *transport)
825 {
826 DBusCredentials *auth_identity;
827
828 if (!transport->authenticated)
829 return TRUE;
830
831 auth_identity = _dbus_auth_get_identity (transport->auth);
832
833 if (_dbus_credentials_are_anonymous (auth_identity))
834 return TRUE;
835 else
836 return FALSE;
837 }
838
845 dbus_bool_t
846 _dbus_transport_can_pass_unix_fd(DBusTransport *transport)
847 {
848 return DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport);
849 }
850
858 const char*
859 _dbus_transport_get_address (DBusTransport *transport)
860 {
861 return transport->address;
862 }
863
871 const char*
872 _dbus_transport_get_server_id (DBusTransport *transport)
873 {
874 if (transport->is_server)
875 return NULL;
876 else if (transport->authenticated)
877 return _dbus_auth_get_guid_from_server (transport->auth);
878 else
879 return transport->expected_guid;
880 }
881
891 dbus_bool_t
892 _dbus_transport_handle_watch (DBusTransport *transport,
893 DBusWatch *watch,
894 unsigned int condition)
895 {
896 dbus_bool_t retval;
897
898 _dbus_assert (transport->vtable->handle_watch != NULL);
899
900 if (transport->disconnected)
901 return TRUE;
902
903 if (dbus_watch_get_socket (watch) < 0)
904 {
905 _dbus_warn_check_failed ("Tried to handle an invalidated watch; this watch should have been removed\n");
906 return TRUE;
907 }
908
909 _dbus_watch_sanitize_condition (watch, &condition);
910
911 _dbus_transport_ref (transport);
912 _dbus_watch_ref (watch);
913 retval = (* transport->vtable->handle_watch) (transport, watch, condition);
914 _dbus_watch_unref (watch);
915 _dbus_transport_unref (transport);
916
917 return retval;
918 }
919
929 dbus_bool_t
930 _dbus_transport_set_connection (DBusTransport *transport,
931 DBusConnection *connection)
932 {
933 _dbus_assert (transport->vtable->connection_set != NULL);
934 _dbus_assert (transport->connection == NULL);
935
936 transport->connection = connection;
937
938 _dbus_transport_ref (transport);
939 if (!(* transport->vtable->connection_set) (transport))
940 transport->connection = NULL;
941 _dbus_transport_unref (transport);
942
943 return transport->connection != NULL;
944 }
945
953 dbus_bool_t
954 _dbus_transport_get_socket_fd (DBusTransport *transport,
955 DBusSocket *fd_p)
956 {
957 dbus_bool_t retval;
958
959 if (transport->vtable->get_socket_fd == NULL)
960 return FALSE;
961
962 if (transport->disconnected)
963 return FALSE;
964
965 _dbus_transport_ref (transport);
966
967 retval = (* transport->vtable->get_socket_fd) (transport,
968 fd_p);
969
970 _dbus_transport_unref (transport);
971
972 return retval;
973 }
974
986 void
987 _dbus_transport_do_iteration (DBusTransport *transport,
988 unsigned int flags,
989 int timeout_milliseconds)
990 {
991 _dbus_assert (transport->vtable->do_iteration != NULL);
992
993 _dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
994 flags, timeout_milliseconds, !transport->disconnected);
995
996 if ((flags & (DBUS_ITERATION_DO_WRITING |
997 DBUS_ITERATION_DO_READING)) == 0)
998 return; /* Nothing to do */
999
1000 if (transport->disconnected)
1001 return;
1002
1003 _dbus_transport_ref (transport);
1004 (* transport->vtable->do_iteration) (transport, flags,
1005 timeout_milliseconds);
1006 _dbus_transport_unref (transport);
1007
1008 _dbus_verbose ("end\n");
1009 }
1010
1011 static dbus_bool_t
1012 recover_unused_bytes (DBusTransport *transport)
1013 {
1014 if (_dbus_auth_needs_decoding (transport->auth))
1015 {
1016 DBusString plaintext;
1017 const DBusString *encoded;
1018 DBusString *buffer;
1019 int orig_len;
1020
1021 if (!_dbus_string_init (&plaintext))
1022 goto nomem;
1023
1024 _dbus_auth_get_unused_bytes (transport->auth,
1025 &encoded);
1026
1027 if (!_dbus_auth_decode_data (transport->auth,
1028 encoded, &plaintext))
1029 {
1030 _dbus_string_free (&plaintext);
1031 goto nomem;
1032 }
1033
1034 _dbus_message_loader_get_buffer (transport->loader,
1035 &buffer);
1036
1037 orig_len = _dbus_string_get_length (buffer);
1038
1039 if (!_dbus_string_move (&plaintext, 0, buffer,
1040 orig_len))
1041 {
1042 _dbus_string_free (&plaintext);
1043 goto nomem;
1044 }
1045
1046 _dbus_verbose (" %d unused bytes sent to message loader\n",
1047 _dbus_string_get_length (buffer) -
1048 orig_len);
1049
1050 _dbus_message_loader_return_buffer (transport->loader,
1051 buffer);
1052
1053 _dbus_auth_delete_unused_bytes (transport->auth);
1054
1055 _dbus_string_free (&plaintext);
1056 }
1057 else
1058 {
1059 const DBusString *bytes;
1060 DBusString *buffer;
1061 int orig_len;
1062 dbus_bool_t succeeded;
1063
1064 _dbus_message_loader_get_buffer (transport->loader,
1065 &buffer);
1066
1067 orig_len = _dbus_string_get_length (buffer);
1068
1069 _dbus_auth_get_unused_bytes (transport->auth,
1070 &bytes);
1071
1072 succeeded = TRUE;
1073 if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
1074 succeeded = FALSE;
1075
1076 _dbus_verbose (" %d unused bytes sent to message loader\n",
1077 _dbus_string_get_length (buffer) -
1078 orig_len);
1079
1080 _dbus_message_loader_return_buffer (transport->loader,
1081 buffer);
1082
1083 if (succeeded)
1084 _dbus_auth_delete_unused_bytes (transport->auth);
1085 else
1086 goto nomem;
1087 }
1088
1089 return TRUE;
1090
1091 nomem:
1092 _dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
1093 return FALSE;
1094 }
1095
1103 DBusDispatchStatus
1104 _dbus_transport_get_dispatch_status (DBusTransport *transport)
1105 {
1106 if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size ||
1107 _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds)
1108 return DBUS_DISPATCH_COMPLETE; /* complete for now */
1109
1110 if (!_dbus_transport_try_to_authenticate (transport))
1111 {
1112 if (_dbus_auth_do_work (transport->auth) ==
1113 DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
1114 return DBUS_DISPATCH_NEED_MEMORY;
1115 else if (!_dbus_transport_try_to_authenticate (transport))
1116 return DBUS_DISPATCH_COMPLETE;
1117 }
1118
1119 if (!transport->unused_bytes_recovered &&
1120 !recover_unused_bytes (transport))
1121 return DBUS_DISPATCH_NEED_MEMORY;
1122
1123 transport->unused_bytes_recovered = TRUE;
1124
1125 if (!_dbus_message_loader_queue_messages (transport->loader))
1126 return DBUS_DISPATCH_NEED_MEMORY;
1127
1128 if (_dbus_message_loader_peek_message (transport->loader) != NULL)
1129 return DBUS_DISPATCH_DATA_REMAINS;
1130 else
1131 return DBUS_DISPATCH_COMPLETE;
1132 }
1133
1142 dbus_bool_t
1143 _dbus_transport_queue_messages (DBusTransport *transport)
1144 {
1145 DBusDispatchStatus status;
1146
1147 #if 0
1148 _dbus_verbose ("_dbus_transport_queue_messages()\n");
1149 #endif
1150
1151 /* Queue any messages */
1152 while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
1153 {
1154 DBusMessage *message;
1155 DBusList *link;
1156
1157 link = _dbus_message_loader_pop_message_link (transport->loader);
1158 _dbus_assert (link != NULL);
1159
1160 message = link->data;
1161
1162 _dbus_verbose ("queueing received message %p\n", message);
1163
1164 if (!_dbus_message_add_counter (message, transport->live_messages))
1165 {
1166 _dbus_message_loader_putback_message_link (transport->loader,
1167 link);
1168 status = DBUS_DISPATCH_NEED_MEMORY;
1169 break;
1170 }
1171 else
1172 {
1173 /* We didn't call the notify function when we added the counter, so
1174 * catch up now. Since we have the connection's lock, it's desirable
1175 * that we bypass the notify function and call this virtual method
1176 * directly. */
1177 if (transport->vtable->live_messages_changed)
1178 (* transport->vtable->live_messages_changed) (transport);
1179
1180 /* pass ownership of link and message ref to connection */
1181 _dbus_connection_queue_received_message_link (transport->connection,
1182 link);
1183 }
1184 }
1185
1186 if (_dbus_message_loader_get_is_corrupted (transport->loader))
1187 {
1188 _dbus_verbose ("Corrupted message stream, disconnecting\n");
1189 _dbus_transport_disconnect (transport);
1190 }
1191
1192 return status != DBUS_DISPATCH_NEED_MEMORY;
1193 }
1194
1201 void
1202 _dbus_transport_set_max_message_size (DBusTransport *transport,
1203 long size)
1204 {
1205 _dbus_message_loader_set_max_message_size (transport->loader, size);
1206 }
1207
1214 void
1215 _dbus_transport_set_max_message_unix_fds (DBusTransport *transport,
1216 long n)
1217 {
1218 _dbus_message_loader_set_max_message_unix_fds (transport->loader, n);
1219 }
1220
1227 long
1228 _dbus_transport_get_max_message_size (DBusTransport *transport)
1229 {
1230 return _dbus_message_loader_get_max_message_size (transport->loader);
1231 }
1232
1239 long
1240 _dbus_transport_get_max_message_unix_fds (DBusTransport *transport)
1241 {
1242 return _dbus_message_loader_get_max_message_unix_fds (transport->loader);
1243 }
1244
1251 void
1252 _dbus_transport_set_max_received_size (DBusTransport *transport,
1253 long size)
1254 {
1255 transport->max_live_messages_size = size;
1256 _dbus_counter_set_notify (transport->live_messages,
1257 transport->max_live_messages_size,
1258 transport->max_live_messages_unix_fds,
1259 live_messages_notify,
1260 transport);
1261 }
1262
1269 void
1270 _dbus_transport_set_max_received_unix_fds (DBusTransport *transport,
1271 long n)
1272 {
1273 transport->max_live_messages_unix_fds = n;
1274 _dbus_counter_set_notify (transport->live_messages,
1275 transport->max_live_messages_size,
1276 transport->max_live_messages_unix_fds,
1277 live_messages_notify,
1278 transport);
1279 }
1280
1287 long
1288 _dbus_transport_get_max_received_size (DBusTransport *transport)
1289 {
1290 return transport->max_live_messages_size;
1291 }
1292
1299 long
1300 _dbus_transport_get_max_received_unix_fds (DBusTransport *transport)
1301 {
1302 return transport->max_live_messages_unix_fds;
1303 }
1304
1312 dbus_bool_t
1313 _dbus_transport_get_unix_user (DBusTransport *transport,
1314 unsigned long *uid)
1315 {
1316 DBusCredentials *auth_identity;
1317
1318 *uid = _DBUS_INT32_MAX; /* better than some root or system user in
1319 * case of bugs in the caller. Caller should
1320 * never use this value on purpose, however.
1321 */
1322
1323 if (!transport->authenticated)
1324 return FALSE;
1325
1326 auth_identity = _dbus_auth_get_identity (transport->auth);
1327
1328 if (_dbus_credentials_include (auth_identity,
1329 DBUS_CREDENTIAL_UNIX_USER_ID))
1330 {
1331 *uid = _dbus_credentials_get_unix_uid (auth_identity);
1332 return TRUE;
1333 }
1334 else
1335 return FALSE;
1336 }
1337
1345 dbus_bool_t
1346 _dbus_transport_get_unix_process_id (DBusTransport *transport,
1347 unsigned long *pid)
1348 {
1349 DBusCredentials *auth_identity;
1350
1351 *pid = DBUS_PID_UNSET; /* Caller should never use this value on purpose,
1352 * but we set it to a safe number, INT_MAX,
1353 * just to root out possible bugs in bad callers.
1354 */
1355
1356 if (!transport->authenticated)
1357 return FALSE;
1358
1359 auth_identity = _dbus_auth_get_identity (transport->auth);
1360
1361 if (_dbus_credentials_include (auth_identity,
1362 DBUS_CREDENTIAL_UNIX_PROCESS_ID))
1363 {
1364 *pid = _dbus_credentials_get_pid (auth_identity);
1365 return TRUE;
1366 }
1367 else
1368 return FALSE;
1369 }
1370
1379 dbus_bool_t
1380 _dbus_transport_get_adt_audit_session_data (DBusTransport *transport,
1381 void **data,
1382 int *data_size)
1383 {
1384 DBusCredentials *auth_identity;
1385
1386 *data = NULL;
1387 *data_size = 0;
1388
1389 if (!transport->authenticated)
1390 return FALSE;
1391
1392 auth_identity = _dbus_auth_get_identity (transport->auth);
1393
1394 if (_dbus_credentials_include (auth_identity,
1395 DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID))
1396 {
1397 *data = (void *) _dbus_credentials_get_adt_audit_data (auth_identity);
1398 *data_size = _dbus_credentials_get_adt_audit_data_size (auth_identity);
1399 return TRUE;
1400 }
1401 else
1402 return FALSE;
1403 }
1404
1415 void
1416 _dbus_transport_set_unix_user_function (DBusTransport *transport,
1417 DBusAllowUnixUserFunction function,
1418 void *data,
1419 DBusFreeFunction free_data_function,
1420 void **old_data,
1421 DBusFreeFunction *old_free_data_function)
1422 {
1423 *old_data = transport->unix_user_data;
1424 *old_free_data_function = transport->free_unix_user_data;
1425
1426 transport->unix_user_function = function;
1427 transport->unix_user_data = data;
1428 transport->free_unix_user_data = free_data_function;
1429 }
1430
1431 dbus_bool_t
1432 _dbus_transport_get_linux_security_label (DBusTransport *transport,
1433 char **label_p)
1434 {
1435 DBusCredentials *auth_identity;
1436
1437 *label_p = NULL;
1438
1439 if (!transport->authenticated)
1440 return FALSE;
1441
1442 auth_identity = _dbus_auth_get_identity (transport->auth);
1443
1444 if (_dbus_credentials_include (auth_identity,
1445 DBUS_CREDENTIAL_LINUX_SECURITY_LABEL))
1446 {
1447 /* If no memory, we are supposed to return TRUE and set NULL */
1448 *label_p = _dbus_strdup (_dbus_credentials_get_linux_security_label (auth_identity));
1449
1450 return TRUE;
1451 }
1452 else
1453 {
1454 return FALSE;
1455 }
1456 }
1457
1465 dbus_bool_t
1466 _dbus_transport_get_windows_user (DBusTransport *transport,
1467 char **windows_sid_p)
1468 {
1469 DBusCredentials *auth_identity;
1470
1471 *windows_sid_p = NULL;
1472
1473 if (!transport->authenticated)
1474 return FALSE;
1475
1476 auth_identity = _dbus_auth_get_identity (transport->auth);
1477
1478 if (_dbus_credentials_include (auth_identity,
1479 DBUS_CREDENTIAL_WINDOWS_SID))
1480 {
1481 /* If no memory, we are supposed to return TRUE and set NULL */
1482 *windows_sid_p = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
1483
1484 return TRUE;
1485 }
1486 else
1487 return FALSE;
1488 }
1489
1501 void
1502 _dbus_transport_set_windows_user_function (DBusTransport *transport,
1503 DBusAllowWindowsUserFunction function,
1504 void *data,
1505 DBusFreeFunction free_data_function,
1506 void **old_data,
1507 DBusFreeFunction *old_free_data_function)
1508 {
1509 *old_data = transport->windows_user_data;
1510 *old_free_data_function = transport->free_windows_user_data;
1511
1512 transport->windows_user_function = function;
1513 transport->windows_user_data = data;
1514 transport->free_windows_user_data = free_data_function;
1515 }
1516
1525 dbus_bool_t
1526 _dbus_transport_set_auth_mechanisms (DBusTransport *transport,
1527 const char **mechanisms)
1528 {
1529 return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
1530 }
1531
1538 void
1539 _dbus_transport_set_allow_anonymous (DBusTransport *transport,
1540 dbus_bool_t value)
1541 {
1542 transport->allow_anonymous = value != FALSE;
1543 }
1544
1550 int
1551 _dbus_transport_get_pending_fds_count (DBusTransport *transport)
1552 {
1553 return _dbus_message_loader_get_pending_fds_count (transport->loader);
1554 }
1555
1563 void
1564 _dbus_transport_set_pending_fds_function (DBusTransport *transport,
1565 void (* callback) (void *),
1566 void *data)
1567 {
1568 _dbus_message_loader_set_pending_fds_function (transport->loader,
1569 callback, data);
1570 }
1571
1572 #ifdef DBUS_ENABLE_STATS
1573 void
1574 _dbus_transport_get_stats (DBusTransport *transport,
1575 dbus_uint32_t *queue_bytes,
1576 dbus_uint32_t *queue_fds,
1577 dbus_uint32_t *peak_queue_bytes,
1578 dbus_uint32_t *peak_queue_fds)
1579 {
1580 if (queue_bytes != NULL)
1581 *queue_bytes = _dbus_counter_get_size_value (transport->live_messages);
1582
1583 if (queue_fds != NULL)
1584 *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages);
1585
1586 if (peak_queue_bytes != NULL)
1587 *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages);
1588
1589 if (peak_queue_fds != NULL)
1590 *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages);
1591 }
1592 #endif /* DBUS_ENABLE_STATS */
1593
_dbus_transport_set_max_received_unix_fds
void _dbus_transport_set_max_received_unix_fds(DBusTransport *transport, long n)
See dbus_connection_set_max_received_unix_fds().
Definition: dbus-transport.c:1270
_dbus_credentials_get_unix_uid
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&#39;t contain...
Definition: dbus-credentials.c:297
_dbus_transport_get_server_id
const char * _dbus_transport_get_server_id(DBusTransport *transport)
Gets the id of the server we are connected to (see dbus_server_get_id()).
Definition: dbus-transport.c:872
DBusTransportVTable::handle_watch
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.
Definition: dbus-transport-protected.h:46
DBusTransport::max_live_messages_unix_fds
long max_live_messages_unix_fds
Max total unix fds of received messages.
Definition: dbus-transport-protected.h:95
DBusDispatchStatus
DBusDispatchStatus
Indicates the status of incoming data on a DBusConnection.
Definition: dbus-connection.h:79
_dbus_auth_delete_unused_bytes
void _dbus_auth_delete_unused_bytes(DBusAuth *auth)
Gets rid of unused bytes returned by _dbus_auth_get_unused_bytes() after we&#39;ve gotten them and succes...
Definition: dbus-auth.c:2608
_dbus_transport_get_address
const char * _dbus_transport_get_address(DBusTransport *transport)
Gets the address of a transport.
Definition: dbus-transport.c:859
DBusWatch
Implementation of DBusWatch.
Definition: dbus-watch.c:40
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
DBusCredentials
Definition: dbus-credentials.c:48
DBusFreeFunction
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
Definition: dbus-memory.h:64
_dbus_credentials_include
dbus_bool_t _dbus_credentials_include(DBusCredentials *credentials, DBusCredentialType type)
Checks whether the given credential is present.
Definition: dbus-credentials.c:255
_dbus_auth_get_unused_bytes
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:2591
_dbus_message_loader_get_max_message_size
DBUS_PRIVATE_EXPORT long _dbus_message_loader_get_max_message_size(DBusMessageLoader *loader)
Gets the maximum allowed message size in bytes.
Definition: dbus-message.c:4563
_dbus_transport_open_platform_specific
DBusTransportOpenResult _dbus_transport_open_platform_specific(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens platform specific transport types.
Definition: dbus-transport-win.c:50
_dbus_message_loader_putback_message_link
void _dbus_message_loader_putback_message_link(DBusMessageLoader *loader, DBusList *link)
Returns a popped message link, used to undo a pop.
Definition: dbus-message.c:4499
DBusTransportVTable::connection_set
dbus_bool_t(* connection_set)(DBusTransport *transport)
Called when transport->connection has been filled in.
Definition: dbus-transport-protected.h:56
_dbus_message_loader_return_buffer
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...
Definition: dbus-message.c:4073
DBUS_DISPATCH_NEED_MEMORY
More memory is needed to continue.
Definition: dbus-connection.h:83
DBusTransport::auth
DBusAuth * auth
Authentication conversation.
Definition: dbus-transport-protected.h:90
DBusTransport::disconnected
unsigned int disconnected
TRUE if we are disconnected.
Definition: dbus-transport-protected.h:113
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:701
_dbus_credentials_get_adt_audit_data_size
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&#39;t contain ADT a...
Definition: dbus-credentials.c:349
_dbus_auth_needs_decoding
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:2684
DBusTransport::max_live_messages_size
long max_live_messages_size
Max total size of received messages.
Definition: dbus-transport-protected.h:94
DBusTransport::free_windows_user_data
DBusFreeFunction free_windows_user_data
Function to free windows_user_data.
Definition: dbus-transport-protected.h:111
_dbus_connection_lock
DBUS_PRIVATE_EXPORT void _dbus_connection_lock(DBusConnection *connection)
Acquires the connection lock.
Definition: dbus-connection.c:388
_dbus_transport_get_socket_fd
dbus_bool_t _dbus_transport_get_socket_fd(DBusTransport *transport, DBusSocket *fd_p)
Get the socket file descriptor, if any.
Definition: dbus-transport.c:954
DBusTransport::expected_guid
char * expected_guid
GUID we expect the server to have, NULL on server side or if we don&#39;t have an expectation.
Definition: dbus-transport-protected.h:101
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition: dbus-internals.h:148
DBusTransportVTable::live_messages_changed
void(* live_messages_changed)(DBusTransport *transport)
Outstanding messages counter changed.
Definition: dbus-transport-protected.h:66
DBusCounter
Internals of DBusCounter.
Definition: dbus-resources.c:54
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
DBusList::data
void * data
Data stored at this element.
Definition: dbus-list.h:38
DBusTransport::authenticated
unsigned int authenticated
Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value.
Definition: dbus-transport-protected.h:114
dbus_address_entry_get_method
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
Definition: dbus-address.c:227
_dbus_transport_open_socket
DBusTransportOpenResult _dbus_transport_open_socket(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens a TCP socket transport.
Definition: dbus-transport-socket.c:1429
_dbus_warn_check_failed
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...
Definition: dbus-internals.c:258
_dbus_transport_get_unix_process_id
dbus_bool_t _dbus_transport_get_unix_process_id(DBusTransport *transport, unsigned long *pid)
See dbus_connection_get_unix_process_id().
Definition: dbus-transport.c:1346
_dbus_transport_queue_messages
dbus_bool_t _dbus_transport_queue_messages(DBusTransport *transport)
Processes data we&#39;ve read while handling a watch, potentially converting some of it to messages and q...
Definition: dbus-transport.c:1143
_dbus_transport_set_unix_user_function
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().
Definition: dbus-transport.c:1416
_dbus_auth_do_work
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:2465
dbus_error_free
void dbus_error_free(DBusError *error)
Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
_dbus_message_loader_unref
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...
Definition: dbus-message.c:4016
DBusTransport::connection
DBusConnection * connection
Connection owning this transport.
Definition: dbus-transport-protected.h:86
DBusTransport::refcount
int refcount
Reference count.
Definition: dbus-transport-protected.h:82
dbus_address_entries_free
void dbus_address_entries_free(DBusAddressEntry **entries)
Frees a NULL-terminated array of address entries.
Definition: dbus-address.c:189
_dbus_transport_get_windows_user
dbus_bool_t _dbus_transport_get_windows_user(DBusTransport *transport, char **windows_sid_p)
See dbus_connection_get_windows_user().
Definition: dbus-transport.c:1466
DBusConnection
Implementation details of DBusConnection.
Definition: dbus-connection.c:256
DBusTransport::send_credentials_pending
unsigned int send_credentials_pending
TRUE if we need to send credentials
Definition: dbus-transport-protected.h:115
_dbus_auth_set_mechanisms
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:2430
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
_dbus_transport_get_max_message_size
long _dbus_transport_get_max_message_size(DBusTransport *transport)
See dbus_connection_get_max_message_size().
Definition: dbus-transport.c:1228
_dbus_string_copy
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&#39;s copied to the d...
Definition: dbus-string.c:1283
DBUS_PID_UNSET
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
Definition: dbus-sysdeps.h:112
_dbus_message_add_counter
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, and decremented by the size/unix fds of this message when this message if finalized.
Definition: dbus-message.c:352
_dbus_transport_get_is_connected
dbus_bool_t _dbus_transport_get_is_connected(DBusTransport *transport)
Returns TRUE if the transport has not been disconnected.
Definition: dbus-transport.c:530
_dbus_get_autolaunch_address
dbus_bool_t _dbus_get_autolaunch_address(const char *scope, DBusString *address, DBusError *error)
Returns the address of a new session bus.
Definition: dbus-sysdeps-unix.c:3769
_dbus_transport_set_auth_mechanisms
dbus_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
Definition: dbus-transport.c:1526
_dbus_transport_init_base
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.
Definition: dbus-transport.c:102
DBUS_DISPATCH_DATA_REMAINS
There is more data to potentially convert to messages.
Definition: dbus-connection.h:81
DBusSocket
Socket interface.
Definition: dbus-sysdeps.h:148
_dbus_auth_get_identity
DBusCredentials * _dbus_auth_get_identity(DBusAuth *auth)
Gets the identity we authorized the client as.
Definition: dbus-auth.c:2765
DBusTransportVTable::get_socket_fd
dbus_bool_t(* get_socket_fd)(DBusTransport *transport, DBusSocket *fd_p)
Get socket file descriptor.
Definition: dbus-transport-protected.h:69
DBusMessage
Internals of DBusMessage.
Definition: dbus-message-private.h:99
_dbus_auth_decode_data
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:2715
_dbus_string_move
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:1259
dbus_address_entry_get_value
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:244
_dbus_transport_get_max_received_unix_fds
long _dbus_transport_get_max_received_unix_fds(DBusTransport *transport)
See dbus_connection_set_max_received_unix_fds().
Definition: dbus-transport.c:1300
_dbus_credentials_are_anonymous
dbus_bool_t _dbus_credentials_are_anonymous(DBusCredentials *credentials)
Checks whether a credentials object contains a user identity.
Definition: dbus-credentials.c:408
_dbus_transport_set_windows_user_function
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().
Definition: dbus-transport.c:1502
DBusTransport::receive_credentials_pending
unsigned int receive_credentials_pending
TRUE if we need to receive credentials
Definition: dbus-transport-protected.h:116
_dbus_string_copy_data
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:672
_dbus_transport_get_adt_audit_session_data
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().
Definition: dbus-transport.c:1380
DBusString
Definition: dbus-string.h:42
DBusTransport::live_messages
DBusCounter * live_messages
Counter for size/unix fds of all live messages.
Definition: dbus-transport-protected.h:97
DBusAuth
Internal members of DBusAuth.
Definition: dbus-auth.c:153
_dbus_message_loader_set_max_message_size
void _dbus_message_loader_set_max_message_size(DBusMessageLoader *loader, long size)
Sets the maximum size message we allow.
Definition: dbus-message.c:4544
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
dbus_watch_get_socket
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:594
_dbus_transport_peek_is_authenticated
dbus_bool_t _dbus_transport_peek_is_authenticated(DBusTransport *transport)
Returns TRUE if we have been authenticated.
Definition: dbus-transport.c:704
DBusTransport::unix_user_data
void * unix_user_data
Data for unix_user_function.
Definition: dbus-transport-protected.h:104
DBUS_DISPATCH_COMPLETE
All currently available data has been processed.
Definition: dbus-connection.h:82
DBusTransport::windows_user_function
DBusAllowWindowsUserFunction windows_user_function
Function for checking whether a user is authorized.
Definition: dbus-transport-protected.h:108
_dbus_credentials_new_from_current_process
DBusCredentials * _dbus_credentials_new_from_current_process(void)
Creates a new object with credentials (user ID and process ID) from the current process.
Definition: dbus-credentials.c:95
_dbus_auth_server_new
DBusAuth * _dbus_auth_server_new(const DBusString *guid)
Creates a new auth conversation object for the server side.
Definition: dbus-auth.c:2281
_dbus_counter_unref
void _dbus_counter_unref(DBusCounter *counter)
Decrements refcount of the counter and possibly finalizes the counter.
Definition: dbus-resources.c:136
_dbus_watch_sanitize_condition
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
DBusTransport::allow_anonymous
unsigned int allow_anonymous
TRUE if an anonymous client can connect
Definition: dbus-transport-protected.h:119
DBusAllowUnixUserFunction
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...
Definition: dbus-connection.h:143
DBusAddressEntry
Internals of DBusAddressEntry.
Definition: dbus-address.c:43
_dbus_message_loader_new
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
Definition: dbus-message.c:3954
_dbus_set_bad_address
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:65
_dbus_connection_unref_unlocked
DBUS_PRIVATE_EXPORT void _dbus_connection_unref_unlocked(DBusConnection *connection)
Decrements the reference count of a DBusConnection.
Definition: dbus-connection.c:1442
DBusError
Object representing an exception.
Definition: dbus-errors.h:48
_dbus_transport_get_is_anonymous
dbus_bool_t _dbus_transport_get_is_anonymous(DBusTransport *transport)
See dbus_connection_get_is_anonymous().
Definition: dbus-transport.c:824
_dbus_message_loader_set_pending_fds_function
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...
Definition: dbus-message.c:4623
dbus_set_error
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
DBusTransport::unused_bytes_recovered
unsigned int unused_bytes_recovered
TRUE if we&#39;ve recovered unused bytes from auth
Definition: dbus-transport-protected.h:118
DBusTransportVTable
The virtual table that must be implemented to create a new kind of transport.
Definition: dbus-transport-protected.h:41
DBusTransport::address
char * address
Address of the server we are connecting to (NULL for the server side of a transport) ...
Definition: dbus-transport-protected.h:99
_dbus_auth_get_guid_from_server
const char * _dbus_auth_get_guid_from_server(DBusAuth *auth)
Gets the GUID from the server if we&#39;ve authenticated; gets NULL otherwise.
Definition: dbus-auth.c:2789
_dbus_message_loader_get_is_corrupted
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
Definition: dbus-message.c:4515
DBusAllowWindowsUserFunction
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...
Definition: dbus-connection.h:153
_DBUS_N_ELEMENTS
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
Definition: dbus-internals.h:189
_dbus_transport_open
DBusTransport * _dbus_transport_open(DBusAddressEntry *entry, DBusError *error)
Try to open a new transport for the given address entry.
Definition: dbus-transport.c:370
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:259
_dbus_transport_get_unix_user
dbus_bool_t _dbus_transport_get_unix_user(DBusTransport *transport, unsigned long *uid)
See dbus_connection_get_unix_user().
Definition: dbus-transport.c:1313
_dbus_message_loader_get_max_message_unix_fds
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader)
Gets the maximum allowed number of unix fds per message.
Definition: dbus-message.c:4594
TRUE
#define TRUE
Expands to "1".
DBusTransport::loader
DBusMessageLoader * loader
Message-loading buffer.
Definition: dbus-transport-protected.h:88
DBusTransport::is_server
unsigned int is_server
TRUE if on the server side
Definition: dbus-transport-protected.h:117
_dbus_counter_set_notify
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&#39;s value...
Definition: dbus-resources.c:303
_dbus_transport_set_connection
dbus_bool_t _dbus_transport_set_connection(DBusTransport *transport, DBusConnection *connection)
Sets the connection using this transport.
Definition: dbus-transport.c:930
dbus_move_error
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:279
DBusTransport
Object representing a transport such as a socket.
Definition: dbus-transport-protected.h:80
DBUS_UID_FORMAT
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
Definition: dbus-sysdeps.h:121
DBusTransportVTable::do_iteration
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)...
Definition: dbus-transport-protected.h:59
_dbus_credentials_new
DBusCredentials * _dbus_credentials_new(void)
Creates a new credentials object.
Definition: dbus-credentials.c:71
_dbus_transport_handle_watch
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...
Definition: dbus-transport.c:892
_dbus_message_loader_pop_message_link
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)...
Definition: dbus-message.c:4487
DBusList
A node in a linked list.
Definition: dbus-list.h:34
_dbus_transport_ref
DBusTransport * _dbus_transport_ref(DBusTransport *transport)
Increments the reference count for the transport.
Definition: dbus-transport.c:463
_dbus_transport_try_to_authenticate
dbus_bool_t _dbus_transport_try_to_authenticate(DBusTransport *transport)
Returns TRUE if we have been authenticated.
Definition: dbus-transport.c:727
_dbus_message_loader_get_buffer
DBUS_PRIVATE_EXPORT void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer)
Gets the buffer to use for reading data from the network.
Definition: dbus-message.c:4053
_dbus_auth_unref
void _dbus_auth_unref(DBusAuth *auth)
Decrements the refcount of an auth object.
Definition: dbus-auth.c:2380
_dbus_transport_do_iteration
void _dbus_transport_do_iteration(DBusTransport *transport, unsigned int flags, int timeout_milliseconds)
Performs a single poll()/select() on the transport&#39;s file descriptors and then reads/writes data as a...
Definition: dbus-transport.c:987
_dbus_transport_get_max_received_size
long _dbus_transport_get_max_received_size(DBusTransport *transport)
See dbus_connection_get_max_received_size().
Definition: dbus-transport.c:1288
_dbus_transport_get_max_message_unix_fds
long _dbus_transport_get_max_message_unix_fds(DBusTransport *transport)
See dbus_connection_get_max_message_unix_fds().
Definition: dbus-transport.c:1240
DBusTransport::unix_user_function
DBusAllowUnixUserFunction unix_user_function
Function for checking whether a user is authorized.
Definition: dbus-transport-protected.h:103
_dbus_credentials_get_pid
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&#39;t cont...
Definition: dbus-credentials.c:284
_dbus_watch_unref
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_transport_set_pending_fds_function
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...
Definition: dbus-transport.c:1564
_dbus_counter_new
DBusCounter * _dbus_counter_new(void)
Creates a new DBusCounter.
Definition: dbus-resources.c:89
_dbus_connection_queue_received_message_link
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...
Definition: dbus-connection.c:480
_dbus_transport_set_allow_anonymous
void _dbus_transport_set_allow_anonymous(DBusTransport *transport, dbus_bool_t value)
See dbus_connection_set_allow_anonymous()
Definition: dbus-transport.c:1539
DBUS_ERROR_NO_MEMORY
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
Definition: dbus-protocol.h:357
_DBUS_INT32_MAX
#define _DBUS_INT32_MAX
Maximum value of type "int32".
Definition: dbus-internals.h:259
_dbus_credentials_unref
void _dbus_credentials_unref(DBusCredentials *credentials)
Decrement refcount on credentials.
Definition: dbus-credentials.c:130
_dbus_transport_set_max_received_size
void _dbus_transport_set_max_received_size(DBusTransport *transport, long size)
See dbus_connection_set_max_received_size().
Definition: dbus-transport.c:1252
FALSE
#define FALSE
Expands to "0".
_dbus_credentials_get_linux_security_label
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...
Definition: dbus-credentials.c:323
_dbus_credentials_same_user
dbus_bool_t _dbus_credentials_same_user(DBusCredentials *credentials, DBusCredentials *other_credentials)
Check whether the user-identifying credentials in two credentials objects are identical.
Definition: dbus-credentials.c:552
DBusTransport::credentials
DBusCredentials * credentials
Credentials of other end read from the socket.
Definition: dbus-transport-protected.h:92
_dbus_transport_get_pending_fds_count
int _dbus_transport_get_pending_fds_count(DBusTransport *transport)
Return how many file descriptors are pending in the loader.
Definition: dbus-transport.c:1551
dbus_parse_address
dbus_bool_t dbus_parse_address(const char *address, DBusAddressEntry ***entry, int *array_len, DBusError *error)
Parses an address string of the form:
Definition: dbus-address.c:363
_dbus_transport_can_pass_unix_fd
dbus_bool_t _dbus_transport_can_pass_unix_fd(DBusTransport *transport)
Returns TRUE if the transport supports sending unix fds.
Definition: dbus-transport.c:846
_dbus_watch_ref
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
Definition: dbus-watch.c:124
_dbus_message_loader_peek_message
DBusMessage * _dbus_message_loader_peek_message(DBusMessageLoader *loader)
Peeks at first loaded message, returns NULL if no messages have been queued.
Definition: dbus-message.c:4456
_dbus_credentials_get_windows_sid
const char * _dbus_credentials_get_windows_sid(DBusCredentials *credentials)
Gets the Windows user SID in the credentials, or NULL if the credentials object doesn&#39;t contain a Win...
Definition: dbus-credentials.c:310
_dbus_message_loader_queue_messages
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
Definition: dbus-message.c:4393
_dbus_connection_ref_unlocked
DBUS_PRIVATE_EXPORT DBusConnection * _dbus_connection_ref_unlocked(DBusConnection *connection)
Increments the reference count of a DBusConnection.
Definition: dbus-connection.c:1419
DBusTransportVTable::disconnect
void(* disconnect)(DBusTransport *transport)
Disconnect this transport.
Definition: dbus-transport-protected.h:53
_dbus_strdup
char * _dbus_strdup(const char *str)
Duplicates a string.
Definition: dbus-internals.c:537
_dbus_transport_disconnect
void _dbus_transport_disconnect(DBusTransport *transport)
Closes our end of the connection to a remote application.
Definition: dbus-transport.c:505
_dbus_transport_finalize_base
void _dbus_transport_finalize_base(DBusTransport *transport)
Finalizes base class members of DBusTransport.
Definition: dbus-transport.c:216
dbus_uid_t
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:107
_dbus_auth_client_new
DBusAuth * _dbus_auth_client_new(void)
Creates a new auth conversation object for the client side.
Definition: dbus-auth.c:2327
_dbus_message_loader_set_max_message_unix_fds
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader, long n)
Sets the maximum unix fds per message we allow.
Definition: dbus-message.c:4575
DBusTransport::vtable
const DBusTransportVTable * vtable
Virtual methods for this instance.
Definition: dbus-transport-protected.h:84
_dbus_connection_unlock
DBUS_PRIVATE_EXPORT void _dbus_connection_unlock(DBusConnection *connection)
Releases the connection lock.
Definition: dbus-connection.c:399
_dbus_transport_set_max_message_size
void _dbus_transport_set_max_message_size(DBusTransport *transport, long size)
See dbus_connection_set_max_message_size().
Definition: dbus-transport.c:1202
DBusMessageLoader
Implementation details of DBusMessageLoader.
Definition: dbus-message-private.h:60
DBusTransport::windows_user_data
void * windows_user_data
Data for windows_user_function.
Definition: dbus-transport-protected.h:109
_dbus_transport_get_dispatch_status
DBusDispatchStatus _dbus_transport_get_dispatch_status(DBusTransport *transport)
Reports our current dispatch status (whether there&#39;s buffered data to be queued as messages...
Definition: dbus-transport.c:1104
dbus_error_is_set
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
_dbus_transport_set_max_message_unix_fds
void _dbus_transport_set_max_message_unix_fds(DBusTransport *transport, long n)
See dbus_connection_set_max_message_unix_fds().
Definition: dbus-transport.c:1215
DBusTransport::free_unix_user_data
DBusFreeFunction free_unix_user_data
Function to free unix_user_data.
Definition: dbus-transport-protected.h:106
_dbus_transport_unref
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
Definition: dbus-transport.c:480
DBusTransportVTable::finalize
void(* finalize)(DBusTransport *transport)
The finalize method must free the transport.
Definition: dbus-transport-protected.h:43
_dbus_counter_get_unix_fd_value
long _dbus_counter_get_unix_fd_value(DBusCounter *counter)
Gets the current value of the unix fd counter.
Definition: dbus-resources.c:286
_dbus_message_loader_get_pending_fds_count
int _dbus_message_loader_get_pending_fds_count(DBusMessageLoader *loader)
Return how many file descriptors are pending in the loader.
Definition: dbus-message.c:4605
_dbus_counter_get_size_value
long _dbus_counter_get_size_value(DBusCounter *counter)
Gets the current value of the size counter.
Definition: dbus-resources.c:274
_dbus_credentials_get_adt_audit_data
void * _dbus_credentials_get_adt_audit_data(DBusCredentials *credentials)
Gets the ADT audit data in the credentials, or NULL if the credentials object doesn&#39;t contain ADT aud...
Definition: dbus-credentials.c:336