From bad2705f9dc9c772aa3084f9572217fc5b1f6431 Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Wed, 15 Jul 2009 18:08:22 -0700 Subject: pam_motd: run the update-motd scripts in pam_motd; render update-motd obsolete, LP: #399071 --- debian/patches-applied/series | 1 + debian/patches-applied/update-motd | 98 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 debian/patches-applied/update-motd (limited to 'debian/patches-applied') diff --git a/debian/patches-applied/series b/debian/patches-applied/series index 652ce5a9..e5fbab49 100644 --- a/debian/patches-applied/series +++ b/debian/patches-applied/series @@ -23,3 +23,4 @@ pam_unix-chkpwd-wait autoconf.patch dont_freeze_password_chain -p0 pam_1.0.4_mindays +update-motd diff --git a/debian/patches-applied/update-motd b/debian/patches-applied/update-motd new file mode 100644 index 00000000..448e3c14 --- /dev/null +++ b/debian/patches-applied/update-motd @@ -0,0 +1,98 @@ +Patch for Ubuntu bug #399071 + +Provide a more dynamic MOTD, based on the short-lived update-motd project. + +Authors: Dustin Kirkland + +Upstream status: not yet submitted + +Index: pam.deb/modules/pam_motd/pam_motd.c +=================================================================== +--- pam.deb.orig/modules/pam_motd/pam_motd.c ++++ pam.deb/modules/pam_motd/pam_motd.c +@@ -48,14 +48,38 @@ + + static char default_motd[] = DEFAULT_MOTD; + ++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; + const char *motd_path = NULL; +- char *mtmp = NULL; ++ struct stat st; + + if (flags & PAM_SILENT) { + return retval; +@@ -80,34 +104,19 @@ + 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 ((stat("/etc/update-motd.d", &st) == 0) && S_IDIR(st.st_mode)) { ++ if (!system("run-parts --lsbsysinit /etc/update-motd.d > /var/run/motd.new")) ++ rename("/var/run/motd.new", "/var/run/motd"); + } + +- _pam_drop (mtmp); +- +- if (fd >= 0) +- close(fd); ++ /* Display the updated motd */ ++ display_file(pamh, motd_path); + +- return retval; ++ return retval; + } + + -- cgit v1.2.3 From ec965a4b45637d5d3a1792b9152f004941f11f81 Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Wed, 15 Jul 2009 20:05:56 -0700 Subject: correct a typo in the update-motd patch, introduced by me :( --- debian/patches-applied/update-motd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'debian/patches-applied') diff --git a/debian/patches-applied/update-motd b/debian/patches-applied/update-motd index 448e3c14..8c7b675a 100644 --- a/debian/patches-applied/update-motd +++ b/debian/patches-applied/update-motd @@ -6,15 +6,15 @@ Authors: Dustin Kirkland Upstream status: not yet submitted -Index: pam.deb/modules/pam_motd/pam_motd.c +Index: pam-1.0.1/modules/pam_motd/pam_motd.c =================================================================== ---- pam.deb.orig/modules/pam_motd/pam_motd.c -+++ pam.deb/modules/pam_motd/pam_motd.c +--- pam-1.0.1.orig/modules/pam_motd/pam_motd.c ++++ pam-1.0.1/modules/pam_motd/pam_motd.c @@ -48,14 +48,38 @@ static char default_motd[] = DEFAULT_MOTD; -+void display_file(pam_handle_t *pamh, const char *motd_path) ++static void display_file(pam_handle_t *pamh, const char *motd_path) +{ + int fd; + char *mtmp = NULL; @@ -79,7 +79,7 @@ Index: pam.deb/modules/pam_motd/pam_motd.c + 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 ((stat("/etc/update-motd.d", &st) == 0) && S_IDIR(st.st_mode)) { ++ if ((stat("/etc/update-motd.d", &st) == 0) && S_ISDIR(st.st_mode)) { + if (!system("run-parts --lsbsysinit /etc/update-motd.d > /var/run/motd.new")) + rename("/var/run/motd.new", "/var/run/motd"); } -- cgit v1.2.3