readpassphrase_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5use std::os::raw::{c_char, c_int};
6
7/// Turn off echo (default).
8pub const RPP_ECHO_OFF: c_int = 0x00;
9
10/// Leave echo on.
11pub const RPP_ECHO_ON: c_int = 0x01;
12
13/// Fail if there is no tty.
14pub const RPP_REQUIRE_TTY: c_int = 0x02;
15
16/// Force input to lower case.
17pub const RPP_FORCELOWER: c_int = 0x04;
18
19/// Force input to upper case.
20pub const RPP_FORCEUPPER: c_int = 0x08;
21
22/// Strip the high bit from input.
23pub const RPP_SEVENBIT: c_int = 0x10;
24
25/// Read from stdin, no /dev/tty
26pub const RPP_STDIN: c_int = 0x20;
27
28/// Supply a prompt to and read password from `/dev/tty`
29///
30/// From `readpassphrase(3)`:
31///
32/// ```no_build
33/// The readpassphrase() function displays a prompt to, and reads in a
34/// passphrase from, /dev/tty. If this file is inaccessible and the
35/// RPP_REQUIRE_TTY flag is not set, readpassphrase() displays the prompt on
36/// the standard error output and reads from the standard input. In this
37/// case it is generally not possible to turn off echo.
38///
39/// Up to bufsiz - 1 characters (one is for the NUL) are read into the
40/// provided buffer buf. Any additional characters and the terminating
41/// newline (or return) character are discarded.
42///
43/// The flags argument is the bitwise OR of zero or more of the following
44/// values:
45///
46///        RPP_ECHO_OFF            turn off echo (default behavior)
47///        RPP_ECHO_ON             leave echo on
48///        RPP_REQUIRE_TTY         fail if there is no tty
49///        RPP_FORCELOWER          force input to lower case
50///        RPP_FORCEUPPER          force input to upper case
51///        RPP_SEVENBIT            strip the high bit from input
52///   	   RPP_STDIN               read passphrase from stdin; ignore prompt
53///
54/// The calling process should zero the passphrase as soon as possible to
55/// avoid leaving the cleartext passphrase visible in the process's address
56/// space.
57///
58///	RETURN VALUES
59///
60/// Upon successful completion, readpassphrase() returns a pointer to the
61/// NUL-terminated passphrase.  If an error is encountered, the terminal
62/// state is restored and a null pointer is returned.
63/// ```
64extern "C" {
65    pub fn readpassphrase(_prompt: *const c_char, _buf: *mut c_char, _bufsiz: usize, _flags: c_int) -> *mut c_char;
66}