1
0
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:
Viktor Szakats
2023-04-18 08:41:20 +00:00
parent 2213352758
commit 17801d2064
23 changed files with 160 additions and 182 deletions

View File

@ -10,51 +10,49 @@
# MBEDX509_LIBRARY - path to mbedTLS X.509 library # MBEDX509_LIBRARY - path to mbedTLS X.509 library
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto 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 # Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE) set(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF() endif()
FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509) find_library(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509) find_library(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto) find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE) set(MBEDTLS_FOUND TRUE)
ENDIF() endif()
IF(MBEDTLS_FOUND) if(MBEDTLS_FOUND)
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config # 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_DIR ${MBEDTLS_LIBRARY} PATH)
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_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" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_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}") set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
IF(NOT MBEDTLS_FIND_QUIETLY) if(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:") message(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH) if(MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}") message(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH) endif()
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}") message(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}") message(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY) endif()
ELSE(MBEDTLS_FOUND) elseif(MBEDTLS_FIND_REQUIRED)
IF(MBEDTLS_FIND_REQUIRED) message(FATAL_ERROR "Could not find mbedTLS")
MESSAGE(FATAL_ERROR "Could not find mbedTLS") endif()
ENDIF(MBEDTLS_FIND_REQUIRED)
ENDIF(MBEDTLS_FOUND)
MARK_AS_ADVANCED( mark_as_advanced(
MBEDTLS_INCLUDE_DIR MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES MBEDTLS_LIBRARIES

View File

@ -7,8 +7,7 @@ libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP
#include <libssh2_sftp.h> #include <libssh2_sftp.h>
#define libssh2_sftp_realpath(sftp, path, target, maxlen) \\ #define libssh2_sftp_realpath(sftp, path, target, maxlen) \\
libssh2_sftp_symlink_ex((sftp), \\ libssh2_sftp_symlink_ex((sftp), (path), strlen(path), \\
(path), strlen(path), \\
(target), (maxlen), \\ (target), (maxlen), \\
LIBSSH2_SFTP_REALPATH) LIBSSH2_SFTP_REALPATH)
.fi .fi

View File

@ -32,7 +32,9 @@ if (!libssh2_version(LIBSSH2_VERSION_NUM)) {
Unconditionally get the version number: Unconditionally get the version number:
.nf
printf(\&"libssh2 version: %s\&", libssh2_version(0)); printf(\&"libssh2 version: %s\&", libssh2_version(0));
.fi
.SH AVAILABILITY .SH AVAILABILITY
This function was added in libssh2 1.1, in previous versions there way no way This function was added in libssh2 1.1, in previous versions there way no way
to extract this info in run-time. to extract this info in run-time.

View File

@ -37,16 +37,14 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.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 *pubkey = "/home/username/.ssh/id_rsa.pub";
static const char *privkey = "/home/username/.ssh/id_rsa"; static const char *privkey = "/home/username/.ssh/id_rsa";
static const char *username = "username"; static const char *username = "username";
static const char *password = "password"; static const char *password = "password";
static const char *sftppath = "/tmp/TEST"; /* source path */ static const char *sftppath = "/tmp/TEST"; /* source path */
static const char *dest = "/tmp/TEST2"; /* destination 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) static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
{ {
@ -170,9 +168,9 @@ int main(int argc, char *argv[])
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
tempstorage = fopen(STORAGE, "wb"); tempstorage = fopen(storage, "wb");
if(!tempstorage) { 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; goto shutdown;
} }
@ -274,10 +272,10 @@ int main(int argc, char *argv[])
libssh2_sftp_close(sftp_handle); libssh2_sftp_close(sftp_handle);
fclose(tempstorage); fclose(tempstorage);
tempstorage = fopen(STORAGE, "rb"); tempstorage = fopen(storage, "rb");
if(!tempstorage) { if(!tempstorage) {
/* weird, we can't read the file we just wrote to... */ /* 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; goto shutdown;
} }

View File

@ -190,11 +190,6 @@
significant byte first (like Motorola and SPARC, unlike Intel). */ significant byte first (like Motorola and SPARC, unlike Intel). */
#define WORDS_BIGENDIAN 1 #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. */ /* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS #undef _FILE_OFFSET_BITS

View File

@ -437,7 +437,6 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
{ {
char fingerprint[64], *fprint = fingerprint; char fingerprint[64], *fprint = fingerprint;
int i; int i;
for(i = 0; i < 20; i++, fprint += 3) { for(i = 0; i < 20; i++, fprint += 3) {
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); 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; char fingerprint[64], *fprint = fingerprint;
int i; int i;
for(i = 0; i < 20; i++, fprint += 3) { for(i = 0; i < 20; i++, fprint += 3) {
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); 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; char fingerprint[64], *fprint = fingerprint;
int i; int i;
for(i = 0; i < 20; i++, fprint += 3) { for(i = 0; i < 20; i++, fprint += 3) {
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
} }
@ -2573,15 +2570,14 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
goto clean_exit; goto clean_exit;
} }
/* The first key exchange has been performed, switch to active /* The first key exchange has been performed,
crypt/comp/mac mode */ switch to active crypt/comp/mac mode */
session->state |= LIBSSH2_STATE_NEWKEYS; session->state |= LIBSSH2_STATE_NEWKEYS;
_libssh2_debug((session, LIBSSH2_TRACE_KEX, _libssh2_debug((session, LIBSSH2_TRACE_KEX,
"Received NEWKEYS message")); "Received NEWKEYS message"));
/* This will actually end up being just packet_type(1) for this packet /* This will actually end up being just packet_type(1)
type anyway */ for this packet type anyway */
LIBSSH2_FREE(session, exchange_state->tmp); LIBSSH2_FREE(session, exchange_state->tmp);
if(!session->session_id) { if(!session->session_id) {

View File

@ -197,6 +197,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
ret = -1; ret = -1;
goto fail; goto fail;
} }
/* First read Version field (should be 0). */ /* First read Version field (should be 0). */
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen); ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
if(ret || (nlen != 1 && *n != '\0')) { if(ret || (nlen != 1 && *n != '\0')) {

View File

@ -2410,6 +2410,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx)
defined(OPENSSL_VERSION_MAJOR) && \ defined(OPENSSL_VERSION_MAJOR) && \
OPENSSL_VERSION_MAJOR < 3 && \ OPENSSL_VERSION_MAJOR < 3 && \
!defined(LIBRESSL_VERSION_NUMBER) !defined(LIBRESSL_VERSION_NUMBER)
if(FIPS_mode()) if(FIPS_mode())
return 0; return 0;
#endif #endif

View File

@ -816,8 +816,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* Spec says we MAY ignore bytes sent beyond * Spec says we MAY ignore bytes sent beyond
* packet_size * packet_size
*/ */
_libssh2_error(session, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"Packet contains more data than we offered" "Packet contains more data than we offered"
" to receive, truncating"); " to receive, truncating");
datalen = channelp->remote.packet_size + data_head; 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 * Spec says we MAY ignore bytes sent beyond
* window_size * window_size
*/ */
_libssh2_error(session, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"The current receive window is full," "The current receive window is full,"
" data ignored"); " data ignored");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@ -840,8 +838,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if(channelp->read_avail + datalen - data_head > if(channelp->read_avail + datalen - data_head >
channelp->remote.window_size) { channelp->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 " "Remote sent more data than current "
"window allows, truncating"); "window allows, truncating");
datalen = channelp->remote.window_size - datalen = channelp->remote.window_size -

View File

@ -693,7 +693,6 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
*(p++) = '\0'; *(p++) = '\0';
/* Make sure we don't get fooled by leftover values */ /* Make sure we don't get fooled by leftover values */
session->scpRecv_mode = strtol(s, &e, 8); session->scpRecv_mode = strtol(s, &e, 8);
if(e && *e) { if(e && *e) {
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,

View File

@ -56,8 +56,8 @@
time_t entry_time = time(NULL); \ time_t entry_time = time(NULL); \
do { \ do { \
rc = x; \ rc = x; \
/* the order of the check below is important to properly deal with \ /* the order of the check below is important to properly \
the case when the 'sess' is freed */ \ deal with the case when the 'sess' is freed */ \
if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \ if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \
break; \ break; \
rc = _libssh2_wait_socket(sess, entry_time); \ rc = _libssh2_wait_socket(sess, entry_time); \

View File

@ -37,14 +37,6 @@
#include "libssh2_priv.h" #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 LIBSSH2_API
const char *libssh2_version(int req_version_num) const char *libssh2_version(int req_version_num)
{ {