dbus-auth-script.c 23.8 KB
Newer Older
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
John Palmieri's avatar
John Palmieri committed
2
/* dbus-auth-script.c Test DBusAuth using a special script file (internal to D-Bus implementation)
3 4 5
 * 
 * Copyright (C) 2003 Red Hat, Inc.
 *
6
 * Licensed under the Academic Free License version 2.1
7 8 9 10 11 12 13 14 15 16 17 18 19
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * 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 24
 *
 */
#include <config.h>

25
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
26 27

#include "dbus-auth-script.h"
28 29 30

#include <stdio.h>

31 32 33
#include "dbus-auth.h"
#include "dbus-string.h"
#include "dbus-hash.h"
34
#include "dbus-credentials.h"
35 36 37 38 39 40 41 42 43 44 45 46 47
#include "dbus-internals.h"

/**
 * @defgroup DBusAuthScript code for running unit test scripts for DBusAuth
 * @ingroup  DBusInternals
 * @brief DBusAuth unit test scripting
 *
 * The code in here is used for unit testing, it loads
 * up a script that tests DBusAuth.
 *
 * @{
 */

48 49 50
/* this is slightly different from the other append_quoted_string
 * in dbus-message-builder.c
 */
51 52 53 54 55
static dbus_bool_t
append_quoted_string (DBusString       *dest,
                      const DBusString *quoted)
{
  dbus_bool_t in_quotes = FALSE;
56
  dbus_bool_t in_backslash = FALSE;
57 58 59 60 61 62 63 64
  int i;

  i = 0;
  while (i < _dbus_string_get_length (quoted))
    {
      unsigned char b;

      b = _dbus_string_get_byte (quoted, i);
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

      if (in_backslash)
        {
          unsigned char a;
          
          if (b == 'r')
            a = '\r';
          else if (b == 'n')
            a = '\n';
          else if (b == '\\')
            a = '\\';
          else
            {
              _dbus_warn ("bad backslashed byte %c\n", b);
              return FALSE;
            }

          if (!_dbus_string_append_byte (dest, a))
            return FALSE;
          
          in_backslash = FALSE;
        }
      else if (b == '\\')
        {
          in_backslash = TRUE;
        }
      else if (in_quotes)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        {
          if (b == '\'')
            in_quotes = FALSE;
          else
            {
              if (!_dbus_string_append_byte (dest, b))
                return FALSE;
            }
        }
      else
        {
          if (b == '\'')
            in_quotes = TRUE;
          else if (b == ' ' || b == '\n' || b == '\t')
            break; /* end on whitespace if not quoted */
          else
            {
              if (!_dbus_string_append_byte (dest, b))
                return FALSE;
            }
        }
      
      ++i;
    }

  return TRUE;
}

static dbus_bool_t
same_first_word (const DBusString *a,
                 const DBusString *b)
{
  int first_a_blank, first_b_blank;

  _dbus_string_find_blank (a, 0, &first_a_blank);
  _dbus_string_find_blank (b, 0, &first_b_blank);

  if (first_a_blank != first_b_blank)
    return FALSE;

  return _dbus_string_equal_len (a, b, first_a_blank);
}

static DBusAuthState
auth_state_from_string (const DBusString *str)
{ 
  if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_INPUT"))
    return DBUS_AUTH_STATE_WAITING_FOR_INPUT;
  else if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_MEMORY"))
    return DBUS_AUTH_STATE_WAITING_FOR_MEMORY;
  else if (_dbus_string_starts_with_c_str (str, "HAVE_BYTES_TO_SEND"))
    return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND;
  else if (_dbus_string_starts_with_c_str (str, "NEED_DISCONNECT"))
    return DBUS_AUTH_STATE_NEED_DISCONNECT;
  else if (_dbus_string_starts_with_c_str (str, "AUTHENTICATED"))
    return DBUS_AUTH_STATE_AUTHENTICATED;
  else
    return -1;
}

