* shared.cc (user_shared_initialize): Fetch potentially changed Cygwin

username from /etc/passwd before loading mount table.
	(shared_info::init_installation_root): New function fetching Cygwin's
	installation root dir and storing as native NT path in global shared
	memory.
	(shared_info::initialize): Call init_installation_root exactly once at
	first startup.
	* shared_info.h (SHARED_INFO_CB): Accommodate change to shared_info.
	(CURR_SHARED_MAGIC): Ditto.
	(class shared_info): Add installation_root member.
	(shared_info::init_installation_root): Declare.

	* grp.cc (pwdgrp::read_group): Call pwdgrp::load with native WCHAR path.
	* passwd.cc (pwdgrp::read_passwd): Ditto.  Avoid recursion.
	(etc::init): Take POBJECT_ATTRIBUTES instead of path_conv.
	* path.h (etc::init): Change prototype accordingly.
	* pwdgrp.h (class pwdgrp): Store path as UNICODE_STRING/PWCHAR instead
	of as path_conv.
	(pwdgrp::load): Accommodate prototype.
	* uinfo.cc (pwdgrp::load): Change argument type from char to wchar_t.
	Create native NT path here instead of calling path_conv.

	* mount.cc (find_root_from_cygwin_dll): Drop in favor of global
	initializaion in shared_info.
	(mount_info::init): Fetch native NT root dir from cygwin_shared.
	(mount_info::from_fstab): Expect native NT path and use native NT
	functions to access file.  Convert username part in user fstab path
	according to special char transformation rules.
	* path.cc (tfx_chars): Convert slash to backslash.
	(transform_chars): Implement for path given as PWCHAR.
	(transform_chars): PUNICODE_STRING version calls PWCHAR version.
	Remove useless commented code.
This commit is contained in:
Corinna Vinschen
2008-07-24 18:25:52 +00:00
parent 410c1d122d
commit 520fcc9747
10 changed files with 170 additions and 90 deletions

View File

@@ -13,6 +13,7 @@ details. */
#include <unistd.h>
#include <wininet.h>
#include <stdlib.h>
#include <wchar.h>
#include <lm.h>
#include <iptypes.h>
#include <sys/cygwin.h>
@@ -22,6 +23,7 @@ details. */
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include "shared_info.h"
#include "registry.h"
#include "child_info.h"
#include "environ.h"
@@ -508,7 +510,7 @@ pwdgrp::add_line (char *eptr)
}
void
pwdgrp::load (const char *posix_fname)
pwdgrp::load (const wchar_t *rel_path)
{
static const char failed[] = "failed";
static const char succeeded[] = "succeeded";
@@ -526,23 +528,26 @@ pwdgrp::load (const char *posix_fname)
buf = NULL;
curr_lines = 0;
pc.check (posix_fname);
etc_ix = etc::init (etc_ix, pc);
paranoid_printf ("%s", posix_fname);
if (pc.error || !pc.exists () || pc.isdir ())
if (!path &&
!(path = (PWCHAR) malloc ((wcslen (cygwin_shared->installation_root)
+ wcslen (rel_path) + 1) * sizeof (WCHAR))))
{
paranoid_printf ("strange path_conv problem");
paranoid_printf ("malloc (%W) failed", rel_path);
goto out;
}
status = NtOpenFile (&fh, FILE_READ_DATA,
pc.get_object_attr (attr, sec_none_nih), &io,
wcpcpy (wcpcpy (path, cygwin_shared->installation_root), rel_path);
RtlInitUnicodeString (&upath, path);
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL);
etc_ix = etc::init (etc_ix, &attr);
paranoid_printf ("%S", &upath);
status = NtOpenFile (&fh, FILE_READ_DATA, &attr, &io,
FILE_SHARE_VALID_FLAGS, 0);
if (!NT_SUCCESS (status))
{
paranoid_printf ("NtOpenFile(%S) failed, status %p",
pc.get_nt_native_path (), status);
paranoid_printf ("NtOpenFile(%S) failed, status %p", &upath, status);
goto out;
}
status = NtQueryInformationFile (fh, &io, &fsi, sizeof fsi,
@@ -550,7 +555,7 @@ pwdgrp::load (const char *posix_fname)
if (!NT_SUCCESS (status))
{
paranoid_printf ("NtQueryInformationFile(%S) failed, status %p",
pc.get_nt_native_path (), status);
&upath, status);
goto out;
}
/* FIXME: Should we test for HighPart set? If so, the
@@ -567,8 +572,7 @@ pwdgrp::load (const char *posix_fname)
fsi.EndOfFile.LowPart, &off, NULL);
if (!NT_SUCCESS (status))
{
paranoid_printf ("NtReadFile(%S) failed, status %p",
pc.get_nt_native_path (), status);
paranoid_printf ("NtReadFile(%S) failed, status %p", &upath, status);
free (buf);
goto out;
}
@@ -576,12 +580,12 @@ pwdgrp::load (const char *posix_fname)
char *eptr = buf;
while ((eptr = add_line (eptr)))
continue;
debug_printf ("%s curr_lines %d", posix_fname, curr_lines);
debug_printf ("%W curr_lines %d", rel_path, curr_lines);
res = succeeded;
out:
if (fh)
NtClose (fh);
debug_printf ("%s load %s", posix_fname, res);
debug_printf ("%W load %s", rel_path, res);
initialized = true;
}