tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: mail.local NSS awareness
On Wed, Apr 30, 2008 at 04:57:36AM +0200, Emmanuel Dreyfus wrote:
> Manuel Bouyer <bouyer%antioche.eu.org@localhost> wrote:
>
> > A better patch may be to use getpwnam_r(), which explicitely
> > "return 0 on success or entry not found, and non-zero on failure".
>
> Something like this, then?
>
> diff -U 4 -r1.23 mail.local.c
> --- mail.local.c 27 Sep 2006 17:15:20 -0000 1.23
> +++ mail.local.c 30 Apr 2008 02:53:27 -0000
> @@ -56,8 +56,9 @@
> #include <string.h>
> #include <syslog.h>
> #include <time.h>
> #include <unistd.h>
> +#include <sysexits.h>
>
> #include "pathnames.h"
>
> #define FATAL 1
> @@ -180,21 +181,33 @@
> char *name;
> int lockfile;
> {
> struct stat sb;
> - struct passwd *pw;
> + struct passwd pwres, *pw;
> + char pwbuf[1024];
> int created, mbfd, nr, nw, off, rval=0, lfd=-1;
> char biffmsg[100], buf[8*1024], path[MAXPATHLEN],
> lpath[MAXPATHLEN];
> off_t curoff;
>
> /*
> * Disallow delivery to unknown names -- special mailboxes can
> be
> * handled in the sendmail aliases file.
> */
> - if (!(pw = getpwnam(name))) {
> - err(NOTFATAL, "unknown name: %s", name);
> - return(1);
> + if ((getpwnam_r(name, &pwres, pwbuf, sizeof(pwbuf), &pw)) != 0)
> {
> + switch (errno) {
> + case EAGAIN:
> + case ETIMEDOUT:
> + err(EX_TEMPFAIL, "unknown name: %s", name);
> + break;
> + default:
> + err(EX_UNAVAILABLE, "unknown name: %s", name);
> + break;
> + }
> + /* NOTREACHED */
> + return(1);
> }
> + if (pw == NULL)
> + err(EX_OK, "unknown name: %s", name);
Shouldn't the last line be "err(EX_UNAVAILABLE, "unknown name: %s", name) ?
--
Manuel Bouyer <bouyer%antioche.eu.org@localhost>
NetBSD: 26 ans d'experience feront toujours la difference
--
Home |
Main Index |
Thread Index |
Old Index