From db2e4b891652368329c2ec7c7c8fc6fdb966e57e Mon Sep 17 00:00:00 2001 From: chombier <> Date: Thu, 5 Jul 2001 14:11:39 +0000 Subject: [PATCH] check that terminal is still opened before asking for password --- macssh/source/ssh/ssh2.c | 86 +++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/macssh/source/ssh/ssh2.c b/macssh/source/ssh/ssh2.c index 0f8f9e4..cab470d 100755 --- a/macssh/source/ssh/ssh2.c +++ b/macssh/source/ssh/ssh2.c @@ -847,29 +847,36 @@ char *getpass( const char *prompt ) return password; } LockDialog(); - context->_pindex = index; - if ( gApplicationPrefs->cachePassphrase && !wind->sshdata.password[0] - && getnextcachedpassphrase(cprompt, password, &context->_pindex) ) { - UnlockDialog(); - return password; - } - if ( wind->sshdata.password[0] ) { - memcpy(password, wind->sshdata.password + 1, wind->sshdata.password[0]); - password[wind->sshdata.password[0]] = '\0'; - wind->sshdata.password[0] = '\0'; - valid = 1; - } else { - ppassword[0] = 0; - valid = SSH2PasswordDialog(prompt, ppassword, wind->wind); + /* may need to reload the window... */ + wind = ssh2_window(); + if ( wind ) { + context->_pindex = index; + if ( gApplicationPrefs->cachePassphrase && !wind->sshdata.password[0] + && getnextcachedpassphrase(cprompt, password, &context->_pindex) ) { + UnlockDialog(); + return password; + } + if ( wind->sshdata.password[0] ) { + memcpy(password, wind->sshdata.password + 1, wind->sshdata.password[0]); + password[wind->sshdata.password[0]] = '\0'; + wind->sshdata.password[0] = '\0'; + valid = 1; + } else { + ppassword[0] = 0; + valid = SSH2PasswordDialog(prompt, ppassword, wind->wind); + if (valid) { + memcpy(password, ppassword + 1, ppassword[0]); + password[ppassword[0]] = '\0'; + } + } if (valid) { - memcpy(password, ppassword + 1, ppassword[0]); - password[ppassword[0]] = '\0'; - } - } - if (valid) { - if ( gApplicationPrefs->cachePassphrase ) { - addcachedpassphrase(context, cprompt, password); + if ( gApplicationPrefs->cachePassphrase ) { + addcachedpassphrase(context, cprompt, password); + } } + } else { + // terminal has been closed + valid = 0; } } else { @@ -883,23 +890,28 @@ char *getpass( const char *prompt ) return context->_kpassword; } LockDialog(); - context->_kindex = index; - if ( gApplicationPrefs->cachePassphrase - && getnextcachedpassphrase(prompt, context->_kpassword, &context->_kindex) ) { - UnlockDialog(); - return context->_kpassword; - } - term = ( wind ) ? wind->wind : NULL; - context->_kpassword[0] = 0; - valid = SSH2PasswordDialog(prompt, (StringPtr)context->_kpassword, term); - if (valid) { - plen = context->_kpassword[0]; - password = (wind != NULL) ? wind->sshdata.currentpass : context->_kpassword; - memcpy(password, context->_kpassword + 1, plen); - password[plen] = '\0'; - if ( gApplicationPrefs->cachePassphrase ) { - addcachedpassphrase(context, prompt, password); + if (wind == ssh2_window()) { + context->_kindex = index; + if ( gApplicationPrefs->cachePassphrase + && getnextcachedpassphrase(prompt, context->_kpassword, &context->_kindex) ) { + UnlockDialog(); + return context->_kpassword; } + term = ( wind ) ? wind->wind : NULL; + context->_kpassword[0] = 0; + valid = SSH2PasswordDialog(prompt, (StringPtr)context->_kpassword, term); + if (valid) { + plen = context->_kpassword[0]; + password = (wind != NULL) ? wind->sshdata.currentpass : context->_kpassword; + memcpy(password, context->_kpassword + 1, plen); + password[plen] = '\0'; + if ( gApplicationPrefs->cachePassphrase ) { + addcachedpassphrase(context, prompt, password); + } + } + } else { + // terminal has been closed + valid = 0; } } UnlockDialog();