[PATCH] nss: look for databases in /usr/share/nss/ if they don't exist in /etc/

Andreas Schwab schwab@suse.de
Mon Sep 30 11:49:14 GMT 2024


On Sep 30 2024, Lennart Poettering wrote:

> diff --git a/nss/nss_files_fopen.c b/nss/nss_files_fopen.c
> index e7c48d7bd8..7e467e89ce 100644
> --- a/nss/nss_files_fopen.c
> +++ b/nss/nss_files_fopen.c
> @@ -21,6 +21,9 @@
>  #include <errno.h>
>  #include <stdio_ext.h>
>
> +#define PRIMARY_PREFIX "/etc/"
> +#define FALLBACK_PREFIX "/usr/share/nss/"
> +
>  FILE *
>  __nss_files_fopen (const char *path)
>  {
> @@ -45,3 +48,26 @@ __nss_files_fopen (const char *path)
>    return fp;
>  }
>  libc_hidden_def (__nss_files_fopen)
> +
> +FILE *
> +__nss_files_fopen_database (const char *database)
> +{
> +  char buf[sizeof(FALLBACK_PREFIX) + NAME_MAX];
> +
> +  /* Protect against overflow */
> +  size_t n = strlen (database);
> +  if (n > NAME_MAX)
> +    {
> +      __set_errno (EINVAL);
> +      return NULL;
> +    }
> +
> +  strcpy (stpcpy (buf, PRIMARY_PREFIX), database);
> +  FILE *fp = __nss_files_fopen (buf);
> +  if (fp != NULL || errno != ENOENT)

I think this should also check for ENOTDIR.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list