D-Bus 1.12.4

dbus-auth-script.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-auth-script.c Test DBusAuth using a special script file (internal to D-Bus implementation)
3 *
4 * Copyright (C) 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#include <config.h>
24
25#ifdef DBUS_ENABLE_EMBEDDED_TESTS
26
27#include "dbus-auth-script.h"
28
29#include <stdio.h>
30
31#include "dbus-auth.h"
32#include "dbus-string.h"
33#include "dbus-hash.h"
34#include "dbus-credentials.h"
35#include "dbus-internals.h"
36
48/* this is slightly different from the other append_quoted_string
49 * in dbus-message-builder.c
50 */
51 static dbus_bool_t
52append_quoted_string (DBusString *dest,
53 const DBusString *quoted)
54{
55 dbus_bool_t in_quotes = FALSE;
56 dbus_bool_t in_backslash = FALSE;
57 int i;
58
59 i = 0;
60 while (i < _dbus_string_get_length (quoted))
61 {
62 unsigned char b;
63
64 b = _dbus_string_get_byte (quoted, i);
65
66 if (in_backslash)
67 {
68 unsigned char a;
69
70 if (b == 'r')
71 a = '\r';
72 else if (b == 'n')
73 a = '\n';
74 else if (b == '\\')
75 a = '\\';
76 else
77 {
78 _dbus_warn ("bad backslashed byte %c", b);
79 return FALSE;
80 }
81
82 if (!_dbus_string_append_byte (dest, a))
83 return FALSE;
84
85 in_backslash = FALSE;
86 }
87 else if (b == '\\')
88 {
89 in_backslash = TRUE;
90 }
91 else if (in_quotes)
92 {
93 if (b == '\'')
94 in_quotes = FALSE;
95 else
96 {
97 if (!_dbus_string_append_byte (dest, b))
98 return FALSE;
99 }
100 }
101 else
102 {
103 if (b == '\'')
104 in_quotes = TRUE;
105 else if (b == ' ' || b == '\n' || b == '\t')
106 break; /* end on whitespace if not quoted */
107 else
108 {
109 if (!_dbus_string_append_byte (dest, b))
110 return FALSE;
111 }
112 }
113
114 ++i;
115 }
116
117 return TRUE;
118}
119
120 static dbus_bool_t
121same_first_word (const DBusString *a,
122 const DBusString *b)
123{
124 int first_a_blank, first_b_blank;
125
126 _dbus_string_find_blank (a, 0, &first_a_blank);
127 _dbus_string_find_blank (b, 0, &first_b_blank);
128
129 if (first_a_blank != first_b_blank)
130 return FALSE;
131
132 return _dbus_string_equal_len (a, b, first_a_blank);
133}
134
135 static DBusAuthState
136auth_state_from_string (const DBusString *str)
137{
138 if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_INPUT"))
139 return DBUS_AUTH_STATE_WAITING_FOR_INPUT;
140 else if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_MEMORY"))
141 return DBUS_AUTH_STATE_WAITING_FOR_MEMORY;
142 else if (_dbus_string_starts_with_c_str (str, "HAVE_BYTES_TO_SEND"))
143 return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND;
144 else if (_dbus_string_starts_with_c_str (str, "NEED_DISCONNECT"))
145 return DBUS_AUTH_STATE_NEED_DISCONNECT;
146 else if (_dbus_string_starts_with_c_str (str, "AUTHENTICATED"))
147 return DBUS_AUTH_STATE_AUTHENTICATED;
148 else
149 return DBUS_AUTH_STATE_INVALID;
150}
151
152 static const char*
153auth_state_to_string (DBusAuthState state)
154{
155 switch (state)
156 {
157 case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
158 return "WAITING_FOR_INPUT";
159 case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
160 return "WAITING_FOR_MEMORY";
161 case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
162 return "HAVE_BYTES_TO_SEND";
163 case DBUS_AUTH_STATE_NEED_DISCONNECT:
164 return "NEED_DISCONNECT";
165 case DBUS_AUTH_STATE_AUTHENTICATED:
166 return "AUTHENTICATED";
167 case DBUS_AUTH_STATE_INVALID:
168 return "INVALID";
169 default:
170 break;
171 }
172
173 return "unknown";
174}
175
176 static char **
177split_string (DBusString *str)
178{
179 int i, j, k, count, end;
180 char **array;
181
182 end = _dbus_string_get_length (str);
183
184 i = 0;
185 _dbus_string_skip_blank (str, i, &i);
186 for (count = 0; i < end; count++)
187 {
188 _dbus_string_find_blank (str, i, &i);
189 _dbus_string_skip_blank (str, i, &i);
190 }
191
192 array = dbus_new0 (char *, count + 1);
193 if (array == NULL)
194 return NULL;
195
196 i = 0;
197 _dbus_string_skip_blank (str, i, &i);
198 for (k = 0; k < count; k++)
199 {
200 _dbus_string_find_blank (str, i, &j);
201
202 array[k] = dbus_malloc (j - i + 1);
203 if (array[k] == NULL)
204 {
205 dbus_free_string_array (array);
206 return NULL;
207 }
208 memcpy (array[k],
209 _dbus_string_get_const_data_len (str, i, j - i), j - i);
210 array[k][j - i] = '\0';
211
212 _dbus_string_skip_blank (str, j, &i);
213 }
214 array[k] = NULL;
215
216 return array;
217}
218
219 static void
220auth_set_unix_credentials(DBusAuth *auth,
221 dbus_uid_t uid,
222 dbus_pid_t pid)
223{
224 DBusCredentials *credentials;
225
226 credentials = _dbus_credentials_new ();
227 if (credentials == NULL)
228 _dbus_assert_not_reached ("no memory");
229
230 if (uid != DBUS_UID_UNSET)
231 {
232 if (!_dbus_credentials_add_unix_uid (credentials, uid))
233 _dbus_assert_not_reached ("no memory");
234 }
235 if (pid != DBUS_PID_UNSET)
236 {
237 if (!_dbus_credentials_add_pid (credentials, pid))
238 _dbus_assert_not_reached ("no memory");
239 }
240 _dbus_auth_set_credentials (auth, credentials);
241
242 _dbus_credentials_unref (credentials);
243}
244
255 dbus_bool_t
256_dbus_auth_script_run (const DBusString *filename)
257{
258 DBusString file;
259 DBusError error = DBUS_ERROR_INIT;
260 DBusString line;
261 dbus_bool_t retval;
262 int line_no;
263 DBusAuth *auth;
264 DBusString from_auth;
265 DBusAuthState state;
266 DBusString context;
267 DBusString guid;
268
269 retval = FALSE;
270 auth = NULL;
271
272 _dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00");
273 _dbus_string_init_const (&context, "org_freedesktop_test");
274
275 if (!_dbus_string_init (&file))
276 return FALSE;
277
278 if (!_dbus_string_init (&line))
279 {
280 _dbus_string_free (&file);
281 return FALSE;
282 }
283
284 if (!_dbus_string_init (&from_auth))
285 {
286 _dbus_string_free (&file);
287 _dbus_string_free (&line);
288 return FALSE;
289 }
290
291 if (!_dbus_file_get_contents (&file, filename, &error)) {
292 _dbus_warn ("Getting contents of %s failed: %s",
293 _dbus_string_get_const_data (filename), error.message);
294 dbus_error_free (&error);
295 goto out;
296 }
297
298 state = DBUS_AUTH_STATE_NEED_DISCONNECT;
299 line_no = 0;
300
301 next_iteration:
302 while (_dbus_string_pop_line (&file, &line))
303 {
304 line_no += 1;
305
306 /* _dbus_warn ("%s", _dbus_string_get_const_data (&line)); */
307
308 _dbus_string_delete_leading_blanks (&line);
309
310 if (auth != NULL)
311 {
312 while ((state = _dbus_auth_do_work (auth)) ==
313 DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
314 {
315 const DBusString *tmp;
316 if (_dbus_auth_get_bytes_to_send (auth, &tmp))
317 {
318 int count = _dbus_string_get_length (tmp);
319
320 if (_dbus_string_copy (tmp, 0, &from_auth,
321 _dbus_string_get_length (&from_auth)))
322 _dbus_auth_bytes_sent (auth, count);
323 }
324 }
325 }
326
327 if (_dbus_string_get_length (&line) == 0)
328 {
329 /* empty line */
330 goto next_iteration;
331 }
332 else if (_dbus_string_starts_with_c_str (&line,
333 "#"))
334 {
335 /* Ignore this comment */
336 goto next_iteration;
337 }
338#ifdef DBUS_WIN
339 else if (_dbus_string_starts_with_c_str (&line,
340 "WIN_ONLY"))
341 {
342 /* Ignore this line */
343 goto next_iteration;
344 }
345 else if (_dbus_string_starts_with_c_str (&line,
346 "UNIX_ONLY"))
347 {
348 /* skip this file */
349 fprintf (stderr, "skipping unix only auth script\n");
350 retval = TRUE;
351 goto out;
352 }
353#endif
354#ifdef DBUS_UNIX
355 else if (_dbus_string_starts_with_c_str (&line,
356 "UNIX_ONLY"))
357 {
358 /* Ignore this line */
359 goto next_iteration;
360 }
361 else if (_dbus_string_starts_with_c_str (&line,
362 "WIN_ONLY"))
363 {
364 /* skip this file */
365 fprintf (stderr, "skipping windows only auth script\n");
366 retval = TRUE;
367 goto out;
368 }
369#endif
370 else if (_dbus_string_starts_with_c_str (&line,
371 "CLIENT"))
372 {
373 DBusCredentials *creds;
374
375 if (auth != NULL)
376 {
377 _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)");
378 goto out;
379 }
380
381 auth = _dbus_auth_client_new ();
382 if (auth == NULL)
383 {
384 _dbus_warn ("no memory to create DBusAuth");
385 goto out;
386 }
387
388 /* test ref/unref */
389 _dbus_auth_ref (auth);
390 _dbus_auth_unref (auth);
391
392 creds = _dbus_credentials_new_from_current_process ();
393 if (creds == NULL)
394 {
395 _dbus_warn ("no memory for credentials");
396 _dbus_auth_unref (auth);
397 auth = NULL;
398 goto out;
399 }
400
401 if (!_dbus_auth_set_credentials (auth, creds))
402 {
403 _dbus_warn ("no memory for setting credentials");
404 _dbus_auth_unref (auth);
405 auth = NULL;
406 _dbus_credentials_unref (creds);
407 goto out;
408 }
409
410 _dbus_credentials_unref (creds);
411 }
412 else if (_dbus_string_starts_with_c_str (&line,
413 "SERVER"))
414 {
415 DBusCredentials *creds;
416
417 if (auth != NULL)
418 {
419 _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)");
420 goto out;
421 }
422
423 auth = _dbus_auth_server_new (&guid);
424 if (auth == NULL)
425 {
426 _dbus_warn ("no memory to create DBusAuth");
427 goto out;
428 }
429
430 /* test ref/unref */
431 _dbus_auth_ref (auth);
432 _dbus_auth_unref (auth);
433
434 creds = _dbus_credentials_new_from_current_process ();
435 if (creds == NULL)
436 {
437 _dbus_warn ("no memory for credentials");
438 _dbus_auth_unref (auth);
439 auth = NULL;
440 goto out;
441 }
442
443 if (!_dbus_auth_set_credentials (auth, creds))
444 {
445 _dbus_warn ("no memory for setting credentials");
446 _dbus_auth_unref (auth);
447 auth = NULL;
448 _dbus_credentials_unref (creds);
449 goto out;
450 }
451
452 _dbus_credentials_unref (creds);
453
454 _dbus_auth_set_context (auth, &context);
455 }
456 else if (auth == NULL)
457 {
458 _dbus_warn ("must specify CLIENT or SERVER");
459 goto out;
460
461 }
462 else if (_dbus_string_starts_with_c_str (&line,
463 "NO_CREDENTIALS"))
464 {
465 auth_set_unix_credentials (auth, DBUS_UID_UNSET, DBUS_PID_UNSET);
466 }
467 else if (_dbus_string_starts_with_c_str (&line,
468 "ROOT_CREDENTIALS"))
469 {
470 auth_set_unix_credentials (auth, 0, DBUS_PID_UNSET);
471 }
472 else if (_dbus_string_starts_with_c_str (&line,
473 "SILLY_CREDENTIALS"))
474 {
475 auth_set_unix_credentials (auth, 4312, DBUS_PID_UNSET);
476 }
477 else if (_dbus_string_starts_with_c_str (&line,
478 "ALLOWED_MECHS"))
479 {
480 char **mechs;
481
482 _dbus_string_delete_first_word (&line);
483 mechs = split_string (&line);
484 _dbus_auth_set_mechanisms (auth, (const char **) mechs);
485 dbus_free_string_array (mechs);
486 }
487 else if (_dbus_string_starts_with_c_str (&line,
488 "SEND"))
489 {
490 DBusString to_send;
491
492 _dbus_string_delete_first_word (&line);
493
494 if (!_dbus_string_init (&to_send))
495 {
496 _dbus_warn ("no memory to allocate string");
497 goto out;
498 }
499
500 if (!append_quoted_string (&to_send, &line))
501 {
502 _dbus_warn ("failed to append quoted string line %d",
503 line_no);
504 _dbus_string_free (&to_send);
505 goto out;
506 }
507
508 _dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send));
509
510 if (!_dbus_string_append (&to_send, "\r\n"))
511 {
512 _dbus_warn ("failed to append \\r\\n from line %d",
513 line_no);
514 _dbus_string_free (&to_send);
515 goto out;
516 }
517
518 /* Replace USERID_HEX with our username in hex */
519 {
520 int where;
521
522 if (_dbus_string_find (&to_send, 0,
523 "USERID_HEX", &where))
524 {
525 DBusString username;
526
527 if (!_dbus_string_init (&username))
528 {
529 _dbus_warn ("no memory for userid");
530 _dbus_string_free (&to_send);
531 goto out;
532 }
533
534 if (!_dbus_append_user_from_current_process (&username))
535 {
536 _dbus_warn ("no memory for userid");
537 _dbus_string_free (&username);
538 _dbus_string_free (&to_send);
539 goto out;
540 }
541
542 _dbus_string_delete (&to_send, where, (int) strlen ("USERID_HEX"));
543
544 if (!_dbus_string_hex_encode (&username, 0,
545 &to_send, where))
546 {
547 _dbus_warn ("no memory to subst USERID_HEX");
548 _dbus_string_free (&username);
549 _dbus_string_free (&to_send);
550 goto out;
551 }
552
553 _dbus_string_free (&username);
554 }
555 else if (_dbus_string_find (&to_send, 0,
556 "USERNAME_HEX", &where))
557 {
558 DBusString username;
559
560 if (!_dbus_string_init (&username))
561 {
562 _dbus_warn ("no memory for username");
563 _dbus_string_free (&to_send);
564 goto out;
565 }
566
567 if (!_dbus_append_user_from_current_process (&username))
568 {
569 _dbus_warn ("no memory for username");
570 _dbus_string_free (&username);
571 _dbus_string_free (&to_send);
572 goto out;
573 }
574
575 _dbus_string_delete (&to_send, where, (int) strlen ("USERNAME_HEX"));
576
577 if (!_dbus_string_hex_encode (&username, 0,
578 &to_send, where))
579 {
580 _dbus_warn ("no memory to subst USERNAME_HEX");
581 _dbus_string_free (&username);
582 _dbus_string_free (&to_send);
583 goto out;
584 }
585
586 _dbus_string_free (&username);
587 }
588 }
589
590 {
591 DBusString *buffer;
592
593 _dbus_auth_get_buffer (auth, &buffer);
594 if (!_dbus_string_copy (&to_send, 0,
595 buffer, _dbus_string_get_length (buffer)))
596 {
597 _dbus_warn ("not enough memory to call bytes_received, or can't add bytes to auth object already in end state");
598 _dbus_string_free (&to_send);
599 _dbus_auth_return_buffer (auth, buffer);
600 goto out;
601 }
602
603 _dbus_auth_return_buffer (auth, buffer);
604 }
605
606 _dbus_string_free (&to_send);
607 }
608 else if (_dbus_string_starts_with_c_str (&line,
609 "EXPECT_STATE"))
610 {
611 DBusAuthState expected;
612
613 _dbus_string_delete_first_word (&line);
614
615 expected = auth_state_from_string (&line);
616 if (expected < 0)
617 {
618 _dbus_warn ("bad auth state given to EXPECT_STATE");
619 goto parse_failed;
620 }
621
622 if (expected != state)
623 {
624 _dbus_warn ("expected auth state %s but got %s on line %d",
625 auth_state_to_string (expected),
626 auth_state_to_string (state),
627 line_no);
628 goto out;
629 }
630 }
631 else if (_dbus_string_starts_with_c_str (&line,
632 "EXPECT_COMMAND"))
633 {
634 DBusString received;
635
636 _dbus_string_delete_first_word (&line);
637
638 if (!_dbus_string_init (&received))
639 {
640 _dbus_warn ("no mem to allocate string received");
641 goto out;
642 }
643
644 if (!_dbus_string_pop_line (&from_auth, &received))
645 {
646 _dbus_warn ("no line popped from the DBusAuth being tested, expected command %s on line %d",
647 _dbus_string_get_const_data (&line), line_no);
648 _dbus_string_free (&received);
649 goto out;
650 }
651
652 if (!same_first_word (&received, &line))
653 {
654 _dbus_warn ("line %d expected command '%s' and got '%s'",
655 line_no,
656 _dbus_string_get_const_data (&line),
657 _dbus_string_get_const_data (&received));
658 _dbus_string_free (&received);
659 goto out;
660 }
661
662 _dbus_string_free (&received);
663 }
664 else if (_dbus_string_starts_with_c_str (&line,
665 "EXPECT_UNUSED"))
666 {
667 DBusString expected;
668 const DBusString *unused;
669
670 _dbus_string_delete_first_word (&line);
671
672 if (!_dbus_string_init (&expected))
673 {
674 _dbus_warn ("no mem to allocate string expected");
675 goto out;
676 }
677
678 if (!append_quoted_string (&expected, &line))
679 {
680 _dbus_warn ("failed to append quoted string line %d",
681 line_no);
682 _dbus_string_free (&expected);
683 goto out;
684 }
685
686 _dbus_auth_get_unused_bytes (auth, &unused);
687
688 if (_dbus_string_equal (&expected, unused))
689 {
690 _dbus_auth_delete_unused_bytes (auth);
691 _dbus_string_free (&expected);
692 }
693 else
694 {
695 _dbus_warn ("Expected unused bytes '%s' and have '%s'",
696 _dbus_string_get_const_data (&expected),
697 _dbus_string_get_const_data (unused));
698 _dbus_string_free (&expected);
699 goto out;
700 }
701 }
702 else if (_dbus_string_starts_with_c_str (&line,
703 "EXPECT_HAVE_NO_CREDENTIALS"))
704 {
705 DBusCredentials *authorized_identity;
706
707 authorized_identity = _dbus_auth_get_identity (auth);
708 if (!_dbus_credentials_are_anonymous (authorized_identity))
709 {
710 _dbus_warn ("Expected anonymous login or failed login, but some credentials were authorized");
711 goto out;
712 }
713 }
714 else if (_dbus_string_starts_with_c_str (&line,
715 "EXPECT_HAVE_SOME_CREDENTIALS"))
716 {
717 DBusCredentials *authorized_identity;
718
719 authorized_identity = _dbus_auth_get_identity (auth);
720 if (_dbus_credentials_are_anonymous (authorized_identity))
721 {
722 _dbus_warn ("Expected to have some credentials, but we don't");
723 goto out;
724 }
725 }
726 else if (_dbus_string_starts_with_c_str (&line,
727 "EXPECT"))
728 {
729 DBusString expected;
730
731 _dbus_string_delete_first_word (&line);
732
733 if (!_dbus_string_init (&expected))
734 {
735 _dbus_warn ("no mem to allocate string expected");
736 goto out;
737 }
738
739 if (!append_quoted_string (&expected, &line))
740 {
741 _dbus_warn ("failed to append quoted string line %d",
742 line_no);
743 _dbus_string_free (&expected);
744 goto out;
745 }
746
747 if (_dbus_string_equal_len (&expected, &from_auth,
748 _dbus_string_get_length (&expected)))
749 {
750 _dbus_string_delete (&from_auth, 0,
751 _dbus_string_get_length (&expected));
752 _dbus_string_free (&expected);
753 }
754 else
755 {
756 _dbus_warn ("Expected exact string '%s' and have '%s'",
757 _dbus_string_get_const_data (&expected),
758 _dbus_string_get_const_data (&from_auth));
759 _dbus_string_free (&expected);
760 goto out;
761 }
762 }
763 else
764 goto parse_failed;
765
766 goto next_iteration; /* skip parse_failed */
767
768 parse_failed:
769 {
770 _dbus_warn ("couldn't process line %d \"%s\"",
771 line_no, _dbus_string_get_const_data (&line));
772 goto out;
773 }
774 }
775
776 if (auth == NULL)
777 {
778 _dbus_warn ("Auth script is bogus, did not even have CLIENT or SERVER");
779 goto out;
780 }
781 else if (state == DBUS_AUTH_STATE_AUTHENTICATED)
782 {
783 const DBusString *unused;
784
785 _dbus_auth_get_unused_bytes (auth, &unused);
786
787 if (_dbus_string_get_length (unused) > 0)
788 {
789 _dbus_warn ("did not expect unused bytes (scripts must specify explicitly if they are expected)");
790 goto out;
791 }
792 }
793
794 if (_dbus_string_get_length (&from_auth) > 0)
795 {
796 _dbus_warn ("script did not have EXPECT_ statements for all the data received from the DBusAuth");
797 _dbus_warn ("Leftover data: %s", _dbus_string_get_const_data (&from_auth));
798 goto out;
799 }
800
801 retval = TRUE;
802
803 out:
804 if (auth)
805 _dbus_auth_unref (auth);
806
807 _dbus_string_free (&file);
808 _dbus_string_free (&line);
809 _dbus_string_free (&from_auth);
810
811 return retval;
812}
813
815#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
_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:2468
_dbus_auth_set_credentials
dbus_bool_t _dbus_auth_set_credentials(DBusAuth *auth, DBusCredentials *credentials)
Sets credentials received via reliable means from the operating system.
Definition: dbus-auth.c:2750
_dbus_auth_ref
DBusAuth * _dbus_auth_ref(DBusAuth *auth)
Increments the refcount of an auth object.
Definition: dbus-auth.c:2368
_dbus_auth_get_identity
DBusCredentials * _dbus_auth_get_identity(DBusAuth *auth)
Gets the identity we authorized the client as.
Definition: dbus-auth.c:2768
_dbus_auth_get_bytes_to_send
dbus_bool_t _dbus_auth_get_bytes_to_send(DBusAuth *auth, const DBusString **str)
Gets bytes that need to be sent to the peer we're conversing with.
Definition: dbus-auth.c:2512
_dbus_auth_unref
void _dbus_auth_unref(DBusAuth *auth)
Decrements the refcount of an auth object.
Definition: dbus-auth.c:2383
_dbus_auth_return_buffer
void _dbus_auth_return_buffer(DBusAuth *auth, DBusString *buffer)
Returns a buffer with new data read into it.
Definition: dbus-auth.c:2575
_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:2433
_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:2611
_dbus_auth_get_buffer
void _dbus_auth_get_buffer(DBusAuth *auth, DBusString **buffer)
Get a buffer to be used for reading bytes from the peer we're conversing with.
Definition: dbus-auth.c:2557
_dbus_auth_set_context
dbus_bool_t _dbus_auth_set_context(DBusAuth *auth, const DBusString *context)
Sets the "authentication context" which scopes cookies with the DBUS_COOKIE_SHA1 auth mechanism for e...
Definition: dbus-auth.c:2811
_dbus_auth_bytes_sent
void _dbus_auth_bytes_sent(DBusAuth *auth, int bytes_sent)
Notifies the auth conversation object that the given number of bytes of the outgoing buffer have been...
Definition: dbus-auth.c:2537
_dbus_auth_client_new
DBusAuth * _dbus_auth_client_new(void)
Creates a new auth conversation object for the client side.
Definition: dbus-auth.c:2330
_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:2284
_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:2594
_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_credentials_new
DBusCredentials * _dbus_credentials_new(void)
Creates a new credentials object.
Definition: dbus-credentials.c:71
_dbus_credentials_unref
void _dbus_credentials_unref(DBusCredentials *credentials)
Decrement refcount on credentials.
Definition: dbus-credentials.c:130
_dbus_credentials_add_unix_uid
dbus_bool_t _dbus_credentials_add_unix_uid(DBusCredentials *credentials, dbus_uid_t uid)
Add a UNIX user ID to the credentials.
Definition: dbus-credentials.c:167
_dbus_credentials_add_pid
dbus_bool_t _dbus_credentials_add_pid(DBusCredentials *credentials, dbus_pid_t pid)
Add a UNIX process ID to the credentials.
Definition: dbus-credentials.c:152
_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_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
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_file_get_contents
dbus_bool_t _dbus_file_get_contents(DBusString *str, const DBusString *filename, DBusError *error)
Appends the contents of the given file to the string, returning error code.
Definition: dbus-file-unix.c:55
_dbus_assert_not_reached
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
Definition: dbus-internals.h:163
_dbus_warn
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
Definition: dbus-internals.c:230
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
TRUE
#define TRUE
Expands to "1".
FALSE
#define FALSE
Expands to "0".
dbus_new0
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:59
dbus_free_string_array
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:750
dbus_malloc
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:462
_dbus_string_append
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:935
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
_dbus_string_init_const
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
_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:1283
_dbus_string_starts_with_c_str
dbus_bool_t _dbus_string_starts_with_c_str(const DBusString *a, const char *c_str)
Checks whether a string starts with the given C string.
Definition: dbus-string.c:2188
_dbus_string_skip_blank
void _dbus_string_skip_blank(const DBusString *str, int start, int *end)
Skips blanks from start, storing the first non-blank in *end (blank is space or tab).
Definition: dbus-string.c:1803
_dbus_string_find
dbus_bool_t _dbus_string_find(const DBusString *str, int start, const char *substr, int *found)
Finds the given substring in the string, returning TRUE and filling in the byte index where the subst...
Definition: dbus-string.c:1604
_dbus_string_find_blank
dbus_bool_t _dbus_string_find_blank(const DBusString *str, int start, int *found)
Finds a blank (space or tab) in the string.
Definition: dbus-string.c:1765
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:259
_dbus_string_delete
void _dbus_string_delete(DBusString *str, int start, int len)
Deletes a segment of a DBusString with length len starting at start.
Definition: dbus-string.c:1193
_dbus_string_pop_line
dbus_bool_t _dbus_string_pop_line(DBusString *source, DBusString *dest)
Assigns a newline-terminated or \r\n-terminated line from the front of the string to the given dest s...
Definition: dbus-string.c:1909
_dbus_string_append_byte
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
Definition: dbus-string.c:1157
_dbus_string_hex_encode
dbus_bool_t _dbus_string_hex_encode(const DBusString *source, int start, DBusString *dest, int insert_at)
Encodes a string in hex, the way MD5 and SHA-1 are usually encoded.
Definition: dbus-string.c:2259
_dbus_string_equal_len
dbus_bool_t _dbus_string_equal_len(const DBusString *a, const DBusString *b, int len)
Tests two DBusString for equality up to the given length.
Definition: dbus-string.c:2056
_dbus_string_equal
dbus_bool_t _dbus_string_equal(const DBusString *a, const DBusString *b)
Tests two DBusString for equality.
Definition: dbus-string.c:2013
dbus_uid_t
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:108
dbus_pid_t
unsigned long dbus_pid_t
A process ID.
Definition: dbus-sysdeps.h:106
DBUS_UID_UNSET
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
Definition: dbus-sysdeps.h:115
DBUS_PID_UNSET
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
Definition: dbus-sysdeps.h:113
_dbus_append_user_from_current_process
dbus_bool_t _dbus_append_user_from_current_process(DBusString *str)
Append to the string the identity we would like to have when we authenticate, on UNIX this is the cur...
Definition: dbus-sysdeps-unix.c:2652
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
DBusAuth
Internal members of DBusAuth.
Definition: dbus-auth.c:154
DBusCredentials
Definition: dbus-credentials.c:48
DBusError
Object representing an exception.
Definition: dbus-errors.h:49
DBusError::message
const char * message
public error message field
Definition: dbus-errors.h:51
DBusString
Definition: dbus-string.h:43