]> git.pld-linux.org Git - packages/pam.git/blame - update-motd.patch
add link to bugtracker
[packages/pam.git] / update-motd.patch
CommitLineData
08e6ed3d 1Patch for Ubuntu bug #399071
c4c4339b 2https://bugs.launchpad.net/ubuntu/+source/pam/+bug/399071
08e6ed3d
ER
3
4Provide a more dynamic MOTD, based on the short-lived update-motd project.
5
6Authors: Dustin Kirkland <kirkland@canonical.com>
7
8Upstream status: not yet submitted
9
10Index: pam.ubuntu/modules/pam_motd/pam_motd.c
11===================================================================
12--- pam.ubuntu.orig/modules/pam_motd/pam_motd.c
13+++ pam.ubuntu/modules/pam_motd/pam_motd.c
14@@ -48,14 +48,39 @@
15
16 static char default_motd[] = DEFAULT_MOTD;
17
18+static void display_file(pam_handle_t *pamh, const char *motd_path)
19+{
20+ int fd;
21+ char *mtmp = NULL;
22+ while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
23+ struct stat st;
24+ /* fill in message buffer with contents of motd */
25+ if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
26+ break;
27+ if (!(mtmp = malloc(st.st_size+1)))
28+ break;
29+ if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
30+ break;
31+ if (mtmp[st.st_size-1] == '\n')
32+ mtmp[st.st_size-1] = '\0';
33+ else
34+ mtmp[st.st_size] = '\0';
35+ pam_info (pamh, "%s", mtmp);
36+ break;
37+ }
38+ _pam_drop (mtmp);
39+ if (fd >= 0)
40+ close(fd);
41+}
42+
43 PAM_EXTERN
44 int pam_sm_open_session(pam_handle_t *pamh, int flags,
45 int argc, const char **argv)
46 {
47 int retval = PAM_IGNORE;
48- int fd;
49+ int do_update = 1;
50 const char *motd_path = NULL;
51- char *mtmp = NULL;
52+ struct stat st;
53
54 if (flags & PAM_SILENT) {
55 return retval;
56@@ -73,6 +98,9 @@
57 "motd= specification missing argument - ignored");
58 }
59 }
60+ else if (!strcmp(*argv,"noupdate")) {
61+ do_update = 0;
62+ }
63 else
64 pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv);
65 }
66@@ -80,34 +108,23 @@
67 if (motd_path == NULL)
68 motd_path = default_motd;
69
70- while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
71- struct stat st;
72-
73- /* fill in message buffer with contents of motd */
74- if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
75- break;
76-
77- if (!(mtmp = malloc(st.st_size+1)))
78- break;
79-
80- if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
81- break;
82-
83- if (mtmp[st.st_size-1] == '\n')
84- mtmp[st.st_size-1] = '\0';
85- else
86- mtmp[st.st_size] = '\0';
87-
88- pam_info (pamh, "%s", mtmp);
89- break;
90+ /* Run the update-motd dynamic motd scripts, outputting to /var/run/motd.
91+ If /etc/motd -> /var/run/motd, the displayed MOTD will be dynamic.
92+ Otherwise, the admin can force a static MOTD by breaking that symlink
93+ and publishing into an /etc/motd text file. */
94+ if (do_update && (stat("/etc/update-motd.d", &st) == 0)
95+ && S_ISDIR(st.st_mode))
96+ {
97+ mode_t old_mask = umask(0022);
109a8689 98+ if (!system("/usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts /etc/update-motd.d > /var/run/motd.new"))
08e6ed3d
ER
99+ rename("/var/run/motd.new", "/var/run/motd");
100+ umask(old_mask);
101 }
102
103- _pam_drop (mtmp);
104-
105- if (fd >= 0)
106- close(fd);
107+ /* Display the updated motd */
108+ display_file(pamh, motd_path);
109
110- return retval;
111+ return retval;
112 }
113
114
115Index: pam.ubuntu/modules/pam_motd/pam_motd.8.xml
116===================================================================
117--- pam.ubuntu.orig/modules/pam_motd/pam_motd.8.xml
118+++ pam.ubuntu/modules/pam_motd/pam_motd.8.xml
119@@ -52,6 +52,17 @@
120 </para>
121 </listitem>
122 </varlistentry>
123+ <varlistentry>
124+ <term>
125+ <option>noupdate</option>
126+ </term>
127+ <listitem>
128+ <para>
129+ Don't run the scripts in <filename>/etc/update-motd.d</filename>
130+ to refresh the motd file.
131+ </para>
132+ </listitem>
133+ </varlistentry>
134 </variablelist>
135 </refsect1>
136
137Index: pam.ubuntu/modules/pam_motd/pam_motd.8
138===================================================================
139--- pam.ubuntu.orig/modules/pam_motd/pam_motd.8
140+++ pam.ubuntu/modules/pam_motd/pam_motd.8
08e6ed3d
ER
141@@ -45,6 +45,13 @@
142 /path/filename
143 file is displayed as message of the day\&.
144 .RE
145+.PP
146+\fBnoupdate\fR
147+.RS 4
148+Don\*(Aqt run the scripts in
149+/etc/update\-motd\&.d
150+to refresh the motd file\&.
151+.RE
152 .SH "MODULE TYPES PROVIDED"
153 .PP
154 Only the
155Index: pam.ubuntu/modules/pam_motd/README
156===================================================================
157--- pam.ubuntu.orig/modules/pam_motd/README
158+++ pam.ubuntu/modules/pam_motd/README
159@@ -14,6 +14,10 @@
160
161 The /path/filename file is displayed as message of the day.
162
163+noupdate
164+
165+ Don't run the scripts in /etc/update-motd.d to refresh the motd file.
166+
167 EXAMPLES
168
169 The suggested usage for /etc/pam.d/login is:
This page took 0.078519 seconds and 4 git commands to generate.