Skip to content

Commit 6354d7a

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 <[email protected]>
1 parent 6b1da1a commit 6354d7a

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

11111111
for (uint16_t idx = 0; !home && idx < NSS_SCHEME_MAX; ++idx)
11121112
{
1113+
if (!ui && home_scheme[idx].method != NSS_SCHEME_ENV)
1114+
continue;
11131115
switch (home_scheme[idx].method)
11141116
{
11151117
case NSS_SCHEME_FALLBACK:
@@ -2169,6 +2171,9 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
21692171
{
21702172
/* Just some fake. */
21712173
sid = csid.create (99, 1, 0);
2174+
if (arg.id == cygheap->user.real_uid)
2175+
home = cygheap->pg.get_home(NULL, cygheap->user.sid(),
2176+
NULL, NULL, false);
21722177
break;
21732178
}
21742179
else if (arg.id >= UNIX_POSIX_OFFSET)
@@ -2698,10 +2703,11 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
26982703
logon. Unless it's the SYSTEM account. This conveniently allows to
26992704
logon interactively as SYSTEM for debugging purposes. */
27002705
else if (acc_type != SidTypeUser && sid != well_known_system_sid)
2701-
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:/:/sbin/nologin",
2706+
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:%s:/sbin/nologin",
27022707
posix_name, uid, gid,
27032708
dom, name,
2704-
sid.string ((char *) sidstr));
2709+
sid.string ((char *) sidstr),
2710+
home ? home : "/");
27052711
else
27062712
__small_sprintf (linebuf, "%W:*:%u:%u:%s%sU-%W\\%W,%s:%s%W:%s",
27072713
posix_name, uid, gid,

0 commit comments

Comments
 (0)