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