diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-03-18 16:27:44 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-11-17 12:13:31 -0800 |
commit | ff499b8904af94ebae9c83e0f2b15afc120c9d75 (patch) | |
tree | 57498f34e65371ce80c908a66ad8675e532a94f7 /winsup | |
parent | 6900a42323bfe9a909deddb27126a5e4e997d979 (diff) | |
download | cygnal-ff499b8904af94ebae9c83e0f2b15afc120c9d75.tar.gz cygnal-ff499b8904af94ebae9c83e0f2b15afc120c9d75.tar.bz2 cygnal-ff499b8904af94ebae9c83e0f2b15afc120c9d75.zip |
Use Windows values in passwd and HOME env var.
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')
-rw-r--r-- | winsup/cygwin/grp.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/passwd.cc | 11 | ||||
-rw-r--r-- | winsup/cygwin/pwdgrp.h | 1 | ||||
-rw-r--r-- | winsup/cygwin/uinfo.cc | 30 |
4 files changed, 25 insertions, 18 deletions
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index d66acad99..40f85feec 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -57,6 +57,7 @@ pwdgrp::init_grp () { pwdgrp_buf_elem_size = sizeof (pg_grp); parse = &pwdgrp::parse_group; + pwd_sep = ':'; } struct group * diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index d2f7b2c2e..dfa90acb3 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -27,16 +27,16 @@ bool pwdgrp::parse_passwd () { pg_pwd &res = passwd ()[curr_lines]; - res.p.pw_name = next_str (':'); - res.p.pw_passwd = next_str (':'); + res.p.pw_name = next_str (pwd_sep); + res.p.pw_passwd = next_str (pwd_sep); if (!next_num (res.p.pw_uid)) return false; if (!next_num (res.p.pw_gid)) return false; res.p.pw_comment = NULL; - res.p.pw_gecos = next_str (':'); - res.p.pw_dir = next_str (':'); - res.p.pw_shell = next_str (':'); + res.p.pw_gecos = next_str (pwd_sep); + res.p.pw_dir = next_str (pwd_sep); + res.p.pw_shell = next_str (pwd_sep); cygsid csid; if (csid.getfrompw_gecos (&res.p)) RtlCopySid (SECURITY_MAX_SID_SIZE, res.sid, csid); @@ -51,6 +51,7 @@ pwdgrp::init_pwd () { pwdgrp_buf_elem_size = sizeof (pg_pwd); parse = &pwdgrp::parse_passwd; + pwd_sep = ':'; } struct passwd * diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index 0705f7528..639773683 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -63,6 +63,7 @@ class pwdgrp unsigned pwdgrp_buf_elem_size; void *pwdgrp_buf; bool (pwdgrp::*parse) (); + char pwd_sep; UNICODE_STRING path; OBJECT_ATTRIBUTES attr; LARGE_INTEGER last_modified; diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 1a2a6aa40..a084af743 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; @@ -1710,19 +1708,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: @@ -2629,6 +2627,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; @@ -2638,6 +2637,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); @@ -2650,13 +2651,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) |