Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-03-22 13:09:01 +0300
committerCorinna Vinschen <corinna@vinschen.de>2009-03-22 13:09:01 +0300
commit35aeac58b03b92d3e5641400cbf5b7ccfad15705 (patch)
tree1fa262a09b88054d17bd094ba1da550828b8b66e
parent1c0674333c495ed9b574ef27eed5b20721b753f3 (diff)
* ldd.cc: Fix compiler warning.
* passwd.c: Use mbstowcs instead of MultiByteToWideChar throughout. (main): Call setlocale. Fix a bug in fetching the logon server from the environment.
-rw-r--r--winsup/utils/ChangeLog8
-rw-r--r--winsup/utils/ldd.cc1
-rw-r--r--winsup/utils/passwd.c41
3 files changed, 29 insertions, 21 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 706188c64..55b707fb0 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,11 @@
+2009-03-22 Corinna Vinschen <corinna@vinschen.de>
+
+ * ldd.cc: Fix compiler warning.
+
+ * passwd.c: Use mbstowcs instead of MultiByteToWideChar throughout.
+ (main): Call setlocale. Fix a bug in fetching the logon server from
+ the environment.
+
2009-03-18 Christopher Faylor <me+cygwin@cgf.cx>
* ldh.cc: New file.
diff --git a/winsup/utils/ldd.cc b/winsup/utils/ldd.cc
index b880c7cbb..8797e3a11 100644
--- a/winsup/utils/ldd.cc
+++ b/winsup/utils/ldd.cc
@@ -319,7 +319,6 @@ report (const char *in_fn, bool multiple)
break;
}
-out:
return 0;
}
diff --git a/winsup/utils/passwd.c b/winsup/utils/passwd.c
index 4b48a95f2..68b3e44f4 100644
--- a/winsup/utils/passwd.c
+++ b/winsup/utils/passwd.c
@@ -27,6 +27,8 @@ details. */
#include <sys/types.h>
#include <time.h>
#include <errno.h>
+#include <locale.h>
+#include <wchar.h>
#define USER_PRIV_ADMIN 2
@@ -114,7 +116,7 @@ PUSER_INFO_3
GetPW (char *user, int print_win_name, LPCWSTR server)
{
char usr_buf[UNLEN + 1];
- WCHAR name[2 * (UNLEN + 1)];
+ WCHAR name[UNLEN + 1];
DWORD ret;
PUSER_INFO_3 ui;
struct passwd *pw;
@@ -135,7 +137,7 @@ GetPW (char *user, int print_win_name, LPCWSTR server)
}
}
}
- MultiByteToWideChar (CP_ACP, 0, user, -1, name, 2 * (UNLEN + 1));
+ mbstowcs (name, user, UNLEN + 1);
ret = NetUserGetInfo (server, name, 3, (void *) &ui);
return EvalRet (ret, user) ? NULL : ui;
}
@@ -144,11 +146,11 @@ int
ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck,
LPCWSTR server)
{
- WCHAR name[2 * (UNLEN + 1)], oldpass[512], pass[512];
+ WCHAR name[UNLEN + 1], oldpass[512], pass[512];
DWORD ret;
- MultiByteToWideChar (CP_ACP, 0, user, -1, name, 2 * (UNLEN + 1));
- MultiByteToWideChar (CP_ACP, 0, pwd, -1, pass, 512);
+ mbstowcs (name, user, UNLEN + 1);
+ mbstowcs (pass, pwd, 512);
if (! oldpwd)
{
USER_INFO_1003 ui;
@@ -158,7 +160,7 @@ ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck,
}
else
{
- MultiByteToWideChar (CP_ACP, 0, oldpwd, -1, oldpass, 512);
+ mbstowcs (oldpass, oldpwd, 512);
ret = NetUserChangePassword (server, name, oldpass, pass);
}
if (justcheck && ret != ERROR_INVALID_PASSWORD)
@@ -327,11 +329,11 @@ Compiled on %s\n\
int
main (int argc, char **argv)
{
- char *c;
+ char *c, *logonserver;
char user[UNLEN + 1], oldpwd[_PASSWORD_LEN + 1], newpwd[_PASSWORD_LEN + 1];
int ret = 0;
int cnt = 0;
- int opt, len;
+ int opt;
int Larg = -1;
int xarg = -1;
int narg = -1;
@@ -360,6 +362,8 @@ main (int argc, char **argv)
if (c)
*c = '\0';
+ setlocale (LC_ALL, "");
+
while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (opt)
{
@@ -417,10 +421,10 @@ main (int argc, char **argv)
if (*optarg != '\\')
strcpy (tmpbuf, "\\\\");
strcat (tmpbuf, optarg);
- server = alloca ((strlen (tmpbuf) + 1) * sizeof (WCHAR));
- if (MultiByteToWideChar (CP_ACP, 0, tmpbuf, -1, server,
- strlen (tmpbuf) + 1) <= 0)
- server = NULL;
+ size_t len = mbstowcs (NULL, tmpbuf, 0);
+ if (len > 0 && len != (size_t) -1)
+ mbstowcs (server = alloca ((len + 1) * sizeof (wchar_t)),
+ tmpbuf, len + 1);
}
break;
@@ -513,15 +517,12 @@ main (int argc, char **argv)
return 0;
}
- if (!server)
+ if (!server && (logonserver = getenv ("LOGONSERVER")))
{
- len = GetEnvironmentVariableW (L"LOGONSERVER", NULL, 0);
- if (len > 0)
- {
- server = alloca (len * sizeof (WCHAR));
- if (GetEnvironmentVariableW (L"LOGONSERVER", server, len) <= 0)
- server = NULL;
- }
+ size_t len = mbstowcs (NULL, logonserver, 0);
+ if (len > 0 && len != (size_t) -1)
+ mbstowcs (server = alloca ((len + 1) * sizeof (wchar_t)),
+ logonserver, len + 1);
}
if (Larg >= 0 || xarg >= 0 || narg >= 0 || iarg >= 0)