public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: libc-alpha@sourceware.org
Subject: Re: v5 [PATCH 6/6] nsswitch: use new internal API (callers)
Date: Wed, 17 Feb 2021 00:42:26 -0500	[thread overview]
Message-ID: <xnczwz8d31.fsf@greed.delorie.com> (raw)
In-Reply-To: <87r1lgquew.fsf@igel.home> (message from Andreas Schwab on Tue, 16 Feb 2021 09:38:31 +0100)

Andreas Schwab <schwab@linux-m68k.org> writes:
> nss_compat needs the {passwd,group,shadow}_compat databases, which
> __nss_database_lookup2 doesn't recognize.

Added.

>> +  /* Primary name not found, try alternate.  */
>> +  for (database_id = 0; database_names[database_id]; database_id++)
>> +    if (strcmp (database_names[database_id], alternate_name) == 0)
>> +      if (__nss_database_get (database_id, ni) && *ni != NULL)
>> +	return 0;
>
> That crashes if alternate_name is NULL.

It looks like alternate_name is only used by the shadow/gshadow
databases, though.

New patch; has a debug printf so you can validate what
nss_database_lookup2 calls happen; remove if you like.

From cabd86ff35008957d9dc3818c5e2a43d247962cb Mon Sep 17 00:00:00 2001
From: DJ Delorie <dj@redhat.com>
Date: Mon, 15 Feb 2021 21:34:23 -0500
Subject: nss: fix nss_database_lookup2's alternate handling [27416]


diff --git a/nss/databases.def b/nss/databases.def
index df5fab4168..3dc95648a8 100644
--- a/nss/databases.def
+++ b/nss/databases.def
@@ -23,17 +23,20 @@
 DEFINE_DATABASE (aliases)
 DEFINE_DATABASE (ethers)
 DEFINE_DATABASE (group)
+DEFINE_DATABASE (group_compat)
 DEFINE_DATABASE (gshadow)
 DEFINE_DATABASE (hosts)
 DEFINE_DATABASE (initgroups)
 DEFINE_DATABASE (netgroup)
 DEFINE_DATABASE (networks)
 DEFINE_DATABASE (passwd)
+DEFINE_DATABASE (passwd_compat)
 DEFINE_DATABASE (protocols)
 DEFINE_DATABASE (publickey)
 DEFINE_DATABASE (rpc)
 DEFINE_DATABASE (services)
 DEFINE_DATABASE (shadow)
+DEFINE_DATABASE (shadow_compat)
 
 /*
    Local Variables:
diff --git a/nss/nss_database.c b/nss/nss_database.c
index e1bef6bd75..162800cda3 100644
--- a/nss/nss_database.c
+++ b/nss/nss_database.c
@@ -172,7 +172,7 @@ nss_database_select_default (struct nss_database_default_cache *cache,
 
 /* database_name must be large enough for each individual name plus a
    null terminator.  */
-typedef char database_name[11];
+typedef char database_name[14];
 #define DEFINE_DATABASE(name) \
   _Static_assert (sizeof (#name) <= sizeof (database_name), #name);
 #include "databases.def"
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 46f232d720..aa59d426bc 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -74,26 +74,33 @@ __nss_database_lookup2 (const char *database, const char *alternate_name,
 {
   int database_id;
 
+  printf("lookup2  %s  %s  %s\n",
+	 database?database:"no-dname",
+	 alternate_name?alternate_name:"no-alt",
+	 defconfig?defconfig:"no-def");
+
   for (database_id = 0; database_names[database_id]; database_id++)
     if (strcmp (database_names[database_id], database) == 0)
-	break;
-
-  if (database_names[database_id] == NULL)
-    return -1;
-
-  /* If *NI is NULL, the database was not mentioned in nsswitch.conf.
-     If *NI is not NULL, but *NI->module is NULL, the database was in
-     nsswitch.conf but listed no actions.  We test for the former.  */
-  if (__nss_database_get (database_id, ni) && *ni != NULL)
-    {
-      /* Success.  */
-      return 0;
-    }
-  else
-    {
-      /* Failure.  */
-      return -1;
-    }
+      /* If *NI is NULL, the database was not mentioned in nsswitch.conf.
+	 If *NI is not NULL, but *NI->module is NULL, the database was in
+	 nsswitch.conf but listed no actions.  We test for the former.  */
+      if (__nss_database_get (database_id, ni) && *ni != NULL)
+	return 0;
+
+  /* Primary name not found, try alternate.  */
+  if (alternate_name)
+    for (database_id = 0; database_names[database_id]; database_id++)
+      if (strcmp (database_names[database_id], alternate_name) == 0)
+	if (__nss_database_get (database_id, ni) && *ni != NULL)
+	  return 0;
+
+  /* Neither found, use default config.  */
+  *ni = __nss_action_parse (defconfig);
+  if (*ni != NULL)
+    return 0;
+
+  /* Failure.  */
+  return -1;
 }
 libc_hidden_def (__nss_database_lookup2)
 


  reply	other threads:[~2021-02-17  5:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 20:34 DJ Delorie
2020-12-04  3:29 ` Siddhesh Poyarekar
2021-02-15 15:42   ` Andreas Schwab
2021-02-16  2:36     ` DJ Delorie
2021-02-16  8:38       ` Andreas Schwab
2021-02-17  5:42         ` DJ Delorie [this message]
2021-02-17 13:27           ` Andreas Schwab
2021-02-17 20:44             ` DJ Delorie
2021-02-17 21:09               ` Andreas Schwab
2021-02-17 21:15                 ` DJ Delorie
2021-02-17 22:31                   ` Andreas Schwab
2021-02-17 22:51                     ` DJ Delorie
2021-02-17 23:23                       ` Andreas Schwab
2021-02-18  4:55                         ` DJ Delorie
2021-02-18  8:43                           ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xnczwz8d31.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).