tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mail.local NSS awareness (third patch)



In article <20080430092146.GC14474%NetBSD.org@localhost>,
Emmanuel Dreyfus  <manu%netbsd.org@localhost> wrote:
>On Wed, Apr 30, 2008 at 11:08:50AM +0200, Manuel Bouyer wrote:
>> > I think returning EX_UNAVAILABLE would be better. OTOH, I wonder if
>> > we should restrict EX_TEMPFAIL to EGAIN ang ETIMEDOUT. I think it would
>> > make sense to return EX_TEMPFAIL for any getpwnam_r() error. After all,
>> > if you fail because of something like ENOMEM, it should be a temporary 
>> > failure.
>> 
>> I think so.
>
>So here is my third attempt:
>
>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 09:20:37 -0000
>@@ -56,8 +56,10 @@
> #include <string.h>
> #include <syslog.h>
> #include <time.h>
> #include <unistd.h>
>+#include <err.h>
>+#include <sysexits.h>
> 
> #include "pathnames.h"
> 
> #define        FATAL           1
>@@ -180,21 +182,22 @@
>        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)
>+               err(EX_TEMPFAIL, "unknown name: %s", name);
>+       if (pw == NULL)
>+               errx(EX_UNAVAILABLE, "unknown name: %s", name);
> 
>        (void)snprintf(path, sizeof path, "%s/%s", _PATH_MAILDIR, name);
> 
>        if (lockfile) {
>

Yes this is a lot better! Please fix the man pages (not only the getpwnam one)
to indicate that errno is going to be set
if the routines return != 0, which is true according to:

    http://www.opengroup.org/onlinepubs/000095399/functions/getpwnam.html

We should also mention that depending on the database back-end other back-end
specific error numbers maybe returned.

christos



Home | Main Index | Thread Index | Old Index