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