Skip to content

Instantly share code, notes, and snippets.

@saidelike
Created July 6, 2021 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saidelike/95b2bb96eae8803c42a62223891e885a to your computer and use it in GitHub Desktop.
Save saidelike/95b2bb96eae8803c42a62223891e885a to your computer and use it in GitHub Desktop.
//sudo_1.8.23-9.el7/plugins/sudoers/logging.c
/*
* Send a message to MAILTO user
*/
static bool
send_mail(const char *fmt, ...)
{
...
/* If mailer is disabled just return. */
[0] if (!def_mailerpath || !def_mailto)
debug_return_bool(true);
[1] /* Make sure the mailer exists and is a regular file. */
if (stat(def_mailerpath, &sb) != 0 || !S_ISREG(sb.st_mode))
debug_return_bool(false);
[2] ...
switch (pid = sudo_debug_fork()) {
case -1:
/* Error. */
...
case 0:
{
char *last, *argv[MAX_MAILFLAGS + 1];
[3] char *mflags, *mpath = def_mailerpath;
int i;
...
if ((argv[0] = strrchr(mpath, '/')))
argv[0]++;
else
argv[0] = mpath;
i = 1;
...
argv[i] = NULL;
/*
* Depending on the config, either run the mailer as root
* (so user cannot kill it) or as the user (for the paranoid).
*/
#ifndef NO_ROOT_MAILER
[4] (void) set_perms(PERM_ROOT);
execve(mpath, argv, root_envp);
#else
[5] (void) set_perms(PERM_FULL_USER);
execv(mpath, argv);
#endif /* NO_ROOT_MAILER */
...
_exit(127);
}
break;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment