Skip to content

Commit

Permalink
Respect the db_home: env setting under more circumstances
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Jan 7, 2016
1 parent 4c36272 commit dfe28f3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions winsup/cygwin/uinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ cygheap_pwdgrp::get_home (PUSER_INFO_3 ui, cygpsid &sid, PCWSTR dom,

for (uint16_t idx = 0; !home && idx < NSS_SCHEME_MAX; ++idx)
{
if (!ui && home_scheme[idx].method != NSS_SCHEME_ENV)
continue;
switch (home_scheme[idx].method)
{
case NSS_SCHEME_FALLBACK:
Expand Down Expand Up @@ -2075,6 +2077,9 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
{
/* Just some fake. */
sid = csid = "S-1-99-0";
if (arg.id == cygheap->user.real_uid)
home = cygheap->pg.get_home(NULL, cygheap->user.sid(),
NULL, NULL, false);
break;
}
else if (arg.id >= UNIX_POSIX_OFFSET)
Expand Down Expand Up @@ -2567,10 +2572,11 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
logon. Unless it's the SYSTEM account. This conveniently allows to
logon interactively as SYSTEM for debugging purposes. */
else if (acc_type != SidTypeUser && sid != well_known_system_sid)
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:/:/sbin/nologin",
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:%s:/sbin/nologin",
posix_name, uid, gid,
dom, name,
sid.string ((char *) sidstr));
sid.string ((char *) sidstr),
home ? home : "/");
else
__small_sprintf (linebuf, "%W:*:%u:%u:%s%sU-%W\\%W,%s:%s%W:%s",
posix_name, uid, gid,
Expand Down

0 comments on commit dfe28f3

Please sign in to comment.