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