Exemplo n.º 1
0
static int
pdkim_header_complete(pdkim_ctx *ctx)
{
/* Special case: The last header can have an extra \r appended */
if ( (ctx->cur_header->len > 1) &&
     (ctx->cur_header->str[(ctx->cur_header->len)-1] == '\r') )
  {
  ctx->cur_header->str[(ctx->cur_header->len)-1] = '\0';
  ctx->cur_header->len--;
  }

ctx->num_headers++;
if (ctx->num_headers > PDKIM_MAX_HEADERS) goto BAIL;

/* SIGNING -------------------------------------------------------------- */
if (ctx->mode == PDKIM_MODE_SIGN)
  {
  pdkim_signature *sig;

  for (sig = ctx->sig; sig; sig = sig->next)			/* Traverse all signatures */
    if (header_name_match(ctx->cur_header->str,
			  sig->sign_headers?
			    sig->sign_headers:
			    PDKIM_DEFAULT_SIGN_HEADERS, 0) == PDKIM_OK)
      {
      pdkim_stringlist *list;

      /* Add header to the signed headers list (in reverse order) */
      if (!(list = pdkim_prepend_stringlist(sig->headers,
				    ctx->cur_header->str)))
	return PDKIM_ERR_OOM;
      sig->headers = list;
      }
  }

/* VERIFICATION ----------------------------------------------------------- */
/* DKIM-Signature: headers are added to the verification list */
if (ctx->mode == PDKIM_MODE_VERIFY)
  {
  if (strncasecmp(ctx->cur_header->str,
		  DKIM_SIGNATURE_HEADERNAME,
		  strlen(DKIM_SIGNATURE_HEADERNAME)) == 0)
    {
    pdkim_signature *new_sig;

    /* Create and chain new signature block */
    DEBUG(D_acl) debug_printf(
	"PDKIM >> Found sig, trying to parse >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");

    if ((new_sig = pdkim_parse_sig_header(ctx, ctx->cur_header->str)))
      {
      pdkim_signature *last_sig = ctx->sig;
      if (!last_sig)
	ctx->sig = new_sig;
      else
        {
	while (last_sig->next) last_sig = last_sig->next;
	last_sig->next = new_sig;
	}
      }
    else
      DEBUG(D_acl) debug_printf(
	  "Error while parsing signature header\n"
	  "PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    }

  /* every other header is stored for signature verification */
  else
    {
    pdkim_stringlist *list;

    if (!(list = pdkim_prepend_stringlist(ctx->headers, ctx->cur_header->str)))
      return PDKIM_ERR_OOM;
    ctx->headers = list;
    }
  }

BAIL:
pdkim_strclear(ctx->cur_header); /* Re-use existing pdkim_str */
return PDKIM_OK;
}
Exemplo n.º 2
0
Arquivo: pdkim.c Projeto: ytrezq/exim
static int
pdkim_header_complete(pdkim_ctx *ctx)
{
/* Special case: The last header can have an extra \r appended */
if ( (ctx->cur_header_len > 1) &&
     (ctx->cur_header[(ctx->cur_header_len)-1] == '\r') )
  --ctx->cur_header_len;
ctx->cur_header[ctx->cur_header_len] = '\0';

ctx->num_headers++;
if (ctx->num_headers > PDKIM_MAX_HEADERS) goto BAIL;

/* SIGNING -------------------------------------------------------------- */
if (ctx->mode == PDKIM_MODE_SIGN)
  {
  pdkim_signature *sig;

  for (sig = ctx->sig; sig; sig = sig->next)			/* Traverse all signatures */

    /* Add header to the signed headers list (in reverse order) */
    sig->headers = pdkim_prepend_stringlist(sig->headers,
				  ctx->cur_header);
  }

/* VERIFICATION ----------------------------------------------------------- */
/* DKIM-Signature: headers are added to the verification list */
if (ctx->mode == PDKIM_MODE_VERIFY)
  {
  if (strncasecmp(CCS ctx->cur_header,
		  DKIM_SIGNATURE_HEADERNAME,
		  Ustrlen(DKIM_SIGNATURE_HEADERNAME)) == 0)
    {
    pdkim_signature *new_sig;

    /* Create and chain new signature block */
    DEBUG(D_acl) debug_printf(
	"PDKIM >> Found sig, trying to parse >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");

    if ((new_sig = pdkim_parse_sig_header(ctx, ctx->cur_header)))
      {
      pdkim_signature *last_sig = ctx->sig;
      if (!last_sig)
	ctx->sig = new_sig;
      else
        {
	while (last_sig->next) last_sig = last_sig->next;
	last_sig->next = new_sig;
	}
      }
    else
      DEBUG(D_acl) debug_printf(
	  "Error while parsing signature header\n"
	  "PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    }

  /* every other header is stored for signature verification */
  else
    ctx->headers = pdkim_prepend_stringlist(ctx->headers, ctx->cur_header);
  }

BAIL:
*ctx->cur_header = '\0';
ctx->cur_header_len = 0;	/* leave buffer for reuse */
return PDKIM_OK;
}