Coverage report for dbus/dbus-auth-script.c.gcov

        -:    0:Source:dbus-auth-script.c
        -:    0:Graph:.libs/dbus-auth-script.gcno
        -:    0:Data:.libs/dbus-auth-script.gcda
        -:    0:Runs:774
        -:    0:Programs:2
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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-internals.h"
        -:   32:#include "dbus-userdb.h"
        -:   33:
        -:   34:/**
        -:   35: * @defgroup DBusAuthScript code for running unit test scripts for DBusAuth
        -:   36: * @ingroup  DBusInternals
        -:   37: * @brief DBusAuth unit test scripting
        -:   38: *
        -:   39: * The code in here is used for unit testing, it loads
        -:   40: * up a script that tests DBusAuth.
        -:   41: *
        -:   42: * @{
        -:   43: */
        -:   44:
        -:   45:/* this is slightly different from the other append_quoted_string
        -:   46: * in dbus-message-builder.c
        -:   47: */
        -:   48:static dbus_bool_t
        -:   49:append_quoted_string (DBusString       *dest,
        -:   50:                      const DBusString *quoted)
function append_quoted_string called 26 returned 100% blocks executed 81%
       26:   51:{
       26:   52:  dbus_bool_t in_quotes = FALSE;
       26:   53:  dbus_bool_t in_backslash = FALSE;
        -:   54:  int i;
        -:   55:
       26:   56:  i = 0;
      657:   57:  while (i < _dbus_string_get_length (quoted))
call    0 returned 100%
branch  1 taken 96%
branch  2 taken 4% (fallthrough)
        -:   58:    {
        -:   59:      unsigned char b;
        -:   60:
      605:   61:      b = _dbus_string_get_byte (quoted, i);
call    0 returned 100%
        -:   62:
      605:   63:      if (in_backslash)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:   64:        {
        -:   65:          unsigned char a;
        -:   66:          
        4:   67:          if (b == 'r')
branch  0 taken 50% (fallthrough)
branch  1 taken 50%
        2:   68:            a = '\r';
        2:   69:          else if (b == 'n')
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        2:   70:            a = '\n';
    #####:   71:          else if (b == '\\')
branch  0 never executed
branch  1 never executed
    #####:   72:            a = '\\';
        -:   73:          else
        -:   74:            {
    #####:   75:              _dbus_warn ("bad backslashed byte %c\n", b);
call    0 never executed
    #####:   76:              return FALSE;
        -:   77:            }
        -:   78:
        4:   79:          if (!_dbus_string_append_byte (dest, a))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:   80:            return FALSE;
        -:   81:          
        4:   82:          in_backslash = FALSE;
        -:   83:        }
      601:   84:      else if (b == '\\')
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:   85:        {
        4:   86:          in_backslash = TRUE;
        -:   87:        }
      597:   88:      else if (in_quotes)
branch  0 taken 95% (fallthrough)
branch  1 taken 5%
        -:   89:        {
      568:   90:          if (b == '\'')
branch  0 taken 4% (fallthrough)
branch  1 taken 96%
       25:   91:            in_quotes = FALSE;
        -:   92:          else
        -:   93:            {
      543:   94:              if (!_dbus_string_append_byte (dest, b))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:   95:                return FALSE;
        -:   96:            }
        -:   97:        }
        -:   98:      else
        -:   99:        {
       29:  100:          if (b == '\'')
branch  0 taken 86% (fallthrough)
branch  1 taken 14%
       25:  101:            in_quotes = TRUE;
        4:  102:          else if (b == ' ' || b == '\n' || b == '\t')
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
        -:  103:            break; /* end on whitespace if not quoted */
        -:  104:          else
        -:  105:            {
        4:  106:              if (!_dbus_string_append_byte (dest, b))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  107:                return FALSE;
        -:  108:            }
        -:  109:        }
        -:  110:      
      605:  111:      ++i;
        -:  112:    }
        -:  113:
       26:  114:  return TRUE;
        -:  115:}
        -:  116:
        -:  117:static dbus_bool_t
        -:  118:same_first_word (const DBusString *a,
        -:  119:                 const DBusString *b)
