diff options
author | Simon Tatham <anakin@pobox.com> | 2005-02-17 21:34:24 +0300 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2005-02-17 21:34:24 +0300 |
commit | 8574822b9b340fbfa9246c309fdfc803c970ea90 (patch) | |
tree | 6eb81ecd7bb04dc8178472e20eeabd79e2fc3429 /unix | |
parent | 92ccb964a2a2dcbc953e18c8bda2f95a30364367 (diff) |
Revamp interface to verify_ssh_host_key() and askalg(). Each of them
now returns an integer: 0 means cancel the SSH connection and 1
means continue with it. Additionally, they can return -1, which
means `front end has set an asynchronous alert box in motion, please
wait to be called back with the result', and each one is passed a
callback function pointer and context for this purpose.
I have not yet done the same to askappend() yet, because it will
take a certain amount of reorganisation of logging.c.
Importantly, this checkin means the host key dialog box now works on
OS X.
[originally from svn r5330]
Diffstat (limited to 'unix')
-rw-r--r-- | unix/gtkdlg.c | 23 | ||||
-rw-r--r-- | unix/uxcons.c | 23 |
2 files changed, 27 insertions, 19 deletions
diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 2a293804..2ef18313 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -2294,8 +2294,9 @@ int reallyclose(void *frontend) return ret; } -void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, - char *keystr, char *fingerprint) +int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, + char *keystr, char *fingerprint, + void (*callback)(void *ctx, int result), void *ctx) { static const char absenttxt[] = "The server's host key is not cached. You have no guarantee " @@ -2332,7 +2333,7 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, ret = verify_host_key(host, port, keytype, keystr); if (ret == 0) /* success - key matched OK */ - return; + return 1; text = dupprintf((ret == 2 ? wrongtxt : absenttxt), keytype, fingerprint); @@ -2347,16 +2348,20 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, sfree(text); if (ret == 0) - cleanup_exit(0); - else if (ret == 2) - store_host_key(host, port, keytype, keystr); + return 0; /* do not continue with connection */ + else { + if (ret == 2) + store_host_key(host, port, keytype, keystr); + return 1; /* continue with connection */ + } } /* * Ask whether the selected algorithm is acceptable (since it was * below the configured 'warn' threshold). */ -void askalg(void *frontend, const char *algtype, const char *algname) +int askalg(void *frontend, const char *algtype, const char *algname, + void (*callback)(void *ctx, int result), void *ctx) { static const char msg[] = "The first %s supported by the server is " @@ -2375,9 +2380,9 @@ void askalg(void *frontend, const char *algtype, const char *algname) sfree(text); if (ret) { - return; + return 1; } else { - cleanup_exit(0); + return 0; } } diff --git a/unix/uxcons.c b/unix/uxcons.c index 7f05d1fa..ef2866cc 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -47,8 +47,9 @@ void timer_change_notify(long next) { } -void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, - char *keystr, char *fingerprint) +int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, + char *keystr, char *fingerprint, + void (*callback)(void *ctx, int result), void *ctx) { int ret; @@ -107,12 +108,12 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, ret = verify_host_key(host, port, keytype, keystr); if (ret == 0) /* success - key matched OK */ - return; + return 1; if (ret == 2) { /* key was different */ if (console_batch_mode) { fprintf(stderr, wrongmsg_batch, keytype, fingerprint); - cleanup_exit(1); + return 0; } fprintf(stderr, wrongmsg, keytype, fingerprint); fflush(stderr); @@ -120,7 +121,7 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, if (ret == 1) { /* key was absent */ if (console_batch_mode) { fprintf(stderr, absentmsg_batch, keytype, fingerprint); - cleanup_exit(1); + return 0; } fprintf(stderr, absentmsg, keytype, fingerprint); fflush(stderr); @@ -140,9 +141,10 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, if (line[0] != '\0' && line[0] != '\r' && line[0] != '\n') { if (line[0] == 'y' || line[0] == 'Y') store_host_key(host, port, keytype, keystr); + return 1; } else { fprintf(stderr, abandoned); - cleanup_exit(0); + return 0; } } @@ -150,7 +152,8 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, * Ask whether the selected algorithm is acceptable (since it was * below the configured 'warn' threshold). */ -void askalg(void *frontend, const char *algtype, const char *algname) +int askalg(void *frontend, const char *algtype, const char *algname, + void (*callback)(void *ctx, int result), void *ctx) { static const char msg[] = "The first %s supported by the server is\n" @@ -166,7 +169,7 @@ void askalg(void *frontend, const char *algtype, const char *algname) if (console_batch_mode) { fprintf(stderr, msg_batch, algtype, algname); - cleanup_exit(1); + return 0; } fprintf(stderr, msg, algtype, algname); @@ -184,10 +187,10 @@ void askalg(void *frontend, const char *algtype, const char *algname) } if (line[0] == 'y' || line[0] == 'Y') { - return; + return 1; } else { fprintf(stderr, abandoned); - cleanup_exit(0); + return 0; } } |