/* * Similar interface to seat_get_userpass_input(), except that here a * -1 return means that we aren't capable of processing the prompt and * someone else should do it. */ int cmdline_get_passwd_input(prompts_t *p) { static bool tried_once = false; /* * We only handle prompts which don't echo (which we assume to be * passwords), and (currently) we only cope with a password prompt * that comes in a prompt-set on its own. */ if (!cmdline_password || p->n_prompts != 1 || p->prompts[0]->echo) { return -1; } /* * If we've tried once, return utter failure (no more passwords left * to try). */ if (tried_once) return 0; prompt_set_result(p->prompts[0], cmdline_password); smemclr(cmdline_password, strlen(cmdline_password)); sfree(cmdline_password); cmdline_password = NULL; tried_once = true; return 1; }
int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen) { size_t curr_prompt; /* * Zero all the results, in case we abort half-way through. */ { int i; for (i = 0; i < (int)p->n_prompts; i++) prompt_set_result(p->prompts[i], ""); } if (console_batch_mode) return 0; for (curr_prompt = 0; curr_prompt < p->n_prompts; curr_prompt++) { prompt_t *pr = p->prompts[curr_prompt]; if (!DoLoginDialog(pr->result, pr->resultsize-1, pr->prompt)) return 0; } return 1; /* success */ }
//--------------------------------------------------------------------------- int get_userpass_input(prompts_t * p, unsigned char * /*in*/, int /*inlen*/) { assert(p != NULL); TSecureShell * SecureShell = reinterpret_cast<TSecureShell *>(p->frontend); assert(SecureShell != NULL); int Result; TStrings * Prompts = new TStringList(); TStrings * Results = new TStringList(); try { for (int Index = 0; Index < int(p->n_prompts); Index++) { prompt_t * Prompt = p->prompts[Index]; Prompts->AddObject(Prompt->prompt, (TObject *)(FLAGMASK(Prompt->echo, pupEcho))); // this fails, when new passwords do not match on change password prompt, // and putty retries the prompt assert(Prompt->resultsize == 0); Results->Add(L""); } if (SecureShell->PromptUser(p->to_server, p->name, p->name_reqd, p->instruction, p->instr_reqd, Prompts, Results)) { for (int Index = 0; Index < int(p->n_prompts); Index++) { prompt_t * Prompt = p->prompts[Index]; prompt_set_result(Prompt, AnsiString(Results->Strings[Index]).c_str()); } Result = 1; } else { Result = 0; } } __finally { delete Prompts; delete Results; } return Result; }
int GetUserpassInput(prompts_t * p, const uint8_t * /*in*/, int /*inlen*/) { assert(p != nullptr); TSecureShell * SecureShell = NB_STATIC_DOWNCAST(TSecureShell, p->frontend); assert(SecureShell != nullptr); int Result; std::unique_ptr<TStrings> Prompts(new TStringList()); std::unique_ptr<TStrings> Results(new TStringList()); { for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; Prompts->AddObject(Prompt->prompt, reinterpret_cast<TObject *>(static_cast<size_t>(FLAGMASK(Prompt->echo, pupEcho)))); // this fails, when new passwords do not match on change password prompt, // and putty retries the prompt assert(Prompt->resultsize == 0); Results->Add(L""); } if (SecureShell->PromptUser(p->to_server != 0, p->name, p->name_reqd != 0, UnicodeString(p->instruction), p->instr_reqd != 0, Prompts.get(), Results.get())) { for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; prompt_set_result(Prompt, AnsiString(Results->GetString(Index).c_str()).c_str()); } Result = 1; } else { Result = 0; } } return Result; }
int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen) { HANDLE hin, hout; size_t curr_prompt; /* * Zero all the results, in case we abort half-way through. */ { int i; for (i = 0; i < (int)p->n_prompts; i++) prompt_set_result(p->prompts[i], ""); } /* * The prompts_t might contain a message to be displayed but no * actual prompt. More usually, though, it will contain * questions that the user needs to answer, in which case we * need to ensure that we're able to get the answers. */ if (p->n_prompts) { if (console_batch_mode) return 0; hin = GetStdHandle(STD_INPUT_HANDLE); if (hin == INVALID_HANDLE_VALUE) { fprintf(stderr, "Cannot get standard input handle\n"); cleanup_exit(1); } } /* * And if we have anything to print, we need standard output. */ if ((p->name_reqd && p->name) || p->instruction || p->n_prompts) { hout = GetStdHandle(STD_OUTPUT_HANDLE); if (hout == INVALID_HANDLE_VALUE) { fprintf(stderr, "Cannot get standard output handle\n"); cleanup_exit(1); } } /* * Preamble. */ /* We only print the `name' caption if we have to... */ if (p->name_reqd && p->name) { size_t l = strlen(p->name); console_data_untrusted(hout, p->name, l); if (p->name[l-1] != '\n') console_data_untrusted(hout, "\n", 1); } /* ...but we always print any `instruction'. */ if (p->instruction) { size_t l = strlen(p->instruction); console_data_untrusted(hout, p->instruction, l); if (p->instruction[l-1] != '\n') console_data_untrusted(hout, "\n", 1); } for (curr_prompt = 0; curr_prompt < p->n_prompts; curr_prompt++) { DWORD savemode, newmode; int len; prompt_t *pr = p->prompts[curr_prompt]; GetConsoleMode(hin, &savemode); newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT; if (!pr->echo) newmode &= ~ENABLE_ECHO_INPUT; else newmode |= ENABLE_ECHO_INPUT; SetConsoleMode(hin, newmode); console_data_untrusted(hout, pr->prompt, strlen(pr->prompt)); len = 0; while (1) { DWORD ret = 0; BOOL r; prompt_ensure_result_size(pr, len * 5 / 4 + 512); r = ReadFile(hin, pr->result + len, pr->resultsize - len - 1, &ret, NULL); if (!r || ret == 0) { len = -1; break; } len += ret; if (pr->result[len - 1] == '\n') { len--; if (pr->result[len - 1] == '\r') len--; break; } } SetConsoleMode(hin, savemode); if (!pr->echo) { DWORD dummy; WriteFile(hout, "\r\n", 2, &dummy, NULL); } if (len < 0) { return 0; /* failure due to read error */ } pr->result[len] = '\0'; } return 1; /* success */ }
int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen) { size_t curr_prompt; FILE *outfp = NULL; int infd; /* * Zero all the results, in case we abort half-way through. */ { int i; for (i = 0; i < p->n_prompts; i++) prompt_set_result(p->prompts[i], ""); } if (p->n_prompts && console_batch_mode) return 0; console_open(&outfp, &infd); /* * Preamble. */ /* We only print the `name' caption if we have to... */ if (p->name_reqd && p->name) { size_t l = strlen(p->name); console_prompt_text(outfp, p->name, l); if (p->name[l-1] != '\n') console_prompt_text(outfp, "\n", 1); } /* ...but we always print any `instruction'. */ if (p->instruction) { size_t l = strlen(p->instruction); console_prompt_text(outfp, p->instruction, l); if (p->instruction[l-1] != '\n') console_prompt_text(outfp, "\n", 1); } for (curr_prompt = 0; curr_prompt < p->n_prompts; curr_prompt++) { struct termios oldmode, newmode; int len; prompt_t *pr = p->prompts[curr_prompt]; tcgetattr(infd, &oldmode); newmode = oldmode; newmode.c_lflag |= ISIG | ICANON; if (!pr->echo) newmode.c_lflag &= ~ECHO; else newmode.c_lflag |= ECHO; tcsetattr(infd, TCSANOW, &newmode); console_prompt_text(outfp, pr->prompt, strlen(pr->prompt)); len = 0; while (1) { int ret; prompt_ensure_result_size(pr, len * 5 / 4 + 512); ret = read(infd, pr->result + len, pr->resultsize - len - 1); if (ret <= 0) { len = -1; break; } len += ret; if (pr->result[len - 1] == '\n') { len--; break; } } tcsetattr(infd, TCSANOW, &oldmode); if (!pr->echo) console_prompt_text(outfp, "\n", 1); if (len < 0) { console_close(outfp, infd); return 0; /* failure due to read error */ } pr->result[len] = '\0'; } console_close(outfp, infd); return 1; /* success */ }
int GetUserpassInput(prompts_t * p, const uint8_t * /*in*/, int /*inlen*/) { DebugAssert(p != nullptr); TSecureShell * SecureShell = NB_STATIC_DOWNCAST(TSecureShell, p->frontend); DebugAssert(SecureShell != nullptr); int Result; std::unique_ptr<TStrings> Prompts(new TStringList()); std::unique_ptr<TStrings> Results(new TStringList()); { UnicodeString Name = UTF8ToString(p->name); UnicodeString AName = Name; TPromptKind PromptKind = SecureShell->IdentifyPromptKind(AName); bool UTF8Prompt = (PromptKind != pkPassphrase); for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; UnicodeString S; if (UTF8Prompt) { S = UTF8ToString(Prompt->prompt); } else { S = UnicodeString(AnsiString(Prompt->prompt)); } Prompts->AddObject(S, reinterpret_cast<TObject *>(static_cast<size_t>(FLAGMASK(Prompt->echo, pupEcho)))); // this fails, when new passwords do not match on change password prompt, // and putty retries the prompt DebugAssert(Prompt->resultsize == 0); Results->Add(L""); } UnicodeString Instructions = UTF8ToString(p->instruction); if (SecureShell->PromptUser(p->to_server != 0, Name, p->name_reqd != 0, Instructions, p->instr_reqd != 0, Prompts.get(), Results.get())) { for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; RawByteString S; if (UTF8Prompt) { S = RawByteString(UTF8String(Results->GetString(Index))); } else { S = RawByteString(AnsiString(Results->GetString(Index))); } prompt_set_result(Prompt, S.c_str()); } Result = 1; } else { Result = 0; } } __finally { // delete Prompts; // delete Results; }; return Result; }