passwd edited /etc/passwd patch
Joshua Daniel Franklin
joshuadfranklin@yahoo.com
Tue Jun 11 18:19:00 GMT 2002
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 <joshuadfranklin@yahoo.com>
* passwd.c (GetPW): Handle case of user-edited /etc/passwd
with cygwin_internal (CW_EXTRACT_DOMAIN_AND_USER, ...)
-------------- next part --------------
--- 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;
}
More information about the Cygwin-patches
mailing list