| 1 |
From: Sam Hartman <[email protected]> |
| 2 |
Date: Mon, 11 Sep 2023 14:00:42 -0600 |
| 3 |
Subject: update-motd |
| 4 |
|
| 5 |
Provide a more dynamic MOTD, based on the short-lived update-motd project. |
| 6 |
|
| 7 |
Authors: Dustin Kirkland <[email protected]> |
| 8 |
|
| 9 |
Last-Update: 2019-02-12 |
| 10 |
Forwarded: no |
| 11 |
Bug-Ubuntu: https://bugs.launchpad.net/bugs/399071 |
| 12 |
--- |
| 13 |
modules/pam_motd/pam_motd.8.xml | 11 +++++++++++ |
| 14 |
modules/pam_motd/pam_motd.c | 18 ++++++++++++++++++ |
| 15 |
2 files changed, 29 insertions(+) |
| 16 |
|
| 17 |
diff --git a/modules/pam_motd/pam_motd.8.xml b/modules/pam_motd/pam_motd.8.xml |
| 18 |
index 2fc5310..8369779 100644 |
| 19 |
--- a/modules/pam_motd/pam_motd.8.xml |
| 20 |
+++ b/modules/pam_motd/pam_motd.8.xml |
| 21 |
@@ -112,6 +112,17 @@ |
| 22 |
</para> |
| 23 |
</listitem> |
| 24 |
</varlistentry> |
| 25 |
+ <varlistentry> |
| 26 |
+ <term> |
| 27 |
+ <option>noupdate</option> |
| 28 |
+ </term> |
| 29 |
+ <listitem> |
| 30 |
+ <para> |
| 31 |
+ Don't run the scripts in <filename>/etc/update-motd.d</filename> |
| 32 |
+ to refresh the motd file. |
| 33 |
+ </para> |
| 34 |
+ </listitem> |
| 35 |
+ </varlistentry> |
| 36 |
</variablelist> |
| 37 |
<para> |
| 38 |
When no options are given, the default behavior applies for both |
| 39 |
diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c |
| 40 |
index 89b2595..e6ce874 100644 |
| 41 |
--- a/modules/pam_motd/pam_motd.c |
| 42 |
+++ b/modules/pam_motd/pam_motd.c |
| 43 |
@@ -387,6 +387,7 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, |
| 44 |
int argc, const char **argv) |
| 45 |
{ |
| 46 |
int retval = PAM_IGNORE; |
| 47 |
+ int do_update = 1; |
| 48 |
const char *motd_path = NULL; |
| 49 |
char *motd_path_copy = NULL; |
| 50 |
size_t num_motd_paths = 0; |
| 51 |
@@ -396,6 +397,7 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, |
| 52 |
size_t num_motd_dir_paths = 0; |
| 53 |
char **motd_dir_path_split = NULL; |
| 54 |
int report_missing; |
| 55 |
+ struct stat st; |
| 56 |
|
| 57 |
if (flags & PAM_SILENT) { |
| 58 |
return retval; |
| 59 |
@@ -425,6 +427,9 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, |
| 60 |
"motd_dir= specification missing argument - ignored"); |
| 61 |
} |
| 62 |
} |
| 63 |
+ else if (!strcmp(*argv,"noupdate")) { |
| 64 |
+ do_update = 0; |
| 65 |
+ } |
| 66 |
else |
| 67 |
pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv); |
| 68 |
} |
| 69 |
@@ -437,6 +442,19 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, |
| 70 |
report_missing = 1; |
| 71 |
} |
| 72 |
|
| 73 |
+ /* Run the update-motd dynamic motd scripts, outputting to /run/motd.dynamic. |
| 74 |
+ This will be displayed only when calling pam_motd with |
| 75 |
+ motd=/run/motd.dynamic; current /etc/pam.d/login and /etc/pam.d/sshd |
| 76 |
+ display both this file and /etc/motd. */ |
| 77 |
+ if (do_update && (stat("/etc/update-motd.d", &st) == 0) |
| 78 |
+ && S_ISDIR(st.st_mode)) |
| 79 |
+ { |
| 80 |
+ mode_t old_mask = umask(0022); |
| 81 |
+ 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")) |
| 82 |
+ rename("/run/motd.dynamic.new", "/run/motd.dynamic"); |
| 83 |
+ umask(old_mask); |
| 84 |
+ } |
| 85 |
+ |
| 86 |
if (motd_path != NULL) { |
| 87 |
motd_path_copy = strdup(motd_path); |
| 88 |
} |