@@ -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+
347359typedef enum { INIT , VERIFY , EXEC , END } State ;
348360
349361static 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