Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add ICAP Content-Type and Filename from TODO List #4595

Merged
merged 3 commits into from Sep 13, 2023

Conversation

lbahtarliev
Copy link
Contributor

It turns out, that external_services plugin is not submitting maybe_part parameter at all when calling icap services check method. In order to avoid expensive operations in icap.lua scanner, I am just getting the filename and content-type/subtype in the external_services plugin and submitting that as maybe_part parameter. Of course, a new parameter can be introduced should maybe_part is used, but I wasn't able to find any usage of it at least related to the ICAP functionality.

local in_fname = p:get_filename()
local in_type, in_stype = p:get_detected_type()
local part_info = {in_fname,in_type,in_stype}
cfg.check(task, content, p:get_digest(), rule, part_info)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original idea was just to pass mime_part object (hence p) and not to split it into some array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right. How I couldn't think of that... I found that maybe_part is always nil, but it didn't occur to me to just pass p object instead of doing all these variable assignments here.
However, will that mean that the extraction of content type and subtype, as well as filename should go in icap.lua in lua_scanners?

local in_type = "application"
local in_stype = "octet-stream"
local part_info = {in_fname,in_type,in_stype}
cfg.check(task, task:get_content(), task:get_digest(), rule, part_info)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have part, then we must just pass nil here and reconstruct the necessary information afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if it's nil we can stick with the already available req_fake_url? Otherwise, I am not sure how I can reconstruct the missing information in the lua_scanner itself... May you can point me in the right direction?

Copy link
Contributor Author

@lbahtarliev lbahtarliev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another attempt.

@@ -240,10 +240,19 @@ local function icap_check(task, content, digest, rule, maybe_part)

local function get_req_headers()

local in_client_ip = task:get_from_ip()
lua_util.debugm(rule.name, task, 'URL: http://%s/%s | Content-Type: %s/%s',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will crash the plugin when maybe_part is nil. Lua does not do lazy evaluations. Also, that will call two C functions twice (get_filename and get_detected_type).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't notice I am missing a check before the debug message. Is it OK to just remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed the debug message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, thank you!

… changes. Remove unnecessary debug message.
@vstakhov vstakhov merged commit 054e08b into rspamd:master Sep 13, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants