Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh

This commit is contained in:
Andreas Schneider
2009-11-05 16:08:49 +01:00
8 changed files with 43 additions and 32 deletions

View File

@@ -21,6 +21,7 @@ check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
endif(CMAKE_COMPILER_IS_GNUC) endif(CMAKE_COMPILER_IS_GNUC)
# HEADER FILES # HEADER FILES
check_include_file(argp.h HAVE_ARGP_H)
check_include_file(pty.h HAVE_PTY_H) check_include_file(pty.h HAVE_PTY_H)
check_include_file(terminos.h HAVE_TERMIOS_H) check_include_file(terminos.h HAVE_TERMIOS_H)
if (WIN32) if (WIN32)

View File

@@ -14,6 +14,9 @@
/************************** HEADER FILES *************************/ /************************** 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. */ /* Define to 1 if you have the <pty.h> header file. */
#cmakedefine HAVE_PTY_H 1 #cmakedefine HAVE_PTY_H 1

View File

@@ -14,7 +14,10 @@ clients must be made or how a client should react.
#include <libssh/libssh.h> #include <libssh/libssh.h>
#include <libssh/server.h> #include <libssh/server.h>
#ifdef HAVE_ARGP_H
#include <argp.h> #include <argp.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@@ -34,7 +37,7 @@ static int auth_password(char *user, char *password){
return 0; return 0;
return 1; // authenticated return 1; // authenticated
} }
#ifdef HAVE_ARGP_H
const char *argp_program_version = "libssh server example " const char *argp_program_version = "libssh server example "
SSH_STRINGIFY(LIBSSH_VERSION); SSH_STRINGIFY(LIBSSH_VERSION);
const char *argp_program_bug_address = "<libssh@libssh.org>"; 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. */ /* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
#endif /* HAVE_ARGP_H */
int main(int argc, char **argv){ int main(int argc, char **argv){
ssh_session session; 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_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_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 * Parse our arguments; every option seen by parse_opt will
* be reflected in arguments. * be reflected in arguments.
*/ */
argp_parse (&argp, argc, argv, 0, 0, sshbind); argp_parse (&argp, argc, argv, 0, 0, sshbind);
#endif
if(ssh_bind_listen(sshbind)<0){ if(ssh_bind_listen(sshbind)<0){
printf("Error listening to socket: %s\n",ssh_get_error(sshbind)); printf("Error listening to socket: %s\n",ssh_get_error(sshbind));
return 1; return 1;

View File

@@ -27,6 +27,12 @@
#define _CRYPTO_H_ #define _CRYPTO_H_
#include "config.h" #include "config.h"
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#endif
#include "libssh/wrapper.h"
#ifdef cbc_encrypt #ifdef cbc_encrypt
#undef cbc_encrypt #undef cbc_encrypt
#endif #endif
@@ -34,11 +40,6 @@
#undef cbc_decrypt #undef cbc_decrypt
#endif #endif
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#endif
#include "libssh/wrapper.h"
struct ssh_crypto_struct { struct ssh_crypto_struct {
bignum e,f,x,k,y; bignum e,f,x,k,y;
unsigned char session_id[SHA_DIGEST_LEN]; unsigned char session_id[SHA_DIGEST_LEN];

View File

@@ -71,62 +71,62 @@ LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind,
/** /**
* @brief Start listening to the socket. * @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. * @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. * @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. * @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. * @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. * @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. * @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 * @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. * @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. * @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 * @param session A preallocated ssh session
* @see ssh_new * @see ssh_new
* @return A newly allocated ssh session, NULL on error. * @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. * @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. * @brief Exchange the banner and cryptographic keys.

View File

@@ -243,11 +243,11 @@ LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp);
* *
* @param sftp The sftp session to use. * @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. * @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. * @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 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. * @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. * @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. * @brief Open a directory used to obtain directory entries.
*
* @param session The sftp session handle to open the directory. * @param session The sftp session handle to open the directory.
* @param path The path of the directory to open. * @param path The path of the directory to open.
* *

View File

@@ -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. * @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. * @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 * @warning The read function using a buffer has been renamed to
* channel_read_buffer(). * 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 */ /* block reading until at least one byte is read
while (buffer_get_rest_len(stdbuf) == 0 || * and ignore the trivial case count=0
buffer_get_rest_len(stdbuf) < count) { */
while (buffer_get_rest_len(stdbuf) == 0 && count > 0) {
if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) { if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) {
leave_function(); leave_function();
return 0; return 0;

View File

@@ -37,10 +37,9 @@
#endif #endif
#include "libssh/priv.h" #include "libssh/priv.h"
#include "libssh/crypto.h"
#include "libssh/session.h" #include "libssh/session.h"
#include "libssh/wrapper.h" #include "libssh/wrapper.h"
#include "libssh/crypto.h"
uint32_t packet_decrypt_len(ssh_session session, char *crypted){ uint32_t packet_decrypt_len(ssh_session session, char *crypted){
uint32_t decrypted; uint32_t decrypted;