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

anacron: read SENDMAIL variable from anacrontab #135

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

corvus1
Copy link

@corvus1 corvus1 commented Jan 11, 2023

Use alternative mailer command.

As briefly discussed in #133 the change looks for SENDMAIL environment variable, and if it is set, uses it as an alternative mailer. It strips the command line arguments from the execl() call, and lets the mailer sort out the standard input. Perhaps it's not ideal, but I'd like to hear some comments.

For my personal use-case, logger very easily takes the standard input and sends it into syslog, eliminating any need for local mail setup. Which was my goal to begin with. :-) Full disclosure.

Another possible issue is that you can't specify command line parameters for the alternative mailer, it has to be just a path to the binary.

Use alternative mailer command
But has all sorts of issues. execl() is acting weird when "" is passed as
parameters. And I think I reached the extent of my C programming capabilities.
For some bizarre reason I can't even if (string == NULL) anymore.
Please help!
@corvus1
Copy link
Author

corvus1 commented Jan 13, 2023

See the latest commit message. This thing is taking a toll on me.
I think I reached the limit of my C programming capability.
I managed to come up with a clever regex to split the command line into the path to binary and arguments, and it even works. However, execl() is acting weird, when passed "" as arguments. And for some reason, if the command line is longer than /usr/bin/logger -t anacronmai by one character, it seems like it overlaps with something in memory, which I imagine is a really bad condition to have. And then, for some bizarre reason I can't even compare mailer_args to NULL.

It's getting bad. Like really bad. I'd greatly appreciate if somebody, who knows C at least a little bit, could take a look at this mess I am about to make.

@corvus1 corvus1 marked this pull request as draft January 14, 2023 03:32
@corvus1
Copy link
Author

corvus1 commented Jan 14, 2023

This isn't just ugly, this is desperate. Please send help. :'-(

complain("mailer_full - `%s`", mailer_full);

strcat(mailer_full," ");
r = match_rx("(^[^ ]*) (.*)", mailer_full, 2, &mailer, &mailer_args);
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this is more complicated as for executing the mailer via execl the arguments would have to be split. Or perhaps better would be to just allow a few mailer arguments in separate environment variables. SENDMAILARG1 SENDMAILARG2 SENDMAILARG3....

Copy link
Author

@corvus1 corvus1 Jan 20, 2023

Choose a reason for hiding this comment

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

Unfortunately this is more complicated as for executing the mailer via execl the arguments would have to be split. Or perhaps better would be to just allow a few mailer arguments in separate environment variables. SENDMAILARG1 SENDMAILARG2 SENDMAILARG3....

Is that... even acceptable to shift the task of separating arguments to the user? I mean... that's kinda rude even for me. Is that okay? I mean... it turns out, it's incredibly hard to separate arguments in C.

Copy link
Member

Choose a reason for hiding this comment

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

It is a problem to properly separate the arguments in C because you'd basically have to re-implement the shell argument separator parser to make it really useful. I.e. you'd have to support at least ", ' as quotes and then you also need to somehow support escaping these quote characters, etc.

Copy link
Author

@corvus1 corvus1 Jan 20, 2023

Choose a reason for hiding this comment

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

It is a problem to properly separate the arguments in C because you'd basically have to re-implement the shell argument separator parser to make it really useful. I.e. you'd have to support at least ", ' as quotes and then you also need to somehow support escaping these quote characters, etc.

I thought I'd just go for something simple, rudimentary even. Look for " -" and split on that. Maybe even with a regex in a loop. There is something going on there, though. If SENDMAIL variable is longer than "/usr/bin/logger -t anacronmai" by a single character, everything breaks and I get some other string there. As if something overlapped in memory.

mailer_full = getenv("SENDMAIL");

if (mailer_full == NULL) {
/* Here, I basically mirrored the way /usr/sbin/sendmail is called
Copy link
Member

Choose a reason for hiding this comment

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

Here I wouldn't duplicate the execl call but instead assign SENDMAIL to mailer_full if it is NULL.

Copy link
Author

Choose a reason for hiding this comment

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

Here I wouldn't duplicate the execl call but instead assign SENDMAIL to mailer_full if it is NULL.

I don't know how to do it, without making it into a special case. We need to pass these arguments to sendmail.

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.

2 participants