Skip to content

Commit 00d660c

Browse files
authored
Merge pull request #13 from lxb007981/main
feat: Add option to auto confirm host key check
2 parents cf9f04c + b1605cc commit 00d660c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Password options: With no options - password will be taken from stdin
3232
Other options:
3333
-P=<str> Which string should sshpass search for to detect a password prompt
3434
-v Be verbose about what you're doing
35+
-k Auto confirm 'Are you sure...' prompt for host keys
3536
```
3637
3738
# Examples

main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct {
2525

2626
const char* passPrompt;
2727
int verbose;
28+
int autoConfirm;
2829

2930
wchar_t* cmd;
3031
} Args;
@@ -204,6 +205,7 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
204205

205206
const char* passPrompt = NULL;
206207
int verbose = 0;
208+
int autoConfirm = 0;
207209
int totalArgc = argc;
208210

209211
struct argparse_option options[] = {
@@ -221,6 +223,7 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
221223
"Which string should sshpass search for to detect a password prompt", NULL,
222224
0, 0),
223225
OPT_BOOLEAN('v', NULL, &verbose, "Be verbose about what you're doing", NULL, 0, 0),
226+
OPT_BOOLEAN('k', "auto-confirm", &autoConfirm, "Auto confirm 'Are you sure...' prompt for host keys", NULL, 0, 0),
224227
OPT_END(),
225228
};
226229

@@ -233,6 +236,7 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
233236
}
234237

235238
ctx->args.verbose = verbose;
239+
ctx->args.autoConfirm = autoConfirm;
236240
if (filename != NULL) {
237241
ctx->args.pwtype = PWT_FILE;
238242
ctx->args.pwsrc.filename = ToUtf16(filename);
@@ -344,13 +348,24 @@ static BOOL IsWaitInputPass(Context* ctx, const char* buffer, DWORD len) {
344348
return TRUE;
345349
}
346350

351+
static BOOL IsWaitConfirmation(const char* buffer) {
352+
/* prompt: "Are you sure you want to continue connecting (yes/no/[fingerprint])?" */
353+
if (strstr(buffer, "Are you sure you want to continue connecting") != NULL) {
354+
return TRUE;
355+
}
356+
return FALSE;
357+
}
358+
347359
typedef enum { INIT, VERIFY, EXEC, END } State;
348360

349361
static State ProcessOutput(Context* ctx, const char* buffer, DWORD len, State state) {
350362
State nextState;
351363
DWORD written;
352364
switch (state) {
353365
case INIT: {
366+
if (ctx->args.autoConfirm && IsWaitConfirmation(buffer)) {
367+
WriteFile(ctx->pipeOut, "yes\n", 4, NULL, NULL);
368+
}
354369
if (!IsWaitInputPass(ctx, buffer, len)) {
355370
nextState = INIT;
356371
} else {

0 commit comments

Comments
 (0)