acadia-newlib/winsup/cygwin
Johannes Schindelin 80ff7bc26c Do not rely on `getenv ("HOME")`'s path conversion
In the very early code path where `dll_crt0_1 ()` calls
`user_shared->initialize ()`, the Cygwin runtime calls `internal_pwsid ()`
to initialize the user name in preparation for reading the `fstab` file.

In case `db_home: env` is defined in `/etc/nsswitch.conf`, we need to
look at the environment variable `HOME` and use it, if set.

When all of this happens, though, the `pinfo_init ()` function has had no
chance to run yet (and therefore, `environ_init ()`). At this stage,
therefore, `getenv ()`'s `findenv_func ()` call still finds `getearly ()`
and we get the _verbatim_ value of `HOME`. That is, the Windows form.
But we need the "POSIX" form.

To add insult to injury, later calls to `getpwuid (getuid ())` will
receive a cached version of the home directory via
`cygheap->pg.pwd_cache.win.find_user ()` thanks to the first
`internal_pwsid ()` call caching the result via
`add_user_from_cygserver ()`, read: we will never receive the converted
`HOME` but always the Windows variant.

So, contrary to the assumptions made in 27376c60a9 (Allow deriving the
current user's home directory via the HOME variable, 2023-03-28), we
cannot assume that `getenv ("HOME")` returned a "POSIX" path.

This is a real problem. Even setting aside that common callers of
`getpwuid ()` (such as OpenSSH) are unable to handle Windows paths in the
`pw_dir` attribute, the Windows path never makes it back to the caller
unscathed. The value returned from `fetch_home_env ()` is not actually
used as-is. Instead, the `fetch_account_from_windows ()` method uses it
to write a pseudo `/etc/passwd`-formatted line that is _then_ parsed via
the `pwdgrp::parse_passwd ()` method which sees no problem with
misinterpreting the colon after the drive letter as a field separator of
that `/etc/passwd`-formatted line, and instead of a Windows path, we now
have a mere drive letter.

Let's detect when the `HOME` value is still in Windows format in
`fetch_home_env ()`, and convert it in that case.

For good measure, interpret this "Windows format" not only to include
absolute paths with drive prefixes, but also UNC paths.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-06-06 15:18:53 +02:00
..
DevDocs Cygwin: testsuite: Add x86_64 code to "dynamically load cygwin" test 2022-08-29 17:53:48 +01:00
fhandler Cygwin: pty: Additional fix for transferring input at exit. 2023-06-02 10:19:18 +09:00
include Cygwin: replace regex with latest verbatim FreeBSD version 2023-03-16 11:12:08 +01:00
lib Cygwin: drop __stdcall usage 2022-08-04 20:54:09 +02:00
libc Cygwin: fnmatch: support collating symbols in [. .] brackets 2023-03-01 10:54:52 +01:00
linux-locale-helpers Cygwin: fetch-lc-def-codesets-from-linux: fix locale name handling 2023-02-26 20:14:54 +01:00
local_includes Cygwin: Fix compiling with w32api-headers v11.0.0 2023-05-01 11:40:52 +01:00
math Cygwin: fix return value of ilogbl(NaN) 2023-04-18 13:43:06 +02:00
mm Cygwin: cygheap: fix fork error after heap has grown 2023-04-18 10:06:53 +02:00
regex Cygwin: regex: fix faulty check for valid range expression 2023-03-20 12:58:03 +01:00
release Cygwin: posix_spawnp: don't fallback to sh 2023-04-19 21:08:48 +02:00
scripts Cygwin: Run testsuite against the just-built DLL 2023-01-10 10:27:13 +00:00
sec Cygwin: get_posix_access: Make mode_t parameter mandatory 2023-02-09 21:58:44 +01:00
tzcode winsup: delete old _LIBC logic 2021-11-10 20:16:15 -05:00
x86_64 Cygwin: x86_64: import swab.S from NetBSD 2022-12-20 10:19:23 +01:00
Makefile.am Cygwin: Makefile.am: fix rule to create version from git describe 2023-02-15 15:04:16 +01:00
advapi32.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
aio.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
assert.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
autoload.cc Cygwin: autoload: clean up arguments to LoadDllFunc* 2023-01-17 16:32:14 +01:00
automode.c Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
binmode.c Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
clock.cc Cygwin: drop wincap::has_precise_system_time 2022-12-04 14:01:41 +01:00
config.h.in Cygwin: Use automake (v5) 2021-04-27 16:49:56 +01:00
create_posix_thread.cc Cygwin: add memory_layout.h 2022-10-28 16:26:53 +02:00
crt0.c Cygwin: drop 32 bit considerations in crt0 code 2022-05-16 18:17:06 +02:00
ctype.cc Cygwin: fully support KOI8-T codeset 2023-02-25 16:12:51 +01:00
cxx.cc cxx.cc: Fix dynamic initialization for static local variables 2021-01-18 12:22:53 +01:00
cygthread.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
cygtls.cc Cygwin: tls_pathbuf: Use Windows heap 2022-08-23 12:09:44 +02:00
cygwait.cc Ensure nanosleep(2) never returns negative rem 2021-07-22 09:57:40 +02:00
cygwin.din Cygwin: Export posix_spawn_file_actions_add{f}chdir_np 2023-04-19 00:34:36 +02:00
cygwin.ldif
cygwin.sc.in Cygwin: drop objcopy .gnu_debuglink juggle 2022-10-28 16:26:53 +02:00
cygxdr.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
dcrt0.cc Cygwin: cygheap: Initialize myself_pinfo before child_copy(). 2023-01-10 21:04:29 +09:00
debug.cc Cygwin: debugging: convert muto to SRWLOCK 2022-08-22 14:38:49 +02:00
devices.cc Cygwin: tape: tapes are character devices, not block devices 2023-01-21 18:25:56 +01:00
devices.in Cygwin: tape: tapes are character devices, not block devices 2023-01-21 18:25:56 +01:00
dir.cc change _COMPILING_NEWLIB to _LIBC 2021-11-15 19:32:23 -05:00
dlfcn.cc Cygwin: remove miscellaneous 32-bit code 2022-05-29 17:54:32 -04:00
dll_init.cc Cygwin: remove most occurrences of __stdcall and __cdecl 2022-06-06 12:00:45 -04:00
dtable.cc Cygwin: ctty: Remove old 'kludge' code. 2023-03-07 10:51:44 +09:00
environ.cc Cygwin: drop macro and code for CYGWIN_VERSION_DLL_MALLOC_ENV 2022-08-03 15:35:34 +02:00
errno.cc Cygwin: create sparse errmap array 2022-08-04 15:16:48 +02:00
exceptions.cc Cygwin: ctty: Replace ctty constant with more descriptive macros. 2023-03-07 10:51:29 +09:00
exec.cc Cygwin: rename __cygwin_environ and drop env redirection via cur_environ() 2022-07-28 22:00:40 +02:00
external.cc Cygwin: ctty: Replace ctty constant with more descriptive macros. 2023-03-07 10:51:29 +09:00
fcntl.cc Cygwin: simplify some function names 2022-05-29 17:45:52 -04:00
fenv.c Cygwin: don't export _feinitialise from newlib 2021-04-13 12:55:34 +02:00
flock.cc Cygwin: flock: drop checking for artificial console handles 2022-12-04 14:01:41 +01:00
fork.cc Cygwin: fork: fix a potential hang in fork 2022-08-29 12:25:24 +02:00
forkable.cc Cygwin: unlink: drop unlink_nt/unlink_nt_shareable wrappers 2023-03-20 12:55:30 +01:00
gcrt0.c Revert "sys/types.h: Don't include sys/_stdint.h" 2022-05-04 15:08:44 +02:00
glob.cc Cygwin: glob: fix conversion from UTF-32 to multibyte 2023-03-03 18:19:17 +01:00
glob_pattern_p.cc
globals.cc Cygwin: convert __collate_range_cmp to __wcollate_range_cmp 2023-02-19 14:40:29 +01:00
gmon.c Cygwin: Zero out gmon header before use 2021-06-26 15:24:27 +01:00
grp.cc Cygwin: simplify some function names 2022-05-29 17:45:52 -04:00
hookapi.cc Cygwin: Fix previous attempt to drop i386 targets from hookapi 2022-07-28 16:38:01 +02:00
init.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
ioctl.cc Cygwin: open: support Linux-specific O_PATH flag 2019-01-07 19:35:00 +01:00
ipc.cc Cygwin: simplify some function names 2022-05-29 17:45:52 -04:00
kernel32.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
ldap.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
libstdcxx_wrapper.cc Cygwin: remove miscellaneous 32-bit code 2022-05-29 17:54:32 -04:00
loadavg.cc Cygwin: loadavg: improve debugging of load_init 2019-03-12 17:09:42 +01:00
lsearch.cc
mcount.c
miscfuncs.cc Cygwin: rename CygwinCreateThread to create_posix_thread 2022-08-10 18:06:28 +02:00
mktemp.cc Cygwin: simplify some function names 2022-05-29 17:45:52 -04:00
mount.cc Cygwin: fs_info::update: fix NTFS filesystem flags 2023-03-21 18:02:49 +01:00
msg.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
net.cc Cygwin: net.cc: convert wsock_errmap into a simple array of error codes 2022-08-04 11:45:58 +02:00
netdb.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
nfs.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
nlsfuncs.cc Cygwin: locales: drop unused has_modifier macro 2023-04-24 22:41:41 +02:00
ntea.cc Cygwin: remove most occurrences of __stdcall and __cdecl 2022-06-06 12:00:45 -04:00
passwd.cc Cygwin: simplify some function names 2022-05-29 17:45:52 -04:00
path.cc Cygwin: Adjust CWD magic to accommodate for the latest Windows previews 2023-05-24 20:44:52 +01:00
pinfo.cc Cygwin: ctty: Replace ctty constant with more descriptive macros. 2023-03-07 10:51:29 +09:00
poll.cc Cygwin: poll: Fix a bug on inquiring same fd with different events. 2022-06-27 10:54:24 +09:00
posix_ipc.cc Cygwin: move POSIX semaphore API functions to posix_ipc.cc 2022-08-10 18:11:57 +02:00
posix_timer.cc Cygwin: posix_timer: fix formatting 2022-08-22 14:53:30 +02:00
profil.c Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
pseudo-reloc.cc Cygwin: drop macro and code for CYGWIN_VERSION_USE_PSEUDO_RELOC_IN_DLL 2022-08-03 16:01:29 +02:00
quotactl.cc Cygwin: Add 'fallthrough' pseudo keyword for switch/case use 2020-08-05 21:58:22 +02:00
random.cc Cygwin: add missing pragma 2022-12-07 21:18:24 +01:00
registry.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
resource.cc Cygwin: fix a few comments mentioning Windows 7 or 8 2022-12-04 14:01:41 +01:00
scandir.cc cygwin: export strverscmp, add versionsort 2017-06-19 08:16:42 -05:00
sched.cc Cygwin: drop support for systems not supporting processor groups 2021-10-29 18:19:45 +02:00
select.cc Cygwin: console: Make the console accessible from other terminals. 2022-12-22 21:05:31 +09:00
sem.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
setlsapwd.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
shm.cc Cygwin: shm: Convert muto into SRWLOCK and avoid overlocking 2022-08-22 14:28:11 +02:00
signal.cc Cygwin: remove regparm.h 2022-05-29 17:45:52 -04:00
sigproc.cc Cygwin: /proc/<PID>/status: avoid crash computing signal info 2023-01-10 11:48:02 +01:00
smallprint.cc Cygwin: smallprint.cc: Drop HEAP_ZERO_MEMORY 2022-08-22 17:58:53 +02:00
spawn.cc Cygwin: posix_spawnp: don't fallback to sh 2023-04-19 21:08:48 +02:00
strace.cc Cygwin: remove most occurrences of __stdcall and __cdecl 2022-06-06 12:00:45 -04:00
strfuncs.cc Cygwin: mbrtowi: fix segfault when pwi is NULL 2023-04-19 10:14:46 +02:00
strsep.cc Cygwin: C++17: register keyword is deprecated 2021-08-26 22:14:11 +02:00
strsig.cc Cygwin: signals: drop accidental spaces from real-time signal names 2023-03-15 21:44:52 +01:00
sync.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
syscalls.cc Cygwin: align renameat2 to Linux behaviour 2023-04-18 18:18:27 +02:00
sysconf.cc Cygwin: remove miscellaneous 32-bit code 2022-05-29 17:54:32 -04:00
syslog.cc Fix a problem that connection to syslogd fails. 2018-07-06 10:41:21 +02:00
termios.cc Cygwin: drop macro and code for CYGWIN_VERSION_DLL_IS_OLD_TERMIOS 2022-08-03 15:35:29 +02:00
textmode.c Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
textreadmode.c Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
thread.cc Cygwin: move POSIX semaphore API functions to posix_ipc.cc 2022-08-10 18:11:57 +02:00
timerfd.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
times.cc Cygwin: drop wincap::has_precise_system_time 2022-12-04 14:01:41 +01:00
tls_pbuf.cc Cygwin: tls_pathbuf: Use Windows heap 2022-08-23 12:09:44 +02:00
tty.cc Cygwin: ctty: Replace ctty constant with more descriptive macros. 2023-03-07 10:51:29 +09:00
uinfo.cc Do not rely on `getenv ("HOME")`'s path conversion 2023-06-06 15:18:53 +02:00
uname.cc Cygwin: uname: fix building in non-git source dir 2022-12-07 22:22:38 +01:00
wait.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
wincap.cc Cygwin: wincap: make capability flags readonly 2023-01-12 10:34:32 +01:00
window.cc Cygwin: drop all usages of WINAPI 2022-08-04 22:13:59 +02:00
winf.cc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00
winver.rc Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option 2016-06-23 10:09:17 +02:00