function same_first_word called 23 returned 100% blocks executed 86%
       23:  120:{
        -:  121:  int first_a_blank, first_b_blank;
        -:  122:
       23:  123:  _dbus_string_find_blank (a, 0, &first_a_blank);
call    0 returned 100%
       23:  124:  _dbus_string_find_blank (b, 0, &first_b_blank);
call    0 returned 100%
        -:  125:
       23:  126:  if (first_a_blank != first_b_blank)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  127:    return FALSE;
        -:  128:
       23:  129:  return _dbus_string_equal_len (a, b, first_a_blank);
call    0 returned 100%
        -:  130:}
        -:  131:
        -:  132:static DBusAuthState
        -:  133:auth_state_from_string (const DBusString *str)
function auth_state_from_string called 25 returned 100% blocks executed 82%
       25:  134:{ 
       25:  135:  if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_INPUT"))
call    0 returned 100%
branch  1 taken 68% (fallthrough)
branch  2 taken 32%
       17:  136:    return DBUS_AUTH_STATE_WAITING_FOR_INPUT;
        8:  137:  else if (_dbus_string_starts_with_c_str (str, "WAITING_FOR_MEMORY"))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  138:    return DBUS_AUTH_STATE_WAITING_FOR_MEMORY;
        8:  139:  else if (_dbus_string_starts_with_c_str (str, "HAVE_BYTES_TO_SEND"))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  140:    return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND;
        8:  141:  else if (_dbus_string_starts_with_c_str (str, "NEED_DISCONNECT"))
call    0 returned 100%
branch  1 taken 25% (fallthrough)
branch  2 taken 75%
        2:  142:    return DBUS_AUTH_STATE_NEED_DISCONNECT;
        6:  143:  else if (_dbus_string_starts_with_c_str (str, "AUTHENTICATED"))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        6:  144:    return DBUS_AUTH_STATE_AUTHENTICATED;
        -:  145:  else
    #####:  146:    return -1;
        -:  147:}
        -:  148:
        -:  149:static const char*
        -:  150:auth_state_to_string (DBusAuthState state)
function auth_state_to_string called 0 returned 0% blocks executed 0%
    #####:  151:{
    #####:  152:  switch (state)
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
        -:  153:    {
        -:  154:    case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
    #####:  155:      return "WAITING_FOR_INPUT";
        -:  156:    case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
    #####:  157:      return "WAITING_FOR_MEMORY";
        -:  158:    case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
    #####:  159:      return "HAVE_BYTES_TO_SEND";
        -:  160:    case DBUS_AUTH_STATE_NEED_DISCONNECT:
    #####:  161:      return "NEED_DISCONNECT";
        -:  162:    case DBUS_AUTH_STATE_AUTHENTICATED:
    #####:  163:      return "AUTHENTICATED";
        -:  164:    }
        -:  165:
    #####:  166:  return "unknown";
        -:  167:}
        -:  168:
        -:  169:static char **
        -:  170:split_string (DBusString *str)
function split_string called 0 returned 0% blocks executed 0%
    #####:  171:{
        -:  172:  int i, j, k, count, end;
        -:  173:  char **array;
        -:  174:
    #####:  175:  end = _dbus_string_get_length (str);
call    0 never executed
        -:  176:
    #####:  177:  i = 0;
    #####:  178:  _dbus_string_skip_blank (str, i, &i);
call    0 never executed
    #####:  179:  for (count = 0; i < end; count++)
branch  0 never executed
branch  1 never executed
        -:  180:    {
    #####:  181:      _dbus_string_find_blank (str, i, &i);
call    0 never executed
    #####:  182:      _dbus_string_skip_blank (str, i, &i);
call    0 never executed
        -:  183:    }
        -:  184:
    #####:  185:  array = dbus_new0 (char *, count + 1);
call    0 never executed
    #####:  186:  if (array == NULL)
branch  0 never executed
branch  1 never executed
    #####:  187:    return NULL;
        -:  188:
    #####:  189:  i = 0;
    #####:  190:  _dbus_string_skip_blank (str, i, &i);
call    0 never executed
    #####:  191:  for (k = 0; k < count; k++)
branch  0 never executed
branch  1 never executed
        -:  192:    {
    #####:  193:      _dbus_string_find_blank (str, i, &j);
call    0 never executed
        -:  194:
    #####:  195:      array[k] = dbus_malloc (j - i + 1);
call    0 never executed
    #####:  196:      if (array[k] == NULL)
branch  0 never executed
branch  1 never executed
        -:  197:        {
    #####:  198:          dbus_free_string_array (array);
call    0 never executed
    #####:  199:          return NULL;
        -:  200:        }
    #####:  201:      memcpy (array[k],
call    0 never executed
call    1 never executed
        -:  202:              _dbus_string_get_const_data_len (str, i, j - i), j - i);
    #####:  203:      array[k][j - i] = '\0';
        -:  204:
    #####:  205:      _dbus_string_skip_blank (str, j, &i);
call    0 never executed
        -:  206:    }
    #####:  207:  array[k] = NULL;
        -:  208:
    #####:  209:  return array;
        -:  210:}
        -:  211:
        -:  212:/**
        -:  213: * Runs an "auth script" which is a script for testing the
        -:  214: * authentication protocol. Scripts send and receive data, and then
        -:  215: * include assertions about the state of both ends of the connection
        -:  216: * after processing the data. A script succeeds if these assertions
        -:  217: * hold.
        -:  218: *
        -:  219: * @param filename the file containing the script to run
        -:  220: * @returns #TRUE if the script succeeds, #FALSE otherwise
        -:  221: */
        -:  222:dbus_bool_t
        -:  223:_dbus_auth_script_run (const DBusString *filename)