static const char*
auth_state_to_string (DBusAuthState state)
{
  switch (state)
    {
    case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
      return "WAITING_FOR_INPUT";
    case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
      return "WAITING_FOR_MEMORY";
    case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
      return "HAVE_BYTES_TO_SEND";
    case DBUS_AUTH_STATE_NEED_DISCONNECT:
      return "NEED_DISCONNECT";
    case DBUS_AUTH_STATE_AUTHENTICATED:
      return "AUTHENTICATED";
    }

  return "unknown";
}

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
static char **
split_string (DBusString *str)
{
  int i, j, k, count, end;
  char **array;

  end = _dbus_string_get_length (str);

  i = 0;
  _dbus_string_skip_blank (str, i, &i);
  for (count = 0; i < end; count++)
    {
      _dbus_string_find_blank (str, i, &i);
      _dbus_string_skip_blank (str, i, &i);
    }

  array = dbus_new0 (char *, count + 1);
  if (array == NULL)
    return NULL;

  i = 0;
  _dbus_string_skip_blank (str, i, &i);
  for (k = 0; k < count; k++)
    {
      _dbus_string_find_blank (str, i, &j);

      array[k] = dbus_malloc (j - i + 1);
      if (array[k] == NULL)
        {
          dbus_free_string_array (array);
          return NULL;
        }
      memcpy (array[k],
              _dbus_string_get_const_data_len (str, i, j - i), j - i);
      array[k][j - i] = '\0';

      _dbus_string_skip_blank (str, j, &i);
    }
  array[k] = NULL;

  return array;
}

215 216 217 218 219 220 221 222 223
static void
auth_set_unix_credentials(DBusAuth  *auth,
                          dbus_uid_t uid,
                          dbus_pid_t pid)
{
  DBusCredentials *credentials;

  credentials = _dbus_credentials_new ();
  if (credentials == NULL)
224 225
    _dbus_assert_not_reached ("no memory");

226
  if (uid != DBUS_UID_UNSET)
227 228 229 230
    {
      if (!_dbus_credentials_add_unix_uid (credentials, uid))
        _dbus_assert_not_reached ("no memory");
    }
231
  if (pid != DBUS_PID_UNSET)
232 233 234 235
    {
      if (!_dbus_credentials_add_pid (credentials, pid))
        _dbus_assert_not_reached ("no memory");
    }
236 237 238 239 240
  _dbus_auth_set_credentials (auth, credentials);

  _dbus_credentials_unref (credentials);
}

241 242 243 244 245 246 247 248 249 250
/**
 * Runs an "auth script" which is a script for testing the
 * authentication protocol. Scripts send and receive data, and then
 * include assertions about the state of both ends of the connection
 * after processing the data. A script succeeds if these assertions
 * hold.
 *
 * @param filename the file containing the script to run
 * @returns #TRUE if the script succeeds, #FALSE otherwise
 */
