1
1

Added auth callback function to sample to test callback stuff.

Этот коммит содержится в:
Andreas Schneider 2009-10-10 11:55:42 +02:00
родитель b1bc283e9a
Коммит ccd886feb4

Просмотреть файл

@ -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));