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