Here's a prototype patch for getpass() in src/user.c

This was very frustrating because, while I thought I entered a password, I actually was not when I did "f user password username".

The issue is entering a password when using mintty on MSYS2. From some prior research, mintty does not use the windows console interface. Instead it uses pipes for some sort of emulation. Therefore, the _getch() function in mintty does not return anything (maybe an error?).

Running fossil in a tcc.exe or cmd.exe window works since those two use the windows console interface.

I don't have any other "consoles" to test this with, but what this patch is attempting to do is determine if stderr is a "console" under windows -- this is true if _isatty(fileno(stderr)) is true. Otherwise, it falls back to getc().

The patch was tested using MSYS2's mintty, and cmd.exe & tcc.exe on win7x64.

--- fossil-2.2/src/user.c.orig  2017-04-11 15:54:55.000000000 -0500
+++ fossil-2.2/src/user.c       2017-05-01 15:22:30.217545000 -0500
@@ -55,6 +55,9 @@
   char *zPwd;
   size_t nPwd;
   size_t i;
+#if defined(_WIN32)
+  int use_getch = _isatty( _fileno(stderr) );
+#endif

   if( zPwdBuffer==0 ){
     zPwdBuffer = fossil_secure_alloc_page(&nPwdBuffer);
@@ -70,7 +73,10 @@
   assert( nPwd>0 );
   for(i=0; i<nPwd-1; ++i){
 #if defined(_WIN32)
-    zPwd[i] = _getch();
+    if ( use_getch )
+      zPwd[i] = _getch();
+    else
+      zPwd[i] = getc(stdin);
 #else
     zPwd[i] = getc(stdin);
 #endif
@@ -93,10 +99,16 @@
       break;
     }
     else{
+#if defined(_WIN32)
+      if ( use_getch )
+#endif
       fputc('*',stderr);
     }
   }
   zPwd[i]='\0';
+#if defined(_WIN32)
+  if ( use_getch )
+#endif
   fputs("\n", stderr);
   assert( zPwd==zPwdBuffer );
   return zPwd;
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to