Compare commits

...

45 Commits

Author SHA1 Message Date
Daniel Stenberg
f1cfa55b60 RELEASE-NOTES: fixed for 1.4.3 2012-11-27 22:44:09 +01:00
Daniel Stenberg
437a3b75ec sftp_read: return error if a too large package arrives 2012-11-20 08:23:39 +01:00
Peter Stuge
a3ad635db4 Only define _libssh2_dsa_*() functions when building with DSA support 2012-11-13 00:11:47 +01:00
Guenter Knauf
e5c5408564 Added .def file to output. 2012-11-08 18:57:14 +01:00
Kamil Dudka
fe8f3deb48 libssh2_hostkey_hash.3: update the description of return value
The function returns NULL also if the hash algorithm is not available.
2012-11-01 15:04:07 +01:00
Guenter Knauf
d49b8f303a Fixed mode acciedently committed. 2012-10-24 03:41:10 +02:00
Guenter Knauf
6f8777505f Ignore generated file. 2012-10-24 03:29:50 +02:00
Guenter Knauf
52b8da7dfa Added hack to make use of Makefile.inc.
This should avoid further maintainance of the objects list.
2012-10-24 03:22:07 +02:00
Guenter Knauf
de7b5d3bc0 Fixed MSVC NMakefile.
Added missing source files; added resource for DLL.
2012-10-24 02:37:55 +02:00
Kamil Dudka
b31e35aba6 examples: use stderr for messages, stdout for data
Reported by: Karel Srot
Bug: https://bugzilla.redhat.com/867462
2012-10-22 13:39:58 +02:00
Kamil Dudka
e2bb780d77 openssl: do not leak memory when handling errors
,.. in aes_ctr_init().  Detected by Coverity.
2012-10-08 14:30:40 +02:00
Kamil Dudka
a8cfc708c5 channel: fix possible NULL dereference
... in libssh2_channel_get_exit_signal().  Detected by Coverity.
2012-10-08 14:19:23 +02:00
Kamil Dudka
9f6fd5af82 Revert "aes: the init function fails when OpenSSL has AES support"
This partially reverts commit f4f2298ef3.

We need to use the EVP_aes_???_ctr() functions in FIPS mode.
2012-09-17 09:48:07 +02:00
Kamil Dudka
5d567faecc crypt: use hard-wired cipher block sizes consistently 2012-09-17 09:48:07 +02:00
Kamil Dudka
bfbb5a4dc7 openssl: do not ignore failure of EVP_CipherInit() 2012-09-17 09:48:07 +02:00
Kamil Dudka
43b730ce56 kex: do not ignore failure of libssh2_md5_init()
The MD5 algorithm is disabled when running in FIPS mode.
2012-09-17 09:48:05 +02:00
Peter Krempa
6af85b6053 known_hosts: Fail when parsing unknown keys in known_hosts file.
libssh2_knownhost_readfile() silently ignored problems when reading keys
in unsupported formats from the known hosts file. When the file is
written again from the internal structures of libssh2 it gets truntcated
to the point where the first unknown key was located.

 * src/knownhost.c:libssh2_knownhost_readfile() - return error if key
                                                  parsing fails
2012-08-21 20:27:28 +02:00
Daniel Stenberg
05641218bc AUTHORS: synced with 42fec44c8a
31 recent authors added
2012-08-19 23:34:53 +02:00
Dave Hayden
42fec44c8a compression: add support for zlib@openssh.com
Add a "use_in_auth" flag to the LIBSSH2_COMP_METHOD struct and a
separate "zlib@openssh.com" method, along with checking session->state
for LIBSSH2_STATE_AUTHENTICATED. Appears to work on the OpenSSH servers
I've tried against, and it should work as before with normal zlib
compression.
2012-08-19 13:47:50 +02:00
Dmitry Smirnov
e470738a0c configure: gcrypt doesn't come with pkg-config support
... so use plain old -lgcrypt to the linker to link with it.

Fixes #225
2012-08-13 23:35:50 +02:00
Daniel Stenberg
62cc59cd06 sftp_read: Value stored to 'next' is never read
Detected by clang-analyzer
2012-08-08 15:18:43 +02:00
Daniel Stenberg
1abf2057de publickey_init: errors are negative, fix check
Detected by clang-analyzer.
2012-08-08 15:15:30 +02:00
Maxime Larocque
6c27922ac1 session_free: wrong variable used for keeping state
If libssh2_session_free is called without the channel being freed
previously by libssh2_channel_free a memory leak could occur.

A mismatch of states variables in session_free() prevent the call to
libssh2_channel_free function. session->state member is used instead of
session->free_state.

It causes a leak of around 600 bytes on every connection on my systems
(Linux, x64 and PPC).

(Debugging done under contract for Accedian Networks)

Fixes #246
2012-07-25 01:08:03 +02:00
Guenter Knauf
112845df0b Small NetWare makefile tweak. 2012-06-29 17:20:56 +02:00
Guenter Knauf
499b22ca36 Some small Win32 makefile fixes. 2012-06-20 18:08:01 +02:00
Daniel Stenberg
6403519fcf libssh2_userauth_publickey_fromfile_ex.3: mention publickey == NULL 2012-06-19 22:08:45 +02:00
Daniel Stenberg
6f8dd9baff comp_method_zlib_decomp: handle Z_BUF_ERROR when inflating
When using libssh2 to perform an SFTP file transfer from the "JSCAPE MFT
Server" (http://www.jscape.com) the transfer failed. The default JSCAPE
configuration is to enforce zlib compression on SSH2 sessions so the
session was compressed. The relevant part of the debug trace contained:

 [libssh2] 1.052750 Transport: unhandled zlib error -5
 [libssh2] 1.052750 Failure Event: -29 - decompression failure

The trace comes from comp_method_zlib_decomp() in comp.c. The "unhandled
zlib error -5" is the status returned from the zlib function
inflate(). The -5 status corresponds to "Z_BUF_ERROR".

The inflate() function takes a pointer to a z_stream structure and
"inflates" (decompresses) as much as it can. The relevant fields of the
z_stream structure are:

  next_in - pointer to the input buffer containing compressed data
  avail_in - the number of bytes available at next_in
  next_out - pointer to the output buffer to be filled with uncompressed
             data
  avail_out - how much space available at next_out

To decompress data you set up a z_stream struct with the relevant fields
filled in and pass it to inflate(). On return the fields will have been
updated so next_in and avail_in show how much compressed data is yet to
be processed and next_out and avail_out show how much space is left in
the output buffer.

If the supplied output buffer is too small then on return there will be
compressed data yet to be processed (avail_in != 0) and inflate() will
return Z_OK. In this case the output buffer must be grown, avail_out
updated and inflate() called again.

If the supplied output buffer was big enough then on return the
compressed data will have been exhausted (avail_in == 0) and inflate()
will return Z_OK, so the data has all been uncompressed.

There is a corner case where inflate() makes no progress. That is, there
may be unprocessed compressed data and space available in the output
buffer and yet the function does nothing. In this case inflate() will
return Z_BUF_ERROR. From the zlib documentation and the source code it
is not clear under what circumstances this happens. It could be that it
needs to write multiple bytes (all in one go) from its internal state to
the output buffer before processing the next chunk of input but but
can't because there is not enough space (though my guesses as to the
cause are not really relevant). Recovery from Z_BUF_ERROR is pretty
simple - just grow the output buffer, update avail_out and call
inflate() again.

The comp_method_zlib_decomp() function does not handle the case when
inflate() returns Z_BUF_ERROR. It treats it as a non-recoverable error
and basically aborts the session.

Fixes #240
2012-06-14 16:11:48 +02:00
Guenter Knauf
a1c0d97ff9 MinGW makefile tweaks.
Use GNU tools when compiling on Linux.
Fixed dist and dev targets.
2012-06-12 01:03:14 +02:00
Guenter Knauf
5c065bf1ff NetWare makefile tweaks.
Changed to use Windows commandline tools instead of
GNU tools when compiling on Windows. Fixed dist and
dev targets. Enabled nlmconv error for unresolved
symbols.
2012-06-12 00:34:18 +02:00
Daniel Stenberg
5237177daf Revert "config.rpath: generated file, no need to keep in git"
This reverts commit 1ac7bd09cc.

