summaryrefslogtreecommitdiff
path: root/debian/patches-applied/update-motd
blob: a89655df6dc57d1ddb000543ba3f3aff7a6bc3b9 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Patch for Ubuntu bug #399071

Provide a more dynamic MOTD, based on the short-lived update-motd project.

Authors: Dustin Kirkland <kirkland@canonical.com>

Upstream status: not yet submitted

Index: pam.debian/modules/pam_motd/pam_motd.c
===================================================================
--- pam.debian.orig/modules/pam_motd/pam_motd.c
+++ pam.debian/modules/pam_motd/pam_motd.c
@@ -48,14 +48,39 @@
 
 static char default_motd[] = DEFAULT_MOTD;
 
+static void display_file(pam_handle_t *pamh, const char *motd_path)
+{
+    int fd;
+    char *mtmp = NULL;
+    while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
+	struct stat st;
+	/* fill in message buffer with contents of motd */
+	if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
+	    break;
+	if (!(mtmp = malloc(st.st_size+1)))
+	    break;
+	if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
+	    break;
+	if (mtmp[st.st_size-1] == '\n')
+	    mtmp[st.st_size-1] = '\0';
+	else
+	    mtmp[st.st_size] = '\0';
+	pam_info (pamh, "%s", mtmp);
+	break;
+    }
+    _pam_drop (mtmp);
+    if (fd >= 0)
+	close(fd);
+}
+
 PAM_EXTERN
 int pam_sm_open_session(pam_handle_t *pamh, int flags,
 			int argc, const char **argv)
 {
     int retval = PAM_IGNORE;
-    int fd;
+    int do_update = 1;
     const char *motd_path = NULL;
-    char *mtmp = NULL;
+    struct stat st;
 
     if (flags & PAM_SILENT) {
 	return retval;
@@ -73,6 +98,9 @@
 			   "motd= specification missing argument - ignored");
 	    }
 	}
+	else if (!strcmp(*argv,"noupdate")) {
+		do_update = 0;
+	}
 	else
 	    pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv);
     }
@@ -80,34 +108,23 @@
     if (motd_path == NULL)
 	motd_path = default_motd;
 
-    while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
-	struct stat st;
-
-	/* fill in message buffer with contents of motd */
-	if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
-	    break;
-
-	if (!(mtmp = malloc(st.st_size+1)))
-	    break;
-
-	if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
-	    break;
-
-	if (mtmp[st.st_size-1] == '\n')
-	    mtmp[st.st_size-1] = '\0';
-	else
-	    mtmp[st.st_size] = '\0';
-
-	pam_info (pamh, "%s", mtmp);
-	break;
+    /* Run the update-motd dynamic motd scripts, outputting to /var/run/motd.
+       If /etc/motd -> /var/run/motd, the displayed MOTD will be dynamic.
+       Otherwise, the admin can force a static MOTD by breaking that symlink
+       and publishing into an /etc/motd text file. */
+    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 > /var/run/motd.new"))
+	    rename("/var/run/motd.new", "/var/run/motd");
+	umask(old_mask);
     }
 
-    _pam_drop (mtmp);
-
-    if (fd >= 0)
-	close(fd);
+    /* Display the updated motd */
+    display_file(pamh, motd_path);
 
-     return retval;
+    return retval;
 }
 
 
Index: pam.debian/modules/pam_motd/pam_motd.8.xml
===================================================================
--- pam.debian.orig/modules/pam_motd/pam_motd.8.xml
+++ pam.debian/modules/pam_motd/pam_motd.8.xml
@@ -52,6 +52,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>
   </refsect1>
 
Index: pam.debian/modules/pam_motd/pam_motd.8
===================================================================
--- pam.debian.orig/modules/pam_motd/pam_motd.8
+++ pam.debian/modules/pam_motd/pam_motd.8
@@ -45,6 +45,13 @@
 /path/filename
 file is displayed as message of the day\&.
 .RE
+.PP
+\fBnoupdate\fR
+.RS 4
+Don\*(Aqt run the scripts in
+/etc/update\-motd\&.d
+to refresh the motd file\&.
+.RE
 .SH "MODULE TYPES PROVIDED"
 .PP
 Only the
Index: pam.debian/modules/pam_motd/README
===================================================================
--- pam.debian.orig/modules/pam_motd/README
+++ pam.debian/modules/pam_motd/README
@@ -14,6 +14,10 @@
 
     The /path/filename file is displayed as message of the day.
 
+noupdate
+
+    Don't run the scripts in /etc/update-motd.d to refresh the motd file.
+
 EXAMPLES
 
 The suggested usage for /etc/pam.d/login is: