summaryrefslogtreecommitdiffstats
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2006-02-07 15:49:08 +0000
committerCorinna Vinschen <corinna@vinschen.de>2006-02-07 15:49:08 +0000
commit03a49a00ab2239e769c61592ea946d151ea95114 (patch)
treef7bad6c6fd475c542d11a6573b22395a23a287d4 /winsup
parent3cb155a97f98f2f7e9e68b6c536b9bb3777e33d8 (diff)
downloadcygnal-03a49a00ab2239e769c61592ea946d151ea95114.tar.gz
cygnal-03a49a00ab2239e769c61592ea946d151ea95114.tar.bz2
cygnal-03a49a00ab2239e769c61592ea946d151ea95114.zip
* dtable.cc (handle_to_fn): Accomodate new argument order in call to
sys_wcstombs. * fhandler_disk_file.cc (fhandler_disk_file::readdir): Call sys_wcstombs instead of just wcstombs to accomodate OEM codepages. * miscfuncs.cc (sys_wcstombs): Split len argument in source and target length. Always 0-terminate result in target string. * security.cc (lsa2wchar): Remove unused function. (lsa2str): Ditto. (get_lsa_srv_inf): Ditto. (get_logon_server): Accomodate new argument order in call to sys_wcstombs. (get_user_groups): Ditto. (get_user_local_groups): Ditto. (get_priv_list): Call sys_wcstombs directly instead of lsa2str. * uinfo.cc (cygheap_user::ontherange): Accomodate new argument order in call to sys_wcstombs. * winsup.h (sys_wcstombs): Change prototype to match new argument order.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog20
-rw-r--r--winsup/cygwin/dtable.cc2
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc3
-rw-r--r--winsup/cygwin/miscfuncs.cc12
-rw-r--r--winsup/cygwin/security.cc85
-rw-r--r--winsup/cygwin/uinfo.cc7
-rw-r--r--winsup/cygwin/winsup.h2
7 files changed, 42 insertions, 89 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index f5c38fdd6..4881f97e6 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,25 @@
2006-02-07 Corinna Vinschen <corinna@vinschen.de>
+ * dtable.cc (handle_to_fn): Accomodate new argument order in call to
+ sys_wcstombs.
+ * fhandler_disk_file.cc (fhandler_disk_file::readdir): Call sys_wcstombs
+ instead of just wcstombs to accomodate OEM codepages.
+ * miscfuncs.cc (sys_wcstombs): Split len argument in source and target
+ length. Always 0-terminate result in target string.
+ * security.cc (lsa2wchar): Remove unused function.
+ (lsa2str): Ditto.
+ (get_lsa_srv_inf): Ditto.
+ (get_logon_server): Accomodate new argument order in call to
+ sys_wcstombs.
+ (get_user_groups): Ditto.
+ (get_user_local_groups): Ditto.
+ (get_priv_list): Call sys_wcstombs directly instead of lsa2str.
+ * uinfo.cc (cygheap_user::ontherange): Accomodate new argument order
+ in call to sys_wcstombs.
+ * winsup.h (sys_wcstombs): Change prototype to match new argument order.
+
+2006-02-07 Corinna Vinschen <corinna@vinschen.de>
+
* init.cc (respawn_wow64_process): Exit with the exit code returned
by the respawned process.
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 31b119871..c4a8333d5 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -848,7 +848,7 @@ handle_to_fn (HANDLE h, char *posix_fn)
ntfn->Name.Buffer[ntfn->Name.Length / sizeof (WCHAR)] = 0;
char win32_fn[CYG_MAX_PATH + 100];
- sys_wcstombs (win32_fn, ntfn->Name.Buffer, ntfn->Name.Length);
+ sys_wcstombs (win32_fn, CYG_MAX_PATH + 100, ntfn->Name.Buffer);
debug_printf ("nt name '%s'", win32_fn);
if (!strncasematch (win32_fn, DEVICE_PREFIX, DEVICE_PREFIX_LEN)
|| !QueryDosDevice (NULL, fnbuf, sizeof (fnbuf)))
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index b187de58b..6edd010b6 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -1681,8 +1681,7 @@ fhandler_disk_file::readdir (DIR *dir, dirent *de)
}
}
}
- wcstombs (fname, FileName, buf->FileNameLength / 2);
- fname[buf->FileNameLength / 2] = '\0';
+ sys_wcstombs (fname, CYG_MAX_PATH - 1, FileName, buf->FileNameLength / 2);
}
if (!(res = readdir_helper (dir, de, RtlNtStatusToDosError (status),
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index 26686bd2b..0f5804ed6 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -210,10 +210,18 @@ get_cp ()
return current_codepage == ansi_cp ? GetACP() : GetOEMCP();
}
+/* tlen is always treated as the maximum buffer size, including the '\0'
+ character. sys_wcstombs will always return a 0-terminated result, no
+ matter what. */
int __stdcall
-sys_wcstombs (char *tgt, const WCHAR *src, int len)
+sys_wcstombs (char *tgt, int tlen, const WCHAR *src, int slen)
{
- return WideCharToMultiByte (get_cp (), 0, src, -1, tgt, len, NULL, NULL);
+ int ret;
+
+ ret = WideCharToMultiByte (get_cp (), 0, src, slen, tgt, tlen, NULL, NULL);
+ if (ret)
+ tgt[ret < tlen ? ret : tlen - 1] = '\0';
+ return ret;
}
int __stdcall
diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc
index f0deda11b..8a994fe80 100644
--- a/winsup/cygwin/security.cc
+++ b/winsup/cygwin/security.cc
@@ -188,28 +188,6 @@ str2uni_cat (UNICODE_STRING &tgt, const char *srcstr)
tgt.Length = tgt.MaximumLength = 0;
}
-#if 0 /* unused */
-static void
-lsa2wchar (WCHAR *tgt, LSA_UNICODE_STRING &src, int size)
-{
- size = (size - 1) * sizeof (WCHAR);
- if (src.Length < size)
- size = src.Length;
- memcpy (tgt, src.Buffer, size);
- size >>= 1;
- tgt[size] = 0;
-}
-#endif
-
-static void
-lsa2str (char *tgt, LSA_UNICODE_STRING &src, int size)
-{
- if (src.Length / 2 < size)
- size = src.Length / 2;
- sys_wcstombs (tgt, src.Buffer, size);
- tgt[size] = 0;
-}
-
static LSA_HANDLE
open_local_policy ()
{
@@ -230,60 +208,6 @@ close_local_policy (LSA_HANDLE &lsa)
lsa = INVALID_HANDLE_VALUE;
}
-#if 0 /* unused */
-static BOOL
-get_lsa_srv_inf (LSA_HANDLE lsa, char *logonserver, char *domain)
-{
- NET_API_STATUS ret;
- WCHAR *buf;
- char name[INTERNET_MAX_HOST_NAME_LENGTH + 1];
- WCHAR account[INTERNET_MAX_HOST_NAME_LENGTH + 1];
- WCHAR primary[INTERNET_MAX_HOST_NAME_LENGTH + 1];
- PPOLICY_ACCOUNT_DOMAIN_INFO adi;
- PPOLICY_PRIMARY_DOMAIN_INFO pdi;
-
- if ((ret = LsaQueryInformationPolicy (lsa, PolicyAccountDomainInformation,
- (PVOID *) &adi)) != STATUS_SUCCESS)
- {
- __seterrno_from_win_error (LsaNtStatusToWinError (ret));
- return FALSE;
- }
- lsa2wchar (account, adi->DomainName, INTERNET_MAX_HOST_NAME_LENGTH + 1);
- LsaFreeMemory (adi);
- if ((ret = LsaQueryInformationPolicy (lsa, PolicyPrimaryDomainInformation,
- (PVOID *) &pdi)) != STATUS_SUCCESS)
- {
- __seterrno_from_win_error (LsaNtStatusToWinError (ret));
- return FALSE;
- }
- lsa2wchar (primary, pdi->Name, INTERNET_MAX_HOST_NAME_LENGTH + 1);
- LsaFreeMemory (pdi);
- /* If the SID given in the primary domain info is NULL, the machine is
- not member of a domain. The name in the primary domain info is the
- name of the workgroup then. */
- if (pdi->Sid &&
- (ret =
- NetGetDCName (NULL, primary, (LPBYTE *) &buf)) == STATUS_SUCCESS)
- {
- sys_wcstombs (name, buf, INTERNET_MAX_HOST_NAME_LENGTH + 1);
- strcpy (logonserver, name);
- if (domain)
- sys_wcstombs (domain, primary, INTERNET_MAX_HOST_NAME_LENGTH + 1);
- }
- else
- {
- sys_wcstombs (name, account, INTERNET_MAX_HOST_NAME_LENGTH + 1);
- strcpy (logonserver, "\\\\");
- strcat (logonserver, name);
- if (domain)
- sys_wcstombs (domain, account, INTERNET_MAX_HOST_NAME_LENGTH + 1);
- }
- if (ret == STATUS_SUCCESS)
- NetApiBufferFree (buf);
- return TRUE;
-}
-#endif
-
bool
get_logon_server (const char *domain, char *server, WCHAR *wserver)
{
@@ -306,7 +230,7 @@ get_logon_server (const char *domain, char *server, WCHAR *wserver)
sys_mbstowcs (wdomain, domain, INTERNET_MAX_HOST_NAME_LENGTH + 1);
if ((ret = NetGetDCName (NULL, wdomain, (LPBYTE *) &buf)) == STATUS_SUCCESS)
{
- sys_wcstombs (server, buf, INTERNET_MAX_HOST_NAME_LENGTH + 1);
+ sys_wcstombs (server, INTERNET_MAX_HOST_NAME_LENGTH + 1, buf);
if (wserver)
for (WCHAR *ptr1 = buf; (*wserver++ = *ptr1++);)
;
@@ -350,7 +274,7 @@ get_user_groups (WCHAR *wlogonserver, cygsidlist &grp_list, char *user,
DWORD dlen = sizeof (domain);
SID_NAME_USE use = SidTypeInvalid;
- sys_wcstombs (dgroup + len, buf[i].grui0_name, GNLEN + 1);
+ sys_wcstombs (dgroup + len, GNLEN + 1, buf[i].grui0_name);
if (!LookupAccountName (NULL, dgroup, gsid, &glen, domain, &dlen, &use))
debug_printf ("LookupAccountName(%s), %E", dgroup);
else if (legal_sid_type (use))
@@ -445,7 +369,7 @@ get_user_local_groups (cygsidlist &grp_list, PSID pusersid)
DWORD dlen = sizeof (domain);
use = SidTypeInvalid;
- sys_wcstombs (bgroup + blen, buf[i].lgrpi0_name, GNLEN + 1);
+ sys_wcstombs (bgroup + blen, GNLEN + 1, buf[i].lgrpi0_name);
if (!LookupAccountName (NULL, bgroup, gsid, &glen, domain, &dlen, &use))
{
if (GetLastError () != ERROR_NONE_MAPPED)
@@ -714,7 +638,8 @@ get_priv_list (LSA_HANDLE lsa, cygsid &usersid, cygsidlist &grp_list)
PTOKEN_PRIVILEGES tmp;
DWORD tmp_count;
- lsa2str (buf, privstrs[i], sizeof (buf) - 1);
+ sys_wcstombs (buf, sizeof (buf),
+ privstrs[i].Buffer, privstrs[i].Length / 2);
if (!(priv = privilege_luid_by_name (buf)))
continue;
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 6948ce2b3..d649733b0 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -306,11 +306,12 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
sys_mbstowcs (wuser, winname (), sizeof (wuser) / sizeof (*wuser));
if (!(ret = NetUserGetInfo (wlogsrv, wuser, 3, (LPBYTE *) &ui)))
{
- sys_wcstombs (homepath_env_buf, ui->usri3_home_dir, CYG_MAX_PATH);
+ sys_wcstombs (homepath_env_buf, CYG_MAX_PATH,
+ ui->usri3_home_dir);
if (!homepath_env_buf[0])
{
- sys_wcstombs (homepath_env_buf, ui->usri3_home_dir_drive,
- CYG_MAX_PATH);
+ sys_wcstombs (homepath_env_buf, CYG_MAX_PATH,
+ ui->usri3_home_dir_drive);
if (homepath_env_buf[0])
strcat (homepath_env_buf, "\\");
else
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index 3fd669fc8..f2eab08bc 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -119,7 +119,7 @@ extern codepage_type current_codepage;
UINT get_cp ();
-int __stdcall sys_wcstombs(char *, const WCHAR *, int)
+int __stdcall sys_wcstombs(char *, int, const WCHAR *, int = -1)
__attribute__ ((regparm(3)));
int __stdcall sys_mbstowcs(WCHAR *, const char *, int)