[PATCH 2/2] cygheap_pwdgrp: Don't keep old schemes when parsing nsswitch.conf

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] cygheap_pwdgrp: Don't keep old schemes when parsing nsswitch.conf

cygwin-patches mailing list
The implicit assumption seemed to be that any subsequent occurence of
the same setting in nsswitch.conf is supposed to rewrite the previous
ones completely.  This was not the case if the third or any further
schema was previously defined and the last line defined less than that
(but at least 2), for example:

```
db_home: windows cygwin /myhome/%U
db_home: cygwin desc
```

Let's document this behavior as well.
---
 winsup/cygwin/uinfo.cc | 5 +++--
 winsup/doc/ntsec.xml   | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 227faa4248..a4fcc33d8d 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -793,9 +793,10 @@ cygheap_pwdgrp::nss_init_line (const char *line)
     scheme = gecos_scheme;
   if (scheme)
     {
-      uint16_t idx = 0;
+      for (uint16_t idx = 0; idx < NSS_SCHEME_MAX; ++idx)
+ scheme[idx].method = NSS_SCHEME_FALLBACK;
 
-      scheme[0].method = scheme[1].method = NSS_SCHEME_FALLBACK;
+      uint16_t idx = 0;
       c = strchr (c, ':') + 1;
       c += strspn (c, " \t");
       while (*c && idx < NSS_SCHEME_MAX)
diff --git a/winsup/doc/ntsec.xml b/winsup/doc/ntsec.xml
index 5287845686..153ff1eac8 100644
--- a/winsup/doc/ntsec.xml
+++ b/winsup/doc/ntsec.xml
@@ -918,6 +918,11 @@ Apart from this restriction, the remainder of the line can have as
 many spaces and TABs as you like.
 </para>
 
+<para>
+When the same keyword occurs multiple times, the last one wins, as if the
+previous ones were ignored.
+</para>
+
 </sect4>
 
 <sect4 id="ntsec-mapping-nsswitch-pwdgrp"><title id="ntsec-mapping-nsswitch-pwdgrp.title">The <literal>passwd:</literal> and <literal>group:</literal> settings</title>
--
2.26.1.windows.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] cygheap_pwdgrp: Don't keep old schemes when parsing nsswitch.conf

Corinna Vinschen-2
On Apr 17 11:31, David Macek via Cygwin-patches wrote:

> The implicit assumption seemed to be that any subsequent occurence of
> the same setting in nsswitch.conf is supposed to rewrite the previous
> ones completely.  This was not the case if the third or any further
> schema was previously defined and the last line defined less than that
> (but at least 2), for example:
>
> ```
> db_home: windows cygwin /myhome/%U
> db_home: cygwin desc
> ```
>
> Let's document this behavior as well.
> ---
>  winsup/cygwin/uinfo.cc | 5 +++--
>  winsup/doc/ntsec.xml   | 5 +++++
>  2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
> index 227faa4248..a4fcc33d8d 100644
> --- a/winsup/cygwin/uinfo.cc
> +++ b/winsup/cygwin/uinfo.cc
> @@ -793,9 +793,10 @@ cygheap_pwdgrp::nss_init_line (const char *line)
>      scheme = gecos_scheme;
>    if (scheme)
>      {
> -      uint16_t idx = 0;
> +      for (uint16_t idx = 0; idx < NSS_SCHEME_MAX; ++idx)
> + scheme[idx].method = NSS_SCHEME_FALLBACK;
>  
> -      scheme[0].method = scheme[1].method = NSS_SCHEME_FALLBACK;
> +      uint16_t idx = 0;
Hmmm.  This `idx' usage is a bit puzzeling.  Here's a counter-proposal:

diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 57d90189d390..9521a973803e 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -793,12 +793,12 @@ cygheap_pwdgrp::nss_init_line (const char *line)
     scheme = gecos_scheme;
   if (scheme)
     {
-      uint16_t idx = 0;
+      for (uint16_t idx = 0; idx < NSS_SCHEME_MAX; ++idx)
+ scheme[idx].method = NSS_SCHEME_FALLBACK;
 
-      scheme[0].method = scheme[1].method = NSS_SCHEME_FALLBACK;
       c = strchr (c, ':') + 1;
       c += strspn (c, " \t");
-      while (*c && idx < NSS_SCHEME_MAX)
+      for (uint16_t idx = 0; *c && idx < NSS_SCHEME_MAX; ++idx)
  {
   if (NSS_CMP ("windows"))
     scheme[idx].method = NSS_SCHEME_WINDOWS;
@@ -829,7 +829,6 @@ cygheap_pwdgrp::nss_init_line (const char *line)
     }
   c += strcspn (c, " \t");
   c += strspn (c, " \t");
-  ++idx;
  }
       /* If nothing has been set, revert to default. */
       if (scheme[0].method == NSS_SCHEME_FALLBACK)

If that's ok with you I check it in as your patch.

Can you please send the 2-clause BSD waiver per
https://cygwin.com/contrib.html to this list, too?


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment