fp, shmem_size, offset, fd);
rspamd_mempool_add_destructor(task->task_pool, rspamd_task_unmapper, m);
-
- return TRUE;
}
+ else {
+ /* Try file */
+ tok = rspamd_task_get_request_header(task, "file");
- tok = rspamd_task_get_request_header(task, "file");
+ if (tok == NULL) {
+ tok = rspamd_task_get_request_header(task, "path");
+ }
- if (tok == NULL) {
- tok = rspamd_task_get_request_header(task, "path");
- }
+ if (tok) {
+ debug_task("want to scan file %T", tok);
- if (tok) {
- debug_task("want to scan file %T", tok);
+ r = rspamd_strlcpy(filepath, tok->begin,
+ MIN(sizeof(filepath), tok->len + 1));
- r = rspamd_strlcpy(filepath, tok->begin,
- MIN(sizeof(filepath), tok->len + 1));
-
- rspamd_url_decode(filepath, filepath, r + 1);
- flen = strlen(filepath);
+ rspamd_url_decode(filepath, filepath, r + 1);
+ flen = strlen(filepath);
- if (filepath[0] == '"' && flen > 2) {
- /* We need to unquote filepath */
- fp = &filepath[1];
- fp[flen - 2] = '\0';
- }
- else {
- fp = &filepath[0];
- }
-
- if (stat(fp, &st) == -1) {
- g_set_error(&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
- "Invalid file (%s): %s", fp, strerror(errno));
- return FALSE;
- }
-
- if (G_UNLIKELY(st.st_size == 0)) {
- /* Empty file */
- task->flags |= RSPAMD_TASK_FLAG_EMPTY;
- task->msg.begin = rspamd_mempool_strdup(task->task_pool, "");
- task->msg.len = 0;
- }
- else {
- fd = open(fp, O_RDONLY);
+ if (filepath[0] == '"' && flen > 2) {
+ /* We need to unquote filepath */
+ fp = &filepath[1];
+ fp[flen - 2] = '\0';
+ }
+ else {
+ fp = &filepath[0];
+ }
- if (fd == -1) {
- g_set_error(&task->err, rspamd_task_quark(),
- RSPAMD_PROTOCOL_ERROR,
- "Cannot open file (%s): %s", fp, strerror(errno));
+ if (stat(fp, &st) == -1) {
+ g_set_error(&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
+ "Invalid file (%s): %s", fp, strerror(errno));
return FALSE;
}
- map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (G_UNLIKELY(st.st_size == 0)) {
+ /* Empty file */
+ task->flags |= RSPAMD_TASK_FLAG_EMPTY;
+ task->msg.begin = rspamd_mempool_strdup(task->task_pool, "");
+ task->msg.len = 0;
+ }
+ else {
+ fd = open(fp, O_RDONLY);
+ if (fd == -1) {
+ g_set_error(&task->err, rspamd_task_quark(),
+ RSPAMD_PROTOCOL_ERROR,
+ "Cannot open file (%s): %s", fp, strerror(errno));
+ return FALSE;
+ }
- if (map == MAP_FAILED) {
- close(fd);
- g_set_error(&task->err, rspamd_task_quark(),
- RSPAMD_PROTOCOL_ERROR,
- "Cannot mmap file (%s): %s", fp, strerror(errno));
- return FALSE;
- }
+ map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
- task->msg.begin = map;
- task->msg.len = st.st_size;
- m = rspamd_mempool_alloc(task->task_pool, sizeof(*m));
- m->begin = map;
- m->len = st.st_size;
- m->fd = fd;
- rspamd_mempool_add_destructor(task->task_pool, rspamd_task_unmapper, m);
- }
+ if (map == MAP_FAILED) {
+ close(fd);
+ g_set_error(&task->err, rspamd_task_quark(),
+ RSPAMD_PROTOCOL_ERROR,
+ "Cannot mmap file (%s): %s", fp, strerror(errno));
+ return FALSE;
+ }
- task->msg.fpath = rspamd_mempool_strdup(task->task_pool, fp);
- task->flags |= RSPAMD_TASK_FLAG_FILE;
+ task->msg.begin = map;
+ task->msg.len = st.st_size;
+ m = rspamd_mempool_alloc(task->task_pool, sizeof(*m));
+ m->begin = map;
+ m->len = st.st_size;
+ m->fd = fd;
- msg_info_task("loaded message from file %s", fp);
+ rspamd_mempool_add_destructor(task->task_pool, rspamd_task_unmapper, m);
+ }
- return TRUE;
+ task->msg.fpath = rspamd_mempool_strdup(task->task_pool, fp);
+ task->flags |= RSPAMD_TASK_FLAG_FILE;
+
+ msg_info_task("loaded message from file %s", fp);
+ }
+ else {
+ /* Plain data */
+ task->msg.begin = start;
+ task->msg.len = len;
+ }
}
- /* Plain data */
+
debug_task("got input of length %z", task->msg.len);
/* Check compression */
zstream = task->cfg->libs_ctx->in_zstream;
zin.pos = 0;
- zin.src = start;
- zin.size = len;
+ zin.src = task->msg.begin;
+ zin.size = task->msg.len;
- if ((outlen = ZSTD_getDecompressedSize(start, len)) == 0) {
+ if ((outlen = ZSTD_getDecompressedSize(task->msg.begin, task->msg.len)) == 0) {
outlen = ZSTD_DStreamOutSize();
}
return FALSE;
}
}
- else {
- task->msg.begin = start;
- task->msg.len = len;
- }
if (task->msg.len == 0) {
task->flags |= RSPAMD_TASK_FLAG_EMPTY;