1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

style: make includes and examples code style strict

make travis and the makefile rule verify them too

Closes #334
This commit is contained in:
Daniel Stenberg
2019-03-21 09:19:48 +01:00
parent 4186a04cfd
commit 452517d96c
28 changed files with 1060 additions and 958 deletions

View File

@ -102,7 +102,7 @@ install:
script: script:
- | - |
if [ "$B" = "style" ]; then if [ "$B" = "style" ]; then
perl src/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] perl src/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c
fi fi
- | - |
if [ "$B" = "configure" ]; then if [ "$B" = "configure" ]; then

View File

@ -149,4 +149,4 @@ $(VCPROJ): win32/vc8proj.head win32/vc8proj.foot Makefile.am
awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ ) awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ )
checksrc: checksrc:
perl src/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] perl src/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c

View File

@ -98,7 +98,7 @@ int main(int argc, char *argv[])
remote_destport = atoi(argv[7]); remote_destport = atoi(argv[7]);
rc = libssh2_init(0); rc = libssh2_init(0);
if (rc != 0) { if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
return 1; return 1;
} }
@ -118,7 +118,8 @@ int main(int argc, char *argv[])
#endif #endif
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) { sin.sin_addr.s_addr = inet_addr(server_ip);
if(INADDR_NONE == sin.sin_addr.s_addr) {
perror("inet_addr"); perror("inet_addr");
return -1; return -1;
} }
@ -177,14 +178,16 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else if (auth & AUTH_PUBLICKEY) { }
else if(auth & AUTH_PUBLICKEY) {
if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) { keyfile2, password)) {
fprintf(stderr, "\tAuthentication by public key failed!\n"); fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown; goto shutdown;
} }
fprintf(stderr, "\tAuthentication by public key succeeded.\n"); fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} else { }
else {
fprintf(stderr, "No supported authentication methods found!\n"); fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown; goto shutdown;
} }
@ -204,12 +207,14 @@ int main(int argc, char *argv[])
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = htons(local_listenport); sin.sin_port = htons(local_listenport);
if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(local_listenip))) { sin.sin_addr.s_addr = inet_addr(local_listenip);
if(INADDR_NONE == sin.sin_addr.s_addr) {
perror("inet_addr"); perror("inet_addr");
goto shutdown; goto shutdown;
} }
sockopt = 1; sockopt = 1;
setsockopt(listensock, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)); setsockopt(listensock, SOL_SOCKET, SO_REUSEADDR, &sockopt,
sizeof(sockopt));
sinlen = sizeof(sin); sinlen = sizeof(sin);
if(-1 == bind(listensock, (struct sockaddr *)&sin, sinlen)) { if(-1 == bind(listensock, (struct sockaddr *)&sin, sinlen)) {
perror("bind"); perror("bind");
@ -269,7 +274,8 @@ int main(int argc, char *argv[])
if(len < 0) { if(len < 0) {
perror("read"); perror("read");
goto shutdown; goto shutdown;
} else if (0 == len) { }
else if(0 == len) {
fprintf(stderr, "The client at %s:%d disconnected!\n", shost, fprintf(stderr, "The client at %s:%d disconnected!\n", shost,
sport); sport);
goto shutdown; goto shutdown;

View File

@ -58,7 +58,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
if(argc > 2) { if(argc > 2) {
@ -72,7 +73,7 @@ int main(int argc, char *argv[])
} }
rc = libssh2_init(0); rc = libssh2_init(0);
if (rc != 0) { if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
return 1; return 1;
} }
@ -125,11 +126,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
#define HOME_DIR "/home/username/"
if(libssh2_userauth_publickey_fromfile(session, username, if(libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", HOME_DIR ".ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa", HOME_DIR ".ssh/id_rsa",
password)) { password)) {
fprintf(stderr, "\tAuthentication by public key failed\n"); fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;
@ -170,7 +173,8 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session,
"Normal Shutdown, Thank you for playing");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -112,7 +112,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
if(argc > 2) { if(argc > 2) {
@ -140,7 +141,7 @@ int main(int argc, char *argv[])
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = htons(22); sin.sin_port = htons(22);
sin.sin_addr.s_addr = hostaddr; sin.sin_addr.s_addr = hostaddr;
if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) {
fprintf(stderr, "failed to connect!\n"); fprintf(stderr, "failed to connect!\n");
return -1; return -1;
} }
@ -187,7 +188,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
while((rc = libssh2_userauth_publickey_fromfile(session, username, while((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/" "/home/username/"
@ -262,7 +264,8 @@ int main(int argc, char *argv[])
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
time_ms = tvdiff(end, start); time_ms = tvdiff(end, start);
fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", (long)total, fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n",
(long)total,
time_ms, 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);

View File

@ -62,7 +62,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
if(argc > 2) { if(argc > 2) {
@ -144,11 +145,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
#define HOME "/home/username/"
if(libssh2_userauth_publickey_fromfile(session, username, if(libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", HOME ".ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa", HOME ".ssh/id_rsa",
password)) { password)) {
fprintf(stderr, "\tAuthentication by public key failed\n"); fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;
@ -207,7 +210,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
if(session) { if(session) {
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
} }
#ifdef WIN32 #ifdef WIN32

View File

@ -101,7 +101,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
if(argc > 2) { if(argc > 2) {
@ -185,12 +186,15 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
#define HOME "/home/username/"
while((rc = libssh2_userauth_publickey_fromfile(session, username, while((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", HOME ".ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa", HOME ".ssh/id_rsa",
password)) == LIBSSH2_ERROR_EAGAIN); password)) ==
LIBSSH2_ERROR_EAGAIN);
if(rc) { if(rc) {
fprintf(stderr, "\tAuthentication by public key failed\n"); fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;
@ -266,7 +270,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
while(libssh2_session_disconnect(session, while(libssh2_session_disconnect(session,
"Normal Shutdown, Thank you for playing") == "Normal Shutdown,") ==
LIBSSH2_ERROR_EAGAIN); LIBSSH2_ERROR_EAGAIN);
libssh2_session_free(session); libssh2_session_free(session);

View File

@ -45,7 +45,8 @@ const char *sftppath="/tmp/TEST";
static void kbd_callback(const char *name, int name_len, static void kbd_callback(const char *name, int name_len,
const char *instruction, int instruction_len, int num_prompts, const char *instruction, int instruction_len,
int num_prompts,
const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
void **abstract) void **abstract)
@ -117,7 +118,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -214,25 +216,32 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else if (auth_pw & 2) { }
else if(auth_pw & 2) {
/* Or via keyboard-interactive */ /* Or via keyboard-interactive */
if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) ) { if(libssh2_userauth_keyboard_interactive(session, username,
&kbd_callback) ) {
fprintf(stderr, fprintf(stderr,
"\tAuthentication by keyboard-interactive failed!\n"); "\tAuthentication by keyboard-interactive failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, fprintf(stderr,
"\tAuthentication by keyboard-interactive succeeded.\n"); "\tAuthentication by keyboard-interactive succeeded.\n");
} }
} else if (auth_pw & 4) { }
else if(auth_pw & 4) {
/* Or by public key */ /* Or by public key */
if (libssh2_userauth_publickey_fromfile(session, username, keyfile1, keyfile2, password)) { if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) {
fprintf(stderr, "\tAuthentication by public key failed!\n"); fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, "\tAuthentication by public key succeeded.\n"); fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} }
} else { }
else {
fprintf(stderr, "No supported authentication methods found!\n"); fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown; goto shutdown;
} }
@ -264,7 +273,8 @@ int main(int argc, char *argv[])
rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
if(rc > 0) { if(rc > 0) {
write(1, mem, rc); write(1, mem, rc);
} else { }
else {
break; break;
} }
} while(1); } while(1);
@ -274,7 +284,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -180,7 +180,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
while((rc = while((rc =
libssh2_userauth_publickey_fromfile(session, username, libssh2_userauth_publickey_fromfile(session, username,
@ -339,7 +340,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
int err; int err;
err = WSAStartup(MAKEWORD(2, 0), &wsadata); err = WSAStartup(MAKEWORD(2, 0), &wsadata);
if (err != 0) { if(err) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err); fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1; return 1;
} }
@ -66,7 +66,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -84,7 +85,7 @@ int main(int argc, char *argv[])
} }
rc = libssh2_init(0); rc = libssh2_init(0);
if (rc != 0) { if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
return 1; return 1;
} }
@ -146,11 +147,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
#define HOME "/home/username/"
if(libssh2_userauth_publickey_fromfile(session, username, if(libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", HOME ".ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa", HOME ".ssh/id_rsa",
password)) { password)) {
fprintf(stderr, "\tAuthentication by public key failed\n"); fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;

View File

@ -59,7 +59,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -127,7 +128,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
if(libssh2_userauth_publickey_fromfile(session, username, if(libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", "/home/username/.ssh/id_rsa.pub",
@ -161,7 +163,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -59,7 +59,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -127,7 +128,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
if(libssh2_userauth_publickey_fromfile(session, username, if(libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", "/home/username/.ssh/id_rsa.pub",
@ -161,7 +163,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -112,7 +112,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -189,7 +190,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
while((rc = while((rc =
libssh2_userauth_publickey_fromfile(session, username, libssh2_userauth_publickey_fromfile(session, username,
@ -255,7 +257,8 @@ int main(int argc, char *argv[])
if(rc > 0) { if(rc > 0) {
total += rc; total += rc;
write(1, mem, rc); write(1, mem, rc);
} else { }
else {
break; break;
} }
} while(1); } while(1);
@ -263,7 +266,8 @@ 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", total, fprintf(stderr, "Got %d bytes in %ld ms = %.1f bytes/sec spin: %d\n",
total,
time_ms, 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 %d bytes spin: %d\n", total, spin);

View File

@ -65,7 +65,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -145,11 +146,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
const char *pubkey = "/home/username/.ssh/id_rsa.pub";
const char *privkey = "/home/username/.ssh/id_rsa.pub";
if(libssh2_userauth_publickey_fromfile(session, username, if(libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", pubkey, privkey,
"/home/username/.ssh/id_rsa",
password)) { password)) {
fprintf(stderr, "\tAuthentication by public key failed\n"); fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;

View File

@ -4,7 +4,7 @@
* The sample code has default values for host name, user name, password * The sample code has default values for host name, user name, password
* and path to copy, but you can specify them on the command line like: * and path to copy, but you can specify them on the command line like:
* *
* "sftp 192.168.0.1 user password sftp_write_nonblock.c /tmp/sftp_write_nonblock.c" * "sftp 192.168.0.1 user password thisfile /tmp/storehere"
*/ */
#include "libssh2_config.h" #include "libssh2_config.h"
@ -105,7 +105,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -188,11 +189,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
const char *pubkey = "/home/username/.ssh/id_rsa.pub";
const char *privkey = "/home/username/.ssh/id_rsa";
while((rc = libssh2_userauth_publickey_fromfile(session, username, while((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", pubkey, privkey,
"/home/username/.ssh/id_rsa",
password)) == password)) ==
LIBSSH2_ERROR_EAGAIN); LIBSSH2_ERROR_EAGAIN);
if(rc) { if(rc) {
@ -217,10 +220,10 @@ int main(int argc, char *argv[])
do { do {
sftp_handle = sftp_handle =
libssh2_sftp_open(sftp_session, sftppath, libssh2_sftp_open(sftp_session, sftppath,
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|
LIBSSH2_FXF_TRUNC,
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
if(!sftp_handle && if(!sftp_handle &&
(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
fprintf(stderr, "Unable to open file with SFTP\n"); fprintf(stderr, "Unable to open file with SFTP\n");
@ -268,7 +271,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
while (libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing") while(libssh2_session_disconnect(session, "Normal Shutdown")
== LIBSSH2_ERROR_EAGAIN); == LIBSSH2_ERROR_EAGAIN);
libssh2_session_free(session); libssh2_session_free(session);

View File

@ -4,7 +4,7 @@
* The sample code has default values for host name, user name, password * The sample code has default values for host name, user name, password
* and path to copy, but you can specify them on the command line like: * and path to copy, but you can specify them on the command line like:
* *
* "sftp 192.168.0.1 user password sftp_write_nonblock.c /tmp/sftp_write_nonblock.c" * "sftp 192.168.0.1 user password file /tmp/storehere"
*/ */
#include "libssh2_config.h" #include "libssh2_config.h"
@ -105,7 +105,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -188,11 +189,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
#define PUBKEY "/home/username/.ssh/id_rsa.pub"
#define PRIVKEY "/home/username/.ssh/id_rsa"
while((rc = libssh2_userauth_publickey_fromfile(session, username, while((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", PUBKEY, PRIVKEY,
"/home/username/.ssh/id_rsa",
password)) == password)) ==
LIBSSH2_ERROR_EAGAIN); LIBSSH2_ERROR_EAGAIN);
if(rc) { if(rc) {
@ -217,7 +220,8 @@ int main(int argc, char *argv[])
do { do {
sftp_handle = sftp_handle =
libssh2_sftp_open(sftp_session, sftppath, libssh2_sftp_open(sftp_session, sftppath,
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|
LIBSSH2_FXF_TRUNC,
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
@ -277,7 +281,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
while (libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing") while(libssh2_session_disconnect(session, "Normal Shutdown")
== LIBSSH2_ERROR_EAGAIN); == LIBSSH2_ERROR_EAGAIN);
libssh2_session_free(session); libssh2_session_free(session);

View File

@ -91,7 +91,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -184,30 +185,36 @@ int main(int argc, char *argv[])
if(libssh2_userauth_password(session, username, password)) { if(libssh2_userauth_password(session, username, password)) {
fprintf(stderr, "\tAuthentication by password failed!\n"); fprintf(stderr, "\tAuthentication by password failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, "\tAuthentication by password succeeded.\n"); fprintf(stderr, "\tAuthentication by password succeeded.\n");
} }
} else if (auth_pw & 2) { }
else if(auth_pw & 2) {
/* Or via keyboard-interactive */ /* Or via keyboard-interactive */
if(libssh2_userauth_keyboard_interactive(session, username, if(libssh2_userauth_keyboard_interactive(session, username,
&kbd_callback) ) { &kbd_callback) ) {
fprintf(stderr, fprintf(stderr,
"\tAuthentication by keyboard-interactive failed!\n"); "\tAuthentication by keyboard-interactive failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, fprintf(stderr,
"\tAuthentication by keyboard-interactive succeeded.\n"); "\tAuthentication by keyboard-interactive succeeded.\n");
} }
} else if (auth_pw & 4) { }
else if(auth_pw & 4) {
/* Or by public key */ /* Or by public key */
if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) { keyfile2, password)) {
fprintf(stderr, "\tAuthentication by public key failed!\n"); fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, "\tAuthentication by public key succeeded.\n"); fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} }
} else { }
else {
fprintf(stderr, "No supported authentication methods found!\n"); fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown; goto shutdown;
} }
@ -246,7 +253,8 @@ int main(int argc, char *argv[])
if(longentry[0] != '\0') { if(longentry[0] != '\0') {
printf("%s\n", longentry); printf("%s\n", longentry);
} else { }
else {
if(attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { if(attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
/* this should check what permissions it /* this should check what permissions it
is and print the output accordingly */ is and print the output accordingly */
@ -280,7 +288,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -52,6 +52,8 @@ int main(int argc, char *argv[])
const char *username = "username"; const char *username = "username";
const char *password = "password"; const char *password = "password";
const char *sftppath = "/tmp/secretdir"; const char *sftppath = "/tmp/secretdir";
const char *pubkey = "/home/username/.ssh/id_rsa.pub";
const char *privkey = "/home/username/.ssh/id_rsa";
int rc; int rc;
LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP *sftp_session;
LIBSSH2_SFTP_HANDLE *sftp_handle; LIBSSH2_SFTP_HANDLE *sftp_handle;
@ -69,7 +71,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -143,12 +146,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else { }
else {
/* Or by public key */ /* Or by public key */
while((rc = libssh2_userauth_publickey_fromfile(session, username, while((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", pubkey, privkey,
"/home/username/.ssh/id_rsa", password)) ==
password)) == LIBSSH2_ERROR_EAGAIN); LIBSSH2_ERROR_EAGAIN);
if(rc) { if(rc) {
fprintf(stderr, "\tAuthentication by public key failed\n"); fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;
@ -196,13 +200,15 @@ int main(int argc, char *argv[])
/* this should check what permissions it /* this should check what permissions it
is and print the output accordingly */ is and print the output accordingly */
printf("--fix----- "); printf("--fix----- ");
} else { }
else {
printf("---------- "); printf("---------- ");
} }
if(attrs.flags & LIBSSH2_SFTP_ATTR_UIDGID) { if(attrs.flags & LIBSSH2_SFTP_ATTR_UIDGID) {
printf("%4d %4d ", (int) attrs.uid, (int) attrs.gid); printf("%4d %4d ", (int) attrs.uid, (int) attrs.gid);
} else { }
else {
printf(" - - "); printf(" - - ");
} }
@ -215,7 +221,8 @@ int main(int argc, char *argv[])
else if(rc == LIBSSH2_ERROR_EAGAIN) { else if(rc == LIBSSH2_ERROR_EAGAIN) {
/* blocking */ /* blocking */
fprintf(stderr, "Blocking\n"); fprintf(stderr, "Blocking\n");
} else { }
else {
break; break;
} }
@ -226,7 +233,7 @@ int main(int argc, char *argv[])
shutdown: shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session); libssh2_session_free(session);
#ifdef WIN32 #ifdef WIN32

View File

@ -86,7 +86,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -169,36 +170,43 @@ int main(int argc, char *argv[])
if(libssh2_userauth_password(session, username, password)) { if(libssh2_userauth_password(session, username, password)) {
fprintf(stderr, "\tAuthentication by password failed!\n"); fprintf(stderr, "\tAuthentication by password failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, "\tAuthentication by password succeeded.\n"); fprintf(stderr, "\tAuthentication by password succeeded.\n");
} }
} else if (auth_pw & 2) { }
else if(auth_pw & 2) {
/* Or via keyboard-interactive */ /* Or via keyboard-interactive */
if(libssh2_userauth_keyboard_interactive(session, username, if(libssh2_userauth_keyboard_interactive(session, username,
&kbd_callback) ) { &kbd_callback) ) {
fprintf(stderr, fprintf(stderr,
"\tAuthentication by keyboard-interactive failed!\n"); "\tAuthentication by keyboard-interactive failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, fprintf(stderr,
"\tAuthentication by keyboard-interactive succeeded.\n"); "\tAuthentication by keyboard-interactive succeeded.\n");
} }
} else if (auth_pw & 4) { }
else if(auth_pw & 4) {
/* Or by public key */ /* Or by public key */
if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) { keyfile2, password)) {
fprintf(stderr, "\tAuthentication by public key failed!\n"); fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown; goto shutdown;
} else { }
else {
fprintf(stderr, "\tAuthentication by public key succeeded.\n"); fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} }
} else { }
else {
fprintf(stderr, "No supported authentication methods found!\n"); fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown; goto shutdown;
} }
/* Request a shell */ /* Request a shell */
if (!(channel = libssh2_channel_open_session(session))) { channel = libssh2_channel_open_session(session);
if(!channel) {
fprintf(stderr, "Unable to open a session\n"); fprintf(stderr, "Unable to open a session\n");
goto shutdown; goto shutdown;
} }

View File

@ -63,7 +63,8 @@ int main(int argc, char *argv[])
if(argc > 1) { if(argc > 1) {
hostaddr = inet_addr(argv[1]); hostaddr = inet_addr(argv[1]);
} else { }
else {
hostaddr = htonl(0x7F000001); hostaddr = htonl(0x7F000001);
} }
@ -156,7 +157,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "\tAuthentication with username %s and " fprintf(stderr, "\tAuthentication with username %s and "
"public key %s failed!\n", "public key %s failed!\n",
username, identity->comment); username, identity->comment);
} else { }
else {
fprintf(stderr, "\tAuthentication with username %s and " fprintf(stderr, "\tAuthentication with username %s and "
"public key %s succeeded!\n", "public key %s succeeded!\n",
username, identity->comment); username, identity->comment);
@ -172,7 +174,8 @@ int main(int argc, char *argv[])
/* We're authenticated now. */ /* We're authenticated now. */
/* Request a shell */ /* Request a shell */
if (!(channel = libssh2_channel_open_session(session))) { channel = libssh2_channel_open_session(session);
if(!channel) {
fprintf(stderr, "Unable to open a session\n"); fprintf(stderr, "Unable to open a session\n");
goto shutdown; goto shutdown;
} }

View File

@ -239,7 +239,8 @@ int main(int argc, char *argv[])
for(i = 0; i < BUFSIZE; i++) for(i = 0; i < BUFSIZE; i++)
buffer[i] = 'A'; buffer[i] = 'A';
if ((fds = malloc (sizeof (LIBSSH2_POLLFD))) == NULL) { fds = malloc(sizeof (LIBSSH2_POLLFD));
if(!fds) {
fprintf(stderr, "malloc failed\n"); fprintf(stderr, "malloc failed\n");
exit(1); exit(1);
} }
@ -301,7 +302,8 @@ int main(int argc, char *argv[])
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
} else { }
else {
/* all data written, send EOF */ /* all data written, send EOF */
rc = libssh2_channel_send_eof(channel); rc = libssh2_channel_send_eof(channel);

View File

@ -237,35 +237,28 @@ int main(int argc, char *argv[])
/* Exec non-blocking on the remove host */ /* Exec non-blocking on the remove host */
while((channel = libssh2_channel_open_session(session)) == NULL && while((channel = libssh2_channel_open_session(session)) == NULL &&
libssh2_session_last_error(session, NULL, NULL, 0) == libssh2_session_last_error(session, NULL, NULL, 0) ==
LIBSSH2_ERROR_EAGAIN ) LIBSSH2_ERROR_EAGAIN) {
{
waitsocket(sock, session); waitsocket(sock, session);
} }
if( channel == NULL ) if(channel == NULL) {
{
fprintf(stderr, "Error\n"); fprintf(stderr, "Error\n");
exit(1); exit(1);
} }
while((rc = libssh2_channel_exec(channel, commandline)) == while((rc = libssh2_channel_exec(channel, commandline)) ==
LIBSSH2_ERROR_EAGAIN ) LIBSSH2_ERROR_EAGAIN) {
{
waitsocket(sock, session); waitsocket(sock, session);
} }
if( rc != 0 ) if(rc != 0) {
{
fprintf(stderr, "Error\n"); fprintf(stderr, "Error\n");
exit(1); exit(1);
} }
for( ;; ) for(;;) {
{
/* loop until we block */ /* loop until we block */
int rc; int rc;
do do {
{
char buffer[0x4000]; char buffer[0x4000];
rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); rc = libssh2_channel_read(channel, buffer, sizeof(buffer) );
if( rc > 0 ) if(rc > 0) {
{
int i; int i;
bytecount += rc; bytecount += rc;
fprintf(stderr, "We read:\n"); fprintf(stderr, "We read:\n");
@ -283,8 +276,7 @@ int main(int argc, char *argv[])
/* 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(rc == LIBSSH2_ERROR_EAGAIN) {
{
waitsocket(sock, session); waitsocket(sock, session);
} }
else else
@ -294,8 +286,7 @@ int main(int argc, char *argv[])
while((rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN) while((rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN)
waitsocket(sock, session); waitsocket(sock, session);
if( rc == 0 ) if(rc == 0) {
{
exitcode = libssh2_channel_get_exit_status(channel); exitcode = libssh2_channel_get_exit_status(channel);
libssh2_channel_get_exit_signal(channel, &exitsignal, libssh2_channel_get_exit_signal(channel, &exitsignal,
NULL, NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL, NULL);

View File

@ -98,7 +98,8 @@ static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag,
} while(!specialsequence && rd < buflen); } while(!specialsequence && rd < buflen);
if(!specialsequence) { if(!specialsequence) {
fprintf(stderr, "%s: ]]>]]> not found! read buffer too small?\n", __func__); fprintf(stderr, "%s: ]]>]]> not found! read buffer too small?\n",
__func__);
return -1; return -1;
} }
@ -162,7 +163,8 @@ int main(int argc, char *argv[])
#endif #endif
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) { sin.sin_addr.s_addr = inet_addr(server_ip);
if(INADDR_NONE == sin.sin_addr.s_addr) {
fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip);
return -1; return -1;
} }
@ -221,14 +223,16 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else if (auth & AUTH_PUBLICKEY) { }
else if(auth & AUTH_PUBLICKEY) {
if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) { keyfile2, password)) {
fprintf(stderr, "Authentication by public key failed!\n"); fprintf(stderr, "Authentication by public key failed!\n");
goto shutdown; goto shutdown;
} }
fprintf(stderr, "Authentication by public key succeeded.\n"); fprintf(stderr, "Authentication by public key succeeded.\n");
} else { }
else {
fprintf(stderr, "No supported authentication methods found!\n"); fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown; goto shutdown;
} }
@ -269,7 +273,8 @@ int main(int argc, char *argv[])
if(-1 == len) if(-1 == len)
goto shutdown; goto shutdown;
fprintf(stderr, "Got %d bytes:\n----------------------\n%s", (int)len, buf); fprintf(stderr, "Got %d bytes:\n----------------------\n%s",
(int)len, buf);
fprintf(stderr, "Sending NETCONF <rpc>\n"); fprintf(stderr, "Sending NETCONF <rpc>\n");
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
@ -286,7 +291,8 @@ int main(int argc, char *argv[])
if(-1 == len) if(-1 == len)
goto shutdown; goto shutdown;
fprintf(stderr, "Got %d bytes:\n----------------------\n%s", (int)len, buf); fprintf(stderr, "Got %d bytes:\n----------------------\n%s",
(int)len, buf);
shutdown: shutdown:
if(channel) if(channel)

View File

@ -115,7 +115,8 @@ int main(int argc, char *argv[])
#endif #endif
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) { sin.sin_addr.s_addr = inet_addr(server_ip);
if(INADDR_NONE == sin.sin_addr.s_addr) {
perror("inet_addr"); perror("inet_addr");
return -1; return -1;
} }
@ -174,14 +175,16 @@ int main(int argc, char *argv[])
fprintf(stderr, "Authentication by password failed.\n"); fprintf(stderr, "Authentication by password failed.\n");
goto shutdown; goto shutdown;
} }
} else if (auth & AUTH_PUBLICKEY) { }
else if(auth & AUTH_PUBLICKEY) {
if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, if(libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) { keyfile2, password)) {
fprintf(stderr, "\tAuthentication by public key failed!\n"); fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown; goto shutdown;
} }
fprintf(stderr, "\tAuthentication by public key succeeded.\n"); fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} else { }
else {
fprintf(stderr, "No supported authentication methods found!\n"); fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown; goto shutdown;
} }
@ -228,7 +231,8 @@ int main(int argc, char *argv[])
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = htons(local_destport); sin.sin_port = htons(local_destport);
if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(local_destip))) { sin.sin_addr.s_addr = inet_addr(local_destip);
if(INADDR_NONE == sin.sin_addr.s_addr) {
perror("inet_addr"); perror("inet_addr");
goto shutdown; goto shutdown;
} }
@ -258,7 +262,8 @@ int main(int argc, char *argv[])
if(len < 0) { if(len < 0) {
perror("read"); perror("read");
goto shutdown; goto shutdown;
} else if (0 == len) { }
else if(0 == len) {
fprintf(stderr, "The local server at %s:%d disconnected!\n", fprintf(stderr, "The local server at %s:%d disconnected!\n",
local_destip, local_destport); local_destip, local_destport);
goto shutdown; goto shutdown;

View File

@ -197,10 +197,12 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock)
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(sock, &set); FD_SET(sock, &set);
if ((buf = calloc (bufsize, sizeof(char))) == NULL) buf = calloc(bufsize, sizeof(char));
if(!buf)
return 0; return 0;
if ((fds = malloc (sizeof (LIBSSH2_POLLFD))) == NULL) { fds = malloc(sizeof (LIBSSH2_POLLFD));
if(!fds) {
free(buf); free(buf);
return 0; return 0;
} }
@ -403,10 +405,12 @@ main (int argc, char *argv[])
w_size.ws_row); w_size.ws_row);
} }
if ((buf = calloc (bufsiz, sizeof(char))) == NULL) buf = calloc(bufsiz, sizeof(char));
if(buf == NULL)
break; break;
if ((fds = malloc (sizeof (LIBSSH2_POLLFD))) == NULL) { fds = malloc(sizeof (LIBSSH2_POLLFD));
if(fds == NULL) {
free(buf); free(buf);
break; break;
} }

View File

@ -213,7 +213,8 @@ typedef off_t libssh2_struct_stat_size;
#ifndef LIBSSH2_STRUCT_STAT_SIZE_FORMAT #ifndef LIBSSH2_STRUCT_STAT_SIZE_FORMAT
# ifdef __VMS # ifdef __VMS
/* We have to roll our own format here because %z is a C99-ism we don't have. */ /* We have to roll our own format here because %z is a C99-ism we don't
have. */
# if __USE_OFF64_T || __USING_STD_STAT # if __USE_OFF64_T || __USING_STD_STAT
# define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%Ld" # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%Ld"
# else # else
@ -229,11 +230,11 @@ typedef off_t libssh2_struct_stat_size;
/* Part of every banner, user specified or not */ /* Part of every banner, user specified or not */
#define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
/* We *could* add a comment here if we so chose */
#define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n" #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */ /* Default generate and safe prime sizes for
diffie-hellman-group-exchange-sha1 */
#define LIBSSH2_DH_GEX_MINGROUP 1024 #define LIBSSH2_DH_GEX_MINGROUP 1024
#define LIBSSH2_DH_GEX_OPTGROUP 1536 #define LIBSSH2_DH_GEX_OPTGROUP 1536
#define LIBSSH2_DH_GEX_MAXGROUP 2048 #define LIBSSH2_DH_GEX_MAXGROUP 2048
@ -324,10 +325,12 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
LIBSSH2_CHANNEL *channel, void **channel_abstract) LIBSSH2_CHANNEL *channel, void **channel_abstract)
/* I/O callbacks */ /* I/O callbacks */
#define LIBSSH2_RECV_FUNC(name) ssize_t name(libssh2_socket_t socket, \ #define LIBSSH2_RECV_FUNC(name) \
ssize_t name(libssh2_socket_t socket, \
void *buffer, size_t length, \ void *buffer, size_t length, \
int flags, void **abstract) int flags, void **abstract)
#define LIBSSH2_SEND_FUNC(name) ssize_t name(libssh2_socket_t socket, \ #define LIBSSH2_SEND_FUNC(name) \
ssize_t name(libssh2_socket_t socket, \
const void *buffer, size_t length, \ const void *buffer, size_t length, \
int flags, void **abstract) int flags, void **abstract)
@ -468,7 +471,8 @@ typedef struct _LIBSSH2_POLLFD {
#define LIBSSH2_ERROR_FILE -16 #define LIBSSH2_ERROR_FILE -16
#define LIBSSH2_ERROR_METHOD_NONE -17 #define LIBSSH2_ERROR_METHOD_NONE -17
#define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18 #define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18
#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED LIBSSH2_ERROR_AUTHENTICATION_FAILED #define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED \
LIBSSH2_ERROR_AUTHENTICATION_FAILED
#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19 #define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20 #define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
#define LIBSSH2_ERROR_CHANNEL_FAILURE -21 #define LIBSSH2_ERROR_CHANNEL_FAILURE -21
@ -609,12 +613,14 @@ LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
unsigned int username_len); unsigned int username_len);
LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session); LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, LIBSSH2_API int
libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
const char *username, const char *username,
unsigned int username_len, unsigned int username_len,
const char *password, const char *password,
unsigned int password_len, unsigned int password_len,
LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb))); LIBSSH2_PASSWD_CHANGEREQ_FUNC
((*passwd_change_cb)));
#define libssh2_userauth_password(session, username, password) \ #define libssh2_userauth_password(session, username, password) \
libssh2_userauth_password_ex((session), (username), \ libssh2_userauth_password_ex((session), (username), \
@ -641,7 +647,8 @@ libssh2_userauth_publickey(LIBSSH2_SESSION *session,
const char *username, const char *username,
const unsigned char *pubkeydata, const unsigned char *pubkeydata,
size_t pubkeydata_len, size_t pubkeydata_len,
LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)), LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC
((*sign_callback)),
void **abstract); void **abstract);
LIBSSH2_API int LIBSSH2_API int
@ -733,7 +740,8 @@ libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
LIBSSH2_API LIBSSH2_LISTENER * LIBSSH2_API LIBSSH2_LISTENER *
libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host, libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
int port, int *bound_port, int queue_maxsize); int port, int *bound_port,
int queue_maxsize);
#define libssh2_channel_forward_listen(session, port) \ #define libssh2_channel_forward_listen(session, port) \
libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16) libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
@ -764,8 +772,10 @@ LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
libssh2_channel_request_pty_ex((channel), (term), \ libssh2_channel_request_pty_ex((channel), (term), \
(unsigned int)strlen(term), \ (unsigned int)strlen(term), \
NULL, 0, \ NULL, 0, \
LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, \ LIBSSH2_TERM_WIDTH, \
LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX) LIBSSH2_TERM_HEIGHT, \
LIBSSH2_TERM_WIDTH_PX, \
LIBSSH2_TERM_HEIGHT_PX)
LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel, LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
int width, int height, int width, int height,
@ -835,7 +845,8 @@ LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
#define libssh2_channel_write(channel, buf, buflen) \ #define libssh2_channel_write(channel, buf, buflen) \
libssh2_channel_write_ex((channel), 0, (buf), (buflen)) libssh2_channel_write_ex((channel), 0, (buf), (buflen))
#define libssh2_channel_write_stderr(channel, buf, buflen) \ #define libssh2_channel_write_stderr(channel, buf, buflen) \
libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen)) libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, \
(buf), (buflen))
LIBSSH2_API unsigned long LIBSSH2_API unsigned long
libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,

View File

@ -81,9 +81,11 @@ extern "C" {
#endif #endif
/* Publickey Subsystem */ /* Publickey Subsystem */
LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session); LIBSSH2_API LIBSSH2_PUBLICKEY *
libssh2_publickey_init(LIBSSH2_SESSION *session);
LIBSSH2_API int libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, LIBSSH2_API int
libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey,
const unsigned char *name, const unsigned char *name,
unsigned long name_len, unsigned long name_len,
const unsigned char *blob, const unsigned char *blob,
@ -107,7 +109,8 @@ LIBSSH2_API int
libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey,
unsigned long *num_keys, unsigned long *num_keys,
libssh2_publickey_list **pkey_list); libssh2_publickey_list **pkey_list);
LIBSSH2_API void libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey, LIBSSH2_API void
libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey,
libssh2_publickey_list *pkey_list); libssh2_publickey_list *pkey_list);
LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey); LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey);

View File

@ -224,7 +224,8 @@ LIBSSH2_API unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp);
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp); LIBSSH2_API LIBSSH2_CHANNEL *libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp);
/* File / Directory Ops */ /* File / Directory Ops */
LIBSSH2_API LIBSSH2_SFTP_HANDLE *libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, LIBSSH2_API LIBSSH2_SFTP_HANDLE *
libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp,
const char *filename, const char *filename,
unsigned int filename_len, unsigned int filename_len,
unsigned long flags, unsigned long flags,
@ -331,7 +332,8 @@ LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp,
const char *path, const char *path,
unsigned int path_len, unsigned int path_len,
char *target, char *target,
unsigned int target_len, int link_type); unsigned int target_len,
int link_type);
#define libssh2_sftp_symlink(sftp, orig, linkpath) \ #define libssh2_sftp_symlink(sftp, orig, linkpath) \
libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), \ libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), \
strlen(linkpath), LIBSSH2_SFTP_SYMLINK) strlen(linkpath), LIBSSH2_SFTP_SYMLINK)