* cygheap.cc (cwcsdup): New function.

(cwcsdup1): New function.
	* cygheap.h (cygheap_user::get_windows_id): New method returning PWCHAR.
	(cwcsdup): Declare.
	(cwcsdup1): Declare.
	* registry.cc (get_registry_hive_path): Use WCHAR instead of char
	throughout.
	(load_registry_hive): Ditto.
	* registry.h (get_registry_hive_path): Change declaration accordingly.
	(load_registry_hive): Ditto.
	* sec_helper.cc (cygpsid::string): New method returning PWCHAR.
	* security.h (cygpsid::string): Declare.
	* syscalls.cc (seteuid32): Convert local name var to WCHAR.
	* uinfo.cc (cygheap_user::env_userprofile): Convert local name buffers
	to WCHAR.  Call sys_wcstombs_alloc to generate puserprof buffer.

	* winsup.h: Fix comment.
	(NT_MAX_PATH): New definition for maximum internal path length.
	Use throughout where appropriate.
	* include/limits.h (PATH_MAX): Set to 4096 as on Linux.
This commit is contained in:
Corinna Vinschen 2008-02-14 16:47:11 +00:00
parent f16db7f54e
commit 7b4b41ab3e
23 changed files with 138 additions and 60 deletions

View File

@ -1,3 +1,26 @@
2008-02-14 Corinna Vinschen <corinna@vinschen.de>
* cygheap.cc (cwcsdup): New function.
(cwcsdup1): New function.
* cygheap.h (cygheap_user::get_windows_id): New method returning PWCHAR.
(cwcsdup): Declare.
(cwcsdup1): Declare.
* registry.cc (get_registry_hive_path): Use WCHAR instead of char
throughout.
(load_registry_hive): Ditto.
* registry.h (get_registry_hive_path): Change declaration accordingly.
(load_registry_hive): Ditto.
* sec_helper.cc (cygpsid::string): New method returning PWCHAR.
* security.h (cygpsid::string): Declare.
* syscalls.cc (seteuid32): Convert local name var to WCHAR.
* uinfo.cc (cygheap_user::env_userprofile): Convert local name buffers
to WCHAR. Call sys_wcstombs_alloc to generate puserprof buffer.
* winsup.h: Fix comment.
(NT_MAX_PATH): New definition for maximum internal path length.
Use throughout where appropriate.
* include/limits.h (PATH_MAX): Set to 4096 as on Linux.
2008-02-13 Christopher Faylor <me+cygwin@cgf.cx>
* configure.in: Remove non-working options.

View File

