Ejemplo n.º 1
0
void target_primary_os(void)
{
    if (token_get("CONFIG_RG_OS_LINUX_24"))
	token_set("CONFIG_RG_OS", "LINUX_24");
    else if (token_get("CONFIG_RG_OS_LINUX_26"))
	token_set("CONFIG_RG_OS", "LINUX_26");
}
/* TODO:
   digest-challenge tken has no order preference??
   verify many situations (extra SP....)
*/
int
authorization_parse (authorization_t * auth, char *hvalue)
{
  char *space = NULL;
  char *next = NULL;

  space = strchr (hvalue, ' ');	/* SEARCH FOR SPACE */
  if (space == NULL)
    return -1;

  if (space - hvalue < 1)
    return -1;
  auth->auth_type = (char *) smalloc (space - hvalue + 1);
  sstrncpy (auth->auth_type, hvalue, space - hvalue);

  for (;;)
    {
      int parse_ok = 0;

      if (quoted_string_set ("username", space, &(auth->username), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("realm", space, &(auth->realm), &next))
	return -1;
      if (next == NULL)
	return 0;
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("nonce", space, &(auth->nonce), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("uri", space, &(auth->uri), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("response", space, &(auth->response), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("digest", space, &(auth->digest), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (token_set ("algorithm", space, &(auth->algorithm), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("cnonce", space, &(auth->cnonce), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("opaque", space, &(auth->opaque), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (token_set ("qop", space, &(auth->message_qop), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (token_set ("nc", space, &(auth->nonce_count), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      /* nothing was recognized:
         here, we should handle a list of unknown tokens where:
         token1 = ( token2 | quoted_text ) */
      /* TODO */

      if (0 == parse_ok)
	{
	  char *quote1, *quote2, *tmp;

	  /* CAUTION */
	  /* parameter not understood!!! I'm too lazy to handle IT */
	  /* let's simply bypass it */
	  if (strlen (space) < 1)
	    return 0;
	  tmp = strchr (space + 1, ',');
	  if (tmp == NULL)	/* it was the last header */
	    return 0;
	  quote1 = quote_find (space);
	  if ((quote1 != NULL) && (quote1 < tmp))	/* this may be a quoted string! */
	    {
	      quote2 = quote_find (quote1 + 1);
	      if (quote2 == NULL)
		return -1;	/* bad header format... */
	      if (tmp < quote2)	/* the comma is inside the quotes! */
		space = strchr (quote2, ',');
	      else
		space = tmp;
	      if (space == NULL)	/* it was the last header */
		return 0;
	    }
	  else
	    space = tmp;
	  /* continue parsing... */
	}
    }
  return 0;			/* ok */
}
void target_os_features(char *os)
{
    /* target OS */
    if (!strcmp(os, "LINUX_24"))
	token_set_y("CONFIG_RG_OS_LINUX_24");
    else if (!strcmp(os, "LINUX_26"))
	token_set_y("CONFIG_RG_OS_LINUX_26");
    else if (!strcmp(os, "ECOS"))
	token_set_y("CONFIG_RG_OS_ECOS");
    else if (!strcmp(os, "VXWORKS"))
	token_set_y("CONFIG_RG_OS_VXWORKS");

    /* VxWorks special behaviour */
    if (token_get("CONFIG_RG_OS_VXWORKS"))
    {
	token_set_y("CONFIG_RG_NOT_UNIX");
	token_set_y("CONFIG_RG_EFSS");
        if (token_get("CONFIG_RG_DEV"))
	    token_set_y("CONFIG_VX_SYMTBL");
	token_set_y("CONFIG_RG_VX_TIMERS_TASK");
    }

    /* Linux Kernel generic configs */
    if (token_get("CONFIG_RG_OS_LINUX_26"))
    {
	token_set_y("CONFIG_RG_OS_LINUX");

	/* Generic kernel */
	
	token_set("CONFIG_INIT_ENV_ARG_LIMIT", "32");
	token_set_y("CONFIG_PRINTK");
	token_set("CONFIG_LOG_BUF_SHIFT", "14");
	token_set_y("CONFIG_BUG");
	if (!token_get("CONFIG_FEROCEON_COMMON"))
	    token_set_y("CONFIG_TINY_SHMEM");
	token_set("CONFIG_BASE_SMALL", "0");
	token_set_y("CONFIG_GENERIC_CALIBRATE_DELAY");
	if (!token_get("CONFIG_COMCERTO_COMMON") &&
	    !token_get("CONFIG_ARCH_SOLOS") &&
	    !token_get("CONFIG_FEROCEON_COMMON"))
	{
	    token_set_y("CONFIG_GENERIC_HARDIRQS");
	}
	token_set_y("CONFIG_SYSCTL");
	token_set_y("CONFIG_BINFMT_ELF");
	token_set_y("CONFIG_CRC32");
	token_set_y("CONFIG_MMU");
	token_set_y("CONFIG_IOSCHED_NOOP");
	token_set_y("CONFIG_IOSCHED_AS");
	token_set_y("CONFIG_IOSCHED_DEADLINE");
	token_set_y("CONFIG_IOSCHED_CFQ");
	token_set_y("CONFIG_SYSVIPC");
	token_set("CONFIG_DEFAULT_IOSCHED", "\"anticipatory\"");
	token_set_y("CONFIG_SLAB");

	/* Pseudo_filesystems */
	
	token_set_y("CONFIG_RAMFS");

	if (!token_get("CONFIG_RG_RGLOADER"))
	{
	    token_set_y("CONFIG_PROC_FS");
	    token_set_y("CONFIG_SYSFS");
	    token_set_m("CONFIG_RG_IPV4");
	}

	/* Modules support */
	
	token_set_y("CONFIG_MODULES");
	if (!token_get("CONFIG_ARCH_SOLOS"))
	    token_set_y("CONFIG_MODULE_UNLOAD");
	token_set_y("CONFIG_OBSOLETE_MODPARM");
	token_set_y("CONFIG_KMOD");

	/* Networking (recheck) */
	
	token_set_y("CONFIG_NET");
	token_set_y("CONFIG_NETDEVICES");
	token_set_y("CONFIG_PACKET");
	token_set_y("CONFIG_UNIX");
	token_set_y("CONFIG_INET");
	token_set_y("CONFIG_IP_MULTICAST");
	token_set_y("CONFIG_IP_FIB_HASH");
	token_set_y("CONFIG_IP_ADVANCED_ROUTER");
	token_set_y("CONFIG_NET_ETHERNET");
	token_set_y("CONFIG_IP_MULTIPLE_TABLES");
	token_set_y("CONFIG_XFRM");
	token_set_y("CONFIG_NET_SCH_CLK_JIFFIES");

	/* PTY */
	token_set_y("CONFIG_LEGACY_PTYS");
	token_set("CONFIG_LEGACY_PTY_COUNT", "256");

	/* Override only if LZMA is not fast enough */
	token_set("CONFIG_RG_KERNEL_COMP_METHOD", "lzma");
    }

    if (token_get("CONFIG_RG_OS_LINUX_24"))
    {
	token_set_y("CONFIG_UID16");
	token_set_y("CONFIG_RWSEM_GENERIC_SPINLOCK");
	token_set_y("CONFIG_IP_MULTICAST");
	token_set_y("CONFIG_IP_ADVANCED_ROUTER");
	token_set_y("CONFIG_UNIX");
	token_set_y("CONFIG_RG_OS_LINUX");
	token_set_y("CONFIG_INET");
	token_set_y("CONFIG_MODULES");
	token_set_y("CONFIG_NET");
	token_set_y("CONFIG_NETDEVICES");
	token_set_y("CONFIG_NETLINK_DEV");
	token_set_y("CONFIG_FILTER");
	token_set_y("CONFIG_NET_ETHERNET");
	token_set_y("CONFIG_PACKET");
	token_set_y("CONFIG_SYSVIPC");

	if (!token_get("CONFIG_RG_RGLOADER"))
	{
	    token_set_y("CONFIG_PROC_FS");
	    token_set_m("CONFIG_RG_IPV4");
	}
	
	/* Override only if LZMA is not fast enough */
	token_set("CONFIG_RG_KERNEL_COMP_METHOD", "lzma");
    }
	
    if (token_get("CONFIG_RG_OS_LINUX"))
	token_set_y("CONFIG_RG_TTYP");

    /* Set CONFIG_RG_TARGET_xxx */
    if (token_get("CONFIG_RG_OS_LINUX"))
	token_set_y("CONFIG_RG_TARGET_LINUX");
    if (token_get("CONFIG_RG_OS_VXWORKS"))
	token_set_y("CONFIG_RG_TARGET_VXWORKS");
}
/* TODO:
   digest-challenge tken has no order preference??
   verify many situations (extra SP....)
*/
int
www_authenticate_parse (www_authenticate_t * wwwa, char *hvalue)
{
  char *space = NULL;
  char *next = NULL;

  space = strchr (hvalue, ' ');	/* SEARCH FOR SPACE */
  if (space == NULL)
    return -1;

  if (space - hvalue + 1 < 2)
    return -1;
  wwwa->auth_type = (char *) smalloc (space - hvalue + 1);
  if (wwwa->auth_type == NULL)
    return -1;
  sstrncpy (wwwa->auth_type, hvalue, space - hvalue);

  for (;;)
    {
      int parse_ok = 0;

      if (quoted_string_set ("realm", space, &(wwwa->realm), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("domain", space, &(wwwa->domain), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("nonce", space, &(wwwa->nonce), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("opaque", space, &(wwwa->opaque), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (token_set ("stale", space, &(wwwa->stale), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (token_set ("algorithm", space, &(wwwa->algorithm), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (quoted_string_set ("qop", space, &(wwwa->qop_options), &next))
	return -1;
      if (next == NULL)
	return 0;		/* end of header detected! */
      else if (next != space)
	{
	  space = next;
	  parse_ok++;
	}
      if (0 == parse_ok)
	{
	  char *quote1, *quote2, *tmp;

	  /* CAUTION */
	  /* parameter not understood!!! I'm too lazy to handle IT */
	  /* let's simply bypass it */
	  if (strlen (space) < 1)
	    return 0;
	  tmp = strchr (space + 1, ',');
	  if (tmp == NULL)	/* it was the last header */
	    return 0;
	  quote1 = quote_find (space);
	  if ((quote1 != NULL) && (quote1 < tmp))	/* this may be a quoted string! */
	    {
	      quote2 = quote_find (quote1 + 1);
	      if (quote2 == NULL)
		return -1;	/* bad header format... */
	      if (tmp < quote2)	/* the comma is inside the quotes! */
		space = strchr (quote2, ',');
	      else
		space = tmp;
	      if (space == NULL)	/* it was the last header */
		return 0;
	    }
	  else
	    space = tmp;
	  /* continue parsing... */
	}
    }
  return 0;			/* ok */
}
Ejemplo n.º 5
0
void set_msg_id(byte *text, uint leng)
{
    (void) leng;		/* suppress compiler warning */
    token_set( msg_id, text, msg_id->leng );
}
Ejemplo n.º 6
0
token_t parse_new_token(word_t *token)
{
    token_t cls = NONE;
    unsigned char *cp;
    bool done = false;

    /* If saved IPADDR, truncate last octet */
    if ( block_on_subnets && save_class == IPADDR )
    {
	byte *t = xmemrchr(ipsave->u.text, '.', ipsave->leng);
	if (t == NULL)
	    save_class = NONE;
	else
	{
	    ipsave->leng = (uint) (t - ipsave->u.text);
	    token_set( token, ipsave->u.text, ipsave->leng);
	    cls = save_class;
	    done = true;
	}
    }

    while (!done) {
	uint leng;
	byte *text;

	cls = (*lexer->yylex)();

	token->leng = lexer->get_parser_token(&token->u.text);
	Z(token->u.text[token->leng]);	/* for easier debugging - removable */

	leng = token->leng;
	text = token->u.text;

	if (DEBUG_TEXT(2)) {
	    word_puts(token, 0, dbgout);
	    fputc('\n', dbgout);
	}
 
	if (cls == NONE) /* End of message */
	    break;

	switch (cls) {

	case EOH:	/* end of header - bogus if not empty */
	    if (leng > max_token_len)
		continue;

	    if (msg_state->mime_type == MIME_MESSAGE)
		mime_add_child(msg_state);
	    if (leng == 1)
		continue;
	    else {	/* "spc:invalid_end_of_header" */
		token_copy( &yylval, nonblank_line);
		done = true;
	    }
	    break;

	case BOUNDARY:	/* don't return boundary tokens to the user */
	    continue;

	case VERP:	/* Variable Envelope Return Path */
	{
	    byte *st = (byte *)text;
	    byte *in;
	    byte *fst = NULL;
	    byte *lst = NULL;

	    for (in = st; *in != '\0'; in += 1) {
		if (*in == '-') {
		    if (fst == NULL)
			fst = in;
		    lst = in;
		}
	    }

	    if (fst != NULL && lst != NULL && lst - fst  > 3) {
		byte *ot = fst;
		*ot++ = '-';
		*ot++ = '#';
		for (in = lst; *in != '\0'; in += 1, ot += 1)
		    *ot = *in;
		token->leng = leng = (uint) (ot - st);
	    }
	    Z(token->u.text[token->leng]);	/* for easier debugging - removable */
	}
	break;

	case HEADKEY:
	{
	    if (!header_line_markup || *text == '\0')
		continue;
	    else {
		const char *delim = strchr((const char *)text, ':');
		leng = (uint) (delim - (const char *)text);
		if (leng > max_token_len)
		    continue;
		token_set( &yylval, text, leng);
	    }
	}

	/*@fallthrough@*/

	case TOKEN:	/* ignore anything when not reading text MIME types */
	    if (leng < min_token_len)
		continue;

	/*@fallthrough@*/

	case MONEY:	/* 2 character money is OK */
	    if (leng > max_token_len)
		continue;

	    token->u.text = text;
	    token->leng = leng;

	    if (token_prefix == NULL) {
		switch (msg_state->mime_type) {
		case MIME_TEXT:
		case MIME_TEXT_HTML:
		case MIME_TEXT_PLAIN:
		case MIME_MULTIPART:
		    break;
		case MIME_MESSAGE:
		case MIME_APPLICATION:
		case MIME_IMAGE:
		    continue;
		default:
		    continue;
		}
	    }
	    break;

	case MESSAGE_ID:
	    /* special token;  saved for formatted output, but not returned to bogofilter */
	    /** \bug: the parser MUST be aligned with lexer_v3.l! */
	    if (leng < max_token_len)
	    {
		while (!isspace(text[0])) {
		    text += 1;
		    leng -= 1;
		}
		while (isspace(text[0])) {
		    text += 1;
		    leng -= 1;
		}
		token_set( msg_id, text, leng);
	    }
	    continue;

	case QUEUE_ID:
	    /* special token;  saved for formatted output, but not returned to bogofilter */
	    /** \bug: the parser MUST be aligned with lexer_v3.l! */
	    if (*queue_id->u.text == '\0' &&
		leng < max_token_len )
	    {
		while (isspace(text[0])) {
		    text += 1;
		    leng -= 1;
		}
		if (memcmp(text, "id", 2) == 0) {
		    text += 2;
		    leng -= 2;
		}
		while (isspace(text[0])) {
		    text += 1;
		    leng -= 1;
		}
		if (text[0] == '<') {
		    text += 1;
		    leng -= 1;
		}
		if (text[leng-1] == '>') {
		    leng -= 1;
		}
		leng = min(queue_id->leng, leng);
		memcpy( queue_id->u.text, text, leng );
		Z(queue_id->u.text[leng]);
	    }
	    continue;

	case MESSAGE_ADDR:
	{
	    /* trim brackets */
	    text += 1;
	    leng -= 2;
	    Z(text[leng]);	/* for easier debugging - removable */
	    token_set( &yylval, text, leng);
	    /* if top level, no address, not localhost, .... */
	    if (token_prefix == w_recv &&
		msg_state->parent == NULL && 
		*msg_addr->u.text == '\0' &&
		strcmp((char *)text, "127.0.0.1") != 0)
	    {
		/* Not guaranteed to be the originating address of the message. */
		memcpy( msg_addr->u.text, yylval.u.text, min(msg_addr->leng, yylval.leng)+D );
		Z(msg_addr->u.text[yylval.leng]);
	    }
	}

	/*@fallthrough@*/

	case IPADDR:
	    if (block_on_subnets)
	    {
		int q1, q2, q3, q4;
		/*
		 * Trick collected by ESR in real time during John
		 * Graham-Cummings's talk at Paul Graham's spam conference
		 * in January 2003...  Some spammers know that people are
		 * doing recognition on spamhaus IP addresses.  They use
		 * the fact that HTML clients normally interpret IP addresses
		 * by doing a simple accumulate-and-shift algorithm; they
		 * add large random multiples of 256 to the quads to
		 * mask their origin.  Nuke the high bits to unmask the
		 * address.
		 */

		if (sscanf((const char *)text, "%d.%d.%d.%d", &q1, &q2, &q3, &q4) == 4)
		    /* safe because result string guaranteed to be shorter */
		    sprintf((char *)text, "%d.%d.%d.%d",
			    q1 & 0xff, q2 & 0xff, q3 & 0xff, q4 & 0xff);
		leng = strlen((const char *)text);

		token->u.text = text;
		token->leng = leng;

		token_copy( ipsave, token );

		save_class = IPADDR;

		return (cls);
	    }

	    token->u.text = text;
	    token->leng = leng;

	    break;

	case NONE:		/* nothing to do */
	    break;

	case MSG_COUNT_LINE:
	    msg_count_file = true;
	    multi_token_count = 1;
	    header_line_markup = false;
	    token_prefix = NULL;
	    lexer = &msg_count_lexer;
	    if (mbox_mode) {
		/* Allows processing multiple messages, **
		** but only a single file.              */
		reader_more = msgcount_more;
	    }
	    continue;

	case BOGO_LEX_LINE:
	    token_set( &yylval, text, leng);
	    done = true;
	    break;
	}

	if (DEBUG_TEXT(1)) {
	    word_puts(&yylval, 0, dbgout);
	    fputc('\n', dbgout);
	}

	/* eat all long words */
	if (token->leng <= max_token_len)
	    done = true;
    }

   if (!msg_count_file) {
	/* Remove trailing blanks */
	/* From "From ", for example */
	while (token->leng > 1 && token->u.text[token->leng-1] == ' ') {
	    token->leng -= 1;
	    token->u.text[token->leng] = (byte) '\0';
	}

	/* Remove trailing colon */
	if (token->leng > 1 && token->u.text[token->leng-1] == ':') {
	    token->leng -= 1;
	    token->u.text[token->leng] = (byte) '\0';
	}

	if (replace_nonascii_characters) {
	    /* replace nonascii characters by '?'s */
	    for (cp = token->u.text; cp < token->u.text+token->leng; cp += 1)
		*cp = casefold_table[*cp];
	}
    }

    return(cls);
}
Ejemplo n.º 7
0
static inline void token_copy( word_t *dst, word_t *src )
{
    token_set(dst, src->u.text, src->leng);
}