Skip to content

Commit 99f447b

Browse files
committed
Respect the db_home: env setting under more circumstances
In particular when we cannot figure out a uid for the current user, we should still respect the `db_home: env` setting. Such a situation occurs for example when the domain returned by `LookupAccountSid()` is not our machine name and at the same time our machine is no domain member: In that case, we have nobody to ask for the POSIX offset necessary to come up with the uid. It is important that even in such cases, the HOME environment variable can be used to override the home directory, e.g. when Git for Windows is used by an account that was generated on the fly, e.g. for transient use in a cloud scenario. Reported by David Ebbo. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 1dedd07 commit 99f447b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

winsup/cygwin/uinfo.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,8 @@ cygheap_pwdgrp::get_home (PUSER_INFO_3 ui, cygpsid &sid, PCWSTR dom,
11211121

11221122
for (uint16_t idx = 0; !home && idx < NSS_SCHEME_MAX; ++idx)
11231123
{
1124+
if (!ui && home_scheme[idx].method != NSS_SCHEME_ENV)
1125+
continue;
11241126
switch (home_scheme[idx].method)
11251127
{
11261128
case NSS_SCHEME_FALLBACK:
@@ -2111,6 +2113,9 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
21112113
{
21122114
/* Just some fake. */
21132115
sid = csid.create (99, 1, 0);
2116+
if (arg.id == cygheap->user.real_uid)
2117+
home = cygheap->pg.get_home(NULL, cygheap->user.sid(),
2118+
NULL, NULL, false);
21142119
break;
21152120
}
21162121
else if (arg.id >= UNIX_POSIX_OFFSET)
@@ -2601,10 +2606,11 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
26012606
logon. Unless it's the SYSTEM account. This conveniently allows to
26022607
logon interactively as SYSTEM for debugging purposes. */
26032608
else if (acc_type != SidTypeUser && sid != well_known_system_sid)
2604-
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:/:/sbin/nologin",
2609+
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:%s:/sbin/nologin",
26052610
posix_name, uid, gid,
26062611
dom, name,
2607-
sid.string ((char *) sidstr));
2612+
sid.string ((char *) sidstr),
2613+
home ? home : "/");
26082614
else
26092615
__small_sprintf (linebuf, "%W:*:%u:%u:%s%sU-%W\\%W,%s:%s%W:%s",
26102616
posix_name, uid, gid,

0 commit comments

Comments
 (0)