This file still used by lib/*m4 functions so we need to keep the file
around.
2012-06-11 14:52:31 +02:00
Daniel Stenberg
bd627d38a1 BINDINGS: added PySsh2, a Python-ctypes binding 2012-06-09 00:14:17 +02:00
Guenter Knauf
c55b0b0425 Fixed MinGW debug build. 2012-06-08 08:03:24 +02:00
Daniel Stenberg
38efbe8243 BINDINGS: Added the Cocoa/Objective-C one
... and sorted the bindings after the languages, alphabetically

Reported by: Mike Abdullah
2012-06-05 15:43:50 +02:00
Daniel Stenberg
34ecc09a3c BINDINGS: document the bindings we know of 2012-06-05 11:40:51 +02:00
Guenter Knauf
d6cf1c7df0 Fixed LIBSSH2_INT64_T_FORMAT macro.
Usually a format macro should hold the whole format, otherwise
it should be named a prefix. Also fixed usage of this macro in
scp.c for a signed var where it was used as prefix for unsigned.
2012-06-04 22:54:25 +02:00
Guenter Knauf
a40c160cff Removed obsolete define from makefiles. 2012-06-04 17:01:27 +02:00
Guenter Knauf
29e256e817 Renamed NetWare makefiles. 2012-06-04 15:27:02 +02:00
Guenter Knauf
137342a41d Renamed NetWare makefiles. 2012-06-04 15:24:39 +02:00
Guenter Knauf
79a7ca3085 Synced MinGW makefiles with 56c64a6..39e438f.
Also synced MinGW test makefile with b092696..f8cb874.
2012-06-04 15:17:22 +02:00
Peter Stuge
50e37bdadc Revert "sftp: Don't send attrs.permissions on read-only SSH_FXP_OPEN"
This reverts commit 04e79e0c79.
2012-05-30 17:50:37 +02:00
Peter Stuge
04e79e0c79 sftp: Don't send attrs.permissions on read-only SSH_FXP_OPEN
This works around a protocol violation in the ProFTPD 1.3.4 mod_sftp
server, as reported by Will Cosgrove in:

http://libssh2.org/mail/libssh2-devel-archive-2012-05/0079.shtml

Based on a suggested fix by TJ Saunders in:

http://libssh2.org/mail/libssh2-devel-archive-2012-05/0104.shtml
2012-05-30 15:29:25 +02:00
Guenter Knauf
9a36065b52 Try to detect OpenSSL build type automatically.
Also fixed recently added libgdi32 linkage which is only
required when OpenSSL libs are linked statically.
2012-05-28 12:53:15 +02:00
Daniel Stenberg
1ac7bd09cc config.rpath: generated file, no need to keep in git 2012-05-25 09:07:18 +02:00
Guenter Knauf
9a7311ba57 Updated dependency libary versions. 2012-05-22 04:10:52 +02:00
Daniel Stenberg
e07b11b7df 1.4.3: towards the future 2012-05-18 23:44:07 +02:00
57 changed files with 734 additions and 517 deletions

31
AUTHORS
View File

@@ -6,32 +6,57 @@
Adam Gobiowski
Alexander Holyapin
Alexander Lamaison
Alfred Gebert
Ben Kibbey
Bjorn Stenborg
Carlo Bramini
Cristian Rodríguez
Daiki Ueno
Dan Casey
Dan Fandrich
Daniel Stenberg
Dave Hayden
Dave McCaldon
David J Sullivan
David Robins
Dmitry Smirnov
Douglas Masterson
Edink Kadribasic
Erik Brossler
Francois Dupoux
Gellule Xg
Grubsky Grigory
Guenter Knauf
Heiner Steven
Henrik Nordstrom
James Housleys
Jasmeet Bagga
Jean-Louis Charton
Jernej Kovacic
Joey Degges
John Little
Jose Baars
Jussi Mononen
Kamil Dudka
Lars Nordin
Mark McPherson
Mark Smith
Markus Moeller
Matt Lilley
Matthew Booth
Maxime Larocque
Mike Protts
Mikhail Gusarov
Neil Gierman
Olivier Hervieu
Paul Howarth
Paul Querna
Paul Veldkamp
Peter Krempa
Peter O'Gorman
Peter Stuge
Pierre Joye
Rafael Kitover
Romain Bondue
Sara Golemon
Satish Mittal
@@ -39,10 +64,16 @@ Sean Peterson
Selcuk Gueney
Simon Hart
Simon Josefsson
Sofian Brabez
Steven Ayre
Steven Dake
Steven Van Ingelgem
TJ Saunders
Tommy Lindgren
Tor Arntsen
Vincent Jaulin
Vincent Torri
Vlad Grachov
Wez Furlong
Yang Tse
Zl Liu

View File

@@ -14,10 +14,9 @@ include_HEADERS = \
include/libssh2_sftp.h
NETWAREFILES = nw/keepscreen.c \
nw/Makefile \
nw/Makefile.netware \
nw/nwlib.c \
nw/test/Makefile.netware
nw/nwlib.c \
nw/GNUmakefile \
nw/test/GNUmakefile
DSP = win32/libssh2.dsp
VCPROJ = win32/libssh2.vcproj
@@ -34,7 +33,7 @@ win32/Makefile.Watcom win32/libssh2.dsw win32/tests.dsp $(DSP) \
win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc
EXTRA_DIST = $(WIN32FILES) buildconf $(NETWAREFILES) get_ver.awk HACKING \
maketgz NMakefile TODO RELEASE-NOTES libssh2.pc.in $(VMSFILES)
maketgz NMakefile TODO RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath
ACLOCAL_AMFLAGS = -I m4

View File

@@ -1,19 +1,28 @@
!include "win32/config.mk"
!include "Makefile.inc"
OBJECTS=$(CSOURCES:.c=.obj)
# SUBDIRS=src example
SUBDIRS=src
all-sub:
all-sub: win32\objects.mk
-for %D in ($(SUBDIRS)) do $(MAKE) /nologo /f %D/NMakefile BUILD=$(BUILD) SUBDIR=%D all-sub
clean:
-rmdir /s/q $(TARGET)
-rmdir 2>NUL /s/q $(TARGET)
real-clean: clean
-del libssh2.dll
-del libssh2.exp
-del libssh2.ilk
-del libssh2.lib
-del *.pdb
real-clean vclean: clean
-del 2>NUL libssh2.dll
-del 2>NUL libssh2.exp
-del 2>NUL libssh2.ilk
-del 2>NUL libssh2.lib
-del 2>NUL *.pdb
-del 2>NUL win32\objects.mk
win32\objects.mk: Makefile.inc
@echo OBJECTS = \>$@
@for %O in ($(OBJECTS)) do @echo $$(INTDIR)\%O \>>$@
@echo $$(EOL)>>$@

View File

@@ -1,21 +1,28 @@
libssh2 1.4.2
libssh2 1.4.3
This release includes the following changes:
o compression: add support for zlib@openssh.com
This release includes the following bugfixes:
o Return LIBSSH2_ERROR_SOCKET_DISCONNECT on EOF when reading banner
o userauth.c: fread() from public key file to correctly detect any errors
o configure.ac: Add option to disable build of the example applications
o Added 'Requires.private:' line to libssh2.pc
o SFTP: filter off incoming "zombie" responses
o gettimeofday: no need for a replacement under cygwin
o SSH_MSG_CHANNEL_REQUEST: default to want_reply
o win32/libssh2_config.h: Remove hardcoded #define LIBSSH2_HAVE_ZLIB
o sftp_read: return error if a too large package arrives
o libssh2_hostkey_hash.3: update the description of return value
o Fixed MSVC NMakefile
o examples: use stderr for messages, stdout for data
o openssl: do not leak memory when handling errors
o improved handling of disabled MD5 algorithm in OpenSSL
o known_hosts: Fail when parsing unknown keys in known_hosts file
o configure: gcrypt doesn't come with pkg-config support
o session_free: wrong variable used for keeping state
o libssh2_userauth_publickey_fromfile_ex.3: mention publickey == NULL
o comp_method_zlib_decomp: handle Z_BUF_ERROR when inflating
This release would not have looked like this without help, code, reports and
advice from friends like these:
Alexander Lamaison, Rafael Kitover, Guenter Knauf, Peter Stuge,
Oleksiy Zagorskyi
Guenter Knauf, Peter Stuge, TJ Saunders, Mike Abdullah, Maxime Larocque,
Dmitry Smirnov, Dave Hayden, Peter Krempa, Kamil Dudka
Thanks! (and sorry if I forgot to mention someone)

View File

@@ -102,7 +102,7 @@ fi
# Look for libgcrypt
if test "$ac_cv_libssl" != "yes" && test "$use_libgcrypt" != "no"; then
AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>])
LIBSREQUIRED=libgcrypt
LIBS="$LIBS -lgcrypt"
fi
AC_SUBST(LIBSREQUIRED)

29
docs/BINDINGS Normal file
View File

@@ -0,0 +1,29 @@
Creative people have written bindings or interfaces for various environments
and programming languages. Using one of these bindings allows you to take
advantage of libssh2 directly from within your favourite language.
The bindings listed below are not part of the libssh2 distribution archives,
but must be downloaded and installed separately.
Cocoa/Objective-C
https://github.com/karelia/libssh2_sftp-Cocoa-wrapper
Haskell
FFI bindings - http://hackage.haskell.org/package/libssh2
Perl
Net::SSH2 - http://search.cpan.org/~rkitover/Net-SSH2-0.45/lib/Net/SSH2.pm
PHP
ssh2 - http://pecl.php.net/package/ssh2
Python
pylibssh2 - http://www.wallix.org/pylibssh2-project/
Python-ctypes
PySsh2 - https://github.com/gellule/PySsh2
Ruby
libssh2-ruby - https://github.com/mitchellh/libssh2-ruby

View File

@@ -1,6 +1,6 @@
# $Id: Makefile.am,v 1.37 2009/03/26 15:41:15 bagder Exp $
EXTRA_DIST = template.3
EXTRA_DIST = template.3 BINDINGS
dist_man_MANS = \
libssh2_agent_connect.3 \

View File

@@ -18,8 +18,9 @@ Returns the computed digest of the remote system's hostkey. The length of
the returned string is hash_type specific (e.g. 16 bytes for MD5,
20 bytes for SHA1).
.SH RETURN VALUE
Computed hostkey hash value. or NULL if the session has not yet been started
up. (The hash consists of raw binary bytes, not hex digits, so is not
directly printable.)
Computed hostkey hash value, or NULL if the information is not available
(either the session has not yet been started up, or the requested hash
algorithm was not available). The hash consists of raw binary bytes, not hex
digits, so it is not directly printable.
.SH SEE ALSO
.BR libssh2_session_init_ex(3)

View File

@@ -11,20 +11,23 @@ int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
const char *privatekey,
const char *passphrase);
.SH DESCRIPTION
\fIsession\fP - Session instance as returned by
.BR libssh2_session_init_ex(3)
\fIsession\fP - Session instance as returned by
\fBlibssh2_session_init_ex(3)\fP
\fIusername\fP - Remote user name to authenticate as.
\fIusername\fP - Pointer to user name to authenticate as.
\fIusername_len\fP - Length of username.
\fIusername_len\fP - Length of \fIusername\fP.
\fIpublickey\fP - Path and name of public key file. (e.g. /etc/ssh/hostkey.pub)
\fIpublickey\fP - Path name of the public key file.
(e.g. /etc/ssh/hostkey.pub). If libssh2 is built against OpenSSL, this option
can be set to NULL.
\fIprivatekey\fP - Path and name of private key file. (e.g. /etc/ssh/hostkey)
\fIprivatekey\fP - Path name of the private key file. (e.g. /etc/ssh/hostkey)
\fIpassphrase\fP - Passphrase to use when decoding private key file.
\fIpassphrase\fP - Passphrase to use when decoding \fIprivatekey\fP.
Attempt public key authentication using a PEM encoded private key file stored on disk
Attempt public key authentication using a PEM encoded private key file stored
on disk
.SH RETURN VALUE
Return 0 on success or negative on failure. It returns

View File

@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
/* check what authentication methods are available */
userauthlist = libssh2_userauth_list(session, username, strlen(username));
printf("Authentication methods: %s\n", userauthlist);
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
if (strstr(userauthlist, "password"))
auth |= AUTH_PASSWORD;
if (strstr(userauthlist, "publickey"))
@@ -157,12 +157,12 @@ int main(int argc, char *argv[])
} else if (auth & AUTH_PUBLICKEY) {
if (libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) {
printf("\tAuthentication by public key failed!\n");
fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown;
}
printf("\tAuthentication by public key succeeded.\n");
fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} else {
printf("No supported authentication methods found!\n");
fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown;
}
@@ -185,7 +185,7 @@ int main(int argc, char *argv[])
goto shutdown;
}
printf("Waiting for TCP connection on %s:%d...\n",
fprintf(stderr, "Waiting for TCP connection on %s:%d...\n",
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
forwardsock = accept(listensock, (struct sockaddr *)&sin, &sinlen);
@@ -197,8 +197,8 @@ int main(int argc, char *argv[])
shost = inet_ntoa(sin.sin_addr);
sport = ntohs(sin.sin_port);
printf("Forwarding connection from %s:%d here to remote %s:%d\n", shost,
sport, remote_desthost, remote_destport);
fprintf(stderr, "Forwarding connection from %s:%d here to remote %s:%d\n",
shost, sport, remote_desthost, remote_destport);
channel = libssh2_channel_direct_tcpip_ex(session, remote_desthost,
remote_destport, shost, sport);
@@ -228,7 +228,8 @@ int main(int argc, char *argv[])
perror("read");
goto shutdown;
} else if (0 == len) {
printf("The client at %s:%d disconnected!\n", shost, sport);
fprintf(stderr, "The client at %s:%d disconnected!\n", shost,
sport);
goto shutdown;
}
wr = 0;
@@ -259,7 +260,7 @@ int main(int argc, char *argv[])
wr += i;
}
if (libssh2_channel_eof(channel)) {
printf("The server at %s:%d disconnected!\n",
fprintf(stderr, "The server at %s:%d disconnected!\n",
remote_desthost, remote_destport);
goto shutdown;
}

View File

@@ -250,7 +250,7 @@ int main(int argc, char *argv[])
gettimeofday(&end, NULL);
time_ms = tvdiff(end, start);
printf("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 );
libssh2_channel_free(channel);

View File

@@ -243,7 +243,7 @@ int main(int argc, char *argv[])
duration = (int)(time(NULL)-start);
printf("%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);
fprintf(stderr, "Sending EOF\n");

View File

@@ -55,24 +55,24 @@ static void kbd_callback(const char *name, int name_len,
char buf[1024];
(void)abstract;
printf("Performing keyboard-interactive authentication.\n");
fprintf(stderr, "Performing keyboard-interactive authentication.\n");
printf("Authentication name: '");
fwrite(name, 1, name_len, stdout);
printf("'\n");
fprintf(stderr, "Authentication name: '");
fwrite(name, 1, name_len, stderr);
fprintf(stderr, "'\n");
printf("Authentication instruction: '");
fwrite(instruction, 1, instruction_len, stdout);
printf("'\n");
fprintf(stderr, "Authentication instruction: '");
fwrite(instruction, 1, instruction_len, stderr);
fprintf(stderr, "'\n");
printf("Number of prompts: %d\n\n", num_prompts);
fprintf(stderr, "Number of prompts: %d\n\n", num_prompts);
for (i = 0; i < num_prompts; i++) {
printf("Prompt %d from server: '", i);
fwrite(prompts[i].text, 1, prompts[i].length, stdout);
printf("'\n");
fprintf(stderr, "Prompt %d from server: '", i);
fwrite(prompts[i].text, 1, prompts[i].length, stderr);
fprintf(stderr, "'\n");
printf("Please type response: ");
fprintf(stderr, "Please type response: ");
fgets(buf, sizeof(buf), stdin);
n = strlen(buf);
while (n > 0 && strchr("\r\n", buf[n - 1]))
@@ -82,12 +82,13 @@ static void kbd_callback(const char *name, int name_len,
responses[i].text = strdup(buf);
responses[i].length = n;
printf("Response %d from user is '", i);
fwrite(responses[i].text, 1, responses[i].length, stdout);
printf("'\n\n");
fprintf(stderr, "Response %d from user is '", i);
fwrite(responses[i].text, 1, responses[i].length, stderr);
fprintf(stderr, "'\n\n");
}
printf("Done. Sending keyboard-interactive responses to server now.\n");
fprintf(stderr,
"Done. Sending keyboard-interactive responses to server now.\n");
}
@@ -127,7 +128,7 @@ int main(int argc, char *argv[])
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
@@ -178,7 +179,7 @@ int main(int argc, char *argv[])
/* check what authentication methods are available */
userauthlist = libssh2_userauth_list(session, username, strlen(username));
printf("Authentication methods: %s\n", userauthlist);
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
if (strstr(userauthlist, "password") != NULL) {
auth_pw |= 1;
}
@@ -211,21 +212,23 @@ int main(int argc, char *argv[])
} else if (auth_pw & 2) {
/* Or via keyboard-interactive */
if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) ) {
printf("\tAuthentication by keyboard-interactive failed!\n");
fprintf(stderr,
"\tAuthentication by keyboard-interactive failed!\n");
goto shutdown;
} else {
printf("\tAuthentication by keyboard-interactive succeeded.\n");
fprintf(stderr,
"\tAuthentication by keyboard-interactive succeeded.\n");
}
} else if (auth_pw & 4) {
/* Or by public key */
if (libssh2_userauth_publickey_fromfile(session, username, keyfile1, keyfile2, password)) {
printf("\tAuthentication by public key failed!\n");
fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown;
} else {
printf("\tAuthentication by public key succeeded.\n");
fprintf(stderr, "\tAuthentication by public key succeeded.\n");
}
} else {
printf("No supported authentication methods found!\n");
fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown;
}

View File

@@ -141,11 +141,11 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if(argc > 1) {
username = argv[1];
@@ -162,7 +162,7 @@ int main(int argc, char *argv[])
tempstorage = fopen(STORAGE, "wb");
if(!tempstorage) {
printf("Can't open temp storage file %s\n", STORAGE);
fprintf(stderr, "Can't open temp storage file %s\n", STORAGE);
goto shutdown;
}
@@ -171,7 +171,7 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_password(session, username, password))
== LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -185,7 +185,7 @@ int main(int argc, char *argv[])
password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -341,7 +341,7 @@ int main(int argc, char *argv[])
#endif
if (tempstorage)
fclose(tempstorage);
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
local = fopen(loclfile, "rb");
if (!local) {
printf("Can't local file %s\n", loclfile);
fprintf(stderr, "Can't open local file %s\n", loclfile);
return -1;
}
@@ -129,16 +129,16 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -174,12 +174,12 @@ int main(int argc, char *argv[])
}
if(libssh2_sftp_fstat_ex(sftp_handle, &attrs, 0) < 0) {
printf("libssh2_sftp_fstat_ex failed\n");
fprintf(stderr, "libssh2_sftp_fstat_ex failed\n");
goto shutdown;
}
else
libssh2_sftp_seek64(sftp_handle, attrs.filesize);
printf("Did a seek to position %ld\n", (long) attrs.filesize);
fprintf(stderr, "Did a seek to position %ld\n", (long) attrs.filesize);
fprintf(stderr, "libssh2_sftp_open() a handle for APPEND\n");
@@ -222,7 +222,7 @@ shutdown:
#endif
if (local)
fclose(local);
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -110,16 +110,16 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -164,7 +164,7 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -110,16 +110,16 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -164,7 +164,7 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
gettimeofday(&end, NULL);
time_ms = tvdiff(end, start);
printf("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 );
libssh2_sftp_close(sftp_handle);
@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
shutdown:
printf("libssh2_session_disconnect\n");
fprintf(stderr, "libssh2_session_disconnect\n");
while (libssh2_session_disconnect(session,
"Normal Shutdown, Thank you") ==
LIBSSH2_ERROR_EAGAIN);

View File

@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
local = fopen(loclfile, "rb");
if (!local) {
printf("Can't local file %s\n", loclfile);
fprintf(stderr, "Can't open local file %s\n", loclfile);
return -1;
}
@@ -128,16 +128,16 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -146,7 +146,7 @@ int main(int argc, char *argv[])
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -206,7 +206,7 @@ shutdown:
#endif
if (local)
fclose(local);
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
local = fopen(loclfile, "rb");
if (!local) {
printf("Can't local file %s\n", loclfile);
fprintf(stderr, "Can't open local file %s\n", loclfile);
return -1;
}
@@ -169,18 +169,18 @@ int main(int argc, char *argv[])
* that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -253,7 +253,7 @@ int main(int argc, char *argv[])
duration = (int)(time(NULL)-start);
printf("%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);
@@ -272,7 +272,7 @@ shutdown:
#else
close(sock);
#endif
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
local = fopen(loclfile, "rb");
if (!local) {
printf("Can't local file %s\n", loclfile);
fprintf(stderr, "Can't open local file %s\n", loclfile);
return -1;
}
@@ -169,18 +169,18 @@ int main(int argc, char *argv[])
* that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -262,7 +262,7 @@ int main(int argc, char *argv[])
duration = (int)(time(NULL)-start);
printf("%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);
@@ -281,7 +281,7 @@ shutdown:
#else
close(sock);
#endif
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -130,16 +130,16 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("Authentication by password failed.\n");
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
}
} else {
@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) {
printf("\tAuthentication by public key failed\n");
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
}
}
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -134,11 +134,11 @@ int main(int argc, char *argv[])
* user, that's your call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
if (auth_pw) {
/* We could authenticate via password */
@@ -239,7 +239,7 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
fprintf(stderr, "all done\n");
libssh2_exit();

View File

@@ -126,15 +126,15 @@ int main(int argc, char *argv[])
* call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
/* check what authentication methods are available */
userauthlist = libssh2_userauth_list(session, username, strlen(username));
printf("Authentication methods: %s\n", userauthlist);
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
if (strstr(userauthlist, "password") != NULL) {
auth_pw |= 1;
}
@@ -161,31 +161,33 @@ int main(int argc, char *argv[])
if (auth_pw & 1) {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("\tAuthentication by password failed!\n");
fprintf(stderr, "\tAuthentication by password failed!\n");
goto shutdown;
} else {
printf("\tAuthentication by password succeeded.\n");
fprintf(stderr, "\tAuthentication by password succeeded.\n");
}
} else if (auth_pw & 2) {
/* Or via keyboard-interactive */
if (libssh2_userauth_keyboard_interactive(session, username,
&kbd_callback) ) {
printf("\tAuthentication by keyboard-interactive failed!\n");
fprintf(stderr,
"\tAuthentication by keyboard-interactive failed!\n");
goto shutdown;
} else {
printf("\tAuthentication by keyboard-interactive succeeded.\n");
fprintf(stderr,
"\tAuthentication by keyboard-interactive succeeded.\n");
}
} else if (auth_pw & 4) {
/* Or by public key */
if (libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) {
printf("\tAuthentication by public key failed!\n");
fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown;
} else {
printf("\tAuthentication by public key succeeded.\n");
fprintf(stderr, "\tAuthentication by public key succeeded.\n");
}
} else {
printf("No supported authentication methods found!\n");
fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown;
}
@@ -250,7 +252,7 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done!\n");
fprintf(stderr, "all done!\n");
libssh2_exit();

