summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/uinfo.cc
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-03-18 16:27:44 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-03-18 16:27:44 -0700
commitd00eca5a10a69be3ccabf0e165de98ab19ef25b2 (patch)
treebbe5bad8b471215e12c894c3fd837818a5fbb2c0 /winsup/cygwin/uinfo.cc
parent5bb41d641c4658b44e9a8a7047498a028cdc8bb1 (diff)
downloadcygnal-2.5.2.tar.gz
cygnal-2.5.2.tar.bz2
cygnal-2.5.2.zip
Use Windows values in passwd and HOME env var.cygnal-2.5.2
In this patch, the path to the Windows command interpreter is reported in the shell field of struct passwd by getpwent by default rather than "/bin/bash". The value of USERPROFILE is used for the home field rather than "/home/<user>". Also, the HOME environment variable is stuffed with a copy of USERPROFILE. The HOME issue solves the following problem: some OSS programs on Windows, such as Vim, respond to a HOME variable. If it has garbage contents that make no sense like "/home/bob", they don't behave well. * winsup/cygwin/grp.cc (pwdgrp::init_grp): Initialize new pwd_sep member. * winsup/cygwin/passwd.cc (pwdgrp::parse_passwd): Use pwd_sep rather than hard-coded colon. (pwdgrp::init_pwd): Initialize pwd_sep. * winsup/cygwin/pwdgrp.h (class pwdgrp): New member, pwd_sep. * winsup/cygwin/uinfo.cc (cygheap_user::ontherange): Copy value of USERPROFILE into HOME. (pwdgrp::next_num, pwdgrp::fetch_account_from_line): Use pwd_sep rather than ':'. (pwdgrp::next_num, pwdgrp::fetch_account_from_windows): Get real Windows shell as default shell field. Get USERPROFILE as home directory. Use '|' as the field separator because these fields contain colons. Set pwd_sep to '|'.
Diffstat (limited to 'winsup/cygwin/uinfo.cc')
-rw-r--r--winsup/cygwin/uinfo.cc30
1 files changed, 17 insertions, 13 deletions
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 323222a47..830ca9c97 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -377,11 +377,9 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
}
else
{
- char home[strlen (name ()) + 8];
-
- debug_printf ("Set HOME to default /home/USER");
- __small_sprintf (home, "/home/%s", name ());
- setenv ("HOME", home, 1);
+ char *usrpro = getenv("USERPROFILE");
+ if (usrpro)
+ setenv("HOME", usrpro, 1);
}
}
}
@@ -592,7 +590,7 @@ pwdgrp::next_str (char c)
bool
pwdgrp::next_num (unsigned long& n)
{
- char *p = next_str (':');
+ char *p = next_str (pwd_sep);
char *cp;
n = strtoul (p, &cp, 10);
return p != cp && !*cp;
@@ -1677,19 +1675,19 @@ pwdgrp::fetch_account_from_line (fetch_user_arg_t &arg, const char *line)
{
case SID_arg:
/* Ignore fields, just scan for SID string. */
- if (!(p = strstr (line, arg.name)) || p[arg.len] != ':')
+ if (!(p = strstr (line, arg.name)) || p[arg.len] != pwd_sep)
return NULL;
break;
case NAME_arg:
/* First field is always name. */
- if (!strncasematch (line, arg.name, arg.len) || line[arg.len] != ':')
+ if (!strncasematch (line, arg.name, arg.len) || line[arg.len] != pwd_sep)
return NULL;
break;
case ID_arg:
/* Skip to third field. */
- if (!(p = strchr (line, ':')) || !(p = strchr (p + 1, ':')))
+ if (!(p = strchr (line, pwd_sep)) || !(p = strchr (p + 1, pwd_sep)))
return NULL;
- if (strtoul (p + 1, &e, 10) != arg.id || !e || *e != ':')
+ if (strtoul (p + 1, &e, 10) != arg.id || !e || *e != pwd_sep)
return NULL;
break;
default:
@@ -2521,6 +2519,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
tmp_pathbuf tp;
char *linebuf = tp.c_get ();
char *line = NULL;
+ char *userprofile = getenv("USERPROFILE");
WCHAR posix_name[UNLEN + 1 + DNLEN + 1];
p = posix_name;
@@ -2530,6 +2529,8 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
p = wcpcpy (wcpcpy (p, dom), cygheap->pg.nss_separator ());
wcpcpy (p, name);
+ pwd_sep = ':';
+
if (is_group ())
__small_sprintf (linebuf, "%W:%s:%u:",
posix_name, sid.string ((char *) sidstr), uid);
@@ -2542,13 +2543,16 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
dom, name,
sid.string ((char *) sidstr));
else
- __small_sprintf (linebuf, "%W:*:%u:%u:%s%sU-%W\\%W,%s:%s%W:%s",
+ {
+ __small_sprintf (linebuf, "%W|*|%u|%u|%s%sU-%W\\%W,%s|%s|%s",
posix_name, uid, gid,
gecos ?: "", gecos ? "," : "",
dom, name,
sid.string ((char *) sidstr),
- home ?: "/home/", home ? L"" : name,
- shell ?: "/bin/bash");
+ home ? home : (userprofile ? userprofile : ""),
+ shell ?: get_cmd_exe_path());
+ pwd_sep = '|';
+ }
if (gecos)
free (gecos);
if (home)