From 681602d2f28836aea37040270b127cd38490d95e Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 08:02:23 +0000 Subject: Apply patch autofs-5.1.5-optionally-log-mount-requestor-process-info.patch patch_name: autofs-5.1.5-optionally-log-mount-requestor-process-info.patch present_in_specfile: true --- diff --git a/CHANGELOG b/CHANGELOG index 7fb15b6..362e98d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -48,6 +48,7 @@ xx/xx/2018 autofs-5.1.5 - add NULL check for get_addr_string() return. - use malloc(3) in spawn.c. - add mount_verbose configuration option. +- optionally log mount requestor process info. 19/12/2017 autofs-5.1.4 - fix spec file url. diff --git a/daemon/direct.c b/daemon/direct.c index e3ce816..c48e59d 100644 --- a/daemon/direct.c +++ b/daemon/direct.c @@ -1242,6 +1242,12 @@ static void *do_mount_direct(void *arg) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state); + if (defaults_get_mount_verbose()) { + pid_t ppid = log_pidinfo(ap, mt.pid, "requestor"); + if (ppid > 0) + log_pidinfo(ap, ppid, "parent"); + } + status = fstat(mt.ioctlfd, &st); if (status == -1) { error(ap->logopt, diff --git a/daemon/indirect.c b/daemon/indirect.c index 4f67f70..b5f6cf0 100644 --- a/daemon/indirect.c +++ b/daemon/indirect.c @@ -758,6 +758,12 @@ static void *do_mount_indirect(void *arg) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state); + if (defaults_get_mount_verbose()) { + pid_t ppid = log_pidinfo(ap, mt.pid, "requestor"); + if (ppid > 0) + log_pidinfo(ap, ppid, "parent"); + } + len = ncat_path(buf, sizeof(buf), ap->path, mt.name, mt.len); if (!len) { crit(ap->logopt, "path to be mounted is to long"); diff --git a/include/log.h b/include/log.h index c9b17b3..69eed96 100644 --- a/include/log.h +++ b/include/log.h @@ -46,6 +46,8 @@ extern void log_crit(unsigned, const char* msg, ...); extern void log_debug(unsigned int, const char* msg, ...); extern void logmsg(const char* msg, ...); +extern pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label); + #define debug(opt, msg, args...) \ do { log_debug(opt, "%s: " msg, __FUNCTION__, ##args); } while (0) diff --git a/lib/log.c b/lib/log.c index ca771d7..0cb47d7 100644 --- a/lib/log.c +++ b/lib/log.c @@ -325,3 +325,42 @@ void log_to_stderr(void) return; } + +pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label) { + char buf[PATH_MAX + 1] = ""; + FILE *statfile; + + pid_t tgid, ppid; + int uid, euid, gid, egid; + char comm[64] = ""; + + sprintf(buf, "/proc/%d/status", pid); + statfile = fopen(buf, "r"); + if (statfile == NULL) { + info(ap->logopt, "pidinfo %s: failed to open %s", label, buf); + return -1; + } + + while (fgets(buf, sizeof(buf), statfile) != NULL) { + if (strncmp(buf, "Name:", 5) == 0) { + sscanf(buf, "Name:\t%s", (char *) &comm); + } else if (strncmp(buf, "Tgid:", 5) == 0) { + sscanf(buf, "Tgid:\t%d", (int *) &tgid); + } else if (strncmp(buf, "PPid:", 5) == 0) { + sscanf(buf, "PPid:\t%d", (int *) &ppid); + } else if (strncmp(buf, "Uid:", 4) == 0) { + sscanf(buf, + "Uid:\t%d\t%d", (int *) &uid, (int *) &euid); + } else if (strncmp(buf, "Gid:", 4) == 0) { + sscanf(buf, + "Gid:\t%d\t%d", (int *) &gid, (int *) &egid); + } + } + fclose(statfile); + + info(ap->logopt, + "pidinfo %s: pid:%d comm:%s tgid:%d uid:%d euid:%d gid:%d egid:%d", + label, pid, comm, tgid, uid, euid, gid, egid); + + return ppid; +} diff --git a/man/autofs.conf.5.in b/man/autofs.conf.5.in index 31136e2..95ff7dd 100644 --- a/man/autofs.conf.5.in +++ b/man/autofs.conf.5.in @@ -43,7 +43,8 @@ setting. .TP .B mount_verbose .br -Use the verbose flag when spawning mount(8) (program default "no"). +Use the verbose flag when spawning mount(8), and log some process info +about the requestor and its parent (program default "no"). .TP .B mount_wait .br diff --git a/redhat/autofs.conf.default.in b/redhat/autofs.conf.default.in index 7949f51..4b89a5f 100644 --- a/redhat/autofs.conf.default.in +++ b/redhat/autofs.conf.default.in @@ -26,7 +26,9 @@ timeout = 300 # #negative_timeout = 60 # -# mount_verbose - use the -v flag when calling mount(8). +# mount_verbose - use the -v flag when calling mount(8) and log some +# process information about the requestor and its +# parent. # #mount_verbose = no # diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in index d33625f..2f15511 100644 --- a/samples/autofs.conf.default.in +++ b/samples/autofs.conf.default.in @@ -26,7 +26,9 @@ timeout = 300 # #negative_timeout = 60 # -# mount_verbose - use the -v flag when calling mount(8). +# mount_verbose - use the -v flag when calling mount(8) and log some +# process information about the requestor and its +# parent. # #mount_verbose = no #