MCPcopy Create free account
hub / github.com/ElementsProject/lightning / read_stdin_pass_with_exit_code

Function read_stdin_pass_with_exit_code

common/hsm_encryption.c:115–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115char *read_stdin_pass_with_exit_code(char **reason, int *exit_code)
116{
117 struct termios current_term, temp_term;
118 char *passwd = NULL;
119 size_t passwd_size = 0;
120
121 if (isatty(fileno(stdin))) {
122 /* Set a temporary term, same as current but with ECHO disabled. */
123 if (tcgetattr(fileno(stdin), &current_term) != 0) {
124 *reason = "Could not get current terminal options.";
125 *exit_code = EXITCODE_HSM_PASSWORD_INPUT_ERR;
126 return NULL;
127 }
128 temp_term = current_term;
129 temp_term.c_lflag &= ~ECHO;
130 if (tcsetattr(fileno(stdin), TCSANOW, &temp_term) != 0) {
131 *reason = "Could not disable pass echoing.";
132 *exit_code = EXITCODE_HSM_PASSWORD_INPUT_ERR;
133 return NULL;
134 }
135
136 if (!getline_stdin_pass(&passwd, &passwd_size)) {
137 *reason = "Could not read pass from stdin.";
138 *exit_code = EXITCODE_HSM_PASSWORD_INPUT_ERR;
139 return NULL;
140 }
141
142 /* Restore the original terminal */
143 if (tcsetattr(fileno(stdin), TCSANOW, &current_term) != 0) {
144 *reason = "Could not restore terminal options.";
145 free(passwd);
146 *exit_code = EXITCODE_HSM_PASSWORD_INPUT_ERR;
147 return NULL;
148 }
149 } else if (!getline_stdin_pass(&passwd, &passwd_size)) {
150 *reason = "Could not read pass from stdin.";
151 *exit_code = EXITCODE_HSM_PASSWORD_INPUT_ERR;
152 return NULL;
153 }
154 return passwd;
155}

Callers 8

decrypt_hsmFunction · 0.85
encrypt_hsmFunction · 0.85
dump_commitments_infosFunction · 0.85
guess_to_remoteFunction · 0.85
generate_hsmFunction · 0.85
dumponchaindescriptorsFunction · 0.85
check_hsmFunction · 0.85
opt_set_hsm_passwordFunction · 0.85

Calls 1

getline_stdin_passFunction · 0.85

Tested by

no test coverage detected