diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-03-18 16:27:44 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-07-26 21:52:26 -0700 |
commit | c7b78aaeec9b6136066634d8234a41fbd129b8fe (patch) | |
tree | cfc8599250fdd56793721737c06a78fcaa128cd4 | |
parent | f11bd3f1d7bc314f90a3fa7b48d2241c48bf2ccd (diff) | |
download | cygnal-c7b78aaeec9b6136066634d8234a41fbd129b8fe.tar.gz cygnal-c7b78aaeec9b6136066634d8234a41fbd129b8fe.tar.bz2 cygnal-c7b78aaeec9b6136066634d8234a41fbd129b8fe.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 '|'.
-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 23e2d0251..f2e6237a4 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 1d6757b37..656ba392a 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 8f3ef3adb..3cc10c9ad 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 c0a0f6163..cba7f9e7b 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; @@ -1706,19 +1704,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: @@ -2756,6 +2754,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; @@ -2765,6 +2764,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); @@ -2777,13 +2778,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) |