D-Bus: dbus-transport.c Source File

D-Bus 1.14.10

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
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
101dbus_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
215void
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
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
271 dbus_address_entries_free (entries);
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 {
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 _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[] = {
350 { _dbus_transport_open_socket },
351 { _dbus_transport_open_platform_specific },
352 { _dbus_transport_open_autolaunch }
353#ifdef DBUS_ENABLE_EMBEDDED_TESTS
354 , { _dbus_transport_open_debug_pipe }
355#endif
356};
357
366 DBusTransport*
367_dbus_transport_open (DBusAddressEntry *entry,
368 DBusError *error)
369{
370 DBusTransport *transport;
371 const char *expected_guid_orig;
372 char *expected_guid;
373 int i;
374 DBusError tmp_error = DBUS_ERROR_INIT;
375
376 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
377
378 transport = NULL;
379 expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
380 expected_guid = _dbus_strdup (expected_guid_orig);
381
382 if (expected_guid_orig != NULL && expected_guid == NULL)
383 {
384 _DBUS_SET_OOM (error);
385 return NULL;
386 }
387
388 for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
389 {
390 DBusTransportOpenResult result;
391
392 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
393 result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
394
395 switch (result)
396 {
397 case DBUS_TRANSPORT_OPEN_OK:
398 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
399 goto out;
400 break;
401 case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
402 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
403 /* keep going through the loop of open funcs */
404 break;
405 case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
406 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
407 goto out;
408 break;
409 case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
410 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
411 goto out;
412 break;
413 default:
414 _dbus_assert_not_reached ("invalid transport open result");
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
479void
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
504void
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
529dbus_bool_t
530_dbus_transport_get_is_connected (DBusTransport *transport)
531{
532 return !transport->disconnected;
533}
534
535static dbus_bool_t
536auth_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
580static dbus_bool_t
581auth_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
630static dbus_bool_t
631auth_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
703dbus_bool_t
704_dbus_transport_peek_is_authenticated (DBusTransport *transport)
705{
706 return transport->authenticated;
707}
708
726dbus_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
753 case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
754 case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
755 case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
756 case DBUS_AUTH_STATE_NEED_DISCONNECT:
757 maybe_authenticated = FALSE;
758 break;
759
760 case DBUS_AUTH_STATE_INVALID:
761 default:
762 _dbus_assert_not_reached ("invalid authentication state");
763 }
764 }
765
766 /* If we're the client, verify the GUID
767 */
768 if (maybe_authenticated && !transport->is_server)
769 {
770 const char *server_guid;
771
772 server_guid = _dbus_auth_get_guid_from_server (transport->auth);
773 _dbus_assert (server_guid != NULL);
774
775 if (transport->expected_guid &&
776 strcmp (transport->expected_guid, server_guid) != 0)
777 {
778 _dbus_verbose ("Client expected GUID '%s' and we got '%s' from the server\n",
779 transport->expected_guid, server_guid);
780 _dbus_transport_disconnect (transport);
781 _dbus_connection_unref_unlocked (transport->connection);
782 return FALSE;
783 }
784 }
785
786 /* If we're the server, see if we want to allow this identity to proceed.
787 */
788 if (maybe_authenticated && transport->is_server)
789 {
790 dbus_bool_t allow;
791 DBusCredentials *auth_identity;
792
793 auth_identity = _dbus_auth_get_identity (transport->auth);
794 _dbus_assert (auth_identity != NULL);
795
796 /* If we have an auth'd user and a user function, delegate
797 * deciding whether auth credentials are good enough to the
798 * app; otherwise, use our default decision process.
799 */
800 if (transport->unix_user_function != NULL &&
801 _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_UNIX_USER_ID))
802 {
803 allow = auth_via_unix_user_function (transport);
804 }
805 else if (transport->windows_user_function != NULL &&
806 _dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_WINDOWS_SID))
807 {
808 allow = auth_via_windows_user_function (transport);
809 }
810 else
811 {
812 allow = auth_via_default_rules (transport);
813 }
814
815 if (!allow)
816 maybe_authenticated = FALSE;
817 }
818
819 transport->authenticated = maybe_authenticated;
820
821 _dbus_connection_unref_unlocked (transport->connection);
822 return maybe_authenticated;
823 }
824}
825
832dbus_bool_t
833_dbus_transport_get_is_anonymous (DBusTransport *transport)
834{
835 DBusCredentials *auth_identity;
836
837 if (!transport->authenticated)
838 return TRUE;
839
840 auth_identity = _dbus_auth_get_identity (transport->auth);
841
842 if (_dbus_credentials_are_anonymous (auth_identity))
843 return TRUE;
844 else
845 return FALSE;
846}
847
854dbus_bool_t
855_dbus_transport_can_pass_unix_fd(DBusTransport *transport)
856{
857 return DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport);
858}
859
867const char*
868_dbus_transport_get_address (DBusTransport *transport)
869{
870 return transport->address;
871}
872
880const char*
881_dbus_transport_get_server_id (DBusTransport *transport)
882{
883 if (transport->is_server)
884 return NULL;
885 else if (transport->authenticated)
886 return _dbus_auth_get_guid_from_server (transport->auth);
887 else
888 return transport->expected_guid;
889}
890
900dbus_bool_t
901_dbus_transport_handle_watch (DBusTransport *transport,
902 DBusWatch *watch,
903 unsigned int condition)
904{
905 dbus_bool_t retval;
906
907 _dbus_assert (transport->vtable->handle_watch != NULL);
908
909 if (transport->disconnected)
910 return TRUE;
911
912 if (dbus_watch_get_socket (watch) < 0)
913 {
914 _dbus_warn_check_failed ("Tried to handle an invalidated watch; this watch should have been removed");
915 return TRUE;
916 }
917
918 _dbus_watch_sanitize_condition (watch, &condition);
919
920 _dbus_transport_ref (transport);
921 _dbus_watch_ref (watch);
922 retval = (* transport->vtable->handle_watch) (transport, watch, condition);
923 _dbus_watch_unref (watch);
924 _dbus_transport_unref (transport);
925
926 return retval;
927}
928
938dbus_bool_t
939_dbus_transport_set_connection (DBusTransport *transport,
940 DBusConnection *connection)
941{
942 _dbus_assert (transport->vtable->connection_set != NULL);
943 _dbus_assert (transport->connection == NULL);
944
945 transport->connection = connection;
946
947 _dbus_transport_ref (transport);
948 if (!(* transport->vtable->connection_set) (transport))
949 transport->connection = NULL;
950 _dbus_transport_unref (transport);
951
952 return transport->connection != NULL;
953}
954
962dbus_bool_t
963_dbus_transport_get_socket_fd (DBusTransport *transport,
964 DBusSocket *fd_p)
965{
966 dbus_bool_t retval;
967
968 if (transport->vtable->get_socket_fd == NULL)
969 return FALSE;
970
971 if (transport->disconnected)
972 return FALSE;
973
974 _dbus_transport_ref (transport);
975
976 retval = (* transport->vtable->get_socket_fd) (transport,
977 fd_p);
978
979 _dbus_transport_unref (transport);
980
981 return retval;
982}
983
995void
996_dbus_transport_do_iteration (DBusTransport *transport,
997 unsigned int flags,
998 int timeout_milliseconds)
999{
1000 _dbus_assert (transport->vtable->do_iteration != NULL);
1001
1002 _dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
1003 flags, timeout_milliseconds, !transport->disconnected);
1004
1005 if ((flags & (DBUS_ITERATION_DO_WRITING |
1006 DBUS_ITERATION_DO_READING)) == 0)
1007 return; /* Nothing to do */
1008
1009 if (transport->disconnected)
1010 return;
1011
1012 _dbus_transport_ref (transport);
1013 (* transport->vtable->do_iteration) (transport, flags,
1014 timeout_milliseconds);
1015 _dbus_transport_unref (transport);
1016
1017 _dbus_verbose ("end\n");
1018}
1019
1020static dbus_bool_t
1021recover_unused_bytes (DBusTransport *transport)
1022{
1023 if (_dbus_auth_needs_decoding (transport->auth))
1024 {
1025 DBusString plaintext;
1026 const DBusString *encoded;
1027 DBusString *buffer;
1028 int orig_len;
1029
1030 if (!_dbus_string_init (&plaintext))
1031 goto nomem;
1032
1033 _dbus_auth_get_unused_bytes (transport->auth,
1034 &encoded);
1035
1036 if (!_dbus_auth_decode_data (transport->auth,
1037 encoded, &plaintext))
1038 {
1039 _dbus_string_free (&plaintext);
1040 goto nomem;
1041 }
1042
1043 _dbus_message_loader_get_buffer (transport->loader,
1044 &buffer,
1045 NULL,
1046 NULL);
1047
1048 orig_len = _dbus_string_get_length (buffer);
1049
1050 if (!_dbus_string_move (&plaintext, 0, buffer,
1051 orig_len))
1052 {
1053 _dbus_string_free (&plaintext);
1054 goto nomem;
1055 }
1056
1057 _dbus_verbose (" %d unused bytes sent to message loader\n",
1058 _dbus_string_get_length (buffer) -
1059 orig_len);
1060
1061 _dbus_message_loader_return_buffer (transport->loader,
1062 buffer);
1063
1064 _dbus_auth_delete_unused_bytes (transport->auth);
1065
1066 _dbus_string_free (&plaintext);
1067 }
1068 else
1069 {
1070 const DBusString *bytes;
1071 DBusString *buffer;
1072#ifdef DBUS_ENABLE_VERBOSE_MODE
1073 int orig_len;
1074#endif
1075 dbus_bool_t succeeded;
1076
1077 _dbus_message_loader_get_buffer (transport->loader,
1078 &buffer,
1079 NULL,
1080 NULL);
1081
1082#ifdef DBUS_ENABLE_VERBOSE_MODE
1083 orig_len = _dbus_string_get_length (buffer);
1084#endif
1085
1086 _dbus_auth_get_unused_bytes (transport->auth,
1087 &bytes);
1088
1089 succeeded = TRUE;
1090 if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
1091 succeeded = FALSE;
1092
1093 _dbus_verbose (" %d unused bytes sent to message loader\n",
1094 _dbus_string_get_length (buffer) -
1095 orig_len);
1096
1097 _dbus_message_loader_return_buffer (transport->loader,
1098 buffer);
1099
1100 if (succeeded)
1101 _dbus_auth_delete_unused_bytes (transport->auth);
1102 else
1103 goto nomem;
1104 }
1105
1106 return TRUE;
1107
1108 nomem:
1109 _dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
1110 return FALSE;
1111}
1112
1120 DBusDispatchStatus
1121_dbus_transport_get_dispatch_status (DBusTransport *transport)
1122{
1123 if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size ||
1124 _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds)
1125 return DBUS_DISPATCH_COMPLETE; /* complete for now */
1126
1127 if (!_dbus_transport_try_to_authenticate (transport))
1128 {
1129 if (_dbus_auth_do_work (transport->auth) ==
1130 DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
1131 return DBUS_DISPATCH_NEED_MEMORY;
1132 else if (!_dbus_transport_try_to_authenticate (transport))
1133 return DBUS_DISPATCH_COMPLETE;
1134 }
1135
1136 if (!transport->unused_bytes_recovered &&
1137 !recover_unused_bytes (transport))
1138 return DBUS_DISPATCH_NEED_MEMORY;
1139
1140 transport->unused_bytes_recovered = TRUE;
1141
1142 if (!_dbus_message_loader_queue_messages (transport->loader))
1143 return DBUS_DISPATCH_NEED_MEMORY;
1144
1145 if (_dbus_message_loader_peek_message (transport->loader) != NULL)
1146 return DBUS_DISPATCH_DATA_REMAINS;
1147 else
1148 return DBUS_DISPATCH_COMPLETE;
1149}
1150
1159dbus_bool_t
1160_dbus_transport_queue_messages (DBusTransport *transport)
1161{
1162 DBusDispatchStatus status;
1163
1164#if 0
1165 _dbus_verbose ("enter\n");
1166#endif
1167
1168 /* Queue any messages */
1169 while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
1170 {
1171 DBusMessage *message;
1172 DBusList *link;
1173
1174 link = _dbus_message_loader_pop_message_link (transport->loader);
1175 _dbus_assert (link != NULL);
1176
1177 message = link->data;
1178
1179 _dbus_verbose ("queueing received message %p\n", message);
1180
1181 if (!_dbus_message_add_counter (message, transport->live_messages))
1182 {
1183 _dbus_message_loader_putback_message_link (transport->loader,
1184 link);
1185 status = DBUS_DISPATCH_NEED_MEMORY;
1186 break;
1187 }
1188 else
1189 {
1190 /* We didn't call the notify function when we added the counter, so
1191 * catch up now. Since we have the connection's lock, it's desirable
1192 * that we bypass the notify function and call this virtual method
1193 * directly. */
1194 if (transport->vtable->live_messages_changed)
1195 (* transport->vtable->live_messages_changed) (transport);
1196
1197 /* pass ownership of link and message ref to connection */
1198 _dbus_connection_queue_received_message_link (transport->connection,
1199 link);
1200 }
1201 }
1202
1203 if (_dbus_message_loader_get_is_corrupted (transport->loader))
1204 {
1205 _dbus_verbose ("Corrupted message stream, disconnecting\n");
1206 _dbus_transport_disconnect (transport);
1207 }
1208
1209 return status != DBUS_DISPATCH_NEED_MEMORY;
1210}
1211
1218void
1219_dbus_transport_set_max_message_size (DBusTransport *transport,
1220 long size)
1221{
1222 _dbus_message_loader_set_max_message_size (transport->loader, size);
1223}
1224
1231void
1232_dbus_transport_set_max_message_unix_fds (DBusTransport *transport,
1233 long n)
1234{
1235 _dbus_message_loader_set_max_message_unix_fds (transport->loader, n);
1236}
1237
1244long
1245_dbus_transport_get_max_message_size (DBusTransport *transport)
1246{
1247 return _dbus_message_loader_get_max_message_size (transport->loader);
1248}
1249
1256long
1257_dbus_transport_get_max_message_unix_fds (DBusTransport *transport)
1258{
1259 return _dbus_message_loader_get_max_message_unix_fds (transport->loader);
1260}
1261
1268void
1269_dbus_transport_set_max_received_size (DBusTransport *transport,
1270 long size)
1271{
1272 transport->max_live_messages_size = size;
1273 _dbus_counter_set_notify (transport->live_messages,
1274 transport->max_live_messages_size,
1275 transport->max_live_messages_unix_fds,
1276 live_messages_notify,
1277 transport);
1278}
1279
1286void
1287_dbus_transport_set_max_received_unix_fds (DBusTransport *transport,
1288 long n)
1289{
1290 transport->max_live_messages_unix_fds = n;
1291 _dbus_counter_set_notify (transport->live_messages,
1292 transport->max_live_messages_size,
1293 transport->max_live_messages_unix_fds,
1294 live_messages_notify,
1295 transport);
1296}
1297
1304long
1305_dbus_transport_get_max_received_size (DBusTransport *transport)
1306{
1307 return transport->max_live_messages_size;
1308}
1309
1316long
1317_dbus_transport_get_max_received_unix_fds (DBusTransport *transport)
1318{
1319 return transport->max_live_messages_unix_fds;
1320}
1321
1329dbus_bool_t
1330_dbus_transport_get_unix_user (DBusTransport *transport,
1331 unsigned long *uid)
1332{
1333 DBusCredentials *auth_identity;
1334
1335 *uid = _DBUS_INT32_MAX; /* better than some root or system user in
1336 * case of bugs in the caller. Caller should
1337 * never use this value on purpose, however.
1338 */
1339
1340 if (!transport->authenticated)
1341 return FALSE;
1342
1343 auth_identity = _dbus_auth_get_identity (transport->auth);
1344
1345 if (_dbus_credentials_include (auth_identity,
1346 DBUS_CREDENTIAL_UNIX_USER_ID))
1347 {
1348 *uid = _dbus_credentials_get_unix_uid (auth_identity);
1349 return TRUE;
1350 }
1351 else
1352 return FALSE;
1353}
1354
1362dbus_bool_t
1363_dbus_transport_get_unix_process_id (DBusTransport *transport,
1364 unsigned long *pid)
1365{
1366 DBusCredentials *auth_identity;
1367
1368 *pid = DBUS_PID_UNSET; /* Caller should never use this value on purpose,
1369 * but we set it to a safe number, INT_MAX,
1370 * just to root out possible bugs in bad callers.
1371 */
1372
1373 if (!transport->authenticated)
1374 return FALSE;
1375
1376 auth_identity = _dbus_auth_get_identity (transport->auth);
1377
1378 if (_dbus_credentials_include (auth_identity,
1379 DBUS_CREDENTIAL_UNIX_PROCESS_ID))
1380 {
1381 *pid = _dbus_credentials_get_pid (auth_identity);
1382 return TRUE;
1383 }
1384 else
1385 return FALSE;
1386}
1387
1396dbus_bool_t
1397_dbus_transport_get_adt_audit_session_data (DBusTransport *transport,
1398 void **data,
1399 int *data_size)
1400{
1401 DBusCredentials *auth_identity;
1402
1403 *data = NULL;
1404 *data_size = 0;
1405
1406 if (!transport->authenticated)
1407 return FALSE;
1408
1409 auth_identity = _dbus_auth_get_identity (transport->auth);
1410
1411 if (_dbus_credentials_include (auth_identity,
1412 DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID))
1413 {
1414 *data = (void *) _dbus_credentials_get_adt_audit_data (auth_identity);
1415 *data_size = _dbus_credentials_get_adt_audit_data_size (auth_identity);
1416 return TRUE;
1417 }
1418 else
1419 return FALSE;
1420}
1421
1432void
1433_dbus_transport_set_unix_user_function (DBusTransport *transport,
1434 DBusAllowUnixUserFunction function,
1435 void *data,
1436 DBusFreeFunction free_data_function,
1437 void **old_data,
1438 DBusFreeFunction *old_free_data_function)
1439{
1440 *old_data = transport->unix_user_data;
1441 *old_free_data_function = transport->free_unix_user_data;
1442
1443 transport->unix_user_function = function;
1444 transport->unix_user_data = data;
1445 transport->free_unix_user_data = free_data_function;
1446}
1447
1448dbus_bool_t
1449_dbus_transport_get_linux_security_label (DBusTransport *transport,
1450 char **label_p)
1451{
1452 DBusCredentials *auth_identity;
1453
1454 *label_p = NULL;
1455
1456 if (!transport->authenticated)
1457 return FALSE;
1458
1459 auth_identity = _dbus_auth_get_identity (transport->auth);
1460
1461 if (_dbus_credentials_include (auth_identity,
1462 DBUS_CREDENTIAL_LINUX_SECURITY_LABEL))
1463 {
1464 /* If no memory, we are supposed to return TRUE and set NULL */
1465 *label_p = _dbus_strdup (_dbus_credentials_get_linux_security_label (auth_identity));
1466
1467 return TRUE;
1468 }
1469 else
1470 {
1471 return FALSE;
1472 }
1473}
1474
1482 DBusCredentials *
1483_dbus_transport_get_credentials (DBusTransport *transport)
1484{
1485 if (!transport->authenticated)
1486 return FALSE;
1487
1488 return _dbus_auth_get_identity (transport->auth);
1489}
1490
1498dbus_bool_t
1499_dbus_transport_get_windows_user (DBusTransport *transport,
1500 char **windows_sid_p)
1501{
1502 DBusCredentials *auth_identity;
1503
1504 *windows_sid_p = NULL;
1505
1506 if (!transport->authenticated)
1507 return FALSE;
1508
1509 auth_identity = _dbus_auth_get_identity (transport->auth);
1510
1511 if (_dbus_credentials_include (auth_identity,
1512 DBUS_CREDENTIAL_WINDOWS_SID))
1513 {
1514 /* If no memory, we are supposed to return TRUE and set NULL */
1515 *windows_sid_p = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
1516
1517 return TRUE;
1518 }
1519 else
1520 return FALSE;
1521}
1522
1534void
1535_dbus_transport_set_windows_user_function (DBusTransport *transport,
1536 DBusAllowWindowsUserFunction function,
1537 void *data,
1538 DBusFreeFunction free_data_function,
1539 void **old_data,
1540 DBusFreeFunction *old_free_data_function)
1541{
1542 *old_data = transport->windows_user_data;
1543 *old_free_data_function = transport->free_windows_user_data;
1544
1545 transport->windows_user_function = function;
1546 transport->windows_user_data = data;
1547 transport->free_windows_user_data = free_data_function;
1548}
1549
1558dbus_bool_t
1559_dbus_transport_set_auth_mechanisms (DBusTransport *transport,
1560 const char **mechanisms)
1561{
1562 return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
1563}
1564
1571void
1572_dbus_transport_set_allow_anonymous (DBusTransport *transport,
1573 dbus_bool_t value)
1574{
1575 transport->allow_anonymous = value != FALSE;
1576}
1577
1583int
1584_dbus_transport_get_pending_fds_count (DBusTransport *transport)
1585{
1586 return _dbus_message_loader_get_pending_fds_count (transport->loader);
1587}
1588
1596void
1597_dbus_transport_set_pending_fds_function (DBusTransport *transport,
1598 void (* callback) (void *),
1599 void *data)
1600{
1601 _dbus_message_loader_set_pending_fds_function (transport->loader,
1602 callback, data);
1603}
1604
1605#ifdef DBUS_ENABLE_STATS
1606void
1607_dbus_transport_get_stats (DBusTransport *transport,
1608 dbus_uint32_t *queue_bytes,
1609 dbus_uint32_t *queue_fds,
1610 dbus_uint32_t *peak_queue_bytes,
1611 dbus_uint32_t *peak_queue_fds)
1612{
1613 if (queue_bytes != NULL)
1614 *queue_bytes = _dbus_counter_get_size_value (transport->live_messages);
1615
1616 if (queue_fds != NULL)
1617 *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages);
1618
1619 if (peak_queue_bytes != NULL)
1620 *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages);
1621
1622 if (peak_queue_fds != NULL)
1623 *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages);
1624}
1625#endif /* DBUS_ENABLE_STATS */
1626
_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:68
dbus_address_entries_free
void dbus_address_entries_free(DBusAddressEntry **entries)
Frees a NULL-terminated array of address entries.
Definition dbus-address.c:192
dbus_parse_address
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
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:230
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:247
_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:2538
_dbus_auth_get_identity
DBusCredentials * _dbus_auth_get_identity(DBusAuth *auth)
Gets the identity we authorized the client as.
Definition dbus-auth.c:2838
_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:2788
_dbus_auth_unref
void _dbus_auth_unref(DBusAuth *auth)
Decrements the refcount of an auth object.
Definition dbus-auth.c:2453
_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:2503
_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've gotten them and succes...
Definition dbus-auth.c:2681
_dbus_auth_get_guid_from_server
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_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:2757
_dbus_auth_client_new
DBusAuth * _dbus_auth_client_new(void)
Creates a new auth conversation object for the client side.
Definition dbus-auth.c:2400
_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:2354
_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:2664
_dbus_connection_unlock
DBUS_PRIVATE_EXPORT void _dbus_connection_unlock(DBusConnection *connection)
Releases the connection lock.
Definition dbus-connection.c:401
_dbus_connection_lock
DBUS_PRIVATE_EXPORT void _dbus_connection_lock(DBusConnection *connection)
Acquires the connection lock.
Definition dbus-connection.c:390
_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:1445
_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:482
_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:1422
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:144
DBusDispatchStatus
DBusDispatchStatus
Indicates the status of incoming data on a DBusConnection.
Definition dbus-connection.h:81
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:154
DBUS_DISPATCH_NEED_MEMORY
@ DBUS_DISPATCH_NEED_MEMORY
More memory is needed to continue.
Definition dbus-connection.h:84
DBUS_DISPATCH_COMPLETE
@ DBUS_DISPATCH_COMPLETE
All currently available data has been processed.
Definition dbus-connection.h:83
DBUS_DISPATCH_DATA_REMAINS
@ DBUS_DISPATCH_DATA_REMAINS
There is more data to potentially convert to messages.
Definition dbus-connection.h:82
_dbus_credentials_include
dbus_bool_t _dbus_credentials_include(DBusCredentials *credentials, DBusCredentialType type)
Checks whether the given credential is present.
Definition dbus-credentials.c:318
_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:645
_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't contain...
Definition dbus-credentials.c:362
_dbus_credentials_new_from_current_process
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...
Definition dbus-credentials.c:100
_dbus_credentials_new
DBusCredentials * _dbus_credentials_new(void)
Creates a new credentials object.
Definition dbus-credentials.c:74
_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't contain ADT aud...
Definition dbus-credentials.c:401
_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:388
_dbus_credentials_unref
void _dbus_credentials_unref(DBusCredentials *credentials)
Decrement refcount on credentials.
Definition dbus-credentials.c:135
_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't cont...
Definition dbus-credentials.c:349
_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't contain ADT a...
Definition dbus-credentials.c:414
_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't contain a Win...
Definition dbus-credentials.c:375
_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:479
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition dbus-errors.h:62
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
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
dbus_error_free
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_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_assert_not_reached
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
Definition dbus-internals.h:164
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition dbus-internals.h:153
_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:270
_dbus_strdup
char * _dbus_strdup(const char *str)
Duplicates a string.
Definition dbus-internals.c:589
_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_INT32_MAX
#define _DBUS_INT32_MAX
Maximum value of type "int32".
Definition dbus-internals.h:307
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:49
TRUE
#define TRUE
Expands to "1".
Definition dbus-macros.h:39
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:42
DBusFreeFunction
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
Definition dbus-memory.h:63
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition dbus-memory.c:692
_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:4825
_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:4796
_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:4221
_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:4904
_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:4780
_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:4886
_dbus_message_loader_get_buffer
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.
Definition dbus-message.c:4256
_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,...
Definition dbus-message.c:364
_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:4737
_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:4856
_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:4844
_dbus_message_loader_new
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
Definition dbus-message.c:4159
_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:4768
_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:4674
_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:4362
_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:4875
DBUS_ERROR_NO_MEMORY
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
Definition dbus-protocol.h:361
_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's value...
Definition dbus-resources.c:311
_dbus_counter_new
DBusCounter * _dbus_counter_new(void)
Creates a new DBusCounter.
Definition dbus-resources.c:89
_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:290
_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_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_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition dbus-string.c:182
_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's copied to the d...
Definition dbus-string.c:1343
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
Definition dbus-string.c:278
_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:703
_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:1319
dbus_uid_t
unsigned long dbus_uid_t
A user ID.
Definition dbus-sysdeps.h:137
DBUS_PID_UNSET
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
Definition dbus-sysdeps.h:142
DBUS_UID_FORMAT
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
Definition dbus-sysdeps.h:151
_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:4133
_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:1454
_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-unix.c:221
_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:1219
_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:1269
_dbus_transport_get_dispatch_status
DBusDispatchStatus _dbus_transport_get_dispatch_status(DBusTransport *transport)
Reports our current dispatch status (whether there's buffered data to be queued as messages,...
Definition dbus-transport.c:1121
_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:1559
_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:1584
_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:1397
_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:1499
_dbus_transport_queue_messages
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...
Definition dbus-transport.c:1160
_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:963
_dbus_transport_get_address
const char * _dbus_transport_get_address(DBusTransport *transport)
Gets the address of a transport.
Definition dbus-transport.c:868
_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:901
_dbus_transport_ref
DBusTransport * _dbus_transport_ref(DBusTransport *transport)
Increments the reference count for the transport.
Definition dbus-transport.c:463
_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
_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:1572
_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_get_max_received_size
long _dbus_transport_get_max_received_size(DBusTransport *transport)
See dbus_connection_get_max_received_size().
Definition dbus-transport.c:1305
_dbus_transport_get_credentials
DBusCredentials * _dbus_transport_get_credentials(DBusTransport *transport)
If the transport has already been authenticated, return its credentials.
Definition dbus-transport.c:1483
_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:939
_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:1433
_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:1257
_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_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:1287
_dbus_transport_unref
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
Definition dbus-transport.c:480
_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:855
_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_transport_do_iteration
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...
Definition dbus-transport.c:996
_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:1317
_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_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:1232
_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:1597
_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:1535
_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:1245
_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:1363
_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:367
_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:881
_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:833
_dbus_transport_finalize_base
void _dbus_transport_finalize_base(DBusTransport *transport)
Finalizes base class members of DBusTransport.
Definition dbus-transport.c:216
_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:1330
_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
_dbus_watch_ref
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
Definition dbus-watch.c:124
_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_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:593
DBusAddressEntry
Internals of DBusAddressEntry.
Definition dbus-address.c:47
DBusAuth
Internal members of DBusAuth.
Definition dbus-auth.c:154
DBusConnection
Implementation details of DBusConnection.
Definition dbus-connection.c:257
DBusCounter
Internals of DBusCounter.
Definition dbus-resources.c:55
DBusCredentials
Definition dbus-credentials.c:49
DBusError
Object representing an exception.
Definition dbus-errors.h:49
DBusList
A node in a linked list.
Definition dbus-list.h:35
DBusList::data
void * data
Data stored at this element.
Definition dbus-list.h:38
DBusMessageLoader
Implementation details of DBusMessageLoader.
Definition dbus-message-private.h:61
DBusMessage
Internals of DBusMessage.
Definition dbus-message-private.h:100
DBusSocket
Socket interface.
Definition dbus-sysdeps.h:181
DBusString
Definition dbus-string.h:43
DBusTransportVTable
The virtual table that must be implemented to create a new kind of transport.
Definition dbus-transport-protected.h:42
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
DBusTransportVTable::disconnect
void(* disconnect)(DBusTransport *transport)
Disconnect this transport.
Definition dbus-transport-protected.h:53
DBusTransportVTable::live_messages_changed
void(* live_messages_changed)(DBusTransport *transport)
Outstanding messages counter changed.
Definition dbus-transport-protected.h:66
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
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
DBusTransportVTable::finalize
void(* finalize)(DBusTransport *transport)
The finalize method must free the transport.
Definition dbus-transport-protected.h:43
DBusTransportVTable::connection_set
dbus_bool_t(* connection_set)(DBusTransport *transport)
Called when transport->connection has been filled in.
Definition dbus-transport-protected.h:56
DBusTransport
Object representing a transport such as a socket.
Definition dbus-transport-protected.h:81
DBusTransport::authenticated
unsigned int authenticated
Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value.
Definition dbus-transport-protected.h:114
DBusTransport::windows_user_function
DBusAllowWindowsUserFunction windows_user_function
Function for checking whether a user is authorized.
Definition dbus-transport-protected.h:108
DBusTransport::refcount
int refcount
Reference count.
Definition dbus-transport-protected.h:82
DBusTransport::max_live_messages_size
long max_live_messages_size
Max total size of received messages.
Definition dbus-transport-protected.h:94
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
DBusTransport::allow_anonymous
unsigned int allow_anonymous
TRUE if an anonymous client can connect
Definition dbus-transport-protected.h:119
DBusTransport::windows_user_data
void * windows_user_data
Data for windows_user_function.
Definition dbus-transport-protected.h:109
DBusTransport::is_server
unsigned int is_server
TRUE if on the server side
Definition dbus-transport-protected.h:117
DBusTransport::disconnected
unsigned int disconnected
TRUE if we are disconnected.
Definition dbus-transport-protected.h:113
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
DBusTransport::unused_bytes_recovered
unsigned int unused_bytes_recovered
TRUE if we've recovered unused bytes from auth
Definition dbus-transport-protected.h:118
DBusTransport::vtable
const DBusTransportVTable * vtable
Virtual methods for this instance.
Definition dbus-transport-protected.h:84
DBusTransport::free_unix_user_data
DBusFreeFunction free_unix_user_data
Function to free unix_user_data.
Definition dbus-transport-protected.h:106
DBusTransport::send_credentials_pending
unsigned int send_credentials_pending
TRUE if we need to send credentials
Definition dbus-transport-protected.h:115
DBusTransport::unix_user_data
void * unix_user_data
Data for unix_user_function.
Definition dbus-transport-protected.h:104
DBusTransport::connection
DBusConnection * connection
Connection owning this transport.
Definition dbus-transport-protected.h:86
DBusTransport::receive_credentials_pending
unsigned int receive_credentials_pending
TRUE if we need to receive credentials
Definition dbus-transport-protected.h:116
DBusTransport::loader
DBusMessageLoader * loader
Message-loading buffer.
Definition dbus-transport-protected.h:88
DBusTransport::expected_guid
char * expected_guid
GUID we expect the server to have, NULL on server side or if we don't have an expectation.
Definition dbus-transport-protected.h:101
DBusTransport::free_windows_user_data
DBusFreeFunction free_windows_user_data
Function to free windows_user_data.
Definition dbus-transport-protected.h:111
DBusTransport::unix_user_function
DBusAllowUnixUserFunction unix_user_function
Function for checking whether a user is authorized.
Definition dbus-transport-protected.h:103
DBusTransport::credentials
DBusCredentials * credentials
Credentials of other end read from the socket.
Definition dbus-transport-protected.h:92
DBusTransport::auth
DBusAuth * auth
Authentication conversation.
Definition dbus-transport-protected.h:90
DBusTransport::live_messages
DBusCounter * live_messages
Counter for size/unix fds of all live messages.
Definition dbus-transport-protected.h:97
DBusWatch
Implementation of DBusWatch.
Definition dbus-watch.c:41