aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-10-10 11:55:42 +0200
committerAndreas Schneider <mail@cynapses.org>2009-10-10 11:55:42 +0200
commitccd886feb40b89eb3b4a00d126806a1e81f4e5da (patch)
treea8935dedc03fa00f08abf4e4606a2de9612526c2 /examples
parentb1bc283e9a37333c3989e263421761e4611ccbfe (diff)
downloadlibssh-ccd886feb40b89eb3b4a00d126806a1e81f4e5da.tar.gz
libssh-ccd886feb40b89eb3b4a00d126806a1e81f4e5da.tar.xz
libssh-ccd886feb40b89eb3b4a00d126806a1e81f4e5da.zip
Added auth callback function to sample to test callback stuff.
Diffstat (limited to 'examples')
-rw-r--r--examples/sample.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/sample.c b/examples/sample.c
index c2aaa66..0a8cc86 100644
--- a/examples/sample.c
+++ b/examples/sample.c
@@ -28,6 +28,7 @@ clients must be made or how a client should react.
#include <sys/ioctl.h>
#include <signal.h>
#include <errno.h>
+#include <libssh/callbacks.h>
#include <libssh/libssh.h>
#include <libssh/sftp.h>
@@ -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] && (n<MAXCMD);n++);
@@ -510,9 +537,18 @@ int main(int argc, char **argv){
char buf[10];
unsigned char *hash = NULL;
int hlen;
+ ssh_callbacks cb;
session = ssh_new();
+ cb = malloc(sizeof(ssh_callbacks));
+
+ cb->auth_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));