[PATCH 1/3 v2] Cygwin: accounts: Unify nsswitch.conf db_* defaults

2020-04-20 Thread David Macek via Cygwin-patches
Signed-off-by: David Macek 
---
 winsup/cygwin/uinfo.cc | 11 +--
 winsup/doc/ntsec.xml   | 27 +++
 2 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 57d90189d3..2d5fc488bb 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -626,15 +626,12 @@ cygheap_pwdgrp::init ()
   grp_cache.cygserver.init_grp ();
   grp_cache.file.init_grp ();
   grp_cache.win.init_grp ();
-  /* Default settings:
+  /* Default settings (excluding fallbacks):
 
  passwd: files db
  group:  files db
  db_prefix: auto   DISABLED
  db_separator: +   DISABLED
- db_home: cygwin desc
- db_shell: cygwin desc
- db_gecos: cygwin desc
  db_enum: cache builtin
   */
   pwd_src = (NSS_SRC_FILES | NSS_SRC_DB);
@@ -831,12 +828,6 @@ cygheap_pwdgrp::nss_init_line (const char *line)
  c += strspn (c, " \t");
  ++idx;
}
- /* If nothing has been set, revert to default. */
- if (scheme[0].method == NSS_SCHEME_FALLBACK)
-   {
- scheme[0].method = NSS_SCHEME_CYGWIN;
- scheme[1].method = NSS_SCHEME_DESC;
-   }
}
}
   break;
diff --git a/winsup/doc/ntsec.xml b/winsup/doc/ntsec.xml
index 5287845686..032bebe4dc 100644
--- a/winsup/doc/ntsec.xml
+++ b/winsup/doc/ntsec.xml
@@ -874,9 +874,6 @@ set up to all default values:
   db_prefix:auto
   db_separator: + -->
   db_enum:  cache builtin
-  db_home:  /home/%U
-  db_shell: /bin/bash
-  db_gecos: empty
 
 
 The 
/etc/nsswitch.conf syntax
@@ -1508,15 +1505,8 @@ of each schema when used with db_home:
 
 
 As has been briefly mentioned before, the default setting for
-db_home: is
-
-
-
-  db_home: /home/%U
-
-
-
-So by default, Cygwin just sets the home dir to
+db_home: defines no schemata, which means only the fallback
+option is used, so by default, Cygwin just sets the home dir to
 /home/$USERNAME.
 
 
@@ -1591,14 +1581,11 @@ when used with db_shell:
 
 
 As for db_home:, the default setting for
-db_shell: is pretty much a constant
+db_shell: defines no schemata, which means only the fallback
+option is used, so by default, Cygwin just sets the home dir to
+/bin/bash.
 
 
-
-  db_shell: /bin/bash
-
-
-
 
 
 
@@ -1664,13 +1651,13 @@ The following list describes the meaning of each schema 
when used with
   
 Fallback
 If none of the schemes given for db_gecos:
- define a non-empty pathname, nothing is added to
+ define a non-empty string, nothing is added to
  pw_gecos.
   
 
 
 
-The default setting for db_gecos: is the empty string.
+The default setting for db_gecos: defines no schemata.
 
 
 
-- 
2.26.1.windows.1



[PATCH 2/3 v2] Cygwin: accounts: Don't keep old schemes when parsing nsswitch.conf

2020-04-20 Thread David Macek via Cygwin-patches
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.

Signed-off-by: David Macek 
---
 winsup/cygwin/uinfo.cc | 7 +++
 winsup/doc/ntsec.xml   | 5 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 2d5fc488bb..b733a6ee87 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -790,12 +790,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;
@@ -826,7 +826,6 @@ cygheap_pwdgrp::nss_init_line (const char *line)
}
  c += strcspn (c, " \t");
  c += strspn (c, " \t");
- ++idx;
}
}
}
diff --git a/winsup/doc/ntsec.xml b/winsup/doc/ntsec.xml
index 032bebe4dc..b5996567f8 100644
--- a/winsup/doc/ntsec.xml
+++ b/winsup/doc/ntsec.xml
@@ -915,6 +915,11 @@ Apart from this restriction, the remainder of the line can 
have as
 many spaces and TABs as you like.
 
 
+
+When the same keyword occurs multiple times, the last one wins, as if the
+previous ones were ignored.
+
+
 
 
 The passwd: and 
group: settings
-- 
2.26.1.windows.1



[PATCH 3/3] Cygwin: accounts: Report unrecognized db_* nsswitch.conf keywords

2020-04-20 Thread David Macek via Cygwin-patches
Signed-off-by: David Macek 
---
 winsup/cygwin/uinfo.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index b733a6ee87..e105248c20 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -828,6 +828,8 @@ cygheap_pwdgrp::nss_init_line (const char *line)
  c += strspn (c, " \t");
}
}
+ else
+ debug_printf ("Invalid nsswitch.conf content: %s", line);
}
   break;
 case '\0':
-- 
2.26.1.windows.1



License declaration

2020-04-20 Thread David Macek via Cygwin-patches
Patches to the Cygwin sources sent by me are licensed under the
2-clause BSD license.  This applies to all past patches as well.

I'll try to add a Signed-off-by to each patch.

-- 
David Macek