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>2002-06-14 15:31:33 +0400
committerCorinna Vinschen <corinna@vinschen.de>2002-06-14 15:31:33 +0400
commit94a23f4860453f8914ea23b75ab1f6850bf53ccc (patch)
treead6fbe963528234db581e1e82ad2c5b41f18fdfb /winsup/utils
parentd61bc7aad81d72b6daa4b336eb9206c8e77f8d84 (diff)
* passwd.c: Rearrange includes to avoid unnecessary warnings.
(GetPW): Add parameter to (dis)allow printing of Windows username. Use defines instead of numerical constants where possible. Try avoiding impersonation problem. Rearrange to print Windows username only if it's different from Cygwin username. (ChangePW): Use defines instead of numerical constants where possible. (main): Call GetPW with additional parameter. Change error text. * passwd.c (GetPW): Handle case of user-edited /etc/passwd with cygwin_internal (CW_EXTRACT_DOMAIN_AND_USER, ...).
Diffstat (limited to 'winsup/utils')
-rw-r--r--winsup/utils/ChangeLog15
-rw-r--r--winsup/utils/passwd.c50
2 files changed, 50 insertions, 15 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index a98a84e21..5c8dc8335 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,18 @@
+2002-06-14 Corinna Vinschen <corinna@vinschen.de>
+
+ * passwd.c: Rearrange includes to avoid unnecessary warnings.
+ (GetPW): Add parameter to (dis)allow printing of Windows username.
+ Use defines instead of numerical constants where possible.
+ Try avoiding impersonation problem. Rearrange to print Windows
+ username only if it's different from Cygwin username.
+ (ChangePW): Use defines instead of numerical constants where possible.
+ (main): Call GetPW with additional parameter. Change error text.
+
+2002-06-14 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
+
+ * passwd.c (GetPW): Handle case of user-edited /etc/passwd
+ with cygwin_internal (CW_EXTRACT_DOMAIN_AND_USER, ...).
+
2002-06-09 Christopher Faylor <cgf@redhat.com>
* path.cc (cygpath): Change MOUNT_AUTO to MOUNT_CYGDRIVE.
diff --git a/winsup/utils/passwd.c b/winsup/utils/passwd.c
index a6b3fe10f..48fa75b2c 100644
--- a/winsup/utils/passwd.c
+++ b/winsup/utils/passwd.c
@@ -10,21 +10,23 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
+#include <windows.h>
+#include <wininet.h>
+#include <lmaccess.h>
+#include <lmerr.h>
+#include <lmcons.h>
+#include <lmapibuf.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <pwd.h>
+#include <sys/cygwin.h>
#include <sys/types.h>
#include <time.h>
-#include <windows.h>
-#include <lmaccess.h>
-#include <lmerr.h>
-#include <lmcons.h>
-#include <lmapibuf.h>
-
#define USER_PRIV_ADMIN 2
#define UF_LOCKOUT 0x00010
@@ -102,13 +104,31 @@ EvalRet (int ret, const char *user)
}
PUSER_INFO_3
-GetPW (const char *user)
+GetPW (char *user, int print_win_name)
{
- WCHAR name[512];
+ char usr_buf[UNLEN + 1];
+ WCHAR name[2 * (UNLEN + 1)];
DWORD ret;
PUSER_INFO_3 ui;
-
- MultiByteToWideChar (CP_ACP, 0, user, -1, name, 512);
+ struct passwd *pw;
+ char *domain = (char *) alloca (INTERNET_MAX_HOST_NAME_LENGTH + 1);
+
+ /* Try getting a Win32 username in case the user edited /etc/passwd */
+ if ((pw = getpwnam (user)))
+ {
+ cygwin_internal (CW_EXTRACT_DOMAIN_AND_USER, pw, domain, usr_buf);
+ if (strcasecmp (pw->pw_name, usr_buf))
+ {
+ /* Hack to avoid problem with LookupAccountSid after impersonation */
+ if (strcasecmp (usr_buf, "SYSTEM"))
+ {
+ user = usr_buf;
+ if (print_win_name)
+ printf ("Windows username : %s\n", user);
+ }
+ }
+ }
+ MultiByteToWideChar (CP_ACP, 0, user, -1, name, 2 * (UNLEN + 1));
ret = NetUserGetInfo (NULL, name, 3, (LPBYTE *) &ui);
return EvalRet (ret, user) ? NULL : ui;
}
@@ -116,10 +136,10 @@ GetPW (const char *user)
int
ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck)
{
- WCHAR name[512], oldpass[512], pass[512];
+ WCHAR name[2 * (UNLEN + 1)], oldpass[512], pass[512];
DWORD ret;
- MultiByteToWideChar (CP_ACP, 0, user, -1, name, 512);
+ MultiByteToWideChar (CP_ACP, 0, user, -1, name, 2 * (UNLEN + 1));
MultiByteToWideChar (CP_ACP, 0, pwd, -1, pass, 512);
if (! oldpwd)
{
@@ -362,11 +382,11 @@ main (int argc, char **argv)
strcpy (user, optind >= argc ? getlogin () : argv[optind]);
- li = GetPW (getlogin ());
+ li = GetPW (getlogin (), 0);
if (! li)
return 1;
- ui = GetPW (user);
+ ui = GetPW (user, 1);
if (! ui)
return 1;
@@ -377,7 +397,7 @@ main (int argc, char **argv)
if (lopt)
{
if (ui->usri3_priv == USER_PRIV_ADMIN)
- return eprint (0, "You may not lock an administrators account.");
+ return eprint (0, "Locking an admin account is disallowed.");
ui->usri3_flags |= UF_ACCOUNTDISABLE;
}
if (uopt)