CFE-4648: cf-execd SMTP port configurable#6064
CFE-4648: cf-execd SMTP port configurable#6064basvandervlies wants to merge 1 commit intocfengine:masterfrom
Conversation
craigcomstock
left a comment
There was a problem hiding this comment.
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.
|
I have adjusted the code to try fitrst |
|
@basvandervlies this looks great! A few unit tests are failing though: I tried it out myself and the failure looks a bit mysterious currently. |
|
Yes It compiles and runs fines, but maybe I have overseen something. It look for me unrelated |
cf-execd/exec-config.c
Outdated
| } | ||
| else | ||
| { | ||
| exec_config->mail_port = (unsigned int) server->s_port; |
There was a problem hiding this comment.
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:
| exec_config->mail_port = (unsigned int) server->s_port; | |
| exec_config->mail_port = htons( (unsigned int) server->s_port ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ;-)
|
@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: |
Changelog: Title Ticket: CFE-4648
CFE-4648: cf-execd SMTP port configurable