D-Bus  1.11.6
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
52 append_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
121 same_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
136 auth_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*
153 auth_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  default:
168  break;
169  }
170 
171  return "unknown";
172 }
173 
174 static char **
175 split_string (DBusString *str)
176 {
177  int i, j, k, count, end;
178  char **array;
179 
180  end = _dbus_string_get_length (str);
181 
182  i = 0;
183  _dbus_string_skip_blank (str, i, &i);
184  for (count = 0; i < end; count++)
185  {
186  _dbus_string_find_blank (str, i, &i);
187  _dbus_string_skip_blank (str, i, &i);
188  }
189 
190  array = dbus_new0 (char *, count + 1);
191  if (array == NULL)
192  return NULL;
193 
194  i = 0;
195  _dbus_string_skip_blank (str, i, &i);
196  for (k = 0; k < count; k++)
197  {
198  _dbus_string_find_blank (str, i, &j);
199 
200  array[k] = dbus_malloc (j - i + 1);
201  if (array[k] == NULL)
202  {
203  dbus_free_string_array (array);
204  return NULL;
205  }
206  memcpy (array[k],
207  _dbus_string_get_const_data_len (str, i, j - i), j - i);
208  array[k][j - i] = '\0';
209 
210  _dbus_string_skip_blank (str, j, &i);
211  }
212  array[k] = NULL;
213 
214  return array;
215 }
216 
217 static void
218 auth_set_unix_credentials(DBusAuth *auth,
219  dbus_uid_t uid,
220  dbus_pid_t pid)
221 {
222  DBusCredentials *credentials;
223 
224  credentials = _dbus_credentials_new ();
225  if (credentials == NULL)
226  _dbus_assert_not_reached ("no memory");
227 
228  if (uid != DBUS_UID_UNSET)
229  {
230  if (!_dbus_credentials_add_unix_uid (credentials, uid))
231  _dbus_assert_not_reached ("no memory");
232  }
233  if (pid != DBUS_PID_UNSET)
234  {
235  if (!_dbus_credentials_add_pid (credentials, pid))
236  _dbus_assert_not_reached ("no memory");
237  }
238  _dbus_auth_set_credentials (auth, credentials);
239 
240  _dbus_credentials_unref (credentials);
241 }
242 
254 _dbus_auth_script_run (const DBusString *filename)
255 {
256  DBusString file;
257  DBusError error = DBUS_ERROR_INIT;
258  DBusString line;
259  dbus_bool_t retval;
260  int line_no;
261  DBusAuth *auth;
262  DBusString from_auth;
263  DBusAuthState state;
264  DBusString context;
265  DBusString guid;
266 
267  retval = FALSE;
268  auth = NULL;
269 
270  _dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00");
271  _dbus_string_init_const (&context, "org_freedesktop_test");
272 
273  if (!_dbus_string_init (&file))
274  return FALSE;
275 
276  if (!_dbus_string_init (&line))
277  {
278  _dbus_string_free (&file);
279  return FALSE;
280  }
281 
282  if (!_dbus_string_init (&from_auth))
283  {
284  _dbus_string_free (&file);
285  _dbus_string_free (&line);
286  return FALSE;
287  }
288 
289  if (!_dbus_file_get_contents (&file, filename, &error)) {
290  _dbus_warn ("Getting contents of %s failed: %s",
291  _dbus_string_get_const_data (filename), error.message);
292  dbus_error_free (&error);
293  goto out;
294  }
295 
296  state = DBUS_AUTH_STATE_NEED_DISCONNECT;
297  line_no = 0;
298 
299  next_iteration:
300  while (_dbus_string_pop_line (&file, &line))
301  {
302  line_no += 1;
303 
304  /* _dbus_warn ("%s", _dbus_string_get_const_data (&line)); */
305 
306  _dbus_string_delete_leading_blanks (&line);
307 
308  if (auth != NULL)
309  {
310  while ((state = _dbus_auth_do_work (auth)) ==
311  DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
312  {
313  const DBusString *tmp;
314  if (_dbus_auth_get_bytes_to_send (auth, &tmp))
315  {
316  int count = _dbus_string_get_length (tmp);
317 
318  if (_dbus_string_copy (tmp, 0, &from_auth,
319  _dbus_string_get_length (&from_auth)))
320  _dbus_auth_bytes_sent (auth, count);
321  }
322  }
323  }
324 
325  if (_dbus_string_get_length (&line) == 0)
326  {
327  /* empty line */
328  goto next_iteration;
329  }
330  else if (_dbus_string_starts_with_c_str (&line,
331  "#"))
332  {
333  /* Ignore this comment */
334  goto next_iteration;
335  }
336 #ifdef DBUS_WIN
337  else if (_dbus_string_starts_with_c_str (&line,
338  "WIN_ONLY"))
339  {
340  /* Ignore this line */
341  goto next_iteration;
342  }
343  else if (_dbus_string_starts_with_c_str (&line,
344  "UNIX_ONLY"))
345  {
346  /* skip this file */
347  fprintf (stderr, "skipping unix only auth script\n");
348  retval = TRUE;
349  goto out;
350  }
351 #endif
352 #ifdef DBUS_UNIX
353  else if (_dbus_string_starts_with_c_str (&line,
354  "UNIX_ONLY"))
355  {
356  /* Ignore this line */
357  goto next_iteration;
358  }
359  else if (_dbus_string_starts_with_c_str (&line,
360  "WIN_ONLY"))
361  {
362  /* skip this file */
363  fprintf (stderr, "skipping windows only auth script\n");
364  retval = TRUE;
365  goto out;
366  }
367 #endif
368  else if (_dbus_string_starts_with_c_str (&line,
369  "CLIENT"))
370  {
371  DBusCredentials *creds;
372 
373  if (auth != NULL)
374  {
375  _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)");
376  goto out;
377  }
378 
379  auth = _dbus_auth_client_new ();
380  if (auth == NULL)
381  {
382  _dbus_warn ("no memory to create DBusAuth");
383  goto out;
384  }
385 
386  /* test ref/unref */
387  _dbus_auth_ref (auth);
388  _dbus_auth_unref (auth);
389 
391  if (creds == NULL)
392  {
393  _dbus_warn ("no memory for credentials");
394  _dbus_auth_unref (auth);
395  auth = NULL;
396  goto out;
397  }
398 
399  if (!_dbus_auth_set_credentials (auth, creds))
400  {
401  _dbus_warn ("no memory for setting credentials");
402  _dbus_auth_unref (auth);
403  auth = NULL;
404  _dbus_credentials_unref (creds);
405  goto out;
406  }
407 
408  _dbus_credentials_unref (creds);
409  }
410  else if (_dbus_string_starts_with_c_str (&line,
411  "SERVER"))
412  {
413  DBusCredentials *creds;
414 
415  if (auth != NULL)
416  {
417  _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)");
418  goto out;
419  }
420 
421  auth = _dbus_auth_server_new (&guid);
422  if (auth == NULL)
423  {
424  _dbus_warn ("no memory to create DBusAuth");
425  goto out;
426  }
427 
428  /* test ref/unref */
429  _dbus_auth_ref (auth);
430  _dbus_auth_unref (auth);
431 
433  if (creds == NULL)
434  {
435  _dbus_warn ("no memory for credentials");
436  _dbus_auth_unref (auth);
437  auth = NULL;
438  goto out;
439  }
440 
441  if (!_dbus_auth_set_credentials (auth, creds))
442  {
443  _dbus_warn ("no memory for setting credentials");
444  _dbus_auth_unref (auth);
445  auth = NULL;
446  _dbus_credentials_unref (creds);
447  goto out;
448  }
449 
450  _dbus_credentials_unref (creds);
451 
452  _dbus_auth_set_context (auth, &context);
453  }
454  else if (auth == NULL)
455  {
456  _dbus_warn ("must specify CLIENT or SERVER");
457  goto out;
458 
459  }
460  else if (_dbus_string_starts_with_c_str (&line,
461  "NO_CREDENTIALS"))
462  {
463  auth_set_unix_credentials (auth, DBUS_UID_UNSET, DBUS_PID_UNSET);
464  }
465  else if (_dbus_string_starts_with_c_str (&line,
466  "ROOT_CREDENTIALS"))
467  {
468  auth_set_unix_credentials (auth, 0, DBUS_PID_UNSET);
469  }
470  else if (_dbus_string_starts_with_c_str (&line,
471  "SILLY_CREDENTIALS"))
472  {
473  auth_set_unix_credentials (auth, 4312, DBUS_PID_UNSET);
474  }
475  else if (_dbus_string_starts_with_c_str (&line,
476  "ALLOWED_MECHS"))
477  {
478  char **mechs;
479 
480  _dbus_string_delete_first_word (&line);
481  mechs = split_string (&line);
482  _dbus_auth_set_mechanisms (auth, (const char **) mechs);
483  dbus_free_string_array (mechs);
484  }
485  else if (_dbus_string_starts_with_c_str (&line,
486  "SEND"))
487  {
488  DBusString to_send;
489 
490  _dbus_string_delete_first_word (&line);
491 
492  if (!_dbus_string_init (&to_send))
493  {
494  _dbus_warn ("no memory to allocate string");
495  goto out;
496  }
497 
498  if (!append_quoted_string (&to_send, &line))
499  {
500  _dbus_warn ("failed to append quoted string line %d",
501  line_no);
502  _dbus_string_free (&to_send);
503  goto out;
504  }
505 
506  _dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send));
507 
508  if (!_dbus_string_append (&to_send, "\r\n"))
509  {
510  _dbus_warn ("failed to append \\r\\n from line %d",
511  line_no);
512  _dbus_string_free (&to_send);
513  goto out;
514  }
515 
516  /* Replace USERID_HEX with our username in hex */
517  {
518  int where;
519 
520  if (_dbus_string_find (&to_send, 0,
521  "USERID_HEX", &where))
522  {
523  DBusString username;
524 
525  if (!_dbus_string_init (&username))
526  {
527  _dbus_warn ("no memory for userid");
528  _dbus_string_free (&to_send);
529  goto out;
530  }
531 
533  {
534  _dbus_warn ("no memory for userid");
535  _dbus_string_free (&username);
536  _dbus_string_free (&to_send);
537  goto out;
538  }
539 
540  _dbus_string_delete (&to_send, where, (int) strlen ("USERID_HEX"));
541 
542  if (!_dbus_string_hex_encode (&username, 0,
543  &to_send, where))
544  {
545  _dbus_warn ("no memory to subst USERID_HEX");
546  _dbus_string_free (&username);
547  _dbus_string_free (&to_send);
548  goto out;
549  }
550 
551  _dbus_string_free (&username);
552  }
553  else if (_dbus_string_find (&to_send, 0,
554  "USERNAME_HEX", &where))
555  {
556  DBusString username;
557 
558  if (!_dbus_string_init (&username))
559  {
560  _dbus_warn ("no memory for username");
561  _dbus_string_free (&to_send);
562  goto out;
563  }
564 
566  {
567  _dbus_warn ("no memory for username");
568  _dbus_string_free (&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 (&username);
580  _dbus_string_free (&to_send);
581  goto out;
582  }
583 
584  _dbus_string_free (&username);
585  }
586  }
587 
588  {
589  DBusString *buffer;
590 
591  _dbus_auth_get_buffer (auth, &buffer);
592  if (!_dbus_string_copy (&to_send, 0,
593  buffer, _dbus_string_get_length (buffer)))
594  {
595  _dbus_warn ("not enough memory to call bytes_received, or can't add bytes to auth object already in end state");
596  _dbus_string_free (&to_send);
597  _dbus_auth_return_buffer (auth, buffer);
598  goto out;
599  }
600 
601  _dbus_auth_return_buffer (auth, buffer);
602  }
603 
604  _dbus_string_free (&to_send);
605  }
606  else if (_dbus_string_starts_with_c_str (&line,
607  "EXPECT_STATE"))
608  {
609  DBusAuthState expected;
610 
611  _dbus_string_delete_first_word (&line);
612 
613  expected = auth_state_from_string (&line);
614  if (expected < 0)
615  {
616  _dbus_warn ("bad auth state given to EXPECT_STATE");
617  goto parse_failed;
618  }
619 
620  if (expected != state)
621  {
622  _dbus_warn ("expected auth state %s but got %s on line %d",
623  auth_state_to_string (expected),
624  auth_state_to_string (state),
625  line_no);
626  goto out;
627  }
628  }
629  else if (_dbus_string_starts_with_c_str (&line,
630  "EXPECT_COMMAND"))
631  {
632  DBusString received;
633 
634  _dbus_string_delete_first_word (&line);
635 
636  if (!_dbus_string_init (&received))
637  {
638  _dbus_warn ("no mem to allocate string received");
639  goto out;
640  }
641 
642  if (!_dbus_string_pop_line (&from_auth, &received))
643  {
644  _dbus_warn ("no line popped from the DBusAuth being tested, expected command %s on line %d",
645  _dbus_string_get_const_data (&line), line_no);
646  _dbus_string_free (&received);
647  goto out;
648  }
649 
650  if (!same_first_word (&received, &line))
651  {
652  _dbus_warn ("line %d expected command '%s' and got '%s'",
653  line_no,
654  _dbus_string_get_const_data (&line),
655  _dbus_string_get_const_data (&received));
656  _dbus_string_free (&received);
657  goto out;
658  }
659 
660  _dbus_string_free (&received);
661  }
662  else if (_dbus_string_starts_with_c_str (&line,
663  "EXPECT_UNUSED"))
664  {
665  DBusString expected;
666  const DBusString *unused;
667 
668  _dbus_string_delete_first_word (&line);
669 
670  if (!_dbus_string_init (&expected))
671  {
672  _dbus_warn ("no mem to allocate string expected");
673  goto out;
674  }
675 
676  if (!append_quoted_string (&expected, &line))
677  {
678  _dbus_warn ("failed to append quoted string line %d",
679  line_no);
680  _dbus_string_free (&expected);
681  goto out;
682  }
683 
684  _dbus_auth_get_unused_bytes (auth, &unused);
685 
686  if (_dbus_string_equal (&expected, unused))
687  {
689  _dbus_string_free (&expected);
690  }
691  else
692  {
693  _dbus_warn ("Expected unused bytes '%s' and have '%s'",
694  _dbus_string_get_const_data (&expected),
695  _dbus_string_get_const_data (unused));
696  _dbus_string_free (&expected);
697  goto out;
698  }
699  }
700  else if (_dbus_string_starts_with_c_str (&line,
701  "EXPECT_HAVE_NO_CREDENTIALS"))
702  {
703  DBusCredentials *authorized_identity;
704 
705  authorized_identity = _dbus_auth_get_identity (auth);
706  if (!_dbus_credentials_are_anonymous (authorized_identity))
707  {
708  _dbus_warn ("Expected anonymous login or failed login, but some credentials were authorized");
709  goto out;
710  }
711  }
712  else if (_dbus_string_starts_with_c_str (&line,
713  "EXPECT_HAVE_SOME_CREDENTIALS"))
714  {
715  DBusCredentials *authorized_identity;
716 
717  authorized_identity = _dbus_auth_get_identity (auth);
718  if (_dbus_credentials_are_anonymous (authorized_identity))
719  {
720  _dbus_warn ("Expected to have some credentials, but we don't");
721  goto out;
722  }
723  }
724  else if (_dbus_string_starts_with_c_str (&line,
725  "EXPECT"))
726  {
727  DBusString expected;
728 
729  _dbus_string_delete_first_word (&line);
730 
731  if (!_dbus_string_init (&expected))
732  {
733  _dbus_warn ("no mem to allocate string expected");
734  goto out;
735  }
736 
737  if (!append_quoted_string (&expected, &line))
738  {
739  _dbus_warn ("failed to append quoted string line %d",
740  line_no);
741  _dbus_string_free (&expected);
742  goto out;
743  }
744 
745  if (_dbus_string_equal_len (&expected, &from_auth,
746  _dbus_string_get_length (&expected)))
747  {
748  _dbus_string_delete (&from_auth, 0,
749  _dbus_string_get_length (&expected));
750  _dbus_string_free (&expected);
751  }
752  else
753  {
754  _dbus_warn ("Expected exact string '%s' and have '%s'",
755  _dbus_string_get_const_data (&expected),
756  _dbus_string_get_const_data (&from_auth));
757  _dbus_string_free (&expected);
758  goto out;
759  }
760  }
761  else
762  goto parse_failed;
763 
764  goto next_iteration; /* skip parse_failed */
765 
766  parse_failed:
767  {
768  _dbus_warn ("couldn't process line %d \"%s\"",
769  line_no, _dbus_string_get_const_data (&line));
770  goto out;
771  }
772  }
773 
774  if (auth == NULL)
775  {
776  _dbus_warn ("Auth script is bogus, did not even have CLIENT or SERVER");
777  goto out;
778  }
779  else if (state == DBUS_AUTH_STATE_AUTHENTICATED)
780  {
781  const DBusString *unused;
782 
783  _dbus_auth_get_unused_bytes (auth, &unused);
784 
785  if (_dbus_string_get_length (unused) > 0)
786  {
787  _dbus_warn ("did not expect unused bytes (scripts must specify explicitly if they are expected)");
788  goto out;
789  }
790  }
791 
792  if (_dbus_string_get_length (&from_auth) > 0)
793  {
794  _dbus_warn ("script did not have EXPECT_ statements for all the data received from the DBusAuth");
795  _dbus_warn ("Leftover data: %s", _dbus_string_get_const_data (&from_auth));
796  goto out;
797  }
798 
799  retval = TRUE;
800 
801  out:
802  if (auth)
803  _dbus_auth_unref (auth);
804 
805  _dbus_string_free (&file);
806  _dbus_string_free (&line);
807  _dbus_string_free (&from_auth);
808 
809  return retval;
810 }
811 
813 #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&#39;ve gotten them and succes...
Definition: dbus-auth.c:2608
#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:2591
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:2808
#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:2572
DBusAuthState _dbus_auth_do_work(DBusAuth *auth)
Analyzes buffered input and moves the auth conversation forward, returning the new state of the auth ...
Definition: dbus-auth.c:2465
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:2430
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:1283
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
Definition: dbus-sysdeps.h:113
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:115
unsigned long dbus_pid_t
A process ID.
Definition: dbus-sysdeps.h:106
DBusCredentials * _dbus_auth_get_identity(DBusAuth *auth)
Gets the identity we authorized the client as.
Definition: dbus-auth.c:2765
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:2554
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:2534
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:2281
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:2365
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:2747
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:2380
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:2509
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:108
DBusAuth * _dbus_auth_client_new(void)
Creates a new auth conversation object for the client side.
Definition: dbus-auth.c:2327