]> git.pond.sub.org Git - empserver/commitdiff
Replace missing getpass()
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 10 Apr 2009 12:57:13 +0000 (14:57 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 10 Apr 2009 17:09:57 +0000 (19:09 +0200)
getpass() is traditional Unix, but has been withdrawn from POSIX.  As
such, it may be missing.  Check for that, and provide ersatz.  It's
not a real replacement, because it doesn't do the special magic
getpass() is supposed to do: read from /dev/tty without echo.

This bypasses our existing getpass() for Windows.  In contrast to the
portable getpass(), the Windows one tries to turn off echo, but that
doesn't work for me (MinGW & Wine).  Remove it.

configure.ac
src/client/configure.ac
src/client/login.c
src/client/sysdep_w32.c
src/client/sysdep_w32.h

index c6e6d432ad7d96d65bbfaefadc50ff30a44833eb..fef05085f0f50e270ee3377f593d28e2957c48d1 100644 (file)
@@ -92,7 +92,7 @@ AC_C_CHAR_UNSIGNED
 
 ### Checks for library functions
 
-AC_CHECK_FUNCS(getaddrinfo)
+AC_CHECK_FUNCS(getaddrinfo getpass)
 MY_FUNC_MAKECONTEXT
 
 
index 4adf3a12507e6309941abdc5787ea88192ca9592..2dc6a67736bb900753c2fe9f1fff85f4d7de3fd6 100644 (file)
@@ -81,7 +81,7 @@ AC_MSG_RESULT([$Windows_res])
 
 ### Checks for library functions.
 
-AC_CHECK_FUNCS(getaddrinfo)
+AC_CHECK_FUNCS(getaddrinfo getpass)
 
 
 ### Site configuration
index 9ec9d53018860be169b73ebfae2f1798e6d3002d..350e64498f43bbc767116c83f7a2c412b687ae01 100644 (file)
 #include "misc.h"
 #include "proto.h"
 
+#ifndef HAVE_GETPASS
+#define getpass ersatz_getpass
+static char *
+ersatz_getpass(char *prompt)
+{
+    static char buf[128];
+    char *p;
+    size_t len;
+
+    printf("Note: your input is echoed to the screen\n");
+    printf("Your name? ");
+    fflush(stdout);
+    p = fgets(buf, sizeof(buf), stdin);
+    if (!p)
+       return NULL;
+    len = strlen(p);
+    if (p[len - 1] == '\n')
+       p[len - 1] = 0;
+    return p;
+}
+#endif
+
 int
 login(int s, char *uname, char *cname, char *cpass,
       int kill_proc, int utf8)
index 12cbaee7b9c773bd1b8b3ee389b73dece3e285ac..a703c228ee53cb8446632adbace23f1c08c89d2e 100644 (file)
@@ -204,35 +204,6 @@ w32_close_socket(int fd)
     return result;
 }
 
-/*
- * WIN32 equivalent for getpass
- */
-char *
-getpass(char *prompt)
-{
-    static char tmp[128];
-    int len;
-    char *cpass;
-    DWORD mode;
-    HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
-
-    if (GetConsoleMode(input_handle, &mode))
-       SetConsoleMode(input_handle, mode & ~ENABLE_ECHO_INPUT);
-    else
-       printf("Note: This is echoed to the screen\n");
-    printf("%s", prompt);
-    fflush(stdout);
-    cpass = fgets(tmp, sizeof(tmp), stdin);
-    if (GetConsoleMode(input_handle, &mode))
-       SetConsoleMode(input_handle, mode | ENABLE_ECHO_INPUT);
-    if (cpass == NULL)
-       return NULL;
-    len = strlen(cpass);
-    if (tmp[len - 1] == '\n')
-       tmp[len - 1] = 0;
-    return cpass;
-}
-
 /*
  * POSIX compatible open() replacement
  */
index b5f2f719e52b1d76eb9cd84b2065ff1fbac02648..0d576314352d4026cbf755b314a4f1d6df3e5816 100644 (file)
@@ -75,7 +75,6 @@ extern int w32_openfd(const char *fname, int oflag, ...);
 extern int w32_openhandle(const char *fname, int oflag);
 
 extern struct passwd *w32_getpw(void);
-extern char *getpass(char *prompt);
 extern void sysdep_init(void);
 
 #define recv(sock, buffer, buf_size, flags) \