aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2009-09-23 23:51:04 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2009-09-23 23:51:04 +0200
commitf84ebc2e2770b16b43c62ecb67cf8d4bd1b99d72 (patch)
tree82abdf7a1e84c9a281f622e38247e67563d68ffa
parentb359229a2ea6f8b623add9bea02015991c8d6e9d (diff)
downloadlibssh-f84ebc2e2770b16b43c62ecb67cf8d4bd1b99d72.tar.gz
libssh-f84ebc2e2770b16b43c62ecb67cf8d4bd1b99d72.tar.xz
libssh-f84ebc2e2770b16b43c62ecb67cf8d4bd1b99d72.zip
Moved lots of declaration out of priv.h
-rw-r--r--include/libssh/agent.h48
-rw-r--r--include/libssh/buffer.h62
-rw-r--r--include/libssh/channels.h58
-rw-r--r--include/libssh/keyfiles.h33
-rw-r--r--include/libssh/packet.h34
-rw-r--r--include/libssh/poll.h61
-rw-r--r--include/libssh/priv.h319
-rw-r--r--include/libssh/scp.h56
-rw-r--r--include/libssh/session.h97
-rw-r--r--include/libssh/socket.h55
-rw-r--r--include/libssh/string.h42
-rw-r--r--libssh/agent.c3
-rw-r--r--libssh/auth.c5
-rw-r--r--libssh/auth1.c4
-rw-r--r--libssh/base64.c1
-rw-r--r--libssh/buffer.c8
-rw-r--r--libssh/channels.c7
-rw-r--r--libssh/channels1.c6
-rw-r--r--libssh/client.c4
-rw-r--r--libssh/connect.c3
-rw-r--r--libssh/crypt.c1
-rw-r--r--libssh/dh.c7
-rw-r--r--libssh/gzip.c2
-rw-r--r--libssh/init.c2
-rw-r--r--libssh/kex.c9
-rw-r--r--libssh/keyfiles.c6
-rw-r--r--libssh/keys.c17
-rw-r--r--libssh/log.c1
-rw-r--r--libssh/messages.c5
-rw-r--r--libssh/packet.c5
-rw-r--r--libssh/poll.c1
-rw-r--r--libssh/scp.c1
-rw-r--r--libssh/server.c6
-rw-r--r--libssh/session.c5
-rw-r--r--libssh/sftp.c7
-rw-r--r--libssh/sftpserver.c5
-rw-r--r--libssh/socket.c4
-rw-r--r--libssh/string.c2
-rw-r--r--libssh/wrapper.c1
39 files changed, 651 insertions, 342 deletions
diff --git a/include/libssh/agent.h b/include/libssh/agent.h
index 42cb230..fca577d 100644
--- a/include/libssh/agent.h
+++ b/include/libssh/agent.h
@@ -1,6 +1,8 @@
#ifndef __AGENT_H
#define __AGENT_H
+#include "libssh/libssh.h"
+
/* Messages for the authentication agent connection. */
#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
#define SSH_AGENT_RSA_IDENTITIES_ANSWER 2
@@ -45,5 +47,51 @@
#define SSH_AGENT_OLD_SIGNATURE 0x01
+struct ssh_agent_struct {
+ struct socket *sock;
+ ssh_buffer ident;
+ unsigned int count;
+};
+
+#ifndef _WIN32
+/* agent.c */
+/**
+ * @brief Create a new ssh agent structure.
+ *
+ * @return An allocated ssh agent structure or NULL on error.
+ */
+struct ssh_agent_struct *agent_new(struct ssh_session_struct *session);
+
+void agent_close(struct ssh_agent_struct *agent);
+
+/**
+ * @brief Free an allocated ssh agent structure.
+ *
+ * @param agent The ssh agent structure to free.
+ */
+void agent_free(struct ssh_agent_struct *agent);
+
+/**
+ * @brief Check if the ssh agent is running.
+ *
+ * @param session The ssh session to check for the agent.
+ *
+ * @return 1 if it is running, 0 if not.
+ */
+int agent_is_running(struct ssh_session_struct *session);
+
+int agent_get_ident_count(struct ssh_session_struct *session);
+
+struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
+ char **comment);
+
+struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *session,
+ char **comment);
+
+ssh_string agent_sign_data(struct ssh_session_struct *session,
+ struct ssh_buffer_struct *data,
+ struct ssh_public_key_struct *pubkey);
+#endif
+
#endif /* __AGENT_H */
/* vim: set ts=2 sw=2 et cindent: */
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
new file mode 100644
index 0000000..d8055fd
--- /dev/null
+++ b/include/libssh/buffer.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef BUFFER_H_
+#define BUFFER_H_
+
+/** Describes a buffer state at a moment
+ */
+struct ssh_buffer_struct {
+ char *data;
+ uint32_t used;
+ uint32_t allocated;
+ uint32_t pos;
+};
+
+int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
+int buffer_add_u8(ssh_buffer buffer, uint8_t data);
+int buffer_add_u32(ssh_buffer buffer, uint32_t data);
+int buffer_add_u64(ssh_buffer buffer, uint64_t data);
+int buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
+int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
+int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
+int buffer_reinit(ssh_buffer buffer);
+
+/* buffer_get_rest returns a pointer to the current position into the buffer */
+void *buffer_get_rest(ssh_buffer buffer);
+/* buffer_get_rest_len returns the number of bytes which can be read */
+uint32_t buffer_get_rest_len(ssh_buffer buffer);
+
+/* buffer_read_*() returns the number of bytes read, except for ssh strings */
+int buffer_get_u8(ssh_buffer buffer, uint8_t *data);
+int buffer_get_u32(ssh_buffer buffer, uint32_t *data);
+int buffer_get_u64(ssh_buffer buffer, uint64_t *data);
+
+uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
+/* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
+ssh_string buffer_get_ssh_string(ssh_buffer buffer);
+/* gets a string out of a SSH-1 mpint */
+ssh_string buffer_get_mpint(ssh_buffer buffer);
+/* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
+uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
+uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
+
+#endif /* BUFFER_H_ */
diff --git a/include/libssh/channels.h b/include/libssh/channels.h
new file mode 100644
index 0000000..6e3bb28
--- /dev/null
+++ b/include/libssh/channels.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef CHANNELS_H_
+#define CHANNELS_H_
+#include "libssh/priv.h"
+
+struct ssh_channel_struct {
+ struct ssh_channel_struct *prev;
+ struct ssh_channel_struct *next;
+ ssh_session session; /* SSH_SESSION pointer */
+ uint32_t local_channel;
+ uint32_t local_window;
+ int local_eof;
+ uint32_t local_maxpacket;
+
+ uint32_t remote_channel;
+ uint32_t remote_window;
+ int remote_eof; /* end of file received */
+ uint32_t remote_maxpacket;
+ int open; /* shows if the channel is still opened */
+ int delayed_close;
+ ssh_buffer stdout_buffer;
+ ssh_buffer stderr_buffer;
+ void *userarg;
+ int version;
+ int blocking;
+ int exit_status;
+};
+
+void channel_handle(ssh_session session, int type);
+ssh_channel channel_new(ssh_session session);
+int channel_default_bufferize(ssh_channel channel, void *data, int len,
+ int is_stderr);
+uint32_t ssh_channel_new_id(ssh_session session);
+ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
+int channel_write_common(ssh_channel channel, const void *data,
+ uint32_t len, int is_stderr);
+
+#endif /* CHANNELS_H_ */
diff --git a/include/libssh/keyfiles.h b/include/libssh/keyfiles.h
new file mode 100644
index 0000000..80e989f
--- /dev/null
+++ b/include/libssh/keyfiles.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef KEYFILES_H_
+#define KEYFILES_H_
+
+/* in keyfiles.c */
+
+ssh_private_key _privatekey_from_file(void *session, const char *filename,
+ int type);
+ssh_string try_publickey_from_file(ssh_session session,
+ struct ssh_keys_struct keytab,
+ char **privkeyfile, int *type);
+
+#endif /* KEYFILES_H_ */
diff --git a/include/libssh/packet.h b/include/libssh/packet.h
new file mode 100644
index 0000000..b06221d
--- /dev/null
+++ b/include/libssh/packet.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef PACKET_H_
+#define PACKET_H_
+
+void packet_parse(ssh_session session);
+int packet_send(ssh_session session);
+
+int packet_read(ssh_session session);
+int packet_translate(ssh_session session);
+int packet_wait(ssh_session session,int type,int blocking);
+int packet_flush(ssh_session session, int enforce_blocking);
+
+
+#endif /* PACKET_H_ */
diff --git a/include/libssh/poll.h b/include/libssh/poll.h
new file mode 100644
index 0000000..7ba939f
--- /dev/null
+++ b/include/libssh/poll.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef POLL_H_
+#define POLL_H_
+
+/* poll.c */
+int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout);
+typedef struct ssh_poll_ctx SSH_POLL_CTX;
+typedef struct ssh_poll SSH_POLL;
+
+/**
+ * @brief SSH poll callback.
+ *
+ * @param p Poll object this callback belongs to.
+ * @param fd The raw socket.
+ * @param revents The current poll events on the socket.
+ * @param userdata Userdata to be passed to the callback function.
+ *
+ * @return 0 on success, < 0 if you removed the poll object from
+ * it's poll context.
+ */
+typedef int (*ssh_poll_callback)(SSH_POLL *p, int fd, int revents,
+ void *userdata);
+
+
+SSH_POLL *ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
+ void *userdata);
+void ssh_poll_free(SSH_POLL *p);
+SSH_POLL_CTX *ssh_poll_get_ctx(SSH_POLL *p);
+short ssh_poll_get_events(SSH_POLL *p);
+void ssh_poll_set_events(SSH_POLL *p, short events);
+void ssh_poll_add_events(SSH_POLL *p, short events);
+void ssh_poll_remove_events(SSH_POLL *p, short events);
+socket_t ssh_poll_get_fd(SSH_POLL *p);
+void ssh_poll_set_callback(SSH_POLL *p, ssh_poll_callback cb, void *userdata);
+SSH_POLL_CTX *ssh_poll_ctx_new(size_t chunk_size);
+void ssh_poll_ctx_free(SSH_POLL_CTX *ctx);
+int ssh_poll_ctx_add(SSH_POLL_CTX *ctx, SSH_POLL *p);
+void ssh_poll_ctx_remove(SSH_POLL_CTX *ctx, SSH_POLL *p);
+int ssh_poll_ctx(SSH_POLL_CTX *ctx, int timeout);
+
+#endif /* POLL_H_ */
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index 1c13a70..f120619 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -192,32 +192,6 @@ HMACCTX hmac_init(const void *key,int len,int type);
void hmac_update(HMACCTX c, const void *data, unsigned long len);
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
-/* strings and buffers */
-/* must be 32 bits number + immediatly our data */
-#ifdef _MSC_VER
-#pragma pack(1)
-#endif
-struct ssh_string_struct {
- uint32_t size;
- unsigned char string[MAX_PACKET_LEN];
-}
-#if !defined(__SUNPRO_C) && !defined(_MSC_VER)
-__attribute__ ((packed))
-#endif
-#ifdef _MSC_VER
-#pragma pack()
-#endif
-;
-
-/** Describes a buffer state at a moment
- */
-struct ssh_buffer_struct {
- char *data;
- uint32_t used;
- uint32_t allocated;
- uint32_t pos;
-};
-
/* i should remove it one day */
typedef struct packet_struct {
int valid;
@@ -320,137 +294,13 @@ typedef struct ssh_crypto_struct {
void *compress_in_ctx; /* really, don't */
} CRYPTO;
-struct ssh_channel_struct {
- struct ssh_channel_struct *prev;
- struct ssh_channel_struct *next;
- ssh_session session; /* SSH_SESSION pointer */
- uint32_t local_channel;
- uint32_t local_window;
- int local_eof;
- uint32_t local_maxpacket;
-
- uint32_t remote_channel;
- uint32_t remote_window;
- int remote_eof; /* end of file received */
- uint32_t remote_maxpacket;
- int open; /* shows if the channel is still opened */
- int delayed_close;
- ssh_buffer stdout_buffer;
- ssh_buffer stderr_buffer;
- void *userarg;
- int version;
- int blocking;
- int exit_status;
-};
-
-struct ssh_agent_struct {
- struct socket *sock;
- ssh_buffer ident;
- unsigned int count;
-};
-
struct ssh_keys_struct {
const char *privatekey;
const char *publickey;
};
-enum ssh_scp_states {
- SSH_SCP_NEW, //Data structure just created
- SSH_SCP_WRITE_INITED, //Gave our intention to write
- SSH_SCP_WRITE_WRITING,//File was opened and currently writing
- SSH_SCP_READ_INITED, //Gave our intention to read
- SSH_SCP_READ_REQUESTED, //We got a read request
- SSH_SCP_READ_READING, //File is opened and reading
- SSH_SCP_ERROR, //Something bad happened
- SSH_SCP_TERMINATED //Transfer finished
-};
-
-struct ssh_scp_struct {
- ssh_session session;
- int mode;
- int recursive;
- ssh_channel channel;
- char *location;
- enum ssh_scp_states state;
- size_t filelen;
- size_t processed;
- enum ssh_scp_request_types request_type;
- char *request_name;
- char *warning;
- int request_mode;
-};
-
struct ssh_message_struct;
-struct ssh_session_struct {
- struct error_struct error;
- struct socket *socket;
- ssh_options options;
- char *serverbanner;
- char *clientbanner;
- int protoversion;
- int server;
- int client;
- int openssh;
- uint32_t send_seq;
- uint32_t recv_seq;
-/* status flags */
- int closed;
- int closed_by_except;
-
- int connected;
- /* !=0 when the user got a session handle */
- int alive;
- /* two previous are deprecated */
- int auth_service_asked;
-
-/* socket status */
- int blocking; // functions should block
-
- ssh_string banner; /* that's the issue banner from
- the server */
- char *remotebanner; /* that's the SSH- banner from
- remote host. */
- char *discon_msg; /* disconnect message from
- the remote host */
- ssh_buffer in_buffer;
- PACKET in_packet;
- ssh_buffer out_buffer;
-
- /* the states are used by the nonblocking stuff to remember */
- /* where it was before being interrupted */
- int packet_state;
- int dh_handshake_state;
- ssh_string dh_server_signature; //information used by dh_handshake.
-
- KEX server_kex;
- KEX client_kex;
- ssh_buffer in_hashbuf;
- ssh_buffer out_hashbuf;
- CRYPTO *current_crypto;
- CRYPTO *next_crypto; /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
-
- ssh_channel channels; /* linked list of channels */
- int maxchannel;
- int exec_channel_opened; /* version 1 only. more
- info in channels1.c */
- ssh_agent agent; /* ssh agent */
-
-/* keyb interactive data */
- struct ssh_kbdint_struct *kbdint;
- int version; /* 1 or 2 */
- /* server host keys */
- ssh_private_key rsa_key;
- ssh_private_key dsa_key;
- /* auths accepted by server */
- int auth_methods;
- int hostkeys; /* contains type of host key wanted by client, in server impl */
- struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
- int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg);
- int log_verbosity; /*cached copy of the option structure */
- int log_indent; /* indentation level in enter_function logs */
-};
-
struct ssh_kbdint_struct {
uint32_t nprompts;
char *name;
@@ -523,111 +373,8 @@ struct ssh_message_struct {
struct ssh_service_request service_request;
};
-#ifndef _WIN32
-/* agent.c */
-/**
- * @brief Create a new ssh agent structure.
- *
- * @return An allocated ssh agent structure or NULL on error.
- */
-struct ssh_agent_struct *agent_new(struct ssh_session_struct *session);
-void agent_close(struct ssh_agent_struct *agent);
-/**
- * @brief Free an allocated ssh agent structure.
- *
- * @param agent The ssh agent structure to free.
- */
-void agent_free(struct ssh_agent_struct *agent);
-
-/**
- * @brief Check if the ssh agent is running.
- *
- * @param session The ssh session to check for the agent.
- *
- * @return 1 if it is running, 0 if not.
- */
-int agent_is_running(struct ssh_session_struct *session);
-
-int agent_get_ident_count(struct ssh_session_struct *session);
-
-struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
- char **comment);
-
-struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *session,
- char **comment);
-
-ssh_string agent_sign_data(struct ssh_session_struct *session,
- struct ssh_buffer_struct *data,
- struct ssh_public_key_struct *pubkey);
-#endif
-
-/* poll.c */
-int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout);
-typedef struct ssh_poll_ctx SSH_POLL_CTX;
-typedef struct ssh_poll SSH_POLL;
-
-/**
- * @brief SSH poll callback.
- *
- * @param p Poll object this callback belongs to.
- * @param fd The raw socket.
- * @param revents The current poll events on the socket.
- * @param userdata Userdata to be passed to the callback function.
- *
- * @return 0 on success, < 0 if you removed the poll object from
- * it's poll context.
- */
-typedef int (*ssh_poll_callback)(SSH_POLL *p, int fd, int revents,
- void *userdata);
-
-
-SSH_POLL *ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
- void *userdata);
-void ssh_poll_free(SSH_POLL *p);
-SSH_POLL_CTX *ssh_poll_get_ctx(SSH_POLL *p);
-short ssh_poll_get_events(SSH_POLL *p);
-void ssh_poll_set_events(SSH_POLL *p, short events);
-void ssh_poll_add_events(SSH_POLL *p, short events);
-void ssh_poll_remove_events(SSH_POLL *p, short events);
-socket_t ssh_poll_get_fd(SSH_POLL *p);
-void ssh_poll_set_callback(SSH_POLL *p, ssh_poll_callback cb, void *userdata);
-SSH_POLL_CTX *ssh_poll_ctx_new(size_t chunk_size);
-void ssh_poll_ctx_free(SSH_POLL_CTX *ctx);
-int ssh_poll_ctx_add(SSH_POLL_CTX *ctx, SSH_POLL *p);
-void ssh_poll_ctx_remove(SSH_POLL_CTX *ctx, SSH_POLL *p);
-int ssh_poll_ctx(SSH_POLL_CTX *ctx, int timeout);
-
-/* socket.c */
-
-struct socket;
-int ssh_socket_init(void);
-struct socket *ssh_socket_new(ssh_session session);
-void ssh_socket_free(struct socket *s);
-void ssh_socket_set_fd(struct socket *s, socket_t fd);
-socket_t ssh_socket_get_fd(struct socket *s);
-#ifndef _WIN32
-int ssh_socket_unix(struct socket *s, const char *path);
-#endif
-void ssh_socket_close(struct socket *s);
-int ssh_socket_read(struct socket *s, void *buffer, int len);
-int ssh_socket_write(struct socket *s,const void *buffer, int len);
-int ssh_socket_is_open(struct socket *s);
-int ssh_socket_fd_isset(struct socket *s, fd_set *set);
-void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max);
-int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len);
-int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len);
-int ssh_socket_wait_for_data(struct socket *s, ssh_session session, uint32_t len);
-int ssh_socket_nonblocking_flush(struct socket *s);
-int ssh_socket_blocking_flush(struct socket *s);
-int ssh_socket_poll(struct socket *s, int *writeable, int *except);
-void ssh_socket_set_towrite(struct socket *s);
-void ssh_socket_set_toread(struct socket *s);
-void ssh_socket_set_except(struct socket *s);
-int ssh_socket_get_status(struct socket *s);
-int ssh_socket_data_available(struct socket *s);
-int ssh_socket_data_writable(struct socket *s);
/* session.c */
void ssh_cleanup(ssh_session session);
@@ -679,15 +426,6 @@ unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len)
/* it returns the hmac buffer if exists*/
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
-/* in packet.c */
-
-void packet_parse(ssh_session session);
-int packet_send(ssh_session session);
-
-int packet_read(ssh_session session);
-int packet_translate(ssh_session session);
-int packet_wait(ssh_session session,int type,int blocking);
-int packet_flush(ssh_session session, int enforce_blocking);
/* connect.c */
int ssh_regex_init(void);
@@ -707,14 +445,6 @@ char **space_tokenize(const char *chain);
int ssh_get_kex1(ssh_session session);
char *ssh_find_matching(const char *in_d, const char *what_d);
-/* in keyfiles.c */
-
-ssh_private_key _privatekey_from_file(void *session, const char *filename,
- int type);
-ssh_string try_publickey_from_file(ssh_session session,
- struct ssh_keys_struct keytab,
- char **privkeyfile, int *type);
-
/* in keys.c */
const char *ssh_type_to_char(int type);
int ssh_type_from_name(const char *name);
@@ -736,15 +466,7 @@ ssh_string ssh_do_sign(ssh_session session,ssh_buffer sigbuf,
ssh_private_key privatekey);
ssh_string ssh_sign_session_id(ssh_session session, ssh_private_key privatekey);
ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key key);
-/* channel.c */
-void channel_handle(ssh_session session, int type);
-ssh_channel channel_new(ssh_session session);
-int channel_default_bufferize(ssh_channel channel, void *data, int len,
- int is_stderr);
-uint32_t ssh_channel_new_id(ssh_session session);
-ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
-int channel_write_common(ssh_channel channel, const void *data,
- uint32_t len, int is_stderr);
+
/* options.c */
@@ -753,35 +475,6 @@ int ssh_options_default_username(ssh_options opt);
int ssh_options_default_ssh_dir(ssh_options opt);
int ssh_options_default_known_hosts_file(ssh_options opt);
-/* buffer.c */
-int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
-int buffer_add_u8(ssh_buffer buffer, uint8_t data);
-int buffer_add_u32(ssh_buffer buffer, uint32_t data);
-int buffer_add_u64(ssh_buffer buffer, uint64_t data);
-int buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
-int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
-int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
-int buffer_reinit(ssh_buffer buffer);
-
-/* buffer_get_rest returns a pointer to the current position into the buffer */
-void *buffer_get_rest(ssh_buffer buffer);
-/* buffer_get_rest_len returns the number of bytes which can be read */
-uint32_t buffer_get_rest_len(ssh_buffer buffer);
-
-/* buffer_read_*() returns the number of bytes read, except for ssh strings */
-int buffer_get_u8(ssh_buffer buffer, uint8_t *data);
-int buffer_get_u32(ssh_buffer buffer, uint32_t *data);
-int buffer_get_u64(ssh_buffer buffer, uint64_t *data);
-
-uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
-/* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
-ssh_string buffer_get_ssh_string(ssh_buffer buffer);
-/* gets a string out of a SSH-1 mpint */
-ssh_string buffer_get_mpint(ssh_buffer buffer);
-/* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
-uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
-uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
-
/* in base64.c */
ssh_buffer base64_to_bin(const char *source);
unsigned char *bin_to_base64(const unsigned char *source, int len);
@@ -859,10 +552,6 @@ int channel_request_exec1(ssh_channel channel, const char *cmd);
int channel_handle1(ssh_session session, int type);
int channel_write1(ssh_channel channel, const void *data, int len);
-/* session.c */
-
-int ssh_handle_packets(ssh_session session);
-
/* match.c */
int match_hostname(const char *host, const char *pattern, unsigned int len);
@@ -871,12 +560,6 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
void message_handle(ssh_session session, uint32_t type);
int ssh_execute_message_callbacks(ssh_session session);
-/* scp.c */
-int ssh_scp_read_string(ssh_scp scp, char *buffer, size_t len);
-int ssh_scp_integer_mode(const char *mode);
-char *ssh_scp_string_mode(int mode);
-int ssh_scp_response(ssh_scp scp, char **response);
-
/* log.c */
#ifndef __FUNCTION__
diff --git a/include/libssh/scp.h b/include/libssh/scp.h
new file mode 100644
index 0000000..346c98b
--- /dev/null
+++ b/include/libssh/scp.h
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2003-2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef _SCP_H
+#define _SCP_H
+
+enum ssh_scp_states {
+ SSH_SCP_NEW, //Data structure just created
+ SSH_SCP_WRITE_INITED, //Gave our intention to write
+ SSH_SCP_WRITE_WRITING,//File was opened and currently writing
+ SSH_SCP_READ_INITED, //Gave our intention to read
+ SSH_SCP_READ_REQUESTED, //We got a read request
+ SSH_SCP_READ_READING, //File is opened and reading
+ SSH_SCP_ERROR, //Something bad happened
+ SSH_SCP_TERMINATED //Transfer finished
+};
+
+struct ssh_scp_struct {
+ ssh_session session;
+ int mode;
+ int recursive;
+ ssh_channel channel;
+ char *location;
+ enum ssh_scp_states state;
+ size_t filelen;
+ size_t processed;
+ enum ssh_scp_request_types request_type;
+ char *request_name;
+ char *warning;
+ int request_mode;
+};
+
+int ssh_scp_read_string(ssh_scp scp, char *buffer, size_t len);
+int ssh_scp_integer_mode(const char *mode);
+char *ssh_scp_string_mode(int mode);
+int ssh_scp_response(ssh_scp scp, char **response);
+
+#endif
diff --git a/include/libssh/session.h b/include/libssh/session.h
new file mode 100644
index 0000000..04239a5
--- /dev/null
+++ b/include/libssh/session.h
@@ -0,0 +1,97 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef SESSION_H_
+#define SESSION_H_
+#include "libssh/priv.h"
+
+struct ssh_session_struct {
+ struct error_struct error;
+ struct socket *socket;
+ ssh_options options;
+ char *serverbanner;
+ char *clientbanner;
+ int protoversion;
+ int server;
+ int client;
+ int openssh;
+ uint32_t send_seq;
+ uint32_t recv_seq;
+/* status flags */
+ int closed;
+ int closed_by_except;
+
+ int connected;
+ /* !=0 when the user got a session handle */
+ int alive;
+ /* two previous are deprecated */
+ int auth_service_asked;
+
+/* socket status */
+ int blocking; // functions should block
+
+ ssh_string banner; /* that's the issue banner from
+ the server */
+ char *remotebanner; /* that's the SSH- banner from
+ remote host. */
+ char *discon_msg; /* disconnect message from
+ the remote host */
+ ssh_buffer in_buffer;
+ PACKET in_packet;
+ ssh_buffer out_buffer;
+
+ /* the states are used by the nonblocking stuff to remember */
+ /* where it was before being interrupted */
+ int packet_state;
+ int dh_handshake_state;
+ ssh_string dh_server_signature; //information used by dh_handshake.
+
+ KEX server_kex;
+ KEX client_kex;
+ ssh_buffer in_hashbuf;
+ ssh_buffer out_hashbuf;
+ CRYPTO *current_crypto;
+ CRYPTO *next_crypto; /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
+
+ ssh_channel channels; /* linked list of channels */
+ int maxchannel;
+ int exec_channel_opened; /* version 1 only. more
+ info in channels1.c */
+ ssh_agent agent; /* ssh agent */
+
+/* keyb interactive data */
+ struct ssh_kbdint_struct *kbdint;
+ int version; /* 1 or 2 */
+ /* server host keys */
+ ssh_private_key rsa_key;
+ ssh_private_key dsa_key;
+ /* auths accepted by server */
+ int auth_methods;
+ int hostkeys; /* contains type of host key wanted by client, in server impl */
+ struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
+ int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg);
+ int log_verbosity; /*cached copy of the option structure */
+ int log_indent; /* indentation level in enter_function logs */
+};
+
+int ssh_handle_packets(ssh_session session);
+
+#endif /* SESSION_H_ */
diff --git a/include/libssh/socket.h b/include/libssh/socket.h
new file mode 100644
index 0000000..bb54c7e
--- /dev/null
+++ b/include/libssh/socket.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef SOCKET_H_
+#define SOCKET_H_
+
+/* socket.c */
+
+struct socket;
+int ssh_socket_init(void);
+struct socket *ssh_socket_new(ssh_session session);
+void ssh_socket_free(struct socket *s);
+void ssh_socket_set_fd(struct socket *s, socket_t fd);
+socket_t ssh_socket_get_fd(struct socket *s);
+#ifndef _WIN32
+int ssh_socket_unix(struct socket *s, const char *path);
+#endif
+void ssh_socket_close(struct socket *s);
+int ssh_socket_read(struct socket *s, void *buffer, int len);
+int ssh_socket_write(struct socket *s,const void *buffer, int len);
+int ssh_socket_is_open(struct socket *s);
+int ssh_socket_fd_isset(struct socket *s, fd_set *set);
+void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max);
+int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len);
+int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len);
+int ssh_socket_wait_for_data(struct socket *s, ssh_session session, uint32_t len);
+int ssh_socket_nonblocking_flush(struct socket *s);
+int ssh_socket_blocking_flush(struct socket *s);
+int ssh_socket_poll(struct socket *s, int *writeable, int *except);
+void ssh_socket_set_towrite(struct socket *s);
+void ssh_socket_set_toread(struct socket *s);
+void ssh_socket_set_except(struct socket *s);
+int ssh_socket_get_status(struct socket *s);
+int ssh_socket_data_available(struct socket *s);
+int ssh_socket_data_writable(struct socket *s);
+
+#endif /* SOCKET_H_ */
diff --git a/include/libssh/string.h b/include/libssh/string.h
new file mode 100644
index 0000000..ccdbb17
--- /dev/null
+++ b/include/libssh/string.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef STRING_H_
+#define STRING_H_
+#include "libssh/priv.h"
+
+/* must be 32 bits number + immediately our data */
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
+struct ssh_string_struct {
+ uint32_t size;
+ unsigned char string[MAX_PACKET_LEN];
+}
+#if !defined(__SUNPRO_C) && !defined(_MSC_VER)
+__attribute__ ((packed))
+#endif
+#ifdef _MSC_VER
+#pragma pack()
+#endif
+;
+
+#endif /* STRING_H_ */
diff --git a/libssh/agent.c b/libssh/agent.c
index 81233c1..1f425b6 100644
--- a/libssh/agent.c
+++ b/libssh/agent.c
@@ -50,6 +50,9 @@
#include "libssh/agent.h"
#include "libssh/priv.h"
+#include "libssh/socket.h"
+#include "libssh/buffer.h"
+#include "libssh/session.h"
/* macro to check for "agent failure" message */
#define agent_failed(x) \
diff --git a/libssh/auth.c b/libssh/auth.c
index 8dc17f8..e16f344 100644
--- a/libssh/auth.c
+++ b/libssh/auth.c
@@ -32,6 +32,11 @@
#include "libssh/priv.h"
#include "libssh/ssh2.h"
+#include "libssh/buffer.h"
+#include "libssh/agent.h"
+#include "libssh/keyfiles.h"
+#include "libssh/packet.h"
+#include "libssh/session.h"
/** \defgroup ssh_auth SSH Authentication functions
* \brief functions to authenticate to servers
diff --git a/libssh/auth1.c b/libssh/auth1.c
index 8a3f819..83f0e69 100644
--- a/libssh/auth1.c
+++ b/libssh/auth1.c
@@ -26,6 +26,10 @@
#include "libssh/priv.h"
#include "libssh/ssh1.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/session.h"
+#include "libssh/string.h"
#ifdef WITH_SSH1
static int wait_auth1_status(ssh_session session) {
diff --git a/libssh/base64.c b/libssh/base64.c
index f4d64fb..5f4f440 100644
--- a/libssh/base64.c
+++ b/libssh/base64.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include "libssh/priv.h"
+#include "libssh/buffer.h"
static char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
diff --git a/libssh/buffer.c b/libssh/buffer.c
index 2f450b5..a24dc68 100644
--- a/libssh/buffer.c
+++ b/libssh/buffer.c
@@ -29,7 +29,7 @@
#endif
#include "libssh/priv.h"
-
+#include "libssh/buffer.h"
/** \defgroup ssh_buffer SSH Buffers
* \brief buffer handling
*/
@@ -167,7 +167,7 @@ int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
struct ssh_string_struct *string) {
uint32_t len = 0;
- len = ntohl(string->size);
+ len = string_len(string);
if (buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) {
return -1;
}
@@ -404,7 +404,7 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
if (str == NULL) {
return NULL;
}
- if (buffer_get_data(buffer, str->string, hostlen) != hostlen) {
+ if (buffer_get_data(buffer, string_data(str), hostlen) != hostlen) {
/* should never happen */
SAFE_FREE(str);
return NULL;
@@ -437,7 +437,7 @@ struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
if (str == NULL) {
return NULL;
}
- if (buffer_get_data(buffer, str->string, len) != len) {
+ if (buffer_get_data(buffer, string_data(str), len) != len) {
SAFE_FREE(str);
return NULL;
}
diff --git a/libssh/channels.c b/libssh/channels.c
index 9910370..cb7e543 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -34,6 +34,11 @@
#include "libssh/priv.h"
#include "libssh/ssh2.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/socket.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
#define WINDOWBASE 128000
#define WINDOWLIMIT (WINDOWBASE/2)
@@ -384,7 +389,7 @@ static void channel_rcv_data(ssh_session session,int is_stderr) {
channel->local_window);
}
- if (channel_default_bufferize(channel, str->string, len,
+ if (channel_default_bufferize(channel, string_data(str), len,
is_stderr) < 0) {
string_free(str);
leave_function();
diff --git a/libssh/channels1.c b/libssh/channels1.c
index 5285f17..daa851c 100644
--- a/libssh/channels1.c
+++ b/libssh/channels1.c
@@ -28,6 +28,10 @@
#include <stdio.h>
#include "libssh/priv.h"
#include "libssh/ssh1.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
#ifdef WITH_SSH1
@@ -218,7 +222,7 @@ static int channel_rcv_data1(ssh_session session, int is_stderr) {
"Adding %zu bytes data in %d",
string_len(str), is_stderr);
- if (channel_default_bufferize(channel, str->string, string_len(str),
+ if (channel_default_bufferize(channel, string_data(str), string_len(str),
is_stderr) < 0) {
string_free(str);
return -1;
diff --git a/libssh/client.c b/libssh/client.c
index 5844095..1c69e15 100644
--- a/libssh/client.c
+++ b/libssh/client.c
@@ -31,6 +31,10 @@
#include "libssh/priv.h"
#include "libssh/ssh2.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/socket.h"
+#include "libssh/session.h"
#define set_status(opt,status) do {\
if (opt->callbacks && opt->callbacks->connect_status_function) \
diff --git a/libssh/connect.c b/libssh/connect.c
index df9c0eb..977dfac 100644
--- a/libssh/connect.c
+++ b/libssh/connect.c
@@ -64,6 +64,9 @@
#endif /* _WIN32 */
#include "libssh/priv.h"
+#include "libssh/socket.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
#ifndef HAVE_SELECT
#error "Your system must have select()"
diff --git a/libssh/crypt.c b/libssh/crypt.c
index d353772..498a5ea 100644
--- a/libssh/crypt.c
+++ b/libssh/crypt.c
@@ -37,6 +37,7 @@
#include "libssh/priv.h"
#include "libssh/crypto.h"
+#include "libssh/session.h"
uint32_t packet_decrypt_len(ssh_session session, char *crypted){
uint32_t decrypted;
diff --git a/libssh/dh.c b/libssh/dh.c
index 3290e0b..c1845d7 100644
--- a/libssh/dh.c
+++ b/libssh/dh.c
@@ -50,7 +50,10 @@
#include "libssh/priv.h"
#include "libssh/crypto.h"
-
+#include "libssh/buffer.h"
+#include "libssh/session.h"
+/* todo: remove it */
+#include "libssh/string.h"
#ifdef HAVE_LIBCRYPTO
#include <openssl/rand.h>
#include <openssl/evp.h>
@@ -340,7 +343,7 @@ ssh_string make_bignum_string(bignum num) {
#ifdef DEBUG_CRYPTO
fprintf(stderr, "%d bits, %d bytes, %d padding\n", bits, len, pad);
#endif /* DEBUG_CRYPTO */
-
+/* TODO: fix that crap !! */
ptr = malloc(4 + len + pad);
if (ptr == NULL) {
return NULL;
diff --git a/libssh/gzip.c b/libssh/gzip.c
index 000e777..c9b0545 100644
--- a/libssh/gzip.c
+++ b/libssh/gzip.c
@@ -24,6 +24,8 @@
#include "config.h"
#include "libssh/priv.h"
+#include "libssh/buffer.h"
+#include "libssh/session.h"
#if defined(HAVE_LIBZ) && defined(WITH_LIBZ)
diff --git a/libssh/init.c b/libssh/init.c
index 2df3f5d..9928820 100644
--- a/libssh/init.c
+++ b/libssh/init.c
@@ -22,6 +22,8 @@
*/
#include "libssh/priv.h"
+#include "libssh/socket.h"
+
#ifdef _WIN32
#include <winsock2.h>
#endif
diff --git a/libssh/kex.c b/libssh/kex.c
index 95468c4..ad2acc4 100644
--- a/libssh/kex.c
+++ b/libssh/kex.c
@@ -33,6 +33,9 @@
#include "libssh/priv.h"
#include "libssh/ssh2.h"
#include "libssh/ssh1.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/session.h"
#ifdef HAVE_LIBGCRYPT
#define BLOWFISH "blowfish-cbc,"
@@ -488,8 +491,8 @@ static int build_session_id1(ssh_session session, ssh_string servern,
ssh_print_hexa("host modulus",hostn->string,string_len(hostn));
ssh_print_hexa("server modulus",servern->string,string_len(servern));
#endif
- md5_update(md5,hostn->string,string_len(hostn));
- md5_update(md5,servern->string,string_len(servern));
+ md5_update(md5,string_data(hostn),string_len(hostn));
+ md5_update(md5,string_data(servern),string_len(servern));
md5_update(md5,session->server_kex.cookie,8);
md5_final(session->next_crypto->session_id,md5);
#ifdef DEBUG_CRYPTO
@@ -741,7 +744,7 @@ int ssh_get_kex1(ssh_session session) {
if (buffer_add_data(session->out_buffer, &bits, sizeof(uint16_t)) < 0) {
goto error;
}
- if (buffer_add_data(session->out_buffer, enc_session->string,
+ if (buffer_add_data(session->out_buffer, string_data(enc_session),
string_len(enc_session)) < 0) {
goto error;
}
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index c292d5d..2a197aa 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -36,6 +36,11 @@
#endif
#include "libssh/priv.h"
+#include "libssh/buffer.h"
+#include "libssh/keyfiles.h"
+#include "libssh/session.h"
+/*todo: remove this include */
+#include "libssh/string.h"
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
@@ -1194,6 +1199,7 @@ static int check_public_key(ssh_session session, char **tokens) {
bignum_free(tmpbn);
return -1;
}
+ /* TODO: fix the hardcoding */
tmpstring->size = htonl(len);
#ifdef HAVE_LIBGCRYPT
bignum_bn2bin(tmpbn, len, tmpstring->string);
diff --git a/libssh/keys.c b/libssh/keys.c
index 8df0b05..8ffa439 100644
--- a/libssh/keys.c
+++ b/libssh/keys.c
@@ -30,6 +30,9 @@
#include "libssh/priv.h"
#include "libssh/ssh2.h"
#include "libssh/server.h"
+#include "libssh/buffer.h"
+#include "libssh/agent.h"
+#include "libssh/session.h"
/** \addtogroup ssh_auth
* @{
@@ -258,7 +261,7 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
return NULL;
}
- if (buffer_add_data(tmpbuf, pubkey_s->string, string_len(pubkey_s)) < 0) {
+ if (buffer_add_data(tmpbuf, string_data(pubkey_s), string_len(pubkey_s)) < 0) {
goto error;
}
@@ -778,8 +781,8 @@ static ssh_string signature_to_string(SIGNATURE *sign) {
return NULL;
}
- memcpy(buffer, r->string + string_len(r) - 20, 20);
- memcpy(buffer + 20, s->string + string_len(s) - 20, 20);
+ memcpy(buffer, (char *)string_data(r) + string_len(r) - 20, 20);
+ memcpy(buffer + 20, (char *)string_data(s) + string_len(s) - 20, 20);
string_free(r);
string_free(s);
@@ -879,7 +882,7 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
return NULL;
}
- if (buffer_add_data(tmpbuf, signature->string, string_len(signature)) < 0) {
+ if (buffer_add_data(tmpbuf, string_data(signature), string_len(signature)) < 0) {
signature_free(sign);
buffer_free(tmpbuf);
return NULL;
@@ -943,8 +946,8 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
return NULL;
}
- string_fill(r, rs->string, 20);
- string_fill(s, rs->string + 20, 20);
+ string_fill(r, string_data(rs), 20);
+ string_fill(s, (char *)string_data(rs) + 20, 20);
sig = DSA_SIG_new();
if (sig == NULL) {
@@ -1368,7 +1371,7 @@ ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key
return NULL;
}
- if (RSA_public_encrypt(len, data->string, str->string, key->rsa_pub,
+ if (RSA_public_encrypt(len, string_data(data), string_data(str), key->rsa_pub,
RSA_PKCS1_PADDING) < 0) {
string_free(str);
return NULL;
diff --git a/libssh/log.c b/libssh/log.c
index fb2d666..2e1c0db 100644
--- a/libssh/log.c
+++ b/libssh/log.c
@@ -26,6 +26,7 @@
#include <string.h>
#include "libssh/priv.h"
+#include "libssh/session.h"
/**
* @defgroup ssh_log SSH Logging
diff --git a/libssh/messages.c b/libssh/messages.c
index 22d150f..1cf6e5e 100644
--- a/libssh/messages.c
+++ b/libssh/messages.c
@@ -42,7 +42,10 @@
#include "libssh/libssh.h"
#include "libssh/priv.h"
#include "libssh/ssh2.h"
-
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
static ssh_message message_new(ssh_session session){
ssh_message msg = malloc(sizeof(struct ssh_message_struct));
diff --git a/libssh/packet.c b/libssh/packet.c
index d52c542..7c7178c 100644
--- a/libssh/packet.c
+++ b/libssh/packet.c
@@ -35,6 +35,11 @@
#include "libssh/ssh2.h"
#include "libssh/ssh1.h"
#include "libssh/crypto.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/socket.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
/* XXX include selected mac size */
static int macsize=SHA_DIGEST_LEN;
diff --git a/libssh/poll.c b/libssh/poll.c
index ee45e5e..023a488 100644
--- a/libssh/poll.c
+++ b/libssh/poll.c
@@ -31,6 +31,7 @@
#include "config.h"
#include "libssh/priv.h"
#include "libssh/libssh.h"
+#include "libssh/poll.h"
#ifndef SSH_POLL_CTX_CHUNK
#define SSH_POLL_CTX_CHUNK 5
diff --git a/libssh/scp.c b/libssh/scp.c
index 2f800ef..54e60d8 100644
--- a/libssh/scp.c
+++ b/libssh/scp.c
@@ -25,6 +25,7 @@
#include <string.h>
#include "libssh/priv.h"
+#include "libssh/scp.h"
/** @brief Creates a new scp session
* @param session the SSH session to use
diff --git a/libssh/server.c b/libssh/server.c
index 3e37291..5a89c93 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -37,6 +37,12 @@
#include "libssh/libssh.h"
#include "libssh/server.h"
#include "libssh/ssh2.h"
+#include "libssh/keyfiles.h"
+#include "libssh/buffer.h"
+#include "libssh/packet.h"
+#include "libssh/socket.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
#ifdef _WIN32
diff --git a/libssh/session.c b/libssh/session.c
index 4c6a81e..5f48023 100644
--- a/libssh/session.c
+++ b/libssh/session.c
@@ -27,6 +27,11 @@
#include "libssh/priv.h"
#include "libssh/server.h"
#include "libssh/callback.h"
+#include "libssh/socket.h"
+#include "libssh/agent.h"
+#include "libssh/packet.h"
+#include "libssh/session.h"
+
#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
/** \defgroup ssh_session SSH Session
diff --git a/libssh/sftp.c b/libssh/sftp.c
index 668ad6e..e0b082e 100644
--- a/libssh/sftp.c
+++ b/libssh/sftp.c
@@ -46,6 +46,9 @@
#include "libssh/priv.h"
#include "libssh/ssh2.h"
#include "libssh/sftp.h"
+#include "libssh/buffer.h"
+#include "libssh/channels.h"
+#include "libssh/session.h"
#ifdef WITH_SFTP
@@ -1668,7 +1671,7 @@ ssize_t sftp_read(SFTP_FILE *handle, void *buf, size_t count) {
}
count = string_len(datastring);
handle->offset += count;
- memcpy(buf, datastring->string, count);
+ memcpy(buf, string_data(datastring), count);
string_free(datastring);
return count;
default:
@@ -1787,7 +1790,7 @@ int sftp_async_read(SFTP_FILE *file, void *data, uint32_t size, uint32_t id){
//handle->offset+=len;
/* We already have set the offset previously. All we can do is warn that the expected len
* and effective lengths are different */
- memcpy(data, datastring->string, len);
+ memcpy(data, string_data(datastring), len);
string_free(datastring);
sftp_leave_function();
return len;
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 4d234e4..d42d0eb 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -33,6 +33,7 @@
#include "libssh/sftp.h"
#include "libssh/ssh2.h"
#include "libssh/priv.h"
+#include "libssh/buffer.h"
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp) {
SFTP_PACKET *packet;
@@ -448,7 +449,7 @@ ssh_string sftp_handle_alloc(SFTP_SESSION *sftp, void *info) {
return NULL;
}
- memcpy(ret->string, &val, sizeof(uint32_t));
+ memcpy(string_data(ret), &val, sizeof(uint32_t));
sftp->handles[i] = info;
return ret;
@@ -465,7 +466,7 @@ void *sftp_handle(SFTP_SESSION *sftp, ssh_string handle){
return NULL;
}
- memcpy(&val, handle->string, sizeof(uint32_t));
+ memcpy(&val, string_data(handle), sizeof(uint32_t));
if (val > SFTP_HANDLES) {
return NULL;
diff --git a/libssh/socket.c b/libssh/socket.c
index 2011b48..933119f 100644
--- a/libssh/socket.c
+++ b/libssh/socket.c
@@ -34,6 +34,10 @@
#include <sys/un.h>
#endif
#include "libssh/priv.h"
+#include "libssh/socket.h"
+#include "libssh/buffer.h"
+#include "libssh/poll.h"
+#include "libssh/session.h"
/** \defgroup ssh_socket SSH Sockets
* \addtogroup ssh_socket
diff --git a/libssh/string.c b/libssh/string.c
index c952084..d06fab6 100644
--- a/libssh/string.c
+++ b/libssh/string.c
@@ -29,7 +29,7 @@
#endif
#include "libssh/priv.h"
-
+#include "libssh/string.h"
/** \defgroup ssh_string SSH Strings
* \brief string manipulations
*/
diff --git a/libssh/wrapper.c b/libssh/wrapper.c
index 4110c4e..f82ae3e 100644
--- a/libssh/wrapper.c
+++ b/libssh/wrapper.c
@@ -36,6 +36,7 @@
#include <string.h>
#include "libssh/priv.h"
+#include "libssh/session.h"
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>