mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
tidy-up: fix more nits
- fix indentation errors. - reformat `cmake/FindmbedTLS.cmake` - replace a macro with a variable in `example/sftp_RW_nonblock.c`. - delete macOS macro `_DARWIN_USE_64_BIT_INODE` from the OS/400 config header, `os400/libssh2_config.h`. - fix other minor nits. Closes #983
This commit is contained in:
@ -10,51 +10,49 @@
|
||||
# MBEDX509_LIBRARY - path to mbedTLS X.509 library
|
||||
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
|
||||
|
||||
FIND_PATH(MBEDTLS_INCLUDE_DIR mbedtls/version.h)
|
||||
find_path(MBEDTLS_INCLUDE_DIR mbedtls/version.h)
|
||||
|
||||
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
|
||||
if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
|
||||
# Already in cache, be silent
|
||||
SET(MBEDTLS_FIND_QUIETLY TRUE)
|
||||
ENDIF()
|
||||
set(MBEDTLS_FIND_QUIETLY TRUE)
|
||||
endif()
|
||||
|
||||
FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
|
||||
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
|
||||
FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
|
||||
find_library(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
|
||||
find_library(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
|
||||
find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
|
||||
|
||||
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
|
||||
SET(MBEDTLS_FOUND TRUE)
|
||||
ENDIF()
|
||||
if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
|
||||
set(MBEDTLS_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
IF(MBEDTLS_FOUND)
|
||||
if(MBEDTLS_FOUND)
|
||||
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config
|
||||
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
|
||||
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
|
||||
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
|
||||
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
|
||||
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
|
||||
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
|
||||
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
|
||||
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
|
||||
get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
|
||||
get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
|
||||
get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
|
||||
get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
|
||||
string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
|
||||
string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
|
||||
string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
|
||||
set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
|
||||
|
||||
IF(NOT MBEDTLS_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found mbedTLS:")
|
||||
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
|
||||
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
|
||||
IF (MBEDTLSMATCH)
|
||||
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
|
||||
MESSAGE(STATUS " version ${MBEDTLS_VERSION}")
|
||||
ENDIF(MBEDTLSMATCH)
|
||||
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
|
||||
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
|
||||
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
|
||||
ENDIF(NOT MBEDTLS_FIND_QUIETLY)
|
||||
ELSE(MBEDTLS_FOUND)
|
||||
IF(MBEDTLS_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find mbedTLS")
|
||||
ENDIF(MBEDTLS_FIND_REQUIRED)
|
||||
ENDIF(MBEDTLS_FOUND)
|
||||
if(NOT MBEDTLS_FIND_QUIETLY)
|
||||
message(STATUS "Found mbedTLS:")
|
||||
file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
|
||||
string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
|
||||
if(MBEDTLSMATCH)
|
||||
string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
|
||||
message(STATUS " version ${MBEDTLS_VERSION}")
|
||||
endif()
|
||||
message(STATUS " TLS: ${MBEDTLS_LIBRARY}")
|
||||
message(STATUS " X509: ${MBEDX509_LIBRARY}")
|
||||
message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
|
||||
endif()
|
||||
elseif(MBEDTLS_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find mbedTLS")
|
||||
endif()
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
mark_as_advanced(
|
||||
MBEDTLS_INCLUDE_DIR
|
||||
MBEDTLS_LIBRARY_DIR
|
||||
MBEDTLS_LIBRARIES
|
||||
|
@ -7,8 +7,7 @@ libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#define libssh2_sftp_realpath(sftp, path, target, maxlen) \\
|
||||
libssh2_sftp_symlink_ex((sftp), \\
|
||||
(path), strlen(path), \\
|
||||
libssh2_sftp_symlink_ex((sftp), (path), strlen(path), \\
|
||||
(target), (maxlen), \\
|
||||
LIBSSH2_SFTP_REALPATH)
|
||||
.fi
|
||||
|
@ -32,7 +32,9 @@ if (!libssh2_version(LIBSSH2_VERSION_NUM)) {
|
||||
|
||||
Unconditionally get the version number:
|
||||
|
||||
.nf
|
||||
printf(\&"libssh2 version: %s\&", libssh2_version(0));
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libssh2 1.1, in previous versions there way no way
|
||||
to extract this info in run-time.
|
||||
|
@ -37,16 +37,14 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define STORAGE "/tmp/sftp-storage" /* this is the local file name this
|
||||
example uses to store the downloaded
|
||||
file in */
|
||||
|
||||
static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
static const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
static const char *username = "username";
|
||||
static const char *password = "password";
|
||||
static const char *sftppath = "/tmp/TEST"; /* source path */
|
||||
static const char *dest = "/tmp/TEST2"; /* destination path */
|
||||
static const char *storage = "/tmp/sftp-storage"; /* local file name to store
|
||||
the downloaded file in */
|
||||
|
||||
static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
{
|
||||
@ -170,9 +168,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
tempstorage = fopen(STORAGE, "wb");
|
||||
tempstorage = fopen(storage, "wb");
|
||||
if(!tempstorage) {
|
||||
fprintf(stderr, "Can't open temp storage file %s\n", STORAGE);
|
||||
fprintf(stderr, "Can't open temp storage file %s\n", storage);
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
@ -274,10 +272,10 @@ int main(int argc, char *argv[])
|
||||
libssh2_sftp_close(sftp_handle);
|
||||
fclose(tempstorage);
|
||||
|
||||
tempstorage = fopen(STORAGE, "rb");
|
||||
tempstorage = fopen(storage, "rb");
|
||||
if(!tempstorage) {
|
||||
/* weird, we can't read the file we just wrote to... */
|
||||
fprintf(stderr, "can't open %s for reading\n", STORAGE);
|
||||
fprintf(stderr, "can't open %s for reading\n", storage);
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
|
@ -190,11 +190,6 @@
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#define WORDS_BIGENDIAN 1
|
||||
|
||||
/* Enable large inode numbers on Mac OS X 10.5. */
|
||||
#ifndef _DARWIN_USE_64_BIT_INODE
|
||||
# define _DARWIN_USE_64_BIT_INODE 1
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
|
12
src/kex.c
12
src/kex.c
@ -437,7 +437,6 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
|
||||
{
|
||||
char fingerprint[64], *fprint = fingerprint;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 20; i++, fprint += 3) {
|
||||
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
|
||||
}
|
||||
@ -1800,7 +1799,6 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
|
||||
{
|
||||
char fingerprint[64], *fprint = fingerprint;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 20; i++, fprint += 3) {
|
||||
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
|
||||
}
|
||||
@ -2430,7 +2428,6 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
{
|
||||
char fingerprint[64], *fprint = fingerprint;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 20; i++, fprint += 3) {
|
||||
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
|
||||
}
|
||||
@ -2573,15 +2570,14 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
/* The first key exchange has been performed, switch to active
|
||||
crypt/comp/mac mode */
|
||||
|
||||
/* The first key exchange has been performed,
|
||||
switch to active crypt/comp/mac mode */
|
||||
session->state |= LIBSSH2_STATE_NEWKEYS;
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
||||
"Received NEWKEYS message"));
|
||||
|
||||
/* This will actually end up being just packet_type(1) for this packet
|
||||
type anyway */
|
||||
/* This will actually end up being just packet_type(1)
|
||||
for this packet type anyway */
|
||||
LIBSSH2_FREE(session, exchange_state->tmp);
|
||||
|
||||
if(!session->session_id) {
|
||||
|
@ -197,6 +197,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* First read Version field (should be 0). */
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
if(ret || (nlen != 1 && *n != '\0')) {
|
||||
|
@ -2410,6 +2410,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx)
|
||||
defined(OPENSSL_VERSION_MAJOR) && \
|
||||
OPENSSL_VERSION_MAJOR < 3 && \
|
||||
!defined(LIBRESSL_VERSION_NUMBER)
|
||||
|
||||
if(FIPS_mode())
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -816,8 +816,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
* Spec says we MAY ignore bytes sent beyond
|
||||
* packet_size
|
||||
*/
|
||||
_libssh2_error(session,
|
||||
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
|
||||
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
|
||||
"Packet contains more data than we offered"
|
||||
" to receive, truncating");
|
||||
datalen = channelp->remote.packet_size + data_head;
|
||||
@ -827,8 +826,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
* Spec says we MAY ignore bytes sent beyond
|
||||
* window_size
|
||||
*/
|
||||
_libssh2_error(session,
|
||||
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
|
||||
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
|
||||
"The current receive window is full,"
|
||||
" data ignored");
|
||||
LIBSSH2_FREE(session, data);
|
||||
@ -840,8 +838,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
|
||||
if(channelp->read_avail + datalen - data_head >
|
||||
channelp->remote.window_size) {
|
||||
_libssh2_error(session,
|
||||
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
|
||||
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
|
||||
"Remote sent more data than current "
|
||||
"window allows, truncating");
|
||||
datalen = channelp->remote.window_size -
|
||||
|
@ -693,7 +693,6 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
|
||||
*(p++) = '\0';
|
||||
/* Make sure we don't get fooled by leftover values */
|
||||
|
||||
session->scpRecv_mode = strtol(s, &e, 8);
|
||||
if(e && *e) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
|
@ -56,8 +56,8 @@
|
||||
time_t entry_time = time(NULL); \
|
||||
do { \
|
||||
rc = x; \
|
||||
/* the order of the check below is important to properly deal with \
|
||||
the case when the 'sess' is freed */ \
|
||||
/* the order of the check below is important to properly \
|
||||
deal with the case when the 'sess' is freed */ \
|
||||
if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \
|
||||
break; \
|
||||
rc = _libssh2_wait_socket(sess, entry_time); \
|
||||
|
@ -37,14 +37,6 @@
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
/*
|
||||
libssh2_version() can be used like this:
|
||||
|
||||
if(!libssh2_version(LIBSSH2_VERSION_NUM)) {
|
||||
fprintf(stderr, "Runtime libssh2 version too old!\n");
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
LIBSSH2_API
|
||||
const char *libssh2_version(int req_version_num)
|
||||
{
|
||||
|
Reference in New Issue
Block a user