mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-29 13:01:13 +03:00
Added auth callback function to sample to test callback stuff.
This commit is contained in:
@ -28,6 +28,7 @@ clients must be made or how a client should react.
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <libssh/callbacks.h>
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include <libssh/sftp.h>
|
#include <libssh/sftp.h>
|
||||||
|
|
||||||
@ -41,6 +42,32 @@ char *cmds[MAXCMD];
|
|||||||
struct termios terminal;
|
struct termios terminal;
|
||||||
void do_sftp(ssh_session session);
|
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){
|
static void add_cmd(char *cmd){
|
||||||
int n;
|
int n;
|
||||||
for(n=0;cmds[n] && (n<MAXCMD);n++);
|
for(n=0;cmds[n] && (n<MAXCMD);n++);
|
||||||
@ -510,9 +537,18 @@ int main(int argc, char **argv){
|
|||||||
char buf[10];
|
char buf[10];
|
||||||
unsigned char *hash = NULL;
|
unsigned char *hash = NULL;
|
||||||
int hlen;
|
int hlen;
|
||||||
|
ssh_callbacks cb;
|
||||||
|
|
||||||
session = ssh_new();
|
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)) {
|
if(ssh_options_getopt(session, &argc, argv)) {
|
||||||
fprintf(stderr, "error parsing command line :%s\n",
|
fprintf(stderr, "error parsing command line :%s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
|
Reference in New Issue
Block a user