251 252 253 254
dbus_bool_t
_dbus_auth_script_run (const DBusString *filename)
{
  DBusString file;
255
  DBusError error = DBUS_ERROR_INIT;
256 257 258 259 260 261
  DBusString line;
  dbus_bool_t retval;
  int line_no;
  DBusAuth *auth;
  DBusString from_auth;
  DBusAuthState state;
262
  DBusString context;
263
  DBusString guid;
264 265 266
  
  retval = FALSE;
  auth = NULL;
267

268
  _dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00");
269
  _dbus_string_init_const (&context, "org_freedesktop_test");
270
  
271
  if (!_dbus_string_init (&file))
272 273
    return FALSE;

274
  if (!_dbus_string_init (&line))
275 276 277 278 279
    {
      _dbus_string_free (&file);
      return FALSE;
    }

280
  if (!_dbus_string_init (&from_auth))
281 282 283 284 285
    {
      _dbus_string_free (&file);
      _dbus_string_free (&line);
      return FALSE;
    }
286 287

  if (!_dbus_file_get_contents (&file, filename, &error))    {
288
      _dbus_warn ("Getting contents of %s failed: %s\n",
289
                  _dbus_string_get_const_data (filename), error.message);
290
      dbus_error_free (&error);
291 292 293 294 295
      goto out;
    }

  state = DBUS_AUTH_STATE_NEED_DISCONNECT;
  line_no = 0;
296

297 298 299 300 301
 next_iteration:
  while (_dbus_string_pop_line (&file, &line))
    {      
      line_no += 1;

302 303
      /* _dbus_warn ("%s\n", _dbus_string_get_const_data (&line)); */
      
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
      _dbus_string_delete_leading_blanks (&line);

      if (auth != NULL)
        {
          while ((state = _dbus_auth_do_work (auth)) ==
                 DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
            {
              const DBusString *tmp;
              if (_dbus_auth_get_bytes_to_send (auth, &tmp))
                {
                  int count = _dbus_string_get_length (tmp);

                  if (_dbus_string_copy (tmp, 0, &from_auth,
                                         _dbus_string_get_length (&from_auth)))
                    _dbus_auth_bytes_sent (auth, count);
                }
            }
        }
      
      if (_dbus_string_get_length (&line) == 0)
        {
          /* empty line */
          goto next_iteration;
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "#"))
        {
          /* Ignore this comment */
          goto next_iteration;
        }
334 335 336 337 338 339 340 341 342 343 344
#ifdef DBUS_WIN
      else if (_dbus_string_starts_with_c_str (&line,
                                               "WIN_ONLY"))
        {
          /* Ignore this line */
          goto next_iteration;
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "UNIX_ONLY"))
        {
          /* skip this file */
345
          fprintf (stderr, "skipping unix only auth script\n");
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
          retval = TRUE;
          goto out;
        }
#endif
#ifdef DBUS_UNIX
      else if (_dbus_string_starts_with_c_str (&line,
                                               "UNIX_ONLY"))
        {
          /* Ignore this line */
          goto next_iteration;
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "WIN_ONLY"))
        {
          /* skip this file */
361
          fprintf (stderr, "skipping windows only auth script\n");
362 363 364 365
          retval = TRUE;
          goto out;
        }
#endif
366 367 368
      else if (_dbus_string_starts_with_c_str (&line,
                                               "CLIENT"))
        {
369
          DBusCredentials *creds;
370
          
371 372 373 374 375 376 377 378 379 380 381 382
          if (auth != NULL)
            {
              _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n");
              goto out;
            }

          auth = _dbus_auth_client_new ();
          if (auth == NULL)
            {
              _dbus_warn ("no memory to create DBusAuth\n");
              goto out;
            }
383

384 385 386 387
          /* test ref/unref */
          _dbus_auth_ref (auth);
          _dbus_auth_unref (auth);

388 389 390 391
          creds = _dbus_credentials_new_from_current_process ();
          if (creds == NULL)
            {
              _dbus_warn ("no memory for credentials\n");
392 393
              _dbus_auth_unref (auth);
              auth = NULL;
394 395 396 397 398 399
              goto out;
            }
              
          if (!_dbus_auth_set_credentials (auth, creds))
            {
              _dbus_warn ("no memory for setting credentials\n");
400 401
              _dbus_auth_unref (auth);
              auth = NULL;
402 403 404
              _dbus_credentials_unref (creds);
              goto out;
            }
405
          
406
          _dbus_credentials_unref (creds);
407
        }
408 409
      else if (_dbus_string_starts_with_c_str (&line,
                                               "SERVER"))
410
        {
411
          DBusCredentials *creds;
412
          
413 414 415 416 417 418
          if (auth != NULL)
            {
              _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n");
              goto out;
            }

419
          auth = _dbus_auth_server_new (&guid);
420 421 422 423 424
          if (auth == NULL)
            {
              _dbus_warn ("no memory to create DBusAuth\n");
              goto out;
            }
425

426 427 428 429
          /* test ref/unref */
          _dbus_auth_ref (auth);
          _dbus_auth_unref (auth);

430 431 432 433
          creds = _dbus_credentials_new_from_current_process ();
          if (creds == NULL)
            {
              _dbus_warn ("no memory for credentials\n");
434 435
              _dbus_auth_unref (auth);
              auth = NULL;
436 437 438 439 440 441
              goto out;
            }
              
          if (!_dbus_auth_set_credentials (auth, creds))
            {
              _dbus_warn ("no memory for setting credentials\n");
442 443
              _dbus_auth_unref (auth);
              auth = NULL;
444 445 446
              _dbus_credentials_unref (creds);
              goto out;
            }
447
          
448 449
          _dbus_credentials_unref (creds);

450
          _dbus_auth_set_context (auth, &context);
451 452 453 454 455 456 457
        }
      else if (auth == NULL)
        {
          _dbus_warn ("must specify CLIENT or SERVER\n");
          goto out;

        }