@ -24,6 +24,7 @@
#include "sigproc.h"
#include "pinfo.h"
#include <unistd.h>
#include <wchar.h>
init_cygheap NO_COPY *cygheap;
void NO_COPY *cygheap_max;
@ -354,6 +355,30 @@ ccalloc_abort (cygheap_types x, DWORD n, DWORD size)
return ccalloc (x, n, size, "ccalloc");
}
extern "C" PWCHAR __stdcall
cwcsdup (const PWCHAR s)
{
MALLOC_CHECK;
PWCHAR p = (PWCHAR) cmalloc (HEAP_STR, wcslen (s) + 1);
if (!p)
return NULL;
wcpcpy (p, s);
MALLOC_CHECK;
return p;
}
extern "C" PWCHAR __stdcall
cwcsdup1 (const PWCHAR s)
{
MALLOC_CHECK;
PWCHAR p = (PWCHAR) cmalloc (HEAP_1_STR, wcslen (s) + 1);
if (!p)
return NULL;
wcpcpy (p, s);
MALLOC_CHECK;
return p;
}
extern "C" char *__stdcall
cstrdup (const char *s)
{

View File

@ -206,7 +206,11 @@ public:
if (internal_token != NO_IMPERSONATION)
CloseHandle (internal_token);
}
char * get_windows_id (char * buf)
PWCHAR get_windows_id (PWCHAR buf)
{
return effec_cygsid.string (buf);
}
char *get_windows_id (char *buf)
{
return effec_cygsid.string (buf);
}
@ -231,7 +235,7 @@ struct cwdstuff
DWORD get_drive (char * dst)
{
cwd_lock.acquire ();
DWORD ret = sys_wcstombs (dst, PATH_MAX, win32.Buffer, drive_length);
DWORD ret = sys_wcstombs (dst, NT_MAX_PATH, win32.Buffer, drive_length);
cwd_lock.release ();
return ret;
}
@ -423,6 +427,8 @@ void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)
void *__stdcall cmalloc_abort (cygheap_types, DWORD) __attribute__ ((regparm(2)));
void *__stdcall crealloc_abort (void *, DWORD) __attribute__ ((regparm(2)));
void *__stdcall ccalloc_abort (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
PWCHAR __stdcall cwcsdup (const PWCHAR) __attribute__ ((regparm(1)));
PWCHAR __stdcall cwcsdup1 (const PWCHAR) __attribute__ ((regparm(1)));
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
void __stdcall cfree_and_set (char *&, char * = NULL) __attribute__ ((regparm(2)));

View File

@ -544,7 +544,7 @@ break_here ()
static void
initial_env ()
{
char buf[PATH_MAX];
char buf[NT_MAX_PATH];
if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1))
_cygwin_testing = 1;
@ -561,8 +561,8 @@ initial_env ()
}
if (GetEnvironmentVariable ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
{
char buf1[PATH_MAX];
len = GetModuleFileName (NULL, buf1, PATH_MAX);
char buf1[NT_MAX_PATH];
len = GetModuleFileName (NULL, buf1, NT_MAX_PATH);
strlwr (buf1);
strlwr (buf);
char *p = strpbrk (buf, ":=");
@ -870,7 +870,7 @@ dll_crt0_1 (void *)
win32 style. */
if ((strchr (__argv[0], ':')) || (strchr (__argv[0], '\\')))
{
char *new_argv0 = (char *) malloc (PATH_MAX);
char *new_argv0 = (char *) malloc (NT_MAX_PATH);
cygwin_conv_to_posix_path (__argv[0], new_argv0);
__argv[0] = (char *) realloc (new_argv0, strlen (new_argv0) + 1);
}

View File

@ -106,7 +106,7 @@ dll_list::operator[] (const char *name)
dll *
dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
{
char name[PATH_MAX];
char name[NT_MAX_PATH];
DWORD namelen = GetModuleFileName (h, name, sizeof (name));
/* Already loaded? */

View File

@ -51,7 +51,7 @@ struct dll
int count;
dll_type type;
int namelen;
char name[PATH_MAX];
char name[NT_MAX_PATH];
void detach ();
int init ();
};

View File

@ -116,7 +116,7 @@ win_env::add_cache (const char *in_posix, const char *in_native)
}
else
{
char buf[PATH_MAX];
char buf[NT_MAX_PATH];
strcpy (buf, name + namelen);
towin32 (in_posix, buf);
native = (char *) realloc (native, namelen + 1 + strlen (buf));
@ -185,7 +185,7 @@ posify (char **here, const char *value)
/* Turn all the items from c:<foo>;<bar> into their
mounted equivalents - if there is one. */
char outenv[1 + len + PATH_MAX];
char outenv[1 + len + NT_MAX_PATH];
memcpy (outenv, src, len);
char *newvalue = outenv + len;
if (!conv->toposix (value, newvalue) || _impure_ptr->_errno != EIDRM)

View File

@ -35,7 +35,7 @@ details. */
#define CALL_HANDLER_RETRY 20
char debugger_command[2 * PATH_MAX + 20];
char debugger_command[2 * NT_MAX_PATH + 20];
extern "C" {
extern void sigdelayed ();
@ -118,8 +118,8 @@ error_start_init (const char *buf)
return;
}
char pgm[PATH_MAX];
if (!GetModuleFileName (NULL, pgm, PATH_MAX))
char pgm[NT_MAX_PATH];
if (!GetModuleFileName (NULL, pgm, NT_MAX_PATH))
strcpy (pgm, "cygwin1.dll");
for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\'))
*p = '/';

View File

@ -442,7 +442,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_EXENAME:
case PROCESS_EXE:
{
filebuf = (char *) crealloc_abort (filebuf, bufalloc = PATH_MAX);
filebuf = (char *) crealloc_abort (filebuf, bufalloc = NT_MAX_PATH);
if (p->process_state & PID_EXITED)
strcpy (filebuf, "<defunct>");
else
@ -524,8 +524,8 @@ format_process_maps (_pinfo *p, char *&destbuf, size_t maxsize)
DWORD_PTR wset_size;
DWORD_PTR *workingset = NULL;
MODULEINFO info;
WCHAR modname[PATH_MAX];
char posix_modname[PATH_MAX];
WCHAR modname[NT_MAX_PATH];
char posix_modname[NT_MAX_PATH];
if (!EnumProcessModules (proc, NULL, 0, &needed))
{
@ -557,7 +557,7 @@ format_process_maps (_pinfo *p, char *&destbuf, size_t maxsize)
strcpy (access, "r--p");
struct __stat64 st;
if (mount_table->conv_to_posix_path (modname, posix_modname, 0))
sys_wcstombs (posix_modname, PATH_MAX, modname);
sys_wcstombs (posix_modname, NT_MAX_PATH, modname);
if (stat64 (posix_modname, &st))
{
st.st_dev = 0;

View File

@ -321,10 +321,11 @@ details. */
#undef NAME_MAX
#define NAME_MAX 255
/* Maximum length of a path including trailing NUL.
(32767 - max. native NT path prefix) */
/* Maximum length of a path given to API functions including trailing NUL.
Deliberately set to the same default value as on Linux. Internal paths
may be longer. */
#undef PATH_MAX
#define PATH_MAX 32760
#define PATH_MAX 4096
/* # of bytes in a pipe buf. This is the max # of bytes which can be
written to a pipe in one atomic operation. */

View File

@ -266,7 +266,7 @@ struct external_pinfo
__gid32_t gid32;
/* Only available if version >= EXTERNAL_PINFO_VERSION_32_LP */
char progname_long[PATH_MAX];
char progname_long[NT_MAX_PATH];
};
#endif /*__CYGWIN__*/
#endif /*WINVER*/

View File

@ -2002,8 +2002,8 @@ mount_info::conv_to_posix_path (PWCHAR src_path, char *posix_path,
changed = true;
}
}
char buf[PATH_MAX];
sys_wcstombs (buf, PATH_MAX, src_path);
char buf[NT_MAX_PATH];
sys_wcstombs (buf, NT_MAX_PATH, src_path);
int ret = conv_to_posix_path (buf, posix_path, keep_rel_p);
if (changed)
src_path[0] = L'C';
@ -4565,7 +4565,7 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, const char *posix_cwd, bool doit)
if (!posix_cwd)
{
posix_cwd = (const char *) alloca (PATH_MAX);
posix_cwd = (const char *) alloca (NT_MAX_PATH);
mount_table->conv_to_posix_path (win32.Buffer, (char *) posix_cwd, 0);
}
posix = (char *) crealloc_abort (posix, strlen (posix_cwd) + 1);
@ -4598,8 +4598,8 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen)
char *tocopy;
if (!need_posix)
{
tocopy = (char *) alloca (PATH_MAX);
sys_wcstombs (tocopy, PATH_MAX, win32.Buffer, win32.Length);
tocopy = (char *) alloca (NT_MAX_PATH);
sys_wcstombs (tocopy, NT_MAX_PATH, win32.Buffer, win32.Length);
}
else
tocopy = posix;

View File

@ -392,7 +392,7 @@ DWORD WINAPI
commune_process (void *arg)
{
siginfo_t& si = *((siginfo_t *) arg);
char path[PATH_MAX];
char path[NT_MAX_PATH];
DWORD nr;
HANDLE& tothem = si._si_commune._si_write_handle;
HANDLE process_sync =
@ -439,7 +439,7 @@ commune_process (void *arg)
case PICOM_CWD:
{
sigproc_printf ("processing PICOM_CWD");
unsigned int n = strlen (cygheap->cwd.get (path, 1, 1, PATH_MAX)) + 1;
unsigned int n = strlen (cygheap->cwd.get (path, 1, 1, NT_MAX_PATH)) + 1;
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
sigproc_printf ("WriteFile sizeof cwd failed, %E");
else if (!WriteFile (tothem, path, n, &nr, NULL))
@ -665,7 +665,7 @@ _pinfo::fd (int fd, size_t &n)
if (cfd < 0)
s = cstrdup ("");
else
s = cfd->get_proc_fd_name ((char *) cmalloc_abort (HEAP_COMMUNE, PATH_MAX));
s = cfd->get_proc_fd_name ((char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH));
n = strlen (s) + 1;
}
return s;
@ -736,8 +736,8 @@ _pinfo::cwd (size_t& n)
}
else
{
s = (char *) cmalloc_abort (HEAP_COMMUNE, PATH_MAX);
cygheap->cwd.get (s, 1, 1, PATH_MAX);
s = (char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH);
cygheap->cwd.get (s, 1, 1, NT_MAX_PATH);
n = strlen (s) + 1;
}
return s;

View File

@ -64,7 +64,7 @@ public:
DWORD dwProcessId;
/* Used to spawn a child for fork(), among other things. */
char progname[PATH_MAX];
char progname[NT_MAX_PATH];
/* User information.
The information is derived from the GetUserName system call,

View File

@ -19,6 +19,7 @@ details. */
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include <wchar.h>
static const char cygnus_class[] = "cygnus";
reg_key::reg_key (HKEY top, REGSAM access, ...): _disposition (0)
@ -207,54 +208,55 @@ reg_key::~reg_key ()
key_is_invalid = 1;
}
char *
get_registry_hive_path (const char *name, char *path)
PWCHAR
get_registry_hive_path (const PWCHAR name, PWCHAR path)
{
char key[256];
WCHAR key[256], *kend;
HKEY hkey;
if (!name || !path)
return NULL;
__small_sprintf (key, "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\"
"ProfileList\\%s", name);
if (!RegOpenKeyExA (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey))
kend = wcpcpy (key, L"SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\ProfileList\\");
wcpcpy (kend, name);
if (!RegOpenKeyExW (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey))
{
char buf[PATH_MAX];
WCHAR buf[NT_MAX_PATH];
WCHAR tmp[NT_MAX_PATH];
DWORD type, siz;
path[0] = '\0';
if (!RegQueryValueExA (hkey, "ProfileImagePath", 0, &type,
path[0] = L'\0';
if (!RegQueryValueExW (hkey, L"ProfileImagePath", 0, &type,
(BYTE *)buf, (siz = sizeof (buf), &siz)))
ExpandEnvironmentStringsA (buf, path, PATH_MAX);
ExpandEnvironmentStringsW (buf, path, NT_MAX_PATH);
RegCloseKey (hkey);
if (path[0])
return path;
}
debug_printf ("HKLM\\%s not found", key);
debug_printf ("HKLM\\%W not found", key);
return NULL;
}
void
load_registry_hive (const char * name)
load_registry_hive (const PWCHAR name)
{
char path[PATH_MAX];
WCHAR path[NT_MAX_PATH];
HKEY hkey;
LONG ret;
if (!name)
return;
/* Check if user hive is already loaded. */
if (!RegOpenKeyExA (HKEY_USERS, name, 0, KEY_READ, &hkey))
if (!RegOpenKeyExW (HKEY_USERS, name, 0, KEY_READ, &hkey))
{
debug_printf ("User registry hive for %s already exists", name);
debug_printf ("User registry hive for %W already exists", name);
RegCloseKey (hkey);
return;
}
if (get_registry_hive_path (name, path))
{
strcat (path, "\\NTUSER.DAT");
if ((ret = RegLoadKeyA (HKEY_USERS, name, path)) != ERROR_SUCCESS)
debug_printf ("Loading user registry hive for %s failed: %d", name, ret);
wcscat (path, L"\\NTUSER.DAT");
if ((ret = RegLoadKeyW (HKEY_USERS, name, path)) != ERROR_SUCCESS)
debug_printf ("Loading user registry hive for %W failed: %d", name, ret);
}
}

View File

@ -40,5 +40,5 @@ public:
};
/* Evaluates path to the directory of the local user registry hive */
char *__stdcall get_registry_hive_path (const char *name, char *path);
void __stdcall load_registry_hive (const char *name);
PWCHAR __stdcall get_registry_hive_path (const PWCHAR name, PWCHAR path);
void __stdcall load_registry_hive (const PWCHAR name);

View File

@ -101,6 +101,17 @@ cygpsid::get_id (BOOL search_grp, int *type)
return id;
}
PWCHAR
cygpsid::string (PWCHAR nsidstr) const
{
UNICODE_STRING sid;
if (!psid || !nsidstr)
return NULL;
RtlInitEmptyUnicodeString (&sid, nsidstr, 256);
RtlConvertSidToUnicodeString (&sid, psid, FALSE);
return nsidstr;
}
char *
cygpsid::string (char *nsidstr) const

View File

@ -100,6 +100,7 @@ public:
int get_uid () { return get_id (FALSE); }
int get_gid () { return get_id (TRUE); }
PWCHAR string (PWCHAR nsidstr) const;
char *string (char *nsidstr) const;
bool operator== (const PSID nsid) const

View File

@ -64,7 +64,7 @@ __rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned
extern "C" int
__small_vsprintf (char *dst, const char *fmt, va_list ap)
{
char tmp[PATH_MAX];
char tmp[NT_MAX_PATH];
char *orig = dst;
const char *s;
PWCHAR w;
@ -169,7 +169,7 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap)
dst = rnargLL (dst, 16, 0, len, pad);
break;
case 'P':
if (!GetModuleFileName (NULL, tmp, PATH_MAX))
if (!GetModuleFileName (NULL, tmp, NT_MAX_PATH))
s = "cygwin program";
else
s = tmp;

View File

@ -154,7 +154,7 @@ strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
pn = NULL;
char *p;
char progname[PATH_MAX];
char progname[NT_MAX_PATH];
if (!pn)
GetModuleFileName (NULL, pn = progname, sizeof (progname));
if (!pn)

View File

@ -2483,7 +2483,7 @@ seteuid32 (__uid32_t uid)
if (new_token != hProcToken)
{
/* Avoid having HKCU use default user */
char name[128];
WCHAR name[128];
load_registry_hive (usersid.string (name));
/* Try setting owner to same value as user. */

View File

@ -408,12 +408,12 @@ cygheap_user::env_userprofile (const char *name, size_t namelen)
if (test_uid (puserprof, name, namelen))
return puserprof;
char userprofile_env_buf[PATH_MAX];
char win_id[UNLEN + 1]; /* Large enough for SID */
WCHAR userprofile_env_buf[NT_MAX_PATH];
WCHAR win_id[UNLEN + 1]; /* Large enough for SID */
cfree_and_set (puserprof, almost_null);
if (get_registry_hive_path (get_windows_id (win_id), userprofile_env_buf))
puserprof = cstrdup (userprofile_env_buf);
sys_wcstombs_alloc (&puserprof, HEAP_STR, userprofile_env_buf);
return puserprof;
}

View File

@ -61,7 +61,7 @@ extern unsigned long cygwin_inet_addr (const char *cp);
/* Note that MAX_PATH is defined in the windows headers */
/* There is also PATH_MAX and MAXPATHLEN.
PATH_MAX is from Posix and does *not* include the trailing NUL.
PATH_MAX is from Posix and does include the trailing NUL.
MAXPATHLEN is from Unix.
Thou shalt use CYG_MAX_PATH throughout. It avoids the NUL vs no-NUL
@ -76,6 +76,15 @@ extern unsigned long cygwin_inet_addr (const char *cp);
#define CYG_MAX_PATH (MAX_PATH)
/* There's no define for the maximum path length the NT kernel can handle.
That's why we define our own to use in path length test and for path
buffer sizes. As MAX_PATH and PATH_MAX, this is defined including the
trailing 0. Internal buffers and internal path routines should use
NT_MAX_PATH. PATH_MAX as defined in limits.h is the maximum length of
application provided path strings we handle. */
/* FIXME: The name is preliminary and TBD. */
#define NT_MAX_PATH 32768
#ifdef __cplusplus
extern const char case_folded_lower[];