client: Move get_password() from login.c to getpass.c
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
f7ae50261f
commit
c1f1344afe
4 changed files with 86 additions and 43 deletions
|
@ -38,47 +38,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "misc.h"
|
||||
#include "proto.h"
|
||||
|
||||
static char *
|
||||
get_password(const char *prompt)
|
||||
{
|
||||
#ifdef HAVE_GETPASS
|
||||
return getpass(prompt);
|
||||
#else
|
||||
static char buf[128];
|
||||
char *p;
|
||||
size_t len;
|
||||
#ifdef _WIN32
|
||||
DWORD mode;
|
||||
HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
if (GetConsoleMode(input_handle, &mode))
|
||||
SetConsoleMode(input_handle, mode & ~ENABLE_ECHO_INPUT);
|
||||
else
|
||||
#endif
|
||||
printf("Note: your input is echoed to the screen\n");
|
||||
printf("%s", prompt);
|
||||
fflush(stdout);
|
||||
p = fgets(buf, sizeof(buf), stdin);
|
||||
#ifdef _WIN32
|
||||
if (GetConsoleMode(input_handle, &mode))
|
||||
SetConsoleMode(input_handle, mode | ENABLE_ECHO_INPUT);
|
||||
#endif
|
||||
if (!p)
|
||||
return NULL;
|
||||
len = strlen(p);
|
||||
if (p[len - 1] == '\n')
|
||||
p[len - 1] = 0;
|
||||
return p;
|
||||
#endif /* !HAVE_GETPASS */
|
||||
}
|
||||
|
||||
int
|
||||
login(int s, char *uname, char *cname, char *cpass,
|
||||
int kill_proc, int utf8)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue