Exemplo n.º 1
0
/* We have a value for this node.  Calculate the length of the header
   and store it in node->nhdr and store the length of the value in
   node->value. We assume that this is a primitive node and has a
   value of type VALTYPE_MEM. */
static void
set_nhdr_and_len (AsnNode node, unsigned long length)
{
  int buflen = 0;

  if (node->type == TYPE_SET_OF || node->type == TYPE_SEQUENCE_OF)
    buflen++;
  else if (node->type == TYPE_TAG)
    buflen++;
  else if (node->type < 0x1f || node->type == TYPE_PRE_SEQUENCE)
    buflen++;
  else
    {
      never_reached ();
      /* Fixme: tags with values above 31 are not yet implemented */
    }

  if (!node->type /*&& !class*/)
    buflen++; /* end tag */
  else if (node->type == TYPE_NULL /*&& !class*/)
    buflen++; /* NULL tag */
  else if (!length)
    buflen++; /* indefinite length */
  else if (length < 128)
    buflen++;
  else
    {
      buflen += (length <= 0xff ? 2:
                 length <= 0xffff ? 3:
                 length <= 0xffffff ? 4: 5);
    }

  node->len = length;
  node->nhdr = buflen;
}
Exemplo n.º 2
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT("Compiler_Features_10_Test"));
  try
    {
      // ... start the test fresh ...
      reset_counts();
      // Let's try to build a simple object and destroy it, without any
      // exceptions raised ...
      May_Pop m1(false);
      // ... two instances of the base class should be created ...
      check_constructor_count(2, __FILE__, __LINE__);
      // ... but only one instance is destroyed at this point ...
      check_destructor_count(1, __FILE__, __LINE__);
    }
  catch (...)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error: Unexpected exception caught\n")));
    }
  // ... now both instances are gone ...
  check_destructor_count(2, __FILE__, __LINE__);

  try
    {
      // ... start the test fresh ...
      reset_counts();
      // ... now raise an exception ...
      May_Pop m1(true);
      never_reached(__FILE__, __LINE__);
    }
  catch(...)
    {
      // ... only one instance gets created ...
      check_constructor_count(1, __FILE__, __LINE__);
      // ... and it is gone ...
      check_destructor_count(1, __FILE__, __LINE__);
    }

  try
    {
      // ... start the test fresh ...
      reset_counts();
      // ... now build a complex object with a failure in the middle ...
      Aggregate a;
      never_reached(__FILE__, __LINE__);
    }
  catch(...)
    {
      // ... check the expectations ...
      check_constructor_count(4, __FILE__, __LINE__);
      check_destructor_count(4, __FILE__, __LINE__);
    }

  try
    {
      // ... start the test fresh ...
      reset_counts();
      std::auto_ptr<Aggregate> b(new Aggregate);
      never_reached(__FILE__, __LINE__);
    }
  catch(...)
    {
      // ... check the expectations ...
      check_constructor_count(4, __FILE__, __LINE__);
      check_destructor_count(4, __FILE__, __LINE__);
      check_alloc_count(1, __FILE__, __LINE__);
    }

  ACE_END_TEST;
  return status();
}
Exemplo n.º 3
0
/* Note: When in ephemeral mode the search function does visit all
   blobs but in standard mode, blobs flagged as ephemeral are ignored.  */
