From: Sam Hartman Date: Mon, 11 Sep 2023 14:00:42 -0600 Subject: update-motd Provide a more dynamic MOTD, based on the short-lived update-motd project. Authors: Dustin Kirkland Last-Update: 2019-02-12 Forwarded: no Bug-Ubuntu: https://bugs.launchpad.net/bugs/399071 --- modules/pam_motd/pam_motd.8.xml | 11 +++++++++++ modules/pam_motd/pam_motd.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/modules/pam_motd/pam_motd.8.xml b/modules/pam_motd/pam_motd.8.xml index 2fc5310..8369779 100644 --- a/modules/pam_motd/pam_motd.8.xml +++ b/modules/pam_motd/pam_motd.8.xml @@ -112,6 +112,17 @@ + + + + + + + Don't run the scripts in /etc/update-motd.d + to refresh the motd file. + + + When no options are given, the default behavior applies for both diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c index 89b2595..e6ce874 100644 --- a/modules/pam_motd/pam_motd.c +++ b/modules/pam_motd/pam_motd.c @@ -387,6 +387,7 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) { int retval = PAM_IGNORE; + int do_update = 1; const char *motd_path = NULL; char *motd_path_copy = NULL; size_t num_motd_paths = 0; @@ -396,6 +397,7 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, size_t num_motd_dir_paths = 0; char **motd_dir_path_split = NULL; int report_missing; + struct stat st; if (flags & PAM_SILENT) { return retval; @@ -425,6 +427,9 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, "motd_dir= specification missing argument - ignored"); } } + else if (!strcmp(*argv,"noupdate")) { + do_update = 0; + } else pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv); } @@ -437,6 +442,19 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, report_missing = 1; } + /* Run the update-motd dynamic motd scripts, outputting to /run/motd.dynamic. + This will be displayed only when calling pam_motd with + motd=/run/motd.dynamic; current /etc/pam.d/login and /etc/pam.d/sshd + display both this file and /etc/motd. */ + if (do_update && (stat("/etc/update-motd.d", &st) == 0) + && S_ISDIR(st.st_mode)) + { + mode_t old_mask = umask(0022); + if (!system("/usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new")) + rename("/run/motd.dynamic.new", "/run/motd.dynamic"); + umask(old_mask); + } + if (motd_path != NULL) { motd_path_copy = strdup(motd_path); }