View File

@@ -105,15 +105,15 @@ int main(int argc, char *argv[])
* call
*/
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
printf("Fingerprint: ");
fprintf(stderr, "Fingerprint: ");
for(i = 0; i < 20; i++) {
printf("%02X ", (unsigned char)fingerprint[i]);
fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]);
}
printf("\n");
fprintf(stderr, "\n");
/* check what authentication methods are available */
userauthlist = libssh2_userauth_list(session, username, strlen(username));
printf("Authentication methods: %s\n", userauthlist);
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
if (strstr(userauthlist, "publickey") == NULL) {
fprintf(stderr, "\"publickey\" authentication is not supported\n");
goto shutdown;
@@ -147,11 +147,11 @@ int main(int argc, char *argv[])
goto shutdown;
}
if (libssh2_agent_userauth(agent, username, identity)) {
printf("\tAuthentication with username %s and "
fprintf(stderr, "\tAuthentication with username %s and "
"public key %s failed!\n",
username, identity->comment);
} else {
printf("\tAuthentication with username %s and "
fprintf(stderr, "\tAuthentication with username %s and "
"public key %s succeeded!\n",
username, identity->comment);
break;
@@ -234,7 +234,7 @@ int main(int argc, char *argv[])
#endif
}
printf("all done!\n");
fprintf(stderr, "all done!\n");
libssh2_exit();

View File

@@ -327,7 +327,7 @@ int main(int argc, char *argv[])
}
if (exitsignal)
printf("\nGot signal: %s\n", exitsignal);
fprintf(stderr, "\nGot signal: %s\n", exitsignal);
libssh2_channel_free(channel);
channel = NULL;

View File

@@ -292,9 +292,9 @@ int main(int argc, char *argv[])
}
if (exitsignal)
printf("\nGot signal: %s\n", exitsignal);
fprintf(stderr, "\nGot signal: %s\n", exitsignal);
else
printf("\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
libssh2_channel_free(channel);
channel = NULL;

View File

@@ -173,7 +173,7 @@ int main(int argc, char *argv[])
/* check what authentication methods are available */
userauthlist = libssh2_userauth_list(session, username, strlen(username));
printf("Authentication methods: %s\n", userauthlist);
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
if (strstr(userauthlist, "password"))
auth |= AUTH_PASSWORD;
if (strstr(userauthlist, "publickey"))
@@ -195,12 +195,12 @@ int main(int argc, char *argv[])
} else if (auth & AUTH_PUBLICKEY) {
if (libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) {
printf("Authentication by public key failed!\n");
fprintf(stderr, "Authentication by public key failed!\n");
goto shutdown;
}
printf("Authentication by public key succeeded.\n");
fprintf(stderr, "Authentication by public key succeeded.\n");
} else {
printf("No supported authentication methods found!\n");
fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown;
}
@@ -223,7 +223,7 @@ int main(int argc, char *argv[])
/* NETCONF: http://tools.ietf.org/html/draft-ietf-netconf-ssh-06 */
printf("Sending NETCONF client <hello>\n");
fprintf(stderr, "Sending NETCONF client <hello>\n");
snprintf(buf, sizeof(buf),
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<hello>"
@@ -235,14 +235,14 @@ int main(int argc, char *argv[])
if (-1 == netconf_write(channel, buf, len))
goto shutdown;
printf("Reading NETCONF server <hello>\n");
fprintf(stderr, "Reading NETCONF server <hello>\n");
len = netconf_read_until(channel, "</hello>", buf, sizeof(buf));
if (-1 == len)
goto shutdown;
printf("Got %d bytes:\n----------------------\n%s", (int)len, buf);
fprintf(stderr, "Got %d bytes:\n----------------------\n%s", (int)len, buf);
printf("Sending NETCONF <rpc>\n");
fprintf(stderr, "Sending NETCONF <rpc>\n");
snprintf(buf, sizeof(buf),
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
@@ -252,12 +252,12 @@ int main(int argc, char *argv[])
if (-1 == netconf_write(channel, buf, len))
goto shutdown;
printf("Reading NETCONF <rpc-reply>\n");
fprintf(stderr, "Reading NETCONF <rpc-reply>\n");
len = netconf_read_until(channel, "</rpc-reply>", buf, sizeof(buf));
if (-1 == len)
goto shutdown;
printf("Got %d bytes:\n----------------------\n%s", (int)len, buf);
fprintf(stderr, "Got %d bytes:\n----------------------\n%s", (int)len, buf);
shutdown:
if (channel)

View File

@@ -137,7 +137,7 @@ int main(int argc, char *argv[])
/* check what authentication methods are available */
userauthlist = libssh2_userauth_list(session, username, strlen(username));
printf("Authentication methods: %s\n", userauthlist);
fprintf(stderr, "Authentication methods: %s\n", userauthlist);
if (strstr(userauthlist, "password"))
auth |= AUTH_PASSWORD;
if (strstr(userauthlist, "publickey"))
@@ -159,17 +159,17 @@ int main(int argc, char *argv[])
} else if (auth & AUTH_PUBLICKEY) {
if (libssh2_userauth_publickey_fromfile(session, username, keyfile1,
keyfile2, password)) {
printf("\tAuthentication by public key failed!\n");
fprintf(stderr, "\tAuthentication by public key failed!\n");
goto shutdown;
}
printf("\tAuthentication by public key succeeded.\n");
fprintf(stderr, "\tAuthentication by public key succeeded.\n");
} else {
printf("No supported authentication methods found!\n");
fprintf(stderr, "No supported authentication methods found!\n");
goto shutdown;
}
printf("Asking server to listen on remote %s:%d\n", remote_listenhost,
remote_wantport);
fprintf(stderr, "Asking server to listen on remote %s:%d\n",
remote_listenhost, remote_wantport);
listener = libssh2_channel_forward_listen_ex(session, remote_listenhost,
remote_wantport, &remote_listenport, 1);
@@ -180,10 +180,10 @@ int main(int argc, char *argv[])
goto shutdown;
}
printf("Server is listening on %s:%d\n", remote_listenhost,
fprintf(stderr, "Server is listening on %s:%d\n", remote_listenhost,
remote_listenport);
printf("Waiting for remote connection\n");
fprintf(stderr, "Waiting for remote connection\n");
channel = libssh2_channel_forward_accept(listener);
if (!channel) {
fprintf(stderr, "Could not accept connection!\n"
@@ -192,7 +192,8 @@ int main(int argc, char *argv[])
goto shutdown;
}
printf("Accepted remote connection. Connecting to local server %s:%d\n",
fprintf(stderr,
"Accepted remote connection. Connecting to local server %s:%d\n",
local_destip, local_destport);
forwardsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
sin.sin_family = AF_INET;
@@ -206,7 +207,7 @@ int main(int argc, char *argv[])
goto shutdown;
}
printf("Forwarding connection from remote %s:%d to local %s:%d\n",
fprintf(stderr, "Forwarding connection from remote %s:%d to local %s:%d\n",
remote_listenhost, remote_listenport, local_destip, local_destport);
/* Must use non-blocking IO hereafter due to the current libssh2 API */
@@ -228,7 +229,7 @@ int main(int argc, char *argv[])
perror("read");
goto shutdown;
} else if (0 == len) {
printf("The local server at %s:%d disconnected!\n",
fprintf(stderr, "The local server at %s:%d disconnected!\n",
local_destip, local_destport);
goto shutdown;
}
@@ -260,7 +261,7 @@ int main(int argc, char *argv[])
wr += i;
}
if (libssh2_channel_eof(channel)) {
printf("The remote client at %s:%d disconnected!\n",
fprintf(stderr, "The remote client at %s:%d disconnected!\n",
remote_listenhost, remote_listenport);
goto shutdown;
}

View File

@@ -46,13 +46,13 @@
to make the BANNER define (used by src/session.c) be a valid SSH
banner. Release versions have no appended strings and may of course not
have dashes either. */
#define LIBSSH2_VERSION "1.4.2_DEV"
#define LIBSSH2_VERSION "1.4.3_DEV"
/* The numeric version number is also available "in parts" by using these
defines: */
#define LIBSSH2_VERSION_MAJOR 1
#define LIBSSH2_VERSION_MINOR 4
#define LIBSSH2_VERSION_PATCH 2
#define LIBSSH2_VERSION_PATCH 3
/* This is the numeric version of the libssh2 version number, meant for easier
parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
@@ -69,7 +69,7 @@
and it is always a greater number in a more recent release. It makes
comparisons with greater than and less than work.
*/
#define LIBSSH2_VERSION_NUM 0x010402
#define LIBSSH2_VERSION_NUM 0x010403
/*
* This is the date and time when the full source package was created. The
@@ -405,6 +405,7 @@ typedef struct _LIBSSH2_POLLFD {
#define LIBSSH2_ERROR_SOCKET_RECV -43
#define LIBSSH2_ERROR_ENCRYPT -44
#define LIBSSH2_ERROR_BAD_SOCKET -45
#define LIBSSH2_ERROR_KNOWN_HOSTS -46
/* this is a define to provide the old (<= 1.2.7) name */
#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV

View File

@@ -1,7 +1,7 @@
#########################################################################
#
## Makefile for building libssh2 (NetWare version - gnu make)
## Use: make -f Makefile.netware [help|all|clean|dev|devclean|dist|distclean|lib|nlm|objclean]
## Use: make [help|all|clean|dev|devclean|dist|distclean|lib|nlm|objclean]
##
## Hacked by: Guenter Knauf
#
@@ -14,12 +14,12 @@ endif
# Edit the path below to point to the base of your Zlib sources.
ifndef ZLIB_PATH
ZLIB_PATH = ../../zlib-1.2.6
ZLIB_PATH = ../../zlib-1.2.7
endif
# Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH
OPENSSL_PATH = ../../openssl-0.9.8v
OPENSSL_PATH = ../../openssl-0.9.8x
endif
# Edit the path below to point to your Distribution folder.
@@ -76,10 +76,7 @@ ifdef METROWERKS
else
CC = $(CROSSPREFIX)gcc
endif
CP = cp -afv
MD = mkdir
RD = rm -fr
# RM = rm -f
# Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk-20100523.zip
AWK = awk
@@ -89,6 +86,34 @@ AWK = awk
MPKXDC = mkxdc
ZIP = zip -qzr9
# Platform-dependent helper tool macros
ifeq ($(findstring /sh,$(SHELL)),/sh)
DEL = rm -f $1
RMDIR = rm -fr $1
MKDIR = mkdir -p $1
COPY = -cp -afv $1 $2
#COPYR = -cp -afr $1/* $2
COPYR = -rsync -aC $1/* $2
TOUCH = touch $1
CAT = cat
ECHONL = echo ""
DL = '
else
ifeq "$(OS)" "Windows_NT"
DEL = -del 2>NUL /q /f $(subst /,\,$1)
RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
else
DEL = -del 2>NUL $(subst /,\,$1)
RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
endif
MKDIR = -md 2>NUL $(subst /,\,$1)
COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
CAT = type
ECHONL = $(ComSpec) /c echo.
endif
# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH))
LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH))
@@ -120,13 +145,14 @@ else
endif
else
LD = $(CROSSPREFIX)nlmconv
LDFLAGS = -T
LDFLAGS = -UT
AR = $(CROSSPREFIX)ar
ARFLAGS = -cq
LIBEXT = a
RANLIB = $(CROSSPREFIX)ranlib
CFLAGS += -m32
CFLAGS += -fno-builtin -fpcc-struct-return -fno-strict-aliasing
CFLAGS += -m32
CFLAGS += -fno-builtin -fpcc-struct-return
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall # -pedantic
#CFLAGS += -Wno-pointer-sign
ifeq ($(LIBARCH),LIBC)
@@ -185,13 +211,6 @@ ifdef XDCOPT
XDCDATA = $(OBJDIR)/$(TARGET).xdc
endif
ifeq ($(findstring /sh,$(SHELL)),/sh)
DL = '
DS = /
else
DS = \\
endif
vpath %.c . ../src
# include Makefile.inc to get CSOURCES define
@@ -217,73 +236,74 @@ lib: prebuild $(TARGET).$(LIBEXT)
prebuild: $(OBJDIR) $(OBJDIR)/version.inc libssh2_config.h
test: all
$(MAKE) -C test -f Makefile.netware
$(MAKE) -C test
$(OBJDIR)/%.o: %.c
# @echo Compiling $<
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/version.inc: ../include/libssh2.h $(OBJDIR)
$(OBJDIR)/version.inc: ../get_ver.awk ../include/libssh2.h $(OBJDIR)
@echo Creating $@
@$(AWK) -f ../get_ver.awk $< > $@
@$(AWK) -f $^ > $@
dist: all $(DISTDIR) $(DISTDIR)/readme.txt
@-$(MD) $(DISTDIR)$(DS)bin
@-$(CP) ../AUTHORS $(DISTDIR)
@-$(CP) ../COPYING $(DISTDIR)
@-$(CP) ../INSTALL $(DISTDIR)
@-$(CP) ../README $(DISTDIR)
@-$(CP) ../RELEASE-NOTES $(DEVLDIR)
@$(CP) $(TARGET).nlm $(DISTDIR)/bin
@$(call MD, $(DISTDIR)/bin)
@$(call CP, ../AUTHORS, $(DISTDIR))
@$(call CP, ../COPYING, $(DISTDIR))
@$(call CP, ../INSTALL, $(DISTDIR))
@$(call CP, ../README, $(DISTDIR))
@$(call CP, ../RELEASE-NOTES, $(DISTDIR))
@$(call CP, $(TARGET).nlm, $(DISTDIR)/bin)
@echo Creating $(DISTARC)
@$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt
dev: all $(DEVLDIR) $(DEVLDIR)/readme.txt
@-$(MD) $(DEVLDIR)$(DS)bin
@-$(MD) $(DEVLDIR)$(DS)include
@-$(MD) $(DEVLDIR)$(DS)nw
@-$(CP) ../AUTHORS $(DISTDIR)
@-$(CP) ../COPYING $(DISTDIR)
@-$(CP) ../INSTALL $(DEVLDIR)
@-$(CP) ../README $(DEVLDIR)
@-$(CP) ../RELEASE-NOTES $(DEVLDIR)
@$(CP) $(TARGET).nlm $(DEVLDIR)/bin
@$(CP) ../include/*.h $(DEVLDIR)/include
@$(CP) libssh2_config.h $(DEVLDIR)/include
@$(CP) $(TARGET).$(LIBEXT) $(DEVLDIR)/nw
@$(call MD, $(DEVLDIR)/bin)
@$(call MD, $(DEVLDIR)/include)
@$(call MD, $(DEVLDIR)/nw)
@$(call CP, ../AUTHORS, $(DEVLDIR))
@$(call CP, ../COPYING, $(DEVLDIR))
@$(call CP, ../INSTALL, $(DEVLDIR))
@$(call CP, ../README, $(DEVLDIR))
@$(call CP, ../RELEASE-NOTES, $(DEVLDIR))
@$(call CP, ../include/*.h, $(DEVLDIR)/include)
@$(call CP, libssh2_config.h, $(DEVLDIR)/include)
@$(call CP, $(TARGET).nlm, $(DEVLDIR)/bin)
@$(call CP, $(TARGET).imp, $(DEVLDIR)/nw)
@$(call CP, $(TARGET).$(LIBEXT), $(DEVLDIR)/nw)
@echo Creating $(DEVLARC)
@$(ZIP) $(DEVLARC) $(DEVLDIR)/* < $(DEVLDIR)/readme.txt
distclean: clean
-$(RD) $(DISTDIR)
-$(RM) $(DISTARC)
$(call RMDIR, $(DISTDIR))
$(call DEL, $(DISTARC))
devclean: clean
-$(RD) $(DEVLDIR)
-$(RM) $(DEVLARC)
$(call RMDIR, $(DEVLDIR))
$(call DEL, $(DEVLARC))
objclean:
-$(RD) $(OBJDIR)
$(call RMDIR, $(OBJDIR))
testclean: clean
$(MAKE) -C test -f Makefile.netware clean
$(MAKE) -C test clean
clean: objclean
-$(RM) libssh2_config.h
-$(RM) $(TARGET).nlm $(TARGET).$(LIBEXT) $(TARGET).imp
$(call DEL, libssh2_config.h)
$(call DEL, $(TARGET).*)
$(OBJDIR):
@$(MD) $@
@$(call MKDIR, $@)
$(DISTDIR):
@$(MD) $@
@$(call MKDIR, $@)
$(DEVLDIR):
@$(MD) $@
@$(call MKDIR, $@)
$(TARGET).$(LIBEXT): $(OBJS)
@echo Creating $@
@-$(RM) $@
@$(call DEL, $@)
@$(AR) $(ARFLAGS) $@ $^
ifdef RANLIB
@$(RANLIB) $@
@@ -291,14 +311,14 @@ endif
$(TARGET).nlm: $(OBJDIR)/$(TARGET).def $(TARGET).imp $(OBJL) $(XDCDATA)
@echo Linking $@
@-$(RM) $@
@$(call DEL, $@)
@$(LD) $(LDFLAGS) $<
$(OBJDIR)/%.xdc: Makefile.netware
$(OBJDIR)/%.xdc: GNUmakefile
@echo Creating $@
@$(MPKXDC) $(XDCOPT) $@
$(OBJDIR)/%.def: Makefile.netware
$(OBJDIR)/%.def: GNUmakefile
@echo $(DL)# DEF file for linking with $(LD)$(DL) > $@
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
@echo $(DL)# All your changes will be lost!!$(DL) >> $@
@@ -357,7 +377,7 @@ ifeq ($(LD),nlmconv)
@echo $(DL)output $(TARGET).nlm$(DL) >> $@
endif
libssh2_config.h: Makefile.netware
libssh2_config.h: GNUmakefile
@echo Creating $@
@echo $(DL)/* $@ for NetWare target.$(DL) > $@
@echo $(DL)** Do not edit this file - it is created by make!$(DL) >> $@
@@ -483,7 +503,7 @@ ifeq ($(DB),DEBUG)
@echo $(DL)#define LIBSSH2_DEBUG_USERAUTH 1$(DL) >> $@
endif
libssh2.imp: Makefile.netware
libssh2.imp: GNUmakefile
@echo Creating $@
@echo $(DL)# $@ for NetWare target.$(DL) > $@
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
@@ -558,7 +578,7 @@ endif
@echo $(DL) libssh2_userauth_password_ex,$(DL) >> $@
@echo $(DL) libssh2_userauth_publickey_fromfile_ex$(DL) >> $@
$(DISTDIR)/readme.txt: Makefile.netware
$(DISTDIR)/readme.txt: GNUmakefile
@echo Creating $@
@echo $(DL)This is a binary distribution for NetWare platform.$(DL) > $@
@echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@
@@ -566,7 +586,7 @@ $(DISTDIR)/readme.txt: Makefile.netware
@echo $(DL)any further documentation:$(DL) >> $@
@echo $(DL)$(WWWURL)$(DL) >> $@
$(DEVLDIR)/readme.txt: Makefile.netware
$(DEVLDIR)/readme.txt: GNUmakefile
@echo Creating $@
@echo $(DL)This is a development distribution for NetWare platform.$(DL) > $@
@echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@

View File

@@ -1,2 +0,0 @@
include Makefile.netware

View File

@@ -1,7 +1,6 @@
#########################################################################
#
## Makefile for building libssh2 (NetWare version - gnu make)
## Use: make -f Makefile.netware
##
## Hacked by: Guenter Knauf
#
@@ -14,12 +13,12 @@ endif
# Edit the path below to point to the base of your Zlib sources.
ifndef ZLIB_PATH
ZLIB_PATH = ../../../zlib-1.2.6
ZLIB_PATH = ../../../zlib-1.2.7
endif
# Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH
OPENSSL_PATH = ../../../openssl-0.9.8v
OPENSSL_PATH = ../../../openssl-0.9.8x
endif
# Edit the var below to enable static linking of libssh2 and libz
@@ -70,10 +69,7 @@ ifdef METROWERKS
else
CC = $(CROSSPREFIX)gcc
endif
CP = cp -afv
MD = mkdir
RD = rm -fr
# RM = rm -f
# Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk-20100523.zip
AWK = awk
@@ -82,6 +78,34 @@ AWK = awk
# http://www.gknw.net/development/prgtools/mkxdc.zip
MPKXDC = mkxdc
# Platform-dependent helper tool macros
ifeq ($(findstring /sh,$(SHELL)),/sh)
DEL = rm -f $1
RMDIR = rm -fr $1
MKDIR = mkdir -p $1
COPY = -cp -afv $1 $2
#COPYR = -cp -afr $1/* $2
COPYR = -rsync -aC $1/* $2
TOUCH = touch $1
CAT = cat
ECHONL = echo ""
DL = '
else
ifeq "$(OS)" "Windows_NT"
DEL = -del 2>NUL /q /f $(subst /,\,$1)
RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
else
DEL = -del 2>NUL $(subst /,\,$1)
RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
endif
MKDIR = -md 2>NUL $(subst /,\,$1)
COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
CAT = type
ECHONL = $(ComSpec) /c echo.
endif
# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH))
LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH))
@@ -112,12 +136,13 @@ else
endif
else
LD = nlmconv
LDFLAGS = -T
LDFLAGS = -UT
AR = ar
ARFLAGS = -cq
LIBEXT = a
CFLAGS += -m32
CFLAGS += -fno-builtin -fpcc-struct-return -fno-strict-aliasing
CFLAGS += -fno-builtin -fpcc-struct-return
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall # -pedantic
ifeq ($(LIBARCH),LIBC)
PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o
@@ -181,13 +206,6 @@ ifeq ($(MTSAFE),NO)
XDCOPT = -u
endif
ifeq ($(findstring /sh,$(SHELL)),/sh)
DL = '
DS = /
else
DS = \\
endif
vpath %.c $(SAMPLES)
.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.def $(OBJDIR)/%.xdc
@@ -201,29 +219,29 @@ $(OBJDIR)/%.o: %.c
# @echo Compiling $<
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/version.inc: ../../include/libssh2.h $(OBJDIR)
$(OBJDIR)/version.inc: ../../get_ver.awk ../../include/libssh2.h $(OBJDIR)
@echo Creating $@
@$(AWK) -f ../../get_ver.awk $< > $@
@$(AWK) -f $^ > $@
objclean:
-$(RD) $(OBJDIR)
$(call RMDIR, $(OBJDIR))
clean: objclean
-$(RM) $(TARGETS)
$(foreach f, $(TARGETS), $(call DEL, $(f)))
$(OBJDIR):
@$(MD) $@
@$(call MKDIR, $@)
%.nlm: $(OBJDIR)/%.def $(OBJDIR)/%.o $(OBJDIR)/%.xdc
@echo Linking $@
@-$(RM) $@
@$(call DEL, $@)
@$(LD) $(LDFLAGS) $<
$(OBJDIR)/%.xdc: Makefile.netware
$(OBJDIR)/%.xdc: GNUmakefile
@echo Creating $@
@$(MPKXDC) $(XDCOPT) $@
$(OBJDIR)/%.def: Makefile.netware
$(OBJDIR)/%.def: GNUmakefile
@echo $(DL)# DEF file for linking with $(LD)$(DL) > $@
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
@echo $(DL)# All your changes will be lost!!$(DL) >> $@

View File

@@ -1,33 +1,20 @@
!include "win32/config.mk"
!include "win32/objects.mk"
CFLAGS=$(CFLAGS)
OBJECTS = \
$(INTDIR)\channel.obj \
$(INTDIR)\comp.obj \
$(INTDIR)\crypt.obj \
$(INTDIR)\global.obj \
$(INTDIR)\hostkey.obj \
$(INTDIR)\keepalive.obj \
$(INTDIR)\kex.obj \
$(INTDIR)\mac.obj \
$(INTDIR)\misc.obj \
$(INTDIR)\openssl.obj \
$(INTDIR)\packet.obj \
$(INTDIR)\pem.obj \
$(INTDIR)\publickey.obj \
$(INTDIR)\scp.obj \
$(INTDIR)\session.obj \
$(INTDIR)\sftp.obj \
$(INTDIR)\transport.obj \
$(INTDIR)\userauth.obj
RESOURCE=$(INTDIR)\libssh2.res
DLL=libssh2$(SUFFIX).dll
$(DLL): $(OBJECTS)
$(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(LIBS)
all: $(DLL)
$(DLL): $(OBJECTS) $(RESOURCE)
$(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(RESOURCE) $(LIBS)
$(RESOURCE): win32\libssh2.rc
$(RC) $(RCFLAGS) /Fo"$@" $?
!include "win32/rules.mk"

View File

@@ -1483,10 +1483,11 @@ libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel,
char **langtag,
size_t *langtag_len)
{
LIBSSH2_SESSION *session = channel->session;
size_t namelen = 0;
if (channel) {
LIBSSH2_SESSION *session = channel->session;
if (channel->exit_signal) {
namelen = strlen(channel->exit_signal);
if (exitsignal) {

View File

@@ -96,6 +96,7 @@ comp_method_none_decomp(LIBSSH2_SESSION * session,
static const LIBSSH2_COMP_METHOD comp_method_none = {
"none",
0, /* not really compressing */
0, /* isn't used in userauth, go figure */
NULL,
comp_method_none_comp,
comp_method_none_decomp,
@@ -248,83 +249,56 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
if (!strm->next_out)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate decompression buffer");
while (strm->avail_in) {
int status;
/* Loop until it's all inflated or hit error */
for (;;) {
int status, grow_size;
size_t out_ofs;
char *newout;
status = inflate(strm, Z_PARTIAL_FLUSH);
if (status != Z_OK) {
if (status == Z_OK) {
if (! strm->avail_in) {
/* status is OK and input all used so we're done */
break;
}
} else if (status == Z_BUF_ERROR) {
/* This is OK, just drop through to grow the buffer */
} else {
/* error state */
LIBSSH2_FREE(session, out);
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"unhandled zlib error %d", status);
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"decompression failure");
}
/* If we get here we need to grow the output buffer and try again */
out_ofs = out_maxlen - strm->avail_out;
if (strm->avail_in) {
size_t out_ofs = out_maxlen - strm->avail_out;
char *newout;
grow_size = strm->avail_in * 8;
} else {
/* Not sure how much to grow by */
grow_size = 32;
}
out_maxlen += grow_size;
out_maxlen += 8 * strm->avail_in;
if ((out_maxlen > (int) payload_limit) && limiter++) {
LIBSSH2_FREE(session, out);
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression phase");
}
if ((out_maxlen > (int) payload_limit) && limiter++) {
LIBSSH2_FREE(session, out);
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression phase");
}
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) {
LIBSSH2_FREE(session, out);
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand decompression buffer");
}
out = newout;
strm->next_out = (unsigned char *) out + out_ofs;
strm->avail_out += 8 * strm->avail_in;
} else
while (!strm->avail_out) {
/* Done with input, might be a byte or two in internal buffer
* during compress. Or potentially many bytes if it's a
* decompress
*/
int grow_size = 2048;
char *newout;
if (out_maxlen >= (int) payload_limit) {
LIBSSH2_FREE(session, out);
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression "
"phase");
}
if (grow_size > (int) (payload_limit - out_maxlen)) {
grow_size = payload_limit - out_maxlen;
}
out_maxlen += grow_size;
strm->avail_out = grow_size;
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) {
LIBSSH2_FREE(session, out);
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand final "
"decompress buffer");
}
out = newout;
strm->next_out = (unsigned char *) out + out_maxlen -
grow_size;
status = inflate(strm, Z_PARTIAL_FLUSH);
if (status != Z_OK) {
LIBSSH2_FREE(session, out);
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"unhandled zlib error %d", status);
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"decompression failure");
}
}
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) {
LIBSSH2_FREE(session, out);
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand decompression buffer");
}
out = newout;
strm->next_out = (unsigned char *) out + out_ofs;
strm->avail_out += grow_size;
}
*dest = (unsigned char *) out;
@@ -357,6 +331,17 @@ comp_method_zlib_dtor(LIBSSH2_SESSION *session, int compr, void **abstract)
static const LIBSSH2_COMP_METHOD comp_method_zlib = {
"zlib",
1, /* yes, this compresses */
1, /* do compression during userauth */
comp_method_zlib_init,
comp_method_zlib_comp,
comp_method_zlib_decomp,
comp_method_zlib_dtor,
};
static const LIBSSH2_COMP_METHOD comp_method_zlib_openssh = {
"zlib@openssh.com",
1, /* yes, this compresses */
0, /* don't use compression during userauth */
comp_method_zlib_init,
comp_method_zlib_comp,
comp_method_zlib_decomp,
@@ -369,6 +354,7 @@ static const LIBSSH2_COMP_METHOD comp_method_zlib = {
static const LIBSSH2_COMP_METHOD *comp_methods[] = {
#ifdef LIBSSH2_HAVE_ZLIB
&comp_method_zlib,
&comp_method_zlib_openssh,
#endif /* LIBSSH2_HAVE_ZLIB */
&comp_method_none,
NULL

View File

@@ -96,11 +96,12 @@ crypt_init(LIBSSH2_SESSION * session,
static int
crypt_encrypt(LIBSSH2_SESSION * session, unsigned char *block,
void **abstract)
size_t blocksize, void **abstract)
{
struct crypt_ctx *cctx = *(struct crypt_ctx **) abstract;
(void) session;
return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block);
return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block,
blocksize);
}
static int
@@ -248,7 +249,8 @@ crypt_init_arcfour128(LIBSSH2_SESSION * session,
unsigned char block[8];
size_t discard = 1536;
for (; discard; discard -= 8)
_libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block);
_libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block,
method->blocksize);
}
return rc;

View File

@@ -75,6 +75,7 @@ int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
unsigned char **signature,
size_t *signature_len);
#if LIBSSH2_DSA
int _libssh2_dsa_new(libssh2_dsa_ctx ** dsa,
const unsigned char *pdata,
unsigned long plen,
@@ -95,6 +96,7 @@ int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
const unsigned char *hash,
unsigned long hash_len, unsigned char *sig);
#endif
int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
_libssh2_cipher_type(algo),
@@ -103,7 +105,7 @@ int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo),
int encrypt, unsigned char *block);
int encrypt, unsigned char *block, size_t blocksize);
int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
unsigned char **method,

View File

@@ -429,7 +429,9 @@ libssh2_hostkey_hash(LIBSSH2_SESSION * session, int hash_type)
switch (hash_type) {
#if LIBSSH2_MD5
case LIBSSH2_HOSTKEY_HASH_MD5:
return (char *) session->server_hostkey_md5;
return (session->server_hostkey_md5_valid)
? (char *) session->server_hostkey_md5
: NULL;
break;
#endif /* LIBSSH2_MD5 */
case LIBSSH2_HOSTKEY_HASH_SHA1:

View File

@@ -218,10 +218,15 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
{
libssh2_md5_ctx fingerprint_ctx;
libssh2_md5_init(&fingerprint_ctx);
libssh2_md5_update(fingerprint_ctx, session->server_hostkey,
session->server_hostkey_len);
libssh2_md5_final(fingerprint_ctx, session->server_hostkey_md5);
if (libssh2_md5_init(&fingerprint_ctx)) {
libssh2_md5_update(fingerprint_ctx, session->server_hostkey,
session->server_hostkey_len);
libssh2_md5_final(fingerprint_ctx, session->server_hostkey_md5);
session->server_hostkey_md5_valid = TRUE;
}
else {
session->server_hostkey_md5_valid = FALSE;
}
}
#ifdef LIBSSH2DEBUG
{

View File

@@ -910,8 +910,11 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
file = fopen(filename, "r");
if(file) {
while(fgets(buf, sizeof(buf), file)) {
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type))
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) {
num = _libssh2_error(hosts->session, LIBSSH2_ERROR_KNOWN_HOSTS,
"Failed to parse known hosts file");
break;
}
num++;
}
fclose(file);