function _dbus_auth_script_run called 13 returned 100% blocks executed 52%
       13:  224:{
        -:  225:  DBusString file;
        -:  226:  DBusError error;
        -:  227:  DBusString line;
        -:  228:  dbus_bool_t retval;
        -:  229:  int line_no;
        -:  230:  DBusAuth *auth;
        -:  231:  DBusString from_auth;
        -:  232:  DBusAuthState state;
        -:  233:  DBusString context;
        -:  234:  DBusString guid;
        -:  235:  
       13:  236:  retval = FALSE;
       13:  237:  auth = NULL;
        -:  238:
       13:  239:  _dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00");
call    0 returned 100%
       13:  240:  _dbus_string_init_const (&context, "org_freedesktop_test");
call    0 returned 100%
        -:  241:  
       13:  242:  if (!_dbus_string_init (&file))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  243:    return FALSE;
        -:  244:
       13:  245:  if (!_dbus_string_init (&line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  246:    {
    #####:  247:      _dbus_string_free (&file);
call    0 never executed
    #####:  248:      return FALSE;
        -:  249:    }
        -:  250:
       13:  251:  if (!_dbus_string_init (&from_auth))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  252:    {
    #####:  253:      _dbus_string_free (&file);
call    0 never executed
    #####:  254:      _dbus_string_free (&line);
call    0 never executed
    #####:  255:      return FALSE;
        -:  256:    }
        -:  257:
       13:  258:  dbus_error_init (&error);
call    0 returned 100%
       13:  259:  if (!_dbus_file_get_contents (&file, filename, &error))    {
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  260:      _dbus_warn ("Getting contents of %s failed: %s\n",
call    0 never executed
call    1 never executed
        -:  261:                  _dbus_string_get_const_data (filename), error.message);
    #####:  262:      dbus_error_free (&error);
call    0 never executed
    #####:  263:      goto out;
        -:  264:    }
        -:  265:
       13:  266:  state = DBUS_AUTH_STATE_NEED_DISCONNECT;
       13:  267:  line_no = 0;
      164:  268: next_iteration:
      164:  269:  while (_dbus_string_pop_line (&file, &line))
call    0 returned 100%
branch  1 taken 92% (fallthrough)
branch  2 taken 8%
        -:  270:    {      
      151:  271:      line_no += 1;
        -:  272:
      151:  273:      _dbus_string_delete_leading_blanks (&line);
call    0 returned 100%
        -:  274:
      151:  275:      if (auth != NULL)
branch  0 taken 72% (fallthrough)
branch  1 taken 28%
        -:  276:        {
      239:  277:          while ((state = _dbus_auth_do_work (auth)) ==
call    0 returned 100%
branch  1 taken 18%
branch  2 taken 82% (fallthrough)
        -:  278:                 DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
        -:  279:            {
        -:  280:              const DBusString *tmp;
       23:  281:              if (_dbus_auth_get_bytes_to_send (auth, &tmp))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        -:  282:                {
       23:  283:                  int count = _dbus_string_get_length (tmp);
call    0 returned 100%
        -:  284:
       23:  285:                  if (_dbus_string_copy (tmp, 0, &from_auth,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
        -:  286:                                         _dbus_string_get_length (&from_auth)))
       23:  287:                    _dbus_auth_bytes_sent (auth, count);
call    0 returned 100%
        -:  288:                }
        -:  289:            }
        -:  290:        }
        -:  291:      
      151:  292:      if (_dbus_string_get_length (&line) == 0)
call    0 returned 100%
branch  1 taken 22% (fallthrough)
branch  2 taken 78%
        -:  293:        {
        -:  294:          /* empty line */
       33:  295:          goto next_iteration;
        -:  296:        }
      118:  297:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 23% (fallthrough)
branch  2 taken 77%
        -:  298:                                               "#"))
        -:  299:        {
        -:  300:          /* Ignore this comment */
       27:  301:          goto next_iteration;
        -:  302:        }
       91:  303:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 3% (fallthrough)
branch  2 taken 97%
        -:  304:                                               "CLIENT"))
        -:  305:        {
        -:  306:          DBusCredentials creds;
        -:  307:          
        3:  308:          if (auth != NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  309:            {
    #####:  310:              _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n");
call    0 never executed
    #####:  311:              goto out;
        -:  312:            }
        -:  313:
        3:  314:          auth = _dbus_auth_client_new ();
call    0 returned 100%
        3:  315:          if (auth == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  316:            {
    #####:  317:              _dbus_warn ("no memory to create DBusAuth\n");
call    0 never executed
    #####:  318:              goto out;
        -:  319:            }
        -:  320:
        -:  321:          /* test ref/unref */
        3:  322:          _dbus_auth_ref (auth);
call    0 returned 100%
        3:  323:          _dbus_auth_unref (auth);
call    0 returned 100%
        -:  324:          
        3:  325:          _dbus_credentials_from_current_process (&creds);
call    0 returned 100%
        3:  326:          _dbus_auth_set_credentials (auth, &creds);
call    0 returned 100%
        -:  327:        }
       88:  328:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 11% (fallthrough)
branch  2 taken 89%
        -:  329:                                               "SERVER"))
        -:  330:        {
        -:  331:          DBusCredentials creds;
        -:  332:          
       10:  333:          if (auth != NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  334:            {
    #####:  335:              _dbus_warn ("already created a DBusAuth (CLIENT or SERVER given twice)\n");
call    0 never executed
    #####:  336:              goto out;
        -:  337:            }
        -:  338:
       10:  339:          auth = _dbus_auth_server_new (&guid);
call    0 returned 100%
       10:  340:          if (auth == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  341:            {
    #####:  342:              _dbus_warn ("no memory to create DBusAuth\n");
call    0 never executed
    #####:  343:              goto out;
        -:  344:            }
        -:  345:
        -:  346:          /* test ref/unref */
       10:  347:          _dbus_auth_ref (auth);
call    0 returned 100%
       10:  348:          _dbus_auth_unref (auth);
call    0 returned 100%
        -:  349:          
       10:  350:          _dbus_credentials_from_current_process (&creds);
call    0 returned 100%
       10:  351:          _dbus_auth_set_credentials (auth, &creds);
call    0 returned 100%
       10:  352:          _dbus_auth_set_context (auth, &context);
call    0 returned 100%
        -:  353:        }
       78:  354:      else if (auth == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  355:        {
    #####:  356:          _dbus_warn ("must specify CLIENT or SERVER\n");
call    0 never executed
    #####:  357:          goto out;
        -:  358:
        -:  359:        }
       78:  360:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 3% (fallthrough)
branch  2 taken 97%
        -:  361:                                               "NO_CREDENTIALS"))
        -:  362:        {
        2:  363:          DBusCredentials creds = { -1, -1, -1 };
        2:  364:          _dbus_auth_set_credentials (auth, &creds);
call    0 returned 100%
        -:  365:        }
       76:  366:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  367:                                               "ROOT_CREDENTIALS"))
        -:  368:        {
        1:  369:          DBusCredentials creds = { -1, 0, 0 };
        1:  370:          _dbus_auth_set_credentials (auth, &creds);          
call    0 returned 100%
        -:  371:        }
       75:  372:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  373:                                               "SILLY_CREDENTIALS"))
        -:  374:        {
        1:  375:          DBusCredentials creds = { -1, 4312, 1232 };
        1:  376:          _dbus_auth_set_credentials (auth, &creds);          
call    0 returned 100%
        -:  377:        }
       74:  378:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  379:                                               "ALLOWED_MECHS"))
        -:  380:        {
        -:  381:          char **mechs;
        -:  382:
    #####:  383:          _dbus_string_delete_first_word (&line);
call    0 never executed
    #####:  384:          mechs = split_string (&line);
call    0 never executed
    #####:  385:          _dbus_auth_set_mechanisms (auth, (const char **) mechs);
call    0 never executed
    #####:  386:          dbus_free_string_array (mechs);
call    0 never executed
        -:  387:        }
       74:  388:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 34% (fallthrough)
