MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / get_password

Function get_password

cppcryptfsctl/cppcryptfsctl.cpp:71–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71static int get_password(LockZeroBuffer<wchar_t>& password, const wchar_t *password_prompt, const wchar_t *repeat_prompt = nullptr)
72{
73 if (_isatty(_fileno(stdin))) {
74
75 LockZeroBuffer<wchar_t> password2(PASSWORD_BUFLEN, false);
76
77 if (!password2.IsLocked()) {
78 wcerr << L"unable to lock repeat password buffer\n";
79 return 1;
80 }
81
82 // prompt for password
83 if (!read_password(password.m_buf, password.m_len, password_prompt)) {
84 wcerr << L"error reading password" << endl;
85 return 1;
86 }
87 if (repeat_prompt) {
88 // prompt for repeat password
89 if (!read_password(password2.m_buf, password2.m_len, repeat_prompt)) {
90 wcerr << L"error reading repeat password" << endl;
91 return 1;
92 }
93 if (wcscmp(password.m_buf, password2.m_buf) != 0) {
94 wcerr << L"passwords do not match" << endl;
95 return 1;
96 }
97 }
98 } else {
99 // we have stdin redirected, so read password from stdin
100 std::wcout << L"Reading password from stdin" << endl;
101 if (!fgetws(password.m_buf, password.m_len, stdin)) {
102 wcerr << "unable to read password from stdin\n";
103 return 1;
104 }
105 if (wcslen(password.m_buf) > 0 && password.m_buf[wcslen(password.m_buf) - 1] == L'\n') {
106 password.m_buf[wcslen(password.m_buf) - 1] = L'\0';
107 }
108 }
109
110 return 0;
111}
112
113static void GetConfigPath(wstring& path)
114{

Callers 2

do_self_argsFunction · 0.85
wmainFunction · 0.85

Calls 2

read_passwordFunction · 0.85
IsLockedMethod · 0.80

Tested by

no test coverage detected