458 459 460
      else if (_dbus_string_starts_with_c_str (&line,
                                               "NO_CREDENTIALS"))
        {
461
          auth_set_unix_credentials (auth, DBUS_UID_UNSET, DBUS_PID_UNSET);
462 463 464 465
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "ROOT_CREDENTIALS"))
        {
466
          auth_set_unix_credentials (auth, 0, DBUS_PID_UNSET);
467 468 469 470
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "SILLY_CREDENTIALS"))
        {
471
          auth_set_unix_credentials (auth, 4312, DBUS_PID_UNSET);
472
        }
473 474 475 476 477 478 479 480 481 482
      else if (_dbus_string_starts_with_c_str (&line,
                                               "ALLOWED_MECHS"))
        {
          char **mechs;

          _dbus_string_delete_first_word (&line);
          mechs = split_string (&line);
          _dbus_auth_set_mechanisms (auth, (const char **) mechs);
          dbus_free_string_array (mechs);
        }
483 484 485 486 487 488 489
      else if (_dbus_string_starts_with_c_str (&line,
                                               "SEND"))
        {
          DBusString to_send;
          
          _dbus_string_delete_first_word (&line);

490
          if (!_dbus_string_init (&to_send))
491 492 493 494 495 496 497 498 499 500 501 502 503
            {
              _dbus_warn ("no memory to allocate string\n");
              goto out;
            }

          if (!append_quoted_string (&to_send, &line))
            {
              _dbus_warn ("failed to append quoted string line %d\n",
                          line_no);
              _dbus_string_free (&to_send);
              goto out;
            }

504
          _dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send));
505 506 507 508 509 510 511 512
          
          if (!_dbus_string_append (&to_send, "\r\n"))
            {
              _dbus_warn ("failed to append \r\n from line %d\n",
                          line_no);
              _dbus_string_free (&to_send);
              goto out;
            }
513

514
          /* Replace USERID_HEX with our username in hex */
515 516 517 518
          {
            int where;
            
            if (_dbus_string_find (&to_send, 0,
519
                                   "USERID_HEX", &where))
520 521 522
              {
                DBusString username;

523
                if (!_dbus_string_init (&username))
524
                  {
525
                    _dbus_warn ("no memory for userid\n");
526 527 528 529
                    _dbus_string_free (&to_send);
                    goto out;
                  }

530
                if (!_dbus_append_user_from_current_process (&username))
531 532 533 534 535 536 537
                  {
                    _dbus_warn ("no memory for userid\n");
                    _dbus_string_free (&username);
                    _dbus_string_free (&to_send);
                    goto out;
                  }

538
                _dbus_string_delete (&to_send, where, (int) strlen ("USERID_HEX"));
539
                
540 541
                if (!_dbus_string_hex_encode (&username, 0,
					      &to_send, where))
542
                  {
543
                    _dbus_warn ("no memory to subst USERID_HEX\n");
544 545 546 547 548 549 550 551
                    _dbus_string_free (&username);
                    _dbus_string_free (&to_send);
                    goto out;
                  }

                _dbus_string_free (&username);
              }
            else if (_dbus_string_find (&to_send, 0,
552
                                        "USERNAME_HEX", &where))
553 554 555
              {
                DBusString username;
                
556
                if (!_dbus_string_init (&username))
557 558 559 560 561 562
                  {
                    _dbus_warn ("no memory for username\n");
                    _dbus_string_free (&to_send);
                    goto out;
                  }

563
                if (!_dbus_append_user_from_current_process (&username))
564 565 566 567 568 569 570
                  {
                    _dbus_warn ("no memory for username\n");
                    _dbus_string_free (&username);
                    _dbus_string_free (&to_send);
                    goto out;
                  }

571
                _dbus_string_delete (&to_send, where, (int) strlen ("USERNAME_HEX"));
572
                
573 574
                if (!_dbus_string_hex_encode (&username, 0,
					      &to_send, where))
575
                  {
576
                    _dbus_warn ("no memory to subst USERNAME_HEX\n");
577 578 579 580 581 582 583 584
                    _dbus_string_free (&username);
                    _dbus_string_free (&to_send);
                    goto out;
                  }

                _dbus_string_free (&username);
              }
          }
