* 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.
This commit is contained in:
Corinna Vinschen 2009-03-22 10:09:01 +00:00
parent 1c0674333c
commit 35aeac58b0
3 changed files with 29 additions and 21 deletions

View File

@ -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> 2009-03-18 Christopher Faylor <me+cygwin@cgf.cx>
* ldh.cc: New file. * ldh.cc: New file.

View File

@ -319,7 +319,6 @@ report (const char *in_fn, bool multiple)
break; break;
} }
out:
return 0; return 0;
} }

View File

@ -27,6 +27,8 @@ details. */
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <locale.h>
#include <wchar.h>
#define USER_PRIV_ADMIN 2 #define USER_PRIV_ADMIN 2
@ -114,7 +116,7 @@ PUSER_INFO_3
GetPW (char *user, int print_win_name, LPCWSTR server) GetPW (char *user, int print_win_name, LPCWSTR server)
{ {
char usr_buf[UNLEN + 1]; char usr_buf[UNLEN + 1];
WCHAR name[2 * (UNLEN + 1)]; WCHAR name[UNLEN + 1];
DWORD ret; DWORD ret;
PUSER_INFO_3 ui; PUSER_INFO_3 ui;
struct passwd *pw; 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); ret = NetUserGetInfo (server, name, 3, (void *) &ui);
return EvalRet (ret, user) ? NULL : ui; return EvalRet (ret, user) ? NULL : ui;
} }
@ -144,11 +146,11 @@ int
ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck, ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck,
LPCWSTR server) LPCWSTR server)
{ {
WCHAR name[2 * (UNLEN + 1)], oldpass[512], pass[512]; WCHAR name[UNLEN + 1], oldpass[512], pass[512];
DWORD ret; DWORD ret;
MultiByteToWideChar (CP_ACP, 0, user, -1, name, 2 * (UNLEN + 1)); mbstowcs (name, user, UNLEN + 1);
MultiByteToWideChar (CP_ACP, 0, pwd, -1, pass, 512); mbstowcs (pass, pwd, 512);
if (! oldpwd) if (! oldpwd)
{ {
USER_INFO_1003 ui; USER_INFO_1003 ui;
@ -158,7 +160,7 @@ ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck,
} }
else else
{ {
MultiByteToWideChar (CP_ACP, 0, oldpwd, -1, oldpass, 512); mbstowcs (oldpass, oldpwd, 512);
ret = NetUserChangePassword (server, name, oldpass, pass); ret = NetUserChangePassword (server, name, oldpass, pass);
} }
if (justcheck && ret != ERROR_INVALID_PASSWORD) if (justcheck && ret != ERROR_INVALID_PASSWORD)
@ -327,11 +329,11 @@ Compiled on %s\n\
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
char *c; char *c, *logonserver;
char user[UNLEN + 1], oldpwd[_PASSWORD_LEN + 1], newpwd[_PASSWORD_LEN + 1]; char user[UNLEN + 1], oldpwd[_PASSWORD_LEN + 1], newpwd[_PASSWORD_LEN + 1];
int ret = 0; int ret = 0;
int cnt = 0; int cnt = 0;
int opt, len; int opt;
int Larg = -1; int Larg = -1;
int xarg = -1; int xarg = -1;
int narg = -1; int narg = -1;
@ -360,6 +362,8 @@ main (int argc, char **argv)
if (c) if (c)
*c = '\0'; *c = '\0';
setlocale (LC_ALL, "");
while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (opt) switch (opt)
{ {
@ -417,10 +421,10 @@ main (int argc, char **argv)
if (*optarg != '\\') if (*optarg != '\\')
strcpy (tmpbuf, "\\\\"); strcpy (tmpbuf, "\\\\");
strcat (tmpbuf, optarg); strcat (tmpbuf, optarg);
server = alloca ((strlen (tmpbuf) + 1) * sizeof (WCHAR)); size_t len = mbstowcs (NULL, tmpbuf, 0);
if (MultiByteToWideChar (CP_ACP, 0, tmpbuf, -1, server, if (len > 0 && len != (size_t) -1)
strlen (tmpbuf) + 1) <= 0) mbstowcs (server = alloca ((len + 1) * sizeof (wchar_t)),
server = NULL; tmpbuf, len + 1);
} }
break; break;
@ -513,15 +517,12 @@ main (int argc, char **argv)
return 0; return 0;
} }
if (!server) if (!server && (logonserver = getenv ("LOGONSERVER")))
{ {
len = GetEnvironmentVariableW (L"LOGONSERVER", NULL, 0); size_t len = mbstowcs (NULL, logonserver, 0);
if (len > 0) if (len > 0 && len != (size_t) -1)
{ mbstowcs (server = alloca ((len + 1) * sizeof (wchar_t)),
server = alloca (len * sizeof (WCHAR)); logonserver, len + 1);
if (GetEnvironmentVariableW (L"LOGONSERVER", server, len) <= 0)
server = NULL;
}
} }
if (Larg >= 0 || xarg >= 0 || narg >= 0 || iarg >= 0) if (Larg >= 0 || xarg >= 0 || narg >= 0 || iarg >= 0)