Date: Tue, 19 Feb 2002 20:56:47 -0600 (CST) From: Andrew Hesford <jester@core.usrlib.org> To: FreeBSD-gnats-submit@freebsd.org Cc: jester@core.usrlib.org Subject: bin/35129: Maildir support in login(1) Message-ID: <20020220025647.59D8AA811@core.usrlib.org>
index | next in thread | raw e-mail
>Number: 35129
>Category: bin
>Synopsis: Maildir support in login(1)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Tue Feb 19 19:00:03 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Andrew Hesford
>Release: FreeBSD 4.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD core.usrlib.org 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 13 03:22:55 CST 2002 jester@core.usrlib.org:/usr/src/sys/compile/CORE i386
>Description:
login(1) checks a user's mbox file upon login, and if it finds
messages, reports to the user if there is mail (and whether or
not it is new). For systems where Qmail Maildir is used for
mail, this functionality is lost. I have produced a patch that
will use the $MAILDIR/cur and $MAILDIR/new directories to
determine if a user has mail (and whether or not it is new). It
will then report this on login, just as with mbox mail files.
>How-To-Repeat:
On a system using Maildir, send messages to a user, then login
as that user. Notice that login(1) does not report "You have new
mail." Likewise, after reading and saving the messages, logging
in will not produce a "You have mail." message.
>Fix:
This diff can be applied to /usr/src/usr.bin/login/. It makes
login(1) look for $MAILDIR if $MAIL is unset, and if $MAILDIR is
defined, uses $MAILDIR/cur and $MAILDIR/new to find read and
unread mail, respectively. Broken Maildir folders (missing cur
and new) will simply cause login(1) to ignore the mail prompt.
Should it be desired, the code can also be redone to print the
message counts (new and previously-read messages). The following
diff can be applied by changing to the /usr/src/usr.bin/login/
directory and running `patch < login.diff`.
:::: BEGIN login.diff ::::
*** login.c.orig Tue Feb 19 20:25:37 2002
--- login.c Tue Feb 19 20:25:47 2002
***************
*** 53,59 ****
--- 53,61 ----
#include <sys/copyright.h>
#include <sys/param.h>
+ #include <sys/types.h>
#include <sys/stat.h>
+ #include <fts.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/resource.h>
***************
*** 167,172 ****
--- 169,179 ----
char tname[sizeof(_PATH_TTY) + 10];
char *shell = NULL;
login_cap_t *lc = NULL;
+ int use_mdir = 0;
+ FTS *ftsp;
+ char *mdbuf[3];
+ FTSENT *ftse;
+ int mdopt = FTS_NOCHDIR | FTS_NOSTAT | FTS_LOGICAL;
#ifdef USE_PAM
pid_t pid;
int e;
***************
*** 690,701 ****
cw = getenv("MAIL"); /* $MAIL may have been set by class */
if (cw != NULL)
strlcpy(tbuf, cw, sizeof(tbuf));
! else
! snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILDIR,
! pwd->pw_name);
! if (stat(tbuf, &st) == 0 && st.st_size != 0)
(void)printf("You have %smail.\n",
(st.st_mtime > st.st_atime) ? "new " : "");
}
login_close(lc);
--- 697,743 ----
cw = getenv("MAIL"); /* $MAIL may have been set by class */
if (cw != NULL)
strlcpy(tbuf, cw, sizeof(tbuf));
! else {
! cw = getenv("MAILDIR");
! if (cw != NULL) {
! strlcpy(tbuf, cw, sizeof(tbuf));
! use_mdir = 1;
! }
! else
! snprintf(tbuf, sizeof(tbuf), "%s/%s",
! _PATH_MAILDIR, pwd->pw_name);
! }
! if (!use_mdir && stat(tbuf, &st) == 0 && st.st_size != 0)
(void)printf("You have %smail.\n",
(st.st_mtime > st.st_atime) ? "new " : "");
+ else if (use_mdir && stat(tbuf, &st) == 0 &&
+ (st.st_mode & S_IFDIR) != 0) {
+ mdbuf[0] = (char*)malloc(sizeof(tbuf));
+ bzero(mdbuf[0], sizeof(mdbuf[0]));
+ mdbuf[1] = (char*)malloc(sizeof(tbuf));
+ bzero(mdbuf[1], sizeof(mdbuf[1]));
+ snprintf(mdbuf[0], sizeof(tbuf), "%s/new", tbuf);
+ snprintf(mdbuf[1], sizeof(tbuf), "%s/cur", tbuf);
+ if ((ftsp = fts_open(mdbuf, mdopt, NULL)) != NULL) {
+ int ncount = 0, ocount = 0;
+ ftse = fts_read(ftsp);
+ while ((ftse = fts_read(ftsp)) != NULL &&
+ strncmp(ftse->fts_name, "new",
+ sizeof(char)*4) != 0)
+ ncount++;
+ ftse = fts_read(ftsp);
+ while ((ftse = fts_read(ftsp)) != NULL &&
+ strncmp(ftse->fts_name, "cur",
+ sizeof(char)*4) != 0)
+ ocount++;
+ if (ncount > 0)
+ (void)printf("You have new mail.\n");
+ else if (ocount > 0)
+ (void)printf("You have mail.\n");
+ fts_close(ftsp);
+ }
+ }
+
}
login_close(lc);
*** login.1.orig Tue Feb 19 20:25:57 2002
--- login.1 Tue Feb 19 20:26:01 2002
***************
*** 173,179 ****
login account records
.It Pa /var/mail/user
system mailboxes
! .It Pa \&.hushlogin
makes login quieter
.It Pa /etc/auth.conf
configure authentication services
--- 173,181 ----
login account records
.It Pa /var/mail/user
system mailboxes
! .It Pa ~/Maildir
! Maildir mailbox (used if $MAIL is unset)
! .It Pa ~/\&.hushlogin
makes login quieter
.It Pa /etc/auth.conf
configure authentication services
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020220025647.59D8AA811>
