From ccd886feb40b89eb3b4a00d126806a1e81f4e5da Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 10 Oct 2009 11:55:42 +0200 Subject: [PATCH] Added auth callback function to sample to test callback stuff. --- examples/sample.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/examples/sample.c b/examples/sample.c index c2aaa66e..0a8cc868 100644 --- a/examples/sample.c +++ b/examples/sample.c @@ -28,6 +28,7 @@ clients must be made or how a client should react. #include #include #include +#include #include #include @@ -41,6 +42,32 @@ char *cmds[MAXCMD]; struct termios terminal; void do_sftp(ssh_session session); +static int auth_callback(const char *prompt, char *buf, size_t len, + int echo, int verify, void *userdata) { + char *answer = NULL; + char *ptr; + + (void) verify; + (void) userdata; + + if (echo) { + while ((answer = fgets(buf, len, stdin)) == NULL); + if ((ptr = strchr(buf, '\n'))) { + ptr = '\0'; + } + } else { + answer = getpass(prompt); + } + + if (answer == NULL) { + return -1; + } + + strncpy(buf, answer, len); + + return 0; +} + static void add_cmd(char *cmd){ int n; for(n=0;cmds[n] && (nauth_function = auth_callback; + cb->userdata = NULL; + + ssh_callbacks_init(cb); + ssh_set_callbacks(session, cb); + if(ssh_options_getopt(session, &argc, argv)) { fprintf(stderr, "error parsing command line :%s\n", ssh_get_error(session));