int
keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
{
  int rc;
  size_t n;
  int need_words, any_skip;
  KEYBOXBLOB blob = NULL;
  struct sn_array_s *sn_array = NULL;

  if (!hd)
    return gpg_error (GPG_ERR_INV_VALUE);

  /* clear last found result */
  if (hd->found.blob)
    {
      _keybox_release_blob (hd->found.blob);
      hd->found.blob = NULL;
    }

  if (hd->error)
    return hd->error; /* still in error state */
  if (hd->eof)
    return -1; /* still EOF */

  /* figure out what information we need */
  need_words = any_skip = 0;
  for (n=0; n < ndesc; n++)
    {
      switch (desc[n].mode)
        {
        case KEYDB_SEARCH_MODE_WORDS:
          need_words = 1;
          break;
        case KEYDB_SEARCH_MODE_FIRST:
          /* always restart the search in this mode */
          keybox_search_reset (hd);
          break;
        default:
          break;
	}
      if (desc[n].skipfnc)
        any_skip = 1;
      if (desc[n].snlen == -1 && !sn_array)
        {
          sn_array = xtrycalloc (ndesc, sizeof *sn_array);
          if (!sn_array)
            return (hd->error = gpg_error_from_syserror ());
        }
    }

  (void)need_words;  /* Not yet implemented.  */

  if (!hd->fp)
    {
      hd->fp = fopen (hd->kb->fname, "rb");
      if (!hd->fp)
        {
          hd->error = gpg_error_from_syserror ();
          xfree (sn_array);
          return hd->error;
        }
    }

  /* Kludge: We need to convert an SN given as hexstring to its binary
     representation - in some cases we are not able to store it in the
     search descriptor, because due to the way we use it, it is not
     possible to free allocated memory. */
  if (sn_array)
    {
      const unsigned char *s;
      int i, odd;
      size_t snlen;

      for (n=0; n < ndesc; n++)
        {
          if (!desc[n].sn)
            ;
          else if (desc[n].snlen == -1)
            {
              unsigned char *sn;

              s = desc[n].sn;
              for (i=0; *s && *s != '/'; s++, i++)
                ;
              odd = (i & 1);
              snlen = (i+1)/2;
              sn_array[n].sn = xtrymalloc (snlen);
              if (!sn_array[n].sn)
                {
                  hd->error = gpg_error_from_syserror ();
                  release_sn_array (sn_array, n);
                  return hd->error;
                }
              sn_array[n].snlen = snlen;
              sn = sn_array[n].sn;
              s = desc[n].sn;
              if (odd)
                {
                  *sn++ = xtoi_1 (s);
                  s++;
                }
              for (; *s && *s != '/';  s += 2)
                *sn++ = xtoi_2 (s);
            }
          else
            {
              const unsigned char *sn;

              sn = desc[n].sn;
              snlen = desc[n].snlen;
              sn_array[n].sn = xtrymalloc (snlen);
              if (!sn_array[n].sn)
                {
                  hd->error = gpg_error_from_syserror ();
                  release_sn_array (sn_array, n);
                  return hd->error;
                }
              sn_array[n].snlen = snlen;
              memcpy (sn_array[n].sn, sn, snlen);
            }
        }
    }


  for (;;)
    {
      unsigned int blobflags;

      _keybox_release_blob (blob); blob = NULL;
      rc = _keybox_read_blob (&blob, hd->fp);
      if (rc)
        break;

      if (blob_get_type (blob) == BLOBTYPE_HEADER)
        continue;


      blobflags = blob_get_blob_flags (blob);
      if (!hd->ephemeral && (blobflags & 2))
        continue; /* Not in ephemeral mode but blob is flagged ephemeral.  */

      for (n=0; n < ndesc; n++)
        {
          switch (desc[n].mode)
            {
            case KEYDB_SEARCH_MODE_NONE:
              never_reached ();
              break;
            case KEYDB_SEARCH_MODE_EXACT:
              if (has_subject_or_alt (blob, desc[n].u.name, 0))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_MAIL:
              if (has_mail (blob, desc[n].u.name, 0))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_MAILSUB:
              if (has_mail (blob, desc[n].u.name, 1))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_SUBSTR:
              if (has_subject_or_alt (blob, desc[n].u.name, 1))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_MAILEND:
            case KEYDB_SEARCH_MODE_WORDS:
              never_reached (); /* not yet implemented */
              break;
            case KEYDB_SEARCH_MODE_ISSUER:
              if (has_issuer (blob, desc[n].u.name))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_ISSUER_SN:
              if (has_issuer_sn (blob, desc[n].u.name,
                                 sn_array? sn_array[n].sn : desc[n].sn,
                                 sn_array? sn_array[n].snlen : desc[n].snlen))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_SN:
              if (has_sn (blob, sn_array? sn_array[n].sn : desc[n].sn,
                                sn_array? sn_array[n].snlen : desc[n].snlen))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_SUBJECT:
              if (has_subject (blob, desc[n].u.name))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_SHORT_KID:
              if (has_short_kid (blob, desc[n].u.kid[1]))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_LONG_KID:
              if (has_long_kid (blob, desc[n].u.kid[0], desc[n].u.kid[1]))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_FPR:
            case KEYDB_SEARCH_MODE_FPR20:
              if (has_fingerprint (blob, desc[n].u.fpr))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_KEYGRIP:
              if (has_keygrip (blob, desc[n].u.grip))
                goto found;
              break;
            case KEYDB_SEARCH_MODE_FIRST:
              goto found;
              break;
            case KEYDB_SEARCH_MODE_NEXT:
              goto found;
              break;
            default:
              rc = gpg_error (GPG_ERR_INV_VALUE);
              goto found;
            }
	}
      continue;
    found:
      for (n=any_skip?0:ndesc; n < ndesc; n++)
        {
/*            if (desc[n].skipfnc */
/*                && desc[n].skipfnc (desc[n].skipfncvalue, aki, NULL)) */
/*              break; */
        }
      if (n == ndesc)
        break; /* got it */
    }

  if (!rc)
    {
      hd->found.blob = blob;
    }
  else if (rc == -1)
    {
      _keybox_release_blob (blob);
      hd->eof = 1;
    }
  else
    {
      _keybox_release_blob (blob);
      hd->error = rc;
    }

  if (sn_array)
    release_sn_array (sn_array, ndesc);

  return rc;
}