Skip to content

Commit 4935495

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 90d8aad commit 4935495

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
@@ -1094,6 +1094,8 @@ cygheap_pwdgrp::get_home (PUSER_INFO_3 ui, cygpsid &sid, PCWSTR dom,
10941094

10951095
for (uint16_t idx = 0; !home && idx < NSS_SCHEME_MAX; ++idx)
10961096
{
1097+
if (!ui && home_scheme[idx].method != NSS_SCHEME_ENV)
1098+
continue;
10971099
switch (home_scheme[idx].method)
10981100
{
10991101
case NSS_SCHEME_FALLBACK:
@@ -2254,6 +2256,9 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
22542256
{
22552257
/* Just some fake. */
22562258
sid = csid.create (99, 1, 0);
2259+
if (arg.id == cygheap->user.real_uid)
2260+
home = cygheap->pg.get_home(NULL, cygheap->user.sid(),
2261+
NULL, NULL, false);
22572262
break;
22582263
}
22592264
else if (arg.id >= UNIX_POSIX_OFFSET)
@@ -2814,10 +2819,11 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
28142819
logon. Unless it's the SYSTEM account. This conveniently allows to
28152820
logon interactively as SYSTEM for debugging purposes. */
28162821
else if (acc_type != SidTypeUser && sid != well_known_system_sid)
2817-
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:/:/sbin/nologin",
2822+
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:%s:/sbin/nologin",
28182823
posix_name, uid, gid,
28192824
dom, name,
2820-
sid.string ((char *) sidstr));
2825+
sid.string ((char *) sidstr),
2826+
home ? home : "/");
28212827
else
28222828
__small_sprintf (linebuf, "%W:*:%u:%u:%s%sU-%W\\%W,%s:%s%W:%s",
28232829
posix_name, uid, gid,

0 commit comments

Comments
 (0)