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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

/// Turn off echo (default).
#[cfg(not(target_os = "openbsd"))]
pub const RPP_ECHO_OFF: i32 = 0x00;

/// Leave echo on.
#[cfg(not(target_os = "openbsd"))]
pub const RPP_ECHO_ON: i32 = 0x01;

/// Fail if there is no tty.
#[cfg(not(target_os = "openbsd"))]
pub const RPP_REQUIRE_TTY: i32 = 0x02;

/// Force input to lower case.
#[cfg(not(target_os = "openbsd"))]
pub const RPP_FORCELOWER: i32 = 0x04;

/// Force input to upper case.
#[cfg(not(target_os = "openbsd"))]
pub const RPP_FORCEUPPER: i32 = 0x08;

/// Strip the high bit from input.
#[cfg(not(target_os = "openbsd"))]
pub const RPP_SEVENBIT: i32 = 0x10;

/// Read from stdin, not /dev/tty
#[cfg(not(target_os = "openbsd"))]
pub const RPP_STDIN: i32 = 0x20;

/// Supply a prompt to and read password from `/dev/tty`
///
/// From `readpassphrase(3)`:
///
/// ```no_build
/// The readpassphrase() function displays a prompt to, and reads in a
/// passphrase from, /dev/tty. If this file is inaccessible and the
/// RPP_REQUIRE_TTY flag is not set, readpassphrase() displays the prompt on
/// the standard error output and reads from the standard input. In this
/// case it is generally not possible to turn off echo.
///
/// Up to bufsiz - 1 characters (one is for the NUL) are read into the
/// provided buffer buf. Any additional characters and the terminating
/// newline (or return) character are discarded.
///
/// The flags argument is the bitwise OR of zero or more of the following
/// values:
///
///        RPP_ECHO_OFF            turn off echo (default behavior)
///        RPP_ECHO_ON             leave echo on
///        RPP_REQUIRE_TTY         fail if there is no tty
///        RPP_FORCELOWER          force input to lower case
///        RPP_FORCEUPPER          force input to upper case
///        RPP_SEVENBIT            strip the high bit from input
///   	   RPP_STDIN               read passphrase from stdin; ignore prompt
///
/// The calling process should zero the passphrase as soon as possible to
/// avoid leaving the cleartext passphrase visible in the process's address
/// space.
///
///	RETURN VALUES
///
/// Upon successful completion, readpassphrase() returns a pointer to the
/// NUL-terminated passphrase.  If an error is encountered, the terminal
/// state is restored and a null pointer is returned.
/// ```
#[cfg(not(target_os = "openbsd"))]
extern "C" {
    pub fn readpassphrase(_prompt: *const libc::c_char, _buf: *mut libc::c_char, _bufsiz: u64, _flags: i32) -> *mut libc::c_char;
}

#[cfg(test)]
mod tests {
}