Here is that patch for passwd.c to deal with user-edited /etc/passwd
files. I poked around about adding the CW_EXTRACT_DOMAIN_AND_USER
then did a CVS update and Corinna already had done it. Sorry for the
delay, I apparently haven't been paying attention for more than a week...

ChangeLog:

2002-06-11  Joshua Daniel Franklin <[EMAIL PROTECTED]>

        * passwd.c (GetPW): Handle case of user-edited /etc/passwd
        with cygwin_internal (CW_EXTRACT_DOMAIN_AND_USER, ...)

--- passwd.c-orig       Tue Jun 11 20:13:51 2002
+++ passwd.c    Tue Jun 11 19:59:17 2002
@@ -16,6 +16,7 @@ details. */
 #include <unistd.h>
 #include <getopt.h>
 #include <pwd.h>
+#include <sys/cygwin.h>
 #include <sys/types.h>
 #include <time.h>
 
@@ -107,9 +108,21 @@ GetPW (const char *user)
   WCHAR name[512];
   DWORD ret;
   PUSER_INFO_3 ui;
-
+  struct passwd *pw;
+  char *domain = (char *) malloc (MAX_PATH + 1);
+     
   MultiByteToWideChar (CP_ACP, 0, user, -1, name, 512);
   ret = NetUserGetInfo (NULL, name, 3, (LPBYTE *) &ui);
+  /* Try getting a Win32 username in case the user edited /etc/passwd */
+  if (ret == NERR_UserNotFound)
+  {
+    if ((pw = getpwnam (user)))
+      cygwin_internal (CW_EXTRACT_DOMAIN_AND_USER, pw, domain, (char *) user);
+    MultiByteToWideChar (CP_ACP, 0, user, -1, name, 512);
+    ret = NetUserGetInfo (NULL, name, 3, (LPBYTE *) &ui);
+    if (ret == (int) NULL)
+      printf ("Windows username : %s\n", user);
+  }
   return EvalRet (ret, user) ? NULL : ui;
 }
 

Reply via email to