Exemplo n.º 1
0
static void
run_test (void)
{
  static struct
  {
    const char *userid;
    const char *mbox;
  } testtbl[] =
    {
      { "Werner Koch <*****@*****.**>", "*****@*****.**" },
      { "<*****@*****.**>", "*****@*****.**" },
      { "*****@*****.**", "*****@*****.**" },
      { "[email protected] ", NULL },
      { " [email protected]", NULL },
      { "Werner Koch (test) <*****@*****.**>", "*****@*****.**" },
      { "Werner Koch <*****@*****.**> (test)", "*****@*****.**" },
      { "Werner Koch <[email protected] (test)", NULL },
      { "Werner Koch <*****@*****.** >", NULL },
      { "Werner Koch <*****@*****.**", NULL },
      { "", NULL },
      { "@", NULL },
      { "bar <>", NULL },
      { "<*****@*****.**>", "*****@*****.**" },
      { "<*****@*****.**>", "*****@*****.**" },
      { "<*****@*****.**>", "*****@*****.**" },
      { "<*****@*****.**>", "*****@*****.**" },
      { "<*****@*****.**>", "*****@*****.**" },
      { "<[email protected].>", NULL },
      { "<*****@*****.**>", NULL },
      { "<foo@.>", NULL },
      { "<@example.org>", NULL },
      { "<foo@@example.org>", NULL },
      { "<@[email protected]>", NULL },
      { "<*****@*****.**> ()", "*****@*****.**" },
      { "<fo()[email protected]> ()", "fo()[email protected]" },
      { "<fo()[email protected]> ()", "fo()[email protected]" },
      { "fo()[email protected]", NULL},
      { "Mr. Foo <*****@*****.**><*****@*****.**>", "*****@*****.**"},
      { NULL, NULL }
    };
  int idx;

  for (idx=0; testtbl[idx].userid; idx++)
    {
      char *mbox = mailbox_from_userid (testtbl[idx].userid);

      if (!testtbl[idx].mbox)
        {
          if (mbox)
            fail (idx);
        }
      else if (!mbox)
        fail (idx);
      else if (strcmp (mbox, testtbl[idx].mbox))
        fail (idx);

      xfree (mbox);
    }
}
Exemplo n.º 2
0
/* Append UID to LIST and return the new item.  On success LIST is
 * updated.  On error ERRNO is set and NULL returned. */
static uidinfo_list_t
append_to_uidinfo_list (uidinfo_list_t *list, const char *uid, time_t created)
{
  uidinfo_list_t r, sl;

  sl = xtrymalloc (sizeof *sl + strlen (uid));
  if (!sl)
    return NULL;

  strcpy (sl->uid, uid);
  sl->created = created;
  sl->mbox = mailbox_from_userid (uid);
  sl->next = NULL;
  if (!*list)
    *list = sl;
  else
    {
      for (r = *list; r->next; r = r->next )
        ;
      r->next = sl;
    }
  return sl;
}
Exemplo n.º 3
0
Arquivo: sign.c Projeto: larryv/gnupg
/****************
 * Create notations and other stuff.  It is assumed that the stings in
 * STRLIST are already checked to contain only printable data and have
 * a valid NAME=VALUE format.
 */
static void
mk_notation_policy_etc (PKT_signature *sig,
			PKT_public_key *pk, PKT_public_key *pksk)
{
  const char *string;
  char *p = NULL;
  strlist_t pu = NULL;
  struct notation *nd = NULL;
  struct expando_args args;

  log_assert (sig->version >= 4);

  memset (&args, 0, sizeof(args));
  args.pk = pk;
  args.pksk = pksk;

  /* Notation data. */
  if (IS_SIG(sig) && opt.sig_notations)
    nd = opt.sig_notations;
  else if (IS_CERT(sig) && opt.cert_notations)
    nd = opt.cert_notations;

  if (nd)
    {
      struct notation *item;

      for (item = nd; item; item = item->next)
        {
          item->altvalue = pct_expando (item->value,&args);
          if (!item->altvalue)
            log_error (_("WARNING: unable to %%-expand notation "
                         "(too large).  Using unexpanded.\n"));
        }

      keygen_add_notations (sig, nd);

      for (item = nd; item; item = item->next)
        {
          xfree (item->altvalue);
          item->altvalue = NULL;
        }
    }

  /* Set policy URL. */
  if (IS_SIG(sig) && opt.sig_policy_url)
    pu = opt.sig_policy_url;
  else if (IS_CERT(sig) && opt.cert_policy_url)
    pu = opt.cert_policy_url;

  for (; pu; pu = pu->next)
    {
      string = pu->d;

      p = pct_expando (string, &args);
      if (!p)
        {
          log_error(_("WARNING: unable to %%-expand policy URL "
                      "(too large).  Using unexpanded.\n"));
          p = xstrdup(string);
        }

      build_sig_subpkt (sig, (SIGSUBPKT_POLICY
                              | ((pu->flags & 1)?SIGSUBPKT_FLAG_CRITICAL:0)),
                        p, strlen (p));

      xfree (p);
    }

  /* Preferred keyserver URL. */
  if (IS_SIG(sig) && opt.sig_keyserver_url)
    pu = opt.sig_keyserver_url;

  for (; pu; pu = pu->next)
    {
      string = pu->d;

      p = pct_expando (string, &args);
      if (!p)
        {
          log_error (_("WARNING: unable to %%-expand preferred keyserver URL"
                       " (too large).  Using unexpanded.\n"));
          p = xstrdup (string);
        }

      build_sig_subpkt (sig, (SIGSUBPKT_PREF_KS
                              | ((pu->flags & 1)?SIGSUBPKT_FLAG_CRITICAL:0)),
                        p, strlen (p));
      xfree (p);
    }

  /* Set signer's user id.  */
  if (IS_SIG (sig) && !opt.flags.disable_signer_uid)
    {
      char *mbox;

      /* For now we use the uid which was used to locate the key.  */
      if (pksk->user_id && (mbox = mailbox_from_userid (pksk->user_id->name)))
        {
          if (DBG_LOOKUP)
            log_debug ("setting Signer's UID to '%s'\n", mbox);
          build_sig_subpkt (sig, SIGSUBPKT_SIGNERS_UID, mbox, strlen (mbox));
          xfree (mbox);
        }
      else if (opt.sender_list)
        {
          /* If a list of --sender was given we scan that list and use
           * the first one matching a user id of the current key.  */

          /* FIXME: We need to get the list of user ids for the PKSK
           * packet.  That requires either a function to look it up
           * again or we need to extend the key packet struct to link
           * to the primary key which in turn could link to the user
           * ids.  Too much of a change right now.  Let's take just
           * one from the supplied list and hope that the caller
           * passed a matching one.  */
          build_sig_subpkt (sig, SIGSUBPKT_SIGNERS_UID,
                            opt.sender_list->d, strlen (opt.sender_list->d));
        }
    }
}