diff options
-rw-r--r-- | ConfigureChecks.cmake | 1 | ||||
-rw-r--r-- | config.h.cmake | 3 | ||||
-rw-r--r-- | examples/samplesshd.c | 9 | ||||
-rw-r--r-- | include/libssh/crypto.h | 11 | ||||
-rw-r--r-- | include/libssh/server.h | 28 | ||||
-rw-r--r-- | include/libssh/sftp.h | 10 | ||||
-rw-r--r-- | libssh/channels.c | 10 | ||||
-rw-r--r-- | libssh/crypt.c | 3 |
8 files changed, 43 insertions, 32 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 8ca8258..c2bed2e 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -21,6 +21,7 @@ check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN) endif(CMAKE_COMPILER_IS_GNUC) # HEADER FILES +check_include_file(argp.h HAVE_ARGP_H) check_include_file(pty.h HAVE_PTY_H) check_include_file(terminos.h HAVE_TERMIOS_H) if (WIN32) diff --git a/config.h.cmake b/config.h.cmake index 5b75e6b..b483ea1 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -14,6 +14,9 @@ /************************** HEADER FILES *************************/ +/* Define to 1 if you have the <argp.h> header file. */ +#cmakedefine HAVE_ARGP_H 1 + /* Define to 1 if you have the <pty.h> header file. */ #cmakedefine HAVE_PTY_H 1 diff --git a/examples/samplesshd.c b/examples/samplesshd.c index 142e880..f2013b7 100644 --- a/examples/samplesshd.c +++ b/examples/samplesshd.c @@ -14,7 +14,10 @@ clients must be made or how a client should react. #include <libssh/libssh.h> #include <libssh/server.h> + +#ifdef HAVE_ARGP_H #include <argp.h> +#endif #include <stdlib.h> #include <string.h> #include <stdio.h> @@ -34,7 +37,7 @@ static int auth_password(char *user, char *password){ return 0; return 1; // authenticated } - +#ifdef HAVE_ARGP_H const char *argp_program_version = "libssh server example " SSH_STRINGIFY(LIBSSH_VERSION); const char *argp_program_bug_address = "<libssh@libssh.org>"; @@ -135,6 +138,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { /* Our argp parser. */ static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; +#endif /* HAVE_ARGP_H */ int main(int argc, char **argv){ ssh_session session; @@ -153,12 +157,13 @@ int main(int argc, char **argv){ ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key"); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key"); +#ifdef HAVE_ARGP_H /* * Parse our arguments; every option seen by parse_opt will * be reflected in arguments. */ argp_parse (&argp, argc, argv, 0, 0, sshbind); - +#endif if(ssh_bind_listen(sshbind)<0){ printf("Error listening to socket: %s\n",ssh_get_error(sshbind)); return 1; diff --git a/include/libssh/crypto.h b/include/libssh/crypto.h index d838f24..00bb1c9 100644 --- a/include/libssh/crypto.h +++ b/include/libssh/crypto.h @@ -27,6 +27,12 @@ #define _CRYPTO_H_ #include "config.h" + +#ifdef HAVE_LIBGCRYPT +#include <gcrypt.h> +#endif +#include "libssh/wrapper.h" + #ifdef cbc_encrypt #undef cbc_encrypt #endif @@ -34,11 +40,6 @@ #undef cbc_decrypt #endif -#ifdef HAVE_LIBGCRYPT -#include <gcrypt.h> -#endif -#include "libssh/wrapper.h" - struct ssh_crypto_struct { bignum e,f,x,k,y; unsigned char session_id[SHA_DIGEST_LEN]; diff --git a/include/libssh/server.h b/include/libssh/server.h index c9cf634..a235ffa 100644 --- a/include/libssh/server.h +++ b/include/libssh/server.h @@ -71,62 +71,62 @@ LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind, /** * @brief Start listening to the socket. * - * @param ssh_bind The ssh server bind to use. + * @param ssh_bind_o The ssh server bind to use. * * @return 0 on success, < 0 on error. */ -LIBSSH_API int ssh_bind_listen(ssh_bind ssh_bind); +LIBSSH_API int ssh_bind_listen(ssh_bind ssh_bind_o); /** * @brief Set the session to blocking/nonblocking mode. * - * @param ssh_bind The ssh server bind to use. + * @param ssh_bind_o The ssh server bind to use. * * @param blocking Zero for nonblocking mode. */ -LIBSSH_API void ssh_bind_set_blocking(ssh_bind sshbind, int blocking); +LIBSSH_API void ssh_bind_set_blocking(ssh_bind ssh_bind_o, int blocking); /** * @brief Recover the file descriptor from the session. * - * @param ssh_bind The ssh server bind to get the fd from. + * @param ssh_bind_o The ssh server bind to get the fd from. * * @return The file descriptor. */ -LIBSSH_API socket_t ssh_bind_get_fd(ssh_bind ssh_bind); +LIBSSH_API socket_t ssh_bind_get_fd(ssh_bind ssh_bind_o); /** * @brief Set the file descriptor for a session. * - * @param ssh_bind The ssh server bind to set the fd. + * @param ssh_bind_o The ssh server bind to set the fd. * * @param fd The file descriptssh_bind B */ -LIBSSH_API void ssh_bind_set_fd(ssh_bind sshbind, socket_t fd); +LIBSSH_API void ssh_bind_set_fd(ssh_bind ssh_bind_o, socket_t fd); /** * @brief Allow the file descriptor to accept new sessions. * - * @param ssh_bind The ssh server bind to use. + * @param ssh_bind_o The ssh server bind to use. */ -LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind); +LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o); /** * @brief Accept an incoming ssh connection and initialize the session. * - * @param ssh_bind The ssh server bind to accept a connection. + * @param ssh_bind_o The ssh server bind to accept a connection. * @param session A preallocated ssh session * @see ssh_new * @return A newly allocated ssh session, NULL on error. */ -LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind, ssh_session session); +LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session); /** * @brief Free a ssh servers bind. * - * @param ssh_bind The ssh server bind to free. + * @param ssh_bind_o The ssh server bind to free. */ -LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind); +LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind_o); /** * @brief Exchange the banner and cryptographic keys. diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h index 0293f29..403d0c5 100644 --- a/include/libssh/sftp.h +++ b/include/libssh/sftp.h @@ -243,11 +243,11 @@ LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp); * * @param sftp The sftp session to use. * - * @param index The index number of the extension name you want. + * @param indexn The index number of the extension name you want. * * @return The name of the extension. */ -LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int index); +LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int indexn); /** * @brief Get the data of the extension provided by the server. @@ -256,11 +256,11 @@ LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int * * @param sftp The sftp session to use. * - * @param index The index number of the extension data you want. + * @param indexn The index number of the extension data you want. * * @return The data of the extension. */ -LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned int index); +LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned int indexn); /** * @brief Check if the given extension is supported. @@ -284,7 +284,7 @@ LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name, /** * @brief Open a directory used to obtain directory entries. - * + * @param session The sftp session handle to open the directory. * @param path The path of the directory to open. * diff --git a/libssh/channels.c b/libssh/channels.c index 6f1e3ee..229fe20 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -1838,7 +1838,8 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count, * @param is_stderr A boolean value to mark reading from the stderr flow. * * @return The number of bytes read, 0 on end of file or SSH_ERROR on error. - * + * @warning This function may return less than count bytes of data, and won't + * block until count bytes have been read. * @warning The read function using a buffer has been renamed to * channel_read_buffer(). */ @@ -1876,9 +1877,10 @@ int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr) } } - /* block reading if asked bytes=0 */ - while (buffer_get_rest_len(stdbuf) == 0 || - buffer_get_rest_len(stdbuf) < count) { + /* block reading until at least one byte is read + * and ignore the trivial case count=0 + */ + while (buffer_get_rest_len(stdbuf) == 0 && count > 0) { if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) { leave_function(); return 0; diff --git a/libssh/crypt.c b/libssh/crypt.c index 172d215..2e05146 100644 --- a/libssh/crypt.c +++ b/libssh/crypt.c @@ -37,10 +37,9 @@ #endif #include "libssh/priv.h" -#include "libssh/crypto.h" #include "libssh/session.h" #include "libssh/wrapper.h" - +#include "libssh/crypto.h" uint32_t packet_decrypt_len(ssh_session session, char *crypted){ uint32_t decrypted; |