View File

@@ -553,17 +553,11 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h,
int
_libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo),
int encrypt, unsigned char *block)
int encrypt, unsigned char *block, size_t blklen)
{
int cipher = _libssh2_gcry_cipher (algo);
size_t blklen = gcry_cipher_get_algo_blklen(cipher);
int ret;
if (blklen == 1) {
/* Hack for arcfour. */
blklen = 8;
}
if (encrypt) {
ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen);
} else {

View File

@@ -68,7 +68,11 @@
gcry_md_hash_buffer (GCRY_MD_SHA1, out, message, len)
#define libssh2_md5_ctx gcry_md_hd_t
#define libssh2_md5_init(ctx) gcry_md_open (ctx, GCRY_MD_MD5, 0);
/* returns 0 in case of failure */
#define libssh2_md5_init(ctx) \
(GPG_ERR_NO_ERROR == gcry_md_open (ctx, GCRY_MD_MD5, 0))
#define libssh2_md5_update(ctx, data, len) gcry_md_write (ctx, data, len)
#define libssh2_md5_final(ctx, out) \
memcpy (out, gcry_md_read (ctx, 0), MD5_DIGEST_LENGTH), gcry_md_close (ctx)

View File

@@ -597,6 +597,7 @@ struct _LIBSSH2_SESSION
uint32_t server_hostkey_len;
#if LIBSSH2_MD5
unsigned char server_hostkey_md5[MD5_DIGEST_LENGTH];
int server_hostkey_md5_valid;
#endif /* ! LIBSSH2_MD5 */
unsigned char server_hostkey_sha1[SHA_DIGEST_LENGTH];
@@ -882,7 +883,7 @@ struct _LIBSSH2_CRYPT_METHOD
int *free_iv, unsigned char *secret, int *free_secret,
int encrypt, void **abstract);
int (*crypt) (LIBSSH2_SESSION * session, unsigned char *block,
void **abstract);
size_t blocksize, void **abstract);
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
_libssh2_cipher_type(algo);
@@ -892,6 +893,7 @@ struct _LIBSSH2_COMP_METHOD
{
const char *name;
int compress; /* 1 if it does compress, 0 if it doesn't */
int use_in_auth; /* 1 if compression should be used in userauth */
int (*init) (LIBSSH2_SESSION *session, int compress, void **abstract);
int (*comp) (LIBSSH2_SESSION *session,
unsigned char *dest,
@@ -1030,9 +1032,9 @@ void _libssh2_init_if_needed (void);
/* define to output the libssh2_int64_t type in a *printf() */
#if defined( __BORLANDC__ ) || defined( _MSC_VER ) || defined( __MINGW32__ )
#define LIBSSH2_INT64_T_FORMAT "I64"
#define LIBSSH2_INT64_T_FORMAT "I64d"
#else
#define LIBSSH2_INT64_T_FORMAT "ll"
#define LIBSSH2_INT64_T_FORMAT "lld"
#endif
#endif /* LIBSSH2_H */

View File

@@ -175,25 +175,19 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h,
unsigned char *iv, unsigned char *secret, int encrypt)
{
EVP_CIPHER_CTX_init(h);
EVP_CipherInit(h, algo(), secret, iv, encrypt);
return 0;
return !EVP_CipherInit(h, algo(), secret, iv, encrypt);
}
int
_libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo),
int encrypt, unsigned char *block)
int encrypt, unsigned char *block, size_t blocksize)
{
int blocksize = ctx->cipher->block_size;
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
int ret;
(void) algo;
(void) encrypt;
if (blocksize == 1) {
/* Hack for arcfour. */
blocksize = 8;
}
ret = EVP_Cipher(ctx, buf, block, blocksize);
if (ret == 1) {
memcpy(block, buf, blocksize);
@@ -221,13 +215,10 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
* variable "c" is leaked from this scope, but is later freed
* in aes_ctr_cleanup
*/
aes_ctr_ctx *c = malloc(sizeof(*c));
aes_ctr_ctx *c;
const EVP_CIPHER *aes_cipher;
(void) enc;
if (c == NULL)
return 0;
switch (ctx->key_len) {
case 16:
aes_cipher = EVP_aes_128_ecb();
@@ -241,11 +232,20 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
default:
return 0;
}
c->aes_ctx = malloc(sizeof(EVP_CIPHER_CTX));
if (c->aes_ctx == NULL)
c = malloc(sizeof(*c));
if (c == NULL)
return 0;
c->aes_ctx = malloc(sizeof(EVP_CIPHER_CTX));
if (c->aes_ctx == NULL) {
free(c);
return 0;
}
if (EVP_EncryptInit(c->aes_ctx, aes_cipher, key, NULL) != 1) {
free(c->aes_ctx);
free(c);
return 0;
}

View File

@@ -113,7 +113,10 @@
void libssh2_sha1(const unsigned char *message, unsigned long len, unsigned char *out);
#define libssh2_md5_ctx EVP_MD_CTX
/* returns 0 in case of failure */
#define libssh2_md5_init(ctx) EVP_DigestInit(ctx, EVP_get_digestbyname("md5"))
#define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_md5_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
void libssh2_md5(const unsigned char *message, unsigned long len, unsigned char *out);
@@ -148,9 +151,15 @@ void libssh2_md5(const unsigned char *message, unsigned long len, unsigned char
#define _libssh2_cipher_aes256 EVP_aes_256_cbc
#define _libssh2_cipher_aes192 EVP_aes_192_cbc
#define _libssh2_cipher_aes128 EVP_aes_128_cbc
#ifdef HAVE_EVP_AES_128_CTR
#define _libssh2_cipher_aes128ctr EVP_aes_128_ctr
#define _libssh2_cipher_aes192ctr EVP_aes_192_ctr
#define _libssh2_cipher_aes256ctr EVP_aes_256_ctr
#else
#define _libssh2_cipher_aes128ctr _libssh2_EVP_aes_128_ctr
#define _libssh2_cipher_aes192ctr _libssh2_EVP_aes_192_ctr
#define _libssh2_cipher_aes256ctr _libssh2_EVP_aes_256_ctr
#endif
#define _libssh2_cipher_blowfish EVP_bf_cbc
#define _libssh2_cipher_arcfour EVP_rc4
#define _libssh2_cipher_cast5 EVP_cast5_cbc

View File

@@ -1,5 +1,5 @@
/* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2010 by Daniel Stenberg
* Copyright (c) 2010-2012 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@@ -384,7 +384,7 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending publickey version packet");
return NULL;
} else if (rc) {
} else if (rc < 0) {
_libssh2_error(session, rc,
"Unable to send publickey version packet");
goto err_exit;

View File

@@ -957,7 +957,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_response_len =
snprintf((char *) session->scpSend_response,
LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %"
LIBSSH2_INT64_T_FORMAT "u %s\n", mode,
LIBSSH2_INT64_T_FORMAT " %s\n", mode,
size, base);
_libssh2_debug(session, LIBSSH2_TRACE_SCP, "Sent %s",
session->scpSend_response);

View File

@@ -834,7 +834,7 @@ session_free(LIBSSH2_SESSION *session)
_libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Freeing session resource",
session->remote.banner);
session->state = libssh2_NB_state_created;
session->free_state = libssh2_NB_state_created;
}
if (session->free_state == libssh2_NB_state_created) {
@@ -845,17 +845,17 @@ session_free(LIBSSH2_SESSION *session)
return rc;
}
session->state = libssh2_NB_state_sent;
session->free_state = libssh2_NB_state_sent;
}
if (session->state == libssh2_NB_state_sent) {
if (session->free_state == libssh2_NB_state_sent) {
while ((l = _libssh2_list_first(&session->listeners))) {
rc = _libssh2_channel_forward_cancel(l);
if (rc == LIBSSH2_ERROR_EAGAIN)
return rc;
}
session->state = libssh2_NB_state_sent1;
session->free_state = libssh2_NB_state_sent1;
}
if (session->state & LIBSSH2_STATE_NEWKEYS) {

View File

@@ -1459,9 +1459,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
switch (data[0]) {
case SSH_FXP_STATUS:
/* remove the chunk we just processed keeping track of the
* next one in case we need it */
next = _libssh2_list_next(&chunk->node);
/* remove the chunk we just processed */
_libssh2_list_remove(&chunk->node);
LIBSSH2_FREE(session, chunk);
@@ -1489,6 +1488,14 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol badness");
if(rc32 > chunk->len) {
/* A chunk larger than we requested was returned to us.
This is a protocol violation and we don't know how to
deal with it. Bail out! */
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"FXP_READ response too big");
}
if(rc32 != chunk->len) {
/* a short read does not imply end of file, but we must
adjust the offset_sent since it was advanced with a

View File

@@ -139,7 +139,7 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source,
assert((len % blocksize) == 0);
while (len >= blocksize) {
if (session->remote.crypt->crypt(session, source,
if (session->remote.crypt->crypt(session, source, blocksize,
&session->remote.crypt_abstract)) {
LIBSSH2_FREE(session, p->payload);
return LIBSSH2_ERROR_DECRYPT;
@@ -167,6 +167,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
unsigned char macbuf[MAX_MACSIZE];
struct transportpacket *p = &session->packet;
int rc;
int compressed;
if (session->fullpacket_state == libssh2_NB_state_idle) {
session->fullpacket_macstate = LIBSSH2_MAC_CONFIRMED;
@@ -199,9 +200,13 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
session->fullpacket_payload_len -= p->padding_length;
/* Check for and deal with decompression */
if (session->remote.comp &&
session->remote.comp->compress &&
session->remote.comp_abstract) {
compressed =
session->local.comp != NULL &&
session->local.comp->compress &&
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
session->local.comp->use_in_auth);
if (compressed && session->remote.comp_abstract) {
/*
* The buffer for the decompression (remote.comp_abstract) is
* initialised in time when it is needed so as long it is NULL we
@@ -682,6 +687,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
#endif
struct transportpacket *p = &session->packet;
int encrypted;
int compressed;
ssize_t ret;
int rc;
const unsigned char *orgdata = data;
@@ -723,7 +729,13 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
if (encrypted && session->local.comp->compress) {
compressed =
session->local.comp != NULL &&
session->local.comp->compress &&
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
session->local.comp->use_in_auth);
if (encrypted && compressed) {
/* the idea here is that these function must fail if the output gets
larger than what fits in the assigned buffer so thus they don't
check the input size as we don't know how much it compresses */
@@ -834,6 +846,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
for(i = 0; i < packet_length; i += session->local.crypt->blocksize) {
unsigned char *ptr = &p->outbuf[i];
if (session->local.crypt->crypt(session, ptr,
session->local.crypt->blocksize,
&session->local.crypt_abstract))
return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */
}

1
win32/.gitignore vendored
View File

@@ -11,3 +11,4 @@ Release
*.opt
*.plg
libssh2.dsp
objects.mk

View File

@@ -9,14 +9,12 @@
# Edit the path below to point to the base of your Zlib sources.
ifndef ZLIB_PATH
ZLIB_PATH = ../../zlib-1.2.6
ZLIB_PATH = ../../zlib-1.2.7
endif
# since currently always enabled in libssh2_config.h set here too!
WITH_ZLIB = 1
# Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH
OPENSSL_PATH = ../../openssl-1.0.1a
OPENSSL_PATH = ../../openssl-0.9.8x
endif
# Edit the var below to set to your architecture or set environment var.
@@ -38,8 +36,6 @@ DEVLARC = $(DEVLDIR).zip
# Edit the vars below to change target settings.
TARGET = libssh2
VERSION = $(LIBSSH2_VERSION)
COPYR = (c) $(LIBSSH2_COPYRIGHT_STR)
WWWURL = http://www.libssh2.org/
DESCR = libssh2 $(LIBSSH2_VERSION_STR)
#STACK = 64000
@@ -59,29 +55,39 @@ else
OBJDIR = debug
endif
# Include the version info retrieved from libssh2.h
-include $(OBJDIR)/version.inc
ifeq ($(findstring /sh,$(SHELL)),/sh)
CP = cp -afv
# RM = rm -f
MD = mkdir
RD = rm -fr
DL = '
DS = /
else
CP = copy
RM = del /q /f 2>NUL
MD = md 2>NUL
RD = rd /q /s 2>NUL
XX =
DS = $(XX)\$(XX)
endif
# Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk-20100523.zip
AWK = awk
ZIP = zip -qzr9
# Platform-dependent helper tool macros
ifeq ($(findstring /sh,$(SHELL)),/sh)
DEL = rm -f $1
RMDIR = rm -fr $1
MKDIR = mkdir -p $1
COPY = -cp -afv $1 $2
#COPYR = -cp -afr $1/* $2
COPYR = -rsync -aC $1/* $2
TOUCH = touch $1
CAT = cat
ECHONL = echo ""
DL = '
else
ifeq "$(OS)" "Windows_NT"
DEL = -del 2>NUL /q /f $(subst /,\,$1)
RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
else
DEL = -del 2>NUL $(subst /,\,$1)
RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
endif
MKDIR = -md 2>NUL $(subst /,\,$1)
COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
CAT = type
ECHONL = $(ComSpec) /c echo.
endif
# The following line defines your compiler.
ifdef METROWERKS
CC = mwcc
@@ -89,18 +95,15 @@ else
CC = $(CROSSPREFIX)gcc
endif
# Include the version info retrieved from libssh2.h
-include $(OBJDIR)/version.inc
# Global flags for all compilers
CFLAGS = $(OPT) -D$(DB) -DWIN32 -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
CFLAGS = $(OPT) -D$(DB) -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
ifeq ($(ARCH),w64)
CFLAGS += -D_AMD64_
endif
ifdef LINK_STATIC
LDLIBS += $(OPENSSL_PATH)/out/libcrypto.$(LIBEXT) $(OPENSSL_PATH)/out/libssl.$(LIBEXT)
else
LDLIBS += $(OPENSSL_PATH)/out/libeay32.$(LIBEXT) $(OPENSSL_PATH)/out/libssl32.$(LIBEXT)
endif
ifeq ($(CC),mwcc)
LD = mwld
RC = mwwinrc
@@ -119,24 +122,57 @@ CFLAGS += -w on,nounused,nounusedexpr # -ansi strict
else
LD = $(CROSSPREFIX)gcc
RC = $(CROSSPREFIX)windres
LDFLAGS = -s -shared -Wl,--out-implib,$(TARGET)dll.a
LDFLAGS = -s -shared -Wl,--output-def,$(TARGET).def,--out-implib,$(TARGET)dll.a
AR = $(CROSSPREFIX)ar
ARFLAGS = -cq
LIBEXT = a
RANLIB = $(CROSSPREFIX)ranlib
#LDLIBS += -lwsock32
LDLIBS += -lws2_32 -lgdi32
LDLIBS += -lws2_32
RCFLAGS = -I. -I ../include -O coff -i
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall # -pedantic
endif
INCLUDES = -I. -I../include
INCLUDES += -I$(OPENSSL_PATH)/outinc -I$(OPENSSL_PATH)/outinc/openssl
ifndef OPENSSL_INCLUDE
ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
endif
ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
endif
endif
ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH))
endif
INCLUDES += -I"$(OPENSSL_INCLUDE)"
ifndef OPENSSL_LIBPATH
OPENSSL_LIBS_STAT = crypto ssl
ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
OPENSSL_LIBS_DYN = eay32 ssl32
endif
ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
OPENSSL_LIBS_DYN = crypto.dll ssl.dll
endif
endif
ifdef LINK_OPENSSL_STATIC
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32
else
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN))
endif
ifdef WITH_ZLIB
CFLAGS += -DLIBSSH2_HAVE_ZLIB
INCLUDES += -I$(ZLIB_PATH)
LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
ifdef LINK_ZLIB_STATIC
LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
else
LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT)
endif
endif
CFLAGS += $(INCLUDES)
@@ -166,68 +202,68 @@ $(OBJDIR)/%.o: %.c
# @echo Compiling $<
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/version.inc: ../include/libssh2.h $(OBJDIR)
$(OBJDIR)/version.inc: ../get_ver.awk ../include/libssh2.h $(OBJDIR)
@echo Creating $@
@$(AWK) -f ../get_ver.awk $< > $@
@$(AWK) -f $^ > $@
dist: all $(DISTDIR) $(DISTDIR)/readme.txt
@-$(MD) $(DISTDIR)$(DS)bin
@-$(CP) ..$(DS)AUTHORS $(DISTDIR)
@-$(CP) ..$(DS)COPYING $(DISTDIR)
@-$(CP) ..$(DS)INSTALL $(DISTDIR)
@-$(CP) ..$(DS)README $(DISTDIR)
@-$(CP) ..$(DS)RELEASE-NOTES $(DEVLDIR)
@$(CP) $(TARGET).dll $(DISTDIR)$(DS)bin
@$(call MKDIR, $(DISTDIR)/bin)
@$(call CP, ../AUTHORS, $(DISTDIR))
@$(call CP, ../COPYING, $(DISTDIR))
@$(call CP, ../INSTALL, $(DISTDIR))
@$(call CP, ../README, $(DISTDIR))
@$(call CP, ../RELEASE-NOTES, $(DISTDIR))
@$(call CP, $(TARGET).dll, $(DISTDIR)/bin)
@echo Creating $(DISTARC)
@$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt
dev: all $(DEVLDIR) $(DEVLDIR)/readme.txt
@-$(MD) $(DEVLDIR)$(DS)bin
@-$(MD)$(DEVLDIR)$(DS)include
@-$(MD) $(DEVLDIR)$(DS)win32
@-$(CP) ..$(DS)AUTHORS $(DISTDIR)
@-$(CP) ..$(DS)COPYING $(DISTDIR)
@-$(CP) ..$(DS)INSTALL $(DEVLDIR)
@-$(CP) ..$(DS)README $(DEVLDIR)
@-$(CP) ..$(DS)RELEASE-NOTES $(DEVLDIR)
@$(CP) $(TARGET).dll $(DEVLDIR)$(DS)bin
@$(CP) ..$(DS)include$(DS)*.h $(DEVLDIR)$(DS)include
@$(CP) libssh2_config.h $(DEVLDIR)/include
@$(CP) *.$(LIBEXT) $(DEVLDIR)/win32
@$(call MKDIR, $(DEVLDIR)/bin)
@$(call MKDIR,$(DEVLDIR)/include)
@$(call MKDIR, $(DEVLDIR)/win32)
@$(call CP, ../AUTHORS, $(DEVLDIR))
@$(call CP, ../COPYING, $(DEVLDIR))
@$(call CP, ../INSTALL, $(DEVLDIR))
@$(call CP, ../README, $(DEVLDIR))
@$(call CP, ../RELEASE-NOTES, $(DEVLDIR))
@$(call CP, $(TARGET).dll, $(DEVLDIR)/bin)
@$(call CP, ../include/*.h, $(DEVLDIR)/include)
@$(call CP, libssh2_config.h, $(DEVLDIR)/include)
@$(call CP, *.$(LIBEXT), $(DEVLDIR)/win32)
@echo Creating $(DEVLARC)
@$(ZIP) $(DEVLARC) $(DEVLDIR)/* < $(DEVLDIR)/readme.txt
distclean: clean
-$(RD) $(DISTDIR)
-$(RM) $(DISTARC)
$(call RMDIR, $(DISTDIR))
$(call DEL, $(DISTARC))
devclean: clean
-$(RD) $(DEVLDIR)
-$(RM) $(DEVLARC)
$(call RMDIR, $(DEVLDIR))
$(call DEL, $(DEVLARC))
objclean: all
-$(RD) $(OBJDIR)
$(call RMDIR, $(OBJDIR))
testclean: clean
$(MAKE) -C test -f GNUmakefile clean
clean:
# -$(RM) libssh2_config.h
-$(RM) $(TARGET).dll $(TARGET).$(LIBEXT) $(TARGET)dll.$(LIBEXT)
-$(RD) $(OBJDIR)
# $(call DEL, libssh2_config.h)
$(call DEL, $(TARGET).dll $(TARGET).def $(TARGET).$(LIBEXT) $(TARGET)dll.$(LIBEXT))
$(call RMDIR, $(OBJDIR))
$(OBJDIR):
@$(MD) $@
@$(call MKDIR, $@)
$(DISTDIR):
@$(MD) $@
@$(call MKDIR, $@)
$(DEVLDIR):
@$(MD) $@
@$(call MKDIR, $@)
$(TARGET).$(LIBEXT): $(OBJS)
@echo Creating $@
@-$(RM) $@
@$(call DEL, $@)
@$(AR) $(ARFLAGS) $@ $^
ifdef RANLIB
@$(RANLIB) $@
@@ -235,7 +271,7 @@ endif
$(TARGET).dll $(TARGET)dll.a: $(OBJL)
@echo Linking $@
@-$(RM) $@
@$(call DEL, $@)
@$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS)

View File

@@ -64,13 +64,13 @@ CFLAGS += -d_WIN32_WINNT=0x0501 -dENABLE_IPV6
!ifdef %zlib_root
ZLIB_ROOT = $(%zlib_root)
!else
ZLIB_ROOT = ..\..\zlib-1.2.6
ZLIB_ROOT = ..\..\zlib-1.2.7
!endif
!ifdef %openssl_root
OPENSSL_ROOT = $(%openssl_root)
!else
OPENSSL_ROOT = ..\..\openssl-0.9.8v
OPENSSL_ROOT = ..\..\openssl-0.9.8x
!endif
#!ifdef %use_zlib

View File

@@ -1,10 +1,10 @@
# Tweak these for your system
OPENSSLINC=..\openssl-0.9.8v\inc32
OPENSSLLIB=..\openssl-0.9.8v\out32dll
OPENSSLINC=..\openssl-0.9.8x\inc32
OPENSSLLIB=..\openssl-0.9.8x\out32dll
ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.6
ZLIBLIB=..\zlib-1.2.6
ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.7
ZLIBLIB=..\zlib-1.2.7
!if "$(TARGET)" == ""
TARGET=Release
@@ -21,8 +21,9 @@ DLLFLAGS=/DEBUG /LD
CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude /I$(OPENSSLINC) $(ZLIBINC) -DLIBSSH2_WIN32
CFLAGS=$(CPPFLAGS)
RCFLAGS=/Iinclude
DLLFLAGS=$(CFLAGS) $(DLLFLAGS)
LIBS=$(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib ws2_32.lib $(ZLIBLIB)\zlib.lib
LIBS=$(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib ws2_32.lib user32.lib $(ZLIBLIB)\zlib.lib
INTDIR=$(TARGET)\$(SUBDIR)

View File

@@ -15,6 +15,7 @@
#define HAVE_UNISTD_H
#define HAVE_INTTYPES_H
#define HAVE_SYS_TIME_H
#define HAVE_GETTIMEOFDAY
#endif
#define HAVE_WINSOCK2_H

View File

@@ -9,12 +9,12 @@
# Edit the path below to point to the base of your Zlib sources.
ifndef ZLIB_PATH
ZLIB_PATH = ../../../zlib-1.2.6
ZLIB_PATH = ../../../zlib-1.2.7
endif
# Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH
OPENSSL_PATH = ../../../openssl-0.9.8v
OPENSSL_PATH = ../../../openssl-0.9.8x
endif
# Edit the var below to set to your architecture or set environment var.
@@ -28,8 +28,6 @@ LINK_STATIC = 1
# Edit the vars below to change target settings.
SAMPLES = ../../example
TARGETS := $(filter-out x11.exe,$(patsubst $(SAMPLES)/%.c,%.exe,$(strip $(wildcard $(SAMPLES)/*.c))))
VERSION = $(LIBSSH2_VERSION)
COPYR = (c) $(LIBSSH2_COPYRIGHT_STR)
WWWURL = http://www.libssh2.org/
DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR)
#STACK = 64000
@@ -48,29 +46,39 @@ else
OBJDIR = debug
endif
# Include the version info retrieved from libssh2.h
-include $(OBJDIR)/version.inc
ifeq ($(findstring /sh,$(SHELL)),/sh)
CP = cp -afv
# RM = rm -f
MD = mkdir
RD = rm -fr
DL = '
DS = /
else
CP = copy
RM = del /q /f 2>NUL
MD = md 2>NUL
RD = rd /q /s 2>NUL
XX =
DS = $(XX)\$(XX)
endif
# Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk-20100523.zip
AWK = awk
ZIP = zip -qzr9
# Platform-dependent helper tool macros
ifeq ($(findstring /sh,$(SHELL)),/sh)
DEL = rm -f $1
RMDIR = rm -fr $1
MKDIR = mkdir -p $1
COPY = -cp -afv $1 $2
#COPYR = -cp -afr $1/* $2
COPYR = -rsync -aC $1/* $2
TOUCH = touch $1
CAT = cat
ECHONL = echo ""
DL = '
else
ifeq "$(OS)" "Windows_NT"
DEL = -del 2>NUL /q /f $(subst /,\,$1)
RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
else
DEL = -del 2>NUL $(subst /,\,$1)
RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
endif
MKDIR = -md 2>NUL $(subst /,\,$1)
COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
CAT = type
ECHONL = $(ComSpec) /c echo.
endif
# The following line defines your compiler.
ifdef METROWERKS
CC = mwcc
@@ -78,8 +86,11 @@ else
CC = $(CROSSPREFIX)gcc
endif
# Include the version info retrieved from libssh2.h
-include $(OBJDIR)/version.inc
# Global flags for all compilers
CFLAGS = $(OPT) -D$(DB) -DWIN32 -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
CFLAGS = $(OPT) -D$(DB) -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H
ifeq ($(ARCH),w64)
CFLAGS += -D_AMD64_
endif
@@ -113,26 +124,53 @@ CFLAGS += -Wall #-Wno-unused #-pedantic
endif
INCLUDES = -I.. -I../../include
INCLUDES += -I$(OPENSSL_PATH)/outinc -I$(OPENSSL_PATH)/outinc/openssl
#LIBPATH += -L$(OPENSSL_PATH)/out
LIBPATH += -L..
ifdef LINK_STATIC
LDLIBS += -llibssh2
#LDLIBS += $(OPENSSL_PATH)/out/libcrypto.$(LIBEXT) $(OPENSSL_PATH)/out/libssl.$(LIBEXT)
else
LDLIBS += -llibssh2dll
#LDLIBS += $(OPENSSL_PATH)/out/libeay32.$(LIBEXT) $(OPENSSL_PATH)/out/libssl32.$(LIBEXT)
endif
ifndef OPENSSL_INCLUDE
ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
endif
ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
endif
endif
ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH))
endif
INCLUDES += -I"$(OPENSSL_INCLUDE)"
ifndef OPENSSL_LIBPATH
OPENSSL_LIBS_STAT = crypto ssl
ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
OPENSSL_LIBS_DYN = eay32 ssl32
endif
ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
OPENSSL_LIBS_DYN = crypto.dll ssl.dll
endif
endif
ifdef LINK_STATIC
ifdef LINK_OPENSSL_STATIC
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32
else
LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN))
endif
endif
ifdef WITH_ZLIB
CFLAGS += -DLIBSSH2_HAVE_ZLIB
INCLUDES += -I$(ZLIB_PATH)
#LIBPATH = -L$(ZLIB_PATH)
#ifdef LINK_STATIC
# LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
#else
# LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT)
#endif
ifdef LINK_ZLIB_STATIC
LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT)
else
LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT)
endif
endif
CFLAGS += $(INCLUDES)
@@ -155,17 +193,17 @@ $(OBJDIR)/version.inc: ../../include/libssh2.h $(OBJDIR)
@$(AWK) -f ../../get_ver.awk $< > $@
objclean:
-$(RD) $(OBJDIR)
$(call RMDIR, $(OBJDIR))
clean: objclean
-$(RM) $(TARGETS)
$(call DEL, $(TARGETS))
$(OBJDIR):
$(MD) $@
$(call MKDIR, $@)
%.exe: $(OBJDIR)/%.o $(OBJDIR)/%.res
@echo Linking $@
@-$(RM) $@
@$(call DEL, $@)
$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS)
$(OBJDIR)/%.res: $(OBJDIR)/%.rc
@@ -186,7 +224,7 @@ $(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) BLOCK "040904E4"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) VALUE "LegalCopyright","$(COPYR)\0"$(DL) >> $@
@echo $(DL) VALUE "LegalCopyright","\xA9 $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@
ifdef COMPANY
@echo $(DL) VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@
endif