summaryrefslogtreecommitdiffstats
path: root/lib/libskey/skey_getpass.c
blob: 51b564baa8793477836d648bfaeaaaeaeb58ccc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <unistd.h>
#include <stdio.h>
#include <skey.h>

/* skey_getpass - read regular or s/key password */

char   *skey_getpass(prompt, pwd, pwok)
char   *prompt;
struct passwd *pwd;
int     pwok;
{
    static char buf[128];
    struct skey skey;
    char   *pass = "";
    char   *username = pwd ? pwd->pw_name : ":";
    int     sflag;

    /* Attempt an s/key challenge. */
    sflag = skeyinfo(&skey, username, buf);
    if (!sflag)
	printf("%s\n", buf);

    if (!pwok) {
	printf("(s/key required)\n");
	if (sflag)
	    return (pass);
    }

    pass = getpass(prompt);

    /* Give S/Key users a chance to do it with echo on. */
    if (!sflag && !feof(stdin) && *pass == '\0') {
	fputs(" (turning echo on)\n", stdout);
	fputs(prompt, stdout);
	fflush(stdout);
	fgets(buf, sizeof(buf), stdin);
	rip(buf);
	return (buf);
    } else
	return (pass);
}
OpenPOWER on IntegriCloud