Ejemplo n.º 1
0
static gboolean
rspamd_archive_cheat_detect (struct rspamd_mime_part *part, const gchar *str,
		const guchar *magic_start, gsize magic_len)
{
	struct rspamd_content_type *ct;
	const gchar *p;
	rspamd_ftok_t srch, *fname;

	ct = part->ct;
	RSPAMD_FTOK_ASSIGN (&srch, "application");

	if (ct && ct->type.len && ct->subtype.len > 0 && rspamd_ftok_cmp (&ct->type,
			&srch) == 0) {
		if (rspamd_substring_search_caseless (ct->subtype.begin, ct->subtype.len,
				str, strlen (str)) != -1) {
			return TRUE;
		}
	}

	if (part->cd) {
		fname = &part->cd->filename;

		if (fname && fname->len > strlen (str)) {
			p = fname->begin + fname->len - strlen (str);

			if (rspamd_lc_cmp (p, str, strlen (str)) == 0) {
				if (*(p - 1) == '.') {
					return TRUE;
				}
			}
		}

		if (magic_start != NULL) {
			if (part->parsed_data.len > magic_len && memcmp (part->parsed_data.begin,
					magic_start, magic_len) == 0) {
				return TRUE;
			}
		}
	}

	return FALSE;
}
Ejemplo n.º 2
0
static gboolean
rspamd_archive_cheat_detect (struct rspamd_mime_part *part, const gchar *str,
		const guchar *magic_start, gsize magic_len)
{
	GMimeContentType *ct;
	const gchar *fname, *p;

	ct = part->type;

	if (ct && ct->type && ct->subtype && strcmp (ct->type,
			"application") == 0) {
		if (rspamd_substring_search_caseless (ct->subtype, strlen (ct->subtype),
				str, strlen (str)) != -1) {
			return TRUE;
		}
	}

	fname = part->filename;

	if (fname && strlen (fname) > strlen (str)) {
		p = fname + strlen (fname) - strlen (str);

		if (rspamd_lc_cmp (p, str, strlen (str)) == 0) {
			if (*(p - 1) == '.') {
				return TRUE;
			}
		}
	}

	if (magic_start != NULL) {
		if (part->content->len > magic_len && memcmp (part->content->data,
				magic_start, magic_len) == 0) {
			return TRUE;
		}
	}

	return FALSE;
}