Wietse Venema:
> Kiss G?bor:
> > Feb 16 11:39:56 MYHOST postfix/local[22389]: warning: error looking up 
> > passwd info for +bar: No such file or directory
> 
> That is a bug in your system library implementation: it returns an
> error (ENOENT) for an entry that does not exist.
> 
> API:
>    int getpwnam_r(const char *name, struct passwd *pwd,
>                char *buf, size_t buflen, struct passwd **result);
> 
> OpenGroup standard:
>     The getpwnam_r() function shall return zero on success or if
>     the requested entry was not found and no error has occurred.
>     If an error has occurred, an error number shall be returned to
>     indicate the error.
> 
> What is the back-end for your UNIX system account lookups: is this
> LDAP, files, or something else? This weekend there was a thread
> about getpwnam_r() not returning errors when an LDAP server was
> down. Now we have getpwnam_r() returing errors for non-error lookups.
> If this is the same LDAP driver then it badly needs fixing.

Below is a small C program. Save as getpwnam_r_test.c, build with
"make getpwnam_r_test", and run as "./getpwnam_r_test username".

This is the correct result:

    $ ./getpwnam_r_test wietse
    wietse: no error: uid=304252 (Wietse Venema)
    $ ./getpwnam_r_test +bar
    +bar: no error: not found
    $ ./getpwnam_r_test doesnotexist
    doesnotexist: no error: not found
    $ ./getpwnam_r_test ''
    : no error: not found

As you see, there is no error for non-existent users, even if the
name is spelled in a funny manner.

        Wietse

If you're reading this with a web browser then it may look funny.

#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

int main(int argc, char **argv) {
  char buf[BUFSIZ];
  struct passwd pwbuf;
  struct passwd *pwd;
  int err;

  while (--argc && *++argv) {
    err = getpwnam_r(*argv, &pwbuf, buf, sizeof(buf), &pwd);
    if (err != 0) {
      printf("%s: error: %s\n", *argv, strerror(errno));
    } else if (pwd == 0) {
      printf("%s: no error: not found\n", *argv);
    } else {
      printf("%s: no error: uid=%ld (%s)\n", *argv, (long)pwd->pw_uid,
             pwd->pw_gecos);
    }
  }
  exit(0);
}

Reply via email to