summaryrefslogtreecommitdiffstats
path: root/login-utils/login.c
diff options
context:
space:
mode:
authorKarel Zak2011-10-05 13:30:52 +0200
committerKarel Zak2011-10-26 23:17:17 +0200
commit4d8fc09c27d178eb187544270eeeebb0cd16ab36 (patch)
tree2f02ae0550179bbb65b207a5469939385ac94c6e /login-utils/login.c
parentlogin: remove obsolete info from man page (diff)
downloadkernel-qcow2-util-linux-4d8fc09c27d178eb187544270eeeebb0cd16ab36.tar.gz
kernel-qcow2-util-linux-4d8fc09c27d178eb187544270eeeebb0cd16ab36.tar.xz
kernel-qcow2-util-linux-4d8fc09c27d178eb187544270eeeebb0cd16ab36.zip
login: rewrite motd(), use MOTD_FILE from login.defs
Note that Suse login(1) does not use any default for MOTD_FILE, so MOTD_FILE item in login.defs is required otherwise nothing is printed. We use (for backward compatibility) /etc/motd as default. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/login.c')
-rw-r--r--login-utils/login.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index f4172bfbb..6e7e4e27c 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -43,7 +43,6 @@
#include <grp.h>
#include <pwd.h>
#include <utmp.h>
-#include <setjmp.h>
#include <stdlib.h>
#include <sys/syslog.h>
#include <sys/sysmacros.h>
@@ -52,6 +51,7 @@
#include <lastlog.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
+#include <sys/sendfile.h>
#ifdef HAVE_LIBAUDIT
# include <libaudit.h>
@@ -68,6 +68,8 @@
#include "xalloc.h"
#include "writeall.h"
+#include "logindefs.h"
+
#define is_pam_failure(_rc) ((_rc) != PAM_SUCCESS)
#define LOGIN_MAX_TRIES 3
@@ -122,8 +124,6 @@ static int timeout = LOGIN_TIMEOUT;
static int child_pid = 0;
static volatile int got_sig = 0;
-jmp_buf motdinterrupt;
-
/*
* Robert Ambrose writes:
* A couple of my users have a problem with login processes hanging around
@@ -173,12 +173,6 @@ static void sig_handler(int signal)
kill(-child_pid, SIGHUP); /* because the shell often ignores SIGTERM */
}
-static void sigint(int sig __attribute__ ((__unused__)))
-{
- longjmp(motdinterrupt, 1);
-}
-
-
/* Should not be called from PAM code... */
static void sleepexit(int eval)
{
@@ -186,23 +180,38 @@ static void sleepexit(int eval)
exit(eval);
}
+/*
+ * Output the /etc/motd file
+ *
+ * motd() determines the name of a login announcement file and outputs it to
+ * the user's terminal at login time. The MOTD_FILE configuration option is a
+ * colon-delimited list of filenames. The empty MOTD_FILE option disables motd
+ * printing at all.
+ */
static void motd(void)
{
- int fd, nchars;
- void (*oldint) (int);
- char tbuf[8192];
+ char *motdlist, *motdfile, *cp;
+ const char *mb;
- if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0)
+ mb = getlogindefs_str("MOTD_FILE", _PATH_MOTDFILE);
+ if (!mb || !*mb)
return;
- oldint = signal(SIGINT, sigint);
- if (setjmp(motdinterrupt) == 0)
- while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) {
- if (write(fileno(stdout), tbuf, nchars)) {
- ; /* glibc warn_unused_result */
- }
- }
- signal(SIGINT, oldint);
- close(fd);
+
+ motdlist = xstrdup(mb);
+
+ for (cp = motdlist; (motdfile = strtok(cp, ":")); cp = NULL) {
+ struct stat st;
+ int fd;
+
+ if (stat(motdfile, &st) || !st.st_size)
+ continue;
+ fd = open(motdfile, O_RDONLY, 0);
+ if (fd < 0)
+ continue;
+
+ sendfile(fileno(stdout), fd, NULL, st.st_size);
+ close(fd);
+ }
}
/*