summaryrefslogtreecommitdiff
path: root/modules/pam_motd
diff options
context:
space:
mode:
authorSteve Langasek <vorlon@debian.org>2019-02-11 16:13:42 -0800
committerSteve Langasek <vorlon@debian.org>2019-02-12 06:07:57 +0000
commit668b13da8f830c38388cecac45539972e80cb246 (patch)
treeba3a4e02ed5ec62fe645dfa810c01d26decf591f /modules/pam_motd
parentf00afb1ef201b2eef7f9ddbe5a0c6ca802cf49bb (diff)
parent3b77a78d575b8ab56bb0e828499df328d55c925f (diff)
New upstream version 1.3.1
Diffstat (limited to 'modules/pam_motd')
-rw-r--r--modules/pam_motd/README24
-rw-r--r--modules/pam_motd/pam_motd.854
-rw-r--r--modules/pam_motd/pam_motd.8.xml36
-rw-r--r--modules/pam_motd/pam_motd.c100
4 files changed, 182 insertions, 32 deletions
diff --git a/modules/pam_motd/README b/modules/pam_motd/README
index 12a8fcc7..c16938c1 100644
--- a/modules/pam_motd/README
+++ b/modules/pam_motd/README
@@ -14,14 +14,36 @@ motd=/path/filename
The /path/filename file is displayed as message of the day.
+motd_dir=/path/dirname.d
+
+ The /path/dirname.d directory is scanned and each file contained inside of
+ it is displayed.
+
+When no options are given, the default is to display both /etc/motd and the
+contents of /etc/motd.d. Specifying either option (or both) will disable this
+default behavior.
+
EXAMPLES
The suggested usage for /etc/pam.d/login is:
-session optional pam_motd.so motd=/etc/motd
+session optional pam_motd.so
+
+
+To use a motd file from a different location:
+
+session optional pam_motd.so motd=/elsewhere/motd
+
+
+To use a motd file from elsewhere, along with a corresponding .d directory:
+
+session optional pam_motd.so motd=/elsewhere/motd motd_dir=/elsewhere/motd.d
AUTHOR
pam_motd was written by Ben Collins <bcollins@debian.org>.
+The motd_dir= option was added by Allison Karlitskaya
+<allison.karlitskaya@redhat.com>.
+
diff --git a/modules/pam_motd/pam_motd.8 b/modules/pam_motd/pam_motd.8
index d63f54fb..21c2ed76 100644
--- a/modules/pam_motd/pam_motd.8
+++ b/modules/pam_motd/pam_motd.8
@@ -2,12 +2,12 @@
.\" Title: pam_motd
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\" Date: 04/01/2016
+.\" Date: 05/18/2018
.\" Manual: Linux-PAM Manual
.\" Source: Linux-PAM Manual
.\" Language: English
.\"
-.TH "PAM_MOTD" "8" "04/01/2016" "Linux-PAM Manual" "Linux\-PAM Manual"
+.TH "PAM_MOTD" "8" "05/18/2018" "Linux-PAM Manual" "Linux\-PAM Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -45,6 +45,18 @@ The
/path/filename
file is displayed as message of the day\&.
.RE
+.PP
+\fBmotd_dir=\fR\fB\fI/path/dirname\&.d\fR\fR
+.RS 4
+The
+/path/dirname\&.d
+directory is scanned and each file contained inside of it is displayed\&.
+.RE
+.PP
+When no options are given, the default is to display both
+/etc/motd
+and the contents of
+/etc/motd\&.d\&. Specifying either option (or both) will disable this default behavior\&.
.SH "MODULE TYPES PROVIDED"
.PP
Only the
@@ -66,7 +78,39 @@ is:
.RS 4
.\}
.nf
-session optional pam_motd\&.so motd=/etc/motd
+session optional pam_motd\&.so
+
+.fi
+.if n \{\
+.RE
+.\}
+.PP
+To use a
+motd
+file from a different location:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+session optional pam_motd\&.so motd=/elsewhere/motd
+
+.fi
+.if n \{\
+.RE
+.\}
+.PP
+To use a
+motd
+file from elsewhere, along with a corresponding
+\&.d
+directory:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+session optional pam_motd\&.so motd=/elsewhere/motd motd_dir=/elsewhere/motd\&.d
.fi
.if n \{\
@@ -82,3 +126,7 @@ session optional pam_motd\&.so motd=/etc/motd
.SH "AUTHOR"
.PP
pam_motd was written by Ben Collins <bcollins@debian\&.org>\&.
+.PP
+The
+\fBmotd_dir=\fR
+option was added by Allison Karlitskaya <allison\&.karlitskaya@redhat\&.com>\&.
diff --git a/modules/pam_motd/pam_motd.8.xml b/modules/pam_motd/pam_motd.8.xml
index ff92154e..906c4ed0 100644
--- a/modules/pam_motd/pam_motd.8.xml
+++ b/modules/pam_motd/pam_motd.8.xml
@@ -52,7 +52,24 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <option>motd_dir=<replaceable>/path/dirname.d</replaceable></option>
+ </term>
+ <listitem>
+ <para>
+ The <filename>/path/dirname.d</filename> directory is scanned
+ and each file contained inside of it is displayed.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
+ <para>
+ When no options are given, the default is to display both
+ <filename>/etc/motd</filename> and the contents of
+ <filename>/etc/motd.d</filename>. Specifying either option (or both)
+ will disable this default behavior.
+ </para>
</refsect1>
<refsect1 id="pam_motd-types">
@@ -81,7 +98,20 @@
<para>
The suggested usage for <filename>/etc/pam.d/login</filename> is:
<programlisting>
-session optional pam_motd.so motd=/etc/motd
+session optional pam_motd.so
+ </programlisting>
+ </para>
+ <para>
+ To use a <filename>motd</filename> file from a different location:
+ <programlisting>
+session optional pam_motd.so motd=/elsewhere/motd
+ </programlisting>
+ </para>
+ <para>
+ To use a <filename>motd</filename> file from elsewhere, along with a
+ corresponding <filename>.d</filename> directory:
+ <programlisting>
+session optional pam_motd.so motd=/elsewhere/motd motd_dir=/elsewhere/motd.d
</programlisting>
</para>
</refsect1>
@@ -109,6 +139,10 @@ session optional pam_motd.so motd=/etc/motd
<para>
pam_motd was written by Ben Collins &lt;bcollins@debian.org&gt;.
</para>
+ <para>
+ The <option>motd_dir=</option> option was added by
+ Allison Karlitskaya &lt;allison.karlitskaya@redhat.com&gt;.
+ </para>
</refsect1>
</refentry>
diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c
index 11c7b565..cc828d7e 100644
--- a/modules/pam_motd/pam_motd.c
+++ b/modules/pam_motd/pam_motd.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
+#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
@@ -33,6 +34,7 @@
#define PAM_SM_SESSION
#define DEFAULT_MOTD "/etc/motd"
+#define DEFAULT_MOTD_D "/etc/motd.d"
#include <security/pam_modules.h>
#include <security/pam_modutil.h>
@@ -47,14 +49,60 @@ pam_sm_close_session (pam_handle_t *pamh UNUSED, int flags UNUSED,
}
static char default_motd[] = DEFAULT_MOTD;
+static char default_motd_dir[] = DEFAULT_MOTD_D;
+
+static void try_to_display_fd(pam_handle_t *pamh, int fd)
+{
+ struct stat st;
+ char *mtmp = NULL;
+
+ /* fill in message buffer with contents of motd */
+ if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
+ return;
+
+ if (!(mtmp = malloc(st.st_size+1)))
+ return;
+
+ if (pam_modutil_read(fd, mtmp, st.st_size) == st.st_size) {
+ if (mtmp[st.st_size-1] == '\n')
+ mtmp[st.st_size-1] = '\0';
+ else
+ mtmp[st.st_size] = '\0';
+
+ pam_info (pamh, "%s", mtmp);
+ }
+
+ _pam_drop(mtmp);
+}
+
+static void try_to_display_directory(pam_handle_t *pamh, const char *dirname)
+{
+ DIR *dirp;
+
+ dirp = opendir(dirname);
+
+ if (dirp != NULL) {
+ struct dirent *entry;
+
+ while ((entry = readdir(dirp))) {
+ int fd = openat(dirfd(dirp), entry->d_name, O_RDONLY);
+
+ if (fd >= 0) {
+ try_to_display_fd(pamh, fd);
+ close(fd);
+ }
+ }
+
+ closedir(dirp);
+ }
+}
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;
+ const char *motd_dir_path = NULL;
if (flags & PAM_SILENT) {
return retval;
@@ -72,41 +120,39 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags,
"motd= specification missing argument - ignored");
}
}
+ else if (!strncmp(*argv,"motd_dir=",9)) {
+
+ motd_dir_path = 9 + *argv;
+ if (*motd_dir_path != '\0') {
+ D(("set motd.d path: %s", motd_dir_path));
+ } else {
+ motd_dir_path = NULL;
+ pam_syslog(pamh, LOG_ERR,
+ "motd_dir= specification missing argument - ignored");
+ }
+ }
else
pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv);
}
- if (motd_path == NULL)
+ if (motd_path == NULL && motd_dir_path == NULL) {
motd_path = default_motd;
+ motd_dir_path = default_motd_dir;
+ }
- 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 (motd_path != NULL) {
+ int fd = open(motd_path, O_RDONLY, 0);
- 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;
+ if (fd >= 0) {
+ try_to_display_fd(pamh, fd);
+ close(fd);
+ }
}
- _pam_drop (mtmp);
-
- if (fd >= 0)
- close(fd);
+ if (motd_dir_path != NULL)
+ try_to_display_directory(pamh, motd_dir_path);
- return retval;
+ return retval;
}
/* end of module definition */