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

Add -f arg to sendmail call in email alert #676

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Update Postgres to SQLite migration. [#581](https://github.com/greenbone/gvmd/pull/581) [#601](https://github.com/greenbone/gvmd/pull/601) [#604](https://github.com/greenbone/gvmd/pull/604) [#605](https://github.com/greenbone/gvmd/pull/605)
- Update result diff generation at delta reports [#650](https://github.com/greenbone/gvmd/pull/650)
- Check and create default permissions individually [#671](https://github.com/greenbone/gvmd/pull/671)
- Add -f arg to sendmail call in email alert [#676](https://github.com/greenbone/gvmd/pull/676)

### Fixed
- Fix iCalendar recurrence and timezone handling [#654](https://github.com/greenbone/gvmd/pull/654)
Expand Down
31 changes: 20 additions & 11 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -9351,11 +9351,12 @@ email (const char *to_address, const char *from_address, const char *subject,
const char *attachment_name, const char *attachment_extension,
credential_t recipient_credential)
{
int ret, content_fd, to_fd;
int ret, content_fd, args_fd;
gchar *command;
GError *error = NULL;
char content_file_name[] = "/tmp/gvmd-content-XXXXXX";
char to_file_name[] = "/tmp/gvmd-to-XXXXXX";
char args_file_name[] = "/tmp/gvmd-args-XXXXXX";
gchar *sendmail_args;
FILE *content_file;

content_fd = mkstemp (content_file_name);
Expand Down Expand Up @@ -9497,28 +9498,36 @@ email (const char *to_address, const char *from_address, const char *subject,
}
}

to_fd = mkstemp (to_file_name);
if (to_fd == -1)
args_fd = mkstemp (args_file_name);
if (args_fd == -1)
{
g_warning ("%s: mkstemp: %s", __FUNCTION__, strerror (errno));
fclose (content_file);
return -1;
}

g_file_set_contents (to_file_name, to_address, strlen (to_address), &error);
sendmail_args = g_strdup_printf ("-f %s %s",
from_address,
to_address);
g_file_set_contents (args_file_name,
sendmail_args,
strlen (sendmail_args),
&error);
g_free (sendmail_args);

if (error)
{
g_warning ("%s", error->message);
g_error_free (error);
fclose (content_file);
close (to_fd);
close (args_fd);
return -1;
}

command = g_strdup_printf ("xargs -a %s -I XXX"
" /usr/sbin/sendmail XXX < %s"
" > /dev/null 2>&1",
to_file_name,
args_file_name,
content_file_name);

g_debug (" command: %s", command);
Expand All @@ -9533,16 +9542,16 @@ email (const char *to_address, const char *from_address, const char *subject,
command);
g_free (command);
fclose (content_file);
close (to_fd);
close (args_fd);
unlink (content_file_name);
unlink (to_file_name);
unlink (args_file_name);
return -1;
}
g_free (command);
fclose (content_file);
close (to_fd);
close (args_fd);
unlink (content_file_name);
unlink (to_file_name);
unlink (args_file_name);
return 0;
}

Expand Down