585

586 587 588 589 590 591 592 593 594
          {
            DBusString *buffer;

            _dbus_auth_get_buffer (auth, &buffer);
            if (!_dbus_string_copy (&to_send, 0,
                                    buffer, _dbus_string_get_length (buffer)))
              {
                _dbus_warn ("not enough memory to call bytes_received, or can't add bytes to auth object already in end state\n");
                _dbus_string_free (&to_send);
595
                _dbus_auth_return_buffer (auth, buffer);
596 597 598
                goto out;
              }

599
            _dbus_auth_return_buffer (auth, buffer);
600 601
          }
          
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
          _dbus_string_free (&to_send);
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "EXPECT_STATE"))
        {
          DBusAuthState expected;
          
          _dbus_string_delete_first_word (&line);

          expected = auth_state_from_string (&line);
          if (expected < 0)
            {
              _dbus_warn ("bad auth state given to EXPECT_STATE\n");
              goto parse_failed;
            }

          if (expected != state)
            {
              _dbus_warn ("expected auth state %s but got %s on line %d\n",
                          auth_state_to_string (expected),
                          auth_state_to_string (state),
                          line_no);
              goto out;
            }
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "EXPECT_COMMAND"))
        {
          DBusString received;
          
          _dbus_string_delete_first_word (&line);

634
          if (!_dbus_string_init (&received))
635 636 637 638 639 640 641 642
            {
              _dbus_warn ("no mem to allocate string received\n");
              goto out;
            }

          if (!_dbus_string_pop_line (&from_auth, &received))
            {
              _dbus_warn ("no line popped from the DBusAuth being tested, expected command %s on line %d\n",
643
                          _dbus_string_get_const_data (&line), line_no);
644 645 646 647 648 649
              _dbus_string_free (&received);
              goto out;
            }

          if (!same_first_word (&received, &line))
            {
650
              _dbus_warn ("line %d expected command '%s' and got '%s'\n",
651 652 653
                          line_no,
                          _dbus_string_get_const_data (&line),
                          _dbus_string_get_const_data (&received));
654 655 656 657 658 659
              _dbus_string_free (&received);
              goto out;
            }
          
          _dbus_string_free (&received);
        }
660 661 662 663
      else if (_dbus_string_starts_with_c_str (&line,
                                               "EXPECT_UNUSED"))
        {
          DBusString expected;
664
          const DBusString *unused;
665 666 667
          
          _dbus_string_delete_first_word (&line);

668
          if (!_dbus_string_init (&expected))
669 670 671 672 673 674 675 676 677 678 679 680 681
            {
              _dbus_warn ("no mem to allocate string expected\n");
              goto out;
            }

          if (!append_quoted_string (&expected, &line))
            {
              _dbus_warn ("failed to append quoted string line %d\n",
                          line_no);
              _dbus_string_free (&expected);
              goto out;
            }

682
          _dbus_auth_get_unused_bytes (auth, &unused);
683
          
684
          if (_dbus_string_equal (&expected, unused))
685
            {
686
              _dbus_auth_delete_unused_bytes (auth);
687 688 689 690 691
              _dbus_string_free (&expected);
            }
          else
            {
              _dbus_warn ("Expected unused bytes '%s' and have '%s'\n",
692 693
                          _dbus_string_get_const_data (&expected),
                          _dbus_string_get_const_data (unused));
694 695 696 697
              _dbus_string_free (&expected);
              goto out;
            }
        }
698 699 700 701 702 703
      else if (_dbus_string_starts_with_c_str (&line,
                                               "EXPECT_HAVE_NO_CREDENTIALS"))
        {
          DBusCredentials *authorized_identity;
          
          authorized_identity = _dbus_auth_get_identity (auth);
704
          if (!_dbus_credentials_are_anonymous (authorized_identity))
705 706 707 708 709 710 711 712 713 714 715
            {
              _dbus_warn ("Expected anonymous login or failed login, but some credentials were authorized\n");
              goto out;
            }
        }
      else if (_dbus_string_starts_with_c_str (&line,
                                               "EXPECT_HAVE_SOME_CREDENTIALS"))
        {
          DBusCredentials *authorized_identity;
          
          authorized_identity = _dbus_auth_get_identity (auth);
716
          if (_dbus_credentials_are_anonymous (authorized_identity))
717 718 719 720 721
            {
              _dbus_warn ("Expected to have some credentials, but we don't\n");
              goto out;
            }
        }
722 723 724 725 726 727 728
      else if (_dbus_string_starts_with_c_str (&line,
                                               "EXPECT"))
        {
          DBusString expected;
          
          _dbus_string_delete_first_word (&line);

729
          if (!_dbus_string_init (&expected))
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
            {
              _dbus_warn ("no mem to allocate string expected\n");
              goto out;
            }

          if (!append_quoted_string (&expected, &line))
            {
              _dbus_warn ("failed to append quoted string line %d\n",
                          line_no);
              _dbus_string_free (&expected);
              goto out;
            }

          if (_dbus_string_equal_len (&expected, &from_auth,
                                      _dbus_string_get_length (&expected)))
            {
              _dbus_string_delete (&from_auth, 0,
                                   _dbus_string_get_length (&expected));
              _dbus_string_free (&expected);
            }
          else
            {
              _dbus_warn ("Expected exact string '%s' and have '%s'\n",
753 754
                          _dbus_string_get_const_data (&expected),
                          _dbus_string_get_const_data (&from_auth));
755 756 757 758
              _dbus_string_free (&expected);
              goto out;
            }
        }
759 760 761 762 763 764 765 766
      else
        goto parse_failed;

      goto next_iteration; /* skip parse_failed */
      
    parse_failed:
      {
        _dbus_warn ("couldn't process line %d \"%s\"\n",
767
                    line_no, _dbus_string_get_const_data (&line));
768 769 770 771
        goto out;
      }
    }

772 773 774 775 776 777
  if (auth == NULL)
    {
      _dbus_warn ("Auth script is bogus, did not even have CLIENT or SERVER\n");
      goto out;
    }
  else if (state == DBUS_AUTH_STATE_AUTHENTICATED)
778
    {
779 780 781 782 783 784 785 786 787
      const DBusString *unused;

      _dbus_auth_get_unused_bytes (auth, &unused);

      if (_dbus_string_get_length (unused) > 0)
        {
          _dbus_warn ("did not expect unused bytes (scripts must specify explicitly if they are expected)\n");
          goto out;
        }
788 789 790 791 792
    }

  if (_dbus_string_get_length (&from_auth) > 0)
    {
      _dbus_warn ("script did not have EXPECT_ statements for all the data received from the DBusAuth\n");
793
      _dbus_warn ("Leftover data: %s\n", _dbus_string_get_const_data (&from_auth));
794 795 796 797 798 799 800
      goto out;
    }
  
  retval = TRUE;
  
 out:
  if (auth)
801
    _dbus_auth_unref (auth);
802 803

  _dbus_string_free (&file);
804
  _dbus_string_free (&line);
805 806 807 808 809 810
  _dbus_string_free (&from_auth);
  
  return retval;
}

/** @} */
811
#endif /* DBUS_ENABLE_EMBEDDED_TESTS */