mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
example, tests: address compiler warnings
Fix or silence all C compiler warnings discovered with (or without) `PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and Windows cross-builds using gcc (12) and llvm/clang (14/15). Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`. Cherry-picked from: #846 Closes #861
This commit is contained in:
@ -11,6 +11,8 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
#define recv(s, b, l, f) recv((s), (b), (int)(l), (f))
|
||||||
|
#define send(s, b, l, f) send((s), (b), (int)(l), (f))
|
||||||
#else
|
#else
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@ -161,7 +163,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password"))
|
if(strstr(userauthlist, "password"))
|
||||||
auth |= AUTH_PASSWORD;
|
auth |= AUTH_PASSWORD;
|
||||||
@ -261,7 +264,7 @@ int main(int argc, char *argv[])
|
|||||||
FD_SET(forwardsock, &fds);
|
FD_SET(forwardsock, &fds);
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 100000;
|
tv.tv_usec = 100000;
|
||||||
rc = select(forwardsock + 1, &fds, NULL, NULL, &tv);
|
rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
|
||||||
if(-1 == rc) {
|
if(-1 == rc) {
|
||||||
perror("select");
|
perror("select");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
@ -279,15 +282,17 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
wr = 0;
|
wr = 0;
|
||||||
while(wr < len) {
|
while(wr < len) {
|
||||||
i = libssh2_channel_write(channel, buf + wr, len - wr);
|
ssize_t nwritten = libssh2_channel_write(channel,
|
||||||
if(LIBSSH2_ERROR_EAGAIN == i) {
|
buf + wr, len - wr);
|
||||||
|
if(nwritten == LIBSSH2_ERROR_EAGAIN) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(i < 0) {
|
if(nwritten < 0) {
|
||||||
fprintf(stderr, "libssh2_channel_write: %d\n", i);
|
fprintf(stderr, "libssh2_channel_write: %d\n",
|
||||||
|
(int)nwritten);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr += i;
|
wr += nwritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(;;) {
|
for(;;) {
|
||||||
@ -300,12 +305,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
wr = 0;
|
wr = 0;
|
||||||
while(wr < len) {
|
while(wr < len) {
|
||||||
i = send(forwardsock, buf + wr, len - wr, 0);
|
ssize_t nsent = send(forwardsock, buf + wr, len - wr, 0);
|
||||||
if(i <= 0) {
|
if(nsent <= 0) {
|
||||||
perror("write");
|
perror("write");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr += i;
|
wr += nsent;
|
||||||
}
|
}
|
||||||
if(libssh2_channel_eof(channel)) {
|
if(libssh2_channel_eof(channel)) {
|
||||||
fprintf(stderr, "The server at %s:%d disconnected!\n",
|
fprintf(stderr, "The server at %s:%d disconnected!\n",
|
||||||
|
@ -36,9 +36,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -159,20 +163,22 @@ int main(int argc, char *argv[])
|
|||||||
while(got < fileinfo.st_size) {
|
while(got < fileinfo.st_size) {
|
||||||
char mem[1024];
|
char mem[1024];
|
||||||
int amount = sizeof(mem);
|
int amount = sizeof(mem);
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
if((fileinfo.st_size -got) < amount) {
|
if((fileinfo.st_size - got) < amount) {
|
||||||
amount = (int)(fileinfo.st_size -got);
|
amount = (int)(fileinfo.st_size - got);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_channel_read(channel, mem, amount);
|
nread = libssh2_channel_read(channel, mem, amount);
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
write(1, mem, rc);
|
write(1, mem, nread);
|
||||||
}
|
}
|
||||||
else if(rc < 0) {
|
else if(nread < 0) {
|
||||||
fprintf(stderr, "libssh2_channel_read() failed: %d\n", rc);
|
fprintf(stderr, "libssh2_channel_read() failed: %d\n",
|
||||||
|
(int)nread);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
got += rc;
|
got += nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
|
@ -44,6 +44,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
/* diff in ms */
|
/* diff in ms */
|
||||||
static long tvdiff(struct timeval newer, struct timeval older)
|
static long tvdiff(struct timeval newer, struct timeval older)
|
||||||
@ -78,14 +82,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -238,6 +242,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
while(got < fileinfo.st_size) {
|
while(got < fileinfo.st_size) {
|
||||||
char mem[1024*24];
|
char mem[1024*24];
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int amount = sizeof(mem);
|
int amount = sizeof(mem);
|
||||||
@ -247,15 +252,15 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* loop until we block */
|
/* loop until we block */
|
||||||
rc = libssh2_channel_read(channel, mem, amount);
|
nread = libssh2_channel_read(channel, mem, amount);
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
write(1, mem, rc);
|
write(1, mem, nread);
|
||||||
got += rc;
|
got += nread;
|
||||||
total += rc;
|
total += nread;
|
||||||
}
|
}
|
||||||
} while(rc > 0);
|
} while(nread > 0);
|
||||||
|
|
||||||
if((rc == LIBSSH2_ERROR_EAGAIN) && (got < fileinfo.st_size)) {
|
if((nread == LIBSSH2_ERROR_EAGAIN) && (got < fileinfo.st_size)) {
|
||||||
/* this is due to blocking that would occur otherwise
|
/* this is due to blocking that would occur otherwise
|
||||||
so we loop on this condition */
|
so we loop on this condition */
|
||||||
|
|
||||||
@ -271,8 +276,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
time_ms = tvdiff(end, start);
|
time_ms = tvdiff(end, start);
|
||||||
fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n",
|
fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n",
|
||||||
(long)total,
|
(long)total, time_ms, (double)total/(time_ms/1000.0), spin);
|
||||||
time_ms, total/(time_ms/1000.0), spin);
|
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin);
|
fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin);
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -171,7 +171,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Send a file via scp. The mode parameter must only have permissions! */
|
/* Send a file via scp. The mode parameter must only have permissions! */
|
||||||
channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777,
|
channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777,
|
||||||
(unsigned long)fileinfo.st_size);
|
(size_t)fileinfo.st_size);
|
||||||
|
|
||||||
if(!channel) {
|
if(!channel) {
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
@ -191,16 +191,17 @@ int main(int argc, char *argv[])
|
|||||||
ptr = mem;
|
ptr = mem;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
ssize_t nwritten;
|
||||||
/* write the same data over and over, until error or completion */
|
/* write the same data over and over, until error or completion */
|
||||||
rc = libssh2_channel_write(channel, ptr, nread);
|
nwritten = libssh2_channel_write(channel, ptr, nread);
|
||||||
if(rc < 0) {
|
if(nwritten < 0) {
|
||||||
fprintf(stderr, "ERROR %d\n", rc);
|
fprintf(stderr, "ERROR %d\n", (int)nwritten);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* rc indicates how many bytes were written this time */
|
/* nwritten indicates how many bytes were written this time */
|
||||||
ptr += rc;
|
ptr += nwritten;
|
||||||
nread -= rc;
|
nread -= nwritten;
|
||||||
}
|
}
|
||||||
} while(nread);
|
} while(nread);
|
||||||
|
|
||||||
|
@ -65,14 +65,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -90,7 +90,7 @@ int main(int argc, char *argv[])
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
struct stat fileinfo;
|
struct stat fileinfo;
|
||||||
time_t start;
|
time_t start;
|
||||||
long total = 0;
|
libssh2_struct_stat_size total = 0;
|
||||||
int duration;
|
int duration;
|
||||||
size_t prev;
|
size_t prev;
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ int main(int argc, char *argv[])
|
|||||||
/* Send a file via scp. The mode parameter must only have permissions! */
|
/* Send a file via scp. The mode parameter must only have permissions! */
|
||||||
do {
|
do {
|
||||||
channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777,
|
channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777,
|
||||||
(unsigned long)fileinfo.st_size);
|
(size_t)fileinfo.st_size);
|
||||||
|
|
||||||
if((!channel) && (libssh2_session_last_errno(session) !=
|
if((!channel) && (libssh2_session_last_errno(session) !=
|
||||||
LIBSSH2_ERROR_EAGAIN)) {
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
@ -236,22 +236,23 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
prev = 0;
|
prev = 0;
|
||||||
do {
|
do {
|
||||||
while((rc = libssh2_channel_write(channel, ptr, nread)) ==
|
ssize_t nwritten;
|
||||||
|
while((nwritten = libssh2_channel_write(channel, ptr, nread)) ==
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
waitsocket(sock, session);
|
||||||
prev = 0;
|
prev = 0;
|
||||||
}
|
}
|
||||||
if(rc < 0) {
|
if(nwritten < 0) {
|
||||||
fprintf(stderr, "ERROR %d total %ld / %d prev %d\n", rc,
|
fprintf(stderr, "ERROR %d total %ld / %d prev %d\n",
|
||||||
total, (int)nread, (int)prev);
|
(int)nwritten, (long)total, (int)nread, (int)prev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prev = nread;
|
prev = nread;
|
||||||
|
|
||||||
/* rc indicates how many bytes were written this time */
|
/* nwritten indicates how many bytes were written this time */
|
||||||
nread -= rc;
|
nread -= nwritten;
|
||||||
ptr += rc;
|
ptr += nwritten;
|
||||||
}
|
}
|
||||||
} while(nread);
|
} while(nread);
|
||||||
} while(!nread); /* only continue if nread was drained */
|
} while(!nread); /* only continue if nread was drained */
|
||||||
@ -259,7 +260,7 @@ int main(int argc, char *argv[])
|
|||||||
duration = (int)(time(NULL)-start);
|
duration = (int)(time(NULL)-start);
|
||||||
|
|
||||||
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
||||||
total, duration, total/(double)duration);
|
(long)total, duration, (double)total / duration);
|
||||||
|
|
||||||
fprintf(stderr, "Sending EOF\n");
|
fprintf(stderr, "Sending EOF\n");
|
||||||
while(libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);
|
while(libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);
|
||||||
|
@ -46,6 +46,10 @@
|
|||||||
#pragma warning(disable:4127)
|
#pragma warning(disable:4127)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *keyfile1 = "~/.ssh/id_rsa.pub";
|
const char *keyfile1 = "~/.ssh/id_rsa.pub";
|
||||||
const char *keyfile2 = "~/.ssh/id_rsa";
|
const char *keyfile2 = "~/.ssh/id_rsa";
|
||||||
const char *username = "username";
|
const char *username = "username";
|
||||||
@ -90,7 +94,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
|
|
||||||
responses[i].text = strdup(buf);
|
responses[i].text = strdup(buf);
|
||||||
responses[i].length = n;
|
responses[i].length = (unsigned int)n;
|
||||||
|
|
||||||
fprintf(stderr, "Response %d from user is '", i);
|
fprintf(stderr, "Response %d from user is '", i);
|
||||||
fwrite(responses[i].text, 1, responses[i].length, stderr);
|
fwrite(responses[i].text, 1, responses[i].length, stderr);
|
||||||
@ -104,7 +108,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 0;
|
int i, auth_pw = 0;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -195,7 +199,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password") != NULL) {
|
if(strstr(userauthlist, "password") != NULL) {
|
||||||
auth_pw |= 1;
|
auth_pw |= 1;
|
||||||
@ -277,12 +282,13 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n");
|
fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n");
|
||||||
do {
|
do {
|
||||||
char mem[1024];
|
char mem[1024];
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
/* loop until we fail */
|
/* loop until we fail */
|
||||||
fprintf(stderr, "libssh2_sftp_read()!\n");
|
fprintf(stderr, "libssh2_sftp_read()!\n");
|
||||||
rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
|
nread = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
write(1, mem, rc);
|
write(1, mem, nread);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
|
@ -43,6 +43,10 @@
|
|||||||
#pragma warning(disable:4127)
|
#pragma warning(disable:4127)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define STORAGE "/tmp/sftp-storage" /* this is the local file name this
|
#define STORAGE "/tmp/sftp-storage" /* this is the local file name this
|
||||||
example uses to store the downloaded
|
example uses to store the downloaded
|
||||||
file in */
|
file in */
|
||||||
@ -72,7 +76,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -237,21 +241,22 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n");
|
fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n");
|
||||||
do {
|
do {
|
||||||
|
ssize_t nread;
|
||||||
do {
|
do {
|
||||||
/* read in a loop until we block */
|
/* read in a loop until we block */
|
||||||
rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
|
nread = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
|
||||||
fprintf(stderr, "libssh2_sftp_read returned %d\n",
|
fprintf(stderr, "libssh2_sftp_read returned %d\n",
|
||||||
rc);
|
(int)nread);
|
||||||
|
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
/* write to stderr */
|
/* write to stderr */
|
||||||
write(2, mem, rc);
|
write(2, mem, nread);
|
||||||
/* write to temporary storage area */
|
/* write to temporary storage area */
|
||||||
fwrite(mem, rc, 1, tempstorage);
|
fwrite(mem, nread, 1, tempstorage);
|
||||||
}
|
}
|
||||||
} while(rc > 0);
|
} while(nread > 0);
|
||||||
|
|
||||||
if(rc != LIBSSH2_ERROR_EAGAIN) {
|
if(nread != LIBSSH2_ERROR_EAGAIN) {
|
||||||
/* error or end of file */
|
/* error or end of file */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -265,7 +270,7 @@ int main(int argc, char *argv[])
|
|||||||
FD_SET(sock, &fd2);
|
FD_SET(sock, &fd2);
|
||||||
|
|
||||||
/* wait for readable or writeable */
|
/* wait for readable or writeable */
|
||||||
rc = select(sock + 1, &fd, &fd2, NULL, &timeout);
|
rc = select((int)(sock + 1), &fd, &fd2, NULL, &timeout);
|
||||||
if(rc <= 0) {
|
if(rc <= 0) {
|
||||||
/* negative is error
|
/* negative is error
|
||||||
0 is timeout */
|
0 is timeout */
|
||||||
@ -296,6 +301,7 @@ int main(int argc, char *argv[])
|
|||||||
size_t nread;
|
size_t nread;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
do {
|
do {
|
||||||
|
ssize_t nwritten;
|
||||||
nread = fread(mem, 1, sizeof(mem), tempstorage);
|
nread = fread(mem, 1, sizeof(mem), tempstorage);
|
||||||
if(nread <= 0) {
|
if(nread <= 0) {
|
||||||
/* end of file */
|
/* end of file */
|
||||||
@ -305,13 +311,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
/* write data in a loop until we block */
|
/* write data in a loop until we block */
|
||||||
rc = libssh2_sftp_write(sftp_handle, ptr,
|
nwritten = libssh2_sftp_write(sftp_handle, ptr,
|
||||||
nread);
|
nread);
|
||||||
ptr += rc;
|
ptr += nwritten;
|
||||||
nread -= nread;
|
nread -= nwritten;
|
||||||
} while(rc >= 0);
|
} while(nwritten >= 0);
|
||||||
|
|
||||||
if(rc != LIBSSH2_ERROR_EAGAIN) {
|
if(nwritten != LIBSSH2_ERROR_EAGAIN) {
|
||||||
/* error or end of file */
|
/* error or end of file */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -325,7 +331,7 @@ int main(int argc, char *argv[])
|
|||||||
FD_SET(sock, &fd2);
|
FD_SET(sock, &fd2);
|
||||||
|
|
||||||
/* wait for readable or writeable */
|
/* wait for readable or writeable */
|
||||||
rc = select(sock + 1, &fd, &fd2, NULL, &timeout);
|
rc = select((int)(sock + 1), &fd, &fd2, NULL, &timeout);
|
||||||
if(rc <= 0) {
|
if(rc <= 0) {
|
||||||
/* negative is error
|
/* negative is error
|
||||||
0 is timeout */
|
0 is timeout */
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -58,6 +58,7 @@ int main(int argc, char *argv[])
|
|||||||
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
||||||
char mem[1024*100];
|
char mem[1024*100];
|
||||||
size_t nread;
|
size_t nread;
|
||||||
|
ssize_t nwritten;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -213,14 +214,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
/* write data in a loop until we block */
|
/* write data in a loop until we block */
|
||||||
rc = libssh2_sftp_write(sftp_handle, ptr, nread);
|
nwritten = libssh2_sftp_write(sftp_handle, ptr, nread);
|
||||||
if(rc < 0)
|
if(nwritten < 0)
|
||||||
break;
|
break;
|
||||||
ptr += rc;
|
ptr += nwritten;
|
||||||
nread -= rc;
|
nread -= nwritten;
|
||||||
} while(nread);
|
} while(nread);
|
||||||
|
|
||||||
} while(rc > 0);
|
} while(nwritten > 0);
|
||||||
|
|
||||||
libssh2_sftp_close(sftp_handle);
|
libssh2_sftp_close(sftp_handle);
|
||||||
libssh2_sftp_shutdown(sftp_session);
|
libssh2_sftp_shutdown(sftp_session);
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
@ -49,6 +49,10 @@
|
|||||||
#pragma warning(disable:4127)
|
#pragma warning(disable:4127)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
/* diff in ms */
|
/* diff in ms */
|
||||||
static long tvdiff(struct timeval newer, struct timeval older)
|
static long tvdiff(struct timeval newer, struct timeval older)
|
||||||
@ -83,14 +87,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -105,7 +109,7 @@ int main(int argc, char *argv[])
|
|||||||
long time_ms;
|
long time_ms;
|
||||||
#endif
|
#endif
|
||||||
int rc;
|
int rc;
|
||||||
int total = 0;
|
libssh2_struct_stat_size total = 0;
|
||||||
int spin = 0;
|
int spin = 0;
|
||||||
LIBSSH2_SFTP *sftp_session;
|
LIBSSH2_SFTP *sftp_session;
|
||||||
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
||||||
@ -258,16 +262,17 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n");
|
fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n");
|
||||||
do {
|
do {
|
||||||
char mem[1024*24];
|
char mem[1024*24];
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
/* loop until we fail */
|
/* loop until we fail */
|
||||||
while((rc = libssh2_sftp_read(sftp_handle, mem,
|
while((nread = libssh2_sftp_read(sftp_handle, mem,
|
||||||
sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) {
|
sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) {
|
||||||
spin++;
|
spin++;
|
||||||
waitsocket(sock, session); /* now we wait */
|
waitsocket(sock, session); /* now we wait */
|
||||||
}
|
}
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
total += rc;
|
total += nread;
|
||||||
write(1, mem, rc);
|
write(1, mem, nread);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
@ -277,11 +282,10 @@ int main(int argc, char *argv[])
|
|||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
time_ms = tvdiff(end, start);
|
time_ms = tvdiff(end, start);
|
||||||
fprintf(stderr, "Got %d bytes in %ld ms = %.1f bytes/sec spin: %d\n",
|
fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n",
|
||||||
total,
|
(long)total, time_ms, (double)total/(time_ms/1000.0), spin);
|
||||||
time_ms, total/(time_ms/1000.0), spin);
|
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "Got %d bytes spin: %d\n", total, spin);
|
fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
libssh2_sftp_close(sftp_handle);
|
libssh2_sftp_close(sftp_handle);
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -57,6 +57,7 @@ int main(int argc, char *argv[])
|
|||||||
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
||||||
char mem[1024*100];
|
char mem[1024*100];
|
||||||
size_t nread;
|
size_t nread;
|
||||||
|
ssize_t nwritten;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -197,14 +198,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
/* write data in a loop until we block */
|
/* write data in a loop until we block */
|
||||||
rc = libssh2_sftp_write(sftp_handle, ptr, nread);
|
nwritten = libssh2_sftp_write(sftp_handle, ptr, nread);
|
||||||
if(rc < 0)
|
if(nwritten < 0)
|
||||||
break;
|
break;
|
||||||
ptr += rc;
|
ptr += nwritten;
|
||||||
nread -= rc;
|
nread -= nwritten;
|
||||||
} while(nread);
|
} while(nread);
|
||||||
|
|
||||||
} while(rc > 0);
|
} while(nwritten > 0);
|
||||||
|
|
||||||
libssh2_sftp_close(sftp_handle);
|
libssh2_sftp_close(sftp_handle);
|
||||||
libssh2_sftp_shutdown(sftp_session);
|
libssh2_sftp_shutdown(sftp_session);
|
||||||
|
@ -71,14 +71,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -94,9 +94,10 @@ int main(int argc, char *argv[])
|
|||||||
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
||||||
char mem[1024 * 100];
|
char mem[1024 * 100];
|
||||||
size_t nread;
|
size_t nread;
|
||||||
|
ssize_t nwritten;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
time_t start;
|
time_t start;
|
||||||
long total = 0;
|
libssh2_struct_stat_size total = 0;
|
||||||
int duration;
|
int duration;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -254,23 +255,22 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
/* write data in a loop until we block */
|
/* write data in a loop until we block */
|
||||||
while((rc = libssh2_sftp_write(sftp_handle, ptr, nread)) ==
|
while((nwritten = libssh2_sftp_write(sftp_handle, ptr, nread)) ==
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
waitsocket(sock, session);
|
||||||
}
|
}
|
||||||
if(rc < 0)
|
if(nwritten < 0)
|
||||||
break;
|
break;
|
||||||
ptr += rc;
|
ptr += nwritten;
|
||||||
nread -= rc;
|
nread -= nwritten;
|
||||||
|
|
||||||
} while(nread);
|
} while(nread);
|
||||||
} while(rc > 0);
|
} while(nwritten > 0);
|
||||||
|
|
||||||
duration = (int)(time(NULL)-start);
|
duration = (int)(time(NULL)-start);
|
||||||
|
|
||||||
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
||||||
total, duration, total/(double)duration);
|
(long)total, duration, (double)total / duration);
|
||||||
|
|
||||||
|
|
||||||
fclose(local);
|
fclose(local);
|
||||||
libssh2_sftp_close(sftp_handle);
|
libssh2_sftp_close(sftp_handle);
|
||||||
|
@ -71,14 +71,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -95,8 +95,9 @@ int main(int argc, char *argv[])
|
|||||||
char mem[1024 * 1000];
|
char mem[1024 * 1000];
|
||||||
size_t nread;
|
size_t nread;
|
||||||
size_t memuse;
|
size_t memuse;
|
||||||
|
ssize_t nwritten;
|
||||||
time_t start;
|
time_t start;
|
||||||
long total = 0;
|
libssh2_struct_stat_size total = 0;
|
||||||
int duration;
|
int duration;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -258,29 +259,28 @@ int main(int argc, char *argv[])
|
|||||||
total += nread;
|
total += nread;
|
||||||
|
|
||||||
/* write data in a loop until we block */
|
/* write data in a loop until we block */
|
||||||
while((rc = libssh2_sftp_write(sftp_handle, mem, memuse)) ==
|
while((nwritten = libssh2_sftp_write(sftp_handle, mem, memuse)) ==
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
waitsocket(sock, session);
|
||||||
}
|
}
|
||||||
if(rc < 0)
|
if(nwritten < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(memuse - rc) {
|
if(memuse - nwritten) {
|
||||||
/* make room for more data at the end of the buffer */
|
/* make room for more data at the end of the buffer */
|
||||||
memmove(&mem[0], &mem[rc], memuse - rc);
|
memmove(&mem[0], &mem[nwritten], memuse - nwritten);
|
||||||
memuse -= rc;
|
memuse -= nwritten;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* 'mem' was consumed fully */
|
/* 'mem' was consumed fully */
|
||||||
memuse = 0;
|
memuse = 0;
|
||||||
|
|
||||||
} while(rc > 0);
|
} while(nwritten > 0);
|
||||||
|
|
||||||
duration = (int)(time(NULL)-start);
|
duration = (int)(time(NULL)-start);
|
||||||
|
|
||||||
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
||||||
total, duration, total/(double)duration);
|
(long)total, duration, (double)total / duration);
|
||||||
|
|
||||||
|
|
||||||
fclose(local);
|
fclose(local);
|
||||||
libssh2_sftp_close(sftp_handle);
|
libssh2_sftp_close(sftp_handle);
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
#pragma warning(disable:4127)
|
#pragma warning(disable:4127)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#if defined(_MSC_VER)
|
||||||
#define __FILESIZE "I64u"
|
#define __FILESIZE "I64u"
|
||||||
#else
|
#else
|
||||||
#define __FILESIZE "llu"
|
#define __FILESIZE "llu"
|
||||||
@ -70,7 +70,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
(void)instruction_len;
|
(void)instruction_len;
|
||||||
if(num_prompts == 1) {
|
if(num_prompts == 1) {
|
||||||
responses[0].text = strdup(password);
|
responses[0].text = strdup(password);
|
||||||
responses[0].length = strlen(password);
|
responses[0].length = (unsigned int)strlen(password);
|
||||||
}
|
}
|
||||||
(void)prompts;
|
(void)prompts;
|
||||||
(void)abstract;
|
(void)abstract;
|
||||||
@ -78,7 +78,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int rc, i, auth_pw = 0;
|
int rc, i, auth_pw = 0;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -166,7 +166,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password") != NULL) {
|
if(strstr(userauthlist, "password") != NULL) {
|
||||||
auth_pw |= 1;
|
auth_pw |= 1;
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
#pragma warning(disable:4127)
|
#pragma warning(disable:4127)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#if defined(_MSC_VER)
|
||||||
#define __FILESIZE "I64u"
|
#define __FILESIZE "I64u"
|
||||||
#else
|
#else
|
||||||
#define __FILESIZE "llu"
|
#define __FILESIZE "llu"
|
||||||
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 1;
|
int i, auth_pw = 1;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
@ -70,7 +70,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
(void)instruction_len;
|
(void)instruction_len;
|
||||||
if(num_prompts == 1) {
|
if(num_prompts == 1) {
|
||||||
responses[0].text = strdup(password);
|
responses[0].text = strdup(password);
|
||||||
responses[0].length = strlen(password);
|
responses[0].length = (unsigned int)strlen(password);
|
||||||
}
|
}
|
||||||
(void)prompts;
|
(void)prompts;
|
||||||
(void)abstract;
|
(void)abstract;
|
||||||
@ -79,7 +79,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int rc, i, auth_pw = 0;
|
int rc, i, auth_pw = 0;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -171,7 +171,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password") != NULL) {
|
if(strstr(userauthlist, "password") != NULL) {
|
||||||
auth_pw |= 1;
|
auth_pw |= 1;
|
||||||
@ -315,7 +316,7 @@ int main(int argc, char *argv[])
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf));
|
ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf));
|
||||||
if(err < 0)
|
if(err < 0)
|
||||||
fprintf(stderr, "Unable to read response: %zd\n", err);
|
fprintf(stderr, "Unable to read response: %d\n", (int)err);
|
||||||
else {
|
else {
|
||||||
fwrite(buf, 1, err, stdout);
|
fwrite(buf, 1, err, stdout);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ const char *username = "username";
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET;
|
libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET;
|
||||||
int i, rc;
|
int i, rc;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -126,7 +126,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "publickey") == NULL) {
|
if(strstr(userauthlist, "publickey") == NULL) {
|
||||||
fprintf(stderr, "\"publickey\" authentication is not supported\n");
|
fprintf(stderr, "\"publickey\" authentication is not supported\n");
|
||||||
|
@ -76,7 +76,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ int main(int argc, char *argv[])
|
|||||||
const char *hostname = "127.0.0.1";
|
const char *hostname = "127.0.0.1";
|
||||||
const char *commandline = "uptime";
|
const char *commandline = "uptime";
|
||||||
const char *username = NULL;
|
const char *username = NULL;
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
@ -96,7 +96,7 @@ int main(int argc, char *argv[])
|
|||||||
int rc;
|
int rc;
|
||||||
int exitcode;
|
int exitcode;
|
||||||
char *exitsignal = (char *)"none";
|
char *exitsignal = (char *)"none";
|
||||||
int bytecount = 0;
|
ssize_t bytecount = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
WSADATA wsadata;
|
WSADATA wsadata;
|
||||||
@ -230,29 +230,31 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
ssize_t nread;
|
||||||
/* loop until we block */
|
/* loop until we block */
|
||||||
do {
|
do {
|
||||||
char buffer[0x4000];
|
char buffer[0x4000];
|
||||||
rc = libssh2_channel_read(channel, buffer, sizeof(buffer) );
|
nread = libssh2_channel_read(channel, buffer, sizeof(buffer) );
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
int i;
|
ssize_t i;
|
||||||
bytecount += rc;
|
bytecount += nread;
|
||||||
fprintf(stderr, "We read:\n");
|
fprintf(stderr, "We read:\n");
|
||||||
for(i = 0; i < rc; ++i)
|
for(i = 0; i < nread; ++i)
|
||||||
fputc(buffer[i], stderr);
|
fputc(buffer[i], stderr);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(rc != LIBSSH2_ERROR_EAGAIN)
|
if(nread != LIBSSH2_ERROR_EAGAIN)
|
||||||
/* no need to output this for the EAGAIN case */
|
/* no need to output this for the EAGAIN case */
|
||||||
fprintf(stderr, "libssh2_channel_read returned %d\n", rc);
|
fprintf(stderr, "libssh2_channel_read returned %d\n",
|
||||||
|
(int)nread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(rc > 0);
|
while(nread > 0);
|
||||||
|
|
||||||
/* this is due to blocking that would occur otherwise so we loop on
|
/* this is due to blocking that would occur otherwise so we loop on
|
||||||
this condition */
|
this condition */
|
||||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
if(nread == LIBSSH2_ERROR_EAGAIN) {
|
||||||
waitsocket(sock, session);
|
waitsocket(sock, session);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -272,7 +274,7 @@ int main(int argc, char *argv[])
|
|||||||
printf("\nGot signal: %s\n", exitsignal);
|
printf("\nGot signal: %s\n", exitsignal);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
|
printf("\nEXIT: %d bytecount: %d\n", exitcode, (int)bytecount);
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
|
@ -72,7 +72,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
|||||||
const char *commandline = "cat";
|
const char *commandline = "cat";
|
||||||
const char *username = "user";
|
const char *username = "user";
|
||||||
const char *password = "password";
|
const char *password = "password";
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
const char *fingerprint;
|
const char *fingerprint;
|
||||||
@ -232,11 +232,11 @@ int main(int argc, char *argv[])
|
|||||||
else {
|
else {
|
||||||
LIBSSH2_POLLFD *fds = NULL;
|
LIBSSH2_POLLFD *fds = NULL;
|
||||||
int running = 1;
|
int running = 1;
|
||||||
int bufsize = BUFSIZE;
|
ssize_t bufsize = BUFSIZE;
|
||||||
char buffer[BUFSIZE];
|
char buffer[BUFSIZE];
|
||||||
int totsize = 1500000;
|
ssize_t totsize = 1500000;
|
||||||
int totwritten = 0;
|
ssize_t totwritten = 0;
|
||||||
int totread = 0;
|
ssize_t totread = 0;
|
||||||
int rereads = 0;
|
int rereads = 0;
|
||||||
int rewrites = 0;
|
int rewrites = 0;
|
||||||
int i;
|
int i;
|
||||||
@ -262,7 +262,8 @@ int main(int argc, char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(fds[0].revents & LIBSSH2_POLLFD_POLLIN) {
|
if(fds[0].revents & LIBSSH2_POLLFD_POLLIN) {
|
||||||
int n = libssh2_channel_read(channel, buffer, sizeof(buffer));
|
ssize_t n = libssh2_channel_read(channel,
|
||||||
|
buffer, sizeof(buffer));
|
||||||
act++;
|
act++;
|
||||||
|
|
||||||
if(n == LIBSSH2_ERROR_EAGAIN) {
|
if(n == LIBSSH2_ERROR_EAGAIN) {
|
||||||
@ -276,7 +277,7 @@ int main(int argc, char *argv[])
|
|||||||
else {
|
else {
|
||||||
totread += n;
|
totread += n;
|
||||||
fprintf(stderr, "read %d bytes (%d in total)\n",
|
fprintf(stderr, "read %d bytes (%d in total)\n",
|
||||||
n, totread);
|
(int)n, (int)totread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,9 +286,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(totwritten < totsize) {
|
if(totwritten < totsize) {
|
||||||
/* we have not written all data yet */
|
/* we have not written all data yet */
|
||||||
int left = totsize - totwritten;
|
ssize_t left = totsize - totwritten;
|
||||||
int size = (left < bufsize) ? left : bufsize;
|
ssize_t size = (left < bufsize) ? left : bufsize;
|
||||||
int n = libssh2_channel_write_ex(channel, 0, buffer, size);
|
ssize_t n = libssh2_channel_write_ex(channel, 0,
|
||||||
|
buffer, size);
|
||||||
|
|
||||||
if(n == LIBSSH2_ERROR_EAGAIN) {
|
if(n == LIBSSH2_ERROR_EAGAIN) {
|
||||||
rewrites++;
|
rewrites++;
|
||||||
@ -300,7 +302,7 @@ int main(int argc, char *argv[])
|
|||||||
else {
|
else {
|
||||||
totwritten += n;
|
totwritten += n;
|
||||||
fprintf(stderr, "wrote %d bytes (%d in total)",
|
fprintf(stderr, "wrote %d bytes (%d in total)",
|
||||||
n, totwritten);
|
(int)n, (int)totwritten);
|
||||||
if(left >= bufsize && n != bufsize) {
|
if(left >= bufsize && n != bufsize) {
|
||||||
fprintf(stderr, " PARTIAL");
|
fprintf(stderr, " PARTIAL");
|
||||||
}
|
}
|
||||||
@ -349,11 +351,11 @@ int main(int argc, char *argv[])
|
|||||||
channel = NULL;
|
channel = NULL;
|
||||||
|
|
||||||
fprintf(stderr, "\nrereads: %d rewrites: %d totwritten %d\n",
|
fprintf(stderr, "\nrereads: %d rewrites: %d totwritten %d\n",
|
||||||
rereads, rewrites, totwritten);
|
rereads, rewrites, (int)totwritten);
|
||||||
|
|
||||||
if(totwritten != totread) {
|
if(totwritten != totread) {
|
||||||
fprintf(stderr, "\n*** FAIL bytes written: %d bytes "
|
fprintf(stderr, "\n*** FAIL bytes written: %d bytes "
|
||||||
"read: %d ***\n", totwritten, totread);
|
"read: %d ***\n", (int)totwritten, (int)totread);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
|||||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||||
writefd = &fd;
|
writefd = &fd;
|
||||||
|
|
||||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
|||||||
const char *commandline = "uptime";
|
const char *commandline = "uptime";
|
||||||
const char *username = "user";
|
const char *username = "user";
|
||||||
const char *password = "password";
|
const char *password = "password";
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
const char *fingerprint;
|
const char *fingerprint;
|
||||||
@ -94,7 +94,7 @@ int main(int argc, char *argv[])
|
|||||||
int rc;
|
int rc;
|
||||||
int exitcode;
|
int exitcode;
|
||||||
char *exitsignal = (char *)"none";
|
char *exitsignal = (char *)"none";
|
||||||
int bytecount = 0;
|
ssize_t bytecount = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
LIBSSH2_KNOWNHOSTS *nh;
|
LIBSSH2_KNOWNHOSTS *nh;
|
||||||
int type;
|
int type;
|
||||||
@ -259,25 +259,27 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
ssize_t nread;
|
||||||
/* loop until we block */
|
/* loop until we block */
|
||||||
do {
|
do {
|
||||||
char buffer[0x4000];
|
char buffer[0x4000];
|
||||||
rc = libssh2_channel_read(channel, buffer, sizeof(buffer) );
|
nread = libssh2_channel_read(channel, buffer, sizeof(buffer));
|
||||||
if(rc > 0) {
|
if(nread > 0) {
|
||||||
int i;
|
ssize_t i;
|
||||||
bytecount += rc;
|
bytecount += nread;
|
||||||
fprintf(stderr, "We read:\n");
|
fprintf(stderr, "We read:\n");
|
||||||
for(i = 0; i < rc; ++i)
|
for(i = 0; i < nread; ++i)
|
||||||
fputc(buffer[i], stderr);
|
fputc(buffer[i], stderr);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(rc != LIBSSH2_ERROR_EAGAIN)
|
if(nread != LIBSSH2_ERROR_EAGAIN)
|
||||||
/* no need to output this for the EAGAIN case */
|
/* no need to output this for the EAGAIN case */
|
||||||
fprintf(stderr, "libssh2_channel_read returned %d\n", rc);
|
fprintf(stderr, "libssh2_channel_read returned %d\n",
|
||||||
|
(int)nread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(rc > 0);
|
while(nread > 0);
|
||||||
|
|
||||||
/* this is due to blocking that would occur otherwise so we loop on
|
/* this is due to blocking that would occur otherwise so we loop on
|
||||||
this condition */
|
this condition */
|
||||||
@ -300,7 +302,8 @@ int main(int argc, char *argv[])
|
|||||||
if(exitsignal)
|
if(exitsignal)
|
||||||
fprintf(stderr, "\nGot signal: %s\n", exitsignal);
|
fprintf(stderr, "\nGot signal: %s\n", exitsignal);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
|
fprintf(stderr, "\nEXIT: %d bytecount: %d\n",
|
||||||
|
exitcode, (int)bytecount);
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
channel = NULL;
|
channel = NULL;
|
||||||
|
@ -56,13 +56,13 @@ enum {
|
|||||||
|
|
||||||
static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len)
|
static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len)
|
||||||
{
|
{
|
||||||
int i;
|
ssize_t i;
|
||||||
ssize_t wr = 0;
|
ssize_t wr = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
i = libssh2_channel_write(channel, buf, len);
|
i = libssh2_channel_write(channel, buf, len);
|
||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
fprintf(stderr, "libssh2_channel_write: %d\n", i);
|
fprintf(stderr, "libssh2_channel_write: %d\n", (int)i);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
wr += i;
|
wr += i;
|
||||||
@ -71,8 +71,8 @@ static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag,
|
static ssize_t netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag,
|
||||||
char *buf, size_t buflen)
|
char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
size_t rd = 0;
|
size_t rd = 0;
|
||||||
@ -202,7 +202,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password"))
|
if(strstr(userauthlist, "password"))
|
||||||
auth |= AUTH_PASSWORD;
|
auth |= AUTH_PASSWORD;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
#define recv(s, b, l, f) recv((s), (b), (int)(l), (f))
|
||||||
|
#define send(s, b, l, f) send((s), (b), (int)(l), (f))
|
||||||
#else
|
#else
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@ -157,7 +159,8 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password"))
|
if(strstr(userauthlist, "password"))
|
||||||
auth |= AUTH_PASSWORD;
|
auth |= AUTH_PASSWORD;
|
||||||
@ -251,12 +254,13 @@ int main(int argc, char *argv[])
|
|||||||
FD_SET(forwardsock, &fds);
|
FD_SET(forwardsock, &fds);
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 100000;
|
tv.tv_usec = 100000;
|
||||||
rc = select(forwardsock + 1, &fds, NULL, NULL, &tv);
|
rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
|
||||||
if(-1 == rc) {
|
if(-1 == rc) {
|
||||||
perror("select");
|
perror("select");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
if(rc && FD_ISSET(forwardsock, &fds)) {
|
if(rc && FD_ISSET(forwardsock, &fds)) {
|
||||||
|
ssize_t nwritten;
|
||||||
len = recv(forwardsock, buf, sizeof(buf), 0);
|
len = recv(forwardsock, buf, sizeof(buf), 0);
|
||||||
if(len < 0) {
|
if(len < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
@ -269,30 +273,33 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
wr = 0;
|
wr = 0;
|
||||||
do {
|
do {
|
||||||
i = libssh2_channel_write(channel, buf, len);
|
nwritten = libssh2_channel_write(channel, buf, len);
|
||||||
if(i < 0) {
|
if(nwritten < 0) {
|
||||||
fprintf(stderr, "libssh2_channel_write: %d\n", i);
|
fprintf(stderr, "libssh2_channel_write: %d\n",
|
||||||
|
(int)nwritten);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr += i;
|
wr += nwritten;
|
||||||
} while(i > 0 && wr < len);
|
} while(nwritten > 0 && wr < len);
|
||||||
}
|
}
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
ssize_t nsent;
|
||||||
len = libssh2_channel_read(channel, buf, sizeof(buf));
|
len = libssh2_channel_read(channel, buf, sizeof(buf));
|
||||||
if(LIBSSH2_ERROR_EAGAIN == len)
|
if(LIBSSH2_ERROR_EAGAIN == len)
|
||||||
break;
|
break;
|
||||||
else if(len < 0) {
|
else if(len < 0) {
|
||||||
fprintf(stderr, "libssh2_channel_read: %d", (int)len);
|
fprintf(stderr, "libssh2_channel_read: %d",
|
||||||
|
(int)len);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr = 0;
|
wr = 0;
|
||||||
while(wr < len) {
|
while(wr < len) {
|
||||||
i = send(forwardsock, buf + wr, len - wr, 0);
|
nsent = send(forwardsock, buf + wr, len - wr, 0);
|
||||||
if(i <= 0) {
|
if(nsent <= 0) {
|
||||||
perror("write");
|
perror("write");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr += i;
|
wr += nsent;
|
||||||
}
|
}
|
||||||
if(libssh2_channel_eof(channel)) {
|
if(libssh2_channel_eof(channel)) {
|
||||||
fprintf(stderr, "The remote client at %s:%d disconnected!\n",
|
fprintf(stderr, "The remote client at %s:%d disconnected!\n",
|
||||||
|
@ -214,11 +214,12 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock)
|
|||||||
|
|
||||||
rc = libssh2_poll(fds, nfds, 0);
|
rc = libssh2_poll(fds, nfds, 0);
|
||||||
if(rc >0) {
|
if(rc >0) {
|
||||||
rc = libssh2_channel_read(channel, buf, bufsize);
|
ssize_t nread;
|
||||||
write(sock, buf, rc);
|
nread = libssh2_channel_read(channel, buf, bufsize);
|
||||||
|
write(sock, buf, nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = select(sock + 1, &set, NULL, NULL, &timeval_out);
|
rc = select((int)(sock + 1), &set, NULL, NULL, &timeval_out);
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
memset((void *)buf, 0, bufsize);
|
memset((void *)buf, 0, bufsize);
|
||||||
|
|
||||||
@ -247,7 +248,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock)
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr = 0;
|
uint32_t hostaddr = 0;
|
||||||
int sock = 0;
|
int sock = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -448,7 +449,7 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = select(fileno(stdin) + 1, &set, NULL, NULL, &timeval_out);
|
rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out);
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
/* Data in stdin*/
|
/* Data in stdin*/
|
||||||
rc = read(fileno(stdin), buf, 1);
|
rc = read(fileno(stdin), buf, 1);
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "openssh_fixture.h"
|
|
||||||
#include "session_fixture.h"
|
#include "session_fixture.h"
|
||||||
|
#include "openssh_fixture.h"
|
||||||
#include "libssh2_config.h"
|
#include "libssh2_config.h"
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
@ -66,6 +66,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if defined(WIN32) && (defined(_M_X64) || defined(__x86_64__))
|
||||||
|
#define LIBSSH2_SOCKET_MASK "%lld"
|
||||||
|
#else
|
||||||
|
#define LIBSSH2_SOCKET_MASK "%d"
|
||||||
|
#endif
|
||||||
|
|
||||||
static int have_docker = 0;
|
static int have_docker = 0;
|
||||||
|
|
||||||
static int run_command_varg(char **output, const char *command, va_list args)
|
static int run_command_varg(char **output, const char *command, va_list args)
|
||||||
@ -113,7 +119,7 @@ static int run_command_varg(char **output, const char *command, va_list args)
|
|||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
buf_len = 0;
|
buf_len = 0;
|
||||||
while(buf_len < (sizeof(buf) - 1) &&
|
while(buf_len < (sizeof(buf) - 1) &&
|
||||||
fgets(&buf[buf_len], sizeof(buf) - buf_len, pipe) != NULL) {
|
fgets(&buf[buf_len], (int)(sizeof(buf) - buf_len), pipe) != NULL) {
|
||||||
buf_len = strlen(buf);
|
buf_len = strlen(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,30 +333,30 @@ static int port_from_container(char *container_id, char **port_out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_socket_to_container(char *container_id)
|
static libssh2_socket_t open_socket_to_container(char *container_id)
|
||||||
{
|
{
|
||||||
char *ip_address = NULL;
|
char *ip_address = NULL;
|
||||||
char *port_string = NULL;
|
char *port_string = NULL;
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int ret;
|
libssh2_socket_t ret = LIBSSH2_INVALID_SOCKET;
|
||||||
|
|
||||||
if(have_docker) {
|
if(have_docker) {
|
||||||
ret = ip_address_from_container(container_id, &ip_address);
|
int res;
|
||||||
if(ret != 0) {
|
res = ip_address_from_container(container_id, &ip_address);
|
||||||
|
if(res != 0) {
|
||||||
fprintf(stderr, "Failed to get IP address for container %s\n",
|
fprintf(stderr, "Failed to get IP address for container %s\n",
|
||||||
container_id);
|
container_id);
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = port_from_container(container_id, &port_string);
|
res = port_from_container(container_id, &port_string);
|
||||||
if(ret != 0) {
|
if(res != 0) {
|
||||||
fprintf(stderr, "Failed to get port for container %s\n",
|
fprintf(stderr, "Failed to get port for container %s\n",
|
||||||
container_id);
|
container_id);
|
||||||
ret = -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -365,7 +371,6 @@ static int open_socket_to_container(char *container_id)
|
|||||||
env = "4711";
|
env = "4711";
|
||||||
}
|
}
|
||||||
port_string = strdup(env);
|
port_string = strdup(env);
|
||||||
ret = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 0.0.0.0 is returned by Docker for Windows, because the container
|
/* 0.0.0.0 is returned by Docker for Windows, because the container
|
||||||
@ -377,16 +382,15 @@ static int open_socket_to_container(char *container_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hostaddr = inet_addr(ip_address);
|
hostaddr = inet_addr(ip_address);
|
||||||
if(hostaddr == (unsigned long)(-1)) {
|
if(hostaddr == (uint32_t)(-1)) {
|
||||||
fprintf(stderr, "Failed to convert %s host address\n", ip_address);
|
fprintf(stderr, "Failed to convert %s host address\n", ip_address);
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(sock <= 0) {
|
if(sock == LIBSSH2_INVALID_SOCKET) {
|
||||||
fprintf(stderr, "Failed to open socket (%d)\n", sock);
|
fprintf(stderr,
|
||||||
ret = -1;
|
"Failed to open socket (" LIBSSH2_SOCKET_MASK ")\n", sock);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,7 +401,6 @@ static int open_socket_to_container(char *container_id)
|
|||||||
for(counter = 0; counter < 3; ++counter) {
|
for(counter = 0; counter < 3; ++counter) {
|
||||||
if(connect(sock, (struct sockaddr *)(&sin),
|
if(connect(sock, (struct sockaddr *)(&sin),
|
||||||
sizeof(struct sockaddr_in)) != 0) {
|
sizeof(struct sockaddr_in)) != 0) {
|
||||||
ret = -1;
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Connection to %s:%s attempt #%d failed: retrying...\n",
|
"Connection to %s:%s attempt #%d failed: retrying...\n",
|
||||||
ip_address, port_string, counter);
|
ip_address, port_string, counter);
|
||||||
@ -408,7 +411,7 @@ static int open_socket_to_container(char *container_id)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ret == -1) {
|
if(ret == LIBSSH2_INVALID_SOCKET) {
|
||||||
fprintf(stderr, "Failed to connect to %s:%s\n",
|
fprintf(stderr, "Failed to connect to %s:%s\n",
|
||||||
ip_address, port_string);
|
ip_address, port_string);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -460,7 +463,7 @@ void stop_openssh_fixture(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_socket_to_openssh_server(void)
|
libssh2_socket_t open_socket_to_openssh_server(void)
|
||||||
{
|
{
|
||||||
return open_socket_to_container(running_container_id);
|
return open_socket_to_container(running_container_id);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,6 @@
|
|||||||
|
|
||||||
int start_openssh_fixture(void);
|
int start_openssh_fixture(void);
|
||||||
void stop_openssh_fixture(void);
|
void stop_openssh_fixture(void);
|
||||||
int open_socket_to_openssh_server(void);
|
libssh2_socket_t open_socket_to_openssh_server(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -65,13 +65,13 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
LIBSSH2_SESSION *connected_session = NULL;
|
LIBSSH2_SESSION *connected_session = NULL;
|
||||||
int connected_socket = -1;
|
libssh2_socket_t connected_socket = LIBSSH2_INVALID_SOCKET;
|
||||||
|
|
||||||
static int connect_to_server(void)
|
static int connect_to_server(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
connected_socket = open_socket_to_openssh_server();
|
connected_socket = open_socket_to_openssh_server();
|
||||||
if(connected_socket <= 0) {
|
if(connected_socket == LIBSSH2_INVALID_SOCKET) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ static void setup_fixture_workdir(void)
|
|||||||
#else
|
#else
|
||||||
char wd_buf[MAXPATHLEN];
|
char wd_buf[MAXPATHLEN];
|
||||||
#endif
|
#endif
|
||||||
char *wd = getenv("FIXTURE_WORKDIR");
|
const char *wd = getenv("FIXTURE_WORKDIR");
|
||||||
#ifdef FIXTURE_WORKDIR
|
#ifdef FIXTURE_WORKDIR
|
||||||
if(!wd) {
|
if(!wd) {
|
||||||
wd = FIXTURE_WORKDIR;
|
wd = FIXTURE_WORKDIR;
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
uint32_t hostaddr;
|
||||||
libssh2_socket_t sock;
|
libssh2_socket_t sock;
|
||||||
int i, auth_pw = 0;
|
int i, auth_pw = 0;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -108,7 +108,8 @@ int main(int argc, char *argv[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
userauthlist = libssh2_userauth_list(session, username,
|
||||||
|
(unsigned int)strlen(username));
|
||||||
printf("Authentication methods: %s\n", userauthlist);
|
printf("Authentication methods: %s\n", userauthlist);
|
||||||
if(strstr(userauthlist, "password") != NULL) {
|
if(strstr(userauthlist, "password") != NULL) {
|
||||||
auth_pw |= 1;
|
auth_pw |= 1;
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -33,13 +33,13 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) {
|
if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) {
|
||||||
rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||||
EXPECTED_ECDSA_HOSTKEY,
|
EXPECTED_ECDSA_HOSTKEY,
|
||||||
strlen(EXPECTED_ECDSA_HOSTKEY));
|
(unsigned int)strlen(EXPECTED_ECDSA_HOSTKEY));
|
||||||
}
|
}
|
||||||
else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) {
|
else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) {
|
||||||
rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||||
EXPECTED_RSA_HOSTKEY,
|
EXPECTED_RSA_HOSTKEY,
|
||||||
strlen(EXPECTED_RSA_HOSTKEY));
|
(unsigned int)strlen(EXPECTED_RSA_HOSTKEY));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Unexpected type of hostkey: %i\n", type);
|
fprintf(stderr, "Unexpected type of hostkey: %i\n", type);
|
||||||
|
@ -26,7 +26,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
|
|
||||||
if(num_prompts == 1) {
|
if(num_prompts == 1) {
|
||||||
responses[0].text = strdup(WRONG_PASSWORD);
|
responses[0].text = strdup(WRONG_PASSWORD);
|
||||||
responses[0].length = strlen(WRONG_PASSWORD);
|
responses[0].length = (unsigned int)strlen(WRONG_PASSWORD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -49,7 +50,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_keyboard_interactive_ex(
|
rc = libssh2_userauth_keyboard_interactive_ex(
|
||||||
session, USERNAME, strlen(USERNAME), kbd_callback);
|
session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback);
|
||||||
if(rc == 0) {
|
if(rc == 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Keyboard-interactive auth succeeded with wrong response\n");
|
"Keyboard-interactive auth succeeded with wrong response\n");
|
||||||
|
@ -28,7 +28,7 @@ static void kbd_callback(const char *name, int name_len,
|
|||||||
|
|
||||||
if(num_prompts == 1) {
|
if(num_prompts == 1) {
|
||||||
responses[0].text = strdup(PASSWORD);
|
responses[0].text = strdup(PASSWORD);
|
||||||
responses[0].length = strlen(PASSWORD);
|
responses[0].length = (unsigned int)strlen(PASSWORD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -51,7 +52,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_keyboard_interactive_ex(
|
rc = libssh2_userauth_keyboard_interactive_ex(
|
||||||
session, USERNAME, strlen(USERNAME), kbd_callback);
|
session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
print_last_session_error("libssh2_userauth_keyboard_interactive_ex");
|
print_last_session_error("libssh2_userauth_keyboard_interactive_ex");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -13,7 +13,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -25,8 +26,10 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_password_ex(session, USERNAME, strlen(USERNAME),
|
rc = libssh2_userauth_password_ex(session, USERNAME,
|
||||||
WRONG_PASSWORD, strlen(WRONG_PASSWORD),
|
(unsigned int)strlen(USERNAME),
|
||||||
|
WRONG_PASSWORD,
|
||||||
|
(unsigned int)strlen(WRONG_PASSWORD),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc == 0) {
|
if(rc == 0) {
|
||||||
fprintf(stderr, "Password auth succeeded with wrong password\n");
|
fprintf(stderr, "Password auth succeeded with wrong password\n");
|
||||||
|
@ -14,7 +14,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, WRONG_USERNAME, strlen(WRONG_USERNAME));
|
libssh2_userauth_list(session, WRONG_USERNAME,
|
||||||
|
(unsigned int)strlen(WRONG_USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -27,8 +28,9 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_password_ex(session, WRONG_USERNAME,
|
rc = libssh2_userauth_password_ex(session, WRONG_USERNAME,
|
||||||
strlen(WRONG_USERNAME), PASSWORD,
|
(unsigned int)strlen(WRONG_USERNAME),
|
||||||
strlen(PASSWORD), NULL);
|
PASSWORD,
|
||||||
|
(unsigned int)strlen(PASSWORD), NULL);
|
||||||
if(rc == 0) {
|
if(rc == 0) {
|
||||||
fprintf(stderr, "Password auth succeeded with wrong username\n");
|
fprintf(stderr, "Password auth succeeded with wrong username\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -14,7 +14,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -26,8 +27,10 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_password_ex(session, USERNAME, strlen(USERNAME),
|
rc = libssh2_userauth_password_ex(session, USERNAME,
|
||||||
PASSWORD, strlen(PASSWORD), NULL);
|
(unsigned int)strlen(USERNAME),
|
||||||
|
PASSWORD,
|
||||||
|
(unsigned int)strlen(PASSWORD), NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
print_last_session_error("libssh2_userauth_password_ex");
|
print_last_session_error("libssh2_userauth_password_ex");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -14,7 +14,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -27,7 +28,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc == 0) {
|
if(rc == 0) {
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL);
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
print_last_session_error("libssh2_userauth_publickey_fromfile_ex");
|
print_last_session_error("libssh2_userauth_publickey_fromfile_ex");
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
const char *userauth_list = NULL;
|
const char *userauth_list = NULL;
|
||||||
|
|
||||||
userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
userauth_list = libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
const char *userauth_list = NULL;
|
const char *userauth_list = NULL;
|
||||||
|
|
||||||
userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
userauth_list = libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -18,7 +18,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
const char *userauth_list = NULL;
|
const char *userauth_list = NULL;
|
||||||
|
|
||||||
userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
userauth_list = libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -16,7 +16,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
const char *userauth_list = NULL;
|
const char *userauth_list = NULL;
|
||||||
|
|
||||||
userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
userauth_list = libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -29,7 +30,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
PASSWORD);
|
PASSWORD);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -16,7 +16,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -29,7 +30,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
PASSWORD);
|
PASSWORD);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
const char *userauth_list = NULL;
|
const char *userauth_list = NULL;
|
||||||
|
|
||||||
userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
userauth_list = libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
||||||
NULL);
|
NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
|
@ -35,7 +35,8 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
|
|
||||||
const char *userauth_list =
|
const char *userauth_list =
|
||||||
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
|
libssh2_userauth_list(session, USERNAME,
|
||||||
|
(unsigned int)strlen(USERNAME));
|
||||||
if(userauth_list == NULL) {
|
if(userauth_list == NULL) {
|
||||||
print_last_session_error("libssh2_userauth_list");
|
print_last_session_error("libssh2_userauth_list");
|
||||||
return 1;
|
return 1;
|
||||||
@ -48,7 +49,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_userauth_publickey_fromfile_ex(
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
||||||
session, USERNAME, strlen(USERNAME),
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
||||||
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL);
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL);
|
||||||
if(rc != 0) {
|
if(rc != 0) {
|
||||||
print_last_session_error("libssh2_userauth_publickey_fromfile_ex");
|
print_last_session_error("libssh2_userauth_publickey_fromfile_ex");
|
||||||
@ -73,7 +74,7 @@ int test(LIBSSH2_SESSION *session)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf));
|
ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf));
|
||||||
if(err < 0)
|
if(err < 0)
|
||||||
fprintf(stderr, "Unable to read response: %zd\n", err);
|
fprintf(stderr, "Unable to read response: %d\n", (int)err);
|
||||||
else {
|
else {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < err; ++i) {
|
for(i = 0; i < err; ++i) {
|
||||||
|
Reference in New Issue
Block a user