Compare commits
56 Commits
RELEASE.0.
...
RELEASE.0.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
bcc4fd6e82 | ||
![]() |
210459db4b | ||
![]() |
4c3dd3ea9f | ||
![]() |
0d78e69016 | ||
![]() |
02e5b3b423 | ||
![]() |
9399ef83c4 | ||
![]() |
68c86e2c4c | ||
![]() |
15e0f56d01 | ||
![]() |
d2ef367552 | ||
![]() |
3167f054ff | ||
![]() |
209d06d6c9 | ||
![]() |
2b7856ad32 | ||
![]() |
9a1ce06e31 | ||
![]() |
c9413c628d | ||
![]() |
327c31a634 | ||
![]() |
4ace76b30d | ||
![]() |
2127c5967e | ||
![]() |
242475c42a | ||
![]() |
854dffe0a4 | ||
![]() |
278219fc0a | ||
![]() |
16be3fc778 | ||
![]() |
edcfab905a | ||
![]() |
46f59112d9 | ||
![]() |
05c1164a67 | ||
![]() |
3fc4caf42f | ||
![]() |
1a9fee074b | ||
![]() |
8f62c7322f | ||
![]() |
839be89a49 | ||
![]() |
669e69966a | ||
![]() |
138b1b3830 | ||
![]() |
4088283465 | ||
![]() |
402978bd1b | ||
![]() |
387a1fdf4b | ||
![]() |
d574d7dea0 | ||
![]() |
b2df0b26f7 | ||
![]() |
bb76ed34a0 | ||
![]() |
153e1959f4 | ||
![]() |
a3155d5d12 | ||
![]() |
8485ee6fd5 | ||
![]() |
4f76c2b80c | ||
![]() |
accd865aff | ||
![]() |
84e16944b4 | ||
![]() |
e0254f3936 | ||
![]() |
14881b2370 | ||
![]() |
4ec68bdc04 | ||
![]() |
a87fdff9e9 | ||
![]() |
50fd6590f0 | ||
![]() |
2b1c979d7e | ||
![]() |
6ac790a477 | ||
![]() |
b53db3d3a9 | ||
![]() |
83d77f3878 | ||
![]() |
530e57d4ac | ||
![]() |
a9fc3bdb4e | ||
![]() |
e2c88f6ae3 | ||
![]() |
cf9ed016e7 | ||
![]() |
1901324122 |
@@ -1,5 +1,5 @@
|
|||||||
jas4711:Simon Josefsson <simon@josefsson.org>
|
jas4711:Simon Josefsson <simon@josefsson.org>
|
||||||
bagder:Daniel Stenberg <daniel@haxx.se>
|
bagder:Daniel Stenberg
|
||||||
sarag:Sara Golemon <pollita@libssh2.org>
|
sarag:Sara Golemon <pollita@libssh2.org>
|
||||||
gusarov:Mikhail Gusarov <dottedmag@dottedmag.net>
|
gusarov:Mikhail Gusarov <dottedmag@dottedmag.net>
|
||||||
wez:Wez Furlong
|
wez:Wez Furlong
|
||||||
|
32
HACKING
Normal file
32
HACKING
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
libssh2 source code style guide:
|
||||||
|
|
||||||
|
- 4 level indent
|
||||||
|
- spaces-only (no tabs)
|
||||||
|
- open braces on the if/for line:
|
||||||
|
|
||||||
|
if (banana) {
|
||||||
|
go_nuts();
|
||||||
|
}
|
||||||
|
|
||||||
|
- write both braces on the else line:
|
||||||
|
|
||||||
|
if (banana) {
|
||||||
|
go_nuts();
|
||||||
|
} else {
|
||||||
|
stay_calm();
|
||||||
|
}
|
||||||
|
|
||||||
|
- use braces even for single-statement blocks
|
||||||
|
|
||||||
|
- keep source lines shorter than 80 columns
|
||||||
|
|
||||||
|
------------
|
||||||
|
|
||||||
|
Older libssh2 code that still hasn't quite transitioned to the above
|
||||||
|
mentioned style, used a different style:
|
||||||
|
|
||||||
|
- indented with tabs (only)
|
||||||
|
|
||||||
|
- no line length limits
|
||||||
|
|
17
Makefile.am
17
Makefile.am
@@ -5,7 +5,13 @@ include_HEADERS = \
|
|||||||
include/libssh2_publickey.h \
|
include/libssh2_publickey.h \
|
||||||
include/libssh2_sftp.h
|
include/libssh2_sftp.h
|
||||||
|
|
||||||
EXTRA_DIST = win32 buildconf
|
NETWAREFILES = nw/keepscreen.c \
|
||||||
|
nw/Makefile \
|
||||||
|
nw/Makefile.netware \
|
||||||
|
nw/nwlib.c \
|
||||||
|
nw/test/Makefile.netware
|
||||||
|
|
||||||
|
EXTRA_DIST = win32 buildconf $(NETWAREFILES) get_ver.awk HACKING maketgz NMakefile
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
@@ -14,3 +20,12 @@ ChangeLog:
|
|||||||
if test -f .cvsusers; then \
|
if test -f .cvsusers; then \
|
||||||
cvs2cl --utc --fsf --FSF --usermap .cvsusers -I ChangeLog -I .cvs; \
|
cvs2cl --utc --fsf --FSF --usermap .cvsusers -I ChangeLog -I .cvs; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dist-hook:
|
||||||
|
rm -rf $(top_builddir)/tests/log
|
||||||
|
find $(distdir) -name "*.dist" -exec rm {} \;
|
||||||
|
(distit=`find $(srcdir) -name "*.dist"`; \
|
||||||
|
for file in $$distit; do \
|
||||||
|
strip=`echo $$file | sed -e s/^$(srcdir)// -e s/\.dist//`; \
|
||||||
|
cp $$file $(distdir)$$strip; \
|
||||||
|
done)
|
||||||
|
48
NEWS
48
NEWS
@@ -1,4 +1,50 @@
|
|||||||
Version
|
Version 0.17
|
||||||
|
------------
|
||||||
|
Changes since previous version include:
|
||||||
|
|
||||||
|
o Re-indented the source code with this GNU indent setup:
|
||||||
|
|
||||||
|
--braces-on-if-line
|
||||||
|
--braces-after-struct-decl-line
|
||||||
|
--space-after-cast
|
||||||
|
--line-length 79
|
||||||
|
--comment-line-length 79
|
||||||
|
--cuddle-else
|
||||||
|
--no-tabs
|
||||||
|
--tab-size 8
|
||||||
|
--indent-level 4
|
||||||
|
--no-space-after-for
|
||||||
|
--space-after-if
|
||||||
|
--space-after-while
|
||||||
|
--no-space-after-function-call-names
|
||||||
|
|
||||||
|
Version 0.16
|
||||||
|
------------
|
||||||
|
Changes since previous version include:
|
||||||
|
|
||||||
|
o CRLF stripping fix for PEM reading
|
||||||
|
o libssh2_scp_recv() error message fix
|
||||||
|
o added HACKING as an initial attempt to describe our source code format
|
||||||
|
o new public defines in include/libssh2.h to allow applictions to figure out
|
||||||
|
version number etc
|
||||||
|
o new script (maketgz) to build releases with
|
||||||
|
o updated files for building with MSVC and mingw
|
||||||
|
o keyboard-interactive would always fail due to claimed memory problem
|
||||||
|
o a few minor memory leaks fixed
|
||||||
|
o libssh2_poll() no longer relies on C99 features
|
||||||
|
o AIX 4 and 5 now supports non-blocking sockets
|
||||||
|
o large file magic checks in configure
|
||||||
|
o LIBSSH2_APINO was removed from the public header file
|
||||||
|
|
||||||
|
This release would not have been possible without these friendly contributors:
|
||||||
|
|
||||||
|
James Housley, Simon Josefsson, Dan Fandrich, Guenter Knauf and I too did
|
||||||
|
some poking. (Sorry if I forgot anyone I should've mentioned here.)
|
||||||
|
|
||||||
|
Of course we would have nothing without the great work by Sara Golemon that
|
||||||
|
we're extending and building upon.
|
||||||
|
|
||||||
|
Version 0.15
|
||||||
------------
|
------------
|
||||||
Added libssh2_sftp_readdir_ex() and updated LIBSSH2_APINO to
|
Added libssh2_sftp_readdir_ex() and updated LIBSSH2_APINO to
|
||||||
200706151200 (James Housley)
|
200706151200 (James Housley)
|
||||||
|
15
NMakefile
15
NMakefile
@@ -1,16 +1,19 @@
|
|||||||
!include "win32/config.mk"
|
!include "win32/config.mk"
|
||||||
|
|
||||||
|
# SUBDIRS=src example\simple
|
||||||
SUBDIRS=src
|
SUBDIRS=src
|
||||||
|
|
||||||
all: all-sub ssh2_sample.exe
|
|
||||||
|
|
||||||
ssh2_sample.exe: ssh2_sample.c
|
|
||||||
$(CC) $(CFLAGS) -DWIN32 -o ssh2_sample.exe ssh2_sample.c libssh2$(SUFFIX).lib $(LIBS)
|
|
||||||
|
|
||||||
all-sub:
|
all-sub:
|
||||||
-for %D in ($(SUBDIRS)) do $(MAKE) /nologo /f %D/NMakefile BUILD=$(BUILD) SUBDIR=%D all-sub
|
-for %D in ($(SUBDIRS)) do $(MAKE) /nologo /f %D/NMakefile BUILD=$(BUILD) SUBDIR=%D all-sub
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rmdir /s/q $(TARGET)
|
-rmdir /s/q $(TARGET)
|
||||||
|
|
||||||
|
real-clean: clean
|
||||||
|
-del libssh2.dll
|
||||||
|
-del libssh2.exp
|
||||||
|
-del libssh2.ilk
|
||||||
|
-del libssh2.lib
|
||||||
|
-del *.pdb
|
||||||
|
|
||||||
|
|
||||||
|
@@ -178,7 +178,7 @@ AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
|
|||||||
# define PLATFORM_SUNOS4
|
# define PLATFORM_SUNOS4
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
|
#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
|
||||||
# define PLATFORM_AIX_V3
|
# define PLATFORM_AIX_V3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -3,5 +3,9 @@
|
|||||||
${LIBTOOLIZE:-libtoolize} --copy --automake --force
|
${LIBTOOLIZE:-libtoolize} --copy --automake --force
|
||||||
${ACLOCAL:-aclocal} -I m4 $ACLOCAL_FLAGS
|
${ACLOCAL:-aclocal} -I m4 $ACLOCAL_FLAGS
|
||||||
${AUTOHEADER:-autoheader}
|
${AUTOHEADER:-autoheader}
|
||||||
|
# copy the private libssh2_config.h.in to the examples dir so that
|
||||||
|
# it can be included without pointing the include path to the private
|
||||||
|
# source dir
|
||||||
|
cp src/libssh2_config.h.in example/simple/config.h.in
|
||||||
${AUTOCONF:-autoconf}
|
${AUTOCONF:-autoconf}
|
||||||
${AUTOMAKE:-automake} --add-missing --copy
|
${AUTOMAKE:-automake} --add-missing --copy
|
||||||
|
29
configure.in
29
configure.in
@@ -1,8 +1,26 @@
|
|||||||
# AC_PREREQ(2.57)
|
# AC_PREREQ(2.57)
|
||||||
AC_INIT(libssh2, 0.15, libssh2-devel@lists.sourceforge.net)
|
AC_INIT(libssh2, [-], libssh2-devel@lists.sourceforge.net)
|
||||||
AM_INIT_AUTOMAKE(libssh2, 0.15)
|
|
||||||
AC_CONFIG_SRCDIR([src])
|
AC_CONFIG_SRCDIR([src])
|
||||||
AC_CONFIG_HEADER([src/libssh2_config.h])
|
AC_CONFIG_HEADER([src/libssh2_config.h example/simple/config.h])
|
||||||
|
AM_MAINTAINER_MODE
|
||||||
|
|
||||||
|
dnl SED is needed by some of the tools
|
||||||
|
AC_PATH_PROG( SED, sed, sed-was-not-found-by-configure,
|
||||||
|
$PATH:/usr/bin:/usr/local/bin)
|
||||||
|
AC_SUBST(SED)
|
||||||
|
|
||||||
|
if test "x$SED" = "xsed-was-not-found-by-configure"; then
|
||||||
|
AC_MSG_WARN([sed was not found, this may ruin your chances to build fine])
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl figure out the libssh2 version
|
||||||
|
VERSION=`$SED -ne 's/^#define LIBSSH2_VERSION *"\(.*\)"/\1/p' ${srcdir}/include/libssh2.h`
|
||||||
|
AM_INIT_AUTOMAKE(libssh2,$VERSION)
|
||||||
|
AC_MSG_CHECKING([libssh2 version])
|
||||||
|
AC_MSG_RESULT($VERSION)
|
||||||
|
|
||||||
|
AB_VERSION=$VERSION
|
||||||
|
|
||||||
AB_INIT
|
AB_INIT
|
||||||
|
|
||||||
# Check for the OS.
|
# Check for the OS.
|
||||||
@@ -40,6 +58,9 @@ if test -z "$PKG_CONFIG"; then
|
|||||||
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
|
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dnl check for how to do large files
|
||||||
|
AC_SYS_LARGEFILE
|
||||||
|
|
||||||
# Look for libgcrypt.
|
# Look for libgcrypt.
|
||||||
AC_ARG_WITH(libgcrypt,
|
AC_ARG_WITH(libgcrypt,
|
||||||
AC_HELP_STRING([--with-libgcrypt],[Use libgcrypt for crypto]),
|
AC_HELP_STRING([--with-libgcrypt],[Use libgcrypt for crypto]),
|
||||||
@@ -230,6 +251,8 @@ AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h])
|
|||||||
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
|
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
|
||||||
AC_CHECK_FUNCS(poll gettimeofday select)
|
AC_CHECK_FUNCS(poll gettimeofday select)
|
||||||
|
|
||||||
|
AC_FUNC_ALLOCA
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_C_CONST
|
AC_C_CONST
|
||||||
AC_C_INLINE
|
AC_C_INLINE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
.\" $Id: libssh2_sftp_readdir.3,v 1.9 2007/06/15 17:22:49 jehousley Exp $
|
.\" $Id: libssh2_sftp_readdir.3,v 1.11 2007/07/04 10:44:40 jehousley Exp $
|
||||||
.\"
|
.\"
|
||||||
.TH libssh2_sftp_readdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual"
|
.TH libssh2_sftp_readdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
@@ -41,7 +41,7 @@ however, it uses a variable sized directory entry (filename) buffer and
|
|||||||
returns statbuf type data in the same call.
|
returns statbuf type data in the same call.
|
||||||
|
|
||||||
.SH RETURN VALUE
|
.SH RETURN VALUE
|
||||||
Number of bytes actually populated into buffer, or -1 on failure. It returns
|
Number of bytes actually populated into buffer, or negative on failure. It returns
|
||||||
LIBSSH2_ERROR_EAGAIN when it would otherwise block. While
|
LIBSSH2_ERROR_EAGAIN when it would otherwise block. While
|
||||||
LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se.
|
LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se.
|
||||||
.SH ERRORS
|
.SH ERRORS
|
||||||
|
@@ -10,7 +10,7 @@ noinst_PROGRAMS = ssh2 \
|
|||||||
sftp_RW_nonblock \
|
sftp_RW_nonblock \
|
||||||
sftpdir sftpdir_nonblock
|
sftpdir sftpdir_nonblock
|
||||||
|
|
||||||
INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/src
|
INCLUDES = -I$(top_srcdir)/include
|
||||||
LDADD = $(top_builddir)/src/libssh2.la
|
LDADD = $(top_builddir)/src/libssh2.la
|
||||||
|
|
||||||
ssh2_SOURCES = ssh2.c
|
ssh2_SOURCES = ssh2.c
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: scp.c,v 1.7 2007/06/06 12:34:08 jehousley Exp $
|
* $Id: scp.c,v 1.9 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do a simple SCP transfer.
|
* Sample showing how to do a simple SCP transfer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: scp_nonblock.c,v 1.5 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: scp_nonblock.c,v 1.8 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SCP transfers in a non-blocking manner.
|
* Sample showing how to do SCP transfers in a non-blocking manner.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -146,7 +146,10 @@ int main(int argc, char *argv[])
|
|||||||
channel = libssh2_scp_recv(session, scppath, &fileinfo);
|
channel = libssh2_scp_recv(session, scppath, &fileinfo);
|
||||||
|
|
||||||
if ((!channel) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
|
if ((!channel) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
|
||||||
fprintf(stderr, "Unable to open a session\n");
|
char *err_msg;
|
||||||
|
|
||||||
|
libssh2_session_last_error(session, &err_msg, NULL, 0);
|
||||||
|
fprintf(stderr, "%s\n", err_msg);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
} while (!channel);
|
} while (!channel);
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: scp_write.c,v 1.1 2007/06/06 12:34:08 jehousley Exp $
|
* $Id: scp_write.c,v 1.4 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do a simple SCP transfer.
|
* Sample showing how to do a simple SCP transfer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -142,10 +142,9 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//libssh2_trace(session, 0xFFFF);
|
|
||||||
|
|
||||||
/* Request a file via SCP */
|
/* Request a file via SCP */
|
||||||
channel = libssh2_scp_send(session, scppath, 0x1FF & fileinfo.st_mode, (unsigned long)fileinfo.st_size);
|
channel = libssh2_scp_send(session, scppath, 0x1FF & fileinfo.st_mode,
|
||||||
|
(unsigned long)fileinfo.st_size);
|
||||||
|
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
fprintf(stderr, "Unable to open a session\n");
|
fprintf(stderr, "Unable to open a session\n");
|
||||||
@@ -178,9 +177,6 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "Waiting for channel to close\n");
|
fprintf(stderr, "Waiting for channel to close\n");
|
||||||
libssh2_channel_wait_closed(channel);
|
libssh2_channel_wait_closed(channel);
|
||||||
|
|
||||||
// fprintf(stderr, "Closing channel\n");
|
|
||||||
// libssh2_channel_close(channel);
|
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
channel = NULL;
|
channel = NULL;
|
||||||
|
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: scp_write_nonblock.c,v 1.2 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: scp_write_nonblock.c,v 1.6 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do a simple SCP transfer.
|
* Sample showing how to do a simple SCP transfer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -141,7 +142,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (auth_pw) {
|
if (auth_pw) {
|
||||||
/* We could authenticate via password */
|
/* We could authenticate via password */
|
||||||
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
|
while ((rc = libssh2_userauth_password(session, username, password)) ==
|
||||||
|
LIBSSH2_ERROR_EAGAIN);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
fprintf(stderr, "Authentication by password failed.\n");
|
fprintf(stderr, "Authentication by password failed.\n");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
@@ -158,14 +160,17 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// libssh2_trace(session, 0xFF7D);
|
|
||||||
|
|
||||||
/* Request a file via SCP */
|
/* Request a file via SCP */
|
||||||
do {
|
do {
|
||||||
channel = libssh2_scp_send(session, scppath, 0x1FF & fileinfo.st_mode, (unsigned long)fileinfo.st_size);
|
channel = libssh2_scp_send(session, scppath, 0x1FF & fileinfo.st_mode,
|
||||||
|
(unsigned long)fileinfo.st_size);
|
||||||
|
|
||||||
if ((!channel) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
|
if ((!channel) && (libssh2_session_last_errno(session) !=
|
||||||
fprintf(stderr, "Unable to open a session\n");
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
|
char *err_msg;
|
||||||
|
|
||||||
|
libssh2_session_last_error(session, &err_msg, NULL, 0);
|
||||||
|
fprintf(stderr, "%s\n", err_msg);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
} while (!channel);
|
} while (!channel);
|
||||||
@@ -181,7 +186,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
/* write data in a loop until we block */
|
/* write data in a loop until we block */
|
||||||
while ((rc = libssh2_channel_write(channel, ptr, nread)) == LIBSSH2_ERROR_EAGAIN);
|
while ((rc = libssh2_channel_write(channel, ptr, nread)) ==
|
||||||
|
LIBSSH2_ERROR_EAGAIN);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
fprintf(stderr, "ERROR %d\n", rc);
|
fprintf(stderr, "ERROR %d\n", rc);
|
||||||
}
|
}
|
||||||
@@ -199,15 +205,13 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "Waiting for channel to close\n");
|
fprintf(stderr, "Waiting for channel to close\n");
|
||||||
while (libssh2_channel_wait_closed(channel) == LIBSSH2_ERROR_EAGAIN);
|
while (libssh2_channel_wait_closed(channel) == LIBSSH2_ERROR_EAGAIN);
|
||||||
|
|
||||||
// fprintf(stderr, "Closing channel\n");
|
|
||||||
// while (libssh2_channel_close(channel) == LIBSSH2_ERROR_EAGAIN);
|
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
channel = NULL;
|
channel = NULL;
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
|
|
||||||
while ((rc = libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing")) == LIBSSH2_ERROR_EAGAIN);
|
while ((rc = libssh2_session_disconnect(session,
|
||||||
|
"Normal Shutdown, Thank you for playing")) == LIBSSH2_ERROR_EAGAIN);
|
||||||
libssh2_session_free(session);
|
libssh2_session_free(session);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp.c,v 1.8 2007/06/06 12:34:08 jehousley Exp $
|
* $Id: sftp.c,v 1.12 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP transfers.
|
* Sample showing how to do SFTP transfers.
|
||||||
*
|
*
|
||||||
* 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 /tmp/secrets"
|
* "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -38,16 +38,41 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
char *keyfile1=(char *)"~/.ssh/id_rsa.pub";
|
||||||
unsigned long hostaddr;
|
char *keyfile2=(char *)"~/.ssh/id_rsa";
|
||||||
int sock, i, auth_pw = 1;
|
|
||||||
struct sockaddr_in sin;
|
|
||||||
const char *fingerprint;
|
|
||||||
LIBSSH2_SESSION *session;
|
|
||||||
char *username=(char *)"username";
|
char *username=(char *)"username";
|
||||||
char *password=(char *)"password";
|
char *password=(char *)"password";
|
||||||
char *sftppath=(char *)"/tmp/TEST";
|
char *sftppath=(char *)"/tmp/TEST";
|
||||||
|
|
||||||
|
|
||||||
|
static void kbd_callback(const char *name, int name_len,
|
||||||
|
const char *instruction, int instruction_len, int num_prompts,
|
||||||
|
const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
|
||||||
|
LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
|
||||||
|
void **abstract)
|
||||||
|
{
|
||||||
|
(void)name;
|
||||||
|
(void)name_len;
|
||||||
|
(void)instruction;
|
||||||
|
(void)instruction_len;
|
||||||
|
if (num_prompts == 1) {
|
||||||
|
responses[0].text = strdup(password);
|
||||||
|
responses[0].length = strlen(password);
|
||||||
|
}
|
||||||
|
(void)prompts;
|
||||||
|
(void)abstract;
|
||||||
|
} /* kbd_callback */
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
unsigned long hostaddr;
|
||||||
|
int sock, i, auth_pw = 0;
|
||||||
|
struct sockaddr_in sin;
|
||||||
|
const char *fingerprint;
|
||||||
|
char *userauthlist;
|
||||||
|
LIBSSH2_SESSION *session;
|
||||||
int rc;
|
int rc;
|
||||||
LIBSSH2_SFTP *sftp_session;
|
LIBSSH2_SFTP *sftp_session;
|
||||||
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
||||||
@@ -121,21 +146,57 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
if (auth_pw) {
|
/* check what authentication methods are available */
|
||||||
|
userauthlist = libssh2_userauth_list(session, username, sizeof(username));
|
||||||
|
printf("Authentication methods: %s\n", userauthlist);
|
||||||
|
if (strstr(userauthlist, "password") != NULL) {
|
||||||
|
auth_pw |= 1;
|
||||||
|
}
|
||||||
|
if (strstr(userauthlist, "keyboard-interactive") != NULL) {
|
||||||
|
auth_pw |= 2;
|
||||||
|
}
|
||||||
|
if (strstr(userauthlist, "publickey") != NULL) {
|
||||||
|
auth_pw |= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we got an 4. argument we set this option if supported */
|
||||||
|
if(argc > 5) {
|
||||||
|
if ((auth_pw & 1) && !strcasecmp(argv[5], "-p")) {
|
||||||
|
auth_pw = 1;
|
||||||
|
}
|
||||||
|
if ((auth_pw & 2) && !strcasecmp(argv[5], "-i")) {
|
||||||
|
auth_pw = 2;
|
||||||
|
}
|
||||||
|
if ((auth_pw & 4) && !strcasecmp(argv[5], "-k")) {
|
||||||
|
auth_pw = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auth_pw & 1) {
|
||||||
/* We could authenticate via password */
|
/* We could authenticate via password */
|
||||||
if (libssh2_userauth_password(session, username, password)) {
|
if (libssh2_userauth_password(session, username, password)) {
|
||||||
fprintf(stderr, "Authentication by password failed.\n");
|
fprintf(stderr, "Authentication by password failed.\n");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (auth_pw & 2) {
|
||||||
/* Or by public key */
|
/* Or via keyboard-interactive */
|
||||||
if (libssh2_userauth_publickey_fromfile(session, username,
|
if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) ) {
|
||||||
"/home/username/.ssh/id_rsa.pub",
|
printf("\tAuthentication by keyboard-interactive failed!\n");
|
||||||
"/home/username/.ssh/id_rsa",
|
|
||||||
password)) {
|
|
||||||
fprintf(stderr, "\tAuthentication by public key failed\n");
|
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
|
} else {
|
||||||
|
printf("\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");
|
||||||
|
goto shutdown;
|
||||||
|
} else {
|
||||||
|
printf("\tAuthentication by public key succeeded.\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("No supported authentication methods found!\n");
|
||||||
|
goto shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "libssh2_sftp_init()!\n");
|
fprintf(stderr, "libssh2_sftp_init()!\n");
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp_RW_nonblock.c,v 1.7 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: sftp_RW_nonblock.c,v 1.9 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP transfers in a non-blocking manner.
|
* Sample showing how to do SFTP transfers in a non-blocking manner.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* Using the SFTP server running on 127.0.0.1
|
* Using the SFTP server running on 127.0.0.1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp_mkdir.c,v 1.4 2007/06/06 12:34:08 jehousley Exp $
|
* $Id: sftp_mkdir.c,v 1.6 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP mkdir
|
* Sample showing how to do SFTP mkdir
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftp 192.168.0.1 user password /tmp/sftp_mkdir"
|
* "sftp 192.168.0.1 user password /tmp/sftp_mkdir"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp_mkdir_nonblock.c,v 1.6 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: sftp_mkdir_nonblock.c,v 1.8 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP non-blocking mkdir.
|
* Sample showing how to do SFTP non-blocking mkdir.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c"
|
* "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp_nonblock.c,v 1.10 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: sftp_nonblock.c,v 1.12 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP non-blocking transfers.
|
* Sample showing how to do SFTP non-blocking transfers.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftp 192.168.0.1 user password /tmp/secrets"
|
* "sftp 192.168.0.1 user password /tmp/secrets"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp_write.c,v 1.4 2007/06/06 12:34:09 jehousley Exp $
|
* $Id: sftp_write.c,v 1.7 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP write transfers.
|
* Sample showing how to do SFTP write transfers.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets"
|
* "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -147,8 +147,6 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//libssh2_trace(session, 0xFFFF);
|
|
||||||
|
|
||||||
fprintf(stderr, "libssh2_sftp_init()!\n");
|
fprintf(stderr, "libssh2_sftp_init()!\n");
|
||||||
sftp_session = libssh2_sftp_init(session);
|
sftp_session = libssh2_sftp_init(session);
|
||||||
|
|
||||||
@@ -195,7 +193,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
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp_write_nonblock.c,v 1.7 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: sftp_write_nonblock.c,v 1.9 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP non-blocking write transfers.
|
* Sample showing how to do SFTP non-blocking write transfers.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftp 192.168.0.1 user password sftp_write_nonblock.c /tmp/sftp_write_nonblock.c"
|
* "sftp 192.168.0.1 user password sftp_write_nonblock.c /tmp/sftp_write_nonblock.c"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftpdir.c,v 1.6 2007/06/15 17:22:49 jehousley Exp $
|
* $Id: sftpdir.c,v 1.8 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample doing an SFTP directory listing.
|
* Sample doing an SFTP directory listing.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftpdir 192.168.0.1 user password /tmp/secretdir"
|
* "sftpdir 192.168.0.1 user password /tmp/secretdir"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftpdir_nonblock.c,v 1.7 2007/06/08 13:33:08 jehousley Exp $
|
* $Id: sftpdir_nonblock.c,v 1.9 2007/07/31 11:00:29 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample doing an SFTP directory listing.
|
* Sample doing an SFTP directory listing.
|
||||||
*
|
*
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
* "sftpdir 192.168.0.1 user password /tmp/secretdir"
|
* "sftpdir 192.168.0.1 user password /tmp/secretdir"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -127,7 +127,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (auth_pw) {
|
if (auth_pw) {
|
||||||
/* We could authenticate via password */
|
/* We could authenticate via password */
|
||||||
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
|
while ((rc = libssh2_userauth_password(session, username, password)) ==
|
||||||
|
LIBSSH2_ERROR_EAGAIN);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
fprintf(stderr, "Authentication by password failed.\n");
|
fprintf(stderr, "Authentication by password failed.\n");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
@@ -148,7 +149,8 @@ int main(int argc, char *argv[])
|
|||||||
do {
|
do {
|
||||||
sftp_session = libssh2_sftp_init(session);
|
sftp_session = libssh2_sftp_init(session);
|
||||||
|
|
||||||
if ((!sftp_session) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
|
if ((!sftp_session) && (libssh2_session_last_errno(session) !=
|
||||||
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
fprintf(stderr, "Unable to init SFTP session\n");
|
fprintf(stderr, "Unable to init SFTP session\n");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
@@ -159,7 +161,8 @@ int main(int argc, char *argv[])
|
|||||||
do {
|
do {
|
||||||
sftp_handle = libssh2_sftp_opendir(sftp_session, sftppath);
|
sftp_handle = libssh2_sftp_opendir(sftp_session, sftppath);
|
||||||
|
|
||||||
if ((!sftp_handle) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
|
if ((!sftp_handle) && (libssh2_session_last_errno(session) !=
|
||||||
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
fprintf(stderr, "Unable to open dir with SFTP\n");
|
fprintf(stderr, "Unable to open dir with SFTP\n");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
@@ -171,7 +174,8 @@ int main(int argc, char *argv[])
|
|||||||
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
||||||
|
|
||||||
/* loop until we fail */
|
/* loop until we fail */
|
||||||
while ((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem), &attrs)) == LIBSSH2_ERROR_EAGAIN) {
|
while ((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem),
|
||||||
|
&attrs)) == LIBSSH2_ERROR_EAGAIN) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: ssh2.c,v 1.3 2007/04/26 23:59:15 gknauf Exp $
|
* $Id: ssh2.c,v 1.16 2007/08/03 15:08:28 jehousley Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SSH2 connect.
|
* Sample showing how to do SSH2 connect.
|
||||||
*
|
*
|
||||||
* 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:
|
||||||
*
|
*
|
||||||
* "ssh2 host user password"
|
* "ssh2 host user password [-p|-i|-k]"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <libssh2.h>
|
#include <libssh2.h>
|
||||||
#include <libssh2_sftp.h>
|
#include <libssh2_sftp.h>
|
||||||
#include <libssh2_config.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -25,6 +25,9 @@
|
|||||||
# ifdef HAVE_UNISTD_H
|
# ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
# ifdef HAVE_ARPA_INET_H
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -32,16 +35,41 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
char *keyfile1=(char *)"~/.ssh/id_rsa.pub";
|
||||||
|
char *keyfile2=(char *)"~/.ssh/id_rsa";
|
||||||
|
char *username=(char *)"username";
|
||||||
|
char *password=(char *)"password";
|
||||||
|
|
||||||
|
|
||||||
|
static void kbd_callback(const char *name, int name_len,
|
||||||
|
const char *instruction, int instruction_len, int num_prompts,
|
||||||
|
const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
|
||||||
|
LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
|
||||||
|
void **abstract)
|
||||||
|
{
|
||||||
|
(void)name;
|
||||||
|
(void)name_len;
|
||||||
|
(void)instruction;
|
||||||
|
(void)instruction_len;
|
||||||
|
if (num_prompts == 1) {
|
||||||
|
responses[0].text = strdup(password);
|
||||||
|
responses[0].length = strlen(password);
|
||||||
|
}
|
||||||
|
(void)prompts;
|
||||||
|
(void)abstract;
|
||||||
|
} /* kbd_callback */
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned long hostaddr;
|
unsigned long hostaddr;
|
||||||
int sock, i, auth_pw = 1;
|
int sock, i, auth_pw = 0;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
const char *fingerprint;
|
const char *fingerprint;
|
||||||
|
char *userauthlist;
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
char *username=(char *)"username";
|
|
||||||
char *password=(char *)"password";
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
WSADATA wsadata;
|
WSADATA wsadata;
|
||||||
|
|
||||||
@@ -97,19 +125,60 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (auth_pw) {
|
/* check what authentication methods are available */
|
||||||
|
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
||||||
|
printf("Authentication methods: %s\n", userauthlist);
|
||||||
|
if (strstr(userauthlist, "password") != NULL) {
|
||||||
|
auth_pw |= 1;
|
||||||
|
}
|
||||||
|
if (strstr(userauthlist, "keyboard-interactive") != NULL) {
|
||||||
|
auth_pw |= 2;
|
||||||
|
}
|
||||||
|
if (strstr(userauthlist, "publickey") != NULL) {
|
||||||
|
auth_pw |= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we got an 4. argument we set this option if supported */
|
||||||
|
if(argc > 4) {
|
||||||
|
if ((auth_pw & 1) && !strcasecmp(argv[4], "-p")) {
|
||||||
|
auth_pw = 1;
|
||||||
|
}
|
||||||
|
if ((auth_pw & 2) && !strcasecmp(argv[4], "-i")) {
|
||||||
|
auth_pw = 2;
|
||||||
|
}
|
||||||
|
if ((auth_pw & 4) && !strcasecmp(argv[4], "-k")) {
|
||||||
|
auth_pw = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auth_pw & 1) {
|
||||||
/* We could authenticate via password */
|
/* We could authenticate via password */
|
||||||
if (libssh2_userauth_password(session, username, password)) {
|
if (libssh2_userauth_password(session, username, password)) {
|
||||||
printf("Authentication by password failed.\n");
|
printf("\tAuthentication by password failed!\n");
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
|
} else {
|
||||||
|
printf("\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");
|
||||||
|
goto shutdown;
|
||||||
|
} else {
|
||||||
|
printf("\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");
|
||||||
|
goto shutdown;
|
||||||
|
} else {
|
||||||
|
printf("\tAuthentication by public key succeeded.\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Or by public key */
|
printf("No supported authentication methods found!\n");
|
||||||
if (libssh2_userauth_publickey_fromfile(session, username, "/home/username/.ssh/id_rsa.pub", "/home/username/.ssh/id_rsa", password)) {
|
|
||||||
printf("\tAuthentication by public key failed\n");
|
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Request a shell */
|
/* Request a shell */
|
||||||
if (!(channel = libssh2_channel_open_session(session))) {
|
if (!(channel = libssh2_channel_open_session(session))) {
|
||||||
@@ -173,6 +242,6 @@ int main(int argc, char *argv[])
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
close(sock);
|
close(sock);
|
||||||
#endif
|
#endif
|
||||||
printf("all done\n");
|
printf("all done!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -64,20 +64,56 @@ extern "C" {
|
|||||||
# include <sys/uio.h>
|
# include <sys/uio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LIBSSH2_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1300)
|
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
|
||||||
typedef unsigned __int64 libssh2_uint64_t;
|
# include <sys/bsdskt.h>
|
||||||
typedef __int64 libssh2_int64_t;
|
|
||||||
#if (_MSC_VER <= 1200)
|
|
||||||
typedef long ssize_t;
|
|
||||||
typedef unsigned int uint32_t;
|
typedef unsigned int uint32_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LIBSSH2_WIN32) && defined(_MSC_VER) && (_MSC_VER <= 1400)
|
||||||
|
typedef unsigned __int64 libssh2_uint64_t;
|
||||||
|
typedef __int64 libssh2_int64_t;
|
||||||
|
typedef long ssize_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
#else
|
#else
|
||||||
typedef unsigned long long libssh2_uint64_t;
|
typedef unsigned long long libssh2_uint64_t;
|
||||||
typedef long long libssh2_int64_t;
|
typedef long long libssh2_int64_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LIBSSH2_VERSION "0.15-CVS"
|
#define LIBSSH2_VERSION "0.16.0-CVS"
|
||||||
#define LIBSSH2_APINO 200706151200
|
|
||||||
|
/* The numeric version number is also available "in parts" by using these
|
||||||
|
defines: */
|
||||||
|
#define LIBSSH2_VERSION_MAJOR 0
|
||||||
|
#define LIBSSH2_VERSION_MINOR 16
|
||||||
|
#define LIBSSH2_VERSION_PATCH 0
|
||||||
|
|
||||||
|
/* This is the numeric version of the libssh2 version number, meant for easier
|
||||||
|
parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
|
||||||
|
always follow this syntax:
|
||||||
|
|
||||||
|
0xXXYYZZ
|
||||||
|
|
||||||
|
Where XX, YY and ZZ are the main version, release and patch numbers in
|
||||||
|
hexadecimal (using 8 bits each). All three numbers are always represented
|
||||||
|
using two digits. 1.2 would appear as "0x010200" while version 9.11.7
|
||||||
|
appears as "0x090b07".
|
||||||
|
|
||||||
|
This 6-digit (24 bits) hexadecimal number does not show pre-release number,
|
||||||
|
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 0x001000
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the date and time when the full source package was created. The
|
||||||
|
* timestamp is not stored in CVS, as the timestamp is properly set in the
|
||||||
|
* tarballs by the maketgz script.
|
||||||
|
*
|
||||||
|
* The format of the date should follow this template:
|
||||||
|
*
|
||||||
|
* "Mon Feb 12 11:35:33 UTC 2007"
|
||||||
|
*/
|
||||||
|
#define LIBSSH2_TIMESTAMP "CVS"
|
||||||
|
|
||||||
/* 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
|
||||||
|
73
maketgz
Executable file
73
maketgz
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Script to build release-archives with
|
||||||
|
#
|
||||||
|
|
||||||
|
version=$1
|
||||||
|
|
||||||
|
if [ -z "$version" ]; then
|
||||||
|
echo "Specify a version number!"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
libversion="$version"
|
||||||
|
|
||||||
|
major=`echo $libversion |cut -d. -f1 | sed -e "s/[^0-9]//g"`
|
||||||
|
minor=`echo $libversion |cut -d. -f2 | sed -e "s/[^0-9]//g"`
|
||||||
|
patch=`echo $libversion |cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g"`
|
||||||
|
|
||||||
|
numeric=`perl -e 'printf("%02x%02x%02x\n", '"$major, $minor, $patch);"`
|
||||||
|
|
||||||
|
HEADER=include/libssh2.h
|
||||||
|
|
||||||
|
# requires a date command that knows -u for UTC time zone
|
||||||
|
datestamp=`date -u`
|
||||||
|
|
||||||
|
# Replace version number in header file:
|
||||||
|
sed -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'"/g' \
|
||||||
|
-e 's/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x'$numeric'/g' \
|
||||||
|
-e 's/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR '$major'/g' \
|
||||||
|
-e 's/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR '$minor'/g' \
|
||||||
|
-e 's/^#define LIBSSH2_VERSION_PATCH .*/#define LIBSSH2_VERSION_PATCH '$patch'/g' \
|
||||||
|
-e "s/^#define LIBSSH2_TIMESTAMP .*/#define LIBSSH2_TIMESTAMP \"$datestamp\"/g" \
|
||||||
|
$HEADER >$HEADER.dist
|
||||||
|
|
||||||
|
echo "libssh2 version $libversion"
|
||||||
|
echo "libssh2 numerical $numeric"
|
||||||
|
echo "datestamp $datestamp"
|
||||||
|
|
||||||
|
findprog()
|
||||||
|
{
|
||||||
|
file="$1"
|
||||||
|
for part in `echo $PATH| tr ':' ' '`; do
|
||||||
|
path="$part/$file"
|
||||||
|
if [ -x "$path" ]; then
|
||||||
|
# there it is!
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# no such executable
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
#
|
||||||
|
# automake is needed to run to make a non-GNU Makefile.in if Makefile.am has
|
||||||
|
# been modified.
|
||||||
|
#
|
||||||
|
|
||||||
|
if { findprog automake >/dev/null 2>/dev/null; } then
|
||||||
|
echo "- Could not find or run automake, I hope you know what you're doing!"
|
||||||
|
else
|
||||||
|
echo "Runs automake --include-deps"
|
||||||
|
automake --include-deps Makefile >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
#
|
||||||
|
# Now run make dist to generate a tar.gz archive
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "make dist"
|
||||||
|
targz="libssh2-$version.tar.gz"
|
||||||
|
make -s dist VERSION=$version
|
@@ -5,7 +5,7 @@
|
|||||||
##
|
##
|
||||||
## Comments to: Guenter Knauf <eflash@gmx.net>
|
## Comments to: Guenter Knauf <eflash@gmx.net>
|
||||||
##
|
##
|
||||||
## $Id: Makefile.netware,v 1.9 2007/06/20 23:44:58 gknauf Exp $
|
## $Id: Makefile.netware,v 1.12 2007/07/22 00:47:21 gknauf Exp $
|
||||||
#
|
#
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ TARGET = libssh2
|
|||||||
VERSION = $(LIBSSH2_VERSION)
|
VERSION = $(LIBSSH2_VERSION)
|
||||||
COPYR = Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
|
COPYR = Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
|
||||||
WWWURL = http://www.libssh2.org/
|
WWWURL = http://www.libssh2.org/
|
||||||
DESCR = libssh2 $(LIBSSH2_VERSION_STR) - $(WWWURL)
|
DESCR = libssh2 $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL)
|
||||||
MTSAFE = YES
|
MTSAFE = YES
|
||||||
STACK = 64000
|
STACK = 64000
|
||||||
SCREEN = none
|
SCREEN = none
|
||||||
@@ -67,11 +67,13 @@ else
|
|||||||
OBJDIR = debug
|
OBJDIR = debug
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Include the version info retrieved from libssh2.h
|
# The following lines defines your compiler.
|
||||||
-include $(OBJDIR)/version.inc
|
ifdef CWFolder
|
||||||
|
METROWERKS = $(CWFolder)
|
||||||
# The following line defines your compiler.
|
endif
|
||||||
ifdef METROWERKS
|
ifdef METROWERKS
|
||||||
|
# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support
|
||||||
|
MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support
|
||||||
CC = mwccnlm
|
CC = mwccnlm
|
||||||
else
|
else
|
||||||
CC = gcc
|
CC = gcc
|
||||||
@@ -87,8 +89,15 @@ AWK = awk
|
|||||||
MPKXDC = mkxdc
|
MPKXDC = mkxdc
|
||||||
ZIP = zip -qzr9
|
ZIP = zip -qzr9
|
||||||
|
|
||||||
|
# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH))
|
||||||
|
LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH))
|
||||||
|
|
||||||
|
# Include the version info retrieved from libssh2.h
|
||||||
|
-include $(OBJDIR)/version.inc
|
||||||
|
|
||||||
# Global flags for all compilers
|
# Global flags for all compilers
|
||||||
CFLAGS = $(OPT) -D$(DB) -DNETWARE -nostdinc # -DHAVE_CONFIG_H
|
CFLAGS = $(OPT) -D$(DB) -DNETWARE -nostdinc
|
||||||
|
#CFLAGS += -DHAVE_CONFIG_H
|
||||||
|
|
||||||
ifeq ($(CC),mwccnlm)
|
ifeq ($(CC),mwccnlm)
|
||||||
LD = mwldnlm
|
LD = mwldnlm
|
||||||
@@ -103,8 +112,10 @@ ifeq ($(LIBARCH),LIBC)
|
|||||||
PRELUDE = $(SDK_LIBC)/imports/libcpre.o
|
PRELUDE = $(SDK_LIBC)/imports/libcpre.o
|
||||||
CFLAGS += -align 4
|
CFLAGS += -align 4
|
||||||
else
|
else
|
||||||
PRELUDE = "$(METROWERKS)/Novell Support/libraries/runtime/prelude.obj"
|
# PRELUDE = $(SDK_CLIB)/imports/clibpre.o
|
||||||
# CFLAGS += -include "$(METROWERKS)/Novell Support/headers/nlm_prefix.h"
|
# to avoid the __init_* / __deinit_* whoes dont use prelude from NDK
|
||||||
|
PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj"
|
||||||
|
# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h"
|
||||||
CFLAGS += -align 1
|
CFLAGS += -align 1
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@@ -120,7 +131,10 @@ CFLAGS += -Wall # -pedantic
|
|||||||
ifeq ($(LIBARCH),LIBC)
|
ifeq ($(LIBARCH),LIBC)
|
||||||
PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o
|
PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o
|
||||||
else
|
else
|
||||||
PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o
|
# PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o
|
||||||
|
# to avoid the __init_* / __deinit_* whoes dont use prelude from NDK
|
||||||
|
# http://www.gknw.net/development/mk_nlm/gcc_pre.zip
|
||||||
|
PRELUDE = $(NDK_ROOT)/pre/prelude.o
|
||||||
CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h
|
CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -130,34 +144,33 @@ LDLIBS =
|
|||||||
NDK_ROOT = $(NDKBASE)/ndk
|
NDK_ROOT = $(NDKBASE)/ndk
|
||||||
SDK_CLIB = $(NDK_ROOT)/nwsdk
|
SDK_CLIB = $(NDK_ROOT)/nwsdk
|
||||||
SDK_LIBC = $(NDK_ROOT)/libc
|
SDK_LIBC = $(NDK_ROOT)/libc
|
||||||
SDK_LDAP = $(NDK_ROOT)/cldapsdk/netware
|
SNPRINTF = $(NDKBASE)/snprintf
|
||||||
|
|
||||||
INCLUDES = -I. -I../include
|
INCLUDES = -I. -I../include
|
||||||
|
|
||||||
ifdef WITH_ZLIB
|
ifdef WITH_ZLIB
|
||||||
INCLUDES += -I$(ZLIB_PATH)
|
INCLUDES += -I$(ZLIB_PATH)
|
||||||
ifdef LINK_STATIC
|
ifdef LINK_STATIC
|
||||||
LDLIBS += $(ZLIB_PATH)/nw/libz.$(LIBEXT)
|
LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT)
|
||||||
else
|
else
|
||||||
MODULES += libz.nlm
|
MODULES += libz.nlm
|
||||||
IMPORTS += @$(ZLIB_PATH)/nw/libz.imp
|
IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_libc -I$(OPENSSL_PATH)/outinc_nw_libc/openssl
|
INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L)/openssl
|
||||||
LDLIBS += $(OPENSSL_PATH)/out_nw_libc/ssl.$(LIBEXT) $(OPENSSL_PATH)/out_nw_libc/crypto.$(LIBEXT)
|
LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT)
|
||||||
|
LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT)
|
||||||
IMPORTS += GetProcessSwitchCount RunningProcess
|
IMPORTS += GetProcessSwitchCount RunningProcess
|
||||||
|
|
||||||
ifeq ($(LIBARCH),LIBC)
|
ifeq ($(LIBARCH),LIBC)
|
||||||
INCLUDES += -I$(SDK_LIBC)/include -I$(SDK_LIBC)/include/nks
|
INCLUDES += -I$(SDK_LIBC)/include
|
||||||
|
# INCLUDES += -I$(SDK_LIBC)/include/nks
|
||||||
# INCLUDES += -I$(SDK_LIBC)/include/winsock
|
# INCLUDES += -I$(SDK_LIBC)/include/winsock
|
||||||
# INCLUDES += -I$(SDK_LDAP)/libc/inc
|
|
||||||
CFLAGS += -D_POSIX_SOURCE
|
CFLAGS += -D_POSIX_SOURCE
|
||||||
# CFLAGS += -D__ANSIC__
|
|
||||||
else
|
else
|
||||||
INCLUDES += -I$(SDK_CLIB)/include/nlm -I$(SDK_CLIB)/include
|
INCLUDES += -I$(SDK_CLIB)/include/nlm
|
||||||
# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete
|
# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete
|
||||||
# INCLUDES += -I$(SDK_LDAP)/clib/inc
|
# INCLUDES += -I$(SDK_CLIB)/include
|
||||||
CFLAGS += -DNETDB_USE_INTERNET
|
|
||||||
endif
|
endif
|
||||||
CFLAGS += $(INCLUDES)
|
CFLAGS += $(INCLUDES)
|
||||||
|
|
||||||
@@ -199,8 +212,16 @@ OBJECTS = \
|
|||||||
transport.o \
|
transport.o \
|
||||||
userauth.o
|
userauth.o
|
||||||
|
|
||||||
|
ifeq ($(LIBARCH),CLIB)
|
||||||
|
# CLIB lacks of snprint() function - here's a replacement:
|
||||||
|
# http://www.ijs.si/software/snprintf/
|
||||||
|
OBJECTS += snprintf.o
|
||||||
|
vpath %.c $(SNPRINTF)
|
||||||
|
endif
|
||||||
|
|
||||||
OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS))
|
OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS))
|
||||||
OBJL = $(OBJS) $(OBJDIR)/nwlibc.o $(LDLIBS)
|
|
||||||
|
OBJL = $(OBJS) $(OBJDIR)/nwlib.o $(LDLIBS)
|
||||||
|
|
||||||
all: lib nlm
|
all: lib nlm
|
||||||
|
|
||||||
@@ -314,6 +335,7 @@ endif
|
|||||||
ifdef XDCDATA
|
ifdef XDCDATA
|
||||||
@echo $(DL)xdcdata $(XDCDATA)$(DL) >> $@
|
@echo $(DL)xdcdata $(XDCDATA)$(DL) >> $@
|
||||||
endif
|
endif
|
||||||
|
@echo $(DL)flag_on 64$(DL) >> $@
|
||||||
ifeq ($(LIBARCH),CLIB)
|
ifeq ($(LIBARCH),CLIB)
|
||||||
@echo $(DL)start _Prelude$(DL) >> $@
|
@echo $(DL)start _Prelude$(DL) >> $@
|
||||||
@echo $(DL)exit _Stop$(DL) >> $@
|
@echo $(DL)exit _Stop$(DL) >> $@
|
||||||
@@ -323,7 +345,6 @@ ifeq ($(LIBARCH),CLIB)
|
|||||||
@echo $(DL)import @$(SDK_CLIB)/imports/socklib.imp$(DL) >> $@
|
@echo $(DL)import @$(SDK_CLIB)/imports/socklib.imp$(DL) >> $@
|
||||||
@echo $(DL)module clib$(DL) >> $@
|
@echo $(DL)module clib$(DL) >> $@
|
||||||
else
|
else
|
||||||
@echo $(DL)flag_on 64$(DL) >> $@
|
|
||||||
@echo $(DL)pseudopreemption$(DL) >> $@
|
@echo $(DL)pseudopreemption$(DL) >> $@
|
||||||
@echo $(DL)start _LibCPrelude$(DL) >> $@
|
@echo $(DL)start _LibCPrelude$(DL) >> $@
|
||||||
@echo $(DL)exit _LibCPostlude$(DL) >> $@
|
@echo $(DL)exit _LibCPostlude$(DL) >> $@
|
||||||
@@ -353,62 +374,83 @@ libssh2_config.h: Makefile.netware
|
|||||||
@echo $(DL)** Do not edit this file - it is created by make!$(DL) >> $@
|
@echo $(DL)** Do not edit this file - it is created by make!$(DL) >> $@
|
||||||
@echo $(DL)** All your changes will be lost!!$(DL) >> $@
|
@echo $(DL)** All your changes will be lost!!$(DL) >> $@
|
||||||
@echo $(DL)*/$(DL) >> $@
|
@echo $(DL)*/$(DL) >> $@
|
||||||
@echo $(DL)#define OS "i586-pc-NetWare"$(DL) >> $@
|
|
||||||
@echo $(DL)#define VERSION "$(LIBSSH2_VERSION_STR)"$(DL) >> $@
|
@echo $(DL)#define VERSION "$(LIBSSH2_VERSION_STR)"$(DL) >> $@
|
||||||
@echo $(DL)#define PACKAGE_BUGREPORT "http://sourceforge.net/projects/libssh2"$(DL) >> $@
|
@echo $(DL)#define PACKAGE_BUGREPORT "http://sourceforge.net/projects/libssh2"$(DL) >> $@
|
||||||
|
ifeq ($(LIBARCH),CLIB)
|
||||||
|
@echo $(DL)#define OS "i586-pc-clib-NetWare"$(DL) >> $@
|
||||||
|
@echo $(DL)#define NETDB_USE_INTERNET 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRICMP 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define socklen_t int$(DL) >> $@
|
||||||
|
@echo $(DL)#define sleep(s) delay(1000 * s)$(DL) >> $@
|
||||||
|
else
|
||||||
|
@echo $(DL)#define OS "i586-pc-libc-NetWare"$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_DLFCN_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_DLOPEN 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_FTRUNCATE 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_GETTIMEOFDAY 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_INET_PTON 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_INTTYPES_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_LIMITS_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_LONGLONG 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STDINT_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRCASECMP 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRLCAT 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRLCPY 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRTOLL 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_SYS_PARAM_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_SYS_SELECT_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_TERMIOS_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_AF_INET6 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_PF_INET6 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRUCT_IN6_ADDR 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_STRUCT_SOCKADDR_IN6 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define SIZEOF_STRUCT_IN6_ADDR 16$(DL) >> $@
|
||||||
|
ifdef ENABLE_IPV6
|
||||||
|
@echo $(DL)#define ENABLE_IPV6 1$(DL) >> $@
|
||||||
|
endif
|
||||||
|
endif
|
||||||
@echo $(DL)#define HAVE_ARPA_INET_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_ARPA_INET_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_ASSERT_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_ASSERT_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_CTYPE_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_CTYPE_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_DLFCN_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_DLOPEN 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_ERR_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_ERR_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_ERRNO_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_ERRNO_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_FCNTL_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_FCNTL_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_FIONBIO 1$(DL) >> $@
|
@echo $(DL)#define HAVE_FIONBIO 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_GETHOSTBYADDR 1$(DL) >> $@
|
@echo $(DL)#define HAVE_GETHOSTBYADDR 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_GETTIMEOFDAY 1$(DL) >> $@
|
@echo $(DL)#define HAVE_GETHOSTBYNAME 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_GETPROTOBYNAME 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_GMTIME_R 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_INET_ADDR 1$(DL) >> $@
|
@echo $(DL)#define HAVE_INET_ADDR 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_INET_NTOA 1$(DL) >> $@
|
@echo $(DL)#define HAVE_INET_NTOA 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_INET_PTON 1$(DL) >> $@
|
@echo $(DL)#define HAVE_LL 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_INTTYPES_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_LOCALTIME_R 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_LIMITS_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_LONGLONG 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_MALLOC_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_MALLOC_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_MATH_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_NETINET_IN_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_NETINET_IN_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SELECT 1$(DL) >> $@
|
@echo $(DL)#define HAVE_SELECT 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SETJMP_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_SETJMP_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SIGNAL 1$(DL) >> $@
|
@echo $(DL)#define HAVE_SIGNAL 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_SIGNAL_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_SIG_ATOMIC_T 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SOCKET 1$(DL) >> $@
|
@echo $(DL)#define HAVE_SOCKET 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_STDARG_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STDDEF_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STDINT_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STDLIB_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STDLIB_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_STRCASECMP 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STRDUP 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STRDUP 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_STRFTIME 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STRFTIME 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_STRING_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STRING_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_STRLCAT 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STRLCPY 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STRSTR 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STRSTR 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SYS_PARAM_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STRUCT_ADDRINFO 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SYS_SELECT_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_STRUCT_TIMEVAL 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_SYS_IOCTL_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SYS_STAT_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_SYS_STAT_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_SYS_TIME_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_SYS_TIME_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_TERMIOS_H 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_TIME_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_TIME_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_UNAME 1$(DL) >> $@
|
@echo $(DL)#define HAVE_UNAME 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_UNISTD_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_UNISTD_H 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_UTIME 1$(DL) >> $@
|
||||||
|
@echo $(DL)#define HAVE_UTIME_H 1$(DL) >> $@
|
||||||
@echo $(DL)#define RETSIGTYPE void$(DL) >> $@
|
@echo $(DL)#define RETSIGTYPE void$(DL) >> $@
|
||||||
|
@echo $(DL)#define SIZEOF_STRUCT_IN_ADDR 4$(DL) >> $@
|
||||||
@echo $(DL)#define STDC_HEADERS 1$(DL) >> $@
|
@echo $(DL)#define STDC_HEADERS 1$(DL) >> $@
|
||||||
@echo $(DL)#define TIME_WITH_SYS_TIME 1$(DL) >> $@
|
@echo $(DL)#define TIME_WITH_SYS_TIME 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_AF_INET6 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_PF_INET6 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STRUCT_IN6_ADDR 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STRUCT_SOCKADDR_IN6 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define HAVE_STRUCT_ADDRINFO 1$(DL) >> $@
|
|
||||||
@echo $(DL)#define SIZEOF_STRUCT_IN6_ADDR 16$(DL) >> $@
|
|
||||||
@echo $(DL)#define SIZEOF_STRUCT_IN_ADDR 4$(DL) >> $@
|
|
||||||
@echo $(DL)#define USE_SSLEAY 1$(DL) >> $@
|
@echo $(DL)#define USE_SSLEAY 1$(DL) >> $@
|
||||||
@echo $(DL)#define USE_OPENSSL 1$(DL) >> $@
|
@echo $(DL)#define USE_OPENSSL 1$(DL) >> $@
|
||||||
@echo $(DL)#define HAVE_OPENSSL_X509_H 1$(DL) >> $@
|
@echo $(DL)#define HAVE_OPENSSL_X509_H 1$(DL) >> $@
|
||||||
@@ -427,9 +469,6 @@ ifdef WITH_ZLIB
|
|||||||
@echo $(DL)#define HAVE_LIBZ 1$(DL) >> $@
|
@echo $(DL)#define HAVE_LIBZ 1$(DL) >> $@
|
||||||
@echo $(DL)#define LIBSSH2_HAVE_ZLIB 1$(DL) >> $@
|
@echo $(DL)#define LIBSSH2_HAVE_ZLIB 1$(DL) >> $@
|
||||||
endif
|
endif
|
||||||
ifdef ENABLE_IPV6
|
|
||||||
@echo $(DL)#define ENABLE_IPV6 1$(DL) >> $@
|
|
||||||
endif
|
|
||||||
ifdef NW_WINSOCK
|
ifdef NW_WINSOCK
|
||||||
@echo $(DL)#define HAVE_CLOSESOCKET 1$(DL) >> $@
|
@echo $(DL)#define HAVE_CLOSESOCKET 1$(DL) >> $@
|
||||||
else
|
else
|
||||||
@@ -458,7 +497,11 @@ libssh2.imp: Makefile.netware
|
|||||||
@echo $(DL)# $@ for NetWare target.$(DL) > $@
|
@echo $(DL)# $@ for NetWare target.$(DL) > $@
|
||||||
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
|
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
|
||||||
@echo $(DL)# All your changes will be lost!!$(DL) >> $@
|
@echo $(DL)# All your changes will be lost!!$(DL) >> $@
|
||||||
@echo $(DL) (LIBSSH2)$(DL) >> $@
|
ifeq ($(LIBARCH),CLIB)
|
||||||
|
@echo $(DL) (CLIB_LIBSSH2)$(DL) >> $@
|
||||||
|
else
|
||||||
|
@echo $(DL) (LIBC_LIBSSH2)$(DL) >> $@
|
||||||
|
endif
|
||||||
@echo $(DL) libssh2_banner_set,$(DL) >> $@
|
@echo $(DL) libssh2_banner_set,$(DL) >> $@
|
||||||
@echo $(DL) libssh2_channel_close,$(DL) >> $@
|
@echo $(DL) libssh2_channel_close,$(DL) >> $@
|
||||||
@echo $(DL) libssh2_channel_direct_tcpip_ex,$(DL) >> $@
|
@echo $(DL) libssh2_channel_direct_tcpip_ex,$(DL) >> $@
|
||||||
@@ -531,7 +574,11 @@ $(DEVLDIR)/readme.txt: Makefile.netware
|
|||||||
|
|
||||||
help: $(OBJDIR)/version.inc
|
help: $(OBJDIR)/version.inc
|
||||||
@echo $(DL)===========================================================$(DL)
|
@echo $(DL)===========================================================$(DL)
|
||||||
|
ifeq ($(LIBARCH),LIBC)
|
||||||
@echo $(DL)Novell LibC NDK = $(SDK_LIBC)$(DL)
|
@echo $(DL)Novell LibC NDK = $(SDK_LIBC)$(DL)
|
||||||
|
else
|
||||||
|
@echo $(DL)Novell CLib NDK = $(SDK_CLIB)$(DL)
|
||||||
|
endif
|
||||||
@echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL)
|
@echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL)
|
||||||
@echo $(DL)Zlib path = $(ZLIB_PATH)$(DL)
|
@echo $(DL)Zlib path = $(ZLIB_PATH)$(DL)
|
||||||
@echo $(DL)===========================================================$(DL)
|
@echo $(DL)===========================================================$(DL)
|
||||||
|
306
nw/nwlib.c
Normal file
306
nw/nwlib.c
Normal file
@@ -0,0 +1,306 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* Universal NetWare library stub. *
|
||||||
|
* written by Ulrich Neuman and given to OpenSource copyright-free. *
|
||||||
|
* Extended for CLIB support by Guenter Knauf. *
|
||||||
|
*********************************************************************
|
||||||
|
* $Id: nwlib.c,v 1.1 2007/07/09 22:50:02 gknauf Exp $ *
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
|
#ifdef NETWARE /* Novell NetWare */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef __NOVELL_LIBC__
|
||||||
|
/* For native LibC-based NLM we need to register as a real lib. */
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <library.h>
|
||||||
|
#include <netware.h>
|
||||||
|
#include <screen.h>
|
||||||
|
#include <nks/thread.h>
|
||||||
|
#include <nks/synch.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int _errno;
|
||||||
|
void *twentybytes;
|
||||||
|
} libthreaddata_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
void *tenbytes;
|
||||||
|
NXKey_t perthreadkey; /* if -1, no key obtained... */
|
||||||
|
NXMutex_t *lock;
|
||||||
|
} libdata_t;
|
||||||
|
|
||||||
|
int gLibId = -1;
|
||||||
|
void *gLibHandle = (void *) NULL;
|
||||||
|
rtag_t gAllocTag = (rtag_t) NULL;
|
||||||
|
NXMutex_t *gLibLock = (NXMutex_t *) NULL;
|
||||||
|
|
||||||
|
/* internal library function prototypes... */
|
||||||
|
int DisposeLibraryData ( void * );
|
||||||
|
void DisposeThreadData ( void * );
|
||||||
|
int GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata );
|
||||||
|
|
||||||
|
|
||||||
|
int _NonAppStart( void *NLMHandle,
|
||||||
|
void *errorScreen,
|
||||||
|
const char *cmdLine,
|
||||||
|
const char *loadDirPath,
|
||||||
|
size_t uninitializedDataLength,
|
||||||
|
void *NLMFileHandle,
|
||||||
|
int (*readRoutineP)( int conn,
|
||||||
|
void *fileHandle, size_t offset,
|
||||||
|
size_t nbytes,
|
||||||
|
size_t *bytesRead,
|
||||||
|
void *buffer ),
|
||||||
|
size_t customDataOffset,
|
||||||
|
size_t customDataSize,
|
||||||
|
int messageCount,
|
||||||
|
const char **messages )
|
||||||
|
{
|
||||||
|
NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
|
||||||
|
|
||||||
|
#ifndef __GNUC__
|
||||||
|
#pragma unused(cmdLine)
|
||||||
|
#pragma unused(loadDirPath)
|
||||||
|
#pragma unused(uninitializedDataLength)
|
||||||
|
#pragma unused(NLMFileHandle)
|
||||||
|
#pragma unused(readRoutineP)
|
||||||
|
#pragma unused(customDataOffset)
|
||||||
|
#pragma unused(customDataSize)
|
||||||
|
#pragma unused(messageCount)
|
||||||
|
#pragma unused(messages)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Here we process our command line, post errors (to the error screen),
|
||||||
|
** perform initializations and anything else we need to do before being able
|
||||||
|
** to accept calls into us. If we succeed, we return non-zero and the NetWare
|
||||||
|
** Loader will leave us up, otherwise we fail to load and get dumped.
|
||||||
|
*/
|
||||||
|
gAllocTag = AllocateResourceTag(NLMHandle,
|
||||||
|
"<library-name> memory allocations", AllocSignature);
|
||||||
|
|
||||||
|
if (!gAllocTag) {
|
||||||
|
OutputToScreen(errorScreen, "Unable to allocate resource tag for "
|
||||||
|
"library memory allocations.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gLibId = register_library(DisposeLibraryData);
|
||||||
|
|
||||||
|
if (gLibId < -1) {
|
||||||
|
OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gLibHandle = NLMHandle;
|
||||||
|
|
||||||
|
gLibLock = NXMutexAlloc(0, 0, &liblock);
|
||||||
|
|
||||||
|
if (!gLibLock) {
|
||||||
|
OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Here we clean up any resources we allocated. Resource tags is a big part
|
||||||
|
** of what we created, but NetWare doesn't ask us to free those.
|
||||||
|
*/
|
||||||
|
void _NonAppStop( void )
|
||||||
|
{
|
||||||
|
(void) unregister_library(gLibId);
|
||||||
|
NXMutexFree(gLibLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** This function cannot be the first in the file for if the file is linked
|
||||||
|
** first, then the check-unload function's offset will be nlmname.nlm+0
|
||||||
|
** which is how to tell that there isn't one. When the check function is
|
||||||
|
** first in the linked objects, it is ambiguous. For this reason, we will
|
||||||
|
** put it inside this file after the stop function.
|
||||||
|
**
|
||||||
|
** Here we check to see if it's alright to ourselves to be unloaded. If not,
|
||||||
|
** we return a non-zero value. Right now, there isn't any reason not to allow
|
||||||
|
** it.
|
||||||
|
*/
|
||||||
|
int _NonAppCheckUnload( void )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetOrSetUpData(int id, libdata_t **appData, libthreaddata_t **threadData)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
libdata_t *app_data;
|
||||||
|
libthreaddata_t *thread_data;
|
||||||
|
NXKey_t key;
|
||||||
|
NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
thread_data = (libthreaddata_t *) NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Attempt to get our data for the application calling us. This is where we
|
||||||
|
** store whatever application-specific information we need to carry in support
|
||||||
|
** of calling applications.
|
||||||
|
*/
|
||||||
|
app_data = (libdata_t *) get_app_data(id);
|
||||||
|
|
||||||
|
if (!app_data) {
|
||||||
|
/*
|
||||||
|
** This application hasn't called us before; set up application AND per-thread
|
||||||
|
** data. Of course, just in case a thread from this same application is calling
|
||||||
|
** us simultaneously, we better lock our application data-creation mutex. We
|
||||||
|
** also need to recheck for data after we acquire the lock because WE might be
|
||||||
|
** that other thread that was too late to create the data and the first thread
|
||||||
|
** in will have created it.
|
||||||
|
*/
|
||||||
|
NXLock(gLibLock);
|
||||||
|
|
||||||
|
if (!(app_data = (libdata_t *) get_app_data(id))) {
|
||||||
|
app_data = (libdata_t *) malloc(sizeof(libdata_t));
|
||||||
|
|
||||||
|
if (app_data) {
|
||||||
|
memset(app_data, 0, sizeof(libdata_t));
|
||||||
|
|
||||||
|
app_data->tenbytes = malloc(10);
|
||||||
|
app_data->lock = NXMutexAlloc(0, 0, &liblock);
|
||||||
|
|
||||||
|
if (!app_data->tenbytes || !app_data->lock) {
|
||||||
|
if (app_data->lock)
|
||||||
|
NXMutexFree(app_data->lock);
|
||||||
|
|
||||||
|
free(app_data);
|
||||||
|
app_data = (libdata_t *) NULL;
|
||||||
|
err = ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app_data) {
|
||||||
|
/*
|
||||||
|
** Here we burn in the application data that we were trying to get by calling
|
||||||
|
** get_app_data(). Next time we call the first function, we'll get this data
|
||||||
|
** we're just now setting. We also go on here to establish the per-thread data
|
||||||
|
** for the calling thread, something we'll have to do on each application
|
||||||
|
** thread the first time it calls us.
|
||||||
|
*/
|
||||||
|
err = set_app_data(gLibId, app_data);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
free(app_data);
|
||||||
|
app_data = (libdata_t *) NULL;
|
||||||
|
err = ENOMEM;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* create key for thread-specific data... */
|
||||||
|
err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
|
||||||
|
|
||||||
|
if (err) /* (no more keys left?) */
|
||||||
|
key = -1;
|
||||||
|
|
||||||
|
app_data->perthreadkey = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NXUnlock(gLibLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app_data) {
|
||||||
|
key = app_data->perthreadkey;
|
||||||
|
|
||||||
|
if (key != -1 /* couldn't create a key? no thread data */
|
||||||
|
&& !(err = NXKeyGetValue(key, (void **) &thread_data))
|
||||||
|
&& !thread_data) {
|
||||||
|
/*
|
||||||
|
** Allocate the per-thread data for the calling thread. Regardless of whether
|
||||||
|
** there was already application data or not, this may be the first call by a
|
||||||
|
** a new thread. The fact that we allocation 20 bytes on a pointer is not very
|
||||||
|
** important, this just helps to demonstrate that we can have arbitrarily
|
||||||
|
** complex per-thread data.
|
||||||
|
*/
|
||||||
|
thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
|
||||||
|
|
||||||
|
if (thread_data) {
|
||||||
|
thread_data->_errno = 0;
|
||||||
|
thread_data->twentybytes = malloc(20);
|
||||||
|
|
||||||
|
if (!thread_data->twentybytes) {
|
||||||
|
free(thread_data);
|
||||||
|
thread_data = (libthreaddata_t *) NULL;
|
||||||
|
err = ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((err = NXKeySetValue(key, thread_data))) {
|
||||||
|
free(thread_data->twentybytes);
|
||||||
|
free(thread_data);
|
||||||
|
thread_data = (libthreaddata_t *) NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appData)
|
||||||
|
*appData = app_data;
|
||||||
|
|
||||||
|
if (threadData)
|
||||||
|
*threadData = thread_data;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DisposeLibraryData( void *data )
|
||||||
|
{
|
||||||
|
if (data) {
|
||||||
|
void *tenbytes = ((libdata_t *) data)->tenbytes;
|
||||||
|
|
||||||
|
if (tenbytes)
|
||||||
|
free(tenbytes);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisposeThreadData( void *data )
|
||||||
|
{
|
||||||
|
if (data) {
|
||||||
|
void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
|
||||||
|
|
||||||
|
if (twentybytes)
|
||||||
|
free(twentybytes);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* __NOVELL_LIBC__ */
|
||||||
|
/* For native CLib-based NLM seems we can do a bit more simple. */
|
||||||
|
#include <nwthread.h>
|
||||||
|
|
||||||
|
int main ( void )
|
||||||
|
{
|
||||||
|
/* initialize any globals here... */
|
||||||
|
|
||||||
|
/* do this if any global initializing was done
|
||||||
|
SynchronizeStart();
|
||||||
|
*/
|
||||||
|
ExitThread (TSR_THREAD, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __NOVELL_LIBC__ */
|
||||||
|
|
||||||
|
#endif /* NETWARE */
|
||||||
|
|
||||||
|
|
309
nw/nwlibc.c
309
nw/nwlibc.c
@@ -1,309 +0,0 @@
|
|||||||
/*********************************************************************
|
|
||||||
* Universal NetWare library stub. *
|
|
||||||
* written by Ulrich Neuman and given to OpenSource copyright-free. *
|
|
||||||
* version: 1.0 *
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <library.h>
|
|
||||||
#include <netware.h>
|
|
||||||
#include <screen.h>
|
|
||||||
#include <nks/thread.h>
|
|
||||||
#include <nks/synch.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int _errno;
|
|
||||||
void *twentybytes;
|
|
||||||
} libthreaddata_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int z;
|
|
||||||
void *tenbytes;
|
|
||||||
NXKey_t perthreadkey; /* if -1, no key obtained... */
|
|
||||||
NXMutex_t *lock;
|
|
||||||
} libdata_t;
|
|
||||||
|
|
||||||
int gLibId = -1;
|
|
||||||
void *gLibHandle = (void *) NULL;
|
|
||||||
rtag_t gAllocTag = (rtag_t) NULL;
|
|
||||||
NXMutex_t *gLibLock = (NXMutex_t *) NULL;
|
|
||||||
|
|
||||||
/* internal library function prototypes... */
|
|
||||||
int DisposeLibraryData ( void * );
|
|
||||||
void DisposeThreadData ( void * );
|
|
||||||
int GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata );
|
|
||||||
|
|
||||||
|
|
||||||
int _NonAppStart
|
|
||||||
(
|
|
||||||
void *NLMHandle,
|
|
||||||
void *errorScreen,
|
|
||||||
const char *cmdLine,
|
|
||||||
const char *loadDirPath,
|
|
||||||
size_t uninitializedDataLength,
|
|
||||||
void *NLMFileHandle,
|
|
||||||
int (*readRoutineP)( int conn, void *fileHandle, size_t offset,
|
|
||||||
size_t nbytes, size_t *bytesRead, void *buffer ),
|
|
||||||
size_t customDataOffset,
|
|
||||||
size_t customDataSize,
|
|
||||||
int messageCount,
|
|
||||||
const char **messages
|
|
||||||
)
|
|
||||||
{
|
|
||||||
NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
|
|
||||||
|
|
||||||
#ifndef __GNUC__
|
|
||||||
#pragma unused(cmdLine)
|
|
||||||
#pragma unused(loadDirPath)
|
|
||||||
#pragma unused(uninitializedDataLength)
|
|
||||||
#pragma unused(NLMFileHandle)
|
|
||||||
#pragma unused(readRoutineP)
|
|
||||||
#pragma unused(customDataOffset)
|
|
||||||
#pragma unused(customDataSize)
|
|
||||||
#pragma unused(messageCount)
|
|
||||||
#pragma unused(messages)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Here we process our command line, post errors (to the error screen),
|
|
||||||
** perform initializations and anything else we need to do before being able
|
|
||||||
** to accept calls into us. If we succeed, we return non-zero and the NetWare
|
|
||||||
** Loader will leave us up, otherwise we fail to load and get dumped.
|
|
||||||
*/
|
|
||||||
gAllocTag = AllocateResourceTag(NLMHandle,
|
|
||||||
"<library-name> memory allocations", AllocSignature);
|
|
||||||
|
|
||||||
if (!gAllocTag)
|
|
||||||
{
|
|
||||||
OutputToScreen(errorScreen, "Unable to allocate resource tag for "
|
|
||||||
"library memory allocations.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gLibId = register_library(DisposeLibraryData);
|
|
||||||
|
|
||||||
if (gLibId < -1)
|
|
||||||
{
|
|
||||||
OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gLibHandle = NLMHandle;
|
|
||||||
|
|
||||||
gLibLock = NXMutexAlloc(0, 0, &liblock);
|
|
||||||
|
|
||||||
if (!gLibLock)
|
|
||||||
{
|
|
||||||
OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Here we clean up any resources we allocated. Resource tags is a big part
|
|
||||||
** of what we created, but NetWare doesn't ask us to free those.
|
|
||||||
*/
|
|
||||||
void _NonAppStop( void )
|
|
||||||
{
|
|
||||||
(void) unregister_library(gLibId);
|
|
||||||
NXMutexFree(gLibLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** This function cannot be the first in the file for if the file is linked
|
|
||||||
** first, then the check-unload function's offset will be nlmname.nlm+0
|
|
||||||
** which is how to tell that there isn't one. When the check function is
|
|
||||||
** first in the linked objects, it is ambiguous. For this reason, we will
|
|
||||||
** put it inside this file after the stop function.
|
|
||||||
**
|
|
||||||
** Here we check to see if it's alright to ourselves to be unloaded. If not,
|
|
||||||
** we return a non-zero value. Right now, there isn't any reason not to allow
|
|
||||||
** it.
|
|
||||||
*/
|
|
||||||
int _NonAppCheckUnload( void )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetOrSetUpData
|
|
||||||
(
|
|
||||||
int id,
|
|
||||||
libdata_t **appData,
|
|
||||||
libthreaddata_t **threadData
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
libdata_t *app_data;
|
|
||||||
libthreaddata_t *thread_data;
|
|
||||||
NXKey_t key;
|
|
||||||
NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
|
|
||||||
|
|
||||||
err = 0;
|
|
||||||
thread_data = (libthreaddata_t *) NULL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Attempt to get our data for the application calling us. This is where we
|
|
||||||
** store whatever application-specific information we need to carry in support
|
|
||||||
** of calling applications.
|
|
||||||
*/
|
|
||||||
app_data = (libdata_t *) get_app_data(id);
|
|
||||||
|
|
||||||
if (!app_data)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
** This application hasn't called us before; set up application AND per-thread
|
|
||||||
** data. Of course, just in case a thread from this same application is calling
|
|
||||||
** us simultaneously, we better lock our application data-creation mutex. We
|
|
||||||
** also need to recheck for data after we acquire the lock because WE might be
|
|
||||||
** that other thread that was too late to create the data and the first thread
|
|
||||||
** in will have created it.
|
|
||||||
*/
|
|
||||||
NXLock(gLibLock);
|
|
||||||
|
|
||||||
if (!(app_data = (libdata_t *) get_app_data(id)))
|
|
||||||
{
|
|
||||||
app_data = (libdata_t *) malloc(sizeof(libdata_t));
|
|
||||||
|
|
||||||
if (app_data)
|
|
||||||
{
|
|
||||||
memset(app_data, 0, sizeof(libdata_t));
|
|
||||||
|
|
||||||
app_data->tenbytes = malloc(10);
|
|
||||||
app_data->lock = NXMutexAlloc(0, 0, &liblock);
|
|
||||||
|
|
||||||
if (!app_data->tenbytes || !app_data->lock)
|
|
||||||
{
|
|
||||||
if (app_data->lock)
|
|
||||||
NXMutexFree(app_data->lock);
|
|
||||||
|
|
||||||
free(app_data);
|
|
||||||
app_data = (libdata_t *) NULL;
|
|
||||||
err = ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app_data)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
** Here we burn in the application data that we were trying to get by calling
|
|
||||||
** get_app_data(). Next time we call the first function, we'll get this data
|
|
||||||
** we're just now setting. We also go on here to establish the per-thread data
|
|
||||||
** for the calling thread, something we'll have to do on each application
|
|
||||||
** thread the first time it calls us.
|
|
||||||
*/
|
|
||||||
err = set_app_data(gLibId, app_data);
|
|
||||||
|
|
||||||
if (err)
|
|
||||||
{
|
|
||||||
free(app_data);
|
|
||||||
app_data = (libdata_t *) NULL;
|
|
||||||
err = ENOMEM;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* create key for thread-specific data... */
|
|
||||||
err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
|
|
||||||
|
|
||||||
if (err) /* (no more keys left?) */
|
|
||||||
key = -1;
|
|
||||||
|
|
||||||
app_data->perthreadkey = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NXUnlock(gLibLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app_data)
|
|
||||||
{
|
|
||||||
key = app_data->perthreadkey;
|
|
||||||
|
|
||||||
if ( key != -1 /* couldn't create a key? no thread data */
|
|
||||||
&& !(err = NXKeyGetValue(key, (void **) &thread_data))
|
|
||||||
&& !thread_data)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
** Allocate the per-thread data for the calling thread. Regardless of whether
|
|
||||||
** there was already application data or not, this may be the first call by a
|
|
||||||
** a new thread. The fact that we allocation 20 bytes on a pointer is not very
|
|
||||||
** important, this just helps to demonstrate that we can have arbitrarily
|
|
||||||
** complex per-thread data.
|
|
||||||
*/
|
|
||||||
thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
|
|
||||||
|
|
||||||
if (thread_data)
|
|
||||||
{
|
|
||||||
thread_data->_errno = 0;
|
|
||||||
thread_data->twentybytes = malloc(20);
|
|
||||||
|
|
||||||
if (!thread_data->twentybytes)
|
|
||||||
{
|
|
||||||
free(thread_data);
|
|
||||||
thread_data = (libthreaddata_t *) NULL;
|
|
||||||
err = ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = NXKeySetValue(key, thread_data)))
|
|
||||||
{
|
|
||||||
free(thread_data->twentybytes);
|
|
||||||
free(thread_data);
|
|
||||||
thread_data = (libthreaddata_t *) NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appData)
|
|
||||||
*appData = app_data;
|
|
||||||
|
|
||||||
if (threadData)
|
|
||||||
*threadData = thread_data;
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DisposeLibraryData
|
|
||||||
(
|
|
||||||
void *data
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
void *tenbytes = ((libdata_t *) data)->tenbytes;
|
|
||||||
|
|
||||||
if (tenbytes)
|
|
||||||
free(tenbytes);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DisposeThreadData
|
|
||||||
(
|
|
||||||
void *data
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
|
|
||||||
|
|
||||||
if (twentybytes)
|
|
||||||
free(twentybytes);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@@ -5,7 +5,7 @@
|
|||||||
##
|
##
|
||||||
## Comments to: Guenter Knauf <eflash@gmx.net>
|
## Comments to: Guenter Knauf <eflash@gmx.net>
|
||||||
##
|
##
|
||||||
## $Id: Makefile.netware,v 1.5 2007/04/21 21:26:54 gknauf Exp $
|
## $Id: Makefile.netware,v 1.7 2007/07/15 20:34:33 gknauf Exp $
|
||||||
#
|
#
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
@@ -28,17 +28,18 @@ endif
|
|||||||
LINK_STATIC = 1
|
LINK_STATIC = 1
|
||||||
|
|
||||||
# Edit the vars below to change NLM target settings.
|
# Edit the vars below to change NLM target settings.
|
||||||
TARGETS = scp.nlm sftp.nlm sftpdir.nlm ssh2.nlm
|
SAMPLES = ../../example/simple
|
||||||
|
TARGETS := $(patsubst $(SAMPLES)/%.c,%.nlm,$(strip $(wildcard $(SAMPLES)/*.c)))
|
||||||
VERSION = $(LIBSSH2_VERSION)
|
VERSION = $(LIBSSH2_VERSION)
|
||||||
COPYR = Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
|
COPYR = Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
|
||||||
WWWURL = http://www.libssh2.org/
|
WWWURL = http://www.libssh2.org/
|
||||||
DESCR = libssh2 $(notdir $(@:.def=)) $(LIBSSH2_VERSION_STR) - $(WWWURL)
|
DESCR = libssh2 $(notdir $(@:.def=)) $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL)
|
||||||
MTSAFE = YES
|
MTSAFE = YES
|
||||||
STACK = 64000
|
STACK = 64000
|
||||||
SCREEN = NONE
|
SCREEN = NONE
|
||||||
#SCREEN = libssh2 $(notdir $(@:.def=))
|
#SCREEN = libssh2 $(notdir $(@:.def=))
|
||||||
# Comment the line below if you dont want to load protected automatically.
|
# Comment the line below if you dont want to load protected automatically.
|
||||||
LDRING = 3
|
#LDRING = 3
|
||||||
|
|
||||||
# Edit the var below to point to your lib architecture.
|
# Edit the var below to point to your lib architecture.
|
||||||
ifndef LIBARCH
|
ifndef LIBARCH
|
||||||
@@ -56,14 +57,17 @@ ifeq ($(DB),NDEBUG)
|
|||||||
OBJDIR = release
|
OBJDIR = release
|
||||||
else
|
else
|
||||||
OPT = -g
|
OPT = -g
|
||||||
|
OPT += -DLIBSSH2DEBUG
|
||||||
OBJDIR = debug
|
OBJDIR = debug
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Include the version info retrieved from xml2ver.h
|
# The following lines defines your compiler.
|
||||||
-include $(OBJDIR)/version.inc
|
ifdef CWFolder
|
||||||
|
METROWERKS = $(CWFolder)
|
||||||
# The following line defines your compiler.
|
endif
|
||||||
ifdef METROWERKS
|
ifdef METROWERKS
|
||||||
|
# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support
|
||||||
|
MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support
|
||||||
CC = mwccnlm
|
CC = mwccnlm
|
||||||
else
|
else
|
||||||
CC = gcc
|
CC = gcc
|
||||||
@@ -78,8 +82,14 @@ AWK = awk
|
|||||||
# http://www.gknw.net/development/prgtools/mkxdc.zip
|
# http://www.gknw.net/development/prgtools/mkxdc.zip
|
||||||
MPKXDC = mkxdc
|
MPKXDC = mkxdc
|
||||||
|
|
||||||
|
# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH))
|
||||||
|
LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH))
|
||||||
|
|
||||||
|
# Include the version info retrieved from libssh2.h
|
||||||
|
-include $(OBJDIR)/version.inc
|
||||||
|
|
||||||
# Global flags for all compilers
|
# Global flags for all compilers
|
||||||
CFLAGS = $(OPT) -D$(DB) -DNETWARE -nostdinc # -DHAVE_CONFIG_H
|
CFLAGS = $(OPT) -D$(DB) -DNETWARE -nostdinc
|
||||||
|
|
||||||
ifeq ($(CC),mwccnlm)
|
ifeq ($(CC),mwccnlm)
|
||||||
LD = mwldnlm
|
LD = mwldnlm
|
||||||
@@ -94,8 +104,10 @@ ifeq ($(LIBARCH),LIBC)
|
|||||||
PRELUDE = $(SDK_LIBC)/imports/libcpre.o
|
PRELUDE = $(SDK_LIBC)/imports/libcpre.o
|
||||||
CFLAGS += -align 4
|
CFLAGS += -align 4
|
||||||
else
|
else
|
||||||
PRELUDE = "$(METROWERKS)/Novell Support/libraries/runtime/prelude.obj"
|
# PRELUDE = $(SDK_CLIB)/imports/clibpre.o
|
||||||
# CFLAGS += -include "$(METROWERKS)/Novell Support/headers/nlm_prefix.h"
|
# to avoid the __init_* / __deinit_* whoes dont use prelude from NDK
|
||||||
|
PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj"
|
||||||
|
# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h"
|
||||||
CFLAGS += -align 1
|
CFLAGS += -align 1
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@@ -117,16 +129,27 @@ endif
|
|||||||
NDK_ROOT = $(NDKBASE)/ndk
|
NDK_ROOT = $(NDKBASE)/ndk
|
||||||
SDK_CLIB = $(NDK_ROOT)/nwsdk
|
SDK_CLIB = $(NDK_ROOT)/nwsdk
|
||||||
SDK_LIBC = $(NDK_ROOT)/libc
|
SDK_LIBC = $(NDK_ROOT)/libc
|
||||||
SDK_LDAP = $(NDK_ROOT)/cldapsdk/netware
|
SNPRINTF = $(NDKBASE)/snprintf
|
||||||
|
|
||||||
INCLUDES = -I. -I.. -I../../include
|
INCLUDES = -I.. -I../../include
|
||||||
|
|
||||||
LDLIBS =
|
LDLIBS =
|
||||||
|
|
||||||
INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_libc -I$(OPENSSL_PATH)/outinc_nw_libc/openssl
|
INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L)/openssl
|
||||||
LDLIBS += $(OPENSSL_PATH)/out_nw_libc/ssl.$(LIBEXT) $(OPENSSL_PATH)/out_nw_libc/crypto.$(LIBEXT)
|
LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT)
|
||||||
|
LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT)
|
||||||
IMPORTS += GetProcessSwitchCount RunningProcess
|
IMPORTS += GetProcessSwitchCount RunningProcess
|
||||||
|
|
||||||
|
ifdef WITH_ZLIB
|
||||||
|
INCLUDES += -I$(ZLIB_PATH)
|
||||||
|
ifdef LINK_STATIC
|
||||||
|
LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT)
|
||||||
|
else
|
||||||
|
MODULES += libz.nlm
|
||||||
|
IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef LINK_STATIC
|
ifdef LINK_STATIC
|
||||||
LDLIBS += ../libssh2.$(LIBEXT)
|
LDLIBS += ../libssh2.$(LIBEXT)
|
||||||
else
|
else
|
||||||
@@ -134,27 +157,16 @@ else
|
|||||||
MODULES += libssh2.nlm
|
MODULES += libssh2.nlm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef WITH_ZLIB
|
|
||||||
INCLUDES += -I$(ZLIB_PATH)
|
|
||||||
ifdef LINK_STATIC
|
|
||||||
LDLIBS += $(ZLIB_PATH)/nw/libz.$(LIBEXT)
|
|
||||||
else
|
|
||||||
IMPORTS += @$(ZLIB_PATH)/nw/libz.imp
|
|
||||||
MODULES += libz.nlm
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(LIBARCH),LIBC)
|
ifeq ($(LIBARCH),LIBC)
|
||||||
INCLUDES += -I$(SDK_LIBC)/include -I$(SDK_LIBC)/include/nks
|
INCLUDES += -I$(SDK_LIBC)/include
|
||||||
|
# INCLUDES += -I$(SDK_LIBC)/include/nks
|
||||||
# INCLUDES += -I$(SDK_LIBC)/include/winsock
|
# INCLUDES += -I$(SDK_LIBC)/include/winsock
|
||||||
# INCLUDES += -I$(SDK_LDAP)/libc/inc
|
|
||||||
CFLAGS += -D_POSIX_SOURCE
|
CFLAGS += -D_POSIX_SOURCE
|
||||||
# CFLAGS += -D__ANSIC__
|
|
||||||
else
|
else
|
||||||
INCLUDES += -I$(SDK_CLIB)/include/nlm -I$(SDK_CLIB)/include
|
INCLUDES += -I$(SDK_CLIB)/include/nlm
|
||||||
# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete
|
# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete
|
||||||
# INCLUDES += -I$(SDK_LDAP)/clib/inc
|
# INCLUDES += -I$(SDK_CLIB)/include
|
||||||
CFLAGS += -DNETDB_USE_INTERNET
|
# CFLAGS += -DNETDB_USE_INTERNET
|
||||||
endif
|
endif
|
||||||
CFLAGS += $(INCLUDES)
|
CFLAGS += $(INCLUDES)
|
||||||
|
|
||||||
@@ -167,10 +179,9 @@ endif
|
|||||||
|
|
||||||
ifeq ($(findstring linux,$(OSTYPE)),linux)
|
ifeq ($(findstring linux,$(OSTYPE)),linux)
|
||||||
DL = '
|
DL = '
|
||||||
#-include $(NDKBASE)/nlmconv/ncpfs.inc
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
vpath %.c ../../example/simple
|
vpath %.c $(SAMPLES)
|
||||||
|
|
||||||
.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.def $(OBJDIR)/%.xdc
|
.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.def $(OBJDIR)/%.xdc
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# $Id: Makefile.am,v 1.9 2007/04/05 10:23:55 jas4711 Exp $
|
# $Id: Makefile.am,v 1.10 2007/07/17 13:22:55 gknauf Exp $
|
||||||
AUTOMAKE_OPTIONS = foreign nostdinc
|
AUTOMAKE_OPTIONS = foreign nostdinc
|
||||||
|
|
||||||
libssh2_la_SOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c \
|
libssh2_la_SOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c \
|
||||||
@@ -11,7 +11,7 @@ else
|
|||||||
libssh2_la_SOURCES += openssl.c
|
libssh2_la_SOURCES += openssl.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
EXTRA_DIST = libssh2_config.h.in
|
EXTRA_DIST = libssh2_config.h.in NMakefile
|
||||||
|
|
||||||
lib_LTLIBRARIES = libssh2.la
|
lib_LTLIBRARIES = libssh2.la
|
||||||
|
|
||||||
|
@@ -2,10 +2,23 @@
|
|||||||
|
|
||||||
CFLAGS=$(CFLAGS)
|
CFLAGS=$(CFLAGS)
|
||||||
|
|
||||||
OBJECTS = $(INTDIR)\channel.obj $(INTDIR)\comp.obj $(INTDIR)\crypt.obj \
|
OBJECTS = \
|
||||||
$(INTDIR)\hostkey.obj $(INTDIR)\kex.obj $(INTDIR)\mac.obj \
|
$(INTDIR)\channel.obj \
|
||||||
$(INTDIR)\misc.obj $(INTDIR)\packet.obj $(INTDIR)\scp.obj \
|
$(INTDIR)\comp.obj \
|
||||||
$(INTDIR)\session.obj $(INTDIR)\sftp.obj $(INTDIR)\userauth.obj
|
$(INTDIR)\crypt.obj \
|
||||||
|
$(INTDIR)\hostkey.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
|
||||||
|
|
||||||
DLL=libssh2$(SUFFIX).dll
|
DLL=libssh2$(SUFFIX).dll
|
||||||
|
|
||||||
|
932
src/channel.c
932
src/channel.c
File diff suppressed because it is too large
Load Diff
74
src/comp.c
74
src/comp.c
@@ -47,15 +47,15 @@
|
|||||||
/* {{{ libssh2_comp_method_none_comp
|
/* {{{ libssh2_comp_method_none_comp
|
||||||
* Minimalist compression: Absolutely none
|
* Minimalist compression: Absolutely none
|
||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_none_comp(LIBSSH2_SESSION *session,
|
static int
|
||||||
|
libssh2_comp_method_none_comp(LIBSSH2_SESSION * session,
|
||||||
int compress,
|
int compress,
|
||||||
unsigned char **dest,
|
unsigned char **dest,
|
||||||
unsigned long *dest_len,
|
unsigned long *dest_len,
|
||||||
unsigned long payload_limit,
|
unsigned long payload_limit,
|
||||||
int *free_dest,
|
int *free_dest,
|
||||||
const unsigned char *src,
|
const unsigned char *src,
|
||||||
unsigned long src_len,
|
unsigned long src_len, void **abstract)
|
||||||
void **abstract)
|
|
||||||
{
|
{
|
||||||
(void) session;
|
(void) session;
|
||||||
(void) compress;
|
(void) compress;
|
||||||
@@ -68,6 +68,7 @@ static int libssh2_comp_method_none_comp(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
|
static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
|
||||||
@@ -87,32 +88,39 @@ static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
|
|||||||
* Deal...
|
* Deal...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static voidpf libssh2_comp_method_zlib_alloc(voidpf opaque, uInt items, uInt size)
|
static voidpf
|
||||||
|
libssh2_comp_method_zlib_alloc(voidpf opaque, uInt items, uInt size)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = (LIBSSH2_SESSION *) opaque;
|
LIBSSH2_SESSION *session = (LIBSSH2_SESSION *) opaque;
|
||||||
|
|
||||||
return (voidpf) LIBSSH2_ALLOC(session, items * size);
|
return (voidpf) LIBSSH2_ALLOC(session, items * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void libssh2_comp_method_zlib_free(voidpf opaque, voidpf address)
|
static void
|
||||||
|
libssh2_comp_method_zlib_free(voidpf opaque, voidpf address)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = (LIBSSH2_SESSION *) opaque;
|
LIBSSH2_SESSION *session = (LIBSSH2_SESSION *) opaque;
|
||||||
|
|
||||||
LIBSSH2_FREE(session, address);
|
LIBSSH2_FREE(session, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_comp_method_zlib_init
|
/* {{{ libssh2_comp_method_zlib_init
|
||||||
* All your bandwidth are belong to us (so save some)
|
* All your bandwidth are belong to us (so save some)
|
||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_zlib_init(LIBSSH2_SESSION *session, int compress, void **abstract)
|
static int
|
||||||
|
libssh2_comp_method_zlib_init(LIBSSH2_SESSION * session, int compress,
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
z_stream *strm;
|
z_stream *strm;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
strm = LIBSSH2_ALLOC(session, sizeof(z_stream));
|
strm = LIBSSH2_ALLOC(session, sizeof(z_stream));
|
||||||
if (!strm) {
|
if (!strm) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for zlib compression/decompression", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for zlib compression/decompression",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(strm, 0, sizeof(z_stream));
|
memset(strm, 0, sizeof(z_stream));
|
||||||
@@ -136,20 +144,21 @@ static int libssh2_comp_method_zlib_init(LIBSSH2_SESSION *session, int compress,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_comp_method_zlib_comp
|
/* {{{ libssh2_comp_method_zlib_comp
|
||||||
* zlib, a compression standard for all occasions
|
* zlib, a compression standard for all occasions
|
||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
static int
|
||||||
|
libssh2_comp_method_zlib_comp(LIBSSH2_SESSION * session,
|
||||||
int compress,
|
int compress,
|
||||||
unsigned char **dest,
|
unsigned char **dest,
|
||||||
unsigned long *dest_len,
|
unsigned long *dest_len,
|
||||||
unsigned long payload_limit,
|
unsigned long payload_limit,
|
||||||
int *free_dest,
|
int *free_dest,
|
||||||
const unsigned char *src,
|
const unsigned char *src,
|
||||||
unsigned long src_len,
|
unsigned long src_len, void **abstract)
|
||||||
void **abstract)
|
|
||||||
{
|
{
|
||||||
z_stream *strm = *abstract;
|
z_stream *strm = *abstract;
|
||||||
/* A short-term alloc of a full data chunk is better than a series of
|
/* A short-term alloc of a full data chunk is better than a series of
|
||||||
@@ -173,7 +182,9 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
out = (char *) strm->next_out;
|
out = (char *) strm->next_out;
|
||||||
strm->avail_out = out_maxlen;
|
strm->avail_out = out_maxlen;
|
||||||
if (!strm->next_out) {
|
if (!strm->next_out) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate compression/decompression buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate compression/decompression buffer",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (strm->avail_in) {
|
while (strm->avail_in) {
|
||||||
@@ -185,7 +196,8 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
status = inflate(strm, Z_PARTIAL_FLUSH);
|
status = inflate(strm, Z_PARTIAL_FLUSH);
|
||||||
}
|
}
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compress/decompression failure", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||||
|
"compress/decompression failure", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -193,10 +205,10 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
unsigned long out_ofs = out_maxlen - strm->avail_out;
|
unsigned long out_ofs = out_maxlen - strm->avail_out;
|
||||||
char *newout;
|
char *newout;
|
||||||
|
|
||||||
out_maxlen += compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
out_maxlen +=
|
||||||
|
compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
||||||
|
|
||||||
if ((out_maxlen > (int)payload_limit) &&
|
if ((out_maxlen > (int) payload_limit) && !compress && limiter++) {
|
||||||
!compress && limiter++) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||||
"Excessive growth in decompression phase", 0);
|
"Excessive growth in decompression phase", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
@@ -205,14 +217,18 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
||||||
if (!newout) {
|
if (!newout) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to expand compress/decompression buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to expand compress/decompression buffer",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
out = newout;
|
out = newout;
|
||||||
strm->next_out = (unsigned char *) out + out_ofs;
|
strm->next_out = (unsigned char *) out + out_ofs;
|
||||||
strm->avail_out += compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
strm->avail_out +=
|
||||||
} else while (!strm->avail_out) {
|
compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
||||||
|
} else
|
||||||
|
while (!strm->avail_out) {
|
||||||
/* Done with input, might be a byte or two in internal buffer during compress
|
/* Done with input, might be a byte or two in internal buffer during compress
|
||||||
* Or potentially many bytes if it's a decompress
|
* Or potentially many bytes if it's a decompress
|
||||||
*/
|
*/
|
||||||
@@ -220,7 +236,9 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
char *newout;
|
char *newout;
|
||||||
|
|
||||||
if (out_maxlen >= (int) payload_limit) {
|
if (out_maxlen >= (int) payload_limit) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "Excessive growth in decompression phase", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||||
|
"Excessive growth in decompression phase",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -234,7 +252,9 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
||||||
if (!newout) {
|
if (!newout) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to expand final compress/decompress buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to expand final compress/decompress buffer",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -248,7 +268,8 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
status = inflate(strm, Z_PARTIAL_FLUSH);
|
status = inflate(strm, Z_PARTIAL_FLUSH);
|
||||||
}
|
}
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compress/decompression failure", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||||
|
"compress/decompression failure", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -261,12 +282,15 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_comp_method_zlib_dtor
|
/* {{{ libssh2_comp_method_zlib_dtor
|
||||||
* All done, no more compression for you
|
* All done, no more compression for you
|
||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_zlib_dtor(LIBSSH2_SESSION *session, int compress, void **abstract)
|
static int
|
||||||
|
libssh2_comp_method_zlib_dtor(LIBSSH2_SESSION * session, int compress,
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
z_stream *strm = *abstract;
|
z_stream *strm = *abstract;
|
||||||
|
|
||||||
@@ -286,6 +310,7 @@ static int libssh2_comp_method_zlib_dtor(LIBSSH2_SESSION *session, int compress,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_COMP_METHOD libssh2_comp_method_zlib = {
|
static const LIBSSH2_COMP_METHOD libssh2_comp_method_zlib = {
|
||||||
@@ -308,7 +333,8 @@ static const LIBSSH2_COMP_METHOD *_libssh2_comp_methods[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIBSSH2_COMP_METHOD **libssh2_comp_methods(void) {
|
const LIBSSH2_COMP_METHOD **
|
||||||
|
libssh2_comp_methods(void)
|
||||||
|
{
|
||||||
return _libssh2_comp_methods;
|
return _libssh2_comp_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
src/crypt.c
31
src/crypt.c
@@ -41,11 +41,14 @@
|
|||||||
/* {{{ libssh2_crypt_none_crypt
|
/* {{{ libssh2_crypt_none_crypt
|
||||||
* Minimalist cipher: VERY secure *wink*
|
* Minimalist cipher: VERY secure *wink*
|
||||||
*/
|
*/
|
||||||
static int libssh2_crypt_none_crypt(LIBSSH2_SESSION *session, unsigned char *buf, void **abstract)
|
static int
|
||||||
|
libssh2_crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf,
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
/* Do nothing to the data! */
|
/* Do nothing to the data! */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
|
||||||
@@ -60,13 +63,15 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
|
|||||||
};
|
};
|
||||||
#endif /* LIBSSH2_CRYPT_NONE */
|
#endif /* LIBSSH2_CRYPT_NONE */
|
||||||
|
|
||||||
struct crypt_ctx {
|
struct crypt_ctx
|
||||||
|
{
|
||||||
int encrypt;
|
int encrypt;
|
||||||
_libssh2_cipher_type(algo);
|
_libssh2_cipher_type(algo);
|
||||||
_libssh2_cipher_ctx h;
|
_libssh2_cipher_ctx h;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int _libssh2_init (LIBSSH2_SESSION *session,
|
static int
|
||||||
|
_libssh2_init(LIBSSH2_SESSION * session,
|
||||||
const LIBSSH2_CRYPT_METHOD * method,
|
const LIBSSH2_CRYPT_METHOD * method,
|
||||||
unsigned char *iv, int *free_iv,
|
unsigned char *iv, int *free_iv,
|
||||||
unsigned char *secret, int *free_secret,
|
unsigned char *secret, int *free_secret,
|
||||||
@@ -79,8 +84,7 @@ static int _libssh2_init (LIBSSH2_SESSION *session,
|
|||||||
}
|
}
|
||||||
ctx->encrypt = encrypt;
|
ctx->encrypt = encrypt;
|
||||||
ctx->algo = method->algo;
|
ctx->algo = method->algo;
|
||||||
if (_libssh2_cipher_init (&ctx->h, ctx->algo, iv, secret, encrypt))
|
if (_libssh2_cipher_init(&ctx->h, ctx->algo, iv, secret, encrypt)) {
|
||||||
{
|
|
||||||
LIBSSH2_FREE(session, ctx);
|
LIBSSH2_FREE(session, ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -90,15 +94,17 @@ static int _libssh2_init (LIBSSH2_SESSION *session,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _libssh2_encrypt(LIBSSH2_SESSION *session, unsigned char *block, void **abstract)
|
static int
|
||||||
|
_libssh2_encrypt(LIBSSH2_SESSION * session, unsigned char *block,
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
struct crypt_ctx *cctx = *(struct crypt_ctx **) abstract;
|
struct crypt_ctx *cctx = *(struct crypt_ctx **) abstract;
|
||||||
(void) session;
|
(void) session;
|
||||||
return _libssh2_cipher_crypt(&cctx->h, cctx->algo,
|
return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block);
|
||||||
cctx->encrypt, block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _libssh2_dtor(LIBSSH2_SESSION *session, void **abstract)
|
static int
|
||||||
|
_libssh2_dtor(LIBSSH2_SESSION * session, void **abstract)
|
||||||
{
|
{
|
||||||
struct crypt_ctx **cctx = (struct crypt_ctx **) abstract;
|
struct crypt_ctx **cctx = (struct crypt_ctx **) abstract;
|
||||||
if (cctx && *cctx) {
|
if (cctx && *cctx) {
|
||||||
@@ -147,7 +153,8 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes256_cbc = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* rijndael-cbc@lysator.liu.se == aes256-cbc */
|
/* rijndael-cbc@lysator.liu.se == aes256-cbc */
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_rijndael_cbc_lysator_liu_se = {
|
static const LIBSSH2_CRYPT_METHOD
|
||||||
|
libssh2_crypt_method_rijndael_cbc_lysator_liu_se = {
|
||||||
"rijndael-cbc@lysator.liu.se",
|
"rijndael-cbc@lysator.liu.se",
|
||||||
16, /* blocksize */
|
16, /* blocksize */
|
||||||
16, /* initial value length */
|
16, /* initial value length */
|
||||||
@@ -242,6 +249,8 @@ static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Expose to kex.c */
|
/* Expose to kex.c */
|
||||||
const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void) {
|
const LIBSSH2_CRYPT_METHOD **
|
||||||
|
libssh2_crypt_methods(void)
|
||||||
|
{
|
||||||
return _libssh2_crypt_methods;
|
return _libssh2_crypt_methods;
|
||||||
}
|
}
|
||||||
|
130
src/hostkey.c
130
src/hostkey.c
@@ -47,7 +47,8 @@
|
|||||||
* ssh-rsa *
|
* ssh-rsa *
|
||||||
*********** */
|
*********** */
|
||||||
|
|
||||||
static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session, void **abstract);
|
static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session,
|
||||||
|
void **abstract);
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_rsa_init
|
/* {{{ libssh2_hostkey_method_ssh_rsa_init
|
||||||
* Initialize the server hostkey working area with e/n pair
|
* Initialize the server hostkey working area with e/n pair
|
||||||
@@ -81,9 +82,12 @@ libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
|||||||
e_len = libssh2_ntohu32(s);
|
e_len = libssh2_ntohu32(s);
|
||||||
s += 4;
|
s += 4;
|
||||||
|
|
||||||
e = s; s += e_len;
|
e = s;
|
||||||
n_len = libssh2_ntohu32(s); s += 4;
|
s += e_len;
|
||||||
n = s; s += n_len;
|
n_len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
n = s;
|
||||||
|
s += n_len;
|
||||||
|
|
||||||
if (_libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0,
|
if (_libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0,
|
||||||
NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0))
|
NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0))
|
||||||
@@ -93,13 +97,17 @@ libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_rsa_initPEM
|
/* {{{ libssh2_hostkey_method_ssh_rsa_initPEM
|
||||||
* Load a Private Key from a PEM file
|
* Load a Private Key from a PEM file
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
static int
|
||||||
const char *privkeyfile, unsigned const char *passphrase, void **abstract)
|
libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION * session,
|
||||||
|
const char *privkeyfile,
|
||||||
|
unsigned const char *passphrase,
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx;
|
libssh2_rsa_ctx *rsactx;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@@ -125,32 +133,40 @@ static int libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_rsa_sign
|
/* {{{ libssh2_hostkey_method_ssh_rsa_sign
|
||||||
* Verify signature created by remote
|
* Verify signature created by remote
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION *session,
|
static int
|
||||||
|
libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len,
|
unsigned long m_len, void **abstract)
|
||||||
void **abstract)
|
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
|
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
|
||||||
(void) session;
|
(void) session;
|
||||||
|
|
||||||
/* Skip past keyname_len(4) + keyname(7){"ssh-rsa"} + signature_len(4) */
|
/* Skip past keyname_len(4) + keyname(7){"ssh-rsa"} + signature_len(4) */
|
||||||
sig += 15; sig_len -= 15;
|
sig += 15;
|
||||||
|
sig_len -= 15;
|
||||||
return _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len);
|
return _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_rsa_signv
|
/* {{{ libssh2_hostkey_method_ssh_rsa_signv
|
||||||
* Construct a signature from an array of vectors
|
* Construct a signature from an array of vectors
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len,
|
static int
|
||||||
unsigned long veccount, const struct iovec datavec[], void **abstract)
|
libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session,
|
||||||
|
unsigned char **signature,
|
||||||
|
unsigned long *signature_len,
|
||||||
|
unsigned long veccount,
|
||||||
|
const struct iovec datavec[],
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
|
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
|
||||||
int ret;
|
int ret;
|
||||||
@@ -172,13 +188,14 @@ static int libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION *session, unsign
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_rsa_dtor
|
/* {{{ libssh2_hostkey_method_ssh_rsa_dtor
|
||||||
* Shutdown the hostkey
|
* Shutdown the hostkey
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session,
|
static int
|
||||||
void **abstract)
|
libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
|
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
|
||||||
(void) session;
|
(void) session;
|
||||||
@@ -189,6 +206,7 @@ static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
|
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
|
||||||
@@ -208,7 +226,8 @@ static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
|
|||||||
* ssh-dss *
|
* ssh-dss *
|
||||||
*********** */
|
*********** */
|
||||||
|
|
||||||
static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session, void **abstract);
|
static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session,
|
||||||
|
void **abstract);
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_dss_init
|
/* {{{ libssh2_hostkey_method_ssh_dss_init
|
||||||
* Initialize the server hostkey working area with p/q/g/y set
|
* Initialize the server hostkey working area with p/q/g/y set
|
||||||
@@ -230,33 +249,44 @@ libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION *session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
s = hostkey_data;
|
s = hostkey_data;
|
||||||
len = libssh2_ntohu32(s); s += 4;
|
len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
if (len != 7 || strncmp((char *) s, "ssh-dss", 7) != 0) {
|
if (len != 7 || strncmp((char *) s, "ssh-dss", 7) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
} s += 7;
|
}
|
||||||
|
s += 7;
|
||||||
|
|
||||||
p_len = libssh2_ntohu32(s); s += 4;
|
p_len = libssh2_ntohu32(s);
|
||||||
p = s; s += p_len;
|
s += 4;
|
||||||
q_len = libssh2_ntohu32(s); s += 4;
|
p = s;
|
||||||
q = s; s += q_len;
|
s += p_len;
|
||||||
g_len = libssh2_ntohu32(s); s += 4;
|
q_len = libssh2_ntohu32(s);
|
||||||
g = s; s += g_len;
|
s += 4;
|
||||||
y_len = libssh2_ntohu32(s); s += 4;
|
q = s;
|
||||||
y = s; s += y_len;
|
s += q_len;
|
||||||
|
g_len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
g = s;
|
||||||
|
s += g_len;
|
||||||
|
y_len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
y = s;
|
||||||
|
s += y_len;
|
||||||
|
|
||||||
_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, g, g_len,
|
_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, g, g_len, y, y_len, NULL, 0);
|
||||||
y, y_len, NULL, 0);
|
|
||||||
|
|
||||||
*abstract = dsactx;
|
*abstract = dsactx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_dss_initPEM
|
/* {{{ libssh2_hostkey_method_ssh_dss_initPEM
|
||||||
* Load a Private Key from a PEM file
|
* Load a Private Key from a PEM file
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
static int
|
||||||
|
libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION * session,
|
||||||
const char *privkeyfile,
|
const char *privkeyfile,
|
||||||
unsigned const char *passphrase,
|
unsigned const char *passphrase,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
@@ -285,31 +315,44 @@ static int libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_dss_sign
|
/* {{{ libssh2_hostkey_method_ssh_dss_sign
|
||||||
* Verify signature created by remote
|
* Verify signature created by remote
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION *session, const unsigned char *sig, unsigned long sig_len,
|
static int
|
||||||
const unsigned char *m, unsigned long m_len, void **abstract)
|
libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
|
||||||
|
const unsigned char *sig,
|
||||||
|
unsigned long sig_len,
|
||||||
|
const unsigned char *m,
|
||||||
|
unsigned long m_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
|
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
|
||||||
|
|
||||||
/* Skip past keyname_len(4) + keyname(7){"ssh-dss"} + signature_len(4) */
|
/* Skip past keyname_len(4) + keyname(7){"ssh-dss"} + signature_len(4) */
|
||||||
sig += 15; sig_len -= 15;
|
sig += 15;
|
||||||
|
sig_len -= 15;
|
||||||
if (sig_len != 40) {
|
if (sig_len != 40) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Invalid DSS signature length", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
|
"Invalid DSS signature length", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
|
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_dss_signv
|
/* {{{ libssh2_hostkey_method_ssh_dss_signv
|
||||||
* Construct a signature from an array of vectors
|
* Construct a signature from an array of vectors
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len,
|
static int
|
||||||
unsigned long veccount, const struct iovec datavec[], void **abstract)
|
libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session,
|
||||||
|
unsigned char **signature,
|
||||||
|
unsigned long *signature_len,
|
||||||
|
unsigned long veccount,
|
||||||
|
const struct iovec datavec[],
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
|
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
@@ -330,22 +373,21 @@ static int libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session, unsign
|
|||||||
}
|
}
|
||||||
libssh2_sha1_final(ctx, hash);
|
libssh2_sha1_final(ctx, hash);
|
||||||
|
|
||||||
if (_libssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH,
|
if (_libssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH, *signature)) {
|
||||||
*signature))
|
|
||||||
{
|
|
||||||
LIBSSH2_FREE(session, *signature);
|
LIBSSH2_FREE(session, *signature);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_method_ssh_dss_dtor
|
/* {{{ libssh2_hostkey_method_ssh_dss_dtor
|
||||||
* Shutdown the hostkey method
|
* Shutdown the hostkey method
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session,
|
static int
|
||||||
void **abstract)
|
libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
|
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
|
||||||
(void) session;
|
(void) session;
|
||||||
@@ -356,6 +398,7 @@ static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_dss = {
|
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_dss = {
|
||||||
@@ -380,7 +423,8 @@ static const LIBSSH2_HOSTKEY_METHOD *_libssh2_hostkey_methods[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void)
|
const LIBSSH2_HOSTKEY_METHOD **
|
||||||
|
libssh2_hostkey_methods(void)
|
||||||
{
|
{
|
||||||
return _libssh2_hostkey_methods;
|
return _libssh2_hostkey_methods;
|
||||||
}
|
}
|
||||||
@@ -391,7 +435,8 @@ const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void)
|
|||||||
* Length of buffer is determined by hash type
|
* Length of buffer is determined by hash type
|
||||||
* i.e. MD5 == 16, SHA1 == 20
|
* i.e. MD5 == 16, SHA1 == 20
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type)
|
LIBSSH2_API const char *
|
||||||
|
libssh2_hostkey_hash(LIBSSH2_SESSION * session, int hash_type)
|
||||||
{
|
{
|
||||||
switch (hash_type) {
|
switch (hash_type) {
|
||||||
#if LIBSSH2_MD5
|
#if LIBSSH2_MD5
|
||||||
@@ -406,6 +451,5 @@ LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
|
@@ -38,7 +38,8 @@
|
|||||||
#include "libssh2_priv.h"
|
#include "libssh2_priv.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
int
|
||||||
|
_libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
|
||||||
const unsigned char *edata,
|
const unsigned char *edata,
|
||||||
unsigned long elen,
|
unsigned long elen,
|
||||||
const unsigned char *ndata,
|
const unsigned char *ndata,
|
||||||
@@ -53,8 +54,7 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata, unsigned long coefflen)
|
||||||
unsigned long coefflen)
|
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
(void) e1data;
|
(void) e1data;
|
||||||
@@ -72,8 +72,7 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
rc = gcry_sexp_build(rsa, NULL, "(public-key(rsa(n%b)(e%b)))",
|
rc = gcry_sexp_build(rsa, NULL, "(public-key(rsa(n%b)(e%b)))",
|
||||||
nlen, ndata, elen, edata);
|
nlen, ndata, elen, edata);
|
||||||
}
|
}
|
||||||
if (rc)
|
if (rc) {
|
||||||
{
|
|
||||||
*rsa = NULL;
|
*rsa = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -81,11 +80,11 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
int
|
||||||
|
_libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len)
|
||||||
unsigned long m_len)
|
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
gcry_sexp_t s_sig, s_hash;
|
gcry_sexp_t s_sig, s_hash;
|
||||||
@@ -100,8 +99,7 @@ int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_sexp_build (&s_sig, NULL, "(sig-val(rsa(s %b)))",
|
rc = gcry_sexp_build(&s_sig, NULL, "(sig-val(rsa(s %b)))", sig_len, sig);
|
||||||
sig_len, sig);
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
gcry_sexp_release(s_hash);
|
gcry_sexp_release(s_hash);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -114,7 +112,8 @@ int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
|||||||
return (rc == 0) ? 0 : -1;
|
return (rc == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
int
|
||||||
|
_libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
|
||||||
const unsigned char *p,
|
const unsigned char *p,
|
||||||
unsigned long p_len,
|
unsigned long p_len,
|
||||||
const unsigned char *q,
|
const unsigned char *q,
|
||||||
@@ -123,8 +122,7 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
|||||||
unsigned long g_len,
|
unsigned long g_len,
|
||||||
const unsigned char *y,
|
const unsigned char *y,
|
||||||
unsigned long y_len,
|
unsigned long y_len,
|
||||||
const unsigned char *x,
|
const unsigned char *x, unsigned long x_len)
|
||||||
unsigned long x_len)
|
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -147,10 +145,10 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
int
|
||||||
|
_libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase)
|
||||||
unsigned const char *passphrase)
|
|
||||||
{
|
{
|
||||||
char *data, *save_data;
|
char *data, *save_data;
|
||||||
unsigned int datalen;
|
unsigned int datalen;
|
||||||
@@ -230,8 +228,7 @@ int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_libssh2_rsa_new(rsa, e, elen, n, nlen, d, dlen, p, plen,
|
if (_libssh2_rsa_new(rsa, e, elen, n, nlen, d, dlen, p, plen,
|
||||||
q, qlen, e1, e1len, e2, e2len,
|
q, qlen, e1, e1len, e2, e2len, coeff, coefflen)) {
|
||||||
coeff, coefflen)) {
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -243,10 +240,10 @@ fail:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
int
|
||||||
|
_libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase)
|
||||||
unsigned const char *passphrase)
|
|
||||||
{
|
{
|
||||||
char *data, *save_data;
|
char *data, *save_data;
|
||||||
unsigned int datalen;
|
unsigned int datalen;
|
||||||
@@ -313,8 +310,7 @@ int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_libssh2_dsa_new (dsa, p, plen, q, qlen,
|
if (_libssh2_dsa_new(dsa, p, plen, q, qlen, g, glen, y, ylen, x, xlen)) {
|
||||||
g, glen, y, ylen, x, xlen)) {
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -326,12 +322,12 @@ fail:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
int
|
||||||
|
_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
||||||
libssh2_dsa_ctx * rsactx,
|
libssh2_dsa_ctx * rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char **signature,
|
unsigned char **signature, unsigned long *signature_len)
|
||||||
unsigned long *signature_len)
|
|
||||||
{
|
{
|
||||||
gcry_sexp_t sig_sexp;
|
gcry_sexp_t sig_sexp;
|
||||||
gcry_sexp_t data;
|
gcry_sexp_t data;
|
||||||
@@ -379,10 +375,10 @@ int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
int
|
||||||
|
_libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len, unsigned char *sig)
|
||||||
unsigned char *sig)
|
|
||||||
{
|
{
|
||||||
unsigned char zhash[SHA_DIGEST_LENGTH + 1];
|
unsigned char zhash[SHA_DIGEST_LENGTH + 1];
|
||||||
gcry_sexp_t sig_sexp;
|
gcry_sexp_t sig_sexp;
|
||||||
@@ -398,8 +394,7 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
|||||||
memcpy(zhash + 1, hash, hash_len);
|
memcpy(zhash + 1, hash, hash_len);
|
||||||
zhash[0] = 0;
|
zhash[0] = 0;
|
||||||
|
|
||||||
if (gcry_sexp_build (&data, NULL, "(data (value %b))",
|
if (gcry_sexp_build(&data, NULL, "(data (value %b))", hash_len + 1, zhash)) {
|
||||||
hash_len + 1, zhash)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,10 +471,10 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
int
|
||||||
|
_libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len)
|
||||||
unsigned long m_len)
|
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH + 1];
|
unsigned char hash[SHA_DIGEST_LENGTH + 1];
|
||||||
gcry_sexp_t s_sig, s_hash;
|
gcry_sexp_t s_sig, s_hash;
|
||||||
@@ -506,11 +501,10 @@ int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
|||||||
return (rc == 0) ? 0 : -1;
|
return (rc == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int
|
||||||
|
_libssh2_cipher_init(_libssh2_cipher_ctx * h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv, unsigned char *secret, int encrypt)
|
||||||
unsigned char *secret,
|
|
||||||
int encrypt)
|
|
||||||
{
|
{
|
||||||
int mode = 0, ret;
|
int mode = 0, ret;
|
||||||
int keylen = gcry_cipher_get_algo_keylen(algo);
|
int keylen = gcry_cipher_get_algo_keylen(algo);
|
||||||
@@ -544,10 +538,10 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
int
|
||||||
|
_libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt, unsigned char *block)
|
||||||
unsigned char *block)
|
|
||||||
{
|
{
|
||||||
size_t blklen = gcry_cipher_get_algo_blklen(algo);
|
size_t blklen = gcry_cipher_get_algo_blklen(algo);
|
||||||
int ret;
|
int ret;
|
||||||
@@ -557,11 +551,9 @@ int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (encrypt) {
|
if (encrypt) {
|
||||||
ret = gcry_cipher_encrypt (*ctx, block, blklen,
|
ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen);
|
||||||
block, blklen);
|
|
||||||
} else {
|
} else {
|
||||||
ret = gcry_cipher_decrypt (*ctx, block, blklen,
|
ret = gcry_cipher_decrypt(*ctx, block, blklen, block, blklen);
|
||||||
block, blklen);
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -108,17 +108,14 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata, unsigned long coefflen);
|
||||||
unsigned long coefflen);
|
|
||||||
int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase);
|
||||||
unsigned const char *passphrase);
|
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
|
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len);
|
||||||
unsigned long m_len);
|
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
||||||
libssh2_rsa_ctx * rsactx,
|
libssh2_rsa_ctx * rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
@@ -139,20 +136,16 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
|||||||
unsigned long glen,
|
unsigned long glen,
|
||||||
const unsigned char *ydata,
|
const unsigned char *ydata,
|
||||||
unsigned long ylen,
|
unsigned long ylen,
|
||||||
const unsigned char *x,
|
const unsigned char *x, unsigned long x_len);
|
||||||
unsigned long x_len);
|
|
||||||
int _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
int _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase);
|
||||||
unsigned const char *passphrase);
|
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsa,
|
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len);
|
||||||
unsigned long m_len);
|
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len, unsigned char *sig);
|
||||||
unsigned char *sig);
|
|
||||||
|
|
||||||
#define _libssh2_dsa_free(dsactx) gcry_sexp_release (dsactx)
|
#define _libssh2_dsa_free(dsactx) gcry_sexp_release (dsactx)
|
||||||
|
|
||||||
@@ -170,13 +163,11 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
|||||||
int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
|
int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv,
|
||||||
unsigned char *secret,
|
unsigned char *secret, int encrypt);
|
||||||
int encrypt);
|
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt, unsigned char *block);
|
||||||
unsigned char *block);
|
|
||||||
|
|
||||||
#define _libssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx))
|
#define _libssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx))
|
||||||
|
|
||||||
|
@@ -127,7 +127,8 @@ typedef struct _LIBSSH2_CHANNEL_BRIGADE LIBSSH2_CHANNEL_BRIGADE;
|
|||||||
|
|
||||||
typedef int libssh2pack_t;
|
typedef int libssh2pack_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
libssh2_NB_state_idle = 0,
|
libssh2_NB_state_idle = 0,
|
||||||
libssh2_NB_state_allocated,
|
libssh2_NB_state_allocated,
|
||||||
libssh2_NB_state_created,
|
libssh2_NB_state_created,
|
||||||
@@ -144,16 +145,19 @@ typedef enum {
|
|||||||
libssh2_NB_state_jump3
|
libssh2_NB_state_jump3
|
||||||
} libssh2_nonblocking_states;
|
} libssh2_nonblocking_states;
|
||||||
|
|
||||||
typedef struct packet_require_state_t {
|
typedef struct packet_require_state_t
|
||||||
|
{
|
||||||
libssh2_nonblocking_states state;
|
libssh2_nonblocking_states state;
|
||||||
time_t start;
|
time_t start;
|
||||||
} packet_require_state_t;
|
} packet_require_state_t;
|
||||||
|
|
||||||
typedef struct packet_requirev_state_t {
|
typedef struct packet_requirev_state_t
|
||||||
|
{
|
||||||
time_t start;
|
time_t start;
|
||||||
} packet_requirev_state_t;
|
} packet_requirev_state_t;
|
||||||
|
|
||||||
typedef struct kmdhgGPsha1kex_state_t {
|
typedef struct kmdhgGPsha1kex_state_t
|
||||||
|
{
|
||||||
libssh2_nonblocking_states state;
|
libssh2_nonblocking_states state;
|
||||||
unsigned char *e_packet;
|
unsigned char *e_packet;
|
||||||
unsigned char *s_packet;
|
unsigned char *s_packet;
|
||||||
@@ -180,7 +184,8 @@ typedef struct kmdhgGPsha1kex_state_t {
|
|||||||
libssh2_nonblocking_states burn_state;
|
libssh2_nonblocking_states burn_state;
|
||||||
} kmdhgGPsha1kex_state_t;
|
} kmdhgGPsha1kex_state_t;
|
||||||
|
|
||||||
typedef struct key_exchange_state_low_t {
|
typedef struct key_exchange_state_low_t
|
||||||
|
{
|
||||||
libssh2_nonblocking_states state;
|
libssh2_nonblocking_states state;
|
||||||
packet_require_state_t req_state;
|
packet_require_state_t req_state;
|
||||||
kmdhgGPsha1kex_state_t exchange_state;
|
kmdhgGPsha1kex_state_t exchange_state;
|
||||||
@@ -192,7 +197,8 @@ typedef struct key_exchange_state_low_t {
|
|||||||
unsigned long data_len;
|
unsigned long data_len;
|
||||||
} key_exchange_state_low_t;
|
} key_exchange_state_low_t;
|
||||||
|
|
||||||
typedef struct key_exchange_state_t {
|
typedef struct key_exchange_state_t
|
||||||
|
{
|
||||||
libssh2_nonblocking_states state;
|
libssh2_nonblocking_states state;
|
||||||
packet_require_state_t req_state;
|
packet_require_state_t req_state;
|
||||||
key_exchange_state_low_t key_state_low;
|
key_exchange_state_low_t key_state_low;
|
||||||
@@ -204,7 +210,8 @@ typedef struct key_exchange_state_t {
|
|||||||
|
|
||||||
#define FwdNotReq "Forward not requested"
|
#define FwdNotReq "Forward not requested"
|
||||||
|
|
||||||
typedef struct packet_queue_listener_state_t {
|
typedef struct packet_queue_listener_state_t
|
||||||
|
{
|
||||||
libssh2_nonblocking_states state;
|
libssh2_nonblocking_states state;
|
||||||
unsigned char packet[17 + (sizeof(FwdNotReq) - 1)];
|
unsigned char packet[17 + (sizeof(FwdNotReq) - 1)];
|
||||||
unsigned char *host;
|
unsigned char *host;
|
||||||
@@ -220,7 +227,8 @@ typedef struct packet_queue_listener_state_t {
|
|||||||
|
|
||||||
#define X11FwdUnAvil "X11 Forward Unavailable"
|
#define X11FwdUnAvil "X11 Forward Unavailable"
|
||||||
|
|
||||||
typedef struct packet_x11_open_state_t {
|
typedef struct packet_x11_open_state_t
|
||||||
|
{
|
||||||
libssh2_nonblocking_states state;
|
libssh2_nonblocking_states state;
|
||||||
unsigned char packet[17 + (sizeof(X11FwdUnAvil) - 1)];
|
unsigned char packet[17 + (sizeof(X11FwdUnAvil) - 1)];
|
||||||
unsigned char *shost;
|
unsigned char *shost;
|
||||||
@@ -231,7 +239,8 @@ typedef struct packet_x11_open_state_t {
|
|||||||
uint32_t shost_len;
|
uint32_t shost_len;
|
||||||
} packet_x11_open_state_t;
|
} packet_x11_open_state_t;
|
||||||
|
|
||||||
struct _LIBSSH2_PACKET {
|
struct _LIBSSH2_PACKET
|
||||||
|
{
|
||||||
unsigned char type;
|
unsigned char type;
|
||||||
|
|
||||||
/* Unencrypted Payload (no type byte, no padding, just the facts ma'am) */
|
/* Unencrypted Payload (no type byte, no padding, just the facts ma'am) */
|
||||||
@@ -250,11 +259,13 @@ struct _LIBSSH2_PACKET {
|
|||||||
LIBSSH2_PACKET *next, *prev;
|
LIBSSH2_PACKET *next, *prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_PACKET_BRIGADE {
|
struct _LIBSSH2_PACKET_BRIGADE
|
||||||
|
{
|
||||||
LIBSSH2_PACKET *head, *tail;
|
LIBSSH2_PACKET *head, *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _libssh2_channel_data {
|
typedef struct _libssh2_channel_data
|
||||||
|
{
|
||||||
/* Identifier */
|
/* Identifier */
|
||||||
unsigned long id;
|
unsigned long id;
|
||||||
|
|
||||||
@@ -265,7 +276,8 @@ typedef struct _libssh2_channel_data {
|
|||||||
char close, eof, extended_data_ignore_mode;
|
char close, eof, extended_data_ignore_mode;
|
||||||
} libssh2_channel_data;
|
} libssh2_channel_data;
|
||||||
|
|
||||||
struct _LIBSSH2_CHANNEL {
|
struct _LIBSSH2_CHANNEL
|
||||||
|
{
|
||||||
unsigned char *channel_type;
|
unsigned char *channel_type;
|
||||||
unsigned channel_type_len;
|
unsigned channel_type_len;
|
||||||
|
|
||||||
@@ -355,11 +367,13 @@ struct _LIBSSH2_CHANNEL {
|
|||||||
libssh2_nonblocking_states extData2_state;
|
libssh2_nonblocking_states extData2_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_CHANNEL_BRIGADE {
|
struct _LIBSSH2_CHANNEL_BRIGADE
|
||||||
|
{
|
||||||
LIBSSH2_CHANNEL *head, *tail;
|
LIBSSH2_CHANNEL *head, *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_LISTENER {
|
struct _LIBSSH2_LISTENER
|
||||||
|
{
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
|
|
||||||
char *host;
|
char *host;
|
||||||
@@ -377,7 +391,8 @@ struct _LIBSSH2_LISTENER {
|
|||||||
size_t chanFwdCncl_data_len;
|
size_t chanFwdCncl_data_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _libssh2_endpoint_data {
|
typedef struct _libssh2_endpoint_data
|
||||||
|
{
|
||||||
unsigned char *banner;
|
unsigned char *banner;
|
||||||
|
|
||||||
unsigned char *kexinit;
|
unsigned char *kexinit;
|
||||||
@@ -402,7 +417,8 @@ typedef struct _libssh2_endpoint_data {
|
|||||||
|
|
||||||
#define PACKETBUFSIZE 4096
|
#define PACKETBUFSIZE 4096
|
||||||
|
|
||||||
struct transportpacket {
|
struct transportpacket
|
||||||
|
{
|
||||||
/* ------------- for incoming data --------------- */
|
/* ------------- for incoming data --------------- */
|
||||||
unsigned char buf[PACKETBUFSIZE];
|
unsigned char buf[PACKETBUFSIZE];
|
||||||
unsigned char init[5]; /* first 5 bytes of the incoming data stream,
|
unsigned char init[5]; /* first 5 bytes of the incoming data stream,
|
||||||
@@ -437,7 +453,8 @@ struct transportpacket {
|
|||||||
unsigned long osent; /* number of bytes already sent */
|
unsigned long osent; /* number of bytes already sent */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_PUBLICKEY {
|
struct _LIBSSH2_PUBLICKEY
|
||||||
|
{
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
unsigned long version;
|
unsigned long version;
|
||||||
|
|
||||||
@@ -464,7 +481,8 @@ struct _LIBSSH2_PUBLICKEY {
|
|||||||
unsigned long listFetch_data_len;
|
unsigned long listFetch_data_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_SFTP_HANDLE {
|
struct _LIBSSH2_SFTP_HANDLE
|
||||||
|
{
|
||||||
LIBSSH2_SFTP *sftp;
|
LIBSSH2_SFTP *sftp;
|
||||||
LIBSSH2_SFTP_HANDLE *prev, *next;
|
LIBSSH2_SFTP_HANDLE *prev, *next;
|
||||||
|
|
||||||
@@ -473,11 +491,14 @@ struct _LIBSSH2_SFTP_HANDLE {
|
|||||||
|
|
||||||
char handle_type;
|
char handle_type;
|
||||||
|
|
||||||
union _libssh2_sftp_handle_data {
|
union _libssh2_sftp_handle_data
|
||||||
struct _libssh2_sftp_handle_file_data {
|
{
|
||||||
|
struct _libssh2_sftp_handle_file_data
|
||||||
|
{
|
||||||
libssh2_uint64_t offset;
|
libssh2_uint64_t offset;
|
||||||
} file;
|
} file;
|
||||||
struct _libssh2_sftp_handle_dir_data {
|
struct _libssh2_sftp_handle_dir_data
|
||||||
|
{
|
||||||
unsigned long names_left;
|
unsigned long names_left;
|
||||||
void *names_packet;
|
void *names_packet;
|
||||||
char *next_name;
|
char *next_name;
|
||||||
@@ -487,9 +508,11 @@ struct _LIBSSH2_SFTP_HANDLE {
|
|||||||
/* State variables used in libssh2_sftp_close_handle() */
|
/* State variables used in libssh2_sftp_close_handle() */
|
||||||
libssh2_nonblocking_states close_state;
|
libssh2_nonblocking_states close_state;
|
||||||
unsigned long close_request_id;
|
unsigned long close_request_id;
|
||||||
|
unsigned char *close_packet;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_SFTP {
|
struct _LIBSSH2_SFTP
|
||||||
|
{
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
|
|
||||||
unsigned long request_id, version;
|
unsigned long request_id, version;
|
||||||
@@ -569,7 +592,8 @@ struct _LIBSSH2_SFTP {
|
|||||||
|
|
||||||
#define LIBSSH2_SCP_RESPONSE_BUFLEN 256
|
#define LIBSSH2_SCP_RESPONSE_BUFLEN 256
|
||||||
|
|
||||||
struct _LIBSSH2_SESSION {
|
struct _LIBSSH2_SESSION
|
||||||
|
{
|
||||||
/* Memory management callbacks */
|
/* Memory management callbacks */
|
||||||
void *abstract;
|
void *abstract;
|
||||||
LIBSSH2_ALLOC_FUNC((*alloc));
|
LIBSSH2_ALLOC_FUNC((*alloc));
|
||||||
@@ -790,6 +814,8 @@ struct _LIBSSH2_SESSION {
|
|||||||
long scpRecv_size;
|
long scpRecv_size;
|
||||||
long scpRecv_mtime;
|
long scpRecv_mtime;
|
||||||
long scpRecv_atime;
|
long scpRecv_atime;
|
||||||
|
char *scpRecv_err_msg;
|
||||||
|
long scpRecv_err_len;
|
||||||
LIBSSH2_CHANNEL *scpRecv_channel;
|
LIBSSH2_CHANNEL *scpRecv_channel;
|
||||||
|
|
||||||
/* State variables used in libssh2_scp_send_ex() */
|
/* State variables used in libssh2_scp_send_ex() */
|
||||||
@@ -798,6 +824,8 @@ struct _LIBSSH2_SESSION {
|
|||||||
unsigned long scpSend_command_len;
|
unsigned long scpSend_command_len;
|
||||||
unsigned char scpSend_response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
unsigned char scpSend_response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
||||||
unsigned long scpSend_response_len;
|
unsigned long scpSend_response_len;
|
||||||
|
char *scpSend_err_msg;
|
||||||
|
long scpSend_err_len;
|
||||||
LIBSSH2_CHANNEL *scpSend_channel;
|
LIBSSH2_CHANNEL *scpSend_channel;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -818,28 +846,40 @@ struct _LIBSSH2_SESSION {
|
|||||||
|
|
||||||
/* libssh2 extensible ssh api, ultimately I'd like to allow loading additional methods via .so/.dll */
|
/* libssh2 extensible ssh api, ultimately I'd like to allow loading additional methods via .so/.dll */
|
||||||
|
|
||||||
struct _LIBSSH2_KEX_METHOD {
|
struct _LIBSSH2_KEX_METHOD
|
||||||
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
/* Key exchange, populates session->* and returns 0 on success, non-0 on error */
|
/* Key exchange, populates session->* and returns 0 on success, non-0 on error */
|
||||||
int (*exchange_keys)(LIBSSH2_SESSION *session, key_exchange_state_low_t *key_state);
|
int (*exchange_keys) (LIBSSH2_SESSION * session,
|
||||||
|
key_exchange_state_low_t * key_state);
|
||||||
|
|
||||||
long flags;
|
long flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_HOSTKEY_METHOD {
|
struct _LIBSSH2_HOSTKEY_METHOD
|
||||||
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned long hash_len;
|
unsigned long hash_len;
|
||||||
|
|
||||||
int (*init)(LIBSSH2_SESSION *session, const unsigned char *hostkey_data, unsigned long hostkey_data_len, void **abstract);
|
int (*init) (LIBSSH2_SESSION * session, const unsigned char *hostkey_data,
|
||||||
int (*initPEM)(LIBSSH2_SESSION *session, const char *privkeyfile, unsigned const char *passphrase, void **abstract);
|
unsigned long hostkey_data_len, void **abstract);
|
||||||
int (*sig_verify)(LIBSSH2_SESSION *session, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, unsigned long m_len, void **abstract);
|
int (*initPEM) (LIBSSH2_SESSION * session, const char *privkeyfile,
|
||||||
int (*signv)(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len, unsigned long veccount, const struct iovec datavec[], void **abstract);
|
unsigned const char *passphrase, void **abstract);
|
||||||
int (*encrypt)(LIBSSH2_SESSION *session, unsigned char **dst, unsigned long *dst_len, const unsigned char *src, unsigned long src_len, void **abstract);
|
int (*sig_verify) (LIBSSH2_SESSION * session, const unsigned char *sig,
|
||||||
|
unsigned long sig_len, const unsigned char *m,
|
||||||
|
unsigned long m_len, void **abstract);
|
||||||
|
int (*signv) (LIBSSH2_SESSION * session, unsigned char **signature,
|
||||||
|
unsigned long *signature_len, unsigned long veccount,
|
||||||
|
const struct iovec datavec[], void **abstract);
|
||||||
|
int (*encrypt) (LIBSSH2_SESSION * session, unsigned char **dst,
|
||||||
|
unsigned long *dst_len, const unsigned char *src,
|
||||||
|
unsigned long src_len, void **abstract);
|
||||||
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
|
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_CRYPT_METHOD {
|
struct _LIBSSH2_CRYPT_METHOD
|
||||||
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
int blocksize;
|
int blocksize;
|
||||||
@@ -850,23 +890,31 @@ struct _LIBSSH2_CRYPT_METHOD {
|
|||||||
|
|
||||||
long flags;
|
long flags;
|
||||||
|
|
||||||
int (*init)(LIBSSH2_SESSION *session, const LIBSSH2_CRYPT_METHOD *method, unsigned char *iv, int *free_iv, unsigned char *secret, int *free_secret, int encrypt, void **abstract);
|
int (*init) (LIBSSH2_SESSION * session,
|
||||||
int (*crypt)(LIBSSH2_SESSION *session, unsigned char *block, void **abstract);
|
const LIBSSH2_CRYPT_METHOD * method, unsigned char *iv,
|
||||||
|
int *free_iv, unsigned char *secret, int *free_secret,
|
||||||
|
int encrypt, void **abstract);
|
||||||
|
int (*crypt) (LIBSSH2_SESSION * session, unsigned char *block,
|
||||||
|
void **abstract);
|
||||||
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
|
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
|
||||||
|
|
||||||
_libssh2_cipher_type(algo);
|
_libssh2_cipher_type(algo);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_COMP_METHOD {
|
struct _LIBSSH2_COMP_METHOD
|
||||||
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
int (*init) (LIBSSH2_SESSION * session, int compress, void **abstract);
|
int (*init) (LIBSSH2_SESSION * session, int compress, void **abstract);
|
||||||
int (*comp)(LIBSSH2_SESSION *session, int compress, unsigned char **dest, unsigned long *dest_len, unsigned long payload_limit, int *free_dest,
|
int (*comp) (LIBSSH2_SESSION * session, int compress, unsigned char **dest,
|
||||||
const unsigned char *src, unsigned long src_len, void **abstract);
|
unsigned long *dest_len, unsigned long payload_limit,
|
||||||
|
int *free_dest, const unsigned char *src,
|
||||||
|
unsigned long src_len, void **abstract);
|
||||||
int (*dtor) (LIBSSH2_SESSION * session, int compress, void **abstract);
|
int (*dtor) (LIBSSH2_SESSION * session, int compress, void **abstract);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_MAC_METHOD {
|
struct _LIBSSH2_MAC_METHOD
|
||||||
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
/* The length of a given MAC packet */
|
/* The length of a given MAC packet */
|
||||||
@@ -876,8 +924,12 @@ struct _LIBSSH2_MAC_METHOD {
|
|||||||
int key_len;
|
int key_len;
|
||||||
|
|
||||||
/* Message Authentication Code Hashing algo */
|
/* Message Authentication Code Hashing algo */
|
||||||
int (*init)(LIBSSH2_SESSION *session, unsigned char *key, int *free_key, void **abstract);
|
int (*init) (LIBSSH2_SESSION * session, unsigned char *key, int *free_key,
|
||||||
int (*hash)(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno, const unsigned char *packet, unsigned long packet_len, const unsigned char *addtl, unsigned long addtl_len, void **abstract);
|
void **abstract);
|
||||||
|
int (*hash) (LIBSSH2_SESSION * session, unsigned char *buf,
|
||||||
|
unsigned long seqno, const unsigned char *packet,
|
||||||
|
unsigned long packet_len, const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len, void **abstract);
|
||||||
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
|
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -890,7 +942,8 @@ struct _LIBSSH2_MAC_METHOD {
|
|||||||
#define LIBSSH2_DBG_ERROR 7
|
#define LIBSSH2_DBG_ERROR 7
|
||||||
#define LIBSSH2_DBG_PUBLICKEY 8
|
#define LIBSSH2_DBG_PUBLICKEY 8
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, ...);
|
void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format,
|
||||||
|
...);
|
||||||
#else
|
#else
|
||||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||||
/* C99 style */
|
/* C99 style */
|
||||||
@@ -900,8 +953,10 @@ void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, .
|
|||||||
#define _libssh2_debug(x,y,z,...) do {} while (0)
|
#define _libssh2_debug(x,y,z,...) do {} while (0)
|
||||||
#else
|
#else
|
||||||
/* no gcc and not C99, do static and hopefully inline */
|
/* no gcc and not C99, do static and hopefully inline */
|
||||||
static inline void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
static inline void
|
||||||
const char *format, ...) {}
|
_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
|
||||||
|
{
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1032,15 +1087,38 @@ int libssh2_packet_ask_ex(LIBSSH2_SESSION *session, unsigned char packet_type,
|
|||||||
const unsigned char *match_buf,
|
const unsigned char *match_buf,
|
||||||
unsigned long match_len, int poll_socket);
|
unsigned long match_len, int poll_socket);
|
||||||
|
|
||||||
int libssh2_packet_askv_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, int poll_socket);
|
int libssh2_packet_askv_ex(LIBSSH2_SESSION * session,
|
||||||
int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, packet_require_state_t *state);
|
const unsigned char *packet_types,
|
||||||
int libssh2_packet_requirev_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, packet_requirev_state_t *state);
|
unsigned char **data, unsigned long *data_len,
|
||||||
int libssh2_packet_burn(LIBSSH2_SESSION *session, libssh2_nonblocking_states *state);
|
unsigned long match_ofs,
|
||||||
int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned long data_len);
|
const unsigned char *match_buf,
|
||||||
int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data, size_t datalen, int macstate);
|
unsigned long match_len, int poll_socket);
|
||||||
int libssh2_kex_exchange(LIBSSH2_SESSION *session, int reexchange, key_exchange_state_t *state);
|
int libssh2_packet_require_ex(LIBSSH2_SESSION * session,
|
||||||
|
unsigned char packet_type, unsigned char **data,
|
||||||
|
unsigned long *data_len, unsigned long match_ofs,
|
||||||
|
const unsigned char *match_buf,
|
||||||
|
unsigned long match_len,
|
||||||
|
packet_require_state_t * state);
|
||||||
|
int libssh2_packet_requirev_ex(LIBSSH2_SESSION * session,
|
||||||
|
const unsigned char *packet_types,
|
||||||
|
unsigned char **data, unsigned long *data_len,
|
||||||
|
unsigned long match_ofs,
|
||||||
|
const unsigned char *match_buf,
|
||||||
|
unsigned long match_len,
|
||||||
|
packet_requirev_state_t * state);
|
||||||
|
int libssh2_packet_burn(LIBSSH2_SESSION * session,
|
||||||
|
libssh2_nonblocking_states * state);
|
||||||
|
int libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
|
||||||
|
unsigned long data_len);
|
||||||
|
int libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
||||||
|
size_t datalen, int macstate);
|
||||||
|
int libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
|
||||||
|
key_exchange_state_t * state);
|
||||||
unsigned long libssh2_channel_nextid(LIBSSH2_SESSION * session);
|
unsigned long libssh2_channel_nextid(LIBSSH2_SESSION * session);
|
||||||
LIBSSH2_CHANNEL *libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id);
|
LIBSSH2_CHANNEL *libssh2_channel_locate(LIBSSH2_SESSION * session,
|
||||||
|
unsigned long channel_id);
|
||||||
|
unsigned long libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel,
|
||||||
|
int stream_id);
|
||||||
|
|
||||||
/* this is the lib-internal set blocking function */
|
/* this is the lib-internal set blocking function */
|
||||||
int _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking);
|
int _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking);
|
||||||
@@ -1058,8 +1136,7 @@ const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void);
|
|||||||
int _libssh2_pem_parse(LIBSSH2_SESSION * session,
|
int _libssh2_pem_parse(LIBSSH2_SESSION * session,
|
||||||
const char *headerbegin,
|
const char *headerbegin,
|
||||||
const char *headerend,
|
const char *headerend,
|
||||||
FILE *fp,
|
FILE * fp, char **data, unsigned int *datalen);
|
||||||
char **data, unsigned int *datalen);
|
|
||||||
int _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen);
|
int _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen);
|
||||||
int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
||||||
unsigned char **i, unsigned int *ilen);
|
unsigned char **i, unsigned int *ilen);
|
||||||
|
85
src/mac.c
85
src/mac.c
@@ -41,12 +41,15 @@
|
|||||||
/* {{{ libssh2_mac_none_MAC
|
/* {{{ libssh2_mac_none_MAC
|
||||||
* Minimalist MAC: No MAC
|
* Minimalist MAC: No MAC
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_none_MAC(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
libssh2_mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
unsigned long seqno, const unsigned char *packet,
|
||||||
|
unsigned long packet_len, const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
@@ -63,7 +66,9 @@ static LIBSSH2_MAC_METHOD libssh2_mac_method_none = {
|
|||||||
/* {{{ libssh2_mac_method_common_init
|
/* {{{ libssh2_mac_method_common_init
|
||||||
* Initialize simple mac methods
|
* Initialize simple mac methods
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_common_init(LIBSSH2_SESSION *session, unsigned char *key, int *free_key, void **abstract)
|
static int
|
||||||
|
libssh2_mac_method_common_init(LIBSSH2_SESSION * session, unsigned char *key,
|
||||||
|
int *free_key, void **abstract)
|
||||||
{
|
{
|
||||||
*abstract = key;
|
*abstract = key;
|
||||||
*free_key = 0;
|
*free_key = 0;
|
||||||
@@ -71,12 +76,14 @@ static int libssh2_mac_method_common_init(LIBSSH2_SESSION *session, unsigned cha
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_mac_method_common_dtor
|
/* {{{ libssh2_mac_method_common_dtor
|
||||||
* Cleanup simple mac methods
|
* Cleanup simple mac methods
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_common_dtor(LIBSSH2_SESSION *session, void **abstract)
|
static int
|
||||||
|
libssh2_mac_method_common_dtor(LIBSSH2_SESSION * session, void **abstract)
|
||||||
{
|
{
|
||||||
if (*abstract) {
|
if (*abstract) {
|
||||||
LIBSSH2_FREE(session, *abstract);
|
LIBSSH2_FREE(session, *abstract);
|
||||||
@@ -85,14 +92,19 @@ static int libssh2_mac_method_common_dtor(LIBSSH2_SESSION *session, void **abstr
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_mac_method_hmac_sha1_hash
|
/* {{{ libssh2_mac_method_hmac_sha1_hash
|
||||||
* Calculate hash using full sha1 value
|
* Calculate hash using full sha1 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
unsigned char *buf, unsigned long seqno,
|
||||||
|
const unsigned char *packet,
|
||||||
|
unsigned long packet_len,
|
||||||
|
const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_hmac_ctx ctx;
|
libssh2_hmac_ctx ctx;
|
||||||
unsigned char seqno_buf[4];
|
unsigned char seqno_buf[4];
|
||||||
@@ -111,6 +123,7 @@ static int libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION *session, unsigned
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1 = {
|
||||||
@@ -125,17 +138,23 @@ static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1 = {
|
|||||||
/* {{{ libssh2_mac_method_hmac_sha1_96_hash
|
/* {{{ libssh2_mac_method_hmac_sha1_96_hash
|
||||||
* Calculate hash using first 96 bits of sha1 value
|
* Calculate hash using first 96 bits of sha1 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
libssh2_mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
unsigned char *buf, unsigned long seqno,
|
||||||
|
const unsigned char *packet,
|
||||||
|
unsigned long packet_len,
|
||||||
|
const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
unsigned char temp[SHA_DIGEST_LENGTH];
|
unsigned char temp[SHA_DIGEST_LENGTH];
|
||||||
|
|
||||||
libssh2_mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len, addtl, addtl_len, abstract);
|
libssh2_mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len,
|
||||||
|
addtl, addtl_len, abstract);
|
||||||
memcpy(buf, (char *) temp, 96 / 8);
|
memcpy(buf, (char *) temp, 96 / 8);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1_96 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1_96 = {
|
||||||
@@ -150,9 +169,13 @@ static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1_96 = {
|
|||||||
/* {{{ libssh2_mac_method_hmac_md5_hash
|
/* {{{ libssh2_mac_method_hmac_md5_hash
|
||||||
* Calculate hash using full md5 value
|
* Calculate hash using full md5 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
unsigned long seqno,
|
||||||
|
const unsigned char *packet,
|
||||||
|
unsigned long packet_len,
|
||||||
|
const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_hmac_ctx ctx;
|
libssh2_hmac_ctx ctx;
|
||||||
unsigned char seqno_buf[4];
|
unsigned char seqno_buf[4];
|
||||||
@@ -171,6 +194,7 @@ static int libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION *session, unsigned c
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5 = {
|
||||||
@@ -185,17 +209,23 @@ static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5 = {
|
|||||||
/* {{{ libssh2_mac_method_hmac_md5_96_hash
|
/* {{{ libssh2_mac_method_hmac_md5_96_hash
|
||||||
* Calculate hash using first 96 bits of md5 value
|
* Calculate hash using first 96 bits of md5 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_md5_96_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
libssh2_mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
unsigned char *buf, unsigned long seqno,
|
||||||
|
const unsigned char *packet,
|
||||||
|
unsigned long packet_len,
|
||||||
|
const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
unsigned char temp[MD5_DIGEST_LENGTH];
|
unsigned char temp[MD5_DIGEST_LENGTH];
|
||||||
|
|
||||||
libssh2_mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, addtl, addtl_len, abstract);
|
libssh2_mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len,
|
||||||
|
addtl, addtl_len, abstract);
|
||||||
memcpy(buf, (char *) temp, 96 / 8);
|
memcpy(buf, (char *) temp, 96 / 8);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
|
||||||
@@ -211,9 +241,14 @@ static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
|
|||||||
/* {{{ libssh2_mac_method_hmac_ripemd160_hash
|
/* {{{ libssh2_mac_method_hmac_ripemd160_hash
|
||||||
* Calculate hash using ripemd160 value
|
* Calculate hash using ripemd160 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
unsigned char *buf, unsigned long seqno,
|
||||||
|
const unsigned char *packet,
|
||||||
|
unsigned long packet_len,
|
||||||
|
const unsigned char *addtl,
|
||||||
|
unsigned long addtl_len,
|
||||||
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_hmac_ctx ctx;
|
libssh2_hmac_ctx ctx;
|
||||||
unsigned char seqno_buf[4];
|
unsigned char seqno_buf[4];
|
||||||
@@ -232,6 +267,7 @@ static int libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION *session, unsi
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160 = {
|
||||||
@@ -268,7 +304,8 @@ static const LIBSSH2_MAC_METHOD *_libssh2_mac_methods[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void) {
|
const LIBSSH2_MAC_METHOD **
|
||||||
|
libssh2_mac_methods(void)
|
||||||
|
{
|
||||||
return _libssh2_mac_methods;
|
return _libssh2_mac_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
src/misc.c
37
src/misc.c
@@ -42,17 +42,20 @@
|
|||||||
|
|
||||||
/* {{{ libssh2_ntohu32
|
/* {{{ libssh2_ntohu32
|
||||||
*/
|
*/
|
||||||
unsigned long libssh2_ntohu32(const unsigned char *buf)
|
unsigned long
|
||||||
|
libssh2_ntohu32(const unsigned char *buf)
|
||||||
{
|
{
|
||||||
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_ntohu64
|
/* {{{ libssh2_ntohu64
|
||||||
* Note: Some 32-bit platforms have issues with bitops on long longs
|
* Note: Some 32-bit platforms have issues with bitops on long longs
|
||||||
* Work around this by doing expensive (but safer) arithmetic ops with optimization defying parentheses
|
* Work around this by doing expensive (but safer) arithmetic ops with optimization defying parentheses
|
||||||
*/
|
*/
|
||||||
libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf)
|
libssh2_uint64_t
|
||||||
|
libssh2_ntohu64(const unsigned char *buf)
|
||||||
{
|
{
|
||||||
unsigned long msl, lsl;
|
unsigned long msl, lsl;
|
||||||
|
|
||||||
@@ -61,22 +64,26 @@ libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf)
|
|||||||
|
|
||||||
return ((msl * 65536) * 65536) + lsl;
|
return ((msl * 65536) * 65536) + lsl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_htonu32
|
/* {{{ libssh2_htonu32
|
||||||
*/
|
*/
|
||||||
void libssh2_htonu32(unsigned char *buf, unsigned long value)
|
void
|
||||||
|
libssh2_htonu32(unsigned char *buf, unsigned long value)
|
||||||
{
|
{
|
||||||
buf[0] = (value >> 24) & 0xFF;
|
buf[0] = (value >> 24) & 0xFF;
|
||||||
buf[1] = (value >> 16) & 0xFF;
|
buf[1] = (value >> 16) & 0xFF;
|
||||||
buf[2] = (value >> 8) & 0xFF;
|
buf[2] = (value >> 8) & 0xFF;
|
||||||
buf[3] = value & 0xFF;
|
buf[3] = value & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_htonu64
|
/* {{{ libssh2_htonu64
|
||||||
*/
|
*/
|
||||||
void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
|
void
|
||||||
|
libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
|
||||||
{
|
{
|
||||||
unsigned long msl = (value / 65536) / 65536;
|
unsigned long msl = (value / 65536) / 65536;
|
||||||
|
|
||||||
@@ -90,6 +97,7 @@ void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
|
|||||||
buf[6] = (value >> 8) & 0xFF;
|
buf[6] = (value >> 8) & 0xFF;
|
||||||
buf[7] = value & 0xFF;
|
buf[7] = value & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* Base64 Conversion */
|
/* Base64 Conversion */
|
||||||
@@ -123,14 +131,17 @@ static const short libssh2_base64_reverse_table[256] = {
|
|||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
||||||
};
|
};
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ libssh2_base64_decode
|
/* {{{ libssh2_base64_decode
|
||||||
* Decode a base64 chunk and store it into a newly alloc'd buffer
|
* Decode a base64 chunk and store it into a newly alloc'd buffer
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, unsigned int *datalen,
|
LIBSSH2_API int
|
||||||
const char *src, unsigned int src_len)
|
libssh2_base64_decode(LIBSSH2_SESSION * session, char **data,
|
||||||
|
unsigned int *datalen, const char *src,
|
||||||
|
unsigned int src_len)
|
||||||
{
|
{
|
||||||
unsigned char *s, *d;
|
unsigned char *s, *d;
|
||||||
short v;
|
short v;
|
||||||
@@ -143,7 +154,8 @@ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, uns
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) {
|
for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) {
|
||||||
if ((v = libssh2_base64_reverse_table[*s]) < 0) continue;
|
if ((v = libssh2_base64_reverse_table[*s]) < 0)
|
||||||
|
continue;
|
||||||
switch (i % 4) {
|
switch (i % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
d[len] = v << 2;
|
d[len] = v << 2;
|
||||||
@@ -171,17 +183,19 @@ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, uns
|
|||||||
*datalen = len;
|
*datalen = len;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask)
|
LIBSSH2_API int
|
||||||
|
libssh2_trace(LIBSSH2_SESSION * session, int bitmask)
|
||||||
{
|
{
|
||||||
session->showmask = bitmask;
|
session->showmask = bitmask;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
void
|
||||||
const char *format, ...)
|
_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
|
||||||
{
|
{
|
||||||
char buffer[1536];
|
char buffer[1536];
|
||||||
int len;
|
int len;
|
||||||
@@ -217,7 +231,8 @@ void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask)
|
LIBSSH2_API int
|
||||||
|
libssh2_trace(LIBSSH2_SESSION * session, int bitmask)
|
||||||
{
|
{
|
||||||
(void) session;
|
(void) session;
|
||||||
(void) bitmask;
|
(void) bitmask;
|
||||||
|
@@ -43,7 +43,8 @@
|
|||||||
#define EVP_MAX_BLOCK_LENGTH 32
|
#define EVP_MAX_BLOCK_LENGTH 32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
int
|
||||||
|
_libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
|
||||||
const unsigned char *edata,
|
const unsigned char *edata,
|
||||||
unsigned long elen,
|
unsigned long elen,
|
||||||
const unsigned char *ndata,
|
const unsigned char *ndata,
|
||||||
@@ -58,8 +59,7 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata, unsigned long coefflen)
|
||||||
unsigned long coefflen)
|
|
||||||
{
|
{
|
||||||
*rsa = RSA_new();
|
*rsa = RSA_new();
|
||||||
|
|
||||||
@@ -91,11 +91,11 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsactx,
|
int
|
||||||
|
_libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len)
|
||||||
unsigned long m_len)
|
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
int ret;
|
int ret;
|
||||||
@@ -106,7 +106,8 @@ int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsactx,
|
|||||||
return (ret == 1) ? 0 : -1;
|
return (ret == 1) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
int
|
||||||
|
_libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
|
||||||
const unsigned char *p,
|
const unsigned char *p,
|
||||||
unsigned long p_len,
|
unsigned long p_len,
|
||||||
const unsigned char *q,
|
const unsigned char *q,
|
||||||
@@ -115,8 +116,7 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
|||||||
unsigned long g_len,
|
unsigned long g_len,
|
||||||
const unsigned char *y,
|
const unsigned char *y,
|
||||||
unsigned long y_len,
|
unsigned long y_len,
|
||||||
const unsigned char *x,
|
const unsigned char *x, unsigned long x_len)
|
||||||
unsigned long x_len)
|
|
||||||
{
|
{
|
||||||
*dsactx = DSA_new();
|
*dsactx = DSA_new();
|
||||||
|
|
||||||
@@ -140,10 +140,10 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
int
|
||||||
|
_libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len)
|
||||||
unsigned long m_len)
|
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
DSA_SIG dsasig;
|
DSA_SIG dsasig;
|
||||||
@@ -162,21 +162,20 @@ int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
|||||||
return (ret == 1) ? 0 : -1;
|
return (ret == 1) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int
|
||||||
|
_libssh2_cipher_init(_libssh2_cipher_ctx * h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv, unsigned char *secret, int encrypt)
|
||||||
unsigned char *secret,
|
|
||||||
int encrypt)
|
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_init(h);
|
EVP_CIPHER_CTX_init(h);
|
||||||
EVP_CipherInit(h, algo(), secret, iv, encrypt);
|
EVP_CipherInit(h, algo(), secret, iv, encrypt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
int
|
||||||
|
_libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt, unsigned char *block)
|
||||||
unsigned char *block)
|
|
||||||
{
|
{
|
||||||
int blocksize = ctx->cipher->block_size;
|
int blocksize = ctx->cipher->block_size;
|
||||||
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
||||||
@@ -199,8 +198,7 @@ int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
|||||||
* calling program
|
* calling program
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
passphrase_cb(char *buf, int size,
|
passphrase_cb(char *buf, int size, int rwflag, char *passphrase)
|
||||||
int rwflag, char *passphrase)
|
|
||||||
{
|
{
|
||||||
int passphrase_len = strlen(passphrase);
|
int passphrase_len = strlen(passphrase);
|
||||||
(void) rwflag;
|
(void) rwflag;
|
||||||
@@ -214,10 +212,10 @@ passphrase_cb(char *buf, int size,
|
|||||||
return passphrase_len;
|
return passphrase_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
int
|
||||||
|
_libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase)
|
||||||
unsigned const char *passphrase)
|
|
||||||
{
|
{
|
||||||
(void) session;
|
(void) session;
|
||||||
if (!EVP_get_cipherbyname("des")) {
|
if (!EVP_get_cipherbyname("des")) {
|
||||||
@@ -235,10 +233,10 @@ int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
int
|
||||||
|
_libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase)
|
||||||
unsigned const char *passphrase)
|
|
||||||
{
|
{
|
||||||
(void) session;
|
(void) session;
|
||||||
if (!EVP_get_cipherbyname("des")) {
|
if (!EVP_get_cipherbyname("des")) {
|
||||||
@@ -256,12 +254,12 @@ int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
int
|
||||||
|
_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
||||||
libssh2_rsa_ctx * rsactx,
|
libssh2_rsa_ctx * rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char **signature,
|
unsigned char **signature, unsigned long *signature_len)
|
||||||
unsigned long *signature_len)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char *sig;
|
unsigned char *sig;
|
||||||
@@ -287,10 +285,10 @@ int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
int
|
||||||
|
_libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len, unsigned char *signature)
|
||||||
unsigned char *signature)
|
|
||||||
{
|
{
|
||||||
DSA_SIG *sig;
|
DSA_SIG *sig;
|
||||||
int r_len, s_len, rs_pad;
|
int r_len, s_len, rs_pad;
|
||||||
|
@@ -146,17 +146,14 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
|||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata, unsigned long coefflen);
|
||||||
unsigned long coefflen);
|
|
||||||
int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase);
|
||||||
unsigned const char *passphrase);
|
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
|
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len);
|
||||||
unsigned long m_len);
|
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
||||||
libssh2_rsa_ctx * rsactx,
|
libssh2_rsa_ctx * rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
@@ -177,20 +174,16 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
|||||||
unsigned long glen,
|
unsigned long glen,
|
||||||
const unsigned char *ydata,
|
const unsigned char *ydata,
|
||||||
unsigned long ylen,
|
unsigned long ylen,
|
||||||
const unsigned char *x,
|
const unsigned char *x, unsigned long x_len);
|
||||||
unsigned long x_len);
|
|
||||||
int _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
int _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
||||||
LIBSSH2_SESSION * session,
|
LIBSSH2_SESSION * session,
|
||||||
FILE *fp,
|
FILE * fp, unsigned const char *passphrase);
|
||||||
unsigned const char *passphrase);
|
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
|
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m, unsigned long m_len);
|
||||||
unsigned long m_len);
|
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len, unsigned char *sig);
|
||||||
unsigned char *sig);
|
|
||||||
|
|
||||||
#define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
|
#define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
|
||||||
|
|
||||||
@@ -208,13 +201,11 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
|||||||
int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
|
int _libssh2_cipher_init(_libssh2_cipher_ctx * h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv,
|
||||||
unsigned char *secret,
|
unsigned char *secret, int encrypt);
|
||||||
int encrypt);
|
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt, unsigned char *block);
|
||||||
unsigned char *block);
|
|
||||||
|
|
||||||
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
|
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
|
||||||
|
|
||||||
|
301
src/packet.c
301
src/packet.c
@@ -80,18 +80,27 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
(void) datalen;
|
(void) datalen;
|
||||||
|
|
||||||
if (listen_state->state == libssh2_NB_state_idle) {
|
if (listen_state->state == libssh2_NB_state_idle) {
|
||||||
listen_state->sender_channel = libssh2_ntohu32(s); s += 4;
|
listen_state->sender_channel = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
listen_state->initial_window_size = libssh2_ntohu32(s); s += 4;
|
listen_state->initial_window_size = libssh2_ntohu32(s);
|
||||||
listen_state->packet_size = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
|
listen_state->packet_size = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
listen_state->host_len = libssh2_ntohu32(s); s += 4;
|
listen_state->host_len = libssh2_ntohu32(s);
|
||||||
listen_state->host = s; s += listen_state->host_len;
|
s += 4;
|
||||||
listen_state->port = libssh2_ntohu32(s); s += 4;
|
listen_state->host = s;
|
||||||
|
s += listen_state->host_len;
|
||||||
|
listen_state->port = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
listen_state->shost_len = libssh2_ntohu32(s); s += 4;
|
listen_state->shost_len = libssh2_ntohu32(s);
|
||||||
listen_state->shost = s; s += listen_state->shost_len;
|
s += 4;
|
||||||
listen_state->sport = libssh2_ntohu32(s); s += 4;
|
listen_state->shost = s;
|
||||||
|
s += listen_state->shost_len;
|
||||||
|
listen_state->sport = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||||
"Remote received connection from %s:%ld to %s:%ld",
|
"Remote received connection from %s:%ld to %s:%ld",
|
||||||
@@ -105,7 +114,9 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
while (listen) {
|
while (listen) {
|
||||||
if ((listen->port == (int) listen_state->port) &&
|
if ((listen->port == (int) listen_state->port) &&
|
||||||
(strlen(listen->host) == listen_state->host_len) &&
|
(strlen(listen->host) == listen_state->host_len) &&
|
||||||
(memcmp(listen->host, listen_state->host, listen_state->host_len) == 0)) {
|
(memcmp
|
||||||
|
(listen->host, listen_state->host,
|
||||||
|
listen_state->host_len) == 0)) {
|
||||||
/* This is our listener */
|
/* This is our listener */
|
||||||
LIBSSH2_CHANNEL *channel, *last_queued = listen->queue;
|
LIBSSH2_CHANNEL *channel, *last_queued = listen->queue;
|
||||||
|
|
||||||
@@ -135,7 +146,9 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
channel->session = session;
|
channel->session = session;
|
||||||
channel->channel_type_len = sizeof("forwarded-tcpip") - 1;
|
channel->channel_type_len = sizeof("forwarded-tcpip") - 1;
|
||||||
channel->channel_type = LIBSSH2_ALLOC(session,
|
channel->channel_type = LIBSSH2_ALLOC(session,
|
||||||
channel->channel_type_len + 1);
|
channel->
|
||||||
|
channel_type_len +
|
||||||
|
1);
|
||||||
if (!channel->channel_type) {
|
if (!channel->channel_type) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate a channel for new connection",
|
"Unable to allocate a channel for new connection",
|
||||||
@@ -149,13 +162,18 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
channel->channel_type_len + 1);
|
channel->channel_type_len + 1);
|
||||||
|
|
||||||
channel->remote.id = listen_state->sender_channel;
|
channel->remote.id = listen_state->sender_channel;
|
||||||
channel->remote.window_size_initial = LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
channel->remote.window_size_initial =
|
||||||
channel->remote.window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
||||||
channel->remote.packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT;
|
channel->remote.window_size =
|
||||||
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
||||||
|
channel->remote.packet_size =
|
||||||
|
LIBSSH2_CHANNEL_PACKET_DEFAULT;
|
||||||
|
|
||||||
channel->local.id = libssh2_channel_nextid(session);
|
channel->local.id = libssh2_channel_nextid(session);
|
||||||
channel->local.window_size_initial = listen_state->initial_window_size;
|
channel->local.window_size_initial =
|
||||||
channel->local.window_size = listen_state->initial_window_size;
|
listen_state->initial_window_size;
|
||||||
|
channel->local.window_size =
|
||||||
|
listen_state->initial_window_size;
|
||||||
channel->local.packet_size = listen_state->packet_size;
|
channel->local.packet_size = listen_state->packet_size;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||||
@@ -185,8 +203,7 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
17);
|
17);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
"Unable to send channel open confirmation",
|
"Unable to send channel open confirmation",
|
||||||
0);
|
0);
|
||||||
@@ -239,8 +256,7 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
rc = libssh2_packet_write(session, listen_state->packet, packet_len);
|
rc = libssh2_packet_write(session, listen_state->packet, packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
"Unable to send open failure", 0);
|
"Unable to send open failure", 0);
|
||||||
listen_state->state = libssh2_NB_state_idle;
|
listen_state->state = libssh2_NB_state_idle;
|
||||||
@@ -250,6 +266,7 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_packet_x11_open
|
/* {{{ libssh2_packet_x11_open
|
||||||
@@ -271,12 +288,18 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
(void) datalen;
|
(void) datalen;
|
||||||
|
|
||||||
if (x11open_state->state == libssh2_NB_state_idle) {
|
if (x11open_state->state == libssh2_NB_state_idle) {
|
||||||
x11open_state->sender_channel = libssh2_ntohu32(s); s += 4;
|
x11open_state->sender_channel = libssh2_ntohu32(s);
|
||||||
x11open_state->initial_window_size = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
x11open_state->packet_size = libssh2_ntohu32(s); s += 4;
|
x11open_state->initial_window_size = libssh2_ntohu32(s);
|
||||||
x11open_state->shost_len = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
x11open_state->shost = s; s += x11open_state->shost_len;
|
x11open_state->packet_size = libssh2_ntohu32(s);
|
||||||
x11open_state->sport = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
|
x11open_state->shost_len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
x11open_state->shost = s;
|
||||||
|
s += x11open_state->shost_len;
|
||||||
|
x11open_state->sport = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||||
"X11 Connection Received from %s:%ld on channel %lu",
|
"X11 Connection Received from %s:%ld on channel %lu",
|
||||||
@@ -301,7 +324,8 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
channel->session = session;
|
channel->session = session;
|
||||||
channel->channel_type_len = sizeof("x11") - 1;
|
channel->channel_type_len = sizeof("x11") - 1;
|
||||||
channel->channel_type = LIBSSH2_ALLOC(session,
|
channel->channel_type = LIBSSH2_ALLOC(session,
|
||||||
channel->channel_type_len + 1);
|
channel->channel_type_len +
|
||||||
|
1);
|
||||||
if (!channel->channel_type) {
|
if (!channel->channel_type) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate a channel for new connection",
|
"Unable to allocate a channel for new connection",
|
||||||
@@ -310,15 +334,18 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
||||||
goto x11_exit;
|
goto x11_exit;
|
||||||
}
|
}
|
||||||
memcpy(channel->channel_type, "x11", channel->channel_type_len + 1);
|
memcpy(channel->channel_type, "x11",
|
||||||
|
channel->channel_type_len + 1);
|
||||||
|
|
||||||
channel->remote.id = x11open_state->sender_channel;
|
channel->remote.id = x11open_state->sender_channel;
|
||||||
channel->remote.window_size_initial = LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
channel->remote.window_size_initial =
|
||||||
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
||||||
channel->remote.window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
channel->remote.window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT;
|
||||||
channel->remote.packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT;
|
channel->remote.packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT;
|
||||||
|
|
||||||
channel->local.id = libssh2_channel_nextid(session);
|
channel->local.id = libssh2_channel_nextid(session);
|
||||||
channel->local.window_size_initial = x11open_state->initial_window_size;
|
channel->local.window_size_initial =
|
||||||
|
x11open_state->initial_window_size;
|
||||||
channel->local.window_size = x11open_state->initial_window_size;
|
channel->local.window_size = x11open_state->initial_window_size;
|
||||||
channel->local.packet_size = x11open_state->packet_size;
|
channel->local.packet_size = x11open_state->packet_size;
|
||||||
|
|
||||||
@@ -331,10 +358,14 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
channel->remote.packet_size);
|
channel->remote.packet_size);
|
||||||
p = x11open_state->packet;
|
p = x11open_state->packet;
|
||||||
*(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
|
*(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
|
||||||
libssh2_htonu32(p, channel->remote.id); p += 4;
|
libssh2_htonu32(p, channel->remote.id);
|
||||||
libssh2_htonu32(p, channel->local.id); p += 4;
|
p += 4;
|
||||||
libssh2_htonu32(p, channel->remote.window_size_initial); p += 4;
|
libssh2_htonu32(p, channel->local.id);
|
||||||
libssh2_htonu32(p, channel->remote.packet_size); p += 4;
|
p += 4;
|
||||||
|
libssh2_htonu32(p, channel->remote.window_size_initial);
|
||||||
|
p += 4;
|
||||||
|
libssh2_htonu32(p, channel->remote.packet_size);
|
||||||
|
p += 4;
|
||||||
|
|
||||||
x11open_state->state = libssh2_NB_state_created;
|
x11open_state->state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
@@ -343,8 +374,7 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
rc = libssh2_packet_write(session, x11open_state->packet, 17);
|
rc = libssh2_packet_write(session, x11open_state->packet, 17);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
"Unable to send channel open confirmation", 0);
|
"Unable to send channel open confirmation", 0);
|
||||||
x11open_state->state = libssh2_NB_state_idle;
|
x11open_state->state = libssh2_NB_state_idle;
|
||||||
@@ -366,7 +396,8 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
* Pass control to the callback, they may turn right around and
|
* Pass control to the callback, they may turn right around and
|
||||||
* free the channel, or actually use it
|
* free the channel, or actually use it
|
||||||
*/
|
*/
|
||||||
LIBSSH2_X11_OPEN(channel, (char *)x11open_state->shost, x11open_state->sport);
|
LIBSSH2_X11_OPEN(channel, (char *) x11open_state->shost,
|
||||||
|
x11open_state->sport);
|
||||||
|
|
||||||
x11open_state->state = libssh2_NB_state_idle;
|
x11open_state->state = libssh2_NB_state_idle;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -378,9 +409,12 @@ libssh2_packet_x11_open(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
x11_exit:
|
x11_exit:
|
||||||
p = x11open_state->packet;
|
p = x11open_state->packet;
|
||||||
*(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE;
|
*(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE;
|
||||||
libssh2_htonu32(p, x11open_state->sender_channel); p += 4;
|
libssh2_htonu32(p, x11open_state->sender_channel);
|
||||||
libssh2_htonu32(p, failure_code); p += 4;
|
p += 4;
|
||||||
libssh2_htonu32(p, sizeof(X11FwdUnAvil) - 1); p += 4;
|
libssh2_htonu32(p, failure_code);
|
||||||
|
p += 4;
|
||||||
|
libssh2_htonu32(p, sizeof(X11FwdUnAvil) - 1);
|
||||||
|
p += 4;
|
||||||
memcpy(s, X11FwdUnAvil, sizeof(X11FwdUnAvil) - 1);
|
memcpy(s, X11FwdUnAvil, sizeof(X11FwdUnAvil) - 1);
|
||||||
p += sizeof(X11FwdUnAvil) - 1;
|
p += sizeof(X11FwdUnAvil) - 1;
|
||||||
libssh2_htonu32(p, 0);
|
libssh2_htonu32(p, 0);
|
||||||
@@ -388,8 +422,7 @@ x11_exit:
|
|||||||
rc = libssh2_packet_write(session, x11open_state->packet, packet_len);
|
rc = libssh2_packet_write(session, x11open_state->packet, packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
"Unable to send open failure", 0);
|
"Unable to send open failure", 0);
|
||||||
x11open_state->state = libssh2_NB_state_idle;
|
x11open_state->state = libssh2_NB_state_idle;
|
||||||
@@ -398,12 +431,14 @@ x11_exit:
|
|||||||
x11open_state->state = libssh2_NB_state_idle;
|
x11open_state->state = libssh2_NB_state_idle;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_packet_new
|
/* {{{ libssh2_packet_new
|
||||||
* Create a new packet and attach it to the brigade
|
* Create a new packet and attach it to the brigade
|
||||||
*/
|
*/
|
||||||
int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
int
|
||||||
|
libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
||||||
size_t datalen, int macstate)
|
size_t datalen, int macstate)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@@ -469,11 +504,9 @@ int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
*/
|
*/
|
||||||
if (session->packAdd_state == libssh2_NB_state_jump1) {
|
if (session->packAdd_state == libssh2_NB_state_jump1) {
|
||||||
goto libssh2_packet_add_jump_point1;
|
goto libssh2_packet_add_jump_point1;
|
||||||
}
|
} else if (session->packAdd_state == libssh2_NB_state_jump2) {
|
||||||
else if (session->packAdd_state == libssh2_NB_state_jump2) {
|
|
||||||
goto libssh2_packet_add_jump_point2;
|
goto libssh2_packet_add_jump_point2;
|
||||||
}
|
} else if (session->packAdd_state == libssh2_NB_state_jump3) {
|
||||||
else if (session->packAdd_state == libssh2_NB_state_jump3) {
|
|
||||||
goto libssh2_packet_add_jump_point3;
|
goto libssh2_packet_add_jump_point3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,7 +619,8 @@ int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
session->packAdd_data_head += 9;
|
session->packAdd_data_head += 9;
|
||||||
{
|
{
|
||||||
session->packAdd_channel = libssh2_channel_locate(session,
|
session->packAdd_channel = libssh2_channel_locate(session,
|
||||||
libssh2_ntohu32(data + 1));
|
libssh2_ntohu32
|
||||||
|
(data + 1));
|
||||||
|
|
||||||
if (!session->packAdd_channel) {
|
if (!session->packAdd_channel) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
|
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
|
||||||
@@ -606,14 +640,17 @@ int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||||
"%d bytes received for channel %lu/%lu stream #%lu",
|
"%d bytes received for channel %lu/%lu stream #%lu",
|
||||||
(int)(datalen - session->packAdd_data_head),
|
(int) (datalen -
|
||||||
|
session->packAdd_data_head),
|
||||||
session->packAdd_channel->local.id,
|
session->packAdd_channel->local.id,
|
||||||
session->packAdd_channel->remote.id,
|
session->packAdd_channel->remote.id,
|
||||||
stream_id);
|
stream_id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ((session->packAdd_channel->remote.extended_data_ignore_mode == LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE) &&
|
if ((session->packAdd_channel->remote.
|
||||||
(data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA)) {
|
extended_data_ignore_mode ==
|
||||||
|
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE)
|
||||||
|
&& (data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA)) {
|
||||||
/* Pretend we didn't receive this */
|
/* Pretend we didn't receive this */
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
|
|
||||||
@@ -623,8 +660,10 @@ int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
|||||||
/* Adjust the window based on the block we just freed */
|
/* Adjust the window based on the block we just freed */
|
||||||
libssh2_packet_add_jump_point1:
|
libssh2_packet_add_jump_point1:
|
||||||
session->packAdd_state = libssh2_NB_state_jump1;
|
session->packAdd_state = libssh2_NB_state_jump1;
|
||||||
rc = libssh2_channel_receive_window_adjust(session->packAdd_channel,
|
rc = libssh2_channel_receive_window_adjust(session->
|
||||||
datalen - 13, 0);
|
packAdd_channel,
|
||||||
|
datalen - 13,
|
||||||
|
0);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
@@ -636,7 +675,8 @@ libssh2_packet_add_jump_point1:
|
|||||||
* REMEMBER! remote means remote as source of data,
|
* REMEMBER! remote means remote as source of data,
|
||||||
* NOT remote window!
|
* NOT remote window!
|
||||||
*/
|
*/
|
||||||
if (session->packAdd_channel->remote.packet_size < (datalen - session->packAdd_data_head)) {
|
if (session->packAdd_channel->remote.packet_size <
|
||||||
|
(datalen - session->packAdd_data_head)) {
|
||||||
/*
|
/*
|
||||||
* Spec says we MAY ignore bytes sent beyond
|
* Spec says we MAY ignore bytes sent beyond
|
||||||
* packet_size
|
* packet_size
|
||||||
@@ -645,7 +685,9 @@ libssh2_packet_add_jump_point1:
|
|||||||
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
|
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
|
||||||
"Packet contains more data than we offered to receive, truncating",
|
"Packet contains more data than we offered to receive, truncating",
|
||||||
0);
|
0);
|
||||||
datalen = session->packAdd_channel->remote.packet_size + session->packAdd_data_head;
|
datalen =
|
||||||
|
session->packAdd_channel->remote.packet_size +
|
||||||
|
session->packAdd_data_head;
|
||||||
}
|
}
|
||||||
if (session->packAdd_channel->remote.window_size <= 0) {
|
if (session->packAdd_channel->remote.window_size <= 0) {
|
||||||
/*
|
/*
|
||||||
@@ -663,15 +705,19 @@ libssh2_packet_add_jump_point1:
|
|||||||
/* Reset EOF status */
|
/* Reset EOF status */
|
||||||
session->packAdd_channel->remote.eof = 0;
|
session->packAdd_channel->remote.eof = 0;
|
||||||
|
|
||||||
if ((datalen - session->packAdd_data_head) > session->packAdd_channel->remote.window_size) {
|
if ((datalen - session->packAdd_data_head) >
|
||||||
|
session->packAdd_channel->remote.window_size) {
|
||||||
libssh2_error(session,
|
libssh2_error(session,
|
||||||
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
|
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
|
||||||
"Remote sent more data than current window allows, truncating",
|
"Remote sent more data than current window allows, truncating",
|
||||||
0);
|
0);
|
||||||
datalen = session->packAdd_channel->remote.window_size + session->packAdd_data_head;
|
datalen =
|
||||||
|
session->packAdd_channel->remote.window_size +
|
||||||
|
session->packAdd_data_head;
|
||||||
} else {
|
} else {
|
||||||
/* Now that we've received it, shrink our window */
|
/* Now that we've received it, shrink our window */
|
||||||
session->packAdd_channel->remote.window_size -= datalen - session->packAdd_data_head;
|
session->packAdd_channel->remote.window_size -=
|
||||||
|
datalen - session->packAdd_data_head;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -679,7 +725,8 @@ libssh2_packet_add_jump_point1:
|
|||||||
case SSH_MSG_CHANNEL_EOF:
|
case SSH_MSG_CHANNEL_EOF:
|
||||||
{
|
{
|
||||||
session->packAdd_channel = libssh2_channel_locate(session,
|
session->packAdd_channel = libssh2_channel_locate(session,
|
||||||
libssh2_ntohu32(data + 1));
|
libssh2_ntohu32
|
||||||
|
(data + 1));
|
||||||
|
|
||||||
if (!session->packAdd_channel) {
|
if (!session->packAdd_channel) {
|
||||||
/* We may have freed already, just quietly ignore this... */
|
/* We may have freed already, just quietly ignore this... */
|
||||||
@@ -704,13 +751,17 @@ libssh2_packet_add_jump_point1:
|
|||||||
case SSH_MSG_CHANNEL_REQUEST:
|
case SSH_MSG_CHANNEL_REQUEST:
|
||||||
{
|
{
|
||||||
if (libssh2_ntohu32(data + 5) == sizeof("exit-status") - 1
|
if (libssh2_ntohu32(data + 5) == sizeof("exit-status") - 1
|
||||||
&& !memcmp("exit-status", data + 9, sizeof("exit-status") - 1)) {
|
&& !memcmp("exit-status", data + 9,
|
||||||
|
sizeof("exit-status") - 1)) {
|
||||||
|
|
||||||
/* we've got "exit-status" packet. Set the session value */
|
/* we've got "exit-status" packet. Set the session value */
|
||||||
session->packAdd_channel = libssh2_channel_locate(session, libssh2_ntohu32(data+1));
|
session->packAdd_channel =
|
||||||
|
libssh2_channel_locate(session,
|
||||||
|
libssh2_ntohu32(data + 1));
|
||||||
|
|
||||||
if (session->packAdd_channel) {
|
if (session->packAdd_channel) {
|
||||||
session->packAdd_channel->exit_status = libssh2_ntohu32(data + 9 + sizeof("exit-status"));
|
session->packAdd_channel->exit_status =
|
||||||
|
libssh2_ntohu32(data + 9 + sizeof("exit-status"));
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||||
"Exit status %lu received for channel %lu/%lu",
|
"Exit status %lu received for channel %lu/%lu",
|
||||||
session->packAdd_channel->exit_status,
|
session->packAdd_channel->exit_status,
|
||||||
@@ -728,7 +779,8 @@ libssh2_packet_add_jump_point1:
|
|||||||
case SSH_MSG_CHANNEL_CLOSE:
|
case SSH_MSG_CHANNEL_CLOSE:
|
||||||
{
|
{
|
||||||
session->packAdd_channel = libssh2_channel_locate(session,
|
session->packAdd_channel = libssh2_channel_locate(session,
|
||||||
libssh2_ntohu32(data + 1));
|
libssh2_ntohu32
|
||||||
|
(data + 1));
|
||||||
|
|
||||||
if (!session->packAdd_channel) {
|
if (!session->packAdd_channel) {
|
||||||
/* We may have freed already, just quietly ignore this... */
|
/* We may have freed already, just quietly ignore this... */
|
||||||
@@ -753,13 +805,17 @@ libssh2_packet_add_jump_point1:
|
|||||||
|
|
||||||
case SSH_MSG_CHANNEL_OPEN:
|
case SSH_MSG_CHANNEL_OPEN:
|
||||||
if ((datalen >= (sizeof("forwarded-tcpip") + 4)) &&
|
if ((datalen >= (sizeof("forwarded-tcpip") + 4)) &&
|
||||||
((sizeof("forwarded-tcpip")-1) == libssh2_ntohu32(data + 1)) &&
|
((sizeof("forwarded-tcpip") - 1) == libssh2_ntohu32(data + 1))
|
||||||
(memcmp(data + 5, "forwarded-tcpip", sizeof("forwarded-tcpip") - 1) == 0)) {
|
&&
|
||||||
|
(memcmp
|
||||||
|
(data + 5, "forwarded-tcpip",
|
||||||
|
sizeof("forwarded-tcpip") - 1) == 0)) {
|
||||||
|
|
||||||
libssh2_packet_add_jump_point2:
|
libssh2_packet_add_jump_point2:
|
||||||
session->packAdd_state = libssh2_NB_state_jump2;
|
session->packAdd_state = libssh2_NB_state_jump2;
|
||||||
rc = libssh2_packet_queue_listener(session, data, datalen,
|
rc = libssh2_packet_queue_listener(session, data, datalen,
|
||||||
&session->packAdd_Qlstn_state);
|
&session->
|
||||||
|
packAdd_Qlstn_state);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
@@ -790,7 +846,8 @@ libssh2_packet_add_jump_point3:
|
|||||||
{
|
{
|
||||||
unsigned long bytestoadd = libssh2_ntohu32(data + 5);
|
unsigned long bytestoadd = libssh2_ntohu32(data + 5);
|
||||||
session->packAdd_channel = libssh2_channel_locate(session,
|
session->packAdd_channel = libssh2_channel_locate(session,
|
||||||
libssh2_ntohu32(data + 1));
|
libssh2_ntohu32
|
||||||
|
(data + 1));
|
||||||
|
|
||||||
if (session->packAdd_channel && bytestoadd) {
|
if (session->packAdd_channel && bytestoadd) {
|
||||||
session->packAdd_channel->local.window_size += bytestoadd;
|
session->packAdd_channel->local.window_size += bytestoadd;
|
||||||
@@ -813,7 +870,8 @@ libssh2_packet_add_jump_point3:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->packAdd_state == libssh2_NB_state_sent) {
|
if (session->packAdd_state == libssh2_NB_state_sent) {
|
||||||
session->packAdd_packet = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET));
|
session->packAdd_packet =
|
||||||
|
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET));
|
||||||
if (!session->packAdd_packet) {
|
if (!session->packAdd_packet) {
|
||||||
_libssh2_debug(session, LIBSSH2_ERROR_ALLOC,
|
_libssh2_debug(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate memory for LIBSSH2_PACKET");
|
"Unable to allocate memory for LIBSSH2_PACKET");
|
||||||
@@ -869,14 +927,18 @@ libssh2_packet_add_jump_point3:
|
|||||||
session->packAdd_state = libssh2_NB_state_idle;
|
session->packAdd_state = libssh2_NB_state_idle;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_packet_ask
|
/* {{{ libssh2_packet_ask
|
||||||
* Scan the brigade for a matching packet type, optionally poll the socket for
|
* Scan the brigade for a matching packet type, optionally poll the socket for
|
||||||
* a packet first
|
* a packet first
|
||||||
*/
|
*/
|
||||||
int libssh2_packet_ask_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data, unsigned long *data_len,
|
int
|
||||||
unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, int poll_socket)
|
libssh2_packet_ask_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
|
||||||
|
unsigned char **data, unsigned long *data_len,
|
||||||
|
unsigned long match_ofs, const unsigned char *match_buf,
|
||||||
|
unsigned long match_len, int poll_socket)
|
||||||
{
|
{
|
||||||
LIBSSH2_PACKET *packet = session->packets.head;
|
LIBSSH2_PACKET *packet = session->packets.head;
|
||||||
|
|
||||||
@@ -896,8 +958,16 @@ int libssh2_packet_ask_ex(LIBSSH2_SESSION *session, unsigned char packet_type, u
|
|||||||
"Looking for packet of type: %d", (int) packet_type);
|
"Looking for packet of type: %d", (int) packet_type);
|
||||||
|
|
||||||
while (packet) {
|
while (packet) {
|
||||||
if (packet->data[0] == packet_type && (packet->data_len >= (match_ofs + match_len)) &&
|
if (packet->data[0] == packet_type
|
||||||
(!match_buf || (memcmp(packet->data + match_ofs, match_buf, match_len) == 0))) {
|
&& (packet->data_len >= (match_ofs + match_len)) && (!match_buf
|
||||||
|
||
|
||||||
|
(memcmp
|
||||||
|
(packet->
|
||||||
|
data +
|
||||||
|
match_ofs,
|
||||||
|
match_buf,
|
||||||
|
match_len)
|
||||||
|
== 0))) {
|
||||||
*data = packet->data;
|
*data = packet->data;
|
||||||
*data_len = packet->data_len;
|
*data_len = packet->data_len;
|
||||||
|
|
||||||
@@ -921,13 +991,15 @@ int libssh2_packet_ask_ex(LIBSSH2_SESSION *session, unsigned char packet_type, u
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_packet_askv
|
/* {{{ libssh2_packet_askv
|
||||||
* Scan for any of a list of packet types in the brigade, optionally poll the
|
* Scan for any of a list of packet types in the brigade, optionally poll the
|
||||||
* socket for a packet first
|
* socket for a packet first
|
||||||
*/
|
*/
|
||||||
int libssh2_packet_askv_ex(LIBSSH2_SESSION *session,
|
int
|
||||||
|
libssh2_packet_askv_ex(LIBSSH2_SESSION * session,
|
||||||
const unsigned char *packet_types,
|
const unsigned char *packet_types,
|
||||||
unsigned char **data, unsigned long *data_len,
|
unsigned char **data, unsigned long *data_len,
|
||||||
unsigned long match_ofs,
|
unsigned long match_ofs,
|
||||||
@@ -952,6 +1024,7 @@ int libssh2_packet_askv_ex(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ waitsocket
|
/* {{{ waitsocket
|
||||||
@@ -962,7 +1035,8 @@ int libssh2_packet_askv_ex(LIBSSH2_SESSION *session,
|
|||||||
*
|
*
|
||||||
* FIXME: convert to use poll on systems that have it.
|
* FIXME: convert to use poll on systems that have it.
|
||||||
*/
|
*/
|
||||||
int libssh2_waitsocket(LIBSSH2_SESSION *session, long seconds)
|
int
|
||||||
|
libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds)
|
||||||
{
|
{
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -987,42 +1061,48 @@ int libssh2_waitsocket(LIBSSH2_SESSION *session, long seconds)
|
|||||||
* Returns negative on error
|
* Returns negative on error
|
||||||
* Returns 0 when it has taken care of the requested packet.
|
* Returns 0 when it has taken care of the requested packet.
|
||||||
*/
|
*/
|
||||||
int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data,
|
int
|
||||||
unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf,
|
libssh2_packet_require_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
|
||||||
unsigned long match_len, packet_require_state_t *state)
|
unsigned char **data, unsigned long *data_len,
|
||||||
|
unsigned long match_ofs,
|
||||||
|
const unsigned char *match_buf,
|
||||||
|
unsigned long match_len,
|
||||||
|
packet_require_state_t * state)
|
||||||
{
|
{
|
||||||
if (state->start == 0) {
|
if (state->start == 0) {
|
||||||
if (libssh2_packet_ask_ex(session, packet_type, data, data_len, match_ofs, match_buf, match_len, 0) == 0) {
|
if (libssh2_packet_ask_ex
|
||||||
|
(session, packet_type, data, data_len, match_ofs, match_buf,
|
||||||
|
match_len, 0) == 0) {
|
||||||
/* A packet was available in the packet brigade */
|
/* A packet was available in the packet brigade */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->start = time(NULL);
|
state->start = time(NULL);
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "May block until packet of type %d becomes available", (int)packet_type);
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS,
|
||||||
|
"May block until packet of type %d becomes available",
|
||||||
|
(int) packet_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
|
while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
|
||||||
libssh2pack_t ret = libssh2_packet_read(session);
|
libssh2pack_t ret = libssh2_packet_read(session);
|
||||||
if (ret == PACKET_EAGAIN) {
|
if (ret == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if ((ret == 0) && (!session->socket_block)) {
|
||||||
else if ((ret == 0) && (!session->socket_block)) {
|
|
||||||
/* If we are in non-blocking and there is no data, return that */
|
/* If we are in non-blocking and there is no data, return that */
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (ret < 0) {
|
||||||
else if (ret < 0) {
|
|
||||||
state->start = 0;
|
state->start = 0;
|
||||||
/* an error which is not just because of blocking */
|
/* an error which is not just because of blocking */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
} else if (ret == packet_type) {
|
||||||
else if (ret == packet_type) {
|
|
||||||
/* Be lazy, let packet_ask pull it out of the brigade */
|
/* Be lazy, let packet_ask pull it out of the brigade */
|
||||||
ret = libssh2_packet_ask_ex(session, packet_type, data, data_len, match_ofs, match_buf, match_len, 0);
|
ret =
|
||||||
|
libssh2_packet_ask_ex(session, packet_type, data, data_len,
|
||||||
|
match_ofs, match_buf, match_len, 0);
|
||||||
state->start = 0;
|
state->start = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
} else if (ret == 0) {
|
||||||
else if (ret == 0) {
|
|
||||||
/* nothing available, wait until data arrives or we time out */
|
/* nothing available, wait until data arrives or we time out */
|
||||||
long left = LIBSSH2_READ_TIMEOUT - (time(NULL) - state->start);
|
long left = LIBSSH2_READ_TIMEOUT - (time(NULL) - state->start);
|
||||||
|
|
||||||
@@ -1036,6 +1116,7 @@ int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_typ
|
|||||||
/* Only reached if the socket died */
|
/* Only reached if the socket died */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_packet_burn
|
/* {{{ libssh2_packet_burn
|
||||||
@@ -1043,7 +1124,9 @@ int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_typ
|
|||||||
* discards it
|
* discards it
|
||||||
* Used during KEX exchange to discard badly guessed KEX_INIT packets
|
* Used during KEX exchange to discard badly guessed KEX_INIT packets
|
||||||
*/
|
*/
|
||||||
int libssh2_packet_burn(LIBSSH2_SESSION *session, libssh2_nonblocking_states *state)
|
int
|
||||||
|
libssh2_packet_burn(LIBSSH2_SESSION * session,
|
||||||
|
libssh2_nonblocking_states * state)
|
||||||
{
|
{
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
unsigned long data_len;
|
unsigned long data_len;
|
||||||
@@ -1056,32 +1139,34 @@ int libssh2_packet_burn(LIBSSH2_SESSION *session, libssh2_nonblocking_states *st
|
|||||||
all_packets[i - 1] = i;
|
all_packets[i - 1] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libssh2_packet_askv_ex(session, all_packets, &data, &data_len, 0, NULL, 0, 0) == 0) {
|
if (libssh2_packet_askv_ex
|
||||||
|
(session, all_packets, &data, &data_len, 0, NULL, 0, 0) == 0) {
|
||||||
i = data[0];
|
i = data[0];
|
||||||
/* A packet was available in the packet brigade, burn it */
|
/* A packet was available in the packet brigade, burn it */
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Blocking until packet becomes available to burn");
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS,
|
||||||
|
"Blocking until packet becomes available to burn");
|
||||||
*state = libssh2_NB_state_created;
|
*state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
|
while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
|
||||||
if ((ret = libssh2_packet_read(session)) == PACKET_EAGAIN) {
|
if ((ret = libssh2_packet_read(session)) == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (ret < 0) {
|
||||||
else if (ret < 0) {
|
|
||||||
*state = libssh2_NB_state_idle;
|
*state = libssh2_NB_state_idle;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
} else if (ret == 0) {
|
||||||
else if (ret == 0) {
|
|
||||||
/* FIXME: this might busyloop */
|
/* FIXME: this might busyloop */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Be lazy, let packet_ask pull it out of the brigade */
|
/* Be lazy, let packet_ask pull it out of the brigade */
|
||||||
if (0 == libssh2_packet_ask_ex(session, ret, &data, &data_len, 0, NULL, 0, 0)) {
|
if (0 ==
|
||||||
|
libssh2_packet_ask_ex(session, ret, &data, &data_len, 0, NULL, 0,
|
||||||
|
0)) {
|
||||||
/* Smoke 'em if you got 'em */
|
/* Smoke 'em if you got 'em */
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
*state = libssh2_NB_state_idle;
|
*state = libssh2_NB_state_idle;
|
||||||
@@ -1092,6 +1177,7 @@ int libssh2_packet_burn(LIBSSH2_SESSION *session, libssh2_nonblocking_states *st
|
|||||||
/* Only reached if the socket died */
|
/* Only reached if the socket died */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1103,11 +1189,18 @@ int libssh2_packet_burn(LIBSSH2_SESSION *session, libssh2_nonblocking_states *st
|
|||||||
* packet_types is a null terminated list of packet_type numbers
|
* packet_types is a null terminated list of packet_type numbers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int libssh2_packet_requirev_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data,
|
int
|
||||||
unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf,
|
libssh2_packet_requirev_ex(LIBSSH2_SESSION * session,
|
||||||
unsigned long match_len, packet_requirev_state_t *state)
|
const unsigned char *packet_types,
|
||||||
|
unsigned char **data, unsigned long *data_len,
|
||||||
|
unsigned long match_ofs,
|
||||||
|
const unsigned char *match_buf,
|
||||||
|
unsigned long match_len,
|
||||||
|
packet_requirev_state_t * state)
|
||||||
{
|
{
|
||||||
if (libssh2_packet_askv_ex(session, packet_types, data, data_len, match_ofs, match_buf, match_len, 0) == 0) {
|
if (libssh2_packet_askv_ex
|
||||||
|
(session, packet_types, data, data_len, match_ofs, match_buf,
|
||||||
|
match_len, 0) == 0) {
|
||||||
/* One of the packets listed was available in the packet
|
/* One of the packets listed was available in the packet
|
||||||
brigade */
|
brigade */
|
||||||
state->start = 0;
|
state->start = 0;
|
||||||
@@ -1130,15 +1223,16 @@ int libssh2_packet_requirev_ex(LIBSSH2_SESSION *session, const unsigned char *pa
|
|||||||
if ((left <= 0) || (libssh2_waitsocket(session, left) <= 0)) {
|
if ((left <= 0) || (libssh2_waitsocket(session, left) <= 0)) {
|
||||||
state->start = 0;
|
state->start = 0;
|
||||||
return PACKET_TIMEOUT;
|
return PACKET_TIMEOUT;
|
||||||
}
|
} else if (ret == PACKET_EAGAIN) {
|
||||||
else if (ret == PACKET_EAGAIN) {
|
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strchr((char *) packet_types, ret)) {
|
if (strchr((char *) packet_types, ret)) {
|
||||||
/* Be lazy, let packet_ask pull it out of the brigade */
|
/* Be lazy, let packet_ask pull it out of the brigade */
|
||||||
return libssh2_packet_askv_ex(session, packet_types, data, data_len, match_ofs, match_buf, match_len, 0);
|
return libssh2_packet_askv_ex(session, packet_types, data,
|
||||||
|
data_len, match_ofs, match_buf,
|
||||||
|
match_len, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,4 +1240,5 @@ int libssh2_packet_requirev_ex(LIBSSH2_SESSION *session, const unsigned char *pa
|
|||||||
state->start = 0;
|
state->start = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
92
src/pem.c
92
src/pem.c
@@ -37,18 +37,16 @@
|
|||||||
|
|
||||||
#include "libssh2_priv.h"
|
#include "libssh2_priv.h"
|
||||||
|
|
||||||
static int readline (char *line, int line_size, FILE *fp)
|
static int
|
||||||
{
|
readline(char *line, int line_size, FILE * fp)
|
||||||
if (!fgets(line, line_size, fp))
|
|
||||||
{
|
{
|
||||||
|
if (!fgets(line, line_size, fp)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (*line && line[strlen(line) - 1] == '\r')
|
if (*line && line[strlen(line) - 1] == '\n') {
|
||||||
{
|
|
||||||
line[strlen(line) - 1] = '\0';
|
line[strlen(line) - 1] = '\0';
|
||||||
}
|
}
|
||||||
if (*line && line[strlen(line) - 1] == '\n')
|
if (*line && line[strlen(line) - 1] == '\r') {
|
||||||
{
|
|
||||||
line[strlen(line) - 1] = '\0';
|
line[strlen(line) - 1] = '\0';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -56,21 +54,19 @@ static int readline (char *line, int line_size, FILE *fp)
|
|||||||
|
|
||||||
#define LINE_SIZE 128
|
#define LINE_SIZE 128
|
||||||
|
|
||||||
int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
int
|
||||||
|
_libssh2_pem_parse(LIBSSH2_SESSION * session,
|
||||||
const char *headerbegin,
|
const char *headerbegin,
|
||||||
const char *headerend,
|
const char *headerend,
|
||||||
FILE *fp,
|
FILE * fp, char **data, unsigned int *datalen)
|
||||||
char **data, unsigned int *datalen)
|
|
||||||
{
|
{
|
||||||
char line[LINE_SIZE];
|
char line[LINE_SIZE];
|
||||||
char *b64data = NULL;
|
char *b64data = NULL;
|
||||||
unsigned int b64datalen = 0;
|
unsigned int b64datalen = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
if (readline(line, LINE_SIZE, fp)) {
|
||||||
if (readline(line, LINE_SIZE, fp))
|
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,18 +74,14 @@ int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
*line = '\0';
|
*line = '\0';
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
if (*line) {
|
||||||
if (*line)
|
|
||||||
{
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
size_t linelen;
|
size_t linelen;
|
||||||
|
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
tmp = LIBSSH2_REALLOC (session, b64data,
|
tmp = LIBSSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||||
b64datalen + linelen);
|
if (!tmp) {
|
||||||
if (!tmp)
|
|
||||||
{
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -98,16 +90,13 @@ int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
|||||||
b64datalen += linelen;
|
b64datalen += linelen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readline(line, LINE_SIZE, fp))
|
if (readline(line, LINE_SIZE, fp)) {
|
||||||
{
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} while (strcmp(line, headerend) != 0);
|
} while (strcmp(line, headerend) != 0);
|
||||||
|
|
||||||
if (libssh2_base64_decode(session, data, datalen,
|
if (libssh2_base64_decode(session, data, datalen, b64data, b64datalen)) {
|
||||||
b64data, b64datalen))
|
|
||||||
{
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -120,59 +109,51 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_asn1_length (const unsigned char *data,
|
static int
|
||||||
unsigned int datalen,
|
read_asn1_length(const unsigned char *data,
|
||||||
unsigned int *len)
|
unsigned int datalen, unsigned int *len)
|
||||||
{
|
{
|
||||||
unsigned int lenlen;
|
unsigned int lenlen;
|
||||||
int nextpos;
|
int nextpos;
|
||||||
|
|
||||||
if (datalen < 1)
|
if (datalen < 1) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*len = data[0];
|
*len = data[0];
|
||||||
|
|
||||||
if (*len >= 0x80)
|
if (*len >= 0x80) {
|
||||||
{
|
|
||||||
lenlen = *len & 0x7F;
|
lenlen = *len & 0x7F;
|
||||||
*len = data[1];
|
*len = data[1];
|
||||||
if (1 + lenlen > datalen)
|
if (1 + lenlen > datalen) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (lenlen > 1)
|
if (lenlen > 1) {
|
||||||
{
|
|
||||||
*len <<= 8;
|
*len <<= 8;
|
||||||
*len |= data[2];
|
*len |= data[2];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
lenlen = 0;
|
lenlen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextpos = 1 + lenlen;
|
nextpos = 1 + lenlen;
|
||||||
if (lenlen > 2 || 1 + lenlen + *len > datalen)
|
if (lenlen > 2 || 1 + lenlen + *len > datalen) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextpos;
|
return nextpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen)
|
int
|
||||||
|
_libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
int lenlen;
|
int lenlen;
|
||||||
|
|
||||||
if (*datalen < 1)
|
if (*datalen < 1) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*data)[0] != '\x30')
|
if ((*data)[0] != '\x30') {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,8 +161,7 @@ int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen)
|
|||||||
(*datalen)--;
|
(*datalen)--;
|
||||||
|
|
||||||
lenlen = read_asn1_length(*data, *datalen, &len);
|
lenlen = read_asn1_length(*data, *datalen, &len);
|
||||||
if (lenlen < 0 || lenlen + len != *datalen)
|
if (lenlen < 0 || lenlen + len != *datalen) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,19 +171,18 @@ int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_pem_decode_integer (unsigned char **data, unsigned int *datalen,
|
int
|
||||||
|
_libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
||||||
unsigned char **i, unsigned int *ilen)
|
unsigned char **i, unsigned int *ilen)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
int lenlen;
|
int lenlen;
|
||||||
|
|
||||||
if (*datalen < 1)
|
if (*datalen < 1) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*data)[0] != '\x02')
|
if ((*data)[0] != '\x02') {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,8 +190,7 @@ int _libssh2_pem_decode_integer (unsigned char **data, unsigned int *datalen,
|
|||||||
(*datalen)--;
|
(*datalen)--;
|
||||||
|
|
||||||
lenlen = read_asn1_length(*data, *datalen, &len);
|
lenlen = read_asn1_length(*data, *datalen, &len);
|
||||||
if (lenlen < 0 || lenlen + len > *datalen)
|
if (lenlen < 0 || lenlen + len > *datalen) {
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
566
src/publickey.c
566
src/publickey.c
@@ -45,16 +45,20 @@
|
|||||||
#define LIBSSH2_PUBLICKEY_RESPONSE_VERSION 1
|
#define LIBSSH2_PUBLICKEY_RESPONSE_VERSION 1
|
||||||
#define LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY 2
|
#define LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY 2
|
||||||
|
|
||||||
typedef struct _LIBSSH2_PUBLICKEY_CODE_LIST {
|
typedef struct _LIBSSH2_PUBLICKEY_CODE_LIST
|
||||||
|
{
|
||||||
int code;
|
int code;
|
||||||
const char *name;
|
const char *name;
|
||||||
int name_len;
|
int name_len;
|
||||||
} LIBSSH2_PUBLICKEY_CODE_LIST;
|
} LIBSSH2_PUBLICKEY_CODE_LIST;
|
||||||
|
|
||||||
static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_response_codes[] = {
|
static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_response_codes[] = {
|
||||||
{ LIBSSH2_PUBLICKEY_RESPONSE_STATUS, "status", sizeof("status") - 1 },
|
{LIBSSH2_PUBLICKEY_RESPONSE_STATUS, "status", sizeof("status") - 1}
|
||||||
{ LIBSSH2_PUBLICKEY_RESPONSE_VERSION, "version", sizeof("version") - 1 },
|
,
|
||||||
{ LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY, "publickey", sizeof("publickey") - 1 },
|
{LIBSSH2_PUBLICKEY_RESPONSE_VERSION, "version", sizeof("version") - 1}
|
||||||
|
,
|
||||||
|
{LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY, "publickey", sizeof("publickey") - 1}
|
||||||
|
,
|
||||||
{0, NULL, 0}
|
{0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,15 +76,32 @@ static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_response_codes[] = {
|
|||||||
#define LIBSSH2_PUBLICKEY_STATUS_CODE_MAX 8
|
#define LIBSSH2_PUBLICKEY_STATUS_CODE_MAX 8
|
||||||
|
|
||||||
static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_status_codes[] = {
|
static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_status_codes[] = {
|
||||||
{ LIBSSH2_PUBLICKEY_SUCCESS, "success", sizeof("success") - 1 },
|
{LIBSSH2_PUBLICKEY_SUCCESS, "success", sizeof("success") - 1}
|
||||||
{ LIBSSH2_PUBLICKEY_ACCESS_DENIED, "access denied", sizeof("access denied") - 1 },
|
,
|
||||||
{ LIBSSH2_PUBLICKEY_STORAGE_EXCEEDED, "storage exceeded", sizeof("storage exceeded") - 1 },
|
{LIBSSH2_PUBLICKEY_ACCESS_DENIED, "access denied",
|
||||||
{ LIBSSH2_PUBLICKEY_VERSION_NOT_SUPPORTED, "version not supported", sizeof("version not supported") - 1 },
|
sizeof("access denied") - 1}
|
||||||
{ LIBSSH2_PUBLICKEY_KEY_NOT_FOUND, "key not found", sizeof("key not found") - 1 },
|
,
|
||||||
{ LIBSSH2_PUBLICKEY_KEY_NOT_SUPPORTED, "key not supported", sizeof("key not supported") - 1 },
|
{LIBSSH2_PUBLICKEY_STORAGE_EXCEEDED, "storage exceeded",
|
||||||
{ LIBSSH2_PUBLICKEY_KEY_ALREADY_PRESENT, "key already present", sizeof("key already present") - 1 },
|
sizeof("storage exceeded") - 1}
|
||||||
{ LIBSSH2_PUBLICKEY_GENERAL_FAILURE, "general failure", sizeof("general failure") - 1 },
|
,
|
||||||
{ LIBSSH2_PUBLICKEY_REQUEST_NOT_SUPPORTED, "request not supported", sizeof("request not supported") - 1 },
|
{LIBSSH2_PUBLICKEY_VERSION_NOT_SUPPORTED, "version not supported",
|
||||||
|
sizeof("version not supported") - 1}
|
||||||
|
,
|
||||||
|
{LIBSSH2_PUBLICKEY_KEY_NOT_FOUND, "key not found",
|
||||||
|
sizeof("key not found") - 1}
|
||||||
|
,
|
||||||
|
{LIBSSH2_PUBLICKEY_KEY_NOT_SUPPORTED, "key not supported",
|
||||||
|
sizeof("key not supported") - 1}
|
||||||
|
,
|
||||||
|
{LIBSSH2_PUBLICKEY_KEY_ALREADY_PRESENT, "key already present",
|
||||||
|
sizeof("key already present") - 1}
|
||||||
|
,
|
||||||
|
{LIBSSH2_PUBLICKEY_GENERAL_FAILURE, "general failure",
|
||||||
|
sizeof("general failure") - 1}
|
||||||
|
,
|
||||||
|
{LIBSSH2_PUBLICKEY_REQUEST_NOT_SUPPORTED, "request not supported",
|
||||||
|
sizeof("request not supported") - 1}
|
||||||
|
,
|
||||||
{0, NULL, 0}
|
{0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,7 +112,8 @@ static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_status_codes[] = {
|
|||||||
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_MID "\" Server Resports: \""
|
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_MID "\" Server Resports: \""
|
||||||
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_END "\""
|
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_END "\""
|
||||||
static void
|
static void
|
||||||
libssh2_publickey_status_error(const LIBSSH2_PUBLICKEY *pkey, LIBSSH2_SESSION *session, int status,
|
libssh2_publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
|
||||||
|
LIBSSH2_SESSION * session, int status,
|
||||||
const unsigned char *message, int message_len)
|
const unsigned char *message, int message_len)
|
||||||
{
|
{
|
||||||
const char *status_text;
|
const char *status_text;
|
||||||
@@ -112,32 +134,41 @@ libssh2_publickey_status_error(const LIBSSH2_PUBLICKEY *pkey, LIBSSH2_SESSION *s
|
|||||||
status_text_len = libssh2_publickey_status_codes[status].name_len;
|
status_text_len = libssh2_publickey_status_codes[status].name_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_len = (sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1) + status_text_len +
|
m_len =
|
||||||
|
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1) + status_text_len +
|
||||||
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1) + message_len +
|
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1) + message_len +
|
||||||
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END) - 1);
|
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END) - 1);
|
||||||
m = LIBSSH2_ALLOC(session, m_len + 1);
|
m = LIBSSH2_ALLOC(session, m_len + 1);
|
||||||
if (!m) {
|
if (!m) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for status message", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for status message", 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s = m;
|
s = m;
|
||||||
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_START, sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1);
|
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_START,
|
||||||
|
sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1);
|
||||||
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1;
|
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1;
|
||||||
memcpy(s, status_text, status_text_len); s += status_text_len;
|
memcpy(s, status_text, status_text_len);
|
||||||
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_MID, sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1);
|
s += status_text_len;
|
||||||
|
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_MID,
|
||||||
|
sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1);
|
||||||
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1;
|
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1;
|
||||||
memcpy(s, message, message_len); s += message_len;
|
memcpy(s, message, message_len);
|
||||||
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_END, sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END) - 1);
|
s += message_len;
|
||||||
|
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_END,
|
||||||
|
sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END) - 1);
|
||||||
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END);
|
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END);
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, m, 1);
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, m, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_packet_receive
|
/* {{{ libssh2_publickey_packet_receive
|
||||||
* Read a packet from the subsystem
|
* Read a packet from the subsystem
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY *pkey, unsigned char **data, unsigned long *data_len)
|
libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
|
||||||
|
unsigned char **data, unsigned long *data_len)
|
||||||
{
|
{
|
||||||
LIBSSH2_CHANNEL *channel = pkey->channel;
|
LIBSSH2_CHANNEL *channel = pkey->channel;
|
||||||
LIBSSH2_SESSION *session = channel->session;
|
LIBSSH2_SESSION *session = channel->session;
|
||||||
@@ -148,16 +179,18 @@ libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY *pkey, unsigned char **data,
|
|||||||
rc = libssh2_channel_read_ex(channel, 0, (char *) buffer, 4);
|
rc = libssh2_channel_read_ex(channel, 0, (char *) buffer, 4);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc != 4) {
|
||||||
else if (rc != 4) {
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Invalid response from publickey subsystem", 0);
|
"Invalid response from publickey subsystem", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkey->receive_packet_len = libssh2_ntohu32(buffer);
|
pkey->receive_packet_len = libssh2_ntohu32(buffer);
|
||||||
pkey->receive_packet = LIBSSH2_ALLOC(session, pkey->receive_packet_len);
|
pkey->receive_packet =
|
||||||
|
LIBSSH2_ALLOC(session, pkey->receive_packet_len);
|
||||||
if (!pkey->receive_packet) {
|
if (!pkey->receive_packet) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate publickey response buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate publickey response buffer", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,12 +198,14 @@ libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY *pkey, unsigned char **data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pkey->receive_state == libssh2_NB_state_sent) {
|
if (pkey->receive_state == libssh2_NB_state_sent) {
|
||||||
rc = libssh2_channel_read_ex(channel, 0, (char *)pkey->receive_packet, pkey->receive_packet_len);
|
rc = libssh2_channel_read_ex(channel, 0, (char *) pkey->receive_packet,
|
||||||
|
pkey->receive_packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc != pkey->receive_packet_len) {
|
||||||
else if (rc != pkey->receive_packet_len) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for publickey subsystem response packet", 0);
|
"Timeout waiting for publickey subsystem response packet",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, pkey->receive_packet);
|
LIBSSH2_FREE(session, pkey->receive_packet);
|
||||||
pkey->receive_packet = NULL;
|
pkey->receive_packet = NULL;
|
||||||
pkey->receive_state = libssh2_NB_state_idle;
|
pkey->receive_state = libssh2_NB_state_idle;
|
||||||
@@ -185,23 +220,28 @@ libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY *pkey, unsigned char **data,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_response_id
|
/* {{{ libssh2_publickey_response_id
|
||||||
* Translate a string response name to a numeric code
|
* Translate a string response name to a numeric code
|
||||||
* Data will be incremented by 4 + response_len on success only
|
* Data will be incremented by 4 + response_len on success only
|
||||||
*/
|
*/
|
||||||
static int libssh2_publickey_response_id(unsigned char **pdata, int data_len)
|
static int
|
||||||
|
libssh2_publickey_response_id(unsigned char **pdata, int data_len)
|
||||||
{
|
{
|
||||||
unsigned long response_len;
|
unsigned long response_len;
|
||||||
unsigned char *data = *pdata;
|
unsigned char *data = *pdata;
|
||||||
const LIBSSH2_PUBLICKEY_CODE_LIST *codes = libssh2_publickey_response_codes;
|
const LIBSSH2_PUBLICKEY_CODE_LIST *codes =
|
||||||
|
libssh2_publickey_response_codes;
|
||||||
|
|
||||||
if (data_len < 4) {
|
if (data_len < 4) {
|
||||||
/* Malformed response */
|
/* Malformed response */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
response_len = libssh2_ntohu32(data); data += 4; data_len -= 4;
|
response_len = libssh2_ntohu32(data);
|
||||||
|
data += 4;
|
||||||
|
data_len -= 4;
|
||||||
if (data_len < response_len) {
|
if (data_len < response_len) {
|
||||||
/* Malformed response */
|
/* Malformed response */
|
||||||
return -1;
|
return -1;
|
||||||
@@ -218,12 +258,14 @@ static int libssh2_publickey_response_id(unsigned char **pdata, int data_len)
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_response_success
|
/* {{{ libssh2_publickey_response_success
|
||||||
* Generic helper routine to wait for success response and nothing else
|
* Generic helper routine to wait for success response and nothing else
|
||||||
*/
|
*/
|
||||||
static int libssh2_publickey_response_success(LIBSSH2_PUBLICKEY *pkey)
|
static int
|
||||||
|
libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = pkey->channel->session;
|
LIBSSH2_SESSION *session = pkey->channel->session;
|
||||||
unsigned char *data, *s;
|
unsigned char *data, *s;
|
||||||
@@ -235,15 +277,17 @@ static int libssh2_publickey_response_success(LIBSSH2_PUBLICKEY *pkey)
|
|||||||
rc = libssh2_publickey_packet_receive(pkey, &data, &data_len);
|
rc = libssh2_publickey_packet_receive(pkey, &data, &data_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for response from publickey subsystem", 0);
|
"Timeout waiting for response from publickey subsystem",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = data;
|
s = data;
|
||||||
if ((response = libssh2_publickey_response_id(&s, data_len)) < 0) {
|
if ((response = libssh2_publickey_response_id(&s, data_len)) < 0) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Invalid publickey subsystem response code", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Invalid publickey subsystem response code", 0);
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -255,14 +299,20 @@ static int libssh2_publickey_response_success(LIBSSH2_PUBLICKEY *pkey)
|
|||||||
unsigned long status, descr_len, lang_len;
|
unsigned long status, descr_len, lang_len;
|
||||||
unsigned char *descr, *lang;
|
unsigned char *descr, *lang;
|
||||||
|
|
||||||
status = libssh2_ntohu32(s); s += 4;
|
status = libssh2_ntohu32(s);
|
||||||
descr_len = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
descr = s; s += descr_len;
|
descr_len = libssh2_ntohu32(s);
|
||||||
lang_len = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
lang = s; s += lang_len;
|
descr = s;
|
||||||
|
s += descr_len;
|
||||||
|
lang_len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
lang = s;
|
||||||
|
s += lang_len;
|
||||||
|
|
||||||
if (s > data + data_len) {
|
if (s > data + data_len) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Malformed publickey subsystem packet", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Malformed publickey subsystem packet", 0);
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -272,13 +322,16 @@ static int libssh2_publickey_response_success(LIBSSH2_PUBLICKEY *pkey)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_publickey_status_error(pkey, session, status, descr, descr_len);
|
libssh2_publickey_status_error(pkey, session, status, descr,
|
||||||
|
descr_len);
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* Unknown/Unexpected */
|
/* Unknown/Unexpected */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Unexpected publickey subsystem response, ignoring", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Unexpected publickey subsystem response, ignoring",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
data = NULL;
|
data = NULL;
|
||||||
}
|
}
|
||||||
@@ -286,6 +339,7 @@ static int libssh2_publickey_response_success(LIBSSH2_PUBLICKEY *pkey)
|
|||||||
/* never reached, but include `return` to silence compiler warnings */
|
/* never reached, but include `return` to silence compiler warnings */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
@@ -296,7 +350,8 @@ static int libssh2_publickey_response_success(LIBSSH2_PUBLICKEY *pkey)
|
|||||||
/* {{{ libssh2_publickey_init
|
/* {{{ libssh2_publickey_init
|
||||||
* Startup the publickey subsystem
|
* Startup the publickey subsystem
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
LIBSSH2_API LIBSSH2_PUBLICKEY *
|
||||||
|
libssh2_publickey_init(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
/* 19 = packet_len(4) + version_len(4) + "version"(7) + version_num(4) */
|
/* 19 = packet_len(4) + version_len(4) + "version"(7) + version_num(4) */
|
||||||
unsigned char buffer[19];
|
unsigned char buffer[19];
|
||||||
@@ -309,23 +364,32 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
session->pkeyInit_pkey = NULL;
|
session->pkeyInit_pkey = NULL;
|
||||||
session->pkeyInit_channel = NULL;
|
session->pkeyInit_channel = NULL;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Initializing publickey subsystem");
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Initializing publickey subsystem");
|
||||||
|
|
||||||
session->pkeyInit_state = libssh2_NB_state_allocated;
|
session->pkeyInit_state = libssh2_NB_state_allocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->pkeyInit_state == libssh2_NB_state_allocated) {
|
if (session->pkeyInit_state == libssh2_NB_state_allocated) {
|
||||||
do {
|
do {
|
||||||
session->pkeyInit_channel = libssh2_channel_open_ex(session, "session", sizeof("session") - 1,
|
session->pkeyInit_channel =
|
||||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT,
|
libssh2_channel_open_ex(session, "session",
|
||||||
NULL, 0);
|
sizeof("session") - 1,
|
||||||
if (!session->pkeyInit_channel && (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN)) {
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||||
|
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL,
|
||||||
|
0);
|
||||||
|
if (!session->pkeyInit_channel
|
||||||
|
&& (libssh2_session_last_errno(session) ==
|
||||||
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
/* The error state is already set, so leave it */
|
/* The error state is already set, so leave it */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block to startup channel", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block to startup channel", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (!session->pkeyInit_channel
|
||||||
else if (!session->pkeyInit_channel && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
|
&& (libssh2_session_last_errno(session) !=
|
||||||
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, "Unable to startup channel", 0);
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
|
||||||
|
"Unable to startup channel", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
} while (!session->pkeyInit_channel);
|
} while (!session->pkeyInit_channel);
|
||||||
@@ -334,14 +398,17 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->pkeyInit_state == libssh2_NB_state_sent) {
|
if (session->pkeyInit_state == libssh2_NB_state_sent) {
|
||||||
rc = libssh2_channel_process_startup(session->pkeyInit_channel, "subsystem", sizeof("subsystem") - 1,
|
rc = libssh2_channel_process_startup(session->pkeyInit_channel,
|
||||||
|
"subsystem",
|
||||||
|
sizeof("subsystem") - 1,
|
||||||
"publickey", strlen("publickey"));
|
"publickey", strlen("publickey"));
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block starting publickkey subsystem", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block starting publickkey subsystem", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, "Unable to request publickey subsystem", 0);
|
"Unable to request publickey subsystem", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,15 +416,19 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->pkeyInit_state == libssh2_NB_state_sent1) {
|
if (session->pkeyInit_state == libssh2_NB_state_sent1) {
|
||||||
rc = libssh2_channel_handle_extended_data2(session->pkeyInit_channel, LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
|
rc = libssh2_channel_handle_extended_data2(session->pkeyInit_channel,
|
||||||
|
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block starting publickkey subsystem", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block starting publickkey subsystem", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
session->pkeyInit_pkey = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PUBLICKEY));
|
session->pkeyInit_pkey =
|
||||||
|
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PUBLICKEY));
|
||||||
if (!session->pkeyInit_pkey) {
|
if (!session->pkeyInit_pkey) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a new publickey structure", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate a new publickey structure", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
memset(session->pkeyInit_pkey, 0, sizeof(LIBSSH2_PUBLICKEY));
|
memset(session->pkeyInit_pkey, 0, sizeof(LIBSSH2_PUBLICKEY));
|
||||||
@@ -365,25 +436,32 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
session->pkeyInit_pkey->version = 0;
|
session->pkeyInit_pkey->version = 0;
|
||||||
|
|
||||||
s = buffer;
|
s = buffer;
|
||||||
libssh2_htonu32(s, 4 + (sizeof("version") - 1) + 4); s += 4;
|
libssh2_htonu32(s, 4 + (sizeof("version") - 1) + 4);
|
||||||
libssh2_htonu32(s, sizeof("version") - 1); s += 4;
|
s += 4;
|
||||||
memcpy(s, "version", sizeof("version") - 1); s += sizeof("version") - 1;
|
libssh2_htonu32(s, sizeof("version") - 1);
|
||||||
libssh2_htonu32(s, LIBSSH2_PUBLICKEY_VERSION); s += 4;
|
s += 4;
|
||||||
|
memcpy(s, "version", sizeof("version") - 1);
|
||||||
|
s += sizeof("version") - 1;
|
||||||
|
libssh2_htonu32(s, LIBSSH2_PUBLICKEY_VERSION);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Sending publickey version packet advertising version %d support",
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Sending publickey version packet advertising version %d support",
|
||||||
(int) LIBSSH2_PUBLICKEY_VERSION);
|
(int) LIBSSH2_PUBLICKEY_VERSION);
|
||||||
|
|
||||||
session->pkeyInit_state = libssh2_NB_state_sent2;
|
session->pkeyInit_state = libssh2_NB_state_sent2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->pkeyInit_state == libssh2_NB_state_sent2) {
|
if (session->pkeyInit_state == libssh2_NB_state_sent2) {
|
||||||
rc = libssh2_channel_write_ex(session->pkeyInit_channel, 0, (char*)buffer, (s - buffer));
|
rc = libssh2_channel_write_ex(session->pkeyInit_channel, 0,
|
||||||
|
(char *) buffer, (s - buffer));
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending publickkey version packet", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block sending publickkey version packet", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if ((s - buffer) != rc) {
|
||||||
else if ((s - buffer) != rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey version packet", 0);
|
"Unable to send publickey version packet", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,19 +470,28 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
if (session->pkeyInit_state == libssh2_NB_state_sent3) {
|
if (session->pkeyInit_state == libssh2_NB_state_sent3) {
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = libssh2_publickey_packet_receive(session->pkeyInit_pkey, &session->pkeyInit_data, &session->pkeyInit_data_len);
|
rc = libssh2_publickey_packet_receive(session->pkeyInit_pkey,
|
||||||
|
&session->pkeyInit_data,
|
||||||
|
&session->pkeyInit_data_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response from publickey subsystem", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for response from publickey subsystem",
|
||||||
|
0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for response from publickey subsystem", 0);
|
"Timeout waiting for response from publickey subsystem",
|
||||||
|
0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = session->pkeyInit_data;
|
s = session->pkeyInit_data;
|
||||||
if ((response = libssh2_publickey_response_id(&s, session->pkeyInit_data_len)) < 0) {
|
if ((response =
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Invalid publickey subsystem response code", 0);
|
libssh2_publickey_response_id(&s,
|
||||||
|
session->pkeyInit_data_len)) <
|
||||||
|
0) {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Invalid publickey subsystem response code", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,30 +502,44 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
unsigned long status, descr_len, lang_len;
|
unsigned long status, descr_len, lang_len;
|
||||||
unsigned char *descr, *lang;
|
unsigned char *descr, *lang;
|
||||||
|
|
||||||
status = libssh2_ntohu32(s); s += 4;
|
status = libssh2_ntohu32(s);
|
||||||
descr_len = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
descr = s; s += descr_len;
|
descr_len = libssh2_ntohu32(s);
|
||||||
lang_len = libssh2_ntohu32(s); s += 4;
|
s += 4;
|
||||||
lang = s; s += lang_len;
|
descr = s;
|
||||||
|
s += descr_len;
|
||||||
|
lang_len = libssh2_ntohu32(s);
|
||||||
|
s += 4;
|
||||||
|
lang = s;
|
||||||
|
s += lang_len;
|
||||||
|
|
||||||
if (s > session->pkeyInit_data + session->pkeyInit_data_len) {
|
if (s >
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Malformed publickey subsystem packet", 0);
|
session->pkeyInit_data + session->pkeyInit_data_len) {
|
||||||
|
libssh2_error(session,
|
||||||
|
LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Malformed publickey subsystem packet",
|
||||||
|
0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_publickey_status_error(NULL, session, status, descr, descr_len);
|
libssh2_publickey_status_error(NULL, session, status,
|
||||||
|
descr, descr_len);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LIBSSH2_PUBLICKEY_RESPONSE_VERSION:
|
case LIBSSH2_PUBLICKEY_RESPONSE_VERSION:
|
||||||
/* What we want */
|
/* What we want */
|
||||||
session->pkeyInit_pkey->version = libssh2_ntohu32(s);
|
session->pkeyInit_pkey->version = libssh2_ntohu32(s);
|
||||||
if (session->pkeyInit_pkey->version > LIBSSH2_PUBLICKEY_VERSION) {
|
if (session->pkeyInit_pkey->version >
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Truncating remote publickey version from %lu",
|
LIBSSH2_PUBLICKEY_VERSION) {
|
||||||
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Truncating remote publickey version from %lu",
|
||||||
session->pkeyInit_pkey->version);
|
session->pkeyInit_pkey->version);
|
||||||
session->pkeyInit_pkey->version = LIBSSH2_PUBLICKEY_VERSION;
|
session->pkeyInit_pkey->version =
|
||||||
|
LIBSSH2_PUBLICKEY_VERSION;
|
||||||
}
|
}
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Enabling publickey subsystem version %lu",
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Enabling publickey subsystem version %lu",
|
||||||
session->pkeyInit_pkey->version);
|
session->pkeyInit_pkey->version);
|
||||||
LIBSSH2_FREE(session, session->pkeyInit_data);
|
LIBSSH2_FREE(session, session->pkeyInit_data);
|
||||||
session->pkeyInit_data = NULL;
|
session->pkeyInit_data = NULL;
|
||||||
@@ -448,7 +549,8 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
default:
|
default:
|
||||||
/* Unknown/Unexpected */
|
/* Unknown/Unexpected */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
"Unexpected publickey subsystem response, ignoring", 0);
|
"Unexpected publickey subsystem response, ignoring",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, session->pkeyInit_data);
|
LIBSSH2_FREE(session, session->pkeyInit_data);
|
||||||
session->pkeyInit_data = NULL;
|
session->pkeyInit_data = NULL;
|
||||||
}
|
}
|
||||||
@@ -461,7 +563,8 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
if (session->pkeyInit_channel) {
|
if (session->pkeyInit_channel) {
|
||||||
rc = libssh2_channel_close(session->pkeyInit_channel);
|
rc = libssh2_channel_close(session->pkeyInit_channel);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block closing channel", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block closing channel", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,14 +579,17 @@ LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session)
|
|||||||
session->pkeyInit_state = libssh2_NB_state_idle;
|
session->pkeyInit_state = libssh2_NB_state_idle;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_add_ex
|
/* {{{ libssh2_publickey_add_ex
|
||||||
* Add a new public key entry
|
* Add a new public key entry
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int
|
LIBSSH2_API int
|
||||||
libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, unsigned long name_len,
|
libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
|
||||||
const unsigned char *blob, unsigned long blob_len, char overwrite, unsigned long num_attrs,
|
unsigned long name_len, const unsigned char *blob,
|
||||||
|
unsigned long blob_len, char overwrite,
|
||||||
|
unsigned long num_attrs,
|
||||||
const libssh2_publickey_attribute attrs[])
|
const libssh2_publickey_attribute attrs[])
|
||||||
{
|
{
|
||||||
LIBSSH2_CHANNEL *channel = pkey->channel;
|
LIBSSH2_CHANNEL *channel = pkey->channel;
|
||||||
@@ -497,13 +603,15 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, uns
|
|||||||
if (pkey->add_state == libssh2_NB_state_idle) {
|
if (pkey->add_state == libssh2_NB_state_idle) {
|
||||||
pkey->add_packet = NULL;
|
pkey->add_packet = NULL;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Adding %s publickey", name);
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Adding %s publickey",
|
||||||
|
name);
|
||||||
|
|
||||||
if (pkey->version == 1) {
|
if (pkey->version == 1) {
|
||||||
for(i = 0; i < num_attrs; i++) {
|
for(i = 0; i < num_attrs; i++) {
|
||||||
/* Search for a comment attribute */
|
/* Search for a comment attribute */
|
||||||
if (attrs[i].name_len == (sizeof("comment") - 1) &&
|
if (attrs[i].name_len == (sizeof("comment") - 1) &&
|
||||||
strncmp(attrs[i].name, "comment", sizeof("comment") - 1) == 0) {
|
strncmp(attrs[i].name, "comment",
|
||||||
|
sizeof("comment") - 1) == 0) {
|
||||||
comment = (unsigned char *) attrs[i].value;
|
comment = (unsigned char *) attrs[i].value;
|
||||||
comment_len = attrs[i].value_len;
|
comment_len = attrs[i].value_len;
|
||||||
break;
|
break;
|
||||||
@@ -520,55 +628,77 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, uns
|
|||||||
|
|
||||||
pkey->add_packet = LIBSSH2_ALLOC(session, packet_len);
|
pkey->add_packet = LIBSSH2_ALLOC(session, packet_len);
|
||||||
if (!pkey->add_packet) {
|
if (!pkey->add_packet) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for publickey \"add\" packet", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for publickey \"add\" packet",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkey->add_s = pkey->add_packet;
|
pkey->add_s = pkey->add_packet;
|
||||||
libssh2_htonu32(pkey->add_s, packet_len - 4); pkey->add_s += 4;
|
libssh2_htonu32(pkey->add_s, packet_len - 4);
|
||||||
libssh2_htonu32(pkey->add_s, sizeof("add") - 1); pkey->add_s += 4;
|
pkey->add_s += 4;
|
||||||
memcpy(pkey->add_s, "add", sizeof("add") - 1); pkey->add_s += sizeof("add") - 1;
|
libssh2_htonu32(pkey->add_s, sizeof("add") - 1);
|
||||||
|
pkey->add_s += 4;
|
||||||
|
memcpy(pkey->add_s, "add", sizeof("add") - 1);
|
||||||
|
pkey->add_s += sizeof("add") - 1;
|
||||||
if (pkey->version == 1) {
|
if (pkey->version == 1) {
|
||||||
libssh2_htonu32(pkey->add_s, comment_len); pkey->add_s += 4;
|
libssh2_htonu32(pkey->add_s, comment_len);
|
||||||
|
pkey->add_s += 4;
|
||||||
if (comment) {
|
if (comment) {
|
||||||
memcpy(pkey->add_s, comment, comment_len); pkey->add_s += comment_len;
|
memcpy(pkey->add_s, comment, comment_len);
|
||||||
|
pkey->add_s += comment_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_htonu32(pkey->add_s, name_len); pkey->add_s += 4;
|
libssh2_htonu32(pkey->add_s, name_len);
|
||||||
memcpy(pkey->add_s, name, name_len); pkey->add_s += name_len;
|
pkey->add_s += 4;
|
||||||
libssh2_htonu32(pkey->add_s, blob_len); pkey->add_s += 4;
|
memcpy(pkey->add_s, name, name_len);
|
||||||
memcpy(pkey->add_s, blob, blob_len); pkey->add_s += blob_len;
|
pkey->add_s += name_len;
|
||||||
|
libssh2_htonu32(pkey->add_s, blob_len);
|
||||||
|
pkey->add_s += 4;
|
||||||
|
memcpy(pkey->add_s, blob, blob_len);
|
||||||
|
pkey->add_s += blob_len;
|
||||||
} else {
|
} else {
|
||||||
/* Version == 2 */
|
/* Version == 2 */
|
||||||
|
|
||||||
libssh2_htonu32(pkey->add_s, name_len); pkey->add_s += 4;
|
libssh2_htonu32(pkey->add_s, name_len);
|
||||||
memcpy(pkey->add_s, name, name_len); pkey->add_s += name_len;
|
pkey->add_s += 4;
|
||||||
libssh2_htonu32(pkey->add_s, blob_len); pkey->add_s += 4;
|
memcpy(pkey->add_s, name, name_len);
|
||||||
memcpy(pkey->add_s, blob, blob_len); pkey->add_s += blob_len;
|
pkey->add_s += name_len;
|
||||||
|
libssh2_htonu32(pkey->add_s, blob_len);
|
||||||
|
pkey->add_s += 4;
|
||||||
|
memcpy(pkey->add_s, blob, blob_len);
|
||||||
|
pkey->add_s += blob_len;
|
||||||
*(pkey->add_s++) = overwrite ? 0x01 : 0;
|
*(pkey->add_s++) = overwrite ? 0x01 : 0;
|
||||||
libssh2_htonu32(pkey->add_s, num_attrs); pkey->add_s += 4;
|
libssh2_htonu32(pkey->add_s, num_attrs);
|
||||||
|
pkey->add_s += 4;
|
||||||
for(i = 0; i < num_attrs; i++) {
|
for(i = 0; i < num_attrs; i++) {
|
||||||
libssh2_htonu32(pkey->add_s, attrs[i].name_len); pkey->add_s += 4;
|
libssh2_htonu32(pkey->add_s, attrs[i].name_len);
|
||||||
memcpy(pkey->add_s, attrs[i].name, attrs[i].name_len); pkey->add_s += attrs[i].name_len;
|
pkey->add_s += 4;
|
||||||
libssh2_htonu32(pkey->add_s, attrs[i].value_len); pkey->add_s += 4;
|
memcpy(pkey->add_s, attrs[i].name, attrs[i].name_len);
|
||||||
memcpy(pkey->add_s, attrs[i].value, attrs[i].value_len); pkey->add_s += attrs[i].value_len;
|
pkey->add_s += attrs[i].name_len;
|
||||||
|
libssh2_htonu32(pkey->add_s, attrs[i].value_len);
|
||||||
|
pkey->add_s += 4;
|
||||||
|
memcpy(pkey->add_s, attrs[i].value, attrs[i].value_len);
|
||||||
|
pkey->add_s += attrs[i].value_len;
|
||||||
*(pkey->add_s++) = attrs[i].mandatory ? 0x01 : 0;
|
*(pkey->add_s++) = attrs[i].mandatory ? 0x01 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Sending publickey \"add\" packet: type=%s blob_len=%ld num_attrs=%ld",
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Sending publickey \"add\" packet: type=%s blob_len=%ld num_attrs=%ld",
|
||||||
name, blob_len, num_attrs);
|
name, blob_len, num_attrs);
|
||||||
|
|
||||||
pkey->add_state = libssh2_NB_state_created;
|
pkey->add_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkey->add_state == libssh2_NB_state_created) {
|
if (pkey->add_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *)pkey->add_packet, (pkey->add_s - pkey->add_packet));
|
rc = libssh2_channel_write_ex(channel, 0, (char *) pkey->add_packet,
|
||||||
|
(pkey->add_s - pkey->add_packet));
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if ((pkey->add_s - pkey->add_packet) != rc) {
|
||||||
else if ((pkey->add_s - pkey->add_packet) != rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey add packet", 0);
|
"Unable to send publickey add packet", 0);
|
||||||
LIBSSH2_FREE(session, pkey->add_packet);
|
LIBSSH2_FREE(session, pkey->add_packet);
|
||||||
pkey->add_packet = NULL;
|
pkey->add_packet = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -588,13 +718,15 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, uns
|
|||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_remove_ex
|
/* {{{ libssh2_publickey_remove_ex
|
||||||
* Remove an existing publickey so that authentication can no longer be performed using it
|
* Remove an existing publickey so that authentication can no longer be performed using it
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int
|
LIBSSH2_API int
|
||||||
libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, unsigned long name_len,
|
libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
|
||||||
|
const unsigned char *name, unsigned long name_len,
|
||||||
const unsigned char *blob, unsigned long blob_len)
|
const unsigned char *blob, unsigned long blob_len)
|
||||||
{
|
{
|
||||||
LIBSSH2_CHANNEL *channel = pkey->channel;
|
LIBSSH2_CHANNEL *channel = pkey->channel;
|
||||||
@@ -608,31 +740,43 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
|
|||||||
|
|
||||||
pkey->remove_packet = LIBSSH2_ALLOC(session, packet_len);
|
pkey->remove_packet = LIBSSH2_ALLOC(session, packet_len);
|
||||||
if (!pkey->remove_packet) {
|
if (!pkey->remove_packet) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for publickey \"remove\" packet", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for publickey \"remove\" packet",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkey->remove_s = pkey->remove_packet;
|
pkey->remove_s = pkey->remove_packet;
|
||||||
libssh2_htonu32(pkey->remove_s, packet_len - 4); pkey->remove_s += 4;
|
libssh2_htonu32(pkey->remove_s, packet_len - 4);
|
||||||
libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1); pkey->remove_s += 4;
|
pkey->remove_s += 4;
|
||||||
memcpy(pkey->remove_s, "remove", sizeof("remove") - 1); pkey->remove_s += sizeof("remove") - 1;
|
libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1);
|
||||||
libssh2_htonu32(pkey->remove_s, name_len); pkey->remove_s += 4;
|
pkey->remove_s += 4;
|
||||||
memcpy(pkey->remove_s, name, name_len); pkey->remove_s += name_len;
|
memcpy(pkey->remove_s, "remove", sizeof("remove") - 1);
|
||||||
libssh2_htonu32(pkey->remove_s, blob_len); pkey->remove_s += 4;
|
pkey->remove_s += sizeof("remove") - 1;
|
||||||
memcpy(pkey->remove_s, blob, blob_len); pkey->remove_s += blob_len;
|
libssh2_htonu32(pkey->remove_s, name_len);
|
||||||
|
pkey->remove_s += 4;
|
||||||
|
memcpy(pkey->remove_s, name, name_len);
|
||||||
|
pkey->remove_s += name_len;
|
||||||
|
libssh2_htonu32(pkey->remove_s, blob_len);
|
||||||
|
pkey->remove_s += 4;
|
||||||
|
memcpy(pkey->remove_s, blob, blob_len);
|
||||||
|
pkey->remove_s += blob_len;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Sending publickey \"remove\" packet: type=%s blob_len=%ld", name, blob_len);
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Sending publickey \"remove\" packet: type=%s blob_len=%ld",
|
||||||
|
name, blob_len);
|
||||||
|
|
||||||
pkey->remove_state = libssh2_NB_state_created;
|
pkey->remove_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkey->remove_state == libssh2_NB_state_created) {
|
if (pkey->remove_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *)pkey->remove_packet, (pkey->remove_s - pkey->remove_packet));
|
rc = libssh2_channel_write_ex(channel, 0, (char *) pkey->remove_packet,
|
||||||
|
(pkey->remove_s - pkey->remove_packet));
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if ((pkey->remove_s - pkey->remove_packet) != rc) {
|
||||||
else if ((pkey->remove_s - pkey->remove_packet) != rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey remove packet", 0);
|
"Unable to send publickey remove packet", 0);
|
||||||
LIBSSH2_FREE(session, pkey->remove_packet);
|
LIBSSH2_FREE(session, pkey->remove_packet);
|
||||||
pkey->remove_packet = NULL;
|
pkey->remove_packet = NULL;
|
||||||
pkey->remove_state = libssh2_NB_state_idle;
|
pkey->remove_state = libssh2_NB_state_idle;
|
||||||
@@ -653,13 +797,15 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
|
|||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_list_fetch
|
/* {{{ libssh2_publickey_list_fetch
|
||||||
* Fetch a list of supported public key from a server
|
* Fetch a list of supported public key from a server
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int
|
LIBSSH2_API int
|
||||||
libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, libssh2_publickey_list **pkey_list)
|
libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
|
||||||
|
libssh2_publickey_list ** pkey_list)
|
||||||
{
|
{
|
||||||
LIBSSH2_CHANNEL *channel = pkey->channel;
|
LIBSSH2_CHANNEL *channel = pkey->channel;
|
||||||
LIBSSH2_SESSION *session = channel->session;
|
LIBSSH2_SESSION *session = channel->session;
|
||||||
@@ -673,22 +819,29 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
pkey->listFetch_data = NULL;
|
pkey->listFetch_data = NULL;
|
||||||
|
|
||||||
pkey->listFetch_s = pkey->listFetch_buffer;
|
pkey->listFetch_s = pkey->listFetch_buffer;
|
||||||
libssh2_htonu32(pkey->listFetch_s, buffer_len - 4); pkey->listFetch_s += 4;
|
libssh2_htonu32(pkey->listFetch_s, buffer_len - 4);
|
||||||
libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1); pkey->listFetch_s += 4;
|
pkey->listFetch_s += 4;
|
||||||
memcpy(pkey->listFetch_s, "list", sizeof("list") - 1); pkey->listFetch_s += sizeof("list") - 1;
|
libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1);
|
||||||
|
pkey->listFetch_s += 4;
|
||||||
|
memcpy(pkey->listFetch_s, "list", sizeof("list") - 1);
|
||||||
|
pkey->listFetch_s += sizeof("list") - 1;
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY, "Sending publickey \"list\" packet");
|
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
|
||||||
|
"Sending publickey \"list\" packet");
|
||||||
|
|
||||||
pkey->listFetch_state = libssh2_NB_state_created;
|
pkey->listFetch_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkey->listFetch_state == libssh2_NB_state_created) {
|
if (pkey->listFetch_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *)pkey->listFetch_buffer, (pkey->listFetch_s - pkey->listFetch_buffer));
|
rc = libssh2_channel_write_ex(channel, 0,
|
||||||
|
(char *) pkey->listFetch_buffer,
|
||||||
|
(pkey->listFetch_s -
|
||||||
|
pkey->listFetch_buffer));
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) {
|
||||||
else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey list packet", 0);
|
"Unable to send publickey list packet", 0);
|
||||||
pkey->listFetch_state = libssh2_NB_state_idle;
|
pkey->listFetch_state = libssh2_NB_state_idle;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -697,18 +850,23 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = libssh2_publickey_packet_receive(pkey, &pkey->listFetch_data, &pkey->listFetch_data_len);
|
rc = libssh2_publickey_packet_receive(pkey, &pkey->listFetch_data,
|
||||||
|
&pkey->listFetch_data_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for response from publickey subsystem", 0);
|
"Timeout waiting for response from publickey subsystem",
|
||||||
|
0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkey->listFetch_s = pkey->listFetch_data;
|
pkey->listFetch_s = pkey->listFetch_data;
|
||||||
if ((response = libssh2_publickey_response_id(&pkey->listFetch_s, pkey->listFetch_data_len)) < 0) {
|
if ((response =
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Invalid publickey subsystem response code", 0);
|
libssh2_publickey_response_id(&pkey->listFetch_s,
|
||||||
|
pkey->listFetch_data_len)) < 0) {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Invalid publickey subsystem response code", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,14 +877,21 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
unsigned long status, descr_len, lang_len;
|
unsigned long status, descr_len, lang_len;
|
||||||
unsigned char *descr, *lang;
|
unsigned char *descr, *lang;
|
||||||
|
|
||||||
status = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
status = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
descr_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
pkey->listFetch_s += 4;
|
||||||
descr = pkey->listFetch_s; pkey->listFetch_s += descr_len;
|
descr_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
lang_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
pkey->listFetch_s += 4;
|
||||||
lang = pkey->listFetch_s; pkey->listFetch_s += lang_len;
|
descr = pkey->listFetch_s;
|
||||||
|
pkey->listFetch_s += descr_len;
|
||||||
|
lang_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
|
pkey->listFetch_s += 4;
|
||||||
|
lang = pkey->listFetch_s;
|
||||||
|
pkey->listFetch_s += lang_len;
|
||||||
|
|
||||||
if (pkey->listFetch_s > pkey->listFetch_data + pkey->listFetch_data_len) {
|
if (pkey->listFetch_s >
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Malformed publickey subsystem packet", 0);
|
pkey->listFetch_data + pkey->listFetch_data_len) {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Malformed publickey subsystem packet", 0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,7 +904,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_publickey_status_error(pkey, session, status, descr, descr_len);
|
libssh2_publickey_status_error(pkey, session, status, descr,
|
||||||
|
descr_len);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY:
|
case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY:
|
||||||
@@ -748,9 +914,14 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
libssh2_publickey_list *newlist;
|
libssh2_publickey_list *newlist;
|
||||||
/* Grow the key list if necessary */
|
/* Grow the key list if necessary */
|
||||||
max_keys += 8;
|
max_keys += 8;
|
||||||
newlist = LIBSSH2_REALLOC(session, list, (max_keys + 1) * sizeof(libssh2_publickey_list));
|
newlist =
|
||||||
|
LIBSSH2_REALLOC(session, list,
|
||||||
|
(max_keys +
|
||||||
|
1) * sizeof(libssh2_publickey_list));
|
||||||
if (!newlist) {
|
if (!newlist) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for publickey list", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for publickey list",
|
||||||
|
0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
list = newlist;
|
list = newlist;
|
||||||
@@ -758,12 +929,17 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
if (pkey->version == 1) {
|
if (pkey->version == 1) {
|
||||||
unsigned long comment_len;
|
unsigned long comment_len;
|
||||||
|
|
||||||
comment_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
comment_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
|
pkey->listFetch_s += 4;
|
||||||
if (comment_len) {
|
if (comment_len) {
|
||||||
list[keys].num_attrs = 1;
|
list[keys].num_attrs = 1;
|
||||||
list[keys].attrs = LIBSSH2_ALLOC(session, sizeof(libssh2_publickey_attribute));
|
list[keys].attrs =
|
||||||
|
LIBSSH2_ALLOC(session,
|
||||||
|
sizeof(libssh2_publickey_attribute));
|
||||||
if (!list[keys].attrs) {
|
if (!list[keys].attrs) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for publickey attributes", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for publickey attributes",
|
||||||
|
0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
list[keys].attrs[0].name = "comment";
|
list[keys].attrs[0].name = "comment";
|
||||||
@@ -777,29 +953,45 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
list[keys].num_attrs = 0;
|
list[keys].num_attrs = 0;
|
||||||
list[keys].attrs = NULL;
|
list[keys].attrs = NULL;
|
||||||
}
|
}
|
||||||
list[keys].name_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
list[keys].name_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
list[keys].name = pkey->listFetch_s; pkey->listFetch_s += list[keys].name_len;
|
pkey->listFetch_s += 4;
|
||||||
list[keys].blob_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
list[keys].name = pkey->listFetch_s;
|
||||||
list[keys].blob = pkey->listFetch_s; pkey->listFetch_s += list[keys].blob_len;
|
pkey->listFetch_s += list[keys].name_len;
|
||||||
|
list[keys].blob_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
|
pkey->listFetch_s += 4;
|
||||||
|
list[keys].blob = pkey->listFetch_s;
|
||||||
|
pkey->listFetch_s += list[keys].blob_len;
|
||||||
} else {
|
} else {
|
||||||
/* Version == 2 */
|
/* Version == 2 */
|
||||||
list[keys].name_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
list[keys].name_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
list[keys].name = pkey->listFetch_s; pkey->listFetch_s += list[keys].name_len;
|
pkey->listFetch_s += 4;
|
||||||
list[keys].blob_len = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
list[keys].name = pkey->listFetch_s;
|
||||||
list[keys].blob = pkey->listFetch_s; pkey->listFetch_s += list[keys].blob_len;
|
pkey->listFetch_s += list[keys].name_len;
|
||||||
list[keys].num_attrs = libssh2_ntohu32(pkey->listFetch_s); pkey->listFetch_s += 4;
|
list[keys].blob_len = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
|
pkey->listFetch_s += 4;
|
||||||
|
list[keys].blob = pkey->listFetch_s;
|
||||||
|
pkey->listFetch_s += list[keys].blob_len;
|
||||||
|
list[keys].num_attrs = libssh2_ntohu32(pkey->listFetch_s);
|
||||||
|
pkey->listFetch_s += 4;
|
||||||
if (list[keys].num_attrs) {
|
if (list[keys].num_attrs) {
|
||||||
list[keys].attrs = LIBSSH2_ALLOC(session, list[keys].num_attrs * sizeof(libssh2_publickey_attribute));
|
list[keys].attrs =
|
||||||
|
LIBSSH2_ALLOC(session,
|
||||||
|
list[keys].num_attrs *
|
||||||
|
sizeof(libssh2_publickey_attribute));
|
||||||
if (!list[keys].attrs) {
|
if (!list[keys].attrs) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for publickey attributes", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for publickey attributes",
|
||||||
|
0);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
for(i = 0; i < list[keys].num_attrs; i++) {
|
for(i = 0; i < list[keys].num_attrs; i++) {
|
||||||
list[keys].attrs[i].name_len = libssh2_ntohu32(pkey->listFetch_s);
|
list[keys].attrs[i].name_len =
|
||||||
|
libssh2_ntohu32(pkey->listFetch_s);
|
||||||
pkey->listFetch_s += 4;
|
pkey->listFetch_s += 4;
|
||||||
list[keys].attrs[i].name = (char *) pkey->listFetch_s;
|
list[keys].attrs[i].name = (char *) pkey->listFetch_s;
|
||||||
pkey->listFetch_s += list[keys].attrs[i].name_len;
|
pkey->listFetch_s += list[keys].attrs[i].name_len;
|
||||||
list[keys].attrs[i].value_len = libssh2_ntohu32(pkey->listFetch_s);
|
list[keys].attrs[i].value_len =
|
||||||
|
libssh2_ntohu32(pkey->listFetch_s);
|
||||||
pkey->listFetch_s += 4;
|
pkey->listFetch_s += 4;
|
||||||
list[keys].attrs[i].value = (char *) pkey->listFetch_s;
|
list[keys].attrs[i].value = (char *) pkey->listFetch_s;
|
||||||
pkey->listFetch_s += list[keys].attrs[i].value_len;
|
pkey->listFetch_s += list[keys].attrs[i].value_len;
|
||||||
@@ -817,7 +1009,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Unknown/Unexpected */
|
/* Unknown/Unexpected */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Unexpected publickey subsystem response, ignoring", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
|
||||||
|
"Unexpected publickey subsystem response, ignoring",
|
||||||
|
0);
|
||||||
LIBSSH2_FREE(session, pkey->listFetch_data);
|
LIBSSH2_FREE(session, pkey->listFetch_data);
|
||||||
pkey->listFetch_data = NULL;
|
pkey->listFetch_data = NULL;
|
||||||
}
|
}
|
||||||
@@ -835,12 +1029,15 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, l
|
|||||||
pkey->listFetch_state = libssh2_NB_state_idle;
|
pkey->listFetch_state = libssh2_NB_state_idle;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_list_free
|
/* {{{ libssh2_publickey_list_free
|
||||||
* Free a previously fetched list of public keys
|
* Free a previously fetched list of public keys
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API void libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey, libssh2_publickey_list *pkey_list)
|
LIBSSH2_API void
|
||||||
|
libssh2_publickey_list_free(LIBSSH2_PUBLICKEY * pkey,
|
||||||
|
libssh2_publickey_list * pkey_list)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = pkey->channel->session;
|
LIBSSH2_SESSION *session = pkey->channel->session;
|
||||||
libssh2_publickey_list *p = pkey_list;
|
libssh2_publickey_list *p = pkey_list;
|
||||||
@@ -855,12 +1052,14 @@ LIBSSH2_API void libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey, libssh2_pu
|
|||||||
|
|
||||||
LIBSSH2_FREE(session, pkey_list);
|
LIBSSH2_FREE(session, pkey_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_publickey_shutdown
|
/* {{{ libssh2_publickey_shutdown
|
||||||
* Shutdown the publickey subsystem
|
* Shutdown the publickey subsystem
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey)
|
LIBSSH2_API int
|
||||||
|
libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY * pkey)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = pkey->channel->session;
|
LIBSSH2_SESSION *session = pkey->channel->session;
|
||||||
|
|
||||||
@@ -891,4 +1090,5 @@ LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey)
|
|||||||
LIBSSH2_FREE(session, pkey);
|
LIBSSH2_FREE(session, pkey);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
467
src/scp.c
467
src/scp.c
@@ -46,7 +46,8 @@
|
|||||||
* otherwise the blocking error code would erase the true
|
* otherwise the blocking error code would erase the true
|
||||||
* cause of the error.
|
* cause of the error.
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb)
|
LIBSSH2_API LIBSSH2_CHANNEL *
|
||||||
|
libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
||||||
{
|
{
|
||||||
int path_len = strlen(path);
|
int path_len = strlen(path);
|
||||||
int rc;
|
int rc;
|
||||||
@@ -63,21 +64,28 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
session->scpRecv_command_len++;
|
session->scpRecv_command_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpRecv_command = LIBSSH2_ALLOC(session, session->scpRecv_command_len);
|
session->scpRecv_command =
|
||||||
|
LIBSSH2_ALLOC(session, session->scpRecv_command_len);
|
||||||
if (!session->scpRecv_command) {
|
if (!session->scpRecv_command) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a command buffer for SCP session", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate a command buffer for SCP session",
|
||||||
|
0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sb) {
|
if (sb) {
|
||||||
memcpy(session->scpRecv_command, "scp -pf ", sizeof("scp -pf ") - 1);
|
memcpy(session->scpRecv_command, "scp -pf ",
|
||||||
memcpy(session->scpRecv_command + sizeof("scp -pf ") - 1, path, path_len);
|
sizeof("scp -pf ") - 1);
|
||||||
|
memcpy(session->scpRecv_command + sizeof("scp -pf ") - 1, path,
|
||||||
|
path_len);
|
||||||
} else {
|
} else {
|
||||||
memcpy(session->scpRecv_command, "scp -f ", sizeof("scp -f ") - 1);
|
memcpy(session->scpRecv_command, "scp -f ", sizeof("scp -f ") - 1);
|
||||||
memcpy(session->scpRecv_command + sizeof("scp -f ") - 1, path, path_len);
|
memcpy(session->scpRecv_command + sizeof("scp -f ") - 1, path,
|
||||||
|
path_len);
|
||||||
}
|
}
|
||||||
session->scpRecv_command[session->scpRecv_command_len - 1] = '\0';
|
session->scpRecv_command[session->scpRecv_command_len - 1] = '\0';
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Opening channel for SCP receive");
|
_libssh2_debug(session, LIBSSH2_DBG_SCP,
|
||||||
|
"Opening channel for SCP receive");
|
||||||
|
|
||||||
session->scpRecv_state = libssh2_NB_state_created;
|
session->scpRecv_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
@@ -85,18 +93,23 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
if (session->scpRecv_state == libssh2_NB_state_created) {
|
if (session->scpRecv_state == libssh2_NB_state_created) {
|
||||||
/* Allocate a channel */
|
/* Allocate a channel */
|
||||||
do {
|
do {
|
||||||
session->scpRecv_channel = libssh2_channel_open_ex(session, "session", sizeof("session") - 1,
|
session->scpRecv_channel =
|
||||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT,
|
libssh2_channel_open_ex(session, "session",
|
||||||
NULL, 0);
|
sizeof("session") - 1,
|
||||||
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||||
|
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL,
|
||||||
|
0);
|
||||||
if (!session->scpRecv_channel) {
|
if (!session->scpRecv_channel) {
|
||||||
if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
if (libssh2_session_last_errno(session) !=
|
||||||
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
LIBSSH2_FREE(session, session->scpRecv_command);
|
LIBSSH2_FREE(session, session->scpRecv_command);
|
||||||
session->scpRecv_command = NULL;
|
session->scpRecv_command = NULL;
|
||||||
session->scpRecv_state = libssh2_NB_state_idle;
|
session->scpRecv_state = libssh2_NB_state_idle;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (libssh2_session_last_errno(session) ==
|
||||||
else if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block starting up channel", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block starting up channel", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,12 +120,15 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent) {
|
if (session->scpRecv_state == libssh2_NB_state_sent) {
|
||||||
/* Request SCP for the desired file */
|
/* Request SCP for the desired file */
|
||||||
rc = libssh2_channel_process_startup(session->scpRecv_channel, "exec", sizeof("exec") - 1, (char *)session->scpRecv_command, session->scpRecv_command_len);
|
rc = libssh2_channel_process_startup(session->scpRecv_channel, "exec",
|
||||||
|
sizeof("exec") - 1,
|
||||||
|
(char *) session->scpRecv_command,
|
||||||
|
session->scpRecv_command_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block requesting SCP startup", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block requesting SCP startup", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
LIBSSH2_FREE(session, session->scpRecv_command);
|
LIBSSH2_FREE(session, session->scpRecv_command);
|
||||||
session->scpRecv_command = NULL;
|
session->scpRecv_command = NULL;
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
@@ -128,12 +144,13 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent1) {
|
if (session->scpRecv_state == libssh2_NB_state_sent1) {
|
||||||
rc = libssh2_channel_write_ex(session->scpRecv_channel, 0, (char *)session->scpRecv_response, 1);
|
rc = libssh2_channel_write_ex(session->scpRecv_channel, 0,
|
||||||
|
(char *) session->scpRecv_response, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending initial wakeup", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block sending initial wakeup", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc != 1) {
|
||||||
else if (rc != 1) {
|
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,43 +160,104 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
session->scpRecv_state = libssh2_NB_state_sent2;
|
session->scpRecv_state = libssh2_NB_state_sent2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((session->scpRecv_state == libssh2_NB_state_sent2) || (session->scpRecv_state == libssh2_NB_state_sent3)) {
|
if ((session->scpRecv_state == libssh2_NB_state_sent2)
|
||||||
while (sb && (session->scpRecv_response_len < LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
|| (session->scpRecv_state == libssh2_NB_state_sent3)) {
|
||||||
|
while (sb
|
||||||
|
&& (session->scpRecv_response_len <
|
||||||
|
LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
||||||
unsigned char *s, *p;
|
unsigned char *s, *p;
|
||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent2) {
|
if (session->scpRecv_state == libssh2_NB_state_sent2) {
|
||||||
rc = libssh2_channel_read_ex(session->scpRecv_channel, 0,
|
rc = libssh2_channel_read_ex(session->scpRecv_channel, 0,
|
||||||
(char *)session->scpRecv_response + session->scpRecv_response_len, 1);
|
(char *) session->
|
||||||
|
scpRecv_response +
|
||||||
|
session->scpRecv_response_len, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for SCP response", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc <= 0) {
|
||||||
else if (rc <= 0) {
|
|
||||||
/* Timeout, give up */
|
/* Timeout, give up */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Timed out waiting for SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Timed out waiting for SCP response", 0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
session->scpRecv_response_len++;
|
session->scpRecv_response_len++;
|
||||||
|
|
||||||
if (session->scpRecv_response[0] != 'T') {
|
if (session->scpRecv_response[0] != 'T') {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response, missing Time data", 0);
|
/*
|
||||||
|
* Set this as the default error for here, if
|
||||||
|
* we are successful it will be replaced
|
||||||
|
*/
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid data in SCP response, missing Time data",
|
||||||
|
0);
|
||||||
|
|
||||||
|
session->scpRecv_err_len =
|
||||||
|
libssh2_channel_packet_data_len(session->
|
||||||
|
scpRecv_channel, 0);
|
||||||
|
session->scpRecv_err_msg =
|
||||||
|
LIBSSH2_ALLOC(session, session->scpRecv_err_len + 1);
|
||||||
|
if (!session->scpRecv_err_msg) {
|
||||||
|
goto scp_recv_error;
|
||||||
|
}
|
||||||
|
memset(session->scpRecv_err_msg, 0,
|
||||||
|
session->scpRecv_err_len + 1);
|
||||||
|
|
||||||
|
/* Read the remote error message */
|
||||||
|
rc = libssh2_channel_read_ex(session->scpRecv_channel, 0,
|
||||||
|
session->scpRecv_err_msg,
|
||||||
|
session->scpRecv_err_len);
|
||||||
|
if (rc <= 0) {
|
||||||
|
/*
|
||||||
|
* Since we have alread started reading this packet, it is
|
||||||
|
* already in the systems so it can't return PACKET_EAGAIN
|
||||||
|
*/
|
||||||
|
LIBSSH2_FREE(session, session->scpRecv_err_msg);
|
||||||
|
session->scpRecv_err_msg = NULL;
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Unknown error while getting error string",
|
||||||
|
0);
|
||||||
|
goto scp_recv_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
session->scpRecv_err_msg, 1);
|
||||||
|
session->scpRecv_err_msg = NULL;
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((session->scpRecv_response_len > 1) &&
|
if ((session->scpRecv_response_len > 1) &&
|
||||||
((session->scpRecv_response[session->scpRecv_response_len-1] < '0') ||
|
((session->
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] > '9')) &&
|
scpRecv_response[session->scpRecv_response_len - 1] <
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] != ' ') &&
|
'0')
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] != '\r') &&
|
|| (session->
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] != '\n')) {
|
scpRecv_response[session->scpRecv_response_len - 1] >
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response", 0);
|
'9'))
|
||||||
|
&& (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
|
' ')
|
||||||
|
&& (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
|
'\r')
|
||||||
|
&& (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
|
'\n')) {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid data in SCP response", 0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((session->scpRecv_response_len < 9) || (session->scpRecv_response[session->scpRecv_response_len-1] != '\n')) {
|
if ((session->scpRecv_response_len < 9)
|
||||||
if (session->scpRecv_response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
|| (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
|
'\n')) {
|
||||||
|
if (session->scpRecv_response_len ==
|
||||||
|
LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||||
/* You had your chance */
|
/* You had your chance */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unterminated response from SCP server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Unterminated response from SCP server",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
/* Way too short to be an SCP response, or not done yet, short circuit */
|
/* Way too short to be an SCP response, or not done yet, short circuit */
|
||||||
@@ -187,12 +265,21 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
||||||
while ((session->scpRecv_response[session->scpRecv_response_len-1] == '\r') || (session->scpRecv_response[session->scpRecv_response_len-1] == '\n')) session->scpRecv_response_len--;
|
while ((session->
|
||||||
session->scpRecv_response[session->scpRecv_response_len] = '\0';
|
scpRecv_response[session->scpRecv_response_len - 1] ==
|
||||||
|
'\r')
|
||||||
|
|| (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len -
|
||||||
|
1] == '\n'))
|
||||||
|
session->scpRecv_response_len--;
|
||||||
|
session->scpRecv_response[session->scpRecv_response_len] =
|
||||||
|
'\0';
|
||||||
|
|
||||||
if (session->scpRecv_response_len < 8) {
|
if (session->scpRecv_response_len < 8) {
|
||||||
/* EOL came too soon */
|
/* EOL came too soon */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, too short",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +288,9 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
p = (unsigned char *) strchr((char *) s, ' ');
|
p = (unsigned char *) strchr((char *) s, ' ');
|
||||||
if (!p || ((p - s) <= 0)) {
|
if (!p || ((p - s) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mtime", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, malformed mtime",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,13 +299,17 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
session->scpRecv_mtime = strtol((char *) s, NULL, 10);
|
session->scpRecv_mtime = strtol((char *) s, NULL, 10);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid mtime", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, invalid mtime",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
s = (unsigned char *) strchr((char *) p, ' ');
|
s = (unsigned char *) strchr((char *) p, ' ');
|
||||||
if (!s || ((s - p) <= 0)) {
|
if (!s || ((s - p) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mtime.usec", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, malformed mtime.usec",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +318,9 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
p = (unsigned char *) strchr((char *) s, ' ');
|
p = (unsigned char *) strchr((char *) s, ' ');
|
||||||
if (!p || ((p - s) <= 0)) {
|
if (!p || ((p - s) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short or malformed", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, too short or malformed",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +329,9 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
session->scpRecv_atime = strtol((char *) s, NULL, 10);
|
session->scpRecv_atime = strtol((char *) s, NULL, 10);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid atime", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, invalid atime",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,16 +342,20 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent3) {
|
if (session->scpRecv_state == libssh2_NB_state_sent3) {
|
||||||
rc = libssh2_channel_write_ex(session->scpRecv_channel, 0, (char *)session->scpRecv_response, 1);
|
rc = libssh2_channel_write_ex(session->scpRecv_channel, 0,
|
||||||
|
(char *) session->
|
||||||
|
scpRecv_response, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting to send SCP ACK", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting to send SCP ACK", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc != 1) {
|
||||||
else if (rc != 1) {
|
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "mtime = %ld, atime = %ld", session->scpRecv_mtime, session->scpRecv_atime);
|
_libssh2_debug(session, LIBSSH2_DBG_SCP,
|
||||||
|
"mtime = %ld, atime = %ld",
|
||||||
|
session->scpRecv_mtime, session->scpRecv_atime);
|
||||||
|
|
||||||
/* We *should* check that atime.usec is valid, but why let that stop use? */
|
/* We *should* check that atime.usec is valid, but why let that stop use? */
|
||||||
break;
|
break;
|
||||||
@@ -270,42 +371,62 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
session->scpRecv_state = libssh2_NB_state_sent5;
|
session->scpRecv_state = libssh2_NB_state_sent5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((session->scpRecv_state == libssh2_NB_state_sent5) || (session->scpRecv_state == libssh2_NB_state_sent6)) {
|
if ((session->scpRecv_state == libssh2_NB_state_sent5)
|
||||||
|
|| (session->scpRecv_state == libssh2_NB_state_sent6)) {
|
||||||
while (session->scpRecv_response_len < LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
while (session->scpRecv_response_len < LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||||
char *s, *p, *e = NULL;
|
char *s, *p, *e = NULL;
|
||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent5) {
|
if (session->scpRecv_state == libssh2_NB_state_sent5) {
|
||||||
rc = libssh2_channel_read_ex(session->scpRecv_channel, 0,
|
rc = libssh2_channel_read_ex(session->scpRecv_channel, 0,
|
||||||
(char *)session->scpRecv_response + session->scpRecv_response_len, 1);
|
(char *) session->
|
||||||
|
scpRecv_response +
|
||||||
|
session->scpRecv_response_len, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for SCP response", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc <= 0) {
|
||||||
else if (rc <= 0) {
|
|
||||||
/* Timeout, give up */
|
/* Timeout, give up */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Timed out waiting for SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Timed out waiting for SCP response", 0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
session->scpRecv_response_len++;
|
session->scpRecv_response_len++;
|
||||||
|
|
||||||
if (session->scpRecv_response[0] != 'C') {
|
if (session->scpRecv_response[0] != 'C') {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server", 0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((session->scpRecv_response_len > 1) &&
|
if ((session->scpRecv_response_len > 1) &&
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] != '\r') &&
|
(session->
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] != '\n') &&
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
((session->scpRecv_response[session->scpRecv_response_len-1] < 32) ||
|
'\r')
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] > 126))) {
|
&& (session->
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response", 0);
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
|
'\n')
|
||||||
|
&&
|
||||||
|
((session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] < 32)
|
||||||
|
|| (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] >
|
||||||
|
126))) {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid data in SCP response", 0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((session->scpRecv_response_len < 7) || (session->scpRecv_response[session->scpRecv_response_len-1] != '\n')) {
|
if ((session->scpRecv_response_len < 7)
|
||||||
if (session->scpRecv_response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
|| (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len - 1] !=
|
||||||
|
'\n')) {
|
||||||
|
if (session->scpRecv_response_len ==
|
||||||
|
LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||||
/* You had your chance */
|
/* You had your chance */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unterminated response from SCP server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Unterminated response from SCP server",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
/* Way too short to be an SCP response, or not done yet, short circuit */
|
/* Way too short to be an SCP response, or not done yet, short circuit */
|
||||||
@@ -313,15 +434,22 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
||||||
while ((session->scpRecv_response[session->scpRecv_response_len-1] == '\r') ||
|
while ((session->
|
||||||
(session->scpRecv_response[session->scpRecv_response_len-1] == '\n')) {
|
scpRecv_response[session->scpRecv_response_len - 1] ==
|
||||||
|
'\r')
|
||||||
|
|| (session->
|
||||||
|
scpRecv_response[session->scpRecv_response_len -
|
||||||
|
1] == '\n')) {
|
||||||
session->scpRecv_response_len--;
|
session->scpRecv_response_len--;
|
||||||
}
|
}
|
||||||
session->scpRecv_response[session->scpRecv_response_len] = '\0';
|
session->scpRecv_response[session->scpRecv_response_len] =
|
||||||
|
'\0';
|
||||||
|
|
||||||
if (session->scpRecv_response_len < 6) {
|
if (session->scpRecv_response_len < 6) {
|
||||||
/* EOL came too soon */
|
/* EOL came too soon */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, too short",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +458,9 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
p = strchr(s, ' ');
|
p = strchr(s, ' ');
|
||||||
if (!p || ((p - s) <= 0)) {
|
if (!p || ((p - s) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mode", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, malformed mode",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,14 +469,17 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
session->scpRecv_mode = strtol(s, &e, 8);
|
session->scpRecv_mode = strtol(s, &e, 8);
|
||||||
if ((e && *e) || errno) {
|
if ((e && *e) || errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid mode", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, invalid mode",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = strchr(p, ' ');
|
s = strchr(p, ' ');
|
||||||
if (!s || ((s - p) <= 0)) {
|
if (!s || ((s - p) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short or malformed",
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, too short or malformed",
|
||||||
0);
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
@@ -356,7 +489,9 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
session->scpRecv_size = strtol(p, &e, 10);
|
session->scpRecv_size = strtol(p, &e, 10);
|
||||||
if ((e && *e) || errno) {
|
if ((e && *e) || errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid size", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid response from SCP server, invalid size",
|
||||||
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,15 +502,19 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent6) {
|
if (session->scpRecv_state == libssh2_NB_state_sent6) {
|
||||||
rc = libssh2_channel_write_ex(session->scpRecv_channel, 0, (char *)session->scpRecv_response, 1);
|
rc = libssh2_channel_write_ex(session->scpRecv_channel, 0,
|
||||||
|
(char *) session->
|
||||||
|
scpRecv_response, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending SCP ACK", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block sending SCP ACK", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc != 1) {
|
||||||
else if (rc != 1) {
|
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "mode = 0%lo size = %ld", session->scpRecv_mode, session->scpRecv_size);
|
_libssh2_debug(session, LIBSSH2_DBG_SCP,
|
||||||
|
"mode = 0%lo size = %ld", session->scpRecv_mode,
|
||||||
|
session->scpRecv_size);
|
||||||
|
|
||||||
/* We *should* check that basename is valid, but why let that stop us? */
|
/* We *should* check that basename is valid, but why let that stop us? */
|
||||||
break;
|
break;
|
||||||
@@ -403,6 +542,7 @@ scp_recv_error:
|
|||||||
session->scpRecv_state = libssh2_NB_state_idle;
|
session->scpRecv_state = libssh2_NB_state_idle;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_scp_send_ex
|
/* {{{ libssh2_scp_send_ex
|
||||||
@@ -413,7 +553,8 @@ scp_recv_error:
|
|||||||
* cause of the error.
|
* cause of the error.
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *
|
LIBSSH2_API LIBSSH2_CHANNEL *
|
||||||
libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime)
|
libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||||
|
size_t size, long mtime, long atime)
|
||||||
{
|
{
|
||||||
int path_len = strlen(path);
|
int path_len = strlen(path);
|
||||||
unsigned const char *base;
|
unsigned const char *base;
|
||||||
@@ -426,30 +567,39 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
session->scpSend_command_len++;
|
session->scpSend_command_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpSend_command = LIBSSH2_ALLOC(session, session->scpSend_command_len);
|
session->scpSend_command =
|
||||||
|
LIBSSH2_ALLOC(session, session->scpSend_command_len);
|
||||||
if (!session->scpSend_command) {
|
if (!session->scpSend_command) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a command buffer for scp session", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate a command buffer for scp session",
|
||||||
|
0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtime || atime) {
|
if (mtime || atime) {
|
||||||
memcpy(session->scpSend_command, "scp -pt ", sizeof("scp -pt ") - 1);
|
memcpy(session->scpSend_command, "scp -pt ",
|
||||||
memcpy(session->scpSend_command + sizeof("scp -pt ") - 1, path, path_len);
|
sizeof("scp -pt ") - 1);
|
||||||
|
memcpy(session->scpSend_command + sizeof("scp -pt ") - 1, path,
|
||||||
|
path_len);
|
||||||
} else {
|
} else {
|
||||||
memcpy(session->scpSend_command, "scp -t ", sizeof("scp -t ") - 1);
|
memcpy(session->scpSend_command, "scp -t ", sizeof("scp -t ") - 1);
|
||||||
memcpy(session->scpSend_command + sizeof("scp -t ") - 1, path, path_len);
|
memcpy(session->scpSend_command + sizeof("scp -t ") - 1, path,
|
||||||
|
path_len);
|
||||||
}
|
}
|
||||||
session->scpSend_command[session->scpSend_command_len - 1] = '\0';
|
session->scpSend_command[session->scpSend_command_len - 1] = '\0';
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Opening channel for SCP send");
|
_libssh2_debug(session, LIBSSH2_DBG_SCP,
|
||||||
|
"Opening channel for SCP send");
|
||||||
/* Allocate a channel */
|
/* Allocate a channel */
|
||||||
|
|
||||||
session->scpSend_state = libssh2_NB_state_created;
|
session->scpSend_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->scpSend_state == libssh2_NB_state_created) {
|
if (session->scpSend_state == libssh2_NB_state_created) {
|
||||||
session->scpSend_channel = libssh2_channel_open_ex(session, "session", sizeof("session") - 1,
|
session->scpSend_channel =
|
||||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
libssh2_channel_open_ex(session, "session", sizeof("session") - 1,
|
||||||
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||||
|
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
||||||
if (!session->scpSend_channel) {
|
if (!session->scpSend_channel) {
|
||||||
if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
||||||
/* previous call set libssh2_session_last_error(), pass it through */
|
/* previous call set libssh2_session_last_error(), pass it through */
|
||||||
@@ -457,9 +607,10 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
session->scpSend_command = NULL;
|
session->scpSend_command = NULL;
|
||||||
session->scpSend_state = libssh2_NB_state_idle;
|
session->scpSend_state = libssh2_NB_state_idle;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (libssh2_session_last_errno(session) ==
|
||||||
else if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block starting up channel", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block starting up channel", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,16 +620,20 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
|
|
||||||
if (session->scpSend_state == libssh2_NB_state_sent) {
|
if (session->scpSend_state == libssh2_NB_state_sent) {
|
||||||
/* Request SCP for the desired file */
|
/* Request SCP for the desired file */
|
||||||
rc = libssh2_channel_process_startup(session->scpSend_channel, "exec", sizeof("exec") - 1,
|
rc = libssh2_channel_process_startup(session->scpSend_channel, "exec",
|
||||||
(char *)session->scpSend_command, session->scpSend_command_len);
|
sizeof("exec") - 1,
|
||||||
|
(char *) session->scpSend_command,
|
||||||
|
session->scpSend_command_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block requesting SCP startup", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block requesting SCP startup", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
/* previous call set libssh2_session_last_error(), pass it through */
|
/* previous call set libssh2_session_last_error(), pass it through */
|
||||||
LIBSSH2_FREE(session, session->scpSend_command);
|
LIBSSH2_FREE(session, session->scpSend_command);
|
||||||
session->scpSend_command = NULL;
|
session->scpSend_command = NULL;
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Unknown error while getting error string", 0);
|
||||||
goto scp_send_error;
|
goto scp_send_error;
|
||||||
}
|
}
|
||||||
LIBSSH2_FREE(session, session->scpSend_command);
|
LIBSSH2_FREE(session, session->scpSend_command);
|
||||||
@@ -489,21 +644,26 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
|
|
||||||
if (session->scpSend_state == libssh2_NB_state_sent1) {
|
if (session->scpSend_state == libssh2_NB_state_sent1) {
|
||||||
/* Wait for ACK */
|
/* Wait for ACK */
|
||||||
rc = libssh2_channel_read_ex(session->scpSend_channel, 0, (char *)session->scpSend_response, 1);
|
rc = libssh2_channel_read_ex(session->scpSend_channel, 0,
|
||||||
|
(char *) session->scpSend_response, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response from remote", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for response from remote", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
|
||||||
else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
"Invalid ACK response from remote", 0);
|
||||||
goto scp_send_error;
|
goto scp_send_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtime || atime) {
|
if (mtime || atime) {
|
||||||
/* Send mtime and atime to be used for file */
|
/* Send mtime and atime to be used for file */
|
||||||
session->scpSend_response_len = snprintf((char *)session->scpSend_response, LIBSSH2_SCP_RESPONSE_BUFLEN,
|
session->scpSend_response_len =
|
||||||
"T%ld 0 %ld 0\n", mtime, atime);
|
snprintf((char *) session->scpSend_response,
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s", session->scpSend_response);
|
LIBSSH2_SCP_RESPONSE_BUFLEN, "T%ld 0 %ld 0\n", mtime,
|
||||||
|
atime);
|
||||||
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s",
|
||||||
|
session->scpSend_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpSend_state = libssh2_NB_state_sent2;
|
session->scpSend_state = libssh2_NB_state_sent2;
|
||||||
@@ -512,14 +672,16 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
/* Send mtime and atime to be used for file */
|
/* Send mtime and atime to be used for file */
|
||||||
if (mtime || atime) {
|
if (mtime || atime) {
|
||||||
if (session->scpSend_state == libssh2_NB_state_sent2) {
|
if (session->scpSend_state == libssh2_NB_state_sent2) {
|
||||||
rc = libssh2_channel_write_ex(session->scpSend_channel, 0, (char *)session->scpSend_response,
|
rc = libssh2_channel_write_ex(session->scpSend_channel, 0,
|
||||||
|
(char *) session->scpSend_response,
|
||||||
session->scpSend_response_len);
|
session->scpSend_response_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending time data for SCP file", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block sending time data for SCP file", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc != session->scpSend_response_len) {
|
||||||
else if (rc != session->scpSend_response_len) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send time data for SCP file", 0);
|
"Unable to send time data for SCP file", 0);
|
||||||
goto scp_send_error;
|
goto scp_send_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,13 +690,16 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
|
|
||||||
if (session->scpSend_state == libssh2_NB_state_sent3) {
|
if (session->scpSend_state == libssh2_NB_state_sent3) {
|
||||||
/* Wait for ACK */
|
/* Wait for ACK */
|
||||||
rc = libssh2_channel_read_ex(session->scpSend_channel, 0, (char *)session->scpSend_response, 1);
|
rc = libssh2_channel_read_ex(session->scpSend_channel, 0,
|
||||||
|
(char *) session->scpSend_response,
|
||||||
|
1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for response", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
|
||||||
else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
"Invalid ACK response from remote", 0);
|
||||||
goto scp_send_error;
|
goto scp_send_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,37 +720,81 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t
|
|||||||
base = (unsigned char *) path;
|
base = (unsigned char *) path;
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpSend_response_len = snprintf((char *)session->scpSend_response, LIBSSH2_SCP_RESPONSE_BUFLEN,
|
session->scpSend_response_len =
|
||||||
"C0%o %lu %s\n", mode, (unsigned long)size, base);
|
snprintf((char *) session->scpSend_response,
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s", session->scpSend_response);
|
LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %lu %s\n", mode,
|
||||||
|
(unsigned long) size, base);
|
||||||
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s",
|
||||||
|
session->scpSend_response);
|
||||||
|
|
||||||
session->scpSend_state = libssh2_NB_state_sent5;
|
session->scpSend_state = libssh2_NB_state_sent5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->scpSend_state == libssh2_NB_state_sent5) {
|
if (session->scpSend_state == libssh2_NB_state_sent5) {
|
||||||
rc = libssh2_channel_write_ex(session->scpSend_channel, 0, (char *)session->scpSend_response,
|
rc = libssh2_channel_write_ex(session->scpSend_channel, 0,
|
||||||
|
(char *) session->scpSend_response,
|
||||||
session->scpSend_response_len);
|
session->scpSend_response_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block send core file data for SCP file", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block send core file data for SCP file", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc != session->scpSend_response_len) {
|
||||||
else if (rc != session->scpSend_response_len) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send core file data for SCP file", 0);
|
"Unable to send core file data for SCP file", 0);
|
||||||
goto scp_send_error;
|
goto scp_send_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpSend_state = libssh2_NB_state_sent6;
|
session->scpSend_state = libssh2_NB_state_sent6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (session->scpSend_state == libssh2_NB_state_sent6) {
|
||||||
/* Wait for ACK */
|
/* Wait for ACK */
|
||||||
rc = libssh2_channel_read_ex(session->scpSend_channel, 0, (char *)session->scpSend_response, 1);
|
rc = libssh2_channel_read_ex(session->scpSend_channel, 0,
|
||||||
|
(char *) session->scpSend_response, 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for response", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (rc <= 0) {
|
||||||
else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
"Invalid ACK response from remote", 0);
|
||||||
goto scp_send_error;
|
goto scp_send_error;
|
||||||
|
} else if (session->scpSend_response[0] != 0) {
|
||||||
|
/*
|
||||||
|
* Set this as the default error for here, if
|
||||||
|
* we are successful it will be replaced
|
||||||
|
*/
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
"Invalid ACK response from remote", 0);
|
||||||
|
|
||||||
|
session->scpSend_err_len =
|
||||||
|
libssh2_channel_packet_data_len(session->scpSend_channel, 0);
|
||||||
|
session->scpSend_err_msg =
|
||||||
|
LIBSSH2_ALLOC(session, session->scpSend_err_len + 1);
|
||||||
|
if (!session->scpSend_err_msg) {
|
||||||
|
goto scp_send_error;
|
||||||
|
}
|
||||||
|
memset(session->scpSend_err_msg, 0, session->scpSend_err_len + 1);
|
||||||
|
|
||||||
|
/* Read the remote error message */
|
||||||
|
rc = libssh2_channel_read_ex(session->scpSend_channel, 0,
|
||||||
|
session->scpSend_err_msg,
|
||||||
|
session->scpSend_err_len);
|
||||||
|
if (rc <= 0) {
|
||||||
|
/*
|
||||||
|
* Since we have alread started reading this packet, it is
|
||||||
|
* already in the systems so it can't return PACKET_EAGAIN
|
||||||
|
*/
|
||||||
|
LIBSSH2_FREE(session, session->scpSend_err_msg);
|
||||||
|
session->scpSend_err_msg = NULL;
|
||||||
|
goto scp_send_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
|
session->scpSend_err_msg, 1);
|
||||||
|
session->scpSend_err_msg = NULL;
|
||||||
|
goto scp_send_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpSend_state = libssh2_NB_state_idle;
|
session->scpSend_state = libssh2_NB_state_idle;
|
||||||
@@ -598,5 +807,5 @@ scp_send_error:
|
|||||||
session->scpSend_state = libssh2_NB_state_idle;
|
session->scpSend_state = libssh2_NB_state_idle;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
400
src/session.c
400
src/session.c
@@ -46,32 +46,41 @@
|
|||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_ALLOCA_H
|
||||||
|
#include <alloca.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* {{{ libssh2_default_alloc
|
/* {{{ libssh2_default_alloc
|
||||||
*/
|
*/
|
||||||
static LIBSSH2_ALLOC_FUNC(libssh2_default_alloc)
|
static
|
||||||
|
LIBSSH2_ALLOC_FUNC(libssh2_default_alloc)
|
||||||
{
|
{
|
||||||
(void) abstract;
|
(void) abstract;
|
||||||
return malloc(count);
|
return malloc(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_default_free
|
/* {{{ libssh2_default_free
|
||||||
*/
|
*/
|
||||||
static LIBSSH2_FREE_FUNC(libssh2_default_free)
|
static
|
||||||
|
LIBSSH2_FREE_FUNC(libssh2_default_free)
|
||||||
{
|
{
|
||||||
(void) abstract;
|
(void) abstract;
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_default_realloc
|
/* {{{ libssh2_default_realloc
|
||||||
*/
|
*/
|
||||||
static LIBSSH2_REALLOC_FUNC(libssh2_default_realloc)
|
static
|
||||||
|
LIBSSH2_REALLOC_FUNC(libssh2_default_realloc)
|
||||||
{
|
{
|
||||||
(void) abstract;
|
(void) abstract;
|
||||||
return realloc(ptr, count);
|
return realloc(ptr, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_banner_receive
|
/* {{{ libssh2_banner_receive
|
||||||
@@ -79,7 +88,8 @@ static LIBSSH2_REALLOC_FUNC(libssh2_default_realloc)
|
|||||||
* Allocate a buffer and store the banner in session->remote.banner
|
* Allocate a buffer and store the banner in session->remote.banner
|
||||||
* Returns: 0 on success, PACKET_EAGAIN if read would block, 1 on failure
|
* Returns: 0 on success, PACKET_EAGAIN if read would block, 1 on failure
|
||||||
*/
|
*/
|
||||||
static int libssh2_banner_receive(LIBSSH2_SESSION *session)
|
static int
|
||||||
|
libssh2_banner_receive(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int banner_len;
|
int banner_len;
|
||||||
@@ -93,10 +103,13 @@ static int libssh2_banner_receive(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((banner_len < (int) sizeof(session->banner_TxRx_banner)) &&
|
while ((banner_len < (int) sizeof(session->banner_TxRx_banner)) &&
|
||||||
((banner_len == 0) || (session->banner_TxRx_banner[banner_len-1] != '\n'))) {
|
((banner_len == 0)
|
||||||
|
|| (session->banner_TxRx_banner[banner_len - 1] != '\n'))) {
|
||||||
char c = '\0';
|
char c = '\0';
|
||||||
|
|
||||||
ret = recv(session->socket_fd, &c, 1, LIBSSH2_SOCKET_RECV_FLAGS(session));
|
ret =
|
||||||
|
recv(session->socket_fd, &c, 1,
|
||||||
|
LIBSSH2_SOCKET_RECV_FLAGS(session));
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -130,7 +143,8 @@ static int libssh2_banner_receive(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret <= 0) continue;
|
if (ret <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (c == '\0') {
|
if (c == '\0') {
|
||||||
/* NULLs are not allowed in SSH banners */
|
/* NULLs are not allowed in SSH banners */
|
||||||
@@ -152,18 +166,22 @@ static int libssh2_banner_receive(LIBSSH2_SESSION *session)
|
|||||||
session->banner_TxRx_state = libssh2_NB_state_idle;
|
session->banner_TxRx_state = libssh2_NB_state_idle;
|
||||||
session->banner_TxRx_total_send = 0;
|
session->banner_TxRx_total_send = 0;
|
||||||
|
|
||||||
if (!banner_len) return 1;
|
if (!banner_len)
|
||||||
|
return 1;
|
||||||
|
|
||||||
session->remote.banner = LIBSSH2_ALLOC(session, banner_len + 1);
|
session->remote.banner = LIBSSH2_ALLOC(session, banner_len + 1);
|
||||||
if (!session->remote.banner) {
|
if (!session->remote.banner) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Error allocating space for remote banner", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Error allocating space for remote banner", 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len);
|
memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len);
|
||||||
session->remote.banner[banner_len] = '\0';
|
session->remote.banner[banner_len] = '\0';
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Received Banner: %s", session->remote.banner);
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Received Banner: %s",
|
||||||
|
session->remote.banner);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_banner_send
|
/* {{{ libssh2_banner_send
|
||||||
@@ -174,7 +192,8 @@ static int libssh2_banner_receive(LIBSSH2_SESSION *session)
|
|||||||
* sent, and this function should then be called with the same argument set
|
* sent, and this function should then be called with the same argument set
|
||||||
* (same data pointer and same data_len) until zero or failure is returned.
|
* (same data pointer and same data_len) until zero or failure is returned.
|
||||||
*/
|
*/
|
||||||
static int libssh2_banner_send(LIBSSH2_SESSION *session)
|
static int
|
||||||
|
libssh2_banner_send(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
char *banner = (char *) LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF;
|
char *banner = (char *) LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF;
|
||||||
int banner_len = sizeof(LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF) - 1;
|
int banner_len = sizeof(LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF) - 1;
|
||||||
@@ -189,7 +208,6 @@ static int libssh2_banner_send(LIBSSH2_SESSION *session)
|
|||||||
banner_len = strlen((char *) session->local.banner);
|
banner_len = strlen((char *) session->local.banner);
|
||||||
banner = (char *) session->local.banner;
|
banner = (char *) session->local.banner;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
/* Hack and slash to avoid sending CRLF in debug output */
|
/* Hack and slash to avoid sending CRLF in debug output */
|
||||||
if (banner_len < 256) {
|
if (banner_len < 256) {
|
||||||
@@ -200,13 +218,16 @@ static int libssh2_banner_send(LIBSSH2_SESSION *session)
|
|||||||
banner[255] = '\0';
|
banner[255] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Sending Banner: %s", banner_dup);
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Sending Banner: %s",
|
||||||
|
banner_dup);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
session->banner_TxRx_state = libssh2_NB_state_created;
|
session->banner_TxRx_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = send(session->socket_fd, banner+session->banner_TxRx_total_send, banner_len-session->banner_TxRx_total_send,
|
ret =
|
||||||
|
send(session->socket_fd, banner + session->banner_TxRx_total_send,
|
||||||
|
banner_len - session->banner_TxRx_total_send,
|
||||||
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||||
|
|
||||||
if (ret != (banner_len - session->banner_TxRx_total_send)) {
|
if (ret != (banner_len - session->banner_TxRx_total_send)) {
|
||||||
@@ -226,6 +247,7 @@ static int libssh2_banner_send(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -233,7 +255,8 @@ static int libssh2_banner_send(LIBSSH2_SESSION *session)
|
|||||||
* non-blocking mode based on the 'nonblock' boolean argument. This function
|
* non-blocking mode based on the 'nonblock' boolean argument. This function
|
||||||
* is copied from the libcurl sources with permission.
|
* is copied from the libcurl sources with permission.
|
||||||
*/
|
*/
|
||||||
static int _libssh2_nonblock(int sockfd, /* operate on this */
|
static int
|
||||||
|
_libssh2_nonblock(int sockfd, /* operate on this */
|
||||||
int nonblock /* TRUE or FALSE */ )
|
int nonblock /* TRUE or FALSE */ )
|
||||||
{
|
{
|
||||||
#undef SETBLOCK
|
#undef SETBLOCK
|
||||||
@@ -301,8 +324,9 @@ static int _libssh2_nonblock(int sockfd, /* operate on this */
|
|||||||
* _libssh2_get_socket_nonblocking() gets the given blocking or non-blocking
|
* _libssh2_get_socket_nonblocking() gets the given blocking or non-blocking
|
||||||
* state of the socket.
|
* state of the socket.
|
||||||
*/
|
*/
|
||||||
static int _libssh2_get_socket_nonblocking(int sockfd) /* operate on this */
|
static int
|
||||||
{
|
_libssh2_get_socket_nonblocking(int sockfd)
|
||||||
|
{ /* operate on this */
|
||||||
#undef GETBLOCK
|
#undef GETBLOCK
|
||||||
#define GETBLOCK 0
|
#define GETBLOCK 0
|
||||||
#ifdef HAVE_O_NONBLOCK
|
#ifdef HAVE_O_NONBLOCK
|
||||||
@@ -323,7 +347,8 @@ static int _libssh2_get_socket_nonblocking(int sockfd) /* operate on this */
|
|||||||
unsigned int option_value;
|
unsigned int option_value;
|
||||||
socklen_t option_len = sizeof(option_value);
|
socklen_t option_len = sizeof(option_value);
|
||||||
|
|
||||||
if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void*)&option_value, &option_len)) {
|
if (getsockopt
|
||||||
|
(sockfd, SOL_SOCKET, SO_ERROR, (void *) &option_value, &option_len)) {
|
||||||
/* Assume blocking on error */
|
/* Assume blocking on error */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -358,7 +383,8 @@ static int _libssh2_get_socket_nonblocking(int sockfd) /* operate on this */
|
|||||||
/* {{{ libssh2_banner_set
|
/* {{{ libssh2_banner_set
|
||||||
* Set the local banner
|
* Set the local banner
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner)
|
LIBSSH2_API int
|
||||||
|
libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner)
|
||||||
{
|
{
|
||||||
int banner_len = banner ? strlen(banner) : 0;
|
int banner_len = banner ? strlen(banner) : 0;
|
||||||
|
|
||||||
@@ -373,19 +399,22 @@ LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner)
|
|||||||
|
|
||||||
session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3);
|
session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3);
|
||||||
if (!session->local.banner) {
|
if (!session->local.banner) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for local banner", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for local banner", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(session->local.banner, banner, banner_len);
|
memcpy(session->local.banner, banner, banner_len);
|
||||||
session->local.banner[banner_len] = '\0';
|
session->local.banner[banner_len] = '\0';
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Setting local Banner: %s", session->local.banner);
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Setting local Banner: %s",
|
||||||
|
session->local.banner);
|
||||||
session->local.banner[banner_len++] = '\r';
|
session->local.banner[banner_len++] = '\r';
|
||||||
session->local.banner[banner_len++] = '\n';
|
session->local.banner[banner_len++] = '\n';
|
||||||
session->local.banner[banner_len++] = '\0';
|
session->local.banner[banner_len++] = '\0';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ proto libssh2_session_init
|
/* {{{ proto libssh2_session_init
|
||||||
@@ -394,11 +423,10 @@ LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner)
|
|||||||
* It's allowable (but unadvisable) to define some but not all of the malloc callbacks
|
* It's allowable (but unadvisable) to define some but not all of the malloc callbacks
|
||||||
* An additional pointer value may be optionally passed to be sent to the callbacks (so they know who's asking)
|
* An additional pointer value may be optionally passed to be sent to the callbacks (so they know who's asking)
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex(
|
LIBSSH2_API LIBSSH2_SESSION *
|
||||||
LIBSSH2_ALLOC_FUNC((*my_alloc)),
|
libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
|
||||||
LIBSSH2_FREE_FUNC((*my_free)),
|
LIBSSH2_FREE_FUNC((*my_free)),
|
||||||
LIBSSH2_REALLOC_FUNC((*my_realloc)),
|
LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract)
|
||||||
void *abstract)
|
|
||||||
{
|
{
|
||||||
LIBSSH2_ALLOC_FUNC((*local_alloc)) = libssh2_default_alloc;
|
LIBSSH2_ALLOC_FUNC((*local_alloc)) = libssh2_default_alloc;
|
||||||
LIBSSH2_FREE_FUNC((*local_free)) = libssh2_default_free;
|
LIBSSH2_FREE_FUNC((*local_free)) = libssh2_default_free;
|
||||||
@@ -422,18 +450,25 @@ LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex(
|
|||||||
session->free = local_free;
|
session->free = local_free;
|
||||||
session->realloc = local_realloc;
|
session->realloc = local_realloc;
|
||||||
session->abstract = abstract;
|
session->abstract = abstract;
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "New session resource allocated");
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS,
|
||||||
|
"New session resource allocated");
|
||||||
libssh2_crypto_init();
|
libssh2_crypto_init();
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_callback_set
|
/* {{{ libssh2_session_callback_set
|
||||||
* Set (or reset) a callback function
|
* Set (or reset) a callback function
|
||||||
* Returns the prior address
|
* Returns the prior address
|
||||||
|
*
|
||||||
|
* FIXME: this function relies on that we can typecast function pointers
|
||||||
|
* to void pointers, which isn't allowed in ISO C!
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API void* libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback)
|
LIBSSH2_API void *
|
||||||
|
libssh2_session_callback_set(LIBSSH2_SESSION * session,
|
||||||
|
int cbtype, void *callback)
|
||||||
{
|
{
|
||||||
void *oldcb;
|
void *oldcb;
|
||||||
|
|
||||||
@@ -468,6 +503,7 @@ LIBSSH2_API void* libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbt
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ proto libssh2_session_startup
|
/* {{{ proto libssh2_session_startup
|
||||||
@@ -477,7 +513,8 @@ LIBSSH2_API void* libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbt
|
|||||||
* callbacks in session
|
* callbacks in session
|
||||||
* socket *must* be populated with an opened and connected socket.
|
* socket *must* be populated with an opened and connected socket.
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
LIBSSH2_API int
|
||||||
|
libssh2_session_startup(LIBSSH2_SESSION * session, int socket)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -487,12 +524,14 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
/* FIXME: on some platforms (like win32) sockets are unsigned */
|
/* FIXME: on some platforms (like win32) sockets are unsigned */
|
||||||
if (socket < 0) {
|
if (socket < 0) {
|
||||||
/* Did we forget something? */
|
/* Did we forget something? */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE, "Bad socket provided", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE,
|
||||||
|
"Bad socket provided", 0);
|
||||||
return LIBSSH2_ERROR_SOCKET_NONE;
|
return LIBSSH2_ERROR_SOCKET_NONE;
|
||||||
}
|
}
|
||||||
session->socket_fd = socket;
|
session->socket_fd = socket;
|
||||||
|
|
||||||
session->socket_block = !_libssh2_get_socket_nonblocking(session->socket_fd);
|
session->socket_block =
|
||||||
|
!_libssh2_get_socket_nonblocking(session->socket_fd);
|
||||||
if (session->socket_block) {
|
if (session->socket_block) {
|
||||||
/*
|
/*
|
||||||
* Since we can't be sure that we are in blocking or there
|
* Since we can't be sure that we are in blocking or there
|
||||||
@@ -510,12 +549,13 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
if (session->startup_state == libssh2_NB_state_created) {
|
if (session->startup_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_banner_send(session);
|
rc = libssh2_banner_send(session);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending banner to remote host", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block sending banner to remote host", 0);
|
||||||
return LIBSSH2_ERROR_EAGAIN;
|
return LIBSSH2_ERROR_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
/* Unable to send banner? */
|
/* Unable to send banner? */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_BANNER_SEND, "Error sending banner to remote host", 0);
|
libssh2_error(session, LIBSSH2_ERROR_BANNER_SEND,
|
||||||
|
"Error sending banner to remote host", 0);
|
||||||
return LIBSSH2_ERROR_BANNER_SEND;
|
return LIBSSH2_ERROR_BANNER_SEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,12 +565,13 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
if (session->startup_state == libssh2_NB_state_sent) {
|
if (session->startup_state == libssh2_NB_state_sent) {
|
||||||
rc = libssh2_banner_receive(session);
|
rc = libssh2_banner_receive(session);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for banner", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block waiting for banner", 0);
|
||||||
return LIBSSH2_ERROR_EAGAIN;
|
return LIBSSH2_ERROR_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
/* Unable to receive banner from remote */
|
/* Unable to receive banner from remote */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_BANNER_NONE, "Timeout waiting for banner", 0);
|
libssh2_error(session, LIBSSH2_ERROR_BANNER_NONE,
|
||||||
|
"Timeout waiting for banner", 0);
|
||||||
return LIBSSH2_ERROR_BANNER_NONE;
|
return LIBSSH2_ERROR_BANNER_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,11 +581,12 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
if (session->startup_state == libssh2_NB_state_sent1) {
|
if (session->startup_state == libssh2_NB_state_sent1) {
|
||||||
rc = libssh2_kex_exchange(session, 0, &session->startup_key_state);
|
rc = libssh2_kex_exchange(session, 0, &session->startup_key_state);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block exchanging encryption keys", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block exchanging encryption keys", 0);
|
||||||
return LIBSSH2_ERROR_EAGAIN;
|
return LIBSSH2_ERROR_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, "Unable to exchange encryption keys", 0);
|
"Unable to exchange encryption keys", 0);
|
||||||
return LIBSSH2_ERROR_KEX_FAILURE;
|
return LIBSSH2_ERROR_KEX_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,24 +594,29 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->startup_state == libssh2_NB_state_sent2) {
|
if (session->startup_state == libssh2_NB_state_sent2) {
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Requesting userauth service");
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS,
|
||||||
|
"Requesting userauth service");
|
||||||
|
|
||||||
/* Request the userauth service */
|
/* Request the userauth service */
|
||||||
session->startup_service[0] = SSH_MSG_SERVICE_REQUEST;
|
session->startup_service[0] = SSH_MSG_SERVICE_REQUEST;
|
||||||
libssh2_htonu32(session->startup_service + 1, sizeof("ssh-userauth") - 1);
|
libssh2_htonu32(session->startup_service + 1,
|
||||||
memcpy(session->startup_service + 5, "ssh-userauth", sizeof("ssh-userauth") - 1);
|
sizeof("ssh-userauth") - 1);
|
||||||
|
memcpy(session->startup_service + 5, "ssh-userauth",
|
||||||
|
sizeof("ssh-userauth") - 1);
|
||||||
|
|
||||||
session->startup_state = libssh2_NB_state_sent3;
|
session->startup_state = libssh2_NB_state_sent3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->startup_state == libssh2_NB_state_sent3) {
|
if (session->startup_state == libssh2_NB_state_sent3) {
|
||||||
rc = libssh2_packet_write(session, session->startup_service, sizeof("ssh-userauth") + 5 - 1);
|
rc = libssh2_packet_write(session, session->startup_service,
|
||||||
|
sizeof("ssh-userauth") + 5 - 1);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block asking for ssh-userauth service", 0);
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block asking for ssh-userauth service", 0);
|
||||||
return LIBSSH2_ERROR_EAGAIN;
|
return LIBSSH2_ERROR_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to ask for ssh-userauth service", 0);
|
"Unable to ask for ssh-userauth service", 0);
|
||||||
return LIBSSH2_ERROR_SOCKET_SEND;
|
return LIBSSH2_ERROR_SOCKET_SEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,21 +624,25 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->startup_state == libssh2_NB_state_sent4) {
|
if (session->startup_state == libssh2_NB_state_sent4) {
|
||||||
rc = libssh2_packet_require_ex(session, SSH_MSG_SERVICE_ACCEPT, &session->startup_data, &session->startup_data_len,
|
rc = libssh2_packet_require_ex(session, SSH_MSG_SERVICE_ACCEPT,
|
||||||
0, NULL, 0, &session->startup_req_state);
|
&session->startup_data,
|
||||||
|
&session->startup_data_len, 0, NULL, 0,
|
||||||
|
&session->startup_req_state);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return LIBSSH2_ERROR_EAGAIN;
|
return LIBSSH2_ERROR_EAGAIN;
|
||||||
}
|
} else if (rc) {
|
||||||
else if (rc) {
|
|
||||||
return LIBSSH2_ERROR_SOCKET_DISCONNECT;
|
return LIBSSH2_ERROR_SOCKET_DISCONNECT;
|
||||||
}
|
}
|
||||||
session->startup_service_length = libssh2_ntohu32(session->startup_data + 1);
|
session->startup_service_length =
|
||||||
|
libssh2_ntohu32(session->startup_data + 1);
|
||||||
|
|
||||||
if ((session->startup_service_length != (sizeof("ssh-userauth") - 1)) ||
|
if ((session->startup_service_length != (sizeof("ssh-userauth") - 1))
|
||||||
strncmp("ssh-userauth", (char *)session->startup_data + 5, session->startup_service_length)) {
|
|| strncmp("ssh-userauth", (char *) session->startup_data + 5,
|
||||||
|
session->startup_service_length)) {
|
||||||
LIBSSH2_FREE(session, session->startup_data);
|
LIBSSH2_FREE(session, session->startup_data);
|
||||||
session->startup_data = NULL;
|
session->startup_data = NULL;
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Invalid response received from server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||||
|
"Invalid response received from server", 0);
|
||||||
return LIBSSH2_ERROR_PROTO;
|
return LIBSSH2_ERROR_PROTO;
|
||||||
}
|
}
|
||||||
LIBSSH2_FREE(session, session->startup_data);
|
LIBSSH2_FREE(session, session->startup_data);
|
||||||
@@ -605,18 +656,21 @@ LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket)
|
|||||||
/* just for safety return some error */
|
/* just for safety return some error */
|
||||||
return LIBSSH2_ERROR_INVAL;
|
return LIBSSH2_ERROR_INVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ proto libssh2_session_free
|
/* {{{ proto libssh2_session_free
|
||||||
* Frees the memory allocated to the session
|
* Frees the memory allocated to the session
|
||||||
* Also closes and frees any channels attached to this session
|
* Also closes and frees any channels attached to this session
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session)
|
LIBSSH2_API int
|
||||||
|
libssh2_session_free(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (session->free_state == libssh2_NB_state_idle) {
|
if (session->free_state == libssh2_NB_state_idle) {
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Freeing session resource", session->remote.banner);
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Freeing session resource",
|
||||||
|
session->remote.banner);
|
||||||
|
|
||||||
session->state = libssh2_NB_state_created;
|
session->state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
@@ -666,11 +720,13 @@ LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session)
|
|||||||
/* Client to Server */
|
/* Client to Server */
|
||||||
/* crypt */
|
/* crypt */
|
||||||
if (session->local.crypt && session->local.crypt->dtor) {
|
if (session->local.crypt && session->local.crypt->dtor) {
|
||||||
session->local.crypt->dtor(session, &session->local.crypt_abstract);
|
session->local.crypt->dtor(session,
|
||||||
|
&session->local.crypt_abstract);
|
||||||
}
|
}
|
||||||
/* comp */
|
/* comp */
|
||||||
if (session->local.comp && session->local.comp->dtor) {
|
if (session->local.comp && session->local.comp->dtor) {
|
||||||
session->local.comp->dtor(session, 1, &session->local.comp_abstract);
|
session->local.comp->dtor(session, 1,
|
||||||
|
&session->local.comp_abstract);
|
||||||
}
|
}
|
||||||
/* mac */
|
/* mac */
|
||||||
if (session->local.mac && session->local.mac->dtor) {
|
if (session->local.mac && session->local.mac->dtor) {
|
||||||
@@ -680,11 +736,13 @@ LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session)
|
|||||||
/* Server to Client */
|
/* Server to Client */
|
||||||
/* crypt */
|
/* crypt */
|
||||||
if (session->remote.crypt && session->remote.crypt->dtor) {
|
if (session->remote.crypt && session->remote.crypt->dtor) {
|
||||||
session->remote.crypt->dtor(session, &session->remote.crypt_abstract);
|
session->remote.crypt->dtor(session,
|
||||||
|
&session->remote.crypt_abstract);
|
||||||
}
|
}
|
||||||
/* comp */
|
/* comp */
|
||||||
if (session->remote.comp && session->remote.comp->dtor) {
|
if (session->remote.comp && session->remote.comp->dtor) {
|
||||||
session->remote.comp->dtor(session, 0, &session->remote.comp_abstract);
|
session->remote.comp->dtor(session, 0,
|
||||||
|
&session->remote.comp_abstract);
|
||||||
}
|
}
|
||||||
/* mac */
|
/* mac */
|
||||||
if (session->remote.mac && session->remote.mac->dtor) {
|
if (session->remote.mac && session->remote.mac->dtor) {
|
||||||
@@ -805,6 +863,17 @@ LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session)
|
|||||||
if (session->scpSend_command) {
|
if (session->scpSend_command) {
|
||||||
LIBSSH2_FREE(session, session->scpSend_command);
|
LIBSSH2_FREE(session, session->scpSend_command);
|
||||||
}
|
}
|
||||||
|
if (session->scpRecv_err_msg) {
|
||||||
|
LIBSSH2_FREE(session, session->scpRecv_err_msg);
|
||||||
|
}
|
||||||
|
if (session->scpSend_err_msg) {
|
||||||
|
LIBSSH2_FREE(session, session->scpSend_err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free the error message, if we ar supposed to */
|
||||||
|
if (session->err_msg && session->err_should_free) {
|
||||||
|
LIBSSH2_FREE(session, session->err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
/* Cleanup any remaining packets */
|
/* Cleanup any remaining packets */
|
||||||
while (session->packets.head) {
|
while (session->packets.head) {
|
||||||
@@ -822,18 +891,23 @@ LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_disconnect_ex
|
/* {{{ libssh2_session_disconnect_ex
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang)
|
LIBSSH2_API int
|
||||||
|
libssh2_session_disconnect_ex(LIBSSH2_SESSION * session, int reason,
|
||||||
|
const char *description, const char *lang)
|
||||||
{
|
{
|
||||||
unsigned char *s;
|
unsigned char *s;
|
||||||
unsigned long descr_len = 0, lang_len = 0;
|
unsigned long descr_len = 0, lang_len = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (session->disconnect_state == libssh2_NB_state_idle) {
|
if (session->disconnect_state == libssh2_NB_state_idle) {
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_TRANS, "Disconnecting: reason=%d, desc=%s, lang=%s", reason, description, lang);
|
_libssh2_debug(session, LIBSSH2_DBG_TRANS,
|
||||||
|
"Disconnecting: reason=%d, desc=%s, lang=%s", reason,
|
||||||
|
description, lang);
|
||||||
if (description) {
|
if (description) {
|
||||||
descr_len = strlen(description);
|
descr_len = strlen(description);
|
||||||
}
|
}
|
||||||
@@ -843,23 +917,29 @@ LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reas
|
|||||||
/* 13 = packet_type(1) + reason code(4) + descr_len(4) + lang_len(4) */
|
/* 13 = packet_type(1) + reason code(4) + descr_len(4) + lang_len(4) */
|
||||||
session->disconnect_data_len = descr_len + lang_len + 13;
|
session->disconnect_data_len = descr_len + lang_len + 13;
|
||||||
|
|
||||||
s = session->disconnect_data = LIBSSH2_ALLOC(session, session->disconnect_data_len);
|
s = session->disconnect_data =
|
||||||
|
LIBSSH2_ALLOC(session, session->disconnect_data_len);
|
||||||
if (!session->disconnect_data) {
|
if (!session->disconnect_data) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for disconnect packet", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
|
"Unable to allocate memory for disconnect packet",
|
||||||
|
0);
|
||||||
session->disconnect_state = libssh2_NB_state_idle;
|
session->disconnect_state = libssh2_NB_state_idle;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(s++) = SSH_MSG_DISCONNECT;
|
*(s++) = SSH_MSG_DISCONNECT;
|
||||||
libssh2_htonu32(s, reason); s += 4;
|
libssh2_htonu32(s, reason);
|
||||||
|
s += 4;
|
||||||
|
|
||||||
libssh2_htonu32(s, descr_len); s += 4;
|
libssh2_htonu32(s, descr_len);
|
||||||
|
s += 4;
|
||||||
if (description) {
|
if (description) {
|
||||||
memcpy(s, description, descr_len);
|
memcpy(s, description, descr_len);
|
||||||
s += descr_len;
|
s += descr_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
libssh2_htonu32(s, lang_len); s += 4;
|
libssh2_htonu32(s, lang_len);
|
||||||
|
s += 4;
|
||||||
if (lang) {
|
if (lang) {
|
||||||
memcpy(s, lang, lang_len);
|
memcpy(s, lang, lang_len);
|
||||||
s += lang_len;
|
s += lang_len;
|
||||||
@@ -868,7 +948,8 @@ LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reas
|
|||||||
session->disconnect_state = libssh2_NB_state_created;
|
session->disconnect_state = libssh2_NB_state_created;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = libssh2_packet_write(session, session->disconnect_data, session->disconnect_data_len);
|
rc = libssh2_packet_write(session, session->disconnect_data,
|
||||||
|
session->disconnect_data_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
@@ -879,6 +960,7 @@ LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reas
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_methods
|
/* {{{ libssh2_session_methods
|
||||||
@@ -886,7 +968,8 @@ LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reas
|
|||||||
* NOTE: Currently lang_cs and lang_sc are ALWAYS set to empty string regardless of actual negotiation
|
* NOTE: Currently lang_cs and lang_sc are ALWAYS set to empty string regardless of actual negotiation
|
||||||
* Strings should NOT be freed
|
* Strings should NOT be freed
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session, int method_type)
|
LIBSSH2_API const char *
|
||||||
|
libssh2_session_methods(LIBSSH2_SESSION * session, int method_type)
|
||||||
{
|
{
|
||||||
/* All methods have char *name as their first element */
|
/* All methods have char *name as their first element */
|
||||||
const LIBSSH2_KEX_METHOD *method = NULL;
|
const LIBSSH2_KEX_METHOD *method = NULL;
|
||||||
@@ -933,27 +1016,32 @@ LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session, int me
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
libssh2_error(session, LIBSSH2_ERROR_INVAL, "Invalid parameter specified for method_type", 0);
|
libssh2_error(session, LIBSSH2_ERROR_INVAL,
|
||||||
|
"Invalid parameter specified for method_type", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!method) {
|
if (!method) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, "No method negotiated", 0);
|
libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE,
|
||||||
|
"No method negotiated", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return method->name;
|
return method->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_abstract
|
/* {{{ libssh2_session_abstract
|
||||||
* Retrieve a pointer to the abstract property
|
* Retrieve a pointer to the abstract property
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session)
|
LIBSSH2_API void **
|
||||||
|
libssh2_session_abstract(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
return &session->abstract;
|
return &session->abstract;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_last_error
|
/* {{{ libssh2_session_last_error
|
||||||
@@ -962,7 +1050,8 @@ LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session)
|
|||||||
* Otherwise it is assumed to be owned by libssh2
|
* Otherwise it is assumed to be owned by libssh2
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int
|
LIBSSH2_API int
|
||||||
libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_len, int want_buf)
|
libssh2_session_last_error(LIBSSH2_SESSION * session, char **errmsg,
|
||||||
|
int *errmsg_len, int want_buf)
|
||||||
{
|
{
|
||||||
/* No error to report */
|
/* No error to report */
|
||||||
if (!session->err_code) {
|
if (!session->err_code) {
|
||||||
@@ -983,8 +1072,7 @@ libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (errmsg) {
|
if (errmsg) {
|
||||||
char *serrmsg = session->err_msg ? session->err_msg :
|
char *serrmsg = session->err_msg ? session->err_msg : (char *) "";
|
||||||
(char *)"";
|
|
||||||
int ownbuf = session->err_msg ? session->err_should_free : 0;
|
int ownbuf = session->err_msg ? session->err_should_free : 0;
|
||||||
|
|
||||||
if (want_buf) {
|
if (want_buf) {
|
||||||
@@ -1011,6 +1099,7 @@ libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_
|
|||||||
|
|
||||||
return session->err_code;
|
return session->err_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_last_error
|
/* {{{ libssh2_session_last_error
|
||||||
@@ -1021,13 +1110,15 @@ libssh2_session_last_errno(LIBSSH2_SESSION *session)
|
|||||||
{
|
{
|
||||||
return session->err_code;
|
return session->err_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_flag
|
/* {{{ libssh2_session_flag
|
||||||
* Set/Get session flags
|
* Set/Get session flags
|
||||||
* Passing flag==0 will avoid changing session->flags while still returning its current value
|
* Passing flag==0 will avoid changing session->flags while still returning its current value
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag, int value)
|
LIBSSH2_API int
|
||||||
|
libssh2_session_flag(LIBSSH2_SESSION * session, int flag, int value)
|
||||||
{
|
{
|
||||||
if (value) {
|
if (value) {
|
||||||
session->flags |= flag;
|
session->flags |= flag;
|
||||||
@@ -1037,16 +1128,19 @@ LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag, int val
|
|||||||
|
|
||||||
return session->flags;
|
return session->flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ _libssh2_session_set_blocking
|
/* {{{ _libssh2_session_set_blocking
|
||||||
* Set a session's blocking mode on or off, return the previous status
|
* Set a session's blocking mode on or off, return the previous status
|
||||||
* when this function is called.
|
* when this function is called.
|
||||||
*/
|
*/
|
||||||
int _libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking)
|
int
|
||||||
|
_libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking)
|
||||||
{
|
{
|
||||||
int bl = session->socket_block;
|
int bl = session->socket_block;
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_CONN, "Setting blocking mode on session %d", blocking);
|
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||||
|
"Setting blocking mode on session %d", blocking);
|
||||||
if (blocking == session->socket_block) {
|
if (blocking == session->socket_block) {
|
||||||
/* avoid if already correct */
|
/* avoid if already correct */
|
||||||
return bl;
|
return bl;
|
||||||
@@ -1057,32 +1151,38 @@ int _libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking)
|
|||||||
|
|
||||||
return bl;
|
return bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_set_blocking
|
/* {{{ libssh2_session_set_blocking
|
||||||
* Set a channel's blocking mode on or off, similar to a socket's
|
* Set a channel's blocking mode on or off, similar to a socket's
|
||||||
* fcntl(fd, F_SETFL, O_NONBLOCK); type command
|
* fcntl(fd, F_SETFL, O_NONBLOCK); type command
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking)
|
LIBSSH2_API void
|
||||||
|
libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking)
|
||||||
{
|
{
|
||||||
(void) _libssh2_session_set_blocking(session, blocking);
|
(void) _libssh2_session_set_blocking(session, blocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_session_get_blocking
|
/* {{{ libssh2_session_get_blocking
|
||||||
* Returns a session's blocking mode on or off
|
* Returns a session's blocking mode on or off
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION *session)
|
LIBSSH2_API int
|
||||||
|
libssh2_session_get_blocking(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
return session->socket_block;
|
return session->socket_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_poll_channel_read
|
/* {{{ libssh2_poll_channel_read
|
||||||
* Returns 0 if no data is waiting on channel,
|
* Returns 0 if no data is waiting on channel,
|
||||||
* non-0 if data is available
|
* non-0 if data is available
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended)
|
LIBSSH2_API int
|
||||||
|
libssh2_poll_channel_read(LIBSSH2_CHANNEL * channel, int extended)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = channel->session;
|
LIBSSH2_SESSION *session = channel->session;
|
||||||
LIBSSH2_PACKET *packet = session->packets.head;
|
LIBSSH2_PACKET *packet = session->packets.head;
|
||||||
@@ -1090,8 +1190,9 @@ LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended
|
|||||||
while (packet) {
|
while (packet) {
|
||||||
if (((packet->data[0] == SSH_MSG_CHANNEL_DATA) && (extended == 0) &&
|
if (((packet->data[0] == SSH_MSG_CHANNEL_DATA) && (extended == 0) &&
|
||||||
(channel->local.id == libssh2_ntohu32(packet->data + 1))) ||
|
(channel->local.id == libssh2_ntohu32(packet->data + 1))) ||
|
||||||
((packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA) && (extended != 0) &&
|
((packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA)
|
||||||
(channel->local.id == libssh2_ntohu32(packet->data + 1)))) {
|
&& (extended != 0)
|
||||||
|
&& (channel->local.id == libssh2_ntohu32(packet->data + 1)))) {
|
||||||
/* Found data waiting to be read */
|
/* Found data waiting to be read */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1100,43 +1201,53 @@ LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_poll_channel_write
|
/* {{{ libssh2_poll_channel_write
|
||||||
* Returns 0 if writing to channel would block,
|
* Returns 0 if writing to channel would block,
|
||||||
* non-0 if data can be written without blocking
|
* non-0 if data can be written without blocking
|
||||||
*/
|
*/
|
||||||
static inline int libssh2_poll_channel_write(LIBSSH2_CHANNEL *channel)
|
static inline int
|
||||||
|
libssh2_poll_channel_write(LIBSSH2_CHANNEL * channel)
|
||||||
{
|
{
|
||||||
return channel->local.window_size ? 1 : 0;
|
return channel->local.window_size ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_poll_listener_queued
|
/* {{{ libssh2_poll_listener_queued
|
||||||
* Returns 0 if no connections are waiting to be accepted
|
* Returns 0 if no connections are waiting to be accepted
|
||||||
* non-0 if one or more connections are available
|
* non-0 if one or more connections are available
|
||||||
*/
|
*/
|
||||||
static inline int libssh2_poll_listener_queued(LIBSSH2_LISTENER *listener)
|
static inline int
|
||||||
|
libssh2_poll_listener_queued(LIBSSH2_LISTENER * listener)
|
||||||
{
|
{
|
||||||
return listener->queue ? 1 : 0;
|
return listener->queue ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ libssh2_poll
|
/* {{{ libssh2_poll
|
||||||
* Poll sockets, channels, and listeners for activity
|
* Poll sockets, channels, and listeners for activity
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout)
|
LIBSSH2_API int
|
||||||
|
libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||||
{
|
{
|
||||||
long timeout_remaining;
|
long timeout_remaining;
|
||||||
unsigned int i, active_fds;
|
unsigned int i, active_fds;
|
||||||
#ifdef HAVE_POLL
|
#ifdef HAVE_POLL
|
||||||
LIBSSH2_SESSION *session = NULL;
|
LIBSSH2_SESSION *session = NULL;
|
||||||
struct pollfd sockets[nfds];
|
#ifdef HAVE_ALLOCA
|
||||||
/* FIXME: (dast) this is not C89 code! However, the prototype for this
|
struct pollfd *sockets = alloca(sizeof(struct pollfd) * nfds);
|
||||||
function doesn't provide a session struct so we can't easily use
|
#else
|
||||||
the user-provided malloc replacement here... I suggest we modify
|
struct pollfd sockets[256];
|
||||||
the proto to make it possible. */
|
|
||||||
|
|
||||||
|
if (nfds > 256)
|
||||||
|
/* systems without alloca use a fixed-size array, this can be fixed
|
||||||
|
if we really want to, at least if the compiler is a C99 capable one */
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
/* Setup sockets for polling */
|
/* Setup sockets for polling */
|
||||||
for(i = 0; i < nfds; i++) {
|
for(i = 0; i < nfds; i++) {
|
||||||
fds[i].revents = 0;
|
fds[i].revents = 0;
|
||||||
@@ -1151,19 +1262,23 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
sockets[i].fd = fds[i].fd.channel->session->socket_fd;
|
sockets[i].fd = fds[i].fd.channel->session->socket_fd;
|
||||||
sockets[i].events = POLLIN;
|
sockets[i].events = POLLIN;
|
||||||
sockets[i].revents = 0;
|
sockets[i].revents = 0;
|
||||||
if (!session) session = fds[i].fd.channel->session;
|
if (!session)
|
||||||
|
session = fds[i].fd.channel->session;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIBSSH2_POLLFD_LISTENER:
|
case LIBSSH2_POLLFD_LISTENER:
|
||||||
sockets[i].fd = fds[i].fd.listener->session->socket_fd;
|
sockets[i].fd = fds[i].fd.listener->session->socket_fd;
|
||||||
sockets[i].events = POLLIN;
|
sockets[i].events = POLLIN;
|
||||||
sockets[i].revents = 0;
|
sockets[i].revents = 0;
|
||||||
if (!session) session = fds[i].fd.listener->session;
|
if (!session)
|
||||||
|
session = fds[i].fd.listener->session;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (session) libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
|
if (session)
|
||||||
"Invalid descriptor passed to libssh2_poll()", 0);
|
libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
|
||||||
|
"Invalid descriptor passed to libssh2_poll()",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1181,29 +1296,37 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
case LIBSSH2_POLLFD_SOCKET:
|
case LIBSSH2_POLLFD_SOCKET:
|
||||||
if (fds[i].events & LIBSSH2_POLLFD_POLLIN) {
|
if (fds[i].events & LIBSSH2_POLLFD_POLLIN) {
|
||||||
FD_SET(fds[i].fd.socket, &rfds);
|
FD_SET(fds[i].fd.socket, &rfds);
|
||||||
if (fds[i].fd.socket > maxfd) maxfd = fds[i].fd.socket;
|
if (fds[i].fd.socket > maxfd)
|
||||||
|
maxfd = fds[i].fd.socket;
|
||||||
}
|
}
|
||||||
if (fds[i].events & LIBSSH2_POLLFD_POLLOUT) {
|
if (fds[i].events & LIBSSH2_POLLFD_POLLOUT) {
|
||||||
FD_SET(fds[i].fd.socket, &wfds);
|
FD_SET(fds[i].fd.socket, &wfds);
|
||||||
if (fds[i].fd.socket > maxfd) maxfd = fds[i].fd.socket;
|
if (fds[i].fd.socket > maxfd)
|
||||||
|
maxfd = fds[i].fd.socket;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIBSSH2_POLLFD_CHANNEL:
|
case LIBSSH2_POLLFD_CHANNEL:
|
||||||
FD_SET(fds[i].fd.channel->session->socket_fd, &rfds);
|
FD_SET(fds[i].fd.channel->session->socket_fd, &rfds);
|
||||||
if (fds[i].fd.channel->session->socket_fd > maxfd) maxfd = fds[i].fd.channel->session->socket_fd;
|
if (fds[i].fd.channel->session->socket_fd > maxfd)
|
||||||
if (!session) session = fds[i].fd.channel->session;
|
maxfd = fds[i].fd.channel->session->socket_fd;
|
||||||
|
if (!session)
|
||||||
|
session = fds[i].fd.channel->session;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIBSSH2_POLLFD_LISTENER:
|
case LIBSSH2_POLLFD_LISTENER:
|
||||||
FD_SET(fds[i].fd.listener->session->socket_fd, &rfds);
|
FD_SET(fds[i].fd.listener->session->socket_fd, &rfds);
|
||||||
if (fds[i].fd.listener->session->socket_fd > maxfd) maxfd = fds[i].fd.listener->session->socket_fd;
|
if (fds[i].fd.listener->session->socket_fd > maxfd)
|
||||||
if (!session) session = fds[i].fd.listener->session;
|
maxfd = fds[i].fd.listener->session->socket_fd;
|
||||||
|
if (!session)
|
||||||
|
session = fds[i].fd.listener->session;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (session) libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
|
if (session)
|
||||||
"Invalid descriptor passed to libssh2_poll()", 0);
|
libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
|
||||||
|
"Invalid descriptor passed to libssh2_poll()",
|
||||||
|
0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1229,31 +1352,50 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
case LIBSSH2_POLLFD_CHANNEL:
|
case LIBSSH2_POLLFD_CHANNEL:
|
||||||
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want to be ready for read */
|
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want to be ready for read */
|
||||||
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* Not yet known to be ready for read */
|
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* Not yet known to be ready for read */
|
||||||
fds[i].revents |= libssh2_poll_channel_read(fds[i].fd.channel, 0) ? LIBSSH2_POLLFD_POLLIN : 0;
|
fds[i].revents |=
|
||||||
|
libssh2_poll_channel_read(fds[i].fd.channel,
|
||||||
|
0) ?
|
||||||
|
LIBSSH2_POLLFD_POLLIN : 0;
|
||||||
}
|
}
|
||||||
if ((fds[i].events & LIBSSH2_POLLFD_POLLEXT) && /* Want to be ready for extended read */
|
if ((fds[i].events & LIBSSH2_POLLFD_POLLEXT) && /* Want to be ready for extended read */
|
||||||
((fds[i].revents & LIBSSH2_POLLFD_POLLEXT) == 0)) { /* Not yet known to be ready for extended read */
|
((fds[i].revents & LIBSSH2_POLLFD_POLLEXT) == 0)) { /* Not yet known to be ready for extended read */
|
||||||
fds[i].revents |= libssh2_poll_channel_read(fds[i].fd.channel, 1) ? LIBSSH2_POLLFD_POLLEXT : 0;
|
fds[i].revents |=
|
||||||
|
libssh2_poll_channel_read(fds[i].fd.channel,
|
||||||
|
1) ?
|
||||||
|
LIBSSH2_POLLFD_POLLEXT : 0;
|
||||||
}
|
}
|
||||||
if ((fds[i].events & LIBSSH2_POLLFD_POLLOUT) && /* Want to be ready for write */
|
if ((fds[i].events & LIBSSH2_POLLFD_POLLOUT) && /* Want to be ready for write */
|
||||||
((fds[i].revents & LIBSSH2_POLLFD_POLLOUT) == 0)) { /* Not yet known to be ready for write */
|
((fds[i].revents & LIBSSH2_POLLFD_POLLOUT) == 0)) { /* Not yet known to be ready for write */
|
||||||
fds[i].revents |= libssh2_poll_channel_write(fds[i].fd.channel) ? LIBSSH2_POLLFD_POLLOUT : 0;
|
fds[i].revents |=
|
||||||
|
libssh2_poll_channel_write(fds[i].fd.
|
||||||
|
channel) ?
|
||||||
|
LIBSSH2_POLLFD_POLLOUT : 0;
|
||||||
}
|
}
|
||||||
if (fds[i].fd.channel->remote.close || fds[i].fd.channel->local.close) {
|
if (fds[i].fd.channel->remote.close
|
||||||
|
|| fds[i].fd.channel->local.close) {
|
||||||
fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED;
|
fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED;
|
||||||
}
|
}
|
||||||
if (fds[i].fd.channel->session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
|
if (fds[i].fd.channel->session->socket_state ==
|
||||||
fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
|
LIBSSH2_SOCKET_DISCONNECTED) {
|
||||||
|
fds[i].revents |=
|
||||||
|
LIBSSH2_POLLFD_CHANNEL_CLOSED |
|
||||||
|
LIBSSH2_POLLFD_SESSION_CLOSED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIBSSH2_POLLFD_LISTENER:
|
case LIBSSH2_POLLFD_LISTENER:
|
||||||
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want a connection */
|
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want a connection */
|
||||||
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* No connections known of yet */
|
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* No connections known of yet */
|
||||||
fds[i].revents |= libssh2_poll_listener_queued(fds[i].fd.listener) ? LIBSSH2_POLLFD_POLLIN : 0;
|
fds[i].revents |=
|
||||||
|
libssh2_poll_listener_queued(fds[i].fd.
|
||||||
|
listener) ?
|
||||||
|
LIBSSH2_POLLFD_POLLIN : 0;
|
||||||
}
|
}
|
||||||
if (fds[i].fd.listener->session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
|
if (fds[i].fd.listener->session->socket_state ==
|
||||||
fds[i].revents |= LIBSSH2_POLLFD_LISTENER_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
|
LIBSSH2_SOCKET_DISCONNECTED) {
|
||||||
|
fds[i].revents |=
|
||||||
|
LIBSSH2_POLLFD_LISTENER_CLOSED |
|
||||||
|
LIBSSH2_POLLFD_SESSION_CLOSED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1267,7 +1409,6 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
/* Don't block on the sockets if we have channels/listeners which are ready */
|
/* Don't block on the sockets if we have channels/listeners which are ready */
|
||||||
timeout_remaining = 0;
|
timeout_remaining = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_POLL
|
#ifdef HAVE_POLL
|
||||||
|
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
@@ -1301,20 +1442,26 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
case LIBSSH2_POLLFD_CHANNEL:
|
case LIBSSH2_POLLFD_CHANNEL:
|
||||||
if (sockets[i].events & POLLIN) {
|
if (sockets[i].events & POLLIN) {
|
||||||
/* Spin session until no data available */
|
/* Spin session until no data available */
|
||||||
while (libssh2_packet_read(fds[i].fd.channel->session) > 0);
|
while (libssh2_packet_read(fds[i].fd.channel->session)
|
||||||
|
> 0);
|
||||||
}
|
}
|
||||||
if (sockets[i].revents & POLLHUP) {
|
if (sockets[i].revents & POLLHUP) {
|
||||||
fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
|
fds[i].revents |=
|
||||||
|
LIBSSH2_POLLFD_CHANNEL_CLOSED |
|
||||||
|
LIBSSH2_POLLFD_SESSION_CLOSED;
|
||||||
}
|
}
|
||||||
sockets[i].revents = 0;
|
sockets[i].revents = 0;
|
||||||
break;
|
break;
|
||||||
case LIBSSH2_POLLFD_LISTENER:
|
case LIBSSH2_POLLFD_LISTENER:
|
||||||
if (sockets[i].events & POLLIN) {
|
if (sockets[i].events & POLLIN) {
|
||||||
/* Spin session until no data available */
|
/* Spin session until no data available */
|
||||||
while (libssh2_packet_read(fds[i].fd.listener->session) > 0);
|
while (libssh2_packet_read(fds[i].fd.listener->session)
|
||||||
|
> 0);
|
||||||
}
|
}
|
||||||
if (sockets[i].revents & POLLHUP) {
|
if (sockets[i].revents & POLLHUP) {
|
||||||
fds[i].revents |= LIBSSH2_POLLFD_LISTENER_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
|
fds[i].revents |=
|
||||||
|
LIBSSH2_POLLFD_LISTENER_CLOSED |
|
||||||
|
LIBSSH2_POLLFD_SESSION_CLOSED;
|
||||||
}
|
}
|
||||||
sockets[i].revents = 0;
|
sockets[i].revents = 0;
|
||||||
break;
|
break;
|
||||||
@@ -1361,14 +1508,17 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
case LIBSSH2_POLLFD_CHANNEL:
|
case LIBSSH2_POLLFD_CHANNEL:
|
||||||
if (FD_ISSET(fds[i].fd.channel->session->socket_fd, &rfds)) {
|
if (FD_ISSET(fds[i].fd.channel->session->socket_fd, &rfds)) {
|
||||||
/* Spin session until no data available */
|
/* Spin session until no data available */
|
||||||
while (libssh2_packet_read(fds[i].fd.channel->session) > 0);
|
while (libssh2_packet_read(fds[i].fd.channel->session)
|
||||||
|
> 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIBSSH2_POLLFD_LISTENER:
|
case LIBSSH2_POLLFD_LISTENER:
|
||||||
if (FD_ISSET(fds[i].fd.listener->session->socket_fd, &rfds)) {
|
if (FD_ISSET
|
||||||
|
(fds[i].fd.listener->session->socket_fd, &rfds)) {
|
||||||
/* Spin session until no data available */
|
/* Spin session until no data available */
|
||||||
while (libssh2_packet_read(fds[i].fd.listener->session) > 0);
|
while (libssh2_packet_read(fds[i].fd.listener->session)
|
||||||
|
> 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1379,5 +1529,5 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeou
|
|||||||
|
|
||||||
return active_fds;
|
return active_fds;
|
||||||
}
|
}
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
961
src/sftp.c
961
src/sftp.c
File diff suppressed because it is too large
Load Diff
@@ -48,9 +48,9 @@
|
|||||||
|
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
#define UNPRINTABLE_CHAR '.'
|
#define UNPRINTABLE_CHAR '.'
|
||||||
static void debugdump(LIBSSH2_SESSION *session,
|
static void
|
||||||
const char *desc, unsigned char *ptr,
|
debugdump(LIBSSH2_SESSION * session,
|
||||||
unsigned long size)
|
const char *desc, unsigned char *ptr, unsigned long size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t c;
|
size_t c;
|
||||||
@@ -66,7 +66,7 @@ static void debugdump(LIBSSH2_SESSION *session,
|
|||||||
|
|
||||||
for(i = 0; i < size; i += width) {
|
for(i = 0; i < size; i += width) {
|
||||||
|
|
||||||
fprintf(stream, "%04lx: ", i);
|
fprintf(stream, "%04lx: ", (long)i);
|
||||||
|
|
||||||
/* hex not disabled, show it */
|
/* hex not disabled, show it */
|
||||||
for(c = 0; c < width; c++) {
|
for(c = 0; c < width; c++) {
|
||||||
@@ -95,7 +95,8 @@ static void debugdump(LIBSSH2_SESSION *session,
|
|||||||
* returns PACKET_NONE on success and PACKET_FAIL on failure
|
* returns PACKET_NONE on success and PACKET_FAIL on failure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static libssh2pack_t decrypt(LIBSSH2_SESSION *session, unsigned char *source,
|
static libssh2pack_t
|
||||||
|
decrypt(LIBSSH2_SESSION * session, unsigned char *source,
|
||||||
unsigned char *dest, int len)
|
unsigned char *dest, int len)
|
||||||
{
|
{
|
||||||
struct transportpacket *p = &session->packet;
|
struct transportpacket *p = &session->packet;
|
||||||
@@ -144,11 +145,11 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
|
|
||||||
/* Calculate MAC hash */
|
/* Calculate MAC hash */
|
||||||
session->remote.mac->hash(session,
|
session->remote.mac->hash(session, macbuf, /* store hash here */
|
||||||
macbuf, /* store hash here */
|
|
||||||
session->remote.seqno,
|
session->remote.seqno,
|
||||||
p->init, 5,
|
p->init, 5,
|
||||||
p->payload, session->fullpacket_payload_len,
|
p->payload,
|
||||||
|
session->fullpacket_payload_len,
|
||||||
&session->remote.mac_abstract);
|
&session->remote.mac_abstract);
|
||||||
|
|
||||||
/* Compare the calculated hash with the MAC we just read from
|
/* Compare the calculated hash with the MAC we just read from
|
||||||
@@ -168,8 +169,7 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
session->fullpacket_payload_len -= p->padding_length;
|
session->fullpacket_payload_len -= p->padding_length;
|
||||||
|
|
||||||
/* Check for and deal with decompression */
|
/* Check for and deal with decompression */
|
||||||
if (session->remote.comp &&
|
if (session->remote.comp && strcmp(session->remote.comp->name, "none")) {
|
||||||
strcmp(session->remote.comp->name, "none")) {
|
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
unsigned long data_len;
|
unsigned long data_len;
|
||||||
int free_payload = 1;
|
int free_payload = 1;
|
||||||
@@ -178,7 +178,8 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
&data, &data_len,
|
&data, &data_len,
|
||||||
LIBSSH2_PACKET_MAXDECOMP,
|
LIBSSH2_PACKET_MAXDECOMP,
|
||||||
&free_payload,
|
&free_payload,
|
||||||
p->payload, session->fullpacket_payload_len,
|
p->payload,
|
||||||
|
session->fullpacket_payload_len,
|
||||||
&session->remote.comp_abstract)) {
|
&session->remote.comp_abstract)) {
|
||||||
LIBSSH2_FREE(session, p->payload);
|
LIBSSH2_FREE(session, p->payload);
|
||||||
return PACKET_FAIL;
|
return PACKET_FAIL;
|
||||||
@@ -188,16 +189,14 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
LIBSSH2_FREE(session, p->payload);
|
LIBSSH2_FREE(session, p->payload);
|
||||||
p->payload = data;
|
p->payload = data;
|
||||||
session->fullpacket_payload_len = data_len;
|
session->fullpacket_payload_len = data_len;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (data == p->payload) {
|
if (data == p->payload) {
|
||||||
/* It's not to be freed, because the
|
/* It's not to be freed, because the
|
||||||
* compression layer reused payload, So let's
|
* compression layer reused payload, So let's
|
||||||
* do the same!
|
* do the same!
|
||||||
*/
|
*/
|
||||||
session->fullpacket_payload_len = data_len;
|
session->fullpacket_payload_len = data_len;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
/* No comp_method actually lets this happen,
|
/* No comp_method actually lets this happen,
|
||||||
* but let's prepare for the future */
|
* but let's prepare for the future */
|
||||||
|
|
||||||
@@ -207,9 +206,9 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
* brigade won't know what to do with it */
|
* brigade won't know what to do with it */
|
||||||
p->payload = LIBSSH2_ALLOC(session, data_len);
|
p->payload = LIBSSH2_ALLOC(session, data_len);
|
||||||
if (!p->payload) {
|
if (!p->payload) {
|
||||||
libssh2_error(session,
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, (char *)
|
||||||
LIBSSH2_ERROR_ALLOC,
|
"Unable to allocate memory for copy of uncompressed data",
|
||||||
(char *)"Unable to allocate memory for copy of uncompressed data", 0);
|
0);
|
||||||
return PACKET_ENOMEM;
|
return PACKET_ENOMEM;
|
||||||
}
|
}
|
||||||
memcpy(p->payload, data, data_len);
|
memcpy(p->payload, data, data_len);
|
||||||
@@ -227,11 +226,12 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->fullpacket_state == libssh2_NB_state_created) {
|
if (session->fullpacket_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_packet_add(session, p->payload, session->fullpacket_payload_len, session->fullpacket_macstate);
|
rc = libssh2_packet_add(session, p->payload,
|
||||||
|
session->fullpacket_payload_len,
|
||||||
|
session->fullpacket_macstate);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
} else if (rc < 0) {
|
||||||
else if (rc < 0) {
|
|
||||||
return PACKET_FAIL;
|
return PACKET_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,8 @@ fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
|||||||
* This function reads the binary stream as specified in chapter 6 of RFC4253
|
* This function reads the binary stream as specified in chapter 6 of RFC4253
|
||||||
* "The Secure Shell (SSH) Transport Layer Protocol"
|
* "The Secure Shell (SSH) Transport Layer Protocol"
|
||||||
*/
|
*/
|
||||||
libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
libssh2pack_t
|
||||||
|
libssh2_packet_read(LIBSSH2_SESSION * session)
|
||||||
{
|
{
|
||||||
libssh2pack_t rc;
|
libssh2pack_t rc;
|
||||||
struct transportpacket *p = &session->packet;
|
struct transportpacket *p = &session->packet;
|
||||||
@@ -324,7 +325,9 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now read a big chunk from the network into the temp buffer */
|
/* now read a big chunk from the network into the temp buffer */
|
||||||
nread = recv(session->socket_fd, &p->buf[remainbuf], PACKETBUFSIZE-remainbuf,
|
nread =
|
||||||
|
recv(session->socket_fd, &p->buf[remainbuf],
|
||||||
|
PACKETBUFSIZE - remainbuf,
|
||||||
LIBSSH2_SOCKET_RECV_FLAGS(session));
|
LIBSSH2_SOCKET_RECV_FLAGS(session));
|
||||||
if (nread <= 0) {
|
if (nread <= 0) {
|
||||||
/* check if this is due to EAGAIN and return
|
/* check if this is due to EAGAIN and return
|
||||||
@@ -382,7 +385,9 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
/* total_num is the number of bytes following the initial
|
/* total_num is the number of bytes following the initial
|
||||||
(5 bytes) packet length and padding length fields */
|
(5 bytes) packet length and padding length fields */
|
||||||
p->total_num = p->packet_length -1 + (encrypted ? session->remote.mac->mac_len : 0);
|
p->total_num =
|
||||||
|
p->packet_length - 1 +
|
||||||
|
(encrypted ? session->remote.mac->mac_len : 0);
|
||||||
|
|
||||||
/* RFC4253 section 6.1 Maximum Packet Length says:
|
/* RFC4253 section 6.1 Maximum Packet Length says:
|
||||||
*
|
*
|
||||||
@@ -515,11 +520,14 @@ libssh2_packet_read_point1:
|
|||||||
|
|
||||||
return PACKET_FAIL; /* we never reach this point */
|
return PACKET_FAIL; /* we never reach this point */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#ifndef OLDSEND
|
#ifndef OLDSEND
|
||||||
|
|
||||||
static libssh2pack_t send_existing(LIBSSH2_SESSION *session, unsigned char *data, unsigned long data_len, ssize_t *ret)
|
static libssh2pack_t
|
||||||
|
send_existing(LIBSSH2_SESSION * session, unsigned char *data,
|
||||||
|
unsigned long data_len, ssize_t * ret)
|
||||||
{
|
{
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
ssize_t length;
|
ssize_t length;
|
||||||
@@ -545,15 +553,15 @@ static libssh2pack_t send_existing(LIBSSH2_SESSION *session, unsigned char *data
|
|||||||
/* number of bytes left to send */
|
/* number of bytes left to send */
|
||||||
length = p->ototal_num - p->osent;
|
length = p->ototal_num - p->osent;
|
||||||
|
|
||||||
rc = send(session->socket_fd, &p->outbuf[p->osent], length, LIBSSH2_SOCKET_SEND_FLAGS(session));
|
rc = send(session->socket_fd, &p->outbuf[p->osent], length,
|
||||||
|
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||||
|
|
||||||
if (rc == length) {
|
if (rc == length) {
|
||||||
/* the remainder of the package was sent */
|
/* the remainder of the package was sent */
|
||||||
LIBSSH2_FREE(session, p->outbuf);
|
LIBSSH2_FREE(session, p->outbuf);
|
||||||
p->outbuf = NULL;
|
p->outbuf = NULL;
|
||||||
p->ototal_num = 0;
|
p->ototal_num = 0;
|
||||||
}
|
} else if (rc < 0) {
|
||||||
else if (rc < 0) {
|
|
||||||
/* nothing was sent */
|
/* nothing was sent */
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
/* send failure! */
|
/* send failure! */
|
||||||
@@ -562,7 +570,8 @@ static libssh2pack_t send_existing(LIBSSH2_SESSION *session, unsigned char *data
|
|||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugdump(session, "libssh2_packet_write send()", &p->outbuf[p->osent], length);
|
debugdump(session, "libssh2_packet_write send()", &p->outbuf[p->osent],
|
||||||
|
length);
|
||||||
p->osent += length; /* we sent away this much data */
|
p->osent += length; /* we sent away this much data */
|
||||||
|
|
||||||
return PACKET_NONE;
|
return PACKET_NONE;
|
||||||
@@ -577,9 +586,13 @@ static libssh2pack_t send_existing(LIBSSH2_SESSION *session, unsigned char *data
|
|||||||
* sent, and this function should then be called with the same argument set
|
* sent, and this function should then be called with the same argument set
|
||||||
* (same data pointer and same data_len) until zero or failure is returned.
|
* (same data pointer and same data_len) until zero or failure is returned.
|
||||||
*/
|
*/
|
||||||
int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned long data_len)
|
int
|
||||||
|
libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
|
||||||
|
unsigned long data_len)
|
||||||
{
|
{
|
||||||
int blocksize = (session->state & LIBSSH2_STATE_NEWKEYS) ? session->local.crypt->blocksize : 8;
|
int blocksize =
|
||||||
|
(session->state & LIBSSH2_STATE_NEWKEYS) ? session->local.crypt->
|
||||||
|
blocksize : 8;
|
||||||
int padding_length;
|
int padding_length;
|
||||||
int packet_length;
|
int packet_length;
|
||||||
int total_length;
|
int total_length;
|
||||||
@@ -608,7 +621,8 @@ int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned
|
|||||||
|
|
||||||
/* check if we should compress */
|
/* check if we should compress */
|
||||||
if (encrypted && strcmp(session->local.comp->name, "none")) {
|
if (encrypted && strcmp(session->local.comp->name, "none")) {
|
||||||
if (session->local.comp->comp(session, 1, &data, &data_len, LIBSSH2_PACKET_MAXCOMP,
|
if (session->local.comp->
|
||||||
|
comp(session, 1, &data, &data_len, LIBSSH2_PACKET_MAXCOMP,
|
||||||
&free_data, data, data_len, &session->local.comp_abstract)) {
|
&free_data, data, data_len, &session->local.comp_abstract)) {
|
||||||
return PACKET_COMPRESS; /* compression failure */
|
return PACKET_COMPRESS; /* compression failure */
|
||||||
}
|
}
|
||||||
@@ -650,7 +664,8 @@ int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned
|
|||||||
packet_length += padding_length;
|
packet_length += padding_length;
|
||||||
|
|
||||||
/* append the MAC length to the total_length size */
|
/* append the MAC length to the total_length size */
|
||||||
total_length = packet_length + (encrypted?session->local.mac->mac_len:0);
|
total_length =
|
||||||
|
packet_length + (encrypted ? session->local.mac->mac_len : 0);
|
||||||
|
|
||||||
/* allocate memory to store the outgoing packet in, in case we can't
|
/* allocate memory to store the outgoing packet in, in case we can't
|
||||||
send the whole one and thus need to keep it after this function
|
send the whole one and thus need to keep it after this function
|
||||||
@@ -678,14 +693,17 @@ int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned
|
|||||||
since that size includes the whole packet. The MAC is
|
since that size includes the whole packet. The MAC is
|
||||||
calculated on the entire unencrypted packet, including all
|
calculated on the entire unencrypted packet, including all
|
||||||
fields except the MAC field itself. */
|
fields except the MAC field itself. */
|
||||||
session->local.mac->hash(session, p->outbuf + packet_length, session->local.seqno, p->outbuf, packet_length,
|
session->local.mac->hash(session, p->outbuf + packet_length,
|
||||||
NULL, 0, &session->local.mac_abstract);
|
session->local.seqno, p->outbuf,
|
||||||
|
packet_length, NULL, 0,
|
||||||
|
&session->local.mac_abstract);
|
||||||
|
|
||||||
/* Encrypt the whole packet data, one block size at a time.
|
/* Encrypt the whole packet data, one block size at a time.
|
||||||
The MAC field is not encrypted. */
|
The MAC field is not encrypted. */
|
||||||
for(i = 0; i < packet_length; i += session->local.crypt->blocksize) {
|
for(i = 0; i < packet_length; i += session->local.crypt->blocksize) {
|
||||||
unsigned char *ptr = &p->outbuf[i];
|
unsigned char *ptr = &p->outbuf[i];
|
||||||
if (session->local.crypt->crypt(session, ptr, &session->local.crypt_abstract))
|
if (session->local.crypt->
|
||||||
|
crypt(session, ptr, &session->local.crypt_abstract))
|
||||||
return PACKET_FAIL; /* encryption failure */
|
return PACKET_FAIL; /* encryption failure */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
783
src/userauth.c
783
src/userauth.c
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
|||||||
##
|
##
|
||||||
## Comments to: Guenter Knauf <eflash@gmx.net>
|
## Comments to: Guenter Knauf <eflash@gmx.net>
|
||||||
##
|
##
|
||||||
## $Id: Makefile.win32,v 1.7 2007/04/21 23:36:51 gknauf Exp $
|
## $Id: Makefile.win32,v 1.8 2007/07/21 22:59:24 gknauf Exp $
|
||||||
#
|
#
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
ifndef ZLIB_PATH
|
ifndef ZLIB_PATH
|
||||||
ZLIB_PATH = ../../zlib-1.2.3
|
ZLIB_PATH = ../../zlib-1.2.3
|
||||||
endif
|
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.
|
# Edit the path below to point to the base of your OpenSSL package.
|
||||||
ifndef OPENSSL_PATH
|
ifndef OPENSSL_PATH
|
||||||
@@ -61,7 +63,7 @@ endif
|
|||||||
ifdef METROWERKS
|
ifdef METROWERKS
|
||||||
CC = mwcc
|
CC = mwcc
|
||||||
else
|
else
|
||||||
CC = gcc
|
CC = $(CRPREFIX)gcc
|
||||||
endif
|
endif
|
||||||
CP = cp -afv
|
CP = cp -afv
|
||||||
# RM = rm -f
|
# RM = rm -f
|
||||||
@@ -87,13 +89,13 @@ CFLAGS += -nostdinc -gccinc -msgstyle gcc -inline off -opt nointrinsics -proc 58
|
|||||||
CFLAGS += -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support"
|
CFLAGS += -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support"
|
||||||
CFLAGS += -w on,nounused,nounusedexpr # -ansi strict
|
CFLAGS += -w on,nounused,nounusedexpr # -ansi strict
|
||||||
else
|
else
|
||||||
LD = gcc
|
LD = $(CRPREFIX)gcc
|
||||||
RC = windres
|
RC = $(CRPREFIX)windres
|
||||||
LDFLAGS = -s -shared -Wl,--out-implib,$(TARGET)dll.a
|
LDFLAGS = -s -shared -Wl,--out-implib,$(TARGET)dll.a
|
||||||
AR = ar
|
AR = $(CRPREFIX)ar
|
||||||
ARFLAGS = -cq
|
ARFLAGS = -cq
|
||||||
LIBEXT = a
|
LIBEXT = a
|
||||||
RANLIB = ranlib
|
RANLIB = $(CRPREFIX)ranlib
|
||||||
#LDLIBS += -lwsock32
|
#LDLIBS += -lwsock32
|
||||||
LDLIBS += -lws2_32
|
LDLIBS += -lws2_32
|
||||||
RCFLAGS = -O coff -i
|
RCFLAGS = -O coff -i
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
# Tweak these for your system
|
# Tweak these for your system
|
||||||
OPENSSLINC=..\libssh2_build\include
|
OPENSSLINC=..\openssl-0.9.8e\inc32
|
||||||
OPENSSLLIB=..\libssh2_build\lib
|
OPENSSLLIB=..\openssl-0.9.8e\out32dll
|
||||||
|
|
||||||
ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\libssh2_build\include
|
ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.3
|
||||||
ZLIBLIB=..\libssh2_build\lib
|
ZLIBLIB=..\zlib-1.2.3
|
||||||
|
|
||||||
!if "$(TARGET)" == ""
|
!if "$(TARGET)" == ""
|
||||||
TARGET=Release
|
TARGET=Release
|
||||||
|
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
Project: "libssh2"=.\libssh2.dsp - Package Owner=<4>
|
Project: "libssh2_dll"=".\libssh2_dll.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
Package=<5>
|
Package=<5>
|
||||||
{{{
|
{{{
|
||||||
@@ -15,7 +15,19 @@ Package=<4>
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
Project: "ssh2_sample"=.\ssh2_sample.dsp - Package Owner=<4>
|
Project: "libssh2_lib"=".\libssh2_lib.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "tests"=".\tests.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
Package=<5>
|
Package=<5>
|
||||||
{{{
|
{{{
|
||||||
|
@@ -9,7 +9,6 @@
|
|||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#define WINSOCK_VERSION MAKEWORD(2,0)
|
|
||||||
#define HAVE_UNISTD_H
|
#define HAVE_UNISTD_H
|
||||||
#define HAVE_INTTYPES_H
|
#define HAVE_INTTYPES_H
|
||||||
#define HAVE_SYS_TIME_H
|
#define HAVE_SYS_TIME_H
|
||||||
@@ -42,8 +41,19 @@ static inline int usleep(int udelay)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
#define vsnprintf _vsnprintf
|
#define vsnprintf _vsnprintf
|
||||||
|
#define strncasecmp _strnicmp
|
||||||
|
#define strcasecmp _stricmp
|
||||||
|
#else
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#define WINSOCK_VERSION MAKEWORD(2,0)
|
||||||
|
#else
|
||||||
|
#define strncasecmp strnicmp
|
||||||
|
#define strcasecmp stricmp
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
/* Compile in zlib support */
|
/* Compile in zlib support */
|
||||||
#define LIBSSH2_HAVE_ZLIB 1
|
#define LIBSSH2_HAVE_ZLIB 1
|
||||||
|
184
win32/libssh2_dll.dsp
Normal file
184
win32/libssh2_dll.dsp
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="libssh2_dll" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||||
|
|
||||||
|
CFG=libssh2_dll - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "libssh2_dll.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "libssh2_dll.mak" CFG="libssh2_dll - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "libssh2_dll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||||
|
!MESSAGE "libssh2_dll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
MTL=midl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "libssh2_dll - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release_dll"
|
||||||
|
# PROP BASE Intermediate_Dir "Release_dll"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release_dll"
|
||||||
|
# PROP Intermediate_Dir "Release_dll"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
|
# SUBTRACT CPP /YX
|
||||||
|
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||||
|
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||||
|
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib ws2_32.lib libeay32.lib ssleay32.lib zlib.lib /nologo /dll /map /debug /machine:I386 /out:"Release_dll/libssh2.dll"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "libssh2_dll - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug_dll"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug_dll"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug_dll"
|
||||||
|
# PROP Intermediate_Dir "Debug_dll"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
|
# SUBTRACT CPP /WX /YX
|
||||||
|
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||||
|
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||||
|
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib ws2_32.lib libeay32.lib ssleay32.lib zlib.lib /nologo /dll /incremental:no /map /debug /machine:I386 /out:"Debug_dll/libssh2.dll" /pdbtype:sept
|
||||||
|
# SUBTRACT LINK32 /nodefaultlib
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "libssh2_dll - Win32 Release"
|
||||||
|
# Name "libssh2_dll - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\channel.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\comp.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\crypt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\hostkey.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\kex.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\mac.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\misc.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\openssl.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\packet.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\pem.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\publickey.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\scp.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\session.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\sftp.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\transport.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\userauth.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\include\libssh2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\libssh2_config.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\include\libssh2_priv.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\include\libssh2_sftp.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
|
|
||||||
|
|
@@ -1,24 +1,24 @@
|
|||||||
# Microsoft Developer Studio Project File - Name="libssh2" - Package Owner=<4>
|
# Microsoft Developer Studio Project File - Name="libssh2_lib" - Package Owner=<4>
|
||||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
# ** DO NOT EDIT **
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||||
|
|
||||||
CFG=libssh2 - Win32 Debug
|
CFG=libssh2_lib - Win32 Debug
|
||||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
!MESSAGE use the Export Makefile command and run
|
!MESSAGE use the Export Makefile command and run
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE NMAKE /f "libssh2.mak".
|
!MESSAGE NMAKE /f "libssh2_lib.mak".
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE You can specify a configuration when running NMAKE
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE NMAKE /f "libssh2.mak" CFG="libssh2 - Win32 Debug"
|
!MESSAGE NMAKE /f "libssh2_lib.mak" CFG="libssh2_lib - Win32 Debug"
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE Possible choices for configuration are:
|
!MESSAGE Possible choices for configuration are:
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE "libssh2 - Win32 Release" (based on "Win32 (x86) Static Library")
|
!MESSAGE "libssh2_lib - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||||
!MESSAGE "libssh2 - Win32 Debug" (based on "Win32 (x86) Static Library")
|
!MESSAGE "libssh2_lib - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
|
|
||||||
# Begin Project
|
# Begin Project
|
||||||
@@ -28,17 +28,17 @@ CFG=libssh2 - Win32 Debug
|
|||||||
CPP=cl.exe
|
CPP=cl.exe
|
||||||
RSC=rc.exe
|
RSC=rc.exe
|
||||||
|
|
||||||
!IF "$(CFG)" == "libssh2 - Win32 Release"
|
!IF "$(CFG)" == "libssh2_lib - Win32 Release"
|
||||||
|
|
||||||
# PROP BASE Use_MFC 0
|
# PROP BASE Use_MFC 0
|
||||||
# PROP BASE Use_Debug_Libraries 0
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
# PROP BASE Output_Dir "libssh2___Win32_Release"
|
# PROP BASE Output_Dir "Release_lib"
|
||||||
# PROP BASE Intermediate_Dir "libssh2___Win32_Release"
|
# PROP BASE Intermediate_Dir "Release_lib"
|
||||||
# PROP BASE Target_Dir ""
|
# PROP BASE Target_Dir ""
|
||||||
# PROP Use_MFC 0
|
# PROP Use_MFC 0
|
||||||
# PROP Use_Debug_Libraries 0
|
# PROP Use_Debug_Libraries 0
|
||||||
# PROP Output_Dir "Release"
|
# PROP Output_Dir "Release_lib"
|
||||||
# PROP Intermediate_Dir "Release"
|
# PROP Intermediate_Dir "Release_lib"
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||||
@@ -50,18 +50,19 @@ BSC32=bscmake.exe
|
|||||||
LIB32=link.exe -lib
|
LIB32=link.exe -lib
|
||||||
# ADD BASE LIB32 /nologo
|
# ADD BASE LIB32 /nologo
|
||||||
# ADD LIB32 /nologo
|
# ADD LIB32 /nologo
|
||||||
|
# ADD LIB32 /nologo /out:"Release_lib\libssh.lib"
|
||||||
|
|
||||||
!ELSEIF "$(CFG)" == "libssh2 - Win32 Debug"
|
!ELSEIF "$(CFG)" == "libssh2_lib - Win32 Debug"
|
||||||
|
|
||||||
# PROP BASE Use_MFC 0
|
# PROP BASE Use_MFC 0
|
||||||
# PROP BASE Use_Debug_Libraries 1
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
# PROP BASE Output_Dir "Debug"
|
# PROP BASE Output_Dir "Debug_lib"
|
||||||
# PROP BASE Intermediate_Dir "Debug"
|
# PROP BASE Intermediate_Dir "Debug_lib"
|
||||||
# PROP BASE Target_Dir ""
|
# PROP BASE Target_Dir ""
|
||||||
# PROP Use_MFC 0
|
# PROP Use_MFC 0
|
||||||
# PROP Use_Debug_Libraries 1
|
# PROP Use_Debug_Libraries 1
|
||||||
# PROP Output_Dir "Debug"
|
# PROP Output_Dir "Debug_lib"
|
||||||
# PROP Intermediate_Dir "Debug"
|
# PROP Intermediate_Dir "Debug_lib"
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||||
@@ -72,14 +73,14 @@ BSC32=bscmake.exe
|
|||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LIB32=link.exe -lib
|
LIB32=link.exe -lib
|
||||||
# ADD BASE LIB32 /nologo
|
# ADD BASE LIB32 /nologo
|
||||||
# ADD LIB32 /nologo /out:"Debug\libssh2d.lib"
|
# ADD LIB32 /nologo /out:"Debug_lib\libssh2d.lib"
|
||||||
|
|
||||||
!ENDIF
|
!ENDIF
|
||||||
|
|
||||||
# Begin Target
|
# Begin Target
|
||||||
|
|
||||||
# Name "libssh2 - Win32 Release"
|
# Name "libssh2_lib - Win32 Release"
|
||||||
# Name "libssh2 - Win32 Debug"
|
# Name "libssh2_lib - Win32 Debug"
|
||||||
# Begin Group "Source Files"
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
@@ -113,10 +114,22 @@ SOURCE=..\src\misc.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\openssl.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\packet.c
|
SOURCE=..\src\packet.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\pem.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\publickey.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\scp.c
|
SOURCE=..\src\scp.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@@ -129,6 +142,10 @@ SOURCE=..\src\sftp.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\transport.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\userauth.c
|
SOURCE=..\src\userauth.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# End Group
|
# End Group
|
||||||
@@ -154,3 +171,5 @@ SOURCE=..\include\libssh2_sftp.h
|
|||||||
# End Group
|
# End Group
|
||||||
# End Target
|
# End Target
|
||||||
# End Project
|
# End Project
|
||||||
|
|
||||||
|
|
@@ -1,24 +1,24 @@
|
|||||||
# Microsoft Developer Studio Project File - Name="ssh2_sample" - Package Owner=<4>
|
# Microsoft Developer Studio Project File - Name="tests" - Package Owner=<4>
|
||||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
# ** DO NOT EDIT **
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
CFG=ssh2_sample - Win32 Debug
|
CFG=tests - Win32 Debug
|
||||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
!MESSAGE use the Export Makefile command and run
|
!MESSAGE use the Export Makefile command and run
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE NMAKE /f "ssh2_sample.mak".
|
!MESSAGE NMAKE /f "tests.mak".
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE You can specify a configuration when running NMAKE
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE NMAKE /f "ssh2_sample.mak" CFG="ssh2_sample - Win32 Debug"
|
!MESSAGE NMAKE /f "tests.mak" CFG="tests - Win32 Debug"
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE Possible choices for configuration are:
|
!MESSAGE Possible choices for configuration are:
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
!MESSAGE "ssh2_sample - Win32 Release" (based on "Win32 (x86) Console Application")
|
!MESSAGE "tests - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
!MESSAGE "ssh2_sample - Win32 Debug" (based on "Win32 (x86) Console Application")
|
!MESSAGE "tests - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
!MESSAGE
|
!MESSAGE
|
||||||
|
|
||||||
# Begin Project
|
# Begin Project
|
||||||
@@ -28,12 +28,12 @@ CFG=ssh2_sample - Win32 Debug
|
|||||||
CPP=cl.exe
|
CPP=cl.exe
|
||||||
RSC=rc.exe
|
RSC=rc.exe
|
||||||
|
|
||||||
!IF "$(CFG)" == "ssh2_sample - Win32 Release"
|
!IF "$(CFG)" == "tests - Win32 Release"
|
||||||
|
|
||||||
# PROP BASE Use_MFC 0
|
# PROP BASE Use_MFC 0
|
||||||
# PROP BASE Use_Debug_Libraries 0
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
# PROP BASE Output_Dir "ssh2_sample___Win32_Release"
|
# PROP BASE Output_Dir "tests___Win32_Release"
|
||||||
# PROP BASE Intermediate_Dir "ssh2_sample___Win32_Release"
|
# PROP BASE Intermediate_Dir "tests___Win32_Release"
|
||||||
# PROP BASE Target_Dir ""
|
# PROP BASE Target_Dir ""
|
||||||
# PROP Use_MFC 0
|
# PROP Use_MFC 0
|
||||||
# PROP Use_Debug_Libraries 0
|
# PROP Use_Debug_Libraries 0
|
||||||
@@ -42,7 +42,7 @@ RSC=rc.exe
|
|||||||
# PROP Ignore_Export_Lib 0
|
# PROP Ignore_Export_Lib 0
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /D "LIBSSH2_LIBRARY" /YX /FD /c
|
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
@@ -50,14 +50,14 @@ BSC32=bscmake.exe
|
|||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LINK32=link.exe
|
LINK32=link.exe
|
||||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2.lib /nologo /subsystem:console /machine:I386 /libpath:"Release"
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2.lib /nologo /subsystem:console /machine:I386 /libpath:"Release" /out:"simple.exe"
|
||||||
|
|
||||||
!ELSEIF "$(CFG)" == "ssh2_sample - Win32 Debug"
|
!ELSEIF "$(CFG)" == "tests - Win32 Debug"
|
||||||
|
|
||||||
# PROP BASE Use_MFC 0
|
# PROP BASE Use_MFC 0
|
||||||
# PROP BASE Use_Debug_Libraries 1
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
# PROP BASE Output_Dir "ssh2_sample___Win32_Debug"
|
# PROP BASE Output_Dir "tests___Win32_Debug"
|
||||||
# PROP BASE Intermediate_Dir "ssh2_sample___Win32_Debug"
|
# PROP BASE Intermediate_Dir "tests___Win32_Debug"
|
||||||
# PROP BASE Target_Dir ""
|
# PROP BASE Target_Dir ""
|
||||||
# PROP Use_MFC 0
|
# PROP Use_MFC 0
|
||||||
# PROP Use_Debug_Libraries 1
|
# PROP Use_Debug_Libraries 1
|
||||||
@@ -66,7 +66,7 @@ LINK32=link.exe
|
|||||||
# PROP Ignore_Export_Lib 0
|
# PROP Ignore_Export_Lib 0
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /D "LIBSSH2_LIBRARY" /YX /FD /GZ /c
|
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
@@ -74,20 +74,20 @@ BSC32=bscmake.exe
|
|||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LINK32=link.exe
|
LINK32=link.exe
|
||||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"Debug"
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"Debug" /out:"simple.exe"
|
||||||
|
|
||||||
!ENDIF
|
!ENDIF
|
||||||
|
|
||||||
# Begin Target
|
# Begin Target
|
||||||
|
|
||||||
# Name "ssh2_sample - Win32 Release"
|
# Name "tests - Win32 Release"
|
||||||
# Name "ssh2_sample - Win32 Debug"
|
# Name "tests - Win32 Debug"
|
||||||
# Begin Group "Source Files"
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\ssh2_sample.c
|
SOURCE=..\tests\simple.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# End Group
|
# End Group
|
||||||
# Begin Group "Header Files"
|
# Begin Group "Header Files"
|
Reference in New Issue
Block a user