aboutsummaryrefslogtreecommitdiff
path: root/debian/patches/update-motd
blob: fc9c9d8d5a91018fcc9bc6ee7230efbf865fb0ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
From: Sam Hartman <hartmans@debian.org>
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 <kirkland@canonical.com>

Last-Update: 2019-02-12
Forwarded: no
Bug-Ubuntu: https://bugs.launchpad.net/bugs/399071
---
 modules/pam_motd/README         |  4 ++++
 modules/pam_motd/pam_motd.8     |  7 +++++++
 modules/pam_motd/pam_motd.8.xml | 11 +++++++++++
 modules/pam_motd/pam_motd.c     | 18 ++++++++++++++++++
 4 files changed, 40 insertions(+)

diff --git a/modules/pam_motd/README b/modules/pam_motd/README
index 01bc64e..375ec80 100644
--- a/modules/pam_motd/README
+++ b/modules/pam_motd/README
@@ -52,6 +52,10 @@ motd_dir=/path/dirname.d
     colon-separated list. By default this option is set to /etc/motd.d:/run/
     motd.d:/usr/lib/motd.d.
 
+noupdate
+
+    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 options.
 Specifying either option (or both) will disable the default behavior for both
 options.
diff --git a/modules/pam_motd/pam_motd.8 b/modules/pam_motd/pam_motd.8
index 3f65bb5..6a6ab4e 100644
--- a/modules/pam_motd/pam_motd.8
+++ b/modules/pam_motd/pam_motd.8
@@ -109,6 +109,13 @@ directory is scanned and each file contained inside of it is displayed\&. Multip
 /etc/motd\&.d:/run/motd\&.d:/usr/lib/motd\&.d\&.
 .RE
 .PP
+\fBnoupdate\fR
+.RS 4
+Don\*(Aqt run the scripts in
+/etc/update\-motd\&.d
+to refresh the motd file\&.
+.RE
+.PP
 When no options are given, the default behavior applies for both options\&. Specifying either option (or both) will disable the default behavior for both options\&.
 .SH "MODULE TYPES PROVIDED"
 .PP
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 @@
           </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term>
+          <option>noupdate</option>
+        </term>
+        <listitem>
+          <para>
+            Don't run the scripts in <filename>/etc/update-motd.d</filename>
+            to refresh the motd file.
+          </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
     <para>
       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 5ca486e..8472dd6 100644
--- a/modules/pam_motd/pam_motd.c
+++ b/modules/pam_motd/pam_motd.c
@@ -383,6 +383,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;
     unsigned int num_motd_paths = 0;
@@ -392,6 +393,7 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags,
     unsigned int num_motd_dir_paths = 0;
     char **motd_dir_path_split = NULL;
     int report_missing;
+    struct stat st;
 
     if (flags & PAM_SILENT) {
 	return retval;
@@ -421,6 +423,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);
     }
@@ -433,6 +438,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);
     }