branch  2 taken 66%
        -:  389:                                               "SEND"))
        -:  390:        {
        -:  391:          DBusString to_send;
        -:  392:          
       25:  393:          _dbus_string_delete_first_word (&line);
call    0 returned 100%
        -:  394:
       25:  395:          if (!_dbus_string_init (&to_send))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  396:            {
    #####:  397:              _dbus_warn ("no memory to allocate string\n");
call    0 never executed
    #####:  398:              goto out;
        -:  399:            }
        -:  400:
       25:  401:          if (!append_quoted_string (&to_send, &line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  402:            {
    #####:  403:              _dbus_warn ("failed to append quoted string line %d\n",
call    0 never executed
        -:  404:                          line_no);
    #####:  405:              _dbus_string_free (&to_send);
call    0 never executed
    #####:  406:              goto out;
        -:  407:            }
        -:  408:
       25:  409:          _dbus_verbose ("Sending '%s'\n", _dbus_string_get_const_data (&to_send));
call    0 returned 100%
call    1 returned 100%
        -:  410:          
       25:  411:          if (!_dbus_string_append (&to_send, "\r\n"))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  412:            {
    #####:  413:              _dbus_warn ("failed to append \r\n from line %d\n",
call    0 never executed
        -:  414:                          line_no);
    #####:  415:              _dbus_string_free (&to_send);
call    0 never executed
    #####:  416:              goto out;
        -:  417:            }
        -:  418:
        -:  419:          /* Replace USERID_HEX with our username in hex */
        -:  420:          {
        -:  421:            int where;
        -:  422:            
       25:  423:            if (_dbus_string_find (&to_send, 0,
call    0 returned 100%
branch  1 taken 52% (fallthrough)
branch  2 taken 48%
        -:  424:                                   "USERID_HEX", &where))
        -:  425:              {
        -:  426:                DBusString username;
        -:  427:
       13:  428:                if (!_dbus_string_init (&username))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  429:                  {
    #####:  430:                    _dbus_warn ("no memory for userid\n");
call    0 never executed
    #####:  431:                    _dbus_string_free (&to_send);
call    0 never executed
    #####:  432:                    goto out;
        -:  433:                  }
        -:  434:
       13:  435:                if (!_dbus_string_append_uint (&username,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  436:                                               _dbus_getuid ()))
        -:  437:                  {
    #####:  438:                    _dbus_warn ("no memory for userid\n");
call    0 never executed
    #####:  439:                    _dbus_string_free (&username);
call    0 never executed
    #####:  440:                    _dbus_string_free (&to_send);
call    0 never executed
    #####:  441:                    goto out;
        -:  442:                  }
        -:  443:
       13:  444:                _dbus_string_delete (&to_send, where, strlen ("USERID_HEX"));
call    0 returned 100%
        -:  445:                
       13:  446:                if (!_dbus_string_hex_encode (&username, 0,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  447:					      &to_send, where))
        -:  448:                  {
    #####:  449:                    _dbus_warn ("no memory to subst USERID_HEX\n");
call    0 never executed
    #####:  450:                    _dbus_string_free (&username);
call    0 never executed
    #####:  451:                    _dbus_string_free (&to_send);
call    0 never executed
    #####:  452:                    goto out;
        -:  453:                  }
        -:  454:
       13:  455:                _dbus_string_free (&username);
call    0 returned 100%
        -:  456:              }
       12:  457:            else if (_dbus_string_find (&to_send, 0,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  458:                                        "USERNAME_HEX", &where))
        -:  459:              {
        -:  460:                DBusString username;
        -:  461:                const DBusString *u;
        -:  462:                
    #####:  463:                if (!_dbus_string_init (&username))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  464:                  {
    #####:  465:                    _dbus_warn ("no memory for username\n");
call    0 never executed
    #####:  466:                    _dbus_string_free (&to_send);
call    0 never executed
    #####:  467:                    goto out;
        -:  468:                  }
        -:  469:
    #####:  470:                if (!_dbus_username_from_current_process (&u) ||
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
branch  5 never executed
branch  6 never executed
        -:  471:                    !_dbus_string_copy (u, 0, &username,
        -:  472:                                        _dbus_string_get_length (&username)))
        -:  473:                  {
    #####:  474:                    _dbus_warn ("no memory for username\n");
call    0 never executed
    #####:  475:                    _dbus_string_free (&username);
call    0 never executed
    #####:  476:                    _dbus_string_free (&to_send);
call    0 never executed
    #####:  477:                    goto out;
        -:  478:                  }
        -:  479:
    #####:  480:                _dbus_string_delete (&to_send, where, strlen ("USERNAME_HEX"));
call    0 never executed
        -:  481:                
    #####:  482:                if (!_dbus_string_hex_encode (&username, 0,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  483:					      &to_send, where))
        -:  484:                  {
    #####:  485:                    _dbus_warn ("no memory to subst USERNAME_HEX\n");
call    0 never executed
    #####:  486:                    _dbus_string_free (&username);
call    0 never executed
    #####:  487:                    _dbus_string_free (&to_send);
call    0 never executed
    #####:  488:                    goto out;
        -:  489:                  }
        -:  490:
    #####:  491:                _dbus_string_free (&username);
call    0 never executed
        -:  492:              }
        -:  493:          }
        -:  494:
        -:  495:          {
        -:  496:            DBusString *buffer;
        -:  497:
       25:  498:            _dbus_auth_get_buffer (auth, &buffer);
call    0 returned 100%
       25:  499:            if (!_dbus_string_copy (&to_send, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  500:                                    buffer, _dbus_string_get_length (buffer)))
        -:  501:              {
    #####:  502:                _dbus_warn ("not enough memory to call bytes_received, or can't add bytes to auth object already in end state\n");
call    0 never executed
    #####:  503:                _dbus_string_free (&to_send);
call    0 never executed
    #####:  504:                _dbus_auth_return_buffer (auth, buffer, 0);
call    0 never executed
    #####:  505:                goto out;
        -:  506:              }
        -:  507:
       25:  508:            _dbus_auth_return_buffer (auth, buffer, _dbus_string_get_length (&to_send));
call    0 returned 100%
call    1 returned 100%
        -:  509:          }
        -:  510:          
       25:  511:          _dbus_string_free (&to_send);
