@@ -25,6 +25,7 @@ typedef struct {
2525
2626 const char * passPrompt ;
2727 int verbose ;
28+ int autoConfirm ;
2829
2930 wchar_t * cmd ;
3031} Args ;
@@ -191,6 +192,7 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
191192
192193 const char * passPrompt = NULL ;
193194 int verbose = 0 ;
195+ int autoConfirm = 0 ;
194196 int totalArgc = argc ;
195197
196198 struct argparse_option options [] = {
@@ -208,6 +210,7 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
208210 "Which string should sshpass search for to detect a password prompt" , NULL ,
209211 0 , 0 ),
210212 OPT_BOOLEAN ('v' , NULL , & verbose , "Be verbose about what you're doing" , NULL , 0 , 0 ),
213+ OPT_BOOLEAN ('k' , "auto-confirm" , & autoConfirm , "Auto confirm 'Are you sure...' prompt for host keys" , NULL , 0 , 0 ),
211214 OPT_END (),
212215 };
213216
@@ -220,6 +223,7 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
220223 }
221224
222225 ctx -> args .verbose = verbose ;
226+ ctx -> args .autoConfirm = autoConfirm ;
223227 if (filename != NULL ) {
224228 ctx -> args .pwtype = PWT_FILE ;
225229 ctx -> args .pwsrc .filename = ToUtf16 (filename );
@@ -331,12 +335,23 @@ static BOOL IsWaitInputPass(Context* ctx, const char* buffer, DWORD len) {
331335 return TRUE;
332336}
333337
338+ static BOOL IsWaitConfirmation (const char * buffer ) {
339+ /* prompt: "Are you sure you want to continue connecting (yes/no/[fingerprint])?" */
340+ if (strstr (buffer , "Are you sure you want to continue connecting" ) != NULL ) {
341+ return TRUE;
342+ }
343+ return FALSE;
344+ }
345+
334346typedef enum { INIT , VERIFY , EXEC , END } State ;
335347
336348static State ProcessOutput (Context * ctx , const char * buffer , DWORD len , State state ) {
337349 State nextState ;
338350 switch (state ) {
339351 case INIT : {
352+ if (ctx -> args .autoConfirm && IsWaitConfirmation (buffer )) {
353+ WriteFile (ctx -> pipeOut , "yes\n" , 4 , NULL , NULL );
354+ }
340355 if (!IsWaitInputPass (ctx , buffer , len )) {
341356 nextState = INIT ;
342357 } else {
0 commit comments