Blame


1 d93fca6a 2005-02-11 devnull .TH READCONS 3
2 d93fca6a 2005-02-11 devnull .SH NAME
3 d93fca6a 2005-02-11 devnull readcons \- prompt console for input
4 d93fca6a 2005-02-11 devnull .SH SYNOPSIS
5 d93fca6a 2005-02-11 devnull .B
6 d93fca6a 2005-02-11 devnull #include <u.h>
7 d93fca6a 2005-02-11 devnull .PP
8 d93fca6a 2005-02-11 devnull .B
9 d93fca6a 2005-02-11 devnull #include <libc.h>
10 d93fca6a 2005-02-11 devnull .PP
11 d93fca6a 2005-02-11 devnull .B
12 d93fca6a 2005-02-11 devnull char *readcons(char *prompt, char *def, int secret)
13 d93fca6a 2005-02-11 devnull .SH DESCRIPTION
14 d93fca6a 2005-02-11 devnull .I Readcons
15 d93fca6a 2005-02-11 devnull prompts at the console for input.
16 d93fca6a 2005-02-11 devnull It returns a NUL-terminated buffer containing the input
17 d93fca6a 2005-02-11 devnull without a final newline.
18 d93fca6a 2005-02-11 devnull The buffer should be freed (and perhaps cleared first)
19 d93fca6a 2005-02-11 devnull when no longer needed.
20 d93fca6a 2005-02-11 devnull .PP
21 d93fca6a 2005-02-11 devnull If the user types an empty string (just a newline) and
22 d93fca6a 2005-02-11 devnull .I def
23 d93fca6a 2005-02-11 devnull is non-zero, then a copy of
24 d93fca6a 2005-02-11 devnull .I def
25 d93fca6a 2005-02-11 devnull is returned instead of the empty string.
26 d93fca6a 2005-02-11 devnull .PP
27 d93fca6a 2005-02-11 devnull If
28 d93fca6a 2005-02-11 devnull .I secret
29 d93fca6a 2005-02-11 devnull is non-zero, the input is not echoed to the screen.
30 d93fca6a 2005-02-11 devnull .SH EXAMPLE
31 d93fca6a 2005-02-11 devnull A stripped-down version of
32 30f6ae14 2005-02-13 devnull .I netkey
33 30f6ae14 2005-02-13 devnull (see
34 d32deab1 2020-08-16 rsc .MR passwd (1) ):
35 d93fca6a 2005-02-11 devnull .IP
36 d93fca6a 2005-02-11 devnull .EX
37 d93fca6a 2005-02-11 devnull pass = readcons("password", nil, 1);
38 d93fca6a 2005-02-11 devnull passtokey(key, pass);
39 d93fca6a 2005-02-11 devnull memset(pass, 0, strlen(pass));
40 d93fca6a 2005-02-11 devnull free(pass);
41 d93fca6a 2005-02-11 devnull for(;;){
42 d93fca6a 2005-02-11 devnull chal = readcons("challenge", nil, 0);
43 d93fca6a 2005-02-11 devnull sprint(buf, "%d", strtol(chal, 0, 10));
44 d93fca6a 2005-02-11 devnull free(chal);
45 d93fca6a 2005-02-11 devnull netcrypt(key, buf);
46 d93fca6a 2005-02-11 devnull print("response: %s\n", buf);
47 d93fca6a 2005-02-11 devnull }
48 d93fca6a 2005-02-11 devnull .EE
49 d93fca6a 2005-02-11 devnull .SH SOURCE
50 d93fca6a 2005-02-11 devnull .B \*9/src/lib9/readcons.c