call    0 returned 100%
        -:  512:        }
       49:  513:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 51% (fallthrough)
branch  2 taken 49%
        -:  514:                                               "EXPECT_STATE"))
        -:  515:        {
        -:  516:          DBusAuthState expected;
        -:  517:          
       25:  518:          _dbus_string_delete_first_word (&line);
call    0 returned 100%
        -:  519:
       25:  520:          expected = auth_state_from_string (&line);
call    0 returned 100%
        -:  521:          if (expected < 0)
        -:  522:            {
        -:  523:              _dbus_warn ("bad auth state given to EXPECT_STATE\n");
        -:  524:              goto parse_failed;
        -:  525:            }
        -:  526:
       25:  527:          if (expected != state)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  528:            {
    #####:  529:              _dbus_warn ("expected auth state %s but got %s on line %d\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -:  530:                          auth_state_to_string (expected),
        -:  531:                          auth_state_to_string (state),
        -:  532:                          line_no);
    #####:  533:              goto out;
        -:  534:            }
        -:  535:        }
       24:  536:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 96% (fallthrough)
branch  2 taken 4%
        -:  537:                                               "EXPECT_COMMAND"))
        -:  538:        {
        -:  539:          DBusString received;
        -:  540:          
       23:  541:          _dbus_string_delete_first_word (&line);
call    0 returned 100%
        -:  542:
       23:  543:          if (!_dbus_string_init (&received))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  544:            {
    #####:  545:              _dbus_warn ("no mem to allocate string received\n");
call    0 never executed
    #####:  546:              goto out;
        -:  547:            }
        -:  548:
       23:  549:          if (!_dbus_string_pop_line (&from_auth, &received))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  550:            {
    #####:  551:              _dbus_warn ("no line popped from the DBusAuth being tested, expected command %s on line %d\n",
call    0 never executed
call    1 never executed
        -:  552:                          _dbus_string_get_const_data (&line), line_no);
    #####:  553:              _dbus_string_free (&received);
call    0 never executed
    #####:  554:              goto out;
        -:  555:            }
        -:  556:
       23:  557:          if (!same_first_word (&received, &line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  558:            {
    #####:  559:              _dbus_warn ("line %d expected command '%s' and got '%s'\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -:  560:                          line_no,
        -:  561:                          _dbus_string_get_const_data (&line),
        -:  562:                          _dbus_string_get_const_data (&received));
    #####:  563:              _dbus_string_free (&received);
call    0 never executed
    #####:  564:              goto out;
        -:  565:            }
        -:  566:          
       23:  567:          _dbus_string_free (&received);
call    0 returned 100%
        -:  568:        }
        1:  569:      else if (_dbus_string_starts_with_c_str (&line,
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        -:  570:                                               "EXPECT_UNUSED"))
        -:  571:        {
        -:  572:          DBusString expected;
        -:  573:          const DBusString *unused;
        -:  574:          
        1:  575:          _dbus_string_delete_first_word (&line);
call    0 returned 100%
        -:  576:
        1:  577:          if (!_dbus_string_init (&expected))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  578:            {
    #####:  579:              _dbus_warn ("no mem to allocate string expected\n");
call    0 never executed
    #####:  580:              goto out;
        -:  581:            }
        -:  582:
        1:  583:          if (!append_quoted_string (&expected, &line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  584:            {
    #####:  585:              _dbus_warn ("failed to append quoted string line %d\n",
call    0 never executed
        -:  586:                          line_no);
    #####:  587:              _dbus_string_free (&expected);
call    0 never executed
    #####:  588:              goto out;
        -:  589:            }
        -:  590:
        1:  591:          _dbus_auth_get_unused_bytes (auth, &unused);
call    0 returned 100%
        -:  592:          
        1:  593:          if (_dbus_string_equal (&expected, unused))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
        -:  594:            {
        1:  595:              _dbus_auth_delete_unused_bytes (auth);
call    0 returned 100%
        1:  596:              _dbus_string_free (&expected);
call    0 returned 100%
        -:  597:            }
        -:  598:          else
        -:  599:            {
    #####:  600:              _dbus_warn ("Expected unused bytes '%s' and have '%s'\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -:  601:                          _dbus_string_get_const_data (&expected),
        -:  602:                          _dbus_string_get_const_data (unused));
    #####:  603:              _dbus_string_free (&expected);
call    0 never executed
    #####:  604:              goto out;
        -:  605:            }
        -:  606:        }
    #####:  607:      else if (_dbus_string_starts_with_c_str (&line,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  608:                                               "EXPECT"))
        -:  609:        {
        -:  610:          DBusString expected;
        -:  611:          
    #####:  612:          _dbus_string_delete_first_word (&line);
call    0 never executed
        -:  613:
    #####:  614:          if (!_dbus_string_init (&expected))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  615:            {
    #####:  616:              _dbus_warn ("no mem to allocate string expected\n");
call    0 never executed
    #####:  617:              goto out;
        -:  618:            }
        -:  619:
    #####:  620:          if (!append_quoted_string (&expected, &line))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  621:            {
    #####:  622:              _dbus_warn ("failed to append quoted string line %d\n",
