Skip to content

CFE-4648: cf-execd SMTP port configurable#6064

Open
basvandervlies wants to merge 1 commit intocfengine:masterfrom
basvandervlies:smtpport
Open

CFE-4648: cf-execd SMTP port configurable#6064
basvandervlies wants to merge 1 commit intocfengine:masterfrom
basvandervlies:smtpport

Conversation

@basvandervlies
Copy link
Copy Markdown
Contributor

CFE-4648: cf-execd SMTP port configurable

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

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

seems reasonable, I do wonder if you shouldn't use the getservbyname() after all just to hedge bets that it couldn't possible be changed in the services database? It does seem prudent to prefer using the "API" as it were instead of hard-coding and assuming.

Squash the commits then good to go I'd say.

@basvandervlies
Copy link
Copy Markdown
Contributor Author

basvandervlies commented Apr 1, 2026

I have adjusted the code to try fitrst getservbyname is this ok? If yes then I will squash the commits

@craigcomstock
Copy link
Copy Markdown
Contributor

@basvandervlies this looks great! A few unit tests are failing though:

test_exec_config_empty: Starting test
test_exec_config_empty: Test failed.
test_exec_config_full: Starting test
test_exec_config_full: Test failed.
test_exec_config_copy: Starting test
test_exec_config_copy: Test failed.
FAIL: exec-config-test

I tried it out myself and the failure looks a bit mysterious currently.

@basvandervlies
Copy link
Copy Markdown
Contributor Author

Yes It compiles and runs fines, but maybe I have overseen something. It look for me unrelated

}
else
{
exec_config->mail_port = (unsigned int) server->s_port;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When I run this I get a port of 6400. Maybe not quite what you expect?

From the man page:

s_port The port number for the service given in network byte order.

So you need to translate that to an integer:

Suggested change
exec_config->mail_port = (unsigned int) server->s_port;
exec_config->mail_port = htons( (unsigned int) server->s_port );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

but it was the orginal code:

-    struct servent *server = getservbyname("smtp", "tcp");
-    if (!server)
-    {
-        Log(LOG_LEVEL_ERR, "Mail report: unable to lookup smtp service. (getservbyname: %s)", GetErrorStr());
-        return -1;
-    }
-
     struct sockaddr_in raddr;
     memset(&raddr, 0, sizeof(raddr));
 
-    raddr.sin_port = (unsigned int) server->s_port;

If I leave out the asserts in the unit tests everything is good:

//assert_int_equal(25, config->mail_port); 

I will try with the htons fucntion inplace

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is what I thought we have to convert the unsinged in to:

    server_addr.sin_port = htons(25);   // <-- key line

Need to add some conversion functions ;-)

@craigcomstock
Copy link
Copy Markdown
Contributor

@basvandervlies looks great. Please squash the commits and while you are doing that, maybe nudge the one commit left to conform to our template https://github.com/cfengine/core/blob/master/CONTRIBUTING.md#commit-message-example

something like:

Added a new smtpport body executor control attribute to specify on which port to send mail

Changelog: Title
Ticket: ENT-4648

Changelog: Title
Ticket: CFE-4648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants