From dd9752e88e985b1ec7ec4a2cb4f3b276f5d35abb Mon Sep 17 00:00:00 2001 From: Egor Duda Date: Wed, 11 Apr 2001 09:38:55 +0000 Subject: [PATCH] * mkgroup.c (uni2ansi): Use native method to convert from Unicode to multi-byte strings. * mkpasswd.c (uni2ansi): Ditto. (enum_users): Pass buffer size when converting string. (enum_local_groups): Ditto. * mkgroup.c (enum_groups): Ditto. (enum_local_groups): Ditto. --- winsup/utils/ChangeLog | 10 ++++++++++ winsup/utils/mkgroup.c | 11 +++++------ winsup/utils/mkpasswd.c | 15 +++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index fdc626e11..4d7199806 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,13 @@ +2001-04-11 Egor Duda + + * mkgroup.c (uni2ansi): Use native method to convert from Unicode + to multi-byte strings. + * mkpasswd.c (uni2ansi): Ditto. + (enum_users): Pass buffer size when converting string. + (enum_local_groups): Ditto. + * mkgroup.c (enum_groups): Ditto. + (enum_local_groups): Ditto. + Mon Apr 2 22:41:33 2001 Christopher Faylor * mount.cc (main): Use getopt_long for parsing arguments. diff --git a/winsup/utils/mkgroup.c b/winsup/utils/mkgroup.c index e81337511..331788fe6 100644 --- a/winsup/utils/mkgroup.c +++ b/winsup/utils/mkgroup.c @@ -92,11 +92,10 @@ psx_dir (char *in, char *out) } void -uni2ansi (LPWSTR wcs, char *mbs) +uni2ansi (LPWSTR wcs, char *mbs, int size) { if (wcs) - wcstombs (mbs, wcs, (wcslen (wcs) + 1) * sizeof (WCHAR)); - + WideCharToMultiByte (CP_ACP, 0, wcs, -1, mbs, size, NULL, NULL); else *mbs = '\0'; } @@ -141,7 +140,7 @@ enum_local_groups (int print_sids) DWORD sid_length = 1024; DWORD gid; SID_NAME_USE acc_type; - uni2ansi (buffer[i].lgrpi0_name, localgroup_name); + uni2ansi (buffer[i].lgrpi0_name, localgroup_name, sizeof (localgroup_name)); if (!LookupAccountName (NULL, localgroup_name, psid, &sid_length, domain_name, &domname_len, @@ -198,7 +197,7 @@ enum_groups (LPWSTR servername, int print_sids) char ansi_srvname[256]; if (servername) - uni2ansi (servername, ansi_srvname); + uni2ansi (servername, ansi_srvname, sizeof (ansi_srvname)); do { @@ -232,7 +231,7 @@ enum_groups (LPWSTR servername, int print_sids) SID_NAME_USE acc_type; int gid = buffer[i].grpi2_group_id; - uni2ansi (buffer[i].grpi2_name, groupname); + uni2ansi (buffer[i].grpi2_name, groupname, sizeof (groupname)); if (print_sids) { if (!LookupAccountName (servername ? ansi_srvname : NULL, diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c index 47d344038..1309cac4d 100644 --- a/winsup/utils/mkpasswd.c +++ b/winsup/utils/mkpasswd.c @@ -92,11 +92,10 @@ psx_dir (char *in, char *out) } void -uni2ansi (LPWSTR wcs, char *mbs) +uni2ansi (LPWSTR wcs, char *mbs, int size) { if (wcs) - wcstombs (mbs, wcs, (wcslen (wcs) + 1) * sizeof (WCHAR)); - + WideCharToMultiByte (CP_ACP, 0, wcs, -1, mbs, size, NULL, NULL); else *mbs = '\0'; } @@ -113,7 +112,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath, char ansi_srvname[256]; if (servername) - uni2ansi (servername, ansi_srvname); + uni2ansi (servername, ansi_srvname, sizeof (ansi_srvname)); do { @@ -152,10 +151,10 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath, int uid = buffer[i].usri3_user_id; int gid = buffer[i].usri3_primary_group_id; - uni2ansi (buffer[i].usri3_name, username); - uni2ansi (buffer[i].usri3_full_name, fullname); + uni2ansi (buffer[i].usri3_name, username, sizeof (username)); + uni2ansi (buffer[i].usri3_full_name, fullname, sizeof (fullname)); homedir_w32[0] = homedir_psx[0] = '\0'; - uni2ansi (buffer[i].usri3_home_dir, homedir_w32); + uni2ansi (buffer[i].usri3_home_dir, homedir_w32, sizeof (homedir_w32)); if (print_cygpath) cygwin_conv_to_posix_path (homedir_w32, homedir_psx); else @@ -264,7 +263,7 @@ enum_local_groups (int print_sids) DWORD sid_length = 1024; DWORD gid; SID_NAME_USE acc_type; - uni2ansi (buffer[i].lgrpi0_name, localgroup_name); + uni2ansi (buffer[i].lgrpi0_name, localgroup_name, sizeof (localgroup_name)); if (!LookupAccountName (NULL, localgroup_name, psid, &sid_length, domain_name, &domname_len,