call    0 never executed
        -:  623:                          line_no);
    #####:  624:              _dbus_string_free (&expected);
call    0 never executed
    #####:  625:              goto out;
        -:  626:            }
        -:  627:
    #####:  628:          if (_dbus_string_equal_len (&expected, &from_auth,
call    0 never executed
call    1 never executed
branch  2 never executed
branch  3 never executed
        -:  629:                                      _dbus_string_get_length (&expected)))
        -:  630:            {
    #####:  631:              _dbus_string_delete (&from_auth, 0,
call    0 never executed
call    1 never executed
        -:  632:                                   _dbus_string_get_length (&expected));
    #####:  633:              _dbus_string_free (&expected);
call    0 never executed
        -:  634:            }
        -:  635:          else
        -:  636:            {
    #####:  637:              _dbus_warn ("Expected exact string '%s' and have '%s'\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -:  638:                          _dbus_string_get_const_data (&expected),
        -:  639:                          _dbus_string_get_const_data (&from_auth));
    #####:  640:              _dbus_string_free (&expected);
call    0 never executed
    #####:  641:              goto out;
        -:  642:            }
        -:  643:        }
        -:  644:      else
    #####:  645:        goto parse_failed;
        -:  646:
       91:  647:      goto next_iteration; /* skip parse_failed */
        -:  648:      
    #####:  649:    parse_failed:
        -:  650:      {
    #####:  651:        _dbus_warn ("couldn't process line %d \"%s\"\n",
call    0 never executed
call    1 never executed
        -:  652:                    line_no, _dbus_string_get_const_data (&line));
    #####:  653:        goto out;
        -:  654:      }
        -:  655:    }
        -:  656:
       13:  657:  if (auth != NULL &&
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 38% (fallthrough)
branch  3 taken 62%
        -:  658:      state == DBUS_AUTH_STATE_AUTHENTICATED)
        -:  659:    {
        -:  660:      const DBusString *unused;
        -:  661:
        5:  662:      _dbus_auth_get_unused_bytes (auth, &unused);
call    0 returned 100%
        -:  663:
        5:  664:      if (_dbus_string_get_length (unused) > 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  665:        {
    #####:  666:          _dbus_warn ("did not expect unused bytes (scripts must specify explicitly if they are expected)\n");
call    0 never executed
    #####:  667:          goto out;
        -:  668:        }
        -:  669:    }
        -:  670:
       13:  671:  if (_dbus_string_get_length (&from_auth) > 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  672:    {
    #####:  673:      _dbus_warn ("script did not have EXPECT_ statements for all the data received from the DBusAuth\n");
call    0 never executed
    #####:  674:      _dbus_warn ("Leftover data: %s\n", _dbus_string_get_const_data (&from_auth));
call    0 never executed
call    1 never executed
    #####:  675:      goto out;
        -:  676:    }
        -:  677:  
       13:  678:  retval = TRUE;
        -:  679:  
       13:  680: out:
       13:  681:  if (auth)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
       13:  682:    _dbus_auth_unref (auth);
call    0 returned 100%
        -:  683:
       13:  684:  _dbus_string_free (&file);
call    0 returned 100%
       13:  685:  _dbus_string_free (&line);
call    0 returned 100%
       13:  686:  _dbus_string_free (&from_auth);
call    0 returned 100%
        -:  687:  
       13:  688:  return retval;
        -:  689:}
        -:  690:
        -:  691:/** @} */
        -:  692:#endif /* DBUS_BUILD_TESTS */