[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 01/24 v2] cleanup: use ssh_ prefix in the agent (non-static) functions
[Thread Prev] | [Thread Next]
- Subject: [PATCH 01/24 v2] cleanup: use ssh_ prefix in the agent (non-static) functions
- From: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Sat, 26 Sep 2015 00:15:55 +0200
- To: libssh@xxxxxxxxxx
- Cc: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/agent.h | 8 ++++----
src/agent.c | 10 +++++-----
src/auth.c | 2 +-
src/session.c | 4 ++--
tests/client/torture_auth.c | 4 ++--
5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/libssh/agent.h b/include/libssh/agent.h
index 77209d0..c739273 100644
--- a/include/libssh/agent.h
+++ b/include/libssh/agent.h
@@ -81,16 +81,16 @@ struct ssh_agent_struct {
*
* @return An allocated ssh agent structure or NULL on error.
*/
-struct ssh_agent_struct *agent_new(struct ssh_session_struct *session);
+struct ssh_agent_struct *ssh_agent_new(struct ssh_session_struct *session);
-void agent_close(struct ssh_agent_struct *agent);
+void ssh_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);
+void ssh_agent_free(struct ssh_agent_struct *agent);
/**
* @brief Check if the ssh agent is running.
@@ -99,7 +99,7 @@ void agent_free(struct ssh_agent_struct *agent);
*
* @return 1 if it is running, 0 if not.
*/
-int agent_is_running(struct ssh_session_struct *session);
+int ssh_agent_is_running(struct ssh_session_struct *session);
int ssh_agent_get_ident_count(struct ssh_session_struct *session);
diff --git a/src/agent.c b/src/agent.c
index 922d753..1cbb9cd 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -143,7 +143,7 @@ static size_t atomicio(struct ssh_agent_struct *agent, void *buf, size_t n, int
}
}
-ssh_agent agent_new(struct ssh_session_struct *session) {
+ssh_agent ssh_agent_new(struct ssh_session_struct *session) {
ssh_agent agent = NULL;
agent = malloc(sizeof(struct ssh_agent_struct));
@@ -205,7 +205,7 @@ int ssh_set_agent_socket(ssh_session session, socket_t fd){
return SSH_OK;
}
-void agent_close(struct ssh_agent_struct *agent) {
+void ssh_agent_close(struct ssh_agent_struct *agent) {
if (agent == NULL) {
return;
}
@@ -213,13 +213,13 @@ void agent_close(struct ssh_agent_struct *agent) {
ssh_socket_close(agent->sock);
}
-void agent_free(ssh_agent agent) {
+void ssh_agent_free(ssh_agent agent) {
if (agent) {
if (agent->ident) {
ssh_buffer_free(agent->ident);
}
if (agent->sock) {
- agent_close(agent);
+ ssh_agent_close(agent);
ssh_socket_free(agent->sock);
}
SAFE_FREE(agent);
@@ -481,7 +481,7 @@ ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session,
return key;
}
-int agent_is_running(ssh_session session) {
+int ssh_agent_is_running(ssh_session session) {
if (session == NULL || session->agent == NULL) {
return 0;
}
diff --git a/src/auth.c b/src/auth.c
index 1381774..eeed8c3 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -771,7 +771,7 @@ int ssh_userauth_agent(ssh_session session,
return SSH_AUTH_ERROR;
}
- if (!agent_is_running(session)) {
+ if (!ssh_agent_is_running(session)) {
return SSH_AUTH_DENIED;
}
if (!session->agent_state){
diff --git a/src/session.c b/src/session.c
index ad1b3a8..c1ef290 100644
--- a/src/session.c
+++ b/src/session.c
@@ -92,7 +92,7 @@ ssh_session ssh_new(void) {
session->maxchannel = FIRST_CHANNEL;
#ifndef _WIN32
- session->agent = agent_new(session);
+ session->agent = ssh_agent_new(session);
if (session->agent == NULL) {
goto err;
}
@@ -222,7 +222,7 @@ void ssh_free(ssh_session session) {
crypto_free(session->next_crypto);
#ifndef _WIN32
- agent_free(session->agent);
+ ssh_agent_free(session->agent);
#endif /* _WIN32 */
ssh_key_free(session->srv.dsa_key);
diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c
index d686b4c..bbd72be 100644
--- a/tests/client/torture_auth.c
+++ b/tests/client/torture_auth.c
@@ -308,7 +308,7 @@ static void torture_auth_agent(void **state) {
" to enable this test!!\n");
return;
}
- if (!agent_is_running(session)){
+ if (!ssh_agent_is_running(session)){
print_message("*** Agent not running. Test ignored\n");
return;
}
@@ -340,7 +340,7 @@ static void torture_auth_agent_nonblocking(void **state) {
" to enable this test!!\n");
return;
}
- if (!agent_is_running(session)){
+ if (!ssh_agent_is_running(session)){
print_message("*** Agent not running. Test ignored\n");
return;
}
--
2.4.3
From 610c808ca74ba13c7f9f4145ab8e6af773047139 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Wed, 16 Sep 2015 22:20:30 +0200
Subject: [PATCH 02/24 v2] cleanup: use ssh_ prefix in the bignum (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/bignum.h | 6 +++---
src/bignum.c | 6 +++---
src/buffer.c | 2 +-
src/dh.c | 10 +++++-----
src/known_hosts.c | 4 ++--
src/pki_crypto.c | 40 ++++++++++++++++++++--------------------
6 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/include/libssh/bignum.h b/include/libssh/bignum.h
index 61786c8..df77ebe 100644
--- a/include/libssh/bignum.h
+++ b/include/libssh/bignum.h
@@ -24,9 +24,9 @@
#include "libssh/libcrypto.h"
#include "libssh/libgcrypt.h"
-bignum make_string_bn(ssh_string string);
-void make_string_bn_inplace(ssh_string string, bignum bnout);
-ssh_string make_bignum_string(bignum num);
+bignum ssh_make_string_bn(ssh_string string);
+void ssh_make_string_bn_inplace(ssh_string string, bignum bnout);
+ssh_string ssh_make_bignum_string(bignum num);
void ssh_print_bignum(const char *which,bignum num);
diff --git a/src/bignum.c b/src/bignum.c
index e9c16dd..de21d6b 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -25,7 +25,7 @@
#include "libssh/bignum.h"
#include "libssh/string.h"
-ssh_string make_bignum_string(bignum num) {
+ssh_string ssh_make_bignum_string(bignum num) {
ssh_string ptr = NULL;
int pad = 0;
unsigned int len = bignum_num_bytes(num);
@@ -63,7 +63,7 @@ ssh_string make_bignum_string(bignum num) {
return ptr;
}
-bignum make_string_bn(ssh_string string){
+bignum ssh_make_string_bn(ssh_string string){
bignum bn = NULL;
unsigned int len = ssh_string_len(string);
@@ -81,7 +81,7 @@ bignum make_string_bn(ssh_string string){
return bn;
}
-void make_string_bn_inplace(ssh_string string, bignum bnout) {
+void ssh_make_string_bn_inplace(ssh_string string, bignum bnout) {
unsigned int len = ssh_string_len(string);
#ifdef HAVE_LIBGCRYPT
/* XXX: FIXME as needed for LIBGCRYPT ECDSA codepaths. */
diff --git a/src/buffer.c b/src/buffer.c
index 0bffdfd..0a33ae3 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -767,7 +767,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
break;
case 'B':
b = va_arg(ap, bignum);
- o.string = make_bignum_string(b);
+ o.string = ssh_make_bignum_string(b);
if(o.string == NULL){
rc = SSH_ERROR;
break;
diff --git a/src/dh.c b/src/dh.c
index e489a1d..b372b2c 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -339,12 +339,12 @@ int dh_generate_f(ssh_session session) {
}
ssh_string dh_get_e(ssh_session session) {
- return make_bignum_string(session->next_crypto->e);
+ return ssh_make_bignum_string(session->next_crypto->e);
}
/* used by server */
ssh_string dh_get_f(ssh_session session) {
- return make_bignum_string(session->next_crypto->f);
+ return ssh_make_bignum_string(session->next_crypto->f);
}
void dh_import_pubkey(ssh_session session, ssh_string pubkey_string) {
@@ -352,7 +352,7 @@ void dh_import_pubkey(ssh_session session, ssh_string pubkey_string) {
}
int dh_import_f(ssh_session session, ssh_string f_string) {
- session->next_crypto->f = make_string_bn(f_string);
+ session->next_crypto->f = ssh_make_string_bn(f_string);
if (session->next_crypto->f == NULL) {
return -1;
}
@@ -366,7 +366,7 @@ int dh_import_f(ssh_session session, ssh_string f_string) {
/* used by the server implementation */
int dh_import_e(ssh_session session, ssh_string e_string) {
- session->next_crypto->e = make_string_bn(e_string);
+ session->next_crypto->e = ssh_make_string_bn(e_string);
if (session->next_crypto->e == NULL) {
return -1;
}
@@ -782,7 +782,7 @@ int generate_session_keys(ssh_session session) {
struct ssh_crypto_struct *crypto = session->next_crypto;
int rc = -1;
- k_string = make_bignum_string(crypto->k);
+ k_string = ssh_make_bignum_string(crypto->k);
if (k_string == NULL) {
ssh_set_error_oom(session);
goto error;
diff --git a/src/known_hosts.c b/src/known_hosts.c
index f7828d5..d87af43 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -225,9 +225,9 @@ static int check_public_key(ssh_session session, char **tokens) {
ssh_buffer_free(pubkey_buffer);
return -1;
}
- /* for some reason, make_bignum_string does not work
+ /* for some reason, ssh_make_bignum_string does not work
because of the padding which it does --kv */
- /* tmpstring = make_bignum_string(tmpbn); */
+ /* tmpstring = ssh_make_bignum_string(tmpbn); */
/* do it manually instead */
len = bignum_num_bytes(tmpbn);
tmpstring = malloc(4 + len);
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index d656e35..7a3caba 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -831,10 +831,10 @@ int pki_pubkey_build_dss(ssh_key key,
return SSH_ERROR;
}
- key->dsa->p = make_string_bn(p);
- key->dsa->q = make_string_bn(q);
- key->dsa->g = make_string_bn(g);
- key->dsa->pub_key = make_string_bn(pubkey);
+ key->dsa->p = ssh_make_string_bn(p);
+ key->dsa->q = ssh_make_string_bn(q);
+ key->dsa->g = ssh_make_string_bn(g);
+ key->dsa->pub_key = ssh_make_string_bn(pubkey);
if (key->dsa->p == NULL ||
key->dsa->q == NULL ||
key->dsa->g == NULL ||
@@ -854,8 +854,8 @@ int pki_pubkey_build_rsa(ssh_key key,
return SSH_ERROR;
}
- key->rsa->e = make_string_bn(e);
- key->rsa->n = make_string_bn(n);
+ key->rsa->e = ssh_make_string_bn(e);
+ key->rsa->n = ssh_make_string_bn(n);
if (key->rsa->e == NULL ||
key->rsa->n == NULL) {
RSA_free(key->rsa);
@@ -897,22 +897,22 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
switch (key->type) {
case SSH_KEYTYPE_DSS:
- p = make_bignum_string(key->dsa->p);
+ p = ssh_make_bignum_string(key->dsa->p);
if (p == NULL) {
goto fail;
}
- q = make_bignum_string(key->dsa->q);
+ q = ssh_make_bignum_string(key->dsa->q);
if (q == NULL) {
goto fail;
}
- g = make_bignum_string(key->dsa->g);
+ g = ssh_make_bignum_string(key->dsa->g);
if (g == NULL) {
goto fail;
}
- n = make_bignum_string(key->dsa->pub_key);
+ n = ssh_make_bignum_string(key->dsa->pub_key);
if (n == NULL) {
goto fail;
}
@@ -946,12 +946,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
break;
case SSH_KEYTYPE_RSA:
case SSH_KEYTYPE_RSA1:
- e = make_bignum_string(key->rsa->e);
+ e = ssh_make_bignum_string(key->rsa->e);
if (e == NULL) {
goto fail;
}
- n = make_bignum_string(key->rsa->n);
+ n = ssh_make_bignum_string(key->rsa->n);
if (n == NULL) {
goto fail;
}
@@ -1150,12 +1150,12 @@ static ssh_string pki_dsa_signature_to_blob(const ssh_signature sig)
ssh_string s;
int s_len, s_offset_in, s_offset_out;
- r = make_bignum_string(sig->dsa_sig->r);
+ r = ssh_make_bignum_string(sig->dsa_sig->r);
if (r == NULL) {
return NULL;
}
- s = make_bignum_string(sig->dsa_sig->s);
+ s = ssh_make_bignum_string(sig->dsa_sig->s);
if (s == NULL) {
ssh_string_free(r);
return NULL;
@@ -1214,7 +1214,7 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
return NULL;
}
- r = make_bignum_string(sig->ecdsa_sig->r);
+ r = ssh_make_bignum_string(sig->ecdsa_sig->r);
if (r == NULL) {
ssh_buffer_free(b);
return NULL;
@@ -1226,7 +1226,7 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
return NULL;
}
- s = make_bignum_string(sig->ecdsa_sig->s);
+ s = ssh_make_bignum_string(sig->ecdsa_sig->s);
if (s == NULL) {
ssh_buffer_free(b);
return NULL;
@@ -1375,7 +1375,7 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey,
}
ssh_string_fill(r, ssh_string_data(sig_blob), 20);
- sig->dsa_sig->r = make_string_bn(r);
+ sig->dsa_sig->r = ssh_make_string_bn(r);
ssh_string_free(r);
if (sig->dsa_sig->r == NULL) {
ssh_signature_free(sig);
@@ -1389,7 +1389,7 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey,
}
ssh_string_fill(s, (char *)ssh_string_data(sig_blob) + 20, 20);
- sig->dsa_sig->s = make_string_bn(s);
+ sig->dsa_sig->s = ssh_make_string_bn(s);
ssh_string_free(s);
if (sig->dsa_sig->s == NULL) {
ssh_signature_free(sig);
@@ -1439,7 +1439,7 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey,
ssh_print_hexa("r", ssh_string_data(r), ssh_string_len(r));
#endif
- make_string_bn_inplace(r, sig->ecdsa_sig->r);
+ ssh_make_string_bn_inplace(r, sig->ecdsa_sig->r);
ssh_string_burn(r);
ssh_string_free(r);
if (sig->ecdsa_sig->r == NULL) {
@@ -1460,7 +1460,7 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey,
ssh_print_hexa("s", ssh_string_data(s), ssh_string_len(s));
#endif
- make_string_bn_inplace(s, sig->ecdsa_sig->s);
+ ssh_make_string_bn_inplace(s, sig->ecdsa_sig->s);
ssh_string_burn(s);
ssh_string_free(s);
if (sig->ecdsa_sig->s == NULL) {
--
2.4.3
From 3157ddf3cb7a2ecf45ce2374536b3f25729fe7b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Wed, 16 Sep 2015 23:24:44 +0200
Subject: [PATCH 03/24 v2] cleanup: use ssh_ prefix in the blf (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/blf.h | 26 +++++++++++++-------------
src/external/bcrypt_pbkdf.c | 4 ++--
src/external/blowfish.c | 42 +++++++++++++++++++++---------------------
3 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/include/libssh/blf.h b/include/libssh/blf.h
index 21185f3..ce131e6 100644
--- a/include/libssh/blf.h
+++ b/include/libssh/blf.h
@@ -53,7 +53,7 @@
typedef struct BlowfishContext {
uint32_t S[4][256]; /* S-Boxes */
uint32_t P[BLF_N + 2]; /* Subkeys */
-} blf_ctx;
+} ssh_blf_ctx;
/* Raw access to customized Blowfish
* blf_key is just:
@@ -61,24 +61,24 @@ typedef struct BlowfishContext {
* Blowfish_expand0state( state, key, keylen )
*/
-void Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *);
-void Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *);
-void Blowfish_initstate(blf_ctx *);
-void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t);
+void Blowfish_encipher(ssh_blf_ctx *, uint32_t *, uint32_t *);
+void Blowfish_decipher(ssh_blf_ctx *, uint32_t *, uint32_t *);
+void Blowfish_initstate(ssh_blf_ctx *);
+void Blowfish_expand0state(ssh_blf_ctx *, const uint8_t *, uint16_t);
void Blowfish_expandstate
-(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
+(ssh_blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
/* Standard Blowfish */
-void blf_key(blf_ctx *, const uint8_t *, uint16_t);
-void blf_enc(blf_ctx *, uint32_t *, uint16_t);
-void blf_dec(blf_ctx *, uint32_t *, uint16_t);
+void ssh_blf_key(ssh_blf_ctx *, const uint8_t *, uint16_t);
+void ssh_blf_enc(ssh_blf_ctx *, uint32_t *, uint16_t);
+void ssh_blf_dec(ssh_blf_ctx *, uint32_t *, uint16_t);
-void blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t);
-void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t);
+void ssh_blf_ecb_encrypt(ssh_blf_ctx *, uint8_t *, uint32_t);
+void ssh_blf_ecb_decrypt(ssh_blf_ctx *, uint8_t *, uint32_t);
-void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
-void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
+void ssh_blf_cbc_encrypt(ssh_blf_ctx *, uint8_t *, uint8_t *, uint32_t);
+void ssh_blf_cbc_decrypt(ssh_blf_ctx *, uint8_t *, uint8_t *, uint32_t);
/* Converts uint8_t to uint32_t */
uint32_t Blowfish_stream2word(const uint8_t *, uint16_t , uint16_t *);
diff --git a/src/external/bcrypt_pbkdf.c b/src/external/bcrypt_pbkdf.c
index 4cca9d8..00314c2 100644
--- a/src/external/bcrypt_pbkdf.c
+++ b/src/external/bcrypt_pbkdf.c
@@ -63,7 +63,7 @@
static void
bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
{
- blf_ctx state;
+ ssh_blf_ctx state;
uint8_t ciphertext[BCRYPT_HASHSIZE] =
"OxychromaticBlowfishSwatDynamite";
uint32_t cdata[BCRYPT_BLOCKS];
@@ -85,7 +85,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext),
&j);
for (i = 0; i < 64; i++)
- blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
+ ssh_blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
/* copy out */
for (i = 0; i < BCRYPT_BLOCKS; i++) {
diff --git a/src/external/blowfish.c b/src/external/blowfish.c
index 99f9cc3..4008a9c 100644
--- a/src/external/blowfish.c
+++ b/src/external/blowfish.c
@@ -70,7 +70,7 @@
#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
void
-Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
+Blowfish_encipher(ssh_blf_ctx *c, uint32_t *xl, uint32_t *xr)
{
uint32_t Xl;
uint32_t Xr;
@@ -95,7 +95,7 @@ Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
}
void
-Blowfish_decipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
+Blowfish_decipher(ssh_blf_ctx *c, uint32_t *xl, uint32_t *xr)
{
uint32_t Xl;
uint32_t Xr;
@@ -120,11 +120,11 @@ Blowfish_decipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
}
void
-Blowfish_initstate(blf_ctx *c)
+Blowfish_initstate(ssh_blf_ctx *c)
{
/* P-box and S-box tables initialized with digits of Pi */
- static const blf_ctx initstate =
+ static const ssh_blf_ctx initstate =
{ {
{
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
@@ -420,7 +420,7 @@ Blowfish_stream2word(const uint8_t *data, uint16_t databytes,
}
void
-Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes)
+Blowfish_expand0state(ssh_blf_ctx *c, const uint8_t *key, uint16_t keybytes)
{
uint16_t i;
uint16_t j;
@@ -458,7 +458,7 @@ Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes)
void
-Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes,
+Blowfish_expandstate(ssh_blf_ctx *c, const uint8_t *data, uint16_t databytes,
const uint8_t *key, uint16_t keybytes)
{
uint16_t i;
@@ -501,7 +501,7 @@ Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes,
}
void
-blf_key(blf_ctx *c, const uint8_t *k, uint16_t len)
+ssh_blf_key(ssh_blf_ctx *c, const uint8_t *k, uint16_t len)
{
/* Initialize S-boxes and subkeys with Pi */
Blowfish_initstate(c);
@@ -511,7 +511,7 @@ blf_key(blf_ctx *c, const uint8_t *k, uint16_t len)
}
void
-blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks)
+ssh_blf_enc(ssh_blf_ctx *c, uint32_t *data, uint16_t blocks)
{
uint32_t *d;
uint16_t i;
@@ -524,7 +524,7 @@ blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks)
}
void
-blf_dec(blf_ctx *c, uint32_t *data, uint16_t blocks)
+ssh_blf_dec(ssh_blf_ctx *c, uint32_t *data, uint16_t blocks)
{
uint32_t *d;
uint16_t i;
@@ -537,7 +537,7 @@ blf_dec(blf_ctx *c, uint32_t *data, uint16_t blocks)
}
void
-blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len)
+ssh_blf_ecb_encrypt(ssh_blf_ctx *c, uint8_t *data, uint32_t len)
{
uint32_t l, r;
uint32_t i;
@@ -559,7 +559,7 @@ blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len)
}
void
-blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len)
+ssh_blf_ecb_decrypt(ssh_blf_ctx *c, uint8_t *data, uint32_t len)
{
uint32_t l, r;
uint32_t i;
@@ -581,7 +581,7 @@ blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len)
}
void
-blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len)
+ssh_blf_cbc_encrypt(ssh_blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len)
{
uint32_t l, r;
uint32_t i, j;
@@ -606,7 +606,7 @@ blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len)
}
void
-blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len)
+ssh_blf_cbc_decrypt(ssh_blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len)
{
uint32_t l, r;
uint8_t *iv;
@@ -659,7 +659,7 @@ void
main(void)
{
- blf_ctx c;
+ ssh_blf_ctx c;
char key[] = "AAAAA";
char key2[] = "abcdefghijklmnopqrstuvwxyz";
@@ -673,19 +673,19 @@ main(void)
for (i = 0; i < 10; i++)
data[i] = i;
- blf_key(&c, (uint8_t *) key, 5);
- blf_enc(&c, data, 5);
- blf_dec(&c, data, 1);
- blf_dec(&c, data + 2, 4);
+ ssh_blf_key(&c, (uint8_t *) key, 5);
+ ssh_blf_enc(&c, data, 5);
+ ssh_blf_dec(&c, data, 1);
+ ssh_blf_dec(&c, data + 2, 4);
printf("Should read as 0 - 9.\n");
report(data, 10);
/* Second test */
- blf_key(&c, (uint8_t *) key2, strlen(key2));
- blf_enc(&c, data2, 1);
+ ssh_blf_key(&c, (uint8_t *) key2, strlen(key2));
+ ssh_blf_enc(&c, data2, 1);
printf("\nShould read as: 0x324ed0fe 0xf413a203.\n");
report(data2, 2);
- blf_dec(&c, data2, 1);
+ ssh_blf_dec(&c, data2, 1);
report(data2, 2);
}
#endif
--
2.4.3
From 545922b1dc1f89bb561d422302456d20a851ab81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 09:43:33 +0200
Subject: [PATCH 04/24 v2] cleanup: use ssh_ prefix in the buffer (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 44 ++++++-------
src/agent.c | 30 ++++-----
src/auth.c | 6 +-
src/auth1.c | 8 +--
src/buffer.c | 94 ++++++++++++++--------------
src/channels.c | 60 +++++++++---------
src/channels1.c | 42 ++++++-------
src/dh.c | 36 +++++------
src/gssapi.c | 14 ++---
src/gzip.c | 14 ++---
src/kex.c | 18 +++---
src/kex1.c | 32 +++++-----
src/known_hosts.c | 16 ++---
src/messages.c | 22 +++----
src/packet.c | 42 ++++++-------
src/packet1.c | 22 +++----
src/packet_cb.c | 4 +-
src/packet_crypt.c | 2 +-
src/pcap.c | 44 ++++++-------
src/pki.c | 50 +++++++--------
src/pki_container_openssh.c | 10 +--
src/pki_crypto.c | 10 +--
src/pki_gcrypt.c | 28 ++++-----
src/server.c | 10 +--
src/sftp.c | 130 +++++++++++++++++++--------------------
src/sftpserver.c | 48 +++++++--------
src/socket.c | 18 +++---
tests/unittests/torture_buffer.c | 70 ++++++++++-----------
28 files changed, 462 insertions(+), 462 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 826d0b7..3ff794a 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -46,11 +46,11 @@ LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
LIBSSH_API ssh_buffer ssh_buffer_new(void);
void ssh_buffer_set_secure(ssh_buffer buffer);
-int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
-int buffer_add_u8(ssh_buffer buffer, uint8_t data);
-int buffer_add_u16(ssh_buffer buffer, uint16_t data);
-int buffer_add_u32(ssh_buffer buffer, uint32_t data);
-int buffer_add_u64(ssh_buffer buffer, uint64_t data);
+int ssh_buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
+int ssh_buffer_add_u8(ssh_buffer buffer, uint8_t data);
+int ssh_buffer_add_u16(ssh_buffer buffer, uint16_t data);
+int ssh_buffer_add_u32(ssh_buffer buffer, uint32_t data);
+int ssh_buffer_add_u64(ssh_buffer buffer, uint64_t data);
int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
@@ -74,27 +74,27 @@ int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
#define ssh_buffer_unpack(buffer, format, ...) \
_ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
-int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
-int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
+int ssh_buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
+int ssh_buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
int ssh_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);
+/* ssh_buffer_get_rest returns a pointer to the current position into the buffer */
+void *ssh_buffer_get_rest(ssh_buffer buffer);
+/* ssh_buffer_get_rest_len returns the number of bytes which can be read */
+uint32_t ssh_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);
+int ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
+int ssh_buffer_get_u32(ssh_buffer buffer, uint32_t *data);
+int ssh_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);
+uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
+/* ssh_buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
+ssh_string ssh_buffer_get_ssh_string(ssh_buffer buffer);
+/* ssh_gets a string out of a SSH-1 mpint */
+ssh_string ssh_buffer_get_mpint(ssh_buffer buffer);
+/* ssh_buffer_pass_bytes acts as if len bytes have been read (used for padding) */
+uint32_t ssh_buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
+uint32_t ssh_buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
#endif /* BUFFER_H_ */
diff --git a/src/agent.c b/src/agent.c
index 1cbb9cd..804ee50 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -273,13 +273,13 @@ static int agent_talk(struct ssh_session_struct *session,
uint32_t len = 0;
uint8_t payload[1024 v2] = {0};
- len = buffer_get_rest_len(request);
+ len = ssh_buffer_get_rest_len(request);
SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
agent_put_u32(payload, len);
/* send length and then the request packet */
if (atomicio(session->agent, payload, 4, 0) == 4) {
- if (atomicio(session->agent, buffer_get_rest(request), len, 0)
+ if (atomicio(session->agent, ssh_buffer_get_rest(request), len, 0)
!= len) {
SSH_LOG(SSH_LOG_WARN, "atomicio sending request failed: %s",
strerror(errno));
@@ -354,7 +354,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
ssh_set_error_oom(session);
return -1;
}
- if (buffer_add_u8(request, c1) < 0) {
+ if (ssh_buffer_add_u8(request, c1) < 0) {
ssh_set_error_oom(session);
ssh_buffer_free(request);
return -1;
@@ -375,7 +375,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
ssh_buffer_free(request);
/* get message type and verify the answer */
- rc = buffer_get_u8(reply, (uint8_t *) &type);
+ rc = ssh_buffer_get_u8(reply, (uint8_t *) &type);
if (rc != sizeof(uint8_t)) {
ssh_set_error(session, SSH_FATAL,
"Bad authentication reply size: %d", rc);
@@ -397,7 +397,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
return -1;
}
- buffer_get_u32(reply, (uint32_t *) buf);
+ ssh_buffer_get_u32(reply, (uint32_t *) buf);
session->agent->count = agent_get_u32(buf);
SSH_LOG(SSH_LOG_DEBUG, "Agent count: %d",
session->agent->count);
@@ -444,13 +444,13 @@ ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session,
return NULL;
case 2:
/* get the blob */
- blob = buffer_get_ssh_string(session->agent->ident);
+ blob = ssh_buffer_get_ssh_string(session->agent->ident);
if (blob == NULL) {
return NULL;
}
/* get the comment */
- tmp = buffer_get_ssh_string(session->agent->ident);
+ tmp = ssh_buffer_get_ssh_string(session->agent->ident);
if (tmp == NULL) {
ssh_string_free(blob);
@@ -518,7 +518,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
}
/* create request */
- if (buffer_add_u8(request, SSH2_AGENTC_SIGN_REQUEST) < 0) {
+ if (ssh_buffer_add_u8(request, SSH2_AGENTC_SIGN_REQUEST) < 0) {
ssh_buffer_free(request);
return NULL;
}
@@ -530,7 +530,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
}
/* adds len + blob */
- rc = buffer_add_ssh_string(request, key_blob);
+ rc = ssh_buffer_add_ssh_string(request, key_blob);
ssh_string_free(key_blob);
if (rc < 0) {
ssh_buffer_free(request);
@@ -538,17 +538,17 @@ ssh_string ssh_agent_sign_data(ssh_session session,
}
/* Add data */
- dlen = buffer_get_rest_len(data);
- if (buffer_add_u32(request, htonl(dlen)) < 0) {
+ dlen = ssh_buffer_get_rest_len(data);
+ if (ssh_buffer_add_u32(request, htonl(dlen)) < 0) {
ssh_buffer_free(request);
return NULL;
}
- if (ssh_buffer_add_data(request, buffer_get_rest(data), dlen) < 0) {
+ if (ssh_buffer_add_data(request, ssh_buffer_get_rest(data), dlen) < 0) {
ssh_buffer_free(request);
return NULL;
}
- if (buffer_add_u32(request, htonl(flags)) < 0) {
+ if (ssh_buffer_add_u32(request, htonl(flags)) < 0) {
ssh_buffer_free(request);
return NULL;
}
@@ -568,7 +568,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
ssh_buffer_free(request);
/* check if reply is valid */
- if (buffer_get_u8(reply, (uint8_t *) &type) != sizeof(uint8_t)) {
+ if (ssh_buffer_get_u8(reply, (uint8_t *) &type) != sizeof(uint8_t)) {
ssh_buffer_free(reply);
return NULL;
}
@@ -583,7 +583,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
return NULL;
}
- sig_blob = buffer_get_ssh_string(reply);
+ sig_blob = ssh_buffer_get_ssh_string(reply);
ssh_buffer_free(reply);
return sig_blob;
diff --git a/src/auth.c b/src/auth.c
index eeed8c3..c2cf52f 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -158,7 +158,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_banner){
(void)type;
(void)user;
- banner = buffer_get_ssh_string(packet);
+ banner = ssh_buffer_get_ssh_string(packet);
if (banner == NULL) {
SSH_LOG(SSH_LOG_WARN,
"Invalid SSH_USERAUTH_BANNER packet");
@@ -615,7 +615,7 @@ int ssh_userauth_publickey(ssh_session session,
goto fail;
}
- rc = buffer_add_ssh_string(session->out_buffer, str);
+ rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
str = NULL;
if (rc < 0) {
@@ -700,7 +700,7 @@ static int ssh_userauth_agent_publickey(ssh_session session,
goto fail;
}
- rc = buffer_add_ssh_string(session->out_buffer, str);
+ rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
if (rc < 0) {
goto fail;
diff --git a/src/auth1.c b/src/auth1.c
index a65c447..e808763 100644
--- a/src/auth1.c
+++ b/src/auth1.c
@@ -103,11 +103,11 @@ static int send_username(ssh_session session, const char *username) {
return SSH_AUTH_ERROR;
}
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_USER) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_USER) < 0) {
ssh_string_free(user);
return SSH_AUTH_ERROR;
}
- if (buffer_add_ssh_string(session->out_buffer, user) < 0) {
+ if (ssh_buffer_add_ssh_string(session->out_buffer, user) < 0) {
ssh_string_free(user);
return SSH_AUTH_ERROR;
}
@@ -197,13 +197,13 @@ int ssh_userauth1_password(ssh_session session, const char *username,
ssh_string_fill(pwd, buf, sizeof(buf));
}
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
ssh_string_burn(pwd);
ssh_string_free(pwd);
return SSH_AUTH_ERROR;
}
- if (buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
+ if (ssh_buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
ssh_string_burn(pwd);
ssh_string_free(pwd);
diff --git a/src/buffer.c b/src/buffer.c
index 0a33ae3..a327aa6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -257,7 +257,7 @@ int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint
*
* @return 0 on success, < 0 on error.
*/
-int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
+int ssh_buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
struct ssh_string_struct *string) {
uint32_t len = 0;
@@ -284,7 +284,7 @@ int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
*
* @return 0 on success, -1 on error.
*/
-int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
+int ssh_buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
{
int rc;
@@ -307,7 +307,7 @@ int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
*
* @return 0 on success, -1 on error.
*/
-int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
+int ssh_buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
{
int rc;
@@ -330,7 +330,7 @@ int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
*
* @return 0 on success, -1 on error.
*/
-int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
+int ssh_buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
{
int rc;
@@ -353,7 +353,7 @@ int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
*
* @return 0 on success, -1 on error.
*/
-int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
+int ssh_buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
{
int rc;
@@ -378,7 +378,7 @@ int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
*
* @return 0 on success, -1 on error.
*/
-int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
+int ssh_buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
uint32_t len) {
buffer_verify(buffer);
@@ -419,14 +419,14 @@ int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
*
* @return 0 on success, -1 on error.
*/
-int buffer_add_buffer(struct ssh_buffer_struct *buffer,
+int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
struct ssh_buffer_struct *source)
{
int rc;
rc = ssh_buffer_add_data(buffer,
- buffer_get_rest(source),
- buffer_get_rest_len(source));
+ ssh_buffer_get_rest(source),
+ ssh_buffer_get_rest_len(source));
if (rc < 0) {
return -1;
}
@@ -444,8 +444,8 @@ int buffer_add_buffer(struct ssh_buffer_struct *buffer,
*
* @warning Don't expect data to be nul-terminated.
*
- * @see buffer_get_rest()
- * @see buffer_get_len()
+ * @see ssh_buffer_get_rest()
+ * @see ssh_buffer_get_len()
*/
void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
return buffer->data;
@@ -460,10 +460,10 @@ void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
*
* @return A pointer to the data from current position.
*
- * @see buffer_get_rest_len()
- * @see buffer_get()
+ * @see ssh_buffer_get_rest_len()
+ * @see ssh_buffer_get()
*/
-void *buffer_get_rest(struct ssh_buffer_struct *buffer){
+void *ssh_buffer_get_rest(struct ssh_buffer_struct *buffer){
return buffer->data + buffer->pos;
}
@@ -474,7 +474,7 @@ void *buffer_get_rest(struct ssh_buffer_struct *buffer){
*
* @return The length of the buffer.
*
- * @see buffer_get()
+ * @see ssh_buffer_get()
*/
uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
return buffer->used;
@@ -489,9 +489,9 @@ uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
*
* @return The length of the buffer.
*
- * @see buffer_get_rest()
+ * @see ssh_buffer_get_rest()
*/
-uint32_t buffer_get_rest_len(struct ssh_buffer_struct *buffer){
+uint32_t ssh_buffer_get_rest_len(struct ssh_buffer_struct *buffer){
buffer_verify(buffer);
return buffer->used - buffer->pos;
}
@@ -509,7 +509,7 @@ uint32_t buffer_get_rest_len(struct ssh_buffer_struct *buffer){
*
* @return The new size of the buffer.
*/
-uint32_t buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
+uint32_t ssh_buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
buffer_verify(buffer);
if (buffer->pos + len < len || buffer->used < buffer->pos + len) {
@@ -537,7 +537,7 @@ uint32_t buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
*
* @return The new size of the buffer.
*/
-uint32_t buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
+uint32_t ssh_buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
buffer_verify(buffer);
if (buffer->used < len) {
@@ -562,7 +562,7 @@ uint32_t buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
*
* @returns 0 if there is not enough data in buffer, len otherwise.
*/
-uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
+uint32_t ssh_buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
/*
* Check for a integer overflow first, then check if not enough data is in
* the buffer.
@@ -587,8 +587,8 @@ uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t
*
* @returns 0 if there is not enough data in buffer, 1 otherwise.
*/
-int buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
- return buffer_get_data(buffer,data,sizeof(uint8_t));
+int ssh_buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
+ return ssh_buffer_get_data(buffer,data,sizeof(uint8_t));
}
/** \internal
@@ -598,8 +598,8 @@ int buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
* \returns 0 if there is not enough data in buffer
* \returns 4 otherwise.
*/
-int buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
- return buffer_get_data(buffer,data,sizeof(uint32_t));
+int ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
+ return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
}
/**
* @internal
@@ -613,8 +613,8 @@ int buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
*
* @returns 0 if there is not enough data in buffer, 8 otherwise.
*/
-int buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
- return buffer_get_data(buffer,data,sizeof(uint64_t));
+int ssh_buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
+ return ssh_buffer_get_data(buffer,data,sizeof(uint64_t));
}
/**
@@ -626,12 +626,12 @@ int buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
*
* @returns The SSH String, NULL on error.
*/
-struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer) {
+struct ssh_string_struct *ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer) {
uint32_t stringlen;
uint32_t hostlen;
struct ssh_string_struct *str = NULL;
- if (buffer_get_u32(buffer, &stringlen) == 0) {
+ if (ssh_buffer_get_u32(buffer, &stringlen) == 0) {
return NULL;
}
hostlen = ntohl(stringlen);
@@ -643,7 +643,7 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
if (str == NULL) {
return NULL;
}
- if (buffer_get_data(buffer, ssh_string_data(str), hostlen) != hostlen) {
+ if (ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen) != hostlen) {
/* should never happen */
SAFE_FREE(str);
return NULL;
@@ -663,12 +663,12 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
*
* @returns The SSH String containing the mpint, NULL on error.
*/
-struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
+struct ssh_string_struct *ssh_buffer_get_mpint(struct ssh_buffer_struct *buffer) {
uint16_t bits;
uint32_t len;
struct ssh_string_struct *str = NULL;
- if (buffer_get_data(buffer, &bits, sizeof(uint16_t)) != sizeof(uint16_t)) {
+ if (ssh_buffer_get_data(buffer, &bits, sizeof(uint16_t)) != sizeof(uint16_t)) {
return NULL;
}
bits = ntohs(bits);
@@ -680,7 +680,7 @@ struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
if (str == NULL) {
return NULL;
}
- if (buffer_get_data(buffer, ssh_string_data(str), len) != len) {
+ if (ssh_buffer_get_data(buffer, ssh_string_data(str), len) != len) {
SAFE_FREE(str);
return NULL;
}
@@ -725,32 +725,32 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
switch(*p) {
case 'b':
o.byte = (uint8_t)va_arg(ap, unsigned int);
- rc = buffer_add_u8(buffer, o.byte);
+ rc = ssh_buffer_add_u8(buffer, o.byte);
break;
case 'w':
o.word = (uint16_t)va_arg(ap, unsigned int);
o.word = htons(o.word);
- rc = buffer_add_u16(buffer, o.word);
+ rc = ssh_buffer_add_u16(buffer, o.word);
break;
case 'd':
o.dword = va_arg(ap, uint32_t);
o.dword = htonl(o.dword);
- rc = buffer_add_u32(buffer, o.dword);
+ rc = ssh_buffer_add_u32(buffer, o.dword);
break;
case 'q':
o.qword = va_arg(ap, uint64_t);
o.qword = htonll(o.qword);
- rc = buffer_add_u64(buffer, o.qword);
+ rc = ssh_buffer_add_u64(buffer, o.qword);
break;
case 'S':
o.string = va_arg(ap, ssh_string);
- rc = buffer_add_ssh_string(buffer, o.string);
+ rc = ssh_buffer_add_ssh_string(buffer, o.string);
o.string = NULL;
break;
case 's':
cstring = va_arg(ap, char *);
len = strlen(cstring);
- rc = buffer_add_u32(buffer, htonl(len));
+ rc = ssh_buffer_add_u32(buffer, htonl(len));
if (rc == SSH_OK){
rc = ssh_buffer_add_data(buffer, cstring, len);
}
@@ -772,7 +772,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
rc = SSH_ERROR;
break;
}
- rc = buffer_add_ssh_string(buffer, o.string);
+ rc = ssh_buffer_add_ssh_string(buffer, o.string);
SAFE_FREE(o.string);
break;
case 't':
@@ -885,37 +885,37 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
switch (*p) {
case 'b':
o.byte = va_arg(ap, uint8_t *);
- rlen = buffer_get_u8(buffer, o.byte);
+ rlen = ssh_buffer_get_u8(buffer, o.byte);
rc = rlen==1 ? SSH_OK : SSH_ERROR;
break;
case 'w':
o.word = va_arg(ap, uint16_t *);
- rlen = buffer_get_data(buffer, o.word, sizeof(uint16_t));
+ rlen = ssh_buffer_get_data(buffer, o.word, sizeof(uint16_t));
*o.word = ntohs(*o.word);
rc = rlen==2 ? SSH_OK : SSH_ERROR;
break;
case 'd':
o.dword = va_arg(ap, uint32_t *);
- rlen = buffer_get_u32(buffer, o.dword);
+ rlen = ssh_buffer_get_u32(buffer, o.dword);
*o.dword = ntohl(*o.dword);
rc = rlen==4 ? SSH_OK : SSH_ERROR;
break;
case 'q':
o.qword = va_arg(ap, uint64_t*);
- rlen = buffer_get_u64(buffer, o.qword);
+ rlen = ssh_buffer_get_u64(buffer, o.qword);
*o.qword = ntohll(*o.qword);
rc = rlen==8 ? SSH_OK : SSH_ERROR;
break;
case 'S':
o.string = va_arg(ap, ssh_string *);
- *o.string = buffer_get_ssh_string(buffer);
+ *o.string = ssh_buffer_get_ssh_string(buffer);
rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
o.string = NULL;
break;
case 's':
o.cstring = va_arg(ap, char **);
*o.cstring = NULL;
- rc = buffer_get_u32(buffer, &u32len);
+ rc = ssh_buffer_get_u32(buffer, &u32len);
if (rc != 4){
rc = SSH_ERROR;
break;
@@ -930,7 +930,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
rc = SSH_ERROR;
break;
}
- rlen = buffer_get_data(buffer, *o.cstring, len);
+ rlen = ssh_buffer_get_data(buffer, *o.cstring, len);
if (rlen != len){
SAFE_FREE(*o.cstring);
rc = SSH_ERROR;
@@ -951,7 +951,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
rc = SSH_ERROR;
break;
}
- rlen = buffer_get_data(buffer, *o.data, len);
+ rlen = ssh_buffer_get_data(buffer, *o.data, len);
if (rlen != len){
SAFE_FREE(*o.data);
rc = SSH_ERROR;
diff --git a/src/channels.c b/src/channels.c
index d8cd190..84e9608 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -286,7 +286,7 @@ static int channel_open(ssh_channel channel, const char *type, int window,
}
if (payload != NULL) {
- if (buffer_add_buffer(session->out_buffer, payload) < 0) {
+ if (ssh_buffer_add_buffer(session->out_buffer, payload) < 0) {
ssh_set_error_oom(session);
return err;
@@ -492,10 +492,10 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
if (is_stderr) {
uint32_t ignore;
/* uint32 data type code. we can ignore it */
- buffer_get_u32(packet, &ignore);
+ ssh_buffer_get_u32(packet, &ignore);
}
- str = buffer_get_ssh_string(packet);
+ str = ssh_buffer_get_ssh_string(packet);
if (str == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
@@ -546,17 +546,17 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
}
rest = channel->callbacks->channel_data_function(channel->session,
channel,
- buffer_get_rest(buf),
- buffer_get_rest_len(buf),
+ ssh_buffer_get_rest(buf),
+ ssh_buffer_get_rest_len(buf),
is_stderr,
channel->callbacks->userdata);
if(rest > 0) {
if (channel->counter != NULL) {
channel->counter->in_bytes += rest;
}
- buffer_pass_bytes(buf, rest);
+ ssh_buffer_pass_bytes(buf, rest);
}
- if (channel->local_window + buffer_get_rest_len(buf) < WINDOWLIMIT) {
+ if (channel->local_window + ssh_buffer_get_rest_len(buf) < WINDOWLIMIT) {
if (grow_window(session, channel, 0) < 0) {
return -1;
}
@@ -612,9 +612,9 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
channel->remote_channel);
if ((channel->stdout_buffer &&
- buffer_get_rest_len(channel->stdout_buffer) > 0) ||
+ ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
(channel->stderr_buffer &&
- buffer_get_rest_len(channel->stderr_buffer) > 0)) {
+ ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
channel->delayed_close = 1;
} else {
channel->state = SSH_CHANNEL_STATE_CLOSED;
@@ -1414,9 +1414,9 @@ int ssh_channel_is_eof(ssh_channel channel) {
return SSH_ERROR;
}
if ((channel->stdout_buffer &&
- buffer_get_rest_len(channel->stdout_buffer) > 0) ||
+ ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
(channel->stderr_buffer &&
- buffer_get_rest_len(channel->stderr_buffer) > 0)) {
+ ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
return 0;
}
@@ -1540,8 +1540,8 @@ static int channel_request(ssh_channel channel, const char *request,
}
if (buffer != NULL) {
- if (ssh_buffer_add_data(session->out_buffer, buffer_get_rest(buffer),
- buffer_get_rest_len(buffer)) < 0) {
+ if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get_rest(buffer),
+ ssh_buffer_get_rest_len(buffer)) < 0) {
ssh_set_error_oom(session);
goto error;
}
@@ -2099,8 +2099,8 @@ static int global_request(ssh_session session, const char *request,
if (buffer != NULL) {
rc = ssh_buffer_add_data(session->out_buffer,
- buffer_get_rest(buffer),
- buffer_get_rest_len(buffer));
+ ssh_buffer_get_rest(buffer),
+ ssh_buffer_get_rest_len(buffer));
if (rc < 0) {
ssh_set_error_oom(session);
rc = SSH_ERROR;
@@ -2584,7 +2584,7 @@ struct ssh_channel_read_termination_struct {
static int ssh_channel_read_termination(void *s){
struct ssh_channel_read_termination_struct *ctx = s;
- if (buffer_get_rest_len(ctx->buffer) >= ctx->count ||
+ if (ssh_buffer_get_rest_len(ctx->buffer) >= ctx->count ||
ctx->channel->remote_eof ||
ctx->channel->session->session_state == SSH_SESSION_STATE_ERROR)
return 1;
@@ -2681,11 +2681,11 @@ int ssh_channel_read_timeout(ssh_channel channel,
SSH_LOG(SSH_LOG_PACKET,
"Read (%d) buffered : %d bytes. Window: %d",
count,
- buffer_get_rest_len(stdbuf),
+ ssh_buffer_get_rest_len(stdbuf),
channel->local_window);
- if (count > buffer_get_rest_len(stdbuf) + channel->local_window) {
- if (grow_window(session, channel, count - buffer_get_rest_len(stdbuf)) < 0) {
+ if (count > ssh_buffer_get_rest_len(stdbuf) + channel->local_window) {
+ if (grow_window(session, channel, count - ssh_buffer_get_rest_len(stdbuf)) < 0) {
return -1;
}
}
@@ -2711,14 +2711,14 @@ int ssh_channel_read_timeout(ssh_channel channel,
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
return SSH_ERROR;
}
- if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) {
+ if (channel->remote_eof && ssh_buffer_get_rest_len(stdbuf) == 0) {
return 0;
}
- len = buffer_get_rest_len(stdbuf);
+ len = ssh_buffer_get_rest_len(stdbuf);
/* Read count bytes if len is greater, everything otherwise */
len = (len > count ? count : len);
- memcpy(dest, buffer_get_rest(stdbuf), len);
- buffer_pass_bytes(stdbuf,len);
+ memcpy(dest, ssh_buffer_get_rest(stdbuf), len);
+ ssh_buffer_pass_bytes(stdbuf,len);
if (channel->counter != NULL) {
channel->counter->in_bytes += len;
}
@@ -2818,7 +2818,7 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
stdbuf = channel->stderr_buffer;
}
- if (buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
+ if (ssh_buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
return SSH_ERROR;
}
@@ -2827,15 +2827,15 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
}
}
- if (buffer_get_rest_len(stdbuf) > 0){
- return buffer_get_rest_len(stdbuf);
+ if (ssh_buffer_get_rest_len(stdbuf) > 0){
+ return ssh_buffer_get_rest_len(stdbuf);
}
if (channel->remote_eof) {
return SSH_EOF;
}
- return buffer_get_rest_len(stdbuf);
+ return ssh_buffer_get_rest_len(stdbuf);
}
/**
@@ -2882,7 +2882,7 @@ int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr){
rc = SSH_ERROR;
goto end;
}
- rc = buffer_get_rest_len(stdbuf);
+ rc = ssh_buffer_get_rest_len(stdbuf);
if(rc > 0)
goto end;
if (channel->remote_eof)
@@ -2971,8 +2971,8 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
ssh_handle_packets(chan->session, SSH_TIMEOUT_NONBLOCKING);
}
- if ((chan->stdout_buffer && buffer_get_rest_len(chan->stdout_buffer) > 0) ||
- (chan->stderr_buffer && buffer_get_rest_len(chan->stderr_buffer) > 0) ||
+ if ((chan->stdout_buffer && ssh_buffer_get_rest_len(chan->stdout_buffer) > 0) ||
+ (chan->stderr_buffer && ssh_buffer_get_rest_len(chan->stderr_buffer) > 0) ||
chan->remote_eof) {
rout[j] = chan;
j++;
diff --git a/src/channels1.c b/src/channels1.c
index 4b7d268..c3e7b92 100644
--- a/src/channels1.c
+++ b/src/channels1.c
@@ -112,18 +112,18 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
return -1;
}
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_REQUEST_PTY) < 0 ||
- buffer_add_ssh_string(session->out_buffer, str) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_REQUEST_PTY) < 0 ||
+ ssh_buffer_add_ssh_string(session->out_buffer, str) < 0) {
ssh_string_free(str);
return -1;
}
ssh_string_free(str);
- if (buffer_add_u32(session->out_buffer, ntohl(row)) < 0 ||
- buffer_add_u32(session->out_buffer, ntohl(col)) < 0 ||
- buffer_add_u32(session->out_buffer, 0) < 0 || /* x */
- buffer_add_u32(session->out_buffer, 0) < 0 || /* y */
- buffer_add_u8(session->out_buffer, 0) < 0) { /* tty things */
+ if (ssh_buffer_add_u32(session->out_buffer, ntohl(row)) < 0 ||
+ ssh_buffer_add_u32(session->out_buffer, ntohl(col)) < 0 ||
+ ssh_buffer_add_u32(session->out_buffer, 0) < 0 || /* x */
+ ssh_buffer_add_u32(session->out_buffer, 0) < 0 || /* y */
+ ssh_buffer_add_u8(session->out_buffer, 0) < 0) { /* tty things */
return -1;
}
@@ -170,11 +170,11 @@ int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
return SSH_ERROR;
}
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_WINDOW_SIZE) < 0 ||
- buffer_add_u32(session->out_buffer, ntohl(rows)) < 0 ||
- buffer_add_u32(session->out_buffer, ntohl(cols)) < 0 ||
- buffer_add_u32(session->out_buffer, 0) < 0 ||
- buffer_add_u32(session->out_buffer, 0) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_WINDOW_SIZE) < 0 ||
+ ssh_buffer_add_u32(session->out_buffer, ntohl(rows)) < 0 ||
+ ssh_buffer_add_u32(session->out_buffer, ntohl(cols)) < 0 ||
+ ssh_buffer_add_u32(session->out_buffer, 0) < 0 ||
+ ssh_buffer_add_u32(session->out_buffer, 0) < 0) {
return SSH_ERROR;
}
channel->request_state=SSH_CHANNEL_REQ_STATE_PENDING;
@@ -215,7 +215,7 @@ int channel_request_shell1(ssh_channel channel) {
}
session = channel->session;
- if (buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) {
return -1;
}
@@ -242,8 +242,8 @@ int channel_request_exec1(ssh_channel channel, const char *cmd) {
return -1;
}
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_EXEC_CMD) < 0 ||
- buffer_add_ssh_string(session->out_buffer, command) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_EXEC_CMD) < 0 ||
+ ssh_buffer_add_ssh_string(session->out_buffer, command) < 0) {
ssh_string_free(command);
return -1;
}
@@ -268,7 +268,7 @@ SSH_PACKET_CALLBACK(ssh_packet_data1){
return SSH_PACKET_NOT_USED;
}
- str = buffer_get_ssh_string(packet);
+ str = ssh_buffer_get_ssh_string(packet);
if (str == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS, "Invalid data packet !\n");
return SSH_PACKET_USED;
@@ -300,7 +300,7 @@ SSH_PACKET_CALLBACK(ssh_packet_close1){
return SSH_PACKET_NOT_USED;
}
- buffer_get_u32(packet, &status);
+ ssh_buffer_get_u32(packet, &status);
/*
* It's much more than a channel closing. spec says it's the last
* message sent by server (strange)
@@ -310,7 +310,7 @@ SSH_PACKET_CALLBACK(ssh_packet_close1){
channel->state = SSH_CHANNEL_STATE_CLOSED;
channel->remote_eof = 1;
- rc = buffer_add_u8(session->out_buffer, SSH_CMSG_EXIT_CONFIRMATION);
+ rc = ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_EXIT_CONFIRMATION);
if (rc < 0) {
return SSH_PACKET_NOT_USED;
}
@@ -329,7 +329,7 @@ SSH_PACKET_CALLBACK(ssh_packet_exist_status1){
return SSH_PACKET_NOT_USED;
}
- buffer_get_u32(packet, &status);
+ ssh_buffer_get_u32(packet, &status);
channel->state = SSH_CHANNEL_STATE_CLOSED;
channel->remote_eof = 1;
channel->exit_status = ntohl(status);
@@ -350,13 +350,13 @@ int channel_write1(ssh_channel channel, const void *data, int len) {
session = channel->session;
while (len > 0) {
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) {
return -1;
}
effectivelen = len > 32000 ? 32000 : len;
- if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
+ if (ssh_buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
ssh_buffer_add_data(session->out_buffer, ptr, effectivelen) < 0) {
return -1;
}
diff --git a/src/dh.c b/src/dh.c
index b372b2c..1d2367b 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -472,14 +472,14 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
ssh_string pubkey = NULL;
ssh_string signature = NULL;
int rc;
- pubkey = buffer_get_ssh_string(packet);
+ pubkey = ssh_buffer_get_ssh_string(packet);
if (pubkey == NULL){
ssh_set_error(session,SSH_FATAL, "No public key in packet");
goto error;
}
dh_import_pubkey(session, pubkey);
- f = buffer_get_ssh_string(packet);
+ f = ssh_buffer_get_ssh_string(packet);
if (f == NULL) {
ssh_set_error(session,SSH_FATAL, "No F number in packet");
goto error;
@@ -492,7 +492,7 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
goto error;
}
- signature = buffer_get_ssh_string(packet);
+ signature = ssh_buffer_get_ssh_string(packet);
if (signature == NULL) {
ssh_set_error(session, SSH_FATAL, "No signature in packet");
goto error;
@@ -505,7 +505,7 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
}
/* Send the MSG_NEWKEYS */
- if (buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
goto error;
}
@@ -550,22 +550,22 @@ int make_sessionid(ssh_session session) {
* boolean first_kex_packet_follows
* uint32 0 (reserved for future extension)
*/
- rc = buffer_add_u8(server_hash, 0);
+ rc = ssh_buffer_add_u8(server_hash, 0);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u32(server_hash, 0);
+ rc = ssh_buffer_add_u32(server_hash, 0);
if (rc < 0) {
goto error;
}
/* These fields are handled for the server case in ssh_packet_kexinit. */
if (session->client) {
- rc = buffer_add_u8(client_hash, 0);
+ rc = ssh_buffer_add_u8(client_hash, 0);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u32(client_hash, 0);
+ rc = ssh_buffer_add_u32(client_hash, 0);
if (rc < 0) {
goto error;
}
@@ -573,12 +573,12 @@ int make_sessionid(ssh_session session) {
rc = ssh_buffer_pack(buf,
"dPdPS",
- buffer_get_rest_len(client_hash),
- buffer_get_rest_len(client_hash),
- buffer_get_rest(client_hash),
- buffer_get_rest_len(server_hash),
- buffer_get_rest_len(server_hash),
- buffer_get_rest(server_hash),
+ ssh_buffer_get_rest_len(client_hash),
+ ssh_buffer_get_rest_len(client_hash),
+ ssh_buffer_get_rest(client_hash),
+ ssh_buffer_get_rest_len(server_hash),
+ ssh_buffer_get_rest_len(server_hash),
+ ssh_buffer_get_rest(server_hash),
session->next_crypto->server_pubkey);
if(rc != SSH_OK){
@@ -643,7 +643,7 @@ int make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
- sha1(buffer_get_rest(buf), buffer_get_rest_len(buf),
+ sha1(ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf),
session->next_crypto->secret_hash);
break;
case SSH_KEX_ECDH_SHA2_NISTP256:
@@ -655,7 +655,7 @@ int make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
- sha256(buffer_get_rest(buf), buffer_get_rest_len(buf),
+ sha256(ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf),
session->next_crypto->secret_hash);
break;
}
@@ -698,7 +698,7 @@ int hashbufout_add_cookie(ssh_session session) {
return -1;
}
- if (buffer_add_u8(session->out_hashbuf, 20) < 0) {
+ if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
ssh_buffer_reinit(session->out_hashbuf);
return -1;
}
@@ -726,7 +726,7 @@ int hashbufin_add_cookie(ssh_session session, unsigned char *cookie) {
return -1;
}
- if (buffer_add_u8(session->in_hashbuf, 20) < 0) {
+ if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
ssh_buffer_reinit(session->in_hashbuf);
return -1;
}
diff --git a/src/gssapi.c b/src/gssapi.c
index 099294e..09f0d93 100644
--- a/src/gssapi.c
+++ b/src/gssapi.c
@@ -115,8 +115,8 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token){
* @param[in] oid the OID that was selected for authentication
*/
static int ssh_gssapi_send_response(ssh_session session, ssh_string oid){
- if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE) < 0 ||
- buffer_add_ssh_string(session->out_buffer,oid) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE) < 0 ||
+ ssh_buffer_add_ssh_string(session->out_buffer,oid) < 0) {
ssh_set_error_oom(session);
return SSH_ERROR;
}
@@ -293,7 +293,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server){
ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_USERAUTH_GSSAPI_TOKEN in invalid state");
return SSH_PACKET_USED;
}
- token = buffer_get_ssh_string(packet);
+ token = ssh_buffer_get_ssh_string(packet);
if (token == NULL){
ssh_set_error(session, SSH_REQUEST_DENIED, "ssh_packet_userauth_gssapi_token: invalid packet");
@@ -409,7 +409,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_mic)
(void)type;
SSH_LOG(SSH_LOG_PACKET,"Received SSH_MSG_USERAUTH_GSSAPI_MIC");
- mic_token = buffer_get_ssh_string(packet);
+ mic_token = ssh_buffer_get_ssh_string(packet);
if (mic_token == NULL) {
ssh_set_error(session, SSH_FATAL, "Missing MIC in packet");
goto error;
@@ -533,7 +533,7 @@ static int ssh_gssapi_send_auth_mic(ssh_session session, ssh_string *oid_set, in
}
for (i=0; i<n_oid; ++i){
- rc = buffer_add_ssh_string(session->out_buffer, oid_set[i]);
+ rc = ssh_buffer_add_ssh_string(session->out_buffer, oid_set[i]);
if (rc < 0) {
goto fail;
}
@@ -732,7 +732,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_response){
ssh_set_error(session, SSH_FATAL, "Invalid state in ssh_packet_userauth_gssapi_response");
return SSH_PACKET_USED;
}
- oid_s = buffer_get_ssh_string(packet);
+ oid_s = ssh_buffer_get_ssh_string(packet);
if (!oid_s){
ssh_set_error(session, SSH_FATAL, "Missing OID");
return SSH_PACKET_USED;
@@ -828,7 +828,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client){
ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_USERAUTH_GSSAPI_TOKEN in invalid state");
return SSH_PACKET_USED;
}
- token = buffer_get_ssh_string(packet);
+ token = ssh_buffer_get_ssh_string(packet);
if (token == NULL){
ssh_set_error(session, SSH_REQUEST_DENIED, "ssh_packet_userauth_gssapi_token: invalid packet");
diff --git a/src/gzip.c b/src/gzip.c
index ca190bc..0a14084 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -58,8 +58,8 @@ static z_stream *initcompress(ssh_session session, int level) {
static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level){
z_stream *zout = session->current_crypto->compress_out_ctx;
- void *in_ptr = buffer_get_rest(source);
- unsigned long in_size = buffer_get_rest_len(source);
+ void *in_ptr = ssh_buffer_get_rest(source);
+ unsigned long in_size = ssh_buffer_get_rest_len(source);
ssh_buffer dest = NULL;
unsigned char out_buf[BLOCKSIZE] = {0};
unsigned long len;
@@ -113,7 +113,7 @@ int compress_buffer(ssh_session session, ssh_buffer buf) {
return -1;
}
- if (ssh_buffer_add_data(buf, buffer_get_rest(dest), buffer_get_rest_len(dest)) < 0) {
+ if (ssh_buffer_add_data(buf, ssh_buffer_get_rest(dest), ssh_buffer_get_rest_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
@@ -147,8 +147,8 @@ static z_stream *initdecompress(ssh_session session) {
static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t maxlen) {
z_stream *zin = session->current_crypto->compress_in_ctx;
- void *in_ptr = buffer_get_rest(source);
- unsigned long in_size = buffer_get_rest_len(source);
+ void *in_ptr = ssh_buffer_get_rest(source);
+ unsigned long in_size = ssh_buffer_get_rest_len(source);
unsigned char out_buf[BLOCKSIZE] = {0};
ssh_buffer dest = NULL;
unsigned long len;
@@ -185,7 +185,7 @@ static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t
ssh_buffer_free(dest);
return NULL;
}
- if (buffer_get_rest_len(dest) > maxlen){
+ if (ssh_buffer_get_rest_len(dest) > maxlen){
/* Size of packet exceeded, avoid a denial of service attack */
ssh_buffer_free(dest);
return NULL;
@@ -209,7 +209,7 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen){
return -1;
}
- if (ssh_buffer_add_data(buf, buffer_get_rest(dest), buffer_get_rest_len(dest)) < 0) {
+ if (ssh_buffer_add_data(buf, ssh_buffer_get_rest(dest), ssh_buffer_get_rest_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
diff --git a/src/kex.c b/src/kex.c
index 519d79c..02965bd 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -346,7 +346,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
}
if (server_kex) {
- rc = buffer_get_data(packet,session->next_crypto->client_kex.cookie, 16);
+ rc = ssh_buffer_get_data(packet,session->next_crypto->client_kex.cookie, 16);
if (rc != 16) {
ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet");
goto error;
@@ -358,7 +358,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
goto error;
}
} else {
- rc = buffer_get_data(packet,session->next_crypto->server_kex.cookie, 16);
+ rc = ssh_buffer_get_data(packet,session->next_crypto->server_kex.cookie, 16);
if (rc != 16) {
ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet");
goto error;
@@ -372,12 +372,12 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
}
for (i = 0; i < KEX_METHODS_SIZE; i++) {
- str = buffer_get_ssh_string(packet);
+ str = ssh_buffer_get_ssh_string(packet);
if (str == NULL) {
goto error;
}
- rc = buffer_add_ssh_string(session->in_hashbuf, str);
+ rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "Error adding string in hash buffer");
goto error;
@@ -414,17 +414,17 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
* 'make_sessionid').
*/
if (server_kex) {
- rc = buffer_get_u8(packet, &first_kex_packet_follows);
+ rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
if (rc != 1) {
goto error;
}
- rc = buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
+ rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u32(session->in_hashbuf, kexinit_reserved);
+ rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
if (rc < 0) {
goto error;
}
@@ -624,10 +624,10 @@ int ssh_send_kex(ssh_session session, int server_kex) {
goto error;
}
- if (buffer_add_ssh_string(session->out_hashbuf, str) < 0) {
+ if (ssh_buffer_add_ssh_string(session->out_hashbuf, str) < 0) {
goto error;
}
- if (buffer_add_ssh_string(session->out_buffer, str) < 0) {
+ if (ssh_buffer_add_ssh_string(session->out_buffer, str) < 0) {
goto error;
}
ssh_string_free(str);
diff --git a/src/kex1.c b/src/kex1.c
index 758054f..9e0794d 100644
--- a/src/kex1.c
+++ b/src/kex1.c
@@ -51,13 +51,13 @@ static ssh_string make_rsa1_string(ssh_string e, ssh_string n){
goto error;
}
- if (buffer_add_ssh_string(buffer, rsa) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, rsa) < 0) {
goto error;
}
- if (buffer_add_ssh_string(buffer, e) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, e) < 0) {
goto error;
}
- if (buffer_add_ssh_string(buffer, n) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, n) < 0) {
goto error;
}
@@ -325,32 +325,32 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
ssh_set_error(session,SSH_FATAL,"SSH_KEXINIT received in wrong state");
goto error;
}
- if (buffer_get_data(packet, session->next_crypto->server_kex.cookie, 8) != 8) {
+ if (ssh_buffer_get_data(packet, session->next_crypto->server_kex.cookie, 8) != 8) {
ssh_set_error(session, SSH_FATAL, "Can't get cookie in buffer");
goto error;
}
- buffer_get_u32(packet, &server_bits);
- server_exp = buffer_get_mpint(packet);
+ ssh_buffer_get_u32(packet, &server_bits);
+ server_exp = ssh_buffer_get_mpint(packet);
if (server_exp == NULL) {
goto error;
}
- server_mod = buffer_get_mpint(packet);
+ server_mod = ssh_buffer_get_mpint(packet);
if (server_mod == NULL) {
goto error;
}
- buffer_get_u32(packet, &host_bits);
- host_exp = buffer_get_mpint(packet);
+ ssh_buffer_get_u32(packet, &host_bits);
+ host_exp = ssh_buffer_get_mpint(packet);
if (host_exp == NULL) {
goto error;
}
- host_mod = buffer_get_mpint(packet);
+ host_mod = ssh_buffer_get_mpint(packet);
if (host_mod == NULL) {
goto error;
}
- buffer_get_u32(packet, &protocol_flags);
- buffer_get_u32(packet, &supported_ciphers_mask);
- ko = buffer_get_u32(packet, &supported_authentications_mask);
+ ssh_buffer_get_u32(packet, &protocol_flags);
+ ssh_buffer_get_u32(packet, &supported_ciphers_mask);
+ ko = ssh_buffer_get_u32(packet, &supported_authentications_mask);
if ((ko != sizeof(uint32_t)) || !host_mod || !host_exp
|| !server_mod || !server_exp) {
@@ -411,10 +411,10 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
}
SSH_LOG(SSH_LOG_PROTOCOL, "Sending SSH_CMSG_SESSION_KEY");
- if (buffer_add_u8(session->out_buffer, SSH_CMSG_SESSION_KEY) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_SESSION_KEY) < 0) {
goto error;
}
- if (buffer_add_u8(session->out_buffer, support_3DES ? SSH_CIPHER_3DES : SSH_CIPHER_DES) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, support_3DES ? SSH_CIPHER_3DES : SSH_CIPHER_DES) < 0) {
goto error;
}
if (ssh_buffer_add_data(session->out_buffer, session->next_crypto->server_kex.cookie, 8) < 0) {
@@ -439,7 +439,7 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
goto error;
}
/* the protocol flags */
- if (buffer_add_u32(session->out_buffer, 0) < 0) {
+ if (ssh_buffer_add_u32(session->out_buffer, 0) < 0) {
goto error;
}
session->session_state=SSH_SESSION_STATE_KEXINIT_RECEIVED;
diff --git a/src/known_hosts.c b/src/known_hosts.c
index d87af43..263289f 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -211,7 +211,7 @@ static int check_public_key(ssh_session session, char **tokens) {
return -1;
}
- if (buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
+ if (ssh_buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
ssh_buffer_free(pubkey_buffer);
ssh_string_free(tmpstring);
return -1;
@@ -244,7 +244,7 @@ static int check_public_key(ssh_session session, char **tokens) {
bignum_bn2bin(tmpbn, ssh_string_data(tmpstring));
#endif
bignum_free(tmpbn);
- if (buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
+ if (ssh_buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
ssh_buffer_free(pubkey_buffer);
ssh_string_free(tmpstring);
bignum_free(tmpbn);
@@ -264,14 +264,14 @@ static int check_public_key(ssh_session session, char **tokens) {
return -1;
}
- if (buffer_get_rest_len(pubkey_buffer) != ssh_string_len(pubkey)) {
+ if (ssh_buffer_get_rest_len(pubkey_buffer) != ssh_string_len(pubkey)) {
ssh_buffer_free(pubkey_buffer);
return 0;
}
/* now test that they are identical */
- if (memcmp(buffer_get_rest(pubkey_buffer), ssh_string_data(pubkey),
- buffer_get_rest_len(pubkey_buffer)) != 0) {
+ if (memcmp(ssh_buffer_get_rest(pubkey_buffer), ssh_string_data(pubkey),
+ ssh_buffer_get_rest_len(pubkey_buffer)) != 0) {
ssh_buffer_free(pubkey_buffer);
return 0;
}
@@ -340,7 +340,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
return 0;
}
- mac = hmac_init(buffer_get_rest(salt), buffer_get_rest_len(salt), SSH_HMAC_SHA1);
+ mac = hmac_init(ssh_buffer_get_rest(salt), ssh_buffer_get_rest_len(salt), SSH_HMAC_SHA1);
if (mac == NULL) {
ssh_buffer_free(salt);
ssh_buffer_free(hash);
@@ -351,8 +351,8 @@ static int match_hashed_host(const char *host, const char *sourcehash)
hmac_update(mac, host, strlen(host));
hmac_final(mac, buffer, &size);
- if (size == buffer_get_rest_len(hash) &&
- memcmp(buffer, buffer_get_rest(hash), size) == 0) {
+ if (size == ssh_buffer_get_rest_len(hash) &&
+ memcmp(buffer, ssh_buffer_get_rest(hash), size) == 0) {
match = 1;
} else {
match = 0;
diff --git a/src/messages.c b/src/messages.c
index ec53877..bd93b58 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -81,9 +81,9 @@ static ssh_message ssh_message_new(ssh_session session){
static int ssh_message_reply_default(ssh_message msg) {
SSH_LOG(SSH_LOG_FUNCTIONS, "Reporting unknown packet");
- if (buffer_add_u8(msg->session->out_buffer, SSH2_MSG_UNIMPLEMENTED) < 0)
+ if (ssh_buffer_add_u8(msg->session->out_buffer, SSH2_MSG_UNIMPLEMENTED) < 0)
goto error;
- if (buffer_add_u32(msg->session->out_buffer,
+ if (ssh_buffer_add_u32(msg->session->out_buffer,
htonl(msg->session->recv_seq-1)) < 0)
goto error;
return packet_send(msg->session);
@@ -579,7 +579,7 @@ SSH_PACKET_CALLBACK(ssh_packet_service_request){
(void)type;
(void)user;
- service = buffer_get_ssh_string(packet);
+ service = ssh_buffer_get_ssh_string(packet);
if (service == NULL) {
ssh_set_error(session, SSH_FATAL, "Invalid SSH_MSG_SERVICE_REQUEST packet");
goto error;
@@ -712,7 +712,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
ssh_string submethods = NULL;
msg->auth_request.method = SSH_AUTH_METHOD_INTERACTIVE;
- lang = buffer_get_ssh_string(packet);
+ lang = ssh_buffer_get_ssh_string(packet);
if (lang == NULL) {
goto error;
}
@@ -722,7 +722,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
*/
ssh_string_free(lang);
- submethods = buffer_get_ssh_string(packet);
+ submethods = ssh_buffer_get_ssh_string(packet);
if (submethods == NULL) {
goto error;
}
@@ -768,7 +768,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
ssh_string sig_blob = NULL;
ssh_buffer digest = NULL;
- sig_blob = buffer_get_ssh_string(packet);
+ sig_blob = ssh_buffer_get_ssh_string(packet);
if(sig_blob == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid signature packet from peer");
msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_ERROR;
@@ -786,8 +786,8 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
rc = ssh_pki_signature_verify_blob(session,
sig_blob,
msg->auth_request.pubkey,
- buffer_get_rest(digest),
- buffer_get_rest_len(digest));
+ ssh_buffer_get_rest(digest),
+ ssh_buffer_get_rest_len(digest));
ssh_string_free(sig_blob);
ssh_buffer_free(digest);
if (rc < 0) {
@@ -811,7 +811,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
ssh_string oid;
char *hexa;
int i;
- buffer_get_u32(packet, &n_oid);
+ ssh_buffer_get_u32(packet, &n_oid);
n_oid=ntohl(n_oid);
if(n_oid > 100){
ssh_set_error(session, SSH_FATAL, "USERAUTH_REQUEST: gssapi-with-mic OID count too big (%d)",n_oid);
@@ -824,7 +824,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
goto error;
}
for (i=0;i<(int) n_oid;++i){
- oid=buffer_get_ssh_string(packet);
+ oid=ssh_buffer_get_ssh_string(packet);
if(oid == NULL){
for(i=i-1;i>=0;--i){
SAFE_FREE(oids[i]);
@@ -969,7 +969,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){
memset(session->kbdint->answers, 0, nanswers * sizeof(char *));
for (i = 0; i < nanswers; i++) {
- tmp = buffer_get_ssh_string(packet);
+ tmp = ssh_buffer_get_ssh_string(packet);
if (tmp == NULL) {
ssh_set_error(session, SSH_FATAL, "Short INFO_RESPONSE packet");
session->kbdint->nanswers = i;
diff --git a/src/packet.c b/src/packet.c
index d16cd16..4636f26 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -253,11 +253,11 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
* Decrypt the rest of the packet (blocksize bytes already
* have been decrypted)
*/
- uint32_t buffer_len = buffer_get_rest_len(session->in_buffer);
+ uint32_t buffer_len = ssh_buffer_get_rest_len(session->in_buffer);
/* The following check avoids decrypting zero bytes */
if (buffer_len > blocksize) {
- uint8_t *payload = ((uint8_t*)buffer_get_rest(session->in_buffer) + blocksize);
+ uint8_t *payload = ((uint8_t*)ssh_buffer_get_rest(session->in_buffer) + blocksize);
uint32_t plen = buffer_len - blocksize;
rc = packet_decrypt(session, payload, plen);
@@ -280,9 +280,9 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
}
/* skip the size field which has been processed before */
- buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
+ ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
- rc = buffer_get_u8(session->in_buffer, &padding);
+ rc = ssh_buffer_get_u8(session->in_buffer, &padding);
if (rc == 0) {
ssh_set_error(session,
SSH_FATAL,
@@ -290,28 +290,28 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
goto error;
}
- if (padding > buffer_get_rest_len(session->in_buffer)) {
+ if (padding > ssh_buffer_get_rest_len(session->in_buffer)) {
ssh_set_error(session,
SSH_FATAL,
"Invalid padding: %d (%d left)",
padding,
- buffer_get_rest_len(session->in_buffer));
+ ssh_buffer_get_rest_len(session->in_buffer));
goto error;
}
- buffer_pass_bytes_end(session->in_buffer, padding);
- compsize = buffer_get_rest_len(session->in_buffer);
+ ssh_buffer_pass_bytes_end(session->in_buffer, padding);
+ compsize = ssh_buffer_get_rest_len(session->in_buffer);
#ifdef WITH_ZLIB
if (session->current_crypto
&& session->current_crypto->do_compress_in
- && buffer_get_rest_len(session->in_buffer) > 0) {
+ && ssh_buffer_get_rest_len(session->in_buffer) > 0) {
rc = decompress_buffer(session, session->in_buffer,MAX_PACKET_LEN);
if (rc < 0) {
goto error;
}
}
#endif /* WITH_ZLIB */
- payloadsize = buffer_get_rest_len(session->in_buffer);
+ payloadsize = ssh_buffer_get_rest_len(session->in_buffer);
session->recv_seq++;
if (session->raw_counter != NULL) {
session->raw_counter->in_bytes += payloadsize;
@@ -489,7 +489,7 @@ int ssh_packet_parse_type(ssh_session session) {
return SSH_ERROR;
}
- if(buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
+ if(ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
return SSH_ERROR;
}
@@ -507,8 +507,8 @@ static int ssh_packet_write(ssh_session session) {
int rc = SSH_ERROR;
rc=ssh_socket_write(session->socket,
- buffer_get_rest(session->out_buffer),
- buffer_get_rest_len(session->out_buffer));
+ ssh_buffer_get_rest(session->out_buffer),
+ ssh_buffer_get_rest_len(session->out_buffer));
return rc;
}
@@ -518,7 +518,7 @@ static int packet_send2(ssh_session session) {
session->current_crypto->out_cipher->blocksize : 8);
enum ssh_hmac_e hmac_type = (session->current_crypto ?
session->current_crypto->out_hmac : session->next_crypto->out_hmac);
- uint32_t currentlen = buffer_get_rest_len(session->out_buffer);
+ uint32_t currentlen = ssh_buffer_get_rest_len(session->out_buffer);
unsigned char *hmac = NULL;
char padstring[32] = { 0 };
int rc = SSH_ERROR;
@@ -531,11 +531,11 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_ZLIB
if (session->current_crypto
&& session->current_crypto->do_compress_out
- && buffer_get_rest_len(session->out_buffer)) {
+ && ssh_buffer_get_rest_len(session->out_buffer)) {
if (compress_buffer(session,session->out_buffer) < 0) {
goto error;
}
- currentlen = buffer_get_rest_len(session->out_buffer);
+ currentlen = ssh_buffer_get_rest_len(session->out_buffer);
}
#endif /* WITH_ZLIB */
compsize = currentlen;
@@ -552,7 +552,7 @@ static int packet_send2(ssh_session session) {
memcpy(&header[0], &finallen, sizeof(finallen));
header[sizeof(finallen)] = padding;
- rc = buffer_prepend_data(session->out_buffer, &header, sizeof(header));
+ rc = ssh_buffer_prepend_data(session->out_buffer, &header, sizeof(header));
if (rc < 0) {
goto error;
}
@@ -563,12 +563,12 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_PCAP
if(session->pcap_ctx){
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,
- buffer_get_rest(session->out_buffer),buffer_get_rest_len(session->out_buffer)
- ,buffer_get_rest_len(session->out_buffer));
+ ssh_buffer_get_rest(session->out_buffer),ssh_buffer_get_rest_len(session->out_buffer)
+ ,ssh_buffer_get_rest_len(session->out_buffer));
}
#endif
- hmac = packet_encrypt(session, buffer_get_rest(session->out_buffer),
- buffer_get_rest_len(session->out_buffer));
+ hmac = packet_encrypt(session, ssh_buffer_get_rest(session->out_buffer),
+ ssh_buffer_get_rest_len(session->out_buffer));
if (hmac) {
rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
if (rc < 0) {
diff --git a/src/packet1.c b/src/packet1.c
index eac7008..543af1f 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -185,7 +185,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
ssh_buffer_get_len(session->in_buffer));
#endif
SSH_LOG(SSH_LOG_PACKET, "%d bytes padding", padding);
- if(((len + padding) != buffer_get_rest_len(session->in_buffer)) ||
+ if(((len + padding) != ssh_buffer_get_rest_len(session->in_buffer)) ||
((len + padding) < sizeof(uint32_t))) {
SSH_LOG(SSH_LOG_RARE, "no crc32 in packet");
ssh_set_error(session, SSH_FATAL, "no crc32 in packet");
@@ -193,26 +193,26 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
}
memcpy(&crc,
- (unsigned char *)buffer_get_rest(session->in_buffer) + (len+padding) - sizeof(uint32_t),
+ (unsigned char *)ssh_buffer_get_rest(session->in_buffer) + (len+padding) - sizeof(uint32_t),
sizeof(uint32_t));
- buffer_pass_bytes_end(session->in_buffer, sizeof(uint32_t));
+ ssh_buffer_pass_bytes_end(session->in_buffer, sizeof(uint32_t));
crc = ntohl(crc);
- if (ssh_crc32(buffer_get_rest(session->in_buffer),
+ if (ssh_crc32(ssh_buffer_get_rest(session->in_buffer),
(len + padding) - sizeof(uint32_t)) != crc) {
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("crc32 on",buffer_get_rest(session->in_buffer),
+ ssh_print_hexa("crc32 on",ssh_buffer_get_rest(session->in_buffer),
len + padding - sizeof(uint32_t));
#endif
SSH_LOG(SSH_LOG_RARE, "Invalid crc32");
ssh_set_error(session, SSH_FATAL,
"Invalid crc32: expected %.8x, got %.8x",
crc,
- ssh_crc32(buffer_get_rest(session->in_buffer),
+ ssh_crc32(ssh_buffer_get_rest(session->in_buffer),
len + padding - sizeof(uint32_t)));
goto error;
}
/* pass the padding */
- buffer_pass_bytes(session->in_buffer, padding);
+ ssh_buffer_pass_bytes(session->in_buffer, padding);
SSH_LOG(SSH_LOG_PACKET, "The packet is valid");
/* TODO FIXME
@@ -270,7 +270,7 @@ int packet_send1(ssh_session session) {
if (compress_buffer(session, session->out_buffer) < 0) {
goto error;
}
- currentlen = buffer_get_len(session->out_buffer);
+ currentlen = ssh_buffer_get_len(session->out_buffer);
}
#endif
*/
@@ -286,17 +286,17 @@ int packet_send1(ssh_session session) {
"%d bytes after comp + %d padding bytes = %d bytes packet",
currentlen, padding, ntohl(finallen));
- if (buffer_prepend_data(session->out_buffer, &padstring, padding) < 0) {
+ if (ssh_buffer_prepend_data(session->out_buffer, &padstring, padding) < 0) {
goto error;
}
- if (buffer_prepend_data(session->out_buffer, &finallen, sizeof(uint32_t)) < 0) {
+ if (ssh_buffer_prepend_data(session->out_buffer, &finallen, sizeof(uint32_t)) < 0) {
goto error;
}
crc = ssh_crc32((char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
- if (buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) {
+ if (ssh_buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) {
goto error;
}
diff --git a/src/packet_cb.c b/src/packet_cb.c
index 4fe6402..8353b46 100644
--- a/src/packet_cb.c
+++ b/src/packet_cb.c
@@ -53,12 +53,12 @@ SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback){
(void)user;
(void)type;
- rc = buffer_get_u32(packet, &code);
+ rc = ssh_buffer_get_u32(packet, &code);
if (rc != 0) {
code = ntohl(code);
}
- error_s = buffer_get_ssh_string(packet);
+ error_s = ssh_buffer_get_ssh_string(packet);
if (error_s != NULL) {
error = ssh_string_to_char(error_s);
ssh_string_free(error_s);
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index 914727e..c24a3e9 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -175,7 +175,7 @@ int packet_hmac_verify(ssh_session session, ssh_buffer buffer,
seq = htonl(session->recv_seq);
hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
- hmac_update(ctx, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
+ hmac_update(ctx, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
hmac_final(ctx, hmacbuf, &len);
#ifdef DEBUG_CRYPTO
diff --git a/src/pcap.c b/src/pcap.c
index 134bdf1..4efb052 100644
--- a/src/pcap.c
+++ b/src/pcap.c
@@ -144,8 +144,8 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
uint32_t len;
if(pcap == NULL || pcap->output==NULL)
return SSH_ERROR;
- len=buffer_get_rest_len(packet);
- err=fwrite(buffer_get_rest(packet),len,1,pcap->output);
+ len=ssh_buffer_get_rest_len(packet);
+ err=fwrite(ssh_buffer_get_rest(packet),len,1,pcap->output);
if(err<0)
return SSH_ERROR;
else
@@ -163,23 +163,23 @@ int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t o
if(header == NULL)
return SSH_ERROR;
gettimeofday(&now,NULL);
- err = buffer_add_u32(header,htonl(now.tv_sec));
+ err = ssh_buffer_add_u32(header,htonl(now.tv_sec));
if (err < 0) {
goto error;
}
- err = buffer_add_u32(header,htonl(now.tv_usec));
+ err = ssh_buffer_add_u32(header,htonl(now.tv_usec));
if (err < 0) {
goto error;
}
- err = buffer_add_u32(header,htonl(buffer_get_rest_len(packet)));
+ err = ssh_buffer_add_u32(header,htonl(ssh_buffer_get_rest_len(packet)));
if (err < 0) {
goto error;
}
- err = buffer_add_u32(header,htonl(original_len));
+ err = ssh_buffer_add_u32(header,htonl(original_len));
if (err < 0) {
goto error;
}
- err = buffer_add_buffer(header,packet);
+ err = ssh_buffer_add_buffer(header,packet);
if (err < 0) {
goto error;
}
@@ -207,35 +207,35 @@ int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename){
header=ssh_buffer_new();
if(header==NULL)
return SSH_ERROR;
- err = buffer_add_u32(header,htonl(PCAP_MAGIC));
+ err = ssh_buffer_add_u32(header,htonl(PCAP_MAGIC));
if (err < 0) {
goto error;
}
- err = buffer_add_u16(header,htons(PCAP_VERSION_MAJOR));
+ err = ssh_buffer_add_u16(header,htons(PCAP_VERSION_MAJOR));
if (err < 0) {
goto error;
}
- err = buffer_add_u16(header,htons(PCAP_VERSION_MINOR));
+ err = ssh_buffer_add_u16(header,htons(PCAP_VERSION_MINOR));
if (err < 0) {
goto error;
}
/* currently hardcode GMT to 0 */
- err = buffer_add_u32(header,htonl(0));
+ err = ssh_buffer_add_u32(header,htonl(0));
if (err < 0) {
goto error;
}
/* accuracy */
- err = buffer_add_u32(header,htonl(0));
+ err = ssh_buffer_add_u32(header,htonl(0));
if (err < 0) {
goto error;
}
/* size of the biggest packet */
- err = buffer_add_u32(header,htonl(MAX_PACKET_LEN));
+ err = ssh_buffer_add_u32(header,htonl(MAX_PACKET_LEN));
if (err < 0) {
goto error;
}
/* we will write sort-of IP */
- err = buffer_add_u32(header,htonl(DLT_RAW));
+ err = ssh_buffer_add_u32(header,htonl(DLT_RAW));
if (err < 0) {
goto error;
}
@@ -371,40 +371,40 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
goto error;
}
if(direction==SSH_PCAP_DIR_OUT){
- rc = buffer_add_u32(ip,ctx->ipsource);
+ rc = ssh_buffer_add_u32(ip,ctx->ipsource);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u32(ip,ctx->ipdest);
+ rc = ssh_buffer_add_u32(ip,ctx->ipdest);
if (rc < 0) {
goto error;
}
} else {
- rc = buffer_add_u32(ip,ctx->ipdest);
+ rc = ssh_buffer_add_u32(ip,ctx->ipdest);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u32(ip,ctx->ipsource);
+ rc = ssh_buffer_add_u32(ip,ctx->ipsource);
if (rc < 0) {
goto error;
}
}
/* TCP */
if(direction==SSH_PCAP_DIR_OUT){
- rc = buffer_add_u16(ip,ctx->portsource);
+ rc = ssh_buffer_add_u16(ip,ctx->portsource);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u16(ip,ctx->portdest);
+ rc = ssh_buffer_add_u16(ip,ctx->portdest);
if (rc < 0) {
goto error;
}
} else {
- rc = buffer_add_u16(ip,ctx->portdest);
+ rc = ssh_buffer_add_u16(ip,ctx->portdest);
if (rc < 0) {
goto error;
}
- rc = buffer_add_u16(ip,ctx->portsource);
+ rc = ssh_buffer_add_u16(ip,ctx->portsource);
if (rc < 0) {
goto error;
}
diff --git a/src/pki.c b/src/pki.c
index 22143cb..12e84e2 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -671,18 +671,18 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
ssh_string g;
ssh_string pubkey;
- p = buffer_get_ssh_string(buffer);
+ p = ssh_buffer_get_ssh_string(buffer);
if (p == NULL) {
goto fail;
}
- q = buffer_get_ssh_string(buffer);
+ q = ssh_buffer_get_ssh_string(buffer);
if (q == NULL) {
ssh_string_burn(p);
ssh_string_free(p);
goto fail;
}
- g = buffer_get_ssh_string(buffer);
+ g = ssh_buffer_get_ssh_string(buffer);
if (g == NULL) {
ssh_string_burn(p);
ssh_string_free(p);
@@ -691,7 +691,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
goto fail;
}
- pubkey = buffer_get_ssh_string(buffer);
+ pubkey = ssh_buffer_get_ssh_string(buffer);
if (pubkey == NULL) {
ssh_string_burn(p);
ssh_string_free(p);
@@ -728,11 +728,11 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
ssh_string e;
ssh_string n;
- e = buffer_get_ssh_string(buffer);
+ e = ssh_buffer_get_ssh_string(buffer);
if (e == NULL) {
goto fail;
}
- n = buffer_get_ssh_string(buffer);
+ n = ssh_buffer_get_ssh_string(buffer);
if (n == NULL) {
ssh_string_burn(e);
ssh_string_free(e);
@@ -761,7 +761,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
ssh_string i;
int nid;
- i = buffer_get_ssh_string(buffer);
+ i = ssh_buffer_get_ssh_string(buffer);
if (i == NULL) {
goto fail;
}
@@ -772,7 +772,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
}
- e = buffer_get_ssh_string(buffer);
+ e = ssh_buffer_get_ssh_string(buffer);
if (e == NULL) {
goto fail;
}
@@ -791,7 +791,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
#endif
case SSH_KEYTYPE_ED25519:
{
- ssh_string pubkey = buffer_get_ssh_string(buffer);
+ ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
if (ssh_string_len(pubkey) != ED25519_PK_LEN) {
SSH_LOG(SSH_LOG_WARN, "Invalid public key length");
ssh_string_burn(pubkey);
@@ -858,13 +858,13 @@ static int pki_import_cert_buffer(ssh_buffer buffer,
if (type_s == NULL) {
goto fail;
}
- rc = buffer_add_ssh_string(cert, type_s);
+ rc = ssh_buffer_add_ssh_string(cert, type_s);
ssh_string_free(type_s);
if (rc != 0) {
goto fail;
}
- rc = buffer_add_buffer(cert, buffer);
+ rc = ssh_buffer_add_buffer(cert, buffer);
if (rc != 0) {
goto fail;
}
@@ -909,7 +909,7 @@ int ssh_pki_import_pubkey_base64(const char *b64_key,
return SSH_ERROR;
}
- type_s = buffer_get_ssh_string(buffer);
+ type_s = ssh_buffer_get_ssh_string(buffer);
if (type_s == NULL) {
ssh_buffer_free(buffer);
return SSH_ERROR;
@@ -966,7 +966,7 @@ int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
goto fail;
}
- type_s = buffer_get_ssh_string(buffer);
+ type_s = ssh_buffer_get_ssh_string(buffer);
if (type_s == NULL) {
SSH_LOG(SSH_LOG_WARN, "Out of memory!");
goto fail;
@@ -1406,7 +1406,7 @@ int ssh_pki_copy_cert_to_privkey(const ssh_key certkey, ssh_key privkey) {
return SSH_ERROR;
}
- rc = buffer_add_buffer(cert_buffer, certkey->cert);
+ rc = ssh_buffer_add_buffer(cert_buffer, certkey->cert);
if (rc != 0) {
ssh_buffer_free(cert_buffer);
return SSH_ERROR;
@@ -1447,7 +1447,7 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
return SSH_ERROR;
}
- rc = buffer_add_ssh_string(buf, str);
+ rc = ssh_buffer_add_ssh_string(buf, str);
ssh_string_free(str);
if (rc < 0) {
ssh_buffer_free(buf);
@@ -1460,20 +1460,20 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
return SSH_ERROR;
}
- rc = buffer_add_ssh_string(buf, str);
+ rc = ssh_buffer_add_ssh_string(buf, str);
ssh_string_free(str);
if (rc < 0) {
ssh_buffer_free(buf);
return SSH_ERROR;
}
- str = ssh_string_new(buffer_get_rest_len(buf));
+ str = ssh_string_new(ssh_buffer_get_rest_len(buf));
if (str == NULL) {
ssh_buffer_free(buf);
return SSH_ERROR;
}
- ssh_string_fill(str, buffer_get_rest(buf), buffer_get_rest_len(buf));
+ ssh_string_fill(str, ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf));
ssh_buffer_free(buf);
*sig_blob = str;
@@ -1508,7 +1508,7 @@ int ssh_pki_import_signature_blob(const ssh_string sig_blob,
return SSH_ERROR;
}
- str = buffer_get_ssh_string(buf);
+ str = ssh_buffer_get_ssh_string(buf);
if (str == NULL) {
ssh_buffer_free(buf);
return SSH_ERROR;
@@ -1517,7 +1517,7 @@ int ssh_pki_import_signature_blob(const ssh_string sig_blob,
type = ssh_key_type_from_name(ssh_string_get_char(str));
ssh_string_free(str);
- str = buffer_get_ssh_string(buf);
+ str = ssh_buffer_get_ssh_string(buf);
ssh_buffer_free(buf);
if (str == NULL) {
return SSH_ERROR;
@@ -1629,7 +1629,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
evp_update(ctx, session_id, ssh_string_len(session_id) + 4);
- evp_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
+ evp_update(ctx, ssh_buffer_get_rest(sigbuf), ssh_buffer_get_rest_len(sigbuf));
evp_final(ctx, ehash, &elen);
#ifdef DEBUG_CRYPTO
@@ -1651,7 +1651,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
rc = ssh_buffer_pack(buf,
"SP",
session_id,
- buffer_get_rest_len(sigbuf), buffer_get_rest(sigbuf));
+ ssh_buffer_get_rest_len(sigbuf), ssh_buffer_get_rest(sigbuf));
if (rc != SSH_OK) {
ssh_string_free(session_id);
ssh_buffer_free(buf);
@@ -1673,7 +1673,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
sha1_update(ctx, session_id, ssh_string_len(session_id) + 4);
- sha1_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
+ sha1_update(ctx, ssh_buffer_get_rest(sigbuf), ssh_buffer_get_rest_len(sigbuf));
sha1_final(hash, ctx);
#ifdef DEBUG_CRYPTO
@@ -1725,7 +1725,7 @@ ssh_string ssh_pki_do_sign_agent(ssh_session session,
return NULL;
}
- rc = buffer_add_ssh_string(sig_buf, session_id);
+ rc = ssh_buffer_add_ssh_string(sig_buf, session_id);
if (rc < 0) {
ssh_string_free(session_id);
ssh_buffer_free(sig_buf);
@@ -1734,7 +1734,7 @@ ssh_string ssh_pki_do_sign_agent(ssh_session session,
ssh_string_free(session_id);
/* append out buffer */
- if (buffer_add_buffer(sig_buf, buf) < 0) {
+ if (ssh_buffer_add_buffer(sig_buf, buf) < 0) {
ssh_buffer_free(sig_buf);
return NULL;
}
diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c
index 40b1156..1f2ed97 100644
--- a/src/pki_container_openssh.c
+++ b/src/pki_container_openssh.c
@@ -384,11 +384,11 @@ ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
if (rc == SSH_ERROR){
goto error;
}
- comment = buffer_get_ssh_string(privkey_buffer);
+ comment = ssh_buffer_get_ssh_string(privkey_buffer);
SAFE_FREE(comment);
/* verify that the remaining data is correct padding */
- for (i=1; buffer_get_rest_len(privkey_buffer) > 0; ++i){
- buffer_get_u8(privkey_buffer, &padding);
+ for (i=1; ssh_buffer_get_rest_len(privkey_buffer) > 0; ++i){
+ ssh_buffer_get_u8(privkey_buffer, &padding);
if (padding != i){
ssh_key_free(key);
key = NULL;
@@ -493,7 +493,7 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer,
return SSH_ERROR;
}
while (ssh_buffer_get_len(privkey_buffer) % cipher.blocksize != 0) {
- rc = buffer_add_u8(privkey_buffer, padding);
+ rc = ssh_buffer_add_u8(privkey_buffer, padding);
if (rc < 0) {
return SSH_ERROR;
}
@@ -704,7 +704,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
}
str_len = ssh_buffer_get_len(buffer);
- len = buffer_get_data(buffer, ssh_string_data(str), str_len);
+ len = ssh_buffer_get_data(buffer, ssh_string_data(str), str_len);
if (str_len != len) {
ssh_string_free(str);
str = NULL;
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index 7a3caba..dde6230 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -1034,12 +1034,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
- str = ssh_string_new(buffer_get_rest_len(buffer));
+ str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
if (str == NULL) {
goto fail;
}
- rc = ssh_string_fill(str, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
+ rc = ssh_string_fill(str, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
if (rc < 0) {
goto fail;
}
@@ -1238,13 +1238,13 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
return NULL;
}
- sig_blob = ssh_string_new(buffer_get_rest_len(b));
+ sig_blob = ssh_string_new(ssh_buffer_get_rest_len(b));
if (sig_blob == NULL) {
ssh_buffer_free(b);
return NULL;
}
- ssh_string_fill(sig_blob, buffer_get_rest(b), buffer_get_rest_len(b));
+ ssh_string_fill(sig_blob, ssh_buffer_get_rest(b), ssh_buffer_get_rest_len(b));
ssh_buffer_free(b);
break;
}
@@ -1449,7 +1449,7 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey,
}
s = buffer_get_ssh_string(b);
- rlen = buffer_get_rest_len(b);
+ rlen = ssh_buffer_get_rest_len(b);
ssh_buffer_free(b);
if (s == NULL) {
ssh_signature_free(sig);
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 0def32c..0b65ccd 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -92,7 +92,7 @@ static uint32_t asn1_get_len(ssh_buffer buffer) {
uint32_t len;
unsigned char tmp[4];
- if (buffer_get_data(buffer,tmp,1) == 0) {
+ if (ssh_buffer_get_data(buffer,tmp,1) == 0) {
return 0;
}
@@ -101,7 +101,7 @@ static uint32_t asn1_get_len(ssh_buffer buffer) {
if (len > 4) {
return 0; /* Length doesn't fit in u32. Can this really happen? */
}
- if (buffer_get_data(buffer,tmp,len) == 0) {
+ if (ssh_buffer_get_data(buffer,tmp,len) == 0) {
return 0;
}
len = char_to_u32(tmp, len);
@@ -117,7 +117,7 @@ static ssh_string asn1_get_int(ssh_buffer buffer) {
unsigned char type;
uint32_t size;
- if (buffer_get_data(buffer, &type, 1) == 0 || type != ASN1_INTEGER) {
+ if (ssh_buffer_get_data(buffer, &type, 1) == 0 || type != ASN1_INTEGER) {
return NULL;
}
size = asn1_get_len(buffer);
@@ -130,7 +130,7 @@ static ssh_string asn1_get_int(ssh_buffer buffer) {
return NULL;
}
- if (buffer_get_data(buffer, ssh_string_data(str), size) == 0) {
+ if (ssh_buffer_get_data(buffer, ssh_string_data(str), size) == 0) {
ssh_string_free(str);
return NULL;
}
@@ -145,7 +145,7 @@ static int asn1_check_sequence(ssh_buffer buffer) {
uint32_t size;
uint32_t padding;
- if (buffer_get_data(buffer, &tmp, 1) == 0 || tmp != ASN1_SEQUENCE) {
+ if (ssh_buffer_get_data(buffer, &tmp, 1) == 0 || tmp != ASN1_SEQUENCE) {
return 0;
}
@@ -1168,7 +1168,7 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
return NULL;
}
- rc = buffer_add_ssh_string(buffer, type_s);
+ rc = ssh_buffer_add_ssh_string(buffer, type_s);
ssh_string_free(type_s);
if (rc < 0) {
ssh_buffer_free(buffer);
@@ -1224,16 +1224,16 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
}
ssh_string_fill(n, (char *) tmp, size);
- if (buffer_add_ssh_string(buffer, p) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, p) < 0) {
goto fail;
}
- if (buffer_add_ssh_string(buffer, q) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, q) < 0) {
goto fail;
}
- if (buffer_add_ssh_string(buffer, g) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, g) < 0) {
goto fail;
}
- if (buffer_add_ssh_string(buffer, n) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, n) < 0) {
goto fail;
}
@@ -1273,10 +1273,10 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
ssh_string_fill(n, (char *) tmp, size);
gcry_sexp_release(sexp);
- if (buffer_add_ssh_string(buffer, e) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, e) < 0) {
goto fail;
}
- if (buffer_add_ssh_string(buffer, n) < 0) {
+ if (ssh_buffer_add_ssh_string(buffer, n) < 0) {
goto fail;
}
@@ -1298,12 +1298,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
- str = ssh_string_new(buffer_get_rest_len(buffer));
+ str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
if (str == NULL) {
goto fail;
}
- rc = ssh_string_fill(str, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
+ rc = ssh_string_fill(str, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
if (rc < 0) {
goto fail;
}
diff --git a/src/server.c b/src/server.c
index a078e7a..6679245 100644
--- a/src/server.c
+++ b/src/server.c
@@ -155,7 +155,7 @@ static int server_set_kex(ssh_session session) {
**/
static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){
ssh_string e;
- e = buffer_get_ssh_string(packet);
+ e = ssh_buffer_get_ssh_string(packet);
if (e == NULL) {
ssh_set_error(session, SSH_FATAL, "No e number in client request");
return -1;
@@ -325,7 +325,7 @@ static int dh_handshake_server(ssh_session session) {
return -1;
}
- if (buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
ssh_buffer_reinit(session->out_buffer);
return -1;
}
@@ -738,7 +738,7 @@ int ssh_message_global_request_reply_success(ssh_message msg, uint16_t bound_por
SSH_LOG(SSH_LOG_FUNCTIONS, "Accepting a global request");
if (msg->global_request.want_reply) {
- if (buffer_add_u8(msg->session->out_buffer
+ if (ssh_buffer_add_u8(msg->session->out_buffer
, SSH2_MSG_REQUEST_SUCCESS) < 0) {
goto error;
}
@@ -770,7 +770,7 @@ static int ssh_message_global_request_reply_default(ssh_message msg) {
SSH_LOG(SSH_LOG_FUNCTIONS, "Refusing a global request");
if (msg->global_request.want_reply) {
- if (buffer_add_u8(msg->session->out_buffer
+ if (ssh_buffer_add_u8(msg->session->out_buffer
, SSH2_MSG_REQUEST_FAILURE) < 0) {
goto error;
}
@@ -994,7 +994,7 @@ int ssh_auth_reply_success(ssh_session session, int partial) {
session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
session->flags |= SSH_SESSION_FLAG_AUTHENTICATED;
- if (buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS) < 0) {
+ if (ssh_buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS) < 0) {
return SSH_ERROR;
}
diff --git a/src/sftp.c b/src/sftp.c
index 39d0819..c1dbda1 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -210,7 +210,7 @@ int sftp_server_init(sftp_session sftp){
SSH_LOG(SSH_LOG_PACKET, "Received SSH_FXP_INIT");
- buffer_get_u32(packet->payload, &version);
+ ssh_buffer_get_u32(packet->payload, &version);
version = ntohl(version);
SSH_LOG(SSH_LOG_PACKET, "Client version: %d", version);
sftp->client_version = version;
@@ -223,7 +223,7 @@ int sftp_server_init(sftp_session sftp){
return -1;
}
- if (buffer_add_u32(reply, ntohl(LIBSFTP_VERSION)) < 0) {
+ if (ssh_buffer_add_u32(reply, ntohl(LIBSFTP_VERSION)) < 0) {
ssh_set_error_oom(session);
ssh_buffer_free(reply);
return -1;
@@ -277,25 +277,25 @@ void sftp_free(sftp_session sftp){
int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
int size;
- if (buffer_prepend_data(payload, &type, sizeof(uint8_t)) < 0) {
+ if (ssh_buffer_prepend_data(payload, &type, sizeof(uint8_t)) < 0) {
ssh_set_error_oom(sftp->session);
return -1;
}
- size = htonl(buffer_get_rest_len(payload));
- if (buffer_prepend_data(payload, &size, sizeof(uint32_t)) < 0) {
+ size = htonl(ssh_buffer_get_rest_len(payload));
+ if (ssh_buffer_prepend_data(payload, &size, sizeof(uint32_t)) < 0) {
ssh_set_error_oom(sftp->session);
return -1;
}
- size = ssh_channel_write(sftp->channel, buffer_get_rest(payload),
- buffer_get_rest_len(payload));
+ size = ssh_channel_write(sftp->channel, ssh_buffer_get_rest(payload),
+ ssh_buffer_get_rest_len(payload));
if (size < 0) {
return -1;
- } else if((uint32_t) size != buffer_get_rest_len(payload)) {
+ } else if((uint32_t) size != ssh_buffer_get_rest_len(payload)) {
SSH_LOG(SSH_LOG_PACKET,
"Had to write %d bytes, wrote only %d",
- buffer_get_rest_len(payload),
+ ssh_buffer_get_rest_len(payload),
size);
}
@@ -335,7 +335,7 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
}
} while (r<4);
ssh_buffer_add_data(packet->payload, buffer, r);
- if (buffer_get_u32(packet->payload, &tmp) != sizeof(uint32_t)) {
+ if (ssh_buffer_get_u32(packet->payload, &tmp) != sizeof(uint32_t)) {
ssh_set_error(sftp->session, SSH_FATAL, "Short sftp packet!");
ssh_buffer_free(packet->payload);
SAFE_FREE(packet);
@@ -350,7 +350,7 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
return NULL;
}
ssh_buffer_add_data(packet->payload, buffer, r);
- buffer_get_u8(packet->payload, &packet->type);
+ ssh_buffer_get_u8(packet->payload, &packet->type);
size = ntohl(tmp);
if (size == 0) {
@@ -460,8 +460,8 @@ static sftp_message sftp_get_message(sftp_packet packet) {
msg->id,
msg->packet_type);
- if (ssh_buffer_add_data(msg->payload, buffer_get_rest(packet->payload),
- buffer_get_rest_len(packet->payload)) < 0) {
+ if (ssh_buffer_add_data(msg->payload, ssh_buffer_get_rest(packet->payload),
+ ssh_buffer_get_rest_len(packet->payload)) < 0) {
ssh_set_error_oom(sftp->session);
sftp_message_free(msg);
return NULL;
@@ -832,7 +832,7 @@ static sftp_file parse_handle_msg(sftp_message msg){
}
ZERO_STRUCTP(file);
- file->handle = buffer_get_ssh_string(msg->payload);
+ file->handle = ssh_buffer_get_ssh_string(msg->payload);
if (file->handle == NULL) {
ssh_set_error(msg->sftp->session, SSH_FATAL,
"Invalid SSH_FXP_HANDLE message");
@@ -871,8 +871,8 @@ sftp_dir sftp_opendir(sftp_session sftp, const char *path){
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(payload, htonl(id)) < 0 ||
- buffer_add_ssh_string(payload, path_s) < 0) {
+ if (ssh_buffer_add_u32(payload, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(payload, path_s) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(payload);
ssh_string_free(path_s);
@@ -963,7 +963,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
/* This isn't really a loop, but it is like a try..catch.. */
do {
- if (buffer_get_u32(buf, &flags) != 4) {
+ if (ssh_buffer_get_u32(buf, &flags) != 4) {
break;
}
@@ -971,14 +971,14 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
attr->flags = flags;
if (flags & SSH_FILEXFER_ATTR_SIZE) {
- if (buffer_get_u64(buf, &attr->size) != 8) {
+ if (ssh_buffer_get_u64(buf, &attr->size) != 8) {
break;
}
attr->size = ntohll(attr->size);
}
if (flags & SSH_FILEXFER_ATTR_OWNERGROUP) {
- owner = buffer_get_ssh_string(buf);
+ owner = ssh_buffer_get_ssh_string(buf);
if (owner == NULL) {
break;
}
@@ -988,7 +988,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
break;
}
- group = buffer_get_ssh_string(buf);
+ group = ssh_buffer_get_ssh_string(buf);
if (group == NULL) {
break;
}
@@ -1000,7 +1000,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
}
if (flags & SSH_FILEXFER_ATTR_PERMISSIONS) {
- if (buffer_get_u32(buf, &attr->permissions) != 4) {
+ if (ssh_buffer_get_u32(buf, &attr->permissions) != 4) {
break;
}
attr->permissions = ntohl(attr->permissions);
@@ -1029,62 +1029,62 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
}
if (flags & SSH_FILEXFER_ATTR_ACCESSTIME) {
- if (buffer_get_u64(buf, &attr->atime64) != 8) {
+ if (ssh_buffer_get_u64(buf, &attr->atime64) != 8) {
break;
}
attr->atime64 = ntohll(attr->atime64);
}
if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
- if (buffer_get_u32(buf, &attr->atime_nseconds) != 4) {
+ if (ssh_buffer_get_u32(buf, &attr->atime_nseconds) != 4) {
break;
}
attr->atime_nseconds = ntohl(attr->atime_nseconds);
}
if (flags & SSH_FILEXFER_ATTR_CREATETIME) {
- if (buffer_get_u64(buf, &attr->createtime) != 8) {
+ if (ssh_buffer_get_u64(buf, &attr->createtime) != 8) {
break;
}
attr->createtime = ntohll(attr->createtime);
}
if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
- if (buffer_get_u32(buf, &attr->createtime_nseconds) != 4) {
+ if (ssh_buffer_get_u32(buf, &attr->createtime_nseconds) != 4) {
break;
}
attr->createtime_nseconds = ntohl(attr->createtime_nseconds);
}
if (flags & SSH_FILEXFER_ATTR_MODIFYTIME) {
- if (buffer_get_u64(buf, &attr->mtime64) != 8) {
+ if (ssh_buffer_get_u64(buf, &attr->mtime64) != 8) {
break;
}
attr->mtime64 = ntohll(attr->mtime64);
}
if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
- if (buffer_get_u32(buf, &attr->mtime_nseconds) != 4) {
+ if (ssh_buffer_get_u32(buf, &attr->mtime_nseconds) != 4) {
break;
}
attr->mtime_nseconds = ntohl(attr->mtime_nseconds);
}
if (flags & SSH_FILEXFER_ATTR_ACL) {
- if ((attr->acl = buffer_get_ssh_string(buf)) == NULL) {
+ if ((attr->acl = ssh_buffer_get_ssh_string(buf)) == NULL) {
break;
}
}
if (flags & SSH_FILEXFER_ATTR_EXTENDED) {
- if (buffer_get_u32(buf,&attr->extended_count) != 4) {
+ if (ssh_buffer_get_u32(buf,&attr->extended_count) != 4) {
break;
}
attr->extended_count = ntohl(attr->extended_count);
while(attr->extended_count &&
- (attr->extended_type = buffer_get_ssh_string(buf)) &&
- (attr->extended_data = buffer_get_ssh_string(buf))){
+ (attr->extended_type = ssh_buffer_get_ssh_string(buf)) &&
+ (attr->extended_data = ssh_buffer_get_ssh_string(buf))){
attr->extended_count--;
}
@@ -1403,8 +1403,8 @@ sftp_attributes sftp_readdir(sftp_session sftp, sftp_dir dir) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(payload, htonl(id)) < 0 ||
- buffer_add_ssh_string(payload, dir->handle) < 0) {
+ if (ssh_buffer_add_u32(payload, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(payload, dir->handle) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(payload);
return NULL;
@@ -1450,7 +1450,7 @@ sftp_attributes sftp_readdir(sftp_session sftp, sftp_dir dir) {
return NULL;
case SSH_FXP_NAME:
- buffer_get_u32(msg->payload, &dir->count);
+ ssh_buffer_get_u32(msg->payload, &dir->count);
dir->count = ntohl(dir->count);
dir->buffer = msg->payload;
msg->payload = NULL;
@@ -1527,8 +1527,8 @@ static int sftp_handle_close(sftp_session sftp, ssh_string handle) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, handle) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, handle) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
return -1;
@@ -1650,8 +1650,8 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
sftp_flags |= SSH_FXF_EXCL;
SSH_LOG(SSH_LOG_PACKET,"Opening file %s with sftp flags %x",file,sftp_flags);
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, filename) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, filename) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
ssh_string_free(filename);
@@ -1659,7 +1659,7 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
}
ssh_string_free(filename);
- if (buffer_add_u32(buffer, htonl(sftp_flags)) < 0 ||
+ if (ssh_buffer_add_u32(buffer, htonl(sftp_flags)) < 0 ||
buffer_add_attributes(buffer, &attr) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
@@ -1787,7 +1787,7 @@ ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
status_msg_free(status);
return -1;
case SSH_FXP_DATA:
- datastring = buffer_get_ssh_string(msg->payload);
+ datastring = ssh_buffer_get_ssh_string(msg->payload);
sftp_message_free(msg);
if (datastring == NULL) {
ssh_set_error(sftp->session, SSH_FATAL,
@@ -1908,7 +1908,7 @@ int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
status_msg_free(status);
return err;
case SSH_FXP_DATA:
- datastring = buffer_get_ssh_string(msg->payload);
+ datastring = ssh_buffer_get_ssh_string(msg->payload);
sftp_message_free(msg);
if (datastring == NULL) {
ssh_set_error(sftp->session, SSH_FATAL,
@@ -1968,7 +1968,7 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
ssh_buffer_free(buffer);
return -1;
}
- packetlen=buffer_get_rest_len(buffer);
+ packetlen=ssh_buffer_get_rest_len(buffer);
len = sftp_packet_write(file->sftp, SSH_FXP_WRITE, buffer);
ssh_buffer_free(buffer);
if (len < 0) {
@@ -2223,8 +2223,8 @@ int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode) {
attr.flags = SSH_FILEXFER_ATTR_PERMISSIONS;
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, path) < 0 ||
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, path) < 0 ||
buffer_add_attributes(buffer, &attr) < 0 ||
sftp_packet_write(sftp, SSH_FXP_MKDIR, buffer) < 0) {
ssh_buffer_free(buffer);
@@ -2317,7 +2317,7 @@ int sftp_rename(sftp_session sftp, const char *original, const char *newname) {
if (sftp->version >= 4){
/* POSIX rename atomically replaces newpath, we should do the same
* only available on >=v4 */
- buffer_add_u32(buffer, SSH_FXF_RENAME_OVERWRITE);
+ ssh_buffer_add_u32(buffer, SSH_FXF_RENAME_OVERWRITE);
}
if (sftp_packet_write(sftp, SSH_FXP_RENAME, buffer) < 0) {
@@ -2389,8 +2389,8 @@ int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, path) < 0 ||
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, path) < 0 ||
buffer_add_attributes(buffer, attr) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
@@ -2606,8 +2606,8 @@ char *sftp_readlink(sftp_session sftp, const char *path) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, path_s) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, path_s) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
ssh_string_free(path_s);
@@ -2630,9 +2630,9 @@ char *sftp_readlink(sftp_session sftp, const char *path) {
if (msg->packet_type == SSH_FXP_NAME) {
/* we don't care about "count" */
- buffer_get_u32(msg->payload, &ignored);
+ ssh_buffer_get_u32(msg->payload, &ignored);
/* we only care about the file name string */
- link_s = buffer_get_ssh_string(msg->payload);
+ link_s = ssh_buffer_get_ssh_string(msg->payload);
sftp_message_free(msg);
if (link_s == NULL) {
/* TODO: what error to set here? */
@@ -2734,9 +2734,9 @@ sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, ext) < 0 ||
- buffer_add_ssh_string(buffer, pathstr) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, ext) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
ssh_string_free(ext);
@@ -2813,9 +2813,9 @@ sftp_statvfs_t sftp_fstatvfs(sftp_file file) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, ext) < 0 ||
- buffer_add_ssh_string(buffer, file->handle) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, ext) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, file->handle) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
ssh_string_free(ext);
@@ -2902,8 +2902,8 @@ char *sftp_canonicalize_path(sftp_session sftp, const char *path) {
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, pathstr) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
ssh_string_free(pathstr);
@@ -2926,9 +2926,9 @@ char *sftp_canonicalize_path(sftp_session sftp, const char *path) {
if (msg->packet_type == SSH_FXP_NAME) {
/* we don't care about "count" */
- buffer_get_u32(msg->payload, &ignored);
+ ssh_buffer_get_u32(msg->payload, &ignored);
/* we only care about the file name string */
- name = buffer_get_ssh_string(msg->payload);
+ name = ssh_buffer_get_ssh_string(msg->payload);
sftp_message_free(msg);
if (name == NULL) {
/* TODO: error message? */
@@ -2980,8 +2980,8 @@ static sftp_attributes sftp_xstat(sftp_session sftp, const char *path,
}
id = sftp_get_new_id(sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, pathstr) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
ssh_set_error_oom(sftp->session);
ssh_buffer_free(buffer);
ssh_string_free(pathstr);
@@ -3047,8 +3047,8 @@ sftp_attributes sftp_fstat(sftp_file file) {
}
id = sftp_get_new_id(file->sftp);
- if (buffer_add_u32(buffer, htonl(id)) < 0 ||
- buffer_add_ssh_string(buffer, file->handle) < 0) {
+ if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+ ssh_buffer_add_ssh_string(buffer, file->handle) < 0) {
ssh_set_error_oom(file->sftp->session);
ssh_buffer_free(buffer);
return NULL;
diff --git a/src/sftpserver.c b/src/sftpserver.c
index 6049879..5939309 100644
--- a/src/sftpserver.c
+++ b/src/sftpserver.c
@@ -65,15 +65,15 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
/* take a copy of the whole packet */
msg->complete_message = ssh_buffer_new();
ssh_buffer_add_data(msg->complete_message,
- buffer_get_rest(payload),
- buffer_get_rest_len(payload));
+ ssh_buffer_get_rest(payload),
+ ssh_buffer_get_rest_len(payload));
- buffer_get_u32(payload, &msg->id);
+ ssh_buffer_get_u32(payload, &msg->id);
switch(msg->type) {
case SSH_FXP_CLOSE:
case SSH_FXP_READDIR:
- msg->handle = buffer_get_ssh_string(payload);
+ msg->handle = ssh_buffer_get_ssh_string(payload);
if (msg->handle == NULL) {
ssh_set_error_oom(session);
sftp_client_message_free(msg);
@@ -148,7 +148,7 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
}
break;
case SSH_FXP_FSETSTAT:
- msg->handle = buffer_get_ssh_string(payload);
+ msg->handle = ssh_buffer_get_ssh_string(payload);
if (msg->handle == NULL) {
ssh_set_error_oom(session);
sftp_client_message_free(msg);
@@ -274,10 +274,10 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
return -1;
}
- if (buffer_add_u32(out, msg->id) < 0 ||
- buffer_add_u32(out, htonl(1)) < 0 ||
- buffer_add_ssh_string(out, file) < 0 ||
- buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
+ if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+ ssh_buffer_add_u32(out, htonl(1)) < 0 ||
+ ssh_buffer_add_ssh_string(out, file) < 0 ||
+ ssh_buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
buffer_add_attributes(out, attr) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
ssh_buffer_free(out);
@@ -298,8 +298,8 @@ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
return -1;
}
- if (buffer_add_u32(out, msg->id) < 0 ||
- buffer_add_ssh_string(out, handle) < 0 ||
+ if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+ ssh_buffer_add_ssh_string(out, handle) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_HANDLE, out) < 0) {
ssh_buffer_free(out);
return -1;
@@ -317,7 +317,7 @@ int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
return -1;
}
- if (buffer_add_u32(out, msg->id) < 0 ||
+ if (ssh_buffer_add_u32(out, msg->id) < 0 ||
buffer_add_attributes(out, attr) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_ATTRS, out) < 0) {
ssh_buffer_free(out);
@@ -345,7 +345,7 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
}
}
- if (buffer_add_ssh_string(msg->attrbuf, name) < 0) {
+ if (ssh_buffer_add_ssh_string(msg->attrbuf, name) < 0) {
ssh_string_free(name);
return -1;
}
@@ -355,7 +355,7 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
if (name == NULL) {
return -1;
}
- if (buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
+ if (ssh_buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
buffer_add_attributes(msg->attrbuf,attr) < 0) {
ssh_string_free(name);
return -1;
@@ -375,10 +375,10 @@ int sftp_reply_names(sftp_client_message msg) {
return -1;
}
- if (buffer_add_u32(out, msg->id) < 0 ||
- buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
- ssh_buffer_add_data(out, buffer_get_rest(msg->attrbuf),
- buffer_get_rest_len(msg->attrbuf)) < 0 ||
+ if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+ ssh_buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
+ ssh_buffer_add_data(out, ssh_buffer_get_rest(msg->attrbuf),
+ ssh_buffer_get_rest_len(msg->attrbuf)) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
ssh_buffer_free(out);
ssh_buffer_free(msg->attrbuf);
@@ -410,10 +410,10 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
return -1;
}
- if (buffer_add_u32(out, msg->id) < 0 ||
- buffer_add_u32(out, htonl(status)) < 0 ||
- buffer_add_ssh_string(out, s) < 0 ||
- buffer_add_u32(out, 0) < 0 || /* language string */
+ if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+ ssh_buffer_add_u32(out, htonl(status)) < 0 ||
+ ssh_buffer_add_ssh_string(out, s) < 0 ||
+ ssh_buffer_add_u32(out, 0) < 0 || /* language string */
sftp_packet_write(msg->sftp, SSH_FXP_STATUS, out) < 0) {
ssh_buffer_free(out);
ssh_string_free(s);
@@ -434,8 +434,8 @@ int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
return -1;
}
- if (buffer_add_u32(out, msg->id) < 0 ||
- buffer_add_u32(out, ntohl(len)) < 0 ||
+ if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+ ssh_buffer_add_u32(out, ntohl(len)) < 0 ||
ssh_buffer_add_data(out, data, len) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_DATA, out) < 0) {
ssh_buffer_free(out);
diff --git a/src/socket.c b/src/socket.c
index 022c9a7..ba5128a 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -290,10 +290,10 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
}
if (s->callbacks && s->callbacks->data) {
do {
- r = s->callbacks->data(buffer_get_rest(s->in_buffer),
- buffer_get_rest_len(s->in_buffer),
+ r = s->callbacks->data(ssh_buffer_get_rest(s->in_buffer),
+ ssh_buffer_get_rest_len(s->in_buffer),
s->callbacks->userdata);
- buffer_pass_bytes(s->in_buffer, r);
+ ssh_buffer_pass_bytes(s->in_buffer, r);
} while ((r > 0) && (s->state == SSH_SOCKET_CONNECTED));
/* p may have been freed, so don't use it
* anymore in this function */
@@ -330,7 +330,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
}
/* If buffered data is pending, write it */
- if (buffer_get_rest_len(s->out_buffer) > 0) {
+ if (ssh_buffer_get_rest_len(s->out_buffer) > 0) {
ssh_socket_nonblocking_flush(s);
} else if (s->callbacks && s->callbacks->controlflow) {
/* Otherwise advertise the upper level that write can be done */
@@ -650,7 +650,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
return SSH_ERROR;
}
- len = buffer_get_rest_len(s->out_buffer);
+ len = ssh_buffer_get_rest_len(s->out_buffer);
if (!s->write_wontblock && s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
@@ -658,7 +658,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
return SSH_AGAIN;
}
if (s->write_wontblock && len > 0) {
- w = ssh_socket_unbuffered_write(s, buffer_get_rest(s->out_buffer), len);
+ w = ssh_socket_unbuffered_write(s, ssh_buffer_get_rest(s->out_buffer), len);
if (w < 0) {
session->alive = 0;
ssh_socket_close(s);
@@ -674,14 +674,14 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
}
return SSH_ERROR;
}
- buffer_pass_bytes(s->out_buffer, w);
+ ssh_buffer_pass_bytes(s->out_buffer, w);
if (s->session->socket_counter != NULL) {
s->session->socket_counter->out_bytes += w;
}
}
/* Is there some data pending? */
- len = buffer_get_rest_len(s->out_buffer);
+ len = ssh_buffer_get_rest_len(s->out_buffer);
if (s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
@@ -721,7 +721,7 @@ int ssh_socket_data_writable(ssh_socket s) {
int ssh_socket_buffered_write_bytes(ssh_socket s){
if(s==NULL || s->out_buffer == NULL)
return 0;
- return buffer_get_rest_len(s->out_buffer);
+ return ssh_buffer_get_rest_len(s->out_buffer);
}
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c
index 390572c..03dfcf9 100644
--- a/tests/unittests/torture_buffer.c
+++ b/tests/unittests/torture_buffer.c
@@ -36,8 +36,8 @@ static void torture_growing_buffer(void **state) {
for(i=0;i<LIMIT;++i){
ssh_buffer_add_data(buffer,"A",1);
if(buffer->used >= 128){
- if(buffer_get_rest_len(buffer) * 2 < buffer->allocated){
- assert_true(buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
+ if(ssh_buffer_get_rest_len(buffer) * 2 < buffer->allocated){
+ assert_true(ssh_buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
}
}
}
@@ -55,11 +55,11 @@ static void torture_growing_buffer_shifting(void **state) {
ssh_buffer_add_data(buffer,"S",1);
}
for(i=0;i<LIMIT;++i){
- buffer_get_u8(buffer,&c);
+ ssh_buffer_get_u8(buffer,&c);
ssh_buffer_add_data(buffer,"A",1);
if(buffer->used >= 128){
- if(buffer_get_rest_len(buffer) * 4 < buffer->allocated){
- assert_true(buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
+ if(ssh_buffer_get_rest_len(buffer) * 4 < buffer->allocated){
+ assert_true(ssh_buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
return;
}
}
@@ -67,39 +67,39 @@ static void torture_growing_buffer_shifting(void **state) {
}
/*
- * Test the behavior of buffer_prepend_data
+ * Test the behavior of ssh_buffer_prepend_data
*/
static void torture_buffer_prepend(void **state) {
ssh_buffer buffer = *state;
uint32_t v;
ssh_buffer_add_data(buffer,"abcdef",6);
- buffer_prepend_data(buffer,"xyz",3);
- assert_int_equal(buffer_get_rest_len(buffer),9);
- assert_memory_equal(buffer_get_rest(buffer), "xyzabcdef", 9);
+ ssh_buffer_prepend_data(buffer,"xyz",3);
+ assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
+ assert_memory_equal(ssh_buffer_get_rest(buffer), "xyzabcdef", 9);
/* Now remove 4 bytes and see if we can replace them */
- buffer_get_u32(buffer,&v);
- assert_int_equal(buffer_get_rest_len(buffer),5);
- assert_memory_equal(buffer_get_rest(buffer), "bcdef", 5);
+ ssh_buffer_get_u32(buffer,&v);
+ assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
+ assert_memory_equal(ssh_buffer_get_rest(buffer), "bcdef", 5);
- buffer_prepend_data(buffer,"aris",4);
- assert_int_equal(buffer_get_rest_len(buffer),9);
- assert_memory_equal(buffer_get_rest(buffer), "arisbcdef", 9);
+ ssh_buffer_prepend_data(buffer,"aris",4);
+ assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
+ assert_memory_equal(ssh_buffer_get_rest(buffer), "arisbcdef", 9);
/* same thing but we add 5 bytes now */
- buffer_get_u32(buffer,&v);
- assert_int_equal(buffer_get_rest_len(buffer),5);
- assert_memory_equal(buffer_get_rest(buffer), "bcdef", 5);
+ ssh_buffer_get_u32(buffer,&v);
+ assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
+ assert_memory_equal(ssh_buffer_get_rest(buffer), "bcdef", 5);
- buffer_prepend_data(buffer,"12345",5);
- assert_int_equal(buffer_get_rest_len(buffer),10);
- assert_memory_equal(buffer_get_rest(buffer), "12345bcdef", 10);
+ ssh_buffer_prepend_data(buffer,"12345",5);
+ assert_int_equal(ssh_buffer_get_rest_len(buffer),10);
+ assert_memory_equal(ssh_buffer_get_rest(buffer), "12345bcdef", 10);
}
/*
- * Test the behavior of buffer_get_ssh_string with invalid data
+ * Test the behavior of ssh_buffer_get_ssh_string with invalid data
*/
-static void torture_buffer_get_ssh_string(void **state) {
+static void torture_ssh_buffer_get_ssh_string(void **state) {
ssh_buffer buffer;
int i,j,k,l, rc;
/* some values that can go wrong */
@@ -115,13 +115,13 @@ static void torture_buffer_get_ssh_string(void **state) {
assert_non_null(buffer);
for(l=0;l<k;++l){
- rc = buffer_add_u32(buffer,htonl(values[i]));
+ rc = ssh_buffer_add_u32(buffer,htonl(values[i]));
assert_int_equal(rc, 0);
}
rc = ssh_buffer_add_data(buffer,data,j);
assert_int_equal(rc, 0);
for(l=0;l<k;++l){
- ssh_string str = buffer_get_ssh_string(buffer);
+ ssh_string str = ssh_buffer_get_ssh_string(buffer);
assert_null(str);
ssh_string_free(str);
}
@@ -131,7 +131,7 @@ static void torture_buffer_get_ssh_string(void **state) {
}
}
-static void torture_buffer_add_format(void **state) {
+static void torture_ssh_buffer_add_format(void **state) {
ssh_buffer buffer=*state;
uint8_t b;
uint16_t w;
@@ -155,14 +155,14 @@ static void torture_buffer_add_format(void **state) {
rc=ssh_buffer_pack(buffer, "bwdqSsPt",b,w,d,q,s,"rocks",7,"So much","Fun!");
assert_int_equal(rc, SSH_OK);
- len = buffer_get_rest_len(buffer);
+ len = ssh_buffer_get_rest_len(buffer);
assert_int_equal(len, sizeof(verif) - 1);
- assert_memory_equal(buffer_get_rest(buffer), verif, sizeof(verif) -1);
+ assert_memory_equal(ssh_buffer_get_rest(buffer), verif, sizeof(verif) -1);
ssh_string_free(s);
}
-static void torture_buffer_get_format(void **state) {
+static void torture_ssh_buffer_get_format(void **state) {
ssh_buffer buffer=*state;
uint8_t b=0;
uint16_t w=0;
@@ -199,14 +199,14 @@ static void torture_buffer_get_format(void **state) {
assert_true(s2 != NULL);
assert_memory_equal(s2, "So much", 7);
- len = buffer_get_rest_len(buffer);
+ len = ssh_buffer_get_rest_len(buffer);
assert_int_equal(len, 0);
SAFE_FREE(s);
SAFE_FREE(s1);
SAFE_FREE(s2);
}
-static void torture_buffer_get_format_error(void **state) {
+static void torture_ssh_buffer_get_format_error(void **state) {
ssh_buffer buffer=*state;
uint8_t b=0;
uint16_t w=0;
@@ -262,10 +262,10 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_growing_buffer, setup, teardown),
cmocka_unit_test_setup_teardown(torture_growing_buffer_shifting, setup, teardown),
cmocka_unit_test_setup_teardown(torture_buffer_prepend, setup, teardown),
- cmocka_unit_test(torture_buffer_get_ssh_string),
- cmocka_unit_test_setup_teardown(torture_buffer_add_format, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_buffer_get_format, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_buffer_get_format_error, setup, teardown),
+ cmocka_unit_test(torture_ssh_buffer_get_ssh_string),
+ cmocka_unit_test_setup_teardown(torture_ssh_buffer_add_format, setup, teardown),
+ cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format, setup, teardown),
+ cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format_error, setup, teardown),
cmocka_unit_test_setup_teardown(torture_buffer_pack_badformat, setup, teardown)
};
--
2.4.3
From d85437429ec73644111017a93546acb5e94e4c79 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 10:09:06 +0200
Subject: [PATCH 05/24 v2] cleanup: use ssh_ prefix in the channels (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/channels.h | 12 ++++++------
src/channels.c | 12 ++++++------
src/channels1.c | 12 ++++++------
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/include/libssh/channels.h b/include/libssh/channels.h
index b05c4c0..44258ba 100644
--- a/include/libssh/channels.h
+++ b/include/libssh/channels.h
@@ -105,13 +105,13 @@ SSH_PACKET_CALLBACK(ssh_packet_close1);
SSH_PACKET_CALLBACK(ssh_packet_exist_status1);
/* channels1.c */
-int channel_open_session1(ssh_channel channel);
-int channel_request_pty_size1(ssh_channel channel, const char *terminal,
+int ssh_channel_open_session1(ssh_channel channel);
+int ssh_channel_request_pty_size1(ssh_channel channel, const char *terminal,
int cols, int rows);
-int channel_change_pty_size1(ssh_channel channel, int cols, int rows);
-int channel_request_shell1(ssh_channel channel);
-int channel_request_exec1(ssh_channel channel, const char *cmd);
-int channel_write1(ssh_channel channel, const void *data, int len);
+int ssh_channel_change_pty_size1(ssh_channel channel, int cols, int rows);
+int ssh_channel_request_shell1(ssh_channel channel);
+int ssh_channel_request_exec1(ssh_channel channel, const char *cmd);
+int ssh_channel_write1(ssh_channel channel, const void *data, int len);
ssh_channel ssh_get_channel1(ssh_session session);
#endif
diff --git a/src/channels.c b/src/channels.c
index 84e9608..6082320 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -864,7 +864,7 @@ int ssh_channel_open_session(ssh_channel channel) {
#ifdef WITH_SSH1
if (channel->session->version == 1) {
- return channel_open_session1(channel);
+ return ssh_channel_open_session1(channel);
}
#endif
@@ -1250,7 +1250,7 @@ static int channel_write_common(ssh_channel channel,
}
#ifdef WITH_SSH1
if (channel->version == 1) {
- rc = channel_write1(channel, data, len);
+ rc = ssh_channel_write1(channel, data, len);
return rc;
}
@@ -1633,7 +1633,7 @@ int ssh_channel_request_pty_size(ssh_channel channel, const char *terminal,
#ifdef WITH_SSH1
if (channel->version==1) {
- rc = channel_request_pty_size1(channel,terminal, col, row);
+ rc = ssh_channel_request_pty_size1(channel,terminal, col, row);
return rc;
}
@@ -1711,7 +1711,7 @@ int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows) {
#ifdef WITH_SSH1
if (channel->version == 1) {
- rc = channel_change_pty_size1(channel,cols,rows);
+ rc = ssh_channel_change_pty_size1(channel,cols,rows);
return rc;
}
@@ -1757,7 +1757,7 @@ int ssh_channel_request_shell(ssh_channel channel) {
}
#ifdef WITH_SSH1
if (channel->version == 1) {
- return channel_request_shell1(channel);
+ return ssh_channel_request_shell1(channel);
}
#endif
return channel_request(channel, "shell", NULL, 1);
@@ -2398,7 +2398,7 @@ int ssh_channel_request_exec(ssh_channel channel, const char *cmd) {
#ifdef WITH_SSH1
if (channel->version == 1) {
- return channel_request_exec1(channel, cmd);
+ return ssh_channel_request_exec1(channel, cmd);
}
#endif
switch(channel->request_state){
diff --git a/src/channels1.c b/src/channels1.c
index c3e7b92..730649a 100644
--- a/src/channels1.c
+++ b/src/channels1.c
@@ -51,7 +51,7 @@
* protocol.
*/
-int channel_open_session1(ssh_channel chan) {
+int ssh_channel_open_session1(ssh_channel chan) {
ssh_session session;
if (chan == NULL) {
@@ -91,7 +91,7 @@ int channel_open_session1(ssh_channel chan) {
* much simplier under ssh2. I just hope the defaults values are ok ...
*/
-int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col,
+int ssh_channel_request_pty_size1(ssh_channel channel, const char *terminal, int col,
int row) {
ssh_session session;
ssh_string str = NULL;
@@ -158,7 +158,7 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
return SSH_ERROR;
}
-int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
+int ssh_channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
ssh_session session;
if (channel == NULL) {
@@ -207,7 +207,7 @@ int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
}
-int channel_request_shell1(ssh_channel channel) {
+int ssh_channel_request_shell1(ssh_channel channel) {
ssh_session session;
if (channel == NULL) {
@@ -228,7 +228,7 @@ int channel_request_shell1(ssh_channel channel) {
return 0;
}
-int channel_request_exec1(ssh_channel channel, const char *cmd) {
+int ssh_channel_request_exec1(ssh_channel channel, const char *cmd) {
ssh_session session;
ssh_string command = NULL;
@@ -338,7 +338,7 @@ SSH_PACKET_CALLBACK(ssh_packet_exist_status1){
}
-int channel_write1(ssh_channel channel, const void *data, int len) {
+int ssh_channel_write1(ssh_channel channel, const void *data, int len) {
ssh_session session;
int origlen = len;
int effectivelen;
--
2.4.3
From 176acf0cd71ce484f704ea9ca3405b4b26760168 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 10:26:05 +0200
Subject: [PATCH 06/24 v2] cleanup: use ssh_ prefix in the dh (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/dh.h | 28 ++++++++++++++--------------
src/dh.c | 40 ++++++++++++++++++++--------------------
src/kex.c | 6 +++---
src/packet_cb.c | 6 +++---
src/server.c | 16 ++++++++--------
5 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/include/libssh/dh.h b/include/libssh/dh.h
index 95b76cd..8e0d5aa 100644
--- a/include/libssh/dh.h
+++ b/include/libssh/dh.h
@@ -25,27 +25,27 @@
#include "libssh/crypto.h"
-int dh_generate_e(ssh_session session);
-int dh_generate_f(ssh_session session);
-int dh_generate_x(ssh_session session);
-int dh_generate_y(ssh_session session);
+int ssh_dh_generate_e(ssh_session session);
+int ssh_dh_generate_f(ssh_session session);
+int ssh_dh_generate_x(ssh_session session);
+int ssh_dh_generate_y(ssh_session session);
int ssh_crypto_init(void);
void ssh_crypto_finalize(void);
-ssh_string dh_get_e(ssh_session session);
-ssh_string dh_get_f(ssh_session session);
-int dh_import_f(ssh_session session,ssh_string f_string);
-int dh_import_e(ssh_session session, ssh_string e_string);
-void dh_import_pubkey(ssh_session session,ssh_string pubkey_string);
-int dh_build_k(ssh_session session);
+ssh_string ssh_dh_get_e(ssh_session session);
+ssh_string ssh_dh_get_f(ssh_session session);
+int ssh_dh_import_f(ssh_session session,ssh_string f_string);
+int ssh_dh_import_e(ssh_session session, ssh_string e_string);
+void ssh_dh_import_pubkey(ssh_session session,ssh_string pubkey_string);
+int ssh_dh_build_k(ssh_session session);
int ssh_client_dh_init(ssh_session session);
int ssh_client_dh_reply(ssh_session session, ssh_buffer packet);
-int make_sessionid(ssh_session session);
+int ssh_make_sessionid(ssh_session session);
/* add data for the final cookie */
-int hashbufin_add_cookie(ssh_session session, unsigned char *cookie);
-int hashbufout_add_cookie(ssh_session session);
-int generate_session_keys(ssh_session session);
+int ssh_hashbufin_add_cookie(ssh_session session, unsigned char *cookie);
+int ssh_hashbufout_add_cookie(ssh_session session);
+int ssh_generate_session_keys(ssh_session session);
#endif /* DH_H_ */
diff --git a/src/dh.c b/src/dh.c
index 1d2367b..485a280 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -226,7 +226,7 @@ void ssh_crypto_finalize(void) {
}
}
-int dh_generate_x(ssh_session session) {
+int ssh_dh_generate_x(ssh_session session) {
session->next_crypto->x = bignum_new();
if (session->next_crypto->x == NULL) {
return -1;
@@ -247,7 +247,7 @@ int dh_generate_x(ssh_session session) {
}
/* used by server */
-int dh_generate_y(ssh_session session) {
+int ssh_dh_generate_y(ssh_session session) {
session->next_crypto->y = bignum_new();
if (session->next_crypto->y == NULL) {
return -1;
@@ -268,7 +268,7 @@ int dh_generate_y(ssh_session session) {
}
/* used by server */
-int dh_generate_e(ssh_session session) {
+int ssh_dh_generate_e(ssh_session session) {
#ifdef HAVE_LIBCRYPTO
bignum_CTX ctx = bignum_ctx_new();
if (ctx == NULL) {
@@ -303,7 +303,7 @@ int dh_generate_e(ssh_session session) {
return 0;
}
-int dh_generate_f(ssh_session session) {
+int ssh_dh_generate_f(ssh_session session) {
#ifdef HAVE_LIBCRYPTO
bignum_CTX ctx = bignum_ctx_new();
if (ctx == NULL) {
@@ -338,20 +338,20 @@ int dh_generate_f(ssh_session session) {
return 0;
}
-ssh_string dh_get_e(ssh_session session) {
+ssh_string ssh_dh_get_e(ssh_session session) {
return ssh_make_bignum_string(session->next_crypto->e);
}
/* used by server */
-ssh_string dh_get_f(ssh_session session) {
+ssh_string ssh_dh_get_f(ssh_session session) {
return ssh_make_bignum_string(session->next_crypto->f);
}
-void dh_import_pubkey(ssh_session session, ssh_string pubkey_string) {
+void ssh_dh_import_pubkey(ssh_session session, ssh_string pubkey_string) {
session->next_crypto->server_pubkey = pubkey_string;
}
-int dh_import_f(ssh_session session, ssh_string f_string) {
+int ssh_dh_import_f(ssh_session session, ssh_string f_string) {
session->next_crypto->f = ssh_make_string_bn(f_string);
if (session->next_crypto->f == NULL) {
return -1;
@@ -365,7 +365,7 @@ int dh_import_f(ssh_session session, ssh_string f_string) {
}
/* used by the server implementation */
-int dh_import_e(ssh_session session, ssh_string e_string) {
+int ssh_dh_import_e(ssh_session session, ssh_string e_string) {
session->next_crypto->e = ssh_make_string_bn(e_string);
if (session->next_crypto->e == NULL) {
return -1;
@@ -378,7 +378,7 @@ int dh_import_e(ssh_session session, ssh_string e_string) {
return 0;
}
-int dh_build_k(ssh_session session) {
+int ssh_dh_build_k(ssh_session session) {
#ifdef HAVE_LIBCRYPTO
bignum_CTX ctx = bignum_ctx_new();
if (ctx == NULL) {
@@ -435,14 +435,14 @@ int ssh_client_dh_init(ssh_session session){
ssh_string e = NULL;
int rc;
- if (dh_generate_x(session) < 0) {
+ if (ssh_dh_generate_x(session) < 0) {
goto error;
}
- if (dh_generate_e(session) < 0) {
+ if (ssh_dh_generate_e(session) < 0) {
goto error;
}
- e = dh_get_e(session);
+ e = ssh_dh_get_e(session);
if (e == NULL) {
goto error;
}
@@ -477,14 +477,14 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
ssh_set_error(session,SSH_FATAL, "No public key in packet");
goto error;
}
- dh_import_pubkey(session, pubkey);
+ ssh_dh_import_pubkey(session, pubkey);
f = ssh_buffer_get_ssh_string(packet);
if (f == NULL) {
ssh_set_error(session,SSH_FATAL, "No F number in packet");
goto error;
}
- rc = dh_import_f(session, f);
+ rc = ssh_dh_import_f(session, f);
ssh_string_burn(f);
ssh_string_free(f);
if (rc < 0) {
@@ -499,7 +499,7 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
}
session->next_crypto->dh_server_signature = signature;
signature=NULL; /* ownership changed */
- if (dh_build_k(session) < 0) {
+ if (ssh_dh_build_k(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Cannot build k number");
goto error;
}
@@ -516,7 +516,7 @@ error:
return SSH_ERROR;
}
-int make_sessionid(ssh_session session) {
+int ssh_make_sessionid(ssh_session session) {
ssh_string num = NULL;
ssh_buffer server_hash = NULL;
ssh_buffer client_hash = NULL;
@@ -692,7 +692,7 @@ error:
return rc;
}
-int hashbufout_add_cookie(ssh_session session) {
+int ssh_hashbufout_add_cookie(ssh_session session) {
session->out_hashbuf = ssh_buffer_new();
if (session->out_hashbuf == NULL) {
return -1;
@@ -720,7 +720,7 @@ int hashbufout_add_cookie(ssh_session session) {
return 0;
}
-int hashbufin_add_cookie(ssh_session session, unsigned char *cookie) {
+int ssh_hashbufin_add_cookie(ssh_session session, unsigned char *cookie) {
session->in_hashbuf = ssh_buffer_new();
if (session->in_hashbuf == NULL) {
return -1;
@@ -777,7 +777,7 @@ static int generate_one_key(ssh_string k,
return 0;
}
-int generate_session_keys(ssh_session session) {
+int ssh_generate_session_keys(ssh_session session) {
ssh_string k_string = NULL;
struct ssh_crypto_struct *crypto = session->next_crypto;
int rc = -1;
diff --git a/src/kex.c b/src/kex.c
index 02965bd..497c67a 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -352,7 +352,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
goto error;
}
- rc = hashbufin_add_cookie(session, session->next_crypto->client_kex.cookie);
+ rc = ssh_hashbufin_add_cookie(session, session->next_crypto->client_kex.cookie);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: adding cookie failed");
goto error;
@@ -364,7 +364,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
goto error;
}
- rc = hashbufin_add_cookie(session, session->next_crypto->server_kex.cookie);
+ rc = ssh_hashbufin_add_cookie(session, session->next_crypto->server_kex.cookie);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: adding cookie failed");
goto error;
@@ -612,7 +612,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
kex->cookie); /* cookie */
if (rc != SSH_OK)
goto error;
- if (hashbufout_add_cookie(session) < 0) {
+ if (ssh_hashbufout_add_cookie(session) < 0) {
goto error;
}
diff --git a/src/packet_cb.c b/src/packet_cb.c
index 8353b46..5cc538c 100644
--- a/src/packet_cb.c
+++ b/src/packet_cb.c
@@ -154,20 +154,20 @@ SSH_PACKET_CALLBACK(ssh_packet_newkeys){
} else {
ssh_key key;
/* client */
- rc = make_sessionid(session);
+ rc = ssh_make_sessionid(session);
if (rc != SSH_OK) {
goto error;
}
/*
* Set the cryptographic functions for the next crypto
- * (it is needed for generate_session_keys for key lengths)
+ * (it is needed for ssh_generate_session_keys for key lengths)
*/
if (crypt_set_algorithms(session, SSH_3DES) /* knows nothing about DES*/ ) {
goto error;
}
- if (generate_session_keys(session) < 0) {
+ if (ssh_generate_session_keys(session) < 0) {
goto error;
}
diff --git a/src/server.c b/src/server.c
index 6679245..c86df1b 100644
--- a/src/server.c
+++ b/src/server.c
@@ -160,7 +160,7 @@ static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){
ssh_set_error(session, SSH_FATAL, "No e number in client request");
return -1;
}
- if (dh_import_e(session, e) < 0) {
+ if (ssh_dh_import_e(session, e) < 0) {
ssh_set_error(session, SSH_FATAL, "Cannot import e number");
session->session_state=SSH_SESSION_STATE_ERROR;
} else {
@@ -258,7 +258,7 @@ int ssh_get_key_params(ssh_session session, ssh_key *privkey){
return -1;
}
- dh_import_pubkey(session, pubkey_blob);
+ ssh_dh_import_pubkey(session, pubkey_blob);
return SSH_OK;
}
@@ -268,16 +268,16 @@ static int dh_handshake_server(ssh_session session) {
ssh_string f;
int rc;
- if (dh_generate_y(session) < 0) {
+ if (ssh_dh_generate_y(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Could not create y number");
return -1;
}
- if (dh_generate_f(session) < 0) {
+ if (ssh_dh_generate_f(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Could not create f number");
return -1;
}
- f = dh_get_f(session);
+ f = ssh_dh_get_f(session);
if (f == NULL) {
ssh_set_error(session, SSH_FATAL, "Could not get the f number");
return -1;
@@ -288,13 +288,13 @@ static int dh_handshake_server(ssh_session session) {
return -1;
}
- if (dh_build_k(session) < 0) {
+ if (ssh_dh_build_k(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Could not import the public key");
ssh_string_free(f);
return -1;
}
- if (make_sessionid(session) != SSH_OK) {
+ if (ssh_make_sessionid(session) != SSH_OK) {
ssh_set_error(session, SSH_FATAL, "Could not create a session id");
ssh_string_free(f);
return -1;
@@ -432,7 +432,7 @@ static void ssh_server_connection_callback(ssh_session session){
break;
case SSH_SESSION_STATE_DH:
if(session->dh_handshake_state==DH_STATE_FINISHED){
- if (generate_session_keys(session) < 0) {
+ if (ssh_generate_session_keys(session) < 0) {
goto error;
}
--
2.4.3
From b22222960cc115b275af7d21a1852c7aac546058 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 13:32:44 +0200
Subject: [PATCH 07/24 v2] cleanup: use ssh_ prefix in the kex (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/kex.h | 6 +++---
src/client.c | 2 +-
src/kex.c | 8 ++++----
src/known_hosts.c | 2 +-
src/options.c | 2 +-
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/libssh/kex.h b/include/libssh/kex.h
index 1a5b6d4..e872bde 100644
--- a/include/libssh/kex.h
+++ b/include/libssh/kex.h
@@ -38,10 +38,10 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1);
int ssh_send_kex(ssh_session session, int server_kex);
void ssh_list_kex(struct ssh_kex_struct *kex);
-int set_client_kex(ssh_session session);
+int ssh_set_client_kex(ssh_session session);
int ssh_kex_select_methods(ssh_session session);
-int verify_existing_algo(int algo, const char *name);
-char **space_tokenize(const char *chain);
+int ssh_verify_existing_algo(int algo, const char *name);
+char **ssh_space_tokenize(const char *chain);
int ssh_get_kex1(ssh_session session);
char *ssh_find_matching(const char *in_d, const char *what_d);
const char *ssh_kex_get_supported_method(uint32_t algo);
diff --git a/src/client.c b/src/client.c
index 64ce5de..0c2b7e4 100644
--- a/src/client.c
+++ b/src/client.c
@@ -399,7 +399,7 @@ static void ssh_client_connection_callback(ssh_session session){
case SSH_SESSION_STATE_KEXINIT_RECEIVED:
set_status(session,0.6f);
ssh_list_kex(&session->next_crypto->server_kex);
- if (set_client_kex(session) < 0) {
+ if (ssh_set_client_kex(session) < 0) {
goto error;
}
if (ssh_kex_select_methods(session) == SSH_ERROR)
diff --git a/src/kex.c b/src/kex.c
index 497c67a..55b8318 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -172,7 +172,7 @@ static char **tokenize(const char *chain){
/* same as tokenize(), but with spaces instead of ',' */
/* TODO FIXME rewrite me! */
-char **space_tokenize(const char *chain){
+char **ssh_space_tokenize(const char *chain){
char **tokens;
int n=1;
int i=0;
@@ -512,7 +512,7 @@ static char *ssh_client_select_hostkeys(ssh_session session){
for (i=0;preferred_hostkeys[i] != NULL; ++i){
for (j=0; methods[j] != NULL; ++j){
if(strcmp(preferred_hostkeys[i], methods[j]) == 0){
- if (verify_existing_algo(SSH_HOSTKEYS, methods[j])){
+ if (ssh_verify_existing_algo(SSH_HOSTKEYS, methods[j])){
if(needcoma)
strncat(methods_buffer,",",sizeof(methods_buffer)-strlen(methods_buffer)-1);
strncat(methods_buffer, methods[j], sizeof(methods_buffer)-strlen(methods_buffer)-1);
@@ -539,7 +539,7 @@ static char *ssh_client_select_hostkeys(ssh_session session){
* @brief sets the key exchange parameters to be sent to the server,
* in function of the options and available methods.
*/
-int set_client_kex(ssh_session session){
+int ssh_set_client_kex(ssh_session session){
struct ssh_kex_struct *client= &session->next_crypto->client_kex;
const char *wanted;
int i;
@@ -656,7 +656,7 @@ error:
}
/* returns 1 if at least one of the name algos is in the default algorithms table */
-int verify_existing_algo(int algo, const char *name){
+int ssh_verify_existing_algo(int algo, const char *name){
char *ptr;
if(algo>9 || algo <0)
return -1;
diff --git a/src/known_hosts.c b/src/known_hosts.c
index 263289f..32f795a 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -134,7 +134,7 @@ static char **ssh_get_knownhost_line(FILE **file, const char *filename,
continue; /* skip empty lines */
}
- tokens = space_tokenize(buffer);
+ tokens = ssh_space_tokenize(buffer);
if (tokens == NULL) {
fclose(*file);
*file = NULL;
diff --git a/src/options.c b/src/options.c
index e715c09..70b4ca5 100644
--- a/src/options.c
+++ b/src/options.c
@@ -164,7 +164,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
int ssh_options_set_algo(ssh_session session, int algo,
const char *list) {
- if (!verify_existing_algo(algo, list)) {
+ if (!ssh_verify_existing_algo(algo, list)) {
ssh_set_error(session, SSH_REQUEST_DENIED,
"Setting method: no algorithm for method \"%s\" (%s)\n",
ssh_kex_get_description(algo), list);
--
2.4.3
From 1c77ef6afdb9ce94c4edc8f4d43f1a3a6bada518 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 13:47:00 +0200
Subject: [PATCH 08/24 v2] cleanup: use ssh_ prefix in the gcrypt missing
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/libgcrypt.h | 8 ++++----
src/gcrypt_missing.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/libssh/libgcrypt.h b/include/libssh/libgcrypt.h
index 8e52a68..7b97c7f 100644
--- a/include/libssh/libgcrypt.h
+++ b/include/libssh/libgcrypt.h
@@ -52,15 +52,15 @@ typedef void *EVPCTX;
typedef gcry_mpi_t bignum;
/* missing gcrypt functions */
-int my_gcry_dec2bn(bignum *bn, const char *data);
-char *my_gcry_bn2dec(bignum bn);
+int ssh_gcry_dec2bn(bignum *bn, const char *data);
+char *ssh_gcry_bn2dec(bignum bn);
#define bignum_new() gcry_mpi_new(0)
#define bignum_free(num) gcry_mpi_release(num)
#define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
#define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
-#define bignum_bn2dec(num) my_gcry_bn2dec(num)
-#define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
+#define bignum_bn2dec(num) ssh_gcry_bn2dec(num)
+#define bignum_dec2bn(num, data) ssh_gcry_dec2bn(data, num)
#define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
#define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
#define bignum_rand(num,bits) gcry_mpi_randomize(num,bits,GCRY_STRONG_RANDOM),gcry_mpi_set_bit(num,bits-1),gcry_mpi_set_bit(num,0)
diff --git a/src/gcrypt_missing.c b/src/gcrypt_missing.c
index b21e5f3..e07843b 100644
--- a/src/gcrypt_missing.c
+++ b/src/gcrypt_missing.c
@@ -27,7 +27,7 @@
#include "libssh/libgcrypt.h"
#ifdef HAVE_LIBGCRYPT
-int my_gcry_dec2bn(bignum *bn, const char *data) {
+int ssh_gcry_dec2bn(bignum *bn, const char *data) {
int count;
*bn = bignum_new();
@@ -43,7 +43,7 @@ int my_gcry_dec2bn(bignum *bn, const char *data) {
return count;
}
-char *my_gcry_bn2dec(bignum bn) {
+char *ssh_gcry_bn2dec(bignum bn) {
bignum bndup, num, ten;
char *ret;
int count, count2;
--
2.4.3
From 72c5de6d9cd976f042a6e227760659a845c1026d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 14:11:08 +0200
Subject: [PATCH 09/24 v2] cleanup: use ssh_ prefix in the packet (non-static)
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/packet.h | 18 +++++++++---------
src/auth.c | 14 +++++++-------
src/auth1.c | 4 ++--
src/channels.c | 16 ++++++++--------
src/channels1.c | 12 ++++++------
src/client.c | 4 ++--
src/dh.c | 4 ++--
src/gssapi.c | 14 +++++++-------
src/kex.c | 2 +-
src/kex1.c | 2 +-
src/messages.c | 6 +++---
src/packet.c | 14 +++++++-------
src/packet1.c | 8 ++++----
src/packet_crypt.c | 10 +++++-----
src/server.c | 24 ++++++++++++------------
src/session.c | 4 ++--
16 files changed, 78 insertions(+), 78 deletions(-)
diff --git a/include/libssh/packet.h b/include/libssh/packet.h
index d8ef35b..3a84eb7 100644
--- a/include/libssh/packet.h
+++ b/include/libssh/packet.h
@@ -43,10 +43,10 @@ enum ssh_packet_state_e {
PACKET_STATE_PROCESSING
};
-int packet_send(ssh_session session);
+int ssh_packet_send(ssh_session session);
#ifdef WITH_SSH1
-int packet_send1(ssh_session session) ;
+int ssh_packet_send1(ssh_session session) ;
void ssh_packet_set_default_callbacks1(ssh_session session);
SSH_PACKET_CALLBACK(ssh_packet_disconnect1);
@@ -78,12 +78,12 @@ void ssh_packet_set_default_callbacks(ssh_session session);
void ssh_packet_process(ssh_session session, uint8_t type);
/* PACKET CRYPT */
-uint32_t packet_decrypt_len(ssh_session session, char *crypted);
-int packet_decrypt(ssh_session session, void *packet, unsigned int len);
-unsigned char *packet_encrypt(ssh_session session,
- void *packet,
- unsigned int len);
-int packet_hmac_verify(ssh_session session,ssh_buffer buffer,
- unsigned char *mac, enum ssh_hmac_e type);
+uint32_t ssh_packet_decrypt_len(ssh_session session, char *crypted);
+int ssh_packet_decrypt(ssh_session session, void *packet, unsigned int len);
+unsigned char *ssh_packet_encrypt(ssh_session session,
+ void *packet,
+ unsigned int len);
+int ssh_packet_hmac_verify(ssh_session session,ssh_buffer buffer,
+ unsigned char *mac, enum ssh_hmac_e type);
#endif /* PACKET_H_ */
diff --git a/src/auth.c b/src/auth.c
index c2cf52f..060ee61 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -391,7 +391,7 @@ int ssh_userauth_none(ssh_session session, const char *username) {
session->auth_state = SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_NONE;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@@ -503,7 +503,7 @@ int ssh_userauth_try_publickey(ssh_session session,
session->auth_state = SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_OFFER_PUBKEY;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@@ -624,7 +624,7 @@ int ssh_userauth_publickey(ssh_session session,
session->auth_state = SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_PUBKEY;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@@ -708,7 +708,7 @@ static int ssh_userauth_agent_publickey(ssh_session session,
session->auth_state = SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_AGENT;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@@ -1152,7 +1152,7 @@ int ssh_userauth_password(ssh_session session,
session->auth_state = SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_OFFER_PUBKEY;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@@ -1321,7 +1321,7 @@ static int ssh_userauth_kbdint_init(ssh_session session,
SSH_LOG(SSH_LOG_DEBUG,
"Sending keyboard-interactive init request");
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@@ -1382,7 +1382,7 @@ static int ssh_userauth_kbdint_send(ssh_session session)
SSH_LOG(SSH_LOG_DEBUG,
"Sending keyboard-interactive response packet");
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
diff --git a/src/auth1.c b/src/auth1.c
index e808763..b61f654 100644
--- a/src/auth1.c
+++ b/src/auth1.c
@@ -114,7 +114,7 @@ static int send_username(ssh_session session, const char *username) {
ssh_string_free(user);
session->auth_state=SSH_AUTH_STATE_NONE;
session->auth_service_state = SSH_AUTH_SERVICE_SENT;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
pending:
@@ -214,7 +214,7 @@ int ssh_userauth1_password(ssh_session session, const char *username,
ssh_string_free(pwd);
session->auth_state=SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_PASSWORD;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
pending:
diff --git a/src/channels.c b/src/channels.c
index 6082320..c04f1fd 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -293,7 +293,7 @@ static int channel_open(ssh_channel channel, const char *type, int window,
}
}
channel->state = SSH_CHANNEL_STATE_OPENING;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return err;
}
@@ -374,7 +374,7 @@ static int grow_window(ssh_session session, ssh_channel channel, int minimumsize
goto error;
}
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
goto error;
}
@@ -752,7 +752,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
if (rc != SSH_OK) {
return SSH_PACKET_USED;
}
- packet_send(session);
+ ssh_packet_send(session);
return SSH_PACKET_USED;
}
@@ -1082,7 +1082,7 @@ int ssh_channel_send_eof(ssh_channel channel){
goto error;
}
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
SSH_LOG(SSH_LOG_PACKET,
"Sent a EOF on client channel (%d:%d)",
channel->local_channel,
@@ -1141,7 +1141,7 @@ int ssh_channel_close(ssh_channel channel){
goto error;
}
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
SSH_LOG(SSH_LOG_PACKET,
"Sent a close on client channel (%d:%d)",
channel->local_channel,
@@ -1318,7 +1318,7 @@ static int channel_write_common(ssh_channel channel,
goto error;
}
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return SSH_ERROR;
}
@@ -1547,7 +1547,7 @@ static int channel_request(ssh_channel channel, const char *request,
}
}
channel->request_state = SSH_CHANNEL_REQ_STATE_PENDING;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return rc;
}
@@ -2109,7 +2109,7 @@ static int global_request(ssh_session session, const char *request,
}
session->global_req_state = SSH_CHANNEL_REQ_STATE_PENDING;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
if (rc == SSH_ERROR) {
return rc;
}
diff --git a/src/channels1.c b/src/channels1.c
index 730649a..2ad087e 100644
--- a/src/channels1.c
+++ b/src/channels1.c
@@ -129,7 +129,7 @@ int ssh_channel_request_pty_size1(ssh_channel channel, const char *terminal, int
SSH_LOG(SSH_LOG_FUNCTIONS, "Opening a ssh1 pty");
channel->request_state = SSH_CHANNEL_REQ_STATE_PENDING;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
@@ -178,7 +178,7 @@ int ssh_channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
return SSH_ERROR;
}
channel->request_state=SSH_CHANNEL_REQ_STATE_PENDING;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return SSH_ERROR;
}
@@ -219,7 +219,7 @@ int ssh_channel_request_shell1(ssh_channel channel) {
return -1;
}
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
@@ -249,7 +249,7 @@ int ssh_channel_request_exec1(ssh_channel channel, const char *cmd) {
}
ssh_string_free(command);
- if(packet_send(session) == SSH_ERROR) {
+ if(ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
@@ -314,7 +314,7 @@ SSH_PACKET_CALLBACK(ssh_packet_close1){
if (rc < 0) {
return SSH_PACKET_NOT_USED;
}
- packet_send(session);
+ ssh_packet_send(session);
return SSH_PACKET_USED;
}
@@ -364,7 +364,7 @@ int ssh_channel_write1(ssh_channel channel, const void *data, int len) {
ptr += effectivelen;
len -= effectivelen;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
ssh_handle_packets(session, SSH_TIMEOUT_NONBLOCKING);
diff --git a/src/client.c b/src/client.c
index 0c2b7e4..0cca110 100644
--- a/src/client.c
+++ b/src/client.c
@@ -283,7 +283,7 @@ int ssh_service_request(ssh_session session, const char *service) {
return SSH_ERROR;
}
session->auth_service_state=SSH_AUTH_SERVICE_SENT;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
ssh_set_error(session, SSH_FATAL,
"Sending SSH2_MSG_SERVICE_REQUEST failed.");
return SSH_ERROR;
@@ -643,7 +643,7 @@ void ssh_disconnect(ssh_session session) {
goto error;
}
- packet_send(session);
+ ssh_packet_send(session);
ssh_socket_close(session->socket);
}
error:
diff --git a/src/dh.c b/src/dh.c
index 485a280..549f7df 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -456,7 +456,7 @@ int ssh_client_dh_init(ssh_session session){
ssh_string_free(e);
e=NULL;
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
return rc;
error:
if(e != NULL){
@@ -509,7 +509,7 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
goto error;
}
- rc=packet_send(session);
+ rc=ssh_packet_send(session);
SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent");
return rc;
error:
diff --git a/src/gssapi.c b/src/gssapi.c
index 09f0d93..1c5a2a4 100644
--- a/src/gssapi.c
+++ b/src/gssapi.c
@@ -121,7 +121,7 @@ static int ssh_gssapi_send_response(ssh_session session, ssh_string oid){
return SSH_ERROR;
}
- packet_send(session);
+ ssh_packet_send(session);
SSH_LOG(SSH_LOG_PACKET,
"Sent SSH_MSG_USERAUTH_GSSAPI_RESPONSE");
return SSH_OK;
@@ -319,7 +319,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server){
ssh_set_error_oom(session);
return SSH_PACKET_USED;
}
- packet_send(session);
+ ssh_packet_send(session);
ssh_string_free(out_token);
} else {
session->gssapi->state = SSH_GSSAPI_STATE_RCV_MIC;
@@ -358,7 +358,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server){
SSH2_MSG_USERAUTH_GSSAPI_TOKEN,
output_token.length,
(size_t)output_token.length, output_token.value);
- packet_send(session);
+ ssh_packet_send(session);
}
if(maj_stat == GSS_S_COMPLETE){
session->gssapi->state = SSH_GSSAPI_STATE_RCV_MIC;
@@ -540,7 +540,7 @@ static int ssh_gssapi_send_auth_mic(ssh_session session, ssh_string *oid_set, in
}
session->auth_state = SSH_AUTH_STATE_GSSAPI_REQUEST_SENT;
- return packet_send(session);
+ return ssh_packet_send(session);
fail:
ssh_buffer_reinit(session->out_buffer);
return SSH_ERROR;
@@ -771,7 +771,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_response){
SSH2_MSG_USERAUTH_GSSAPI_TOKEN,
output_token.length,
(size_t)output_token.length, output_token.value);
- packet_send(session);
+ ssh_packet_send(session);
session->auth_state = SSH_AUTH_STATE_GSSAPI_TOKEN;
}
return SSH_PACKET_USED;
@@ -812,7 +812,7 @@ static int ssh_gssapi_send_mic(ssh_session session){
return SSH_ERROR;
}
- return packet_send(session);
+ return ssh_packet_send(session);
}
SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client){
@@ -866,7 +866,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client){
SSH2_MSG_USERAUTH_GSSAPI_TOKEN,
output_token.length,
(size_t)output_token.length, output_token.value);
- packet_send(session);
+ ssh_packet_send(session);
}
if(maj_stat == GSS_S_COMPLETE){
session->auth_state = SSH_AUTH_STATE_NONE;
diff --git a/src/kex.c b/src/kex.c
index 55b8318..f34728c 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -642,7 +642,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
goto error;
}
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
diff --git a/src/kex1.c b/src/kex1.c
index 9e0794d..10e6327 100644
--- a/src/kex1.c
+++ b/src/kex1.c
@@ -443,7 +443,7 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
goto error;
}
session->session_state=SSH_SESSION_STATE_KEXINIT_RECEIVED;
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
goto error;
}
diff --git a/src/messages.c b/src/messages.c
index bd93b58..4149e28 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -86,7 +86,7 @@ static int ssh_message_reply_default(ssh_message msg) {
if (ssh_buffer_add_u32(msg->session->out_buffer,
htonl(msg->session->recv_seq-1)) < 0)
goto error;
- return packet_send(msg->session);
+ return ssh_packet_send(msg->session);
error:
return SSH_ERROR;
}
@@ -1138,7 +1138,7 @@ int ssh_message_channel_request_open_reply_accept_channel(ssh_message msg, ssh_c
"Accepting a channel request_open for chan %d",
chan->remote_channel);
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
return rc;
}
@@ -1319,7 +1319,7 @@ int ssh_message_channel_request_reply_success(ssh_message msg) {
return SSH_ERROR;
}
- return packet_send(msg->session);
+ return ssh_packet_send(msg->session);
}
SSH_LOG(SSH_LOG_PACKET,
diff --git a/src/packet.c b/src/packet.c
index 4636f26..f10467b 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -192,7 +192,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
memcpy(buffer, data, blocksize);
processed += blocksize;
- len = packet_decrypt_len(session, buffer);
+ len = ssh_packet_decrypt_len(session, buffer);
rc = ssh_buffer_add_data(session->in_buffer, buffer, blocksize);
if (rc < 0) {
@@ -260,7 +260,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
uint8_t *payload = ((uint8_t*)ssh_buffer_get_rest(session->in_buffer) + blocksize);
uint32_t plen = buffer_len - blocksize;
- rc = packet_decrypt(session, payload, plen);
+ rc = ssh_packet_decrypt(session, payload, plen);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "Decrypt error");
goto error;
@@ -271,7 +271,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
packet = ((uint8_t *)data) + processed;
memcpy(mac, packet, current_macsize);
- rc = packet_hmac_verify(session, session->in_buffer, mac, session->current_crypto->in_hmac);
+ rc = ssh_packet_hmac_verify(session, session->in_buffer, mac, session->current_crypto->in_hmac);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "HMAC error");
goto error;
@@ -452,7 +452,7 @@ int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
ssh_set_error_oom(session);
return SSH_ERROR;
}
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
return rc;
}
@@ -567,7 +567,7 @@ static int packet_send2(ssh_session session) {
,ssh_buffer_get_rest_len(session->out_buffer));
}
#endif
- hmac = packet_encrypt(session, ssh_buffer_get_rest(session->out_buffer),
+ hmac = ssh_packet_encrypt(session, ssh_buffer_get_rest(session->out_buffer),
ssh_buffer_get_rest_len(session->out_buffer));
if (hmac) {
rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
@@ -595,10 +595,10 @@ error:
}
-int packet_send(ssh_session session) {
+int ssh_packet_send(ssh_session session) {
#ifdef WITH_SSH1
if (session->version == 1) {
- return packet_send1(session);
+ return ssh_packet_send1(session);
}
#endif
return packet_send2(session);
diff --git a/src/packet1.c b/src/packet1.c
index 543af1f..36e14bb 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -171,7 +171,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
buffer_len = ssh_buffer_get_len(session->in_buffer);
if (buffer_len > 0) {
int rc;
- rc = packet_decrypt(session,
+ rc = ssh_packet_decrypt(session,
ssh_buffer_get_begin(session->in_buffer),
buffer_len);
if (rc < 0) {
@@ -252,7 +252,7 @@ error:
}
-int packet_send1(ssh_session session) {
+int ssh_packet_send1(ssh_session session) {
unsigned int blocksize = (session->current_crypto ?
session->current_crypto->out_cipher->blocksize : 8);
uint32_t currentlen = ssh_buffer_get_len(session->out_buffer) + sizeof(uint32_t);
@@ -306,8 +306,8 @@ int packet_send1(ssh_session session) {
#endif
/* session->out_buffer should have more than sizeof(uint32_t) bytes
- in it as required for packet_encrypt */
- packet_encrypt(session, (unsigned char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
+ in it as required for ssh_packet_encrypt */
+ ssh_packet_encrypt(session, (unsigned char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
#ifdef DEBUG_CRYPTO
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index c24a3e9..fd0db2e 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -44,11 +44,11 @@
#include "libssh/crypto.h"
#include "libssh/buffer.h"
-uint32_t packet_decrypt_len(ssh_session session, char *crypted){
+uint32_t ssh_packet_decrypt_len(ssh_session session, char *crypted){
uint32_t decrypted;
if (session->current_crypto) {
- if (packet_decrypt(session, crypted,
+ if (ssh_packet_decrypt(session, crypted,
session->current_crypto->in_cipher->blocksize) < 0) {
return 0;
}
@@ -57,7 +57,7 @@ uint32_t packet_decrypt_len(ssh_session session, char *crypted){
return ntohl(decrypted);
}
-int packet_decrypt(ssh_session session, void *data,uint32_t len) {
+int ssh_packet_decrypt(ssh_session session, void *data,uint32_t len) {
struct ssh_cipher_struct *crypto = session->current_crypto->in_cipher;
char *out = NULL;
@@ -85,7 +85,7 @@ int packet_decrypt(ssh_session session, void *data,uint32_t len) {
return 0;
}
-unsigned char *packet_encrypt(ssh_session session, void *data, uint32_t len) {
+unsigned char *ssh_packet_encrypt(ssh_session session, void *data, uint32_t len) {
struct ssh_cipher_struct *crypto = NULL;
HMACCTX ctx = NULL;
char *out = NULL;
@@ -160,7 +160,7 @@ unsigned char *packet_encrypt(ssh_session session, void *data, uint32_t len) {
* @return 0 if hmac and mac are equal, < 0 if not or an error
* occurred.
*/
-int packet_hmac_verify(ssh_session session, ssh_buffer buffer,
+int ssh_packet_hmac_verify(ssh_session session, ssh_buffer buffer,
unsigned char *mac, enum ssh_hmac_e type) {
unsigned char hmacbuf[DIGEST_MAX_LEN] = {0};
HMACCTX ctx;
diff --git a/src/server.c b/src/server.c
index c86df1b..0491e33 100644
--- a/src/server.c
+++ b/src/server.c
@@ -321,7 +321,7 @@ static int dh_handshake_server(ssh_session session) {
return -1;
}
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
@@ -330,7 +330,7 @@ static int dh_handshake_server(ssh_session session) {
return -1;
}
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
return -1;
}
SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_NEWKEYS sent");
@@ -651,7 +651,7 @@ int ssh_auth_reply_default(ssh_session session,int partial) {
ssh_set_error_oom(session);
return SSH_ERROR;
}
- rc = packet_send(session);
+ rc = ssh_packet_send(session);
return rc;
}
@@ -672,7 +672,7 @@ static int ssh_message_channel_request_open_reply_default(ssh_message msg) {
return SSH_ERROR;
}
- rc = packet_send(msg->session);
+ rc = ssh_packet_send(msg->session);
return rc;
}
@@ -694,7 +694,7 @@ static int ssh_message_channel_request_reply_default(ssh_message msg) {
ssh_set_error_oom(msg->session);
return SSH_ERROR;
}
- return packet_send(msg->session);
+ return ssh_packet_send(msg->session);
}
SSH_LOG(SSH_LOG_PACKET,
@@ -728,7 +728,7 @@ int ssh_message_service_reply_success(ssh_message msg) {
ssh_set_error_oom(session);
return SSH_ERROR;
}
- rc = packet_send(msg->session);
+ rc = ssh_packet_send(msg->session);
return rc;
}
@@ -752,7 +752,7 @@ int ssh_message_global_request_reply_success(ssh_message msg, uint16_t bound_por
}
}
- return packet_send(msg->session);
+ return ssh_packet_send(msg->session);
}
if(msg->global_request.type == SSH_GLOBAL_REQUEST_TCPIP_FORWARD
@@ -774,7 +774,7 @@ static int ssh_message_global_request_reply_default(ssh_message msg) {
, SSH2_MSG_REQUEST_FAILURE) < 0) {
goto error;
}
- return packet_send(msg->session);
+ return ssh_packet_send(msg->session);
}
SSH_LOG(SSH_LOG_PACKET,
"The client doesn't want to know the request failed!");
@@ -911,7 +911,7 @@ int ssh_message_auth_interactive_request(ssh_message msg, const char *name,
}
}
- rc = packet_send(msg->session);
+ rc = ssh_packet_send(msg->session);
/* fill in the kbdint structure */
if (msg->session->kbdint == NULL) {
@@ -998,7 +998,7 @@ int ssh_auth_reply_success(ssh_session session, int partial) {
return SSH_ERROR;
}
- r = packet_send(session);
+ r = ssh_packet_send(session);
if(session->current_crypto && session->current_crypto->delayed_compress_out){
SSH_LOG(SSH_LOG_PROTOCOL,"Enabling delayed compression OUT");
session->current_crypto->do_compress_out=1;
@@ -1033,7 +1033,7 @@ int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pu
return SSH_ERROR;
}
- rc = packet_send(msg->session);
+ rc = ssh_packet_send(msg->session);
return rc;
}
@@ -1200,7 +1200,7 @@ int ssh_send_keepalive(ssh_session session)
goto err;
}
- if (packet_send(session) == SSH_ERROR) {
+ if (ssh_packet_send(session) == SSH_ERROR) {
goto err;
}
diff --git a/src/session.c b/src/session.c
index c1ef290..a61af44 100644
--- a/src/session.c
+++ b/src/session.c
@@ -828,7 +828,7 @@ int ssh_send_ignore (ssh_session session, const char *data) {
ssh_set_error_oom(session);
goto error;
}
- packet_send(session);
+ ssh_packet_send(session);
ssh_handle_packets(session, 0);
}
@@ -864,7 +864,7 @@ int ssh_send_debug (ssh_session session, const char *message, int always_display
ssh_set_error_oom(session);
goto error;
}
- packet_send(session);
+ ssh_packet_send(session);
ssh_handle_packets(session, 0);
}
--
2.4.3
From 16384b8ec5779510e51ec693f6d2477834bf1456 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 14:28:12 +0200
Subject: [PATCH 10/24 v2] pki_gcrypt: Fix warning about not handled values in
switch
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
/home/ffidenci/src/upstream/libssh/src/pki_gcrypt.c: In function
‘pki_key_compare’:
/home/ffidenci/src/upstream/libssh/src/pki_gcrypt.c:1082:5: warning:
enumeration value ‘SSH_KEYTYPE_DSS_CERT01’ not handled in switch
[-Wswitch]
switch (k1->type) {
^
/home/ffidenci/src/upstream/libssh/src/pki_gcrypt.c:1082:5: warning:
enumeration value ‘SSH_KEYTYPE_RSA_CERT01’ not handled in switch
[-Wswitch]
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
src/pki_gcrypt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 0b65ccd..ed61ef1 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -1135,6 +1135,8 @@ int pki_key_compare(const ssh_key k1,
/* ed25519 keys handled globaly */
return 0;
case SSH_KEYTYPE_ECDSA:
+ case SSH_KEYTYPE_DSS_CERT01:
+ case SSH_KEYTYPE_RSA_CERT01:
case SSH_KEYTYPE_UNKNOWN:
return 1;
}
--
2.4.3
From 83316e5bdb85a3ace1acc0abc901742e9b9c4805 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Thu, 17 Sep 2015 14:30:41 +0200
Subject: [PATCH 11/24 v2] tests: Fix warning about expected format for printf
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
/home/ffidenci/src/upstream/libssh/tests/benchmarks/bench_scp.c: In
function ‘benchmarks_scp_down’:
/home/ffidenci/src/upstream/libssh/tests/benchmarks/bench_scp.c:112:14:
warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has
type ‘size_t {aka long unsigned int}’ [-Wformat=]
printf("Only %d bytes available (on %lu requested).\n",size,bytes);
^
/home/ffidenci/src/upstream/libssh/tests/benchmarks/bench_scp.c:116:14:
warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has
type ‘size_t {aka long unsigned int}’ [-Wformat=]
printf("File is %d bytes (on %lu requested). Will cut the end\n"
,size,bytes);
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
tests/benchmarks/bench_scp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/benchmarks/bench_scp.c b/tests/benchmarks/bench_scp.c
index 340637b..71aba28 100644
--- a/tests/benchmarks/bench_scp.c
+++ b/tests/benchmarks/bench_scp.c
@@ -109,11 +109,11 @@ int benchmarks_scp_down (ssh_session session, struct argument_s *args,
if(r == SSH_SCP_REQUEST_NEWFILE){
size=ssh_scp_request_get_size(scp);
if(bytes > size){
- printf("Only %d bytes available (on %lu requested).\n",size,bytes);
+ printf("Only %zd bytes available (on %lu requested).\n",size,bytes);
bytes = size;
}
if(size > bytes){
- printf("File is %d bytes (on %lu requested). Will cut the end\n",size,bytes);
+ printf("File is %zd bytes (on %lu requested). Will cut the end\n",size,bytes);
}
if(args->verbose>0)
fprintf(stdout,"Starting download of %lu bytes now\n",bytes);
--
2.4.3
From 2ea1e2121bc74254fcaad8ef61d3abaed7cfd8ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Sat, 19 Sep 2015 23:42:55 +0200
Subject: [PATCH 12/24 v2] buffer: fix documentation for ssh_buffer_get_u32()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
src/buffer.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/buffer.c b/src/buffer.c
index a327aa6..73db6d1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -591,12 +591,16 @@ int ssh_buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
return ssh_buffer_get_data(buffer,data,sizeof(uint8_t));
}
-/** \internal
- * \brief gets a 32 bits unsigned int out of the buffer. Adjusts the read pointer.
- * \param buffer Buffer to read
- * \param data pointer to a uint32_t where to store the data
- * \returns 0 if there is not enough data in buffer
- * \returns 4 otherwise.
+/**
+ * @internal
+ *
+ * @brief gets a 32 bits unsigned int out of the buffer. Adjusts the read pointer.
+ *
+ * @param[in] buffer The buffer to read.
+ *
+ * @param[in] data A pointer to a uint32_t where to store the data.
+ *
+ * @returns 0 if there is not enough data in buffer, 4 otherwise.
*/
int ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
--
2.4.3
From 50868efcb040a2b49f7d59bffb886933686ceed7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Sat, 19 Sep 2015 23:44:27 +0200
Subject: [PATCH 13/24 v2] buffer: cosmetic change in ssh_buffer_get_u8()
documentation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
src/buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/buffer.c b/src/buffer.c
index 73db6d1..a281024 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -583,7 +583,7 @@ uint32_t ssh_buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint3
*
* @param[in] buffer The buffer to read.
*
- * @param[in] data A pointer to a uint8_t where to store the data.
+ * @param[in] data A pointer to a uint8_t where to store the data.
*
* @returns 0 if there is not enough data in buffer, 1 otherwise.
*/
--
2.4.3
From c2cf33dbb068eee3daa9e09a22dc5c7378bf8b7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:10:03 +0200
Subject: [PATCH 14/24 v2] buffer: rename ssh_buffer_get_rest() to
ssh_buffer_get()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 2 +-
src/agent.c | 4 ++--
src/buffer.c | 9 ++++-----
src/channels.c | 8 ++++----
src/dh.c | 8 ++++----
src/gzip.c | 8 ++++----
src/known_hosts.c | 6 +++---
src/messages.c | 2 +-
src/packet.c | 8 ++++----
src/packet1.c | 8 ++++----
src/packet_crypt.c | 2 +-
src/pcap.c | 2 +-
src/pki.c | 8 ++++----
src/pki_crypto.c | 4 ++--
src/pki_gcrypt.c | 2 +-
src/sftp.c | 4 ++--
src/sftpserver.c | 4 ++--
src/socket.c | 4 ++--
tests/unittests/torture_buffer.c | 12 ++++++------
19 files changed, 52 insertions(+), 53 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 3ff794a..15294b2 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -79,7 +79,7 @@ int ssh_buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
int ssh_buffer_reinit(ssh_buffer buffer);
/* ssh_buffer_get_rest returns a pointer to the current position into the buffer */
-void *ssh_buffer_get_rest(ssh_buffer buffer);
+void *ssh_buffer_get(ssh_buffer buffer);
/* ssh_buffer_get_rest_len returns the number of bytes which can be read */
uint32_t ssh_buffer_get_rest_len(ssh_buffer buffer);
diff --git a/src/agent.c b/src/agent.c
index 804ee50..c3356bc 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -279,7 +279,7 @@ static int agent_talk(struct ssh_session_struct *session,
/* send length and then the request packet */
if (atomicio(session->agent, payload, 4, 0) == 4) {
- if (atomicio(session->agent, ssh_buffer_get_rest(request), len, 0)
+ if (atomicio(session->agent, ssh_buffer_get(request), len, 0)
!= len) {
SSH_LOG(SSH_LOG_WARN, "atomicio sending request failed: %s",
strerror(errno));
@@ -543,7 +543,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
ssh_buffer_free(request);
return NULL;
}
- if (ssh_buffer_add_data(request, ssh_buffer_get_rest(data), dlen) < 0) {
+ if (ssh_buffer_add_data(request, ssh_buffer_get(data), dlen) < 0) {
ssh_buffer_free(request);
return NULL;
}
diff --git a/src/buffer.c b/src/buffer.c
index a281024..8765989 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -425,7 +425,7 @@ int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
int rc;
rc = ssh_buffer_add_data(buffer,
- ssh_buffer_get_rest(source),
+ ssh_buffer_get(source),
ssh_buffer_get_rest_len(source));
if (rc < 0) {
return -1;
@@ -444,7 +444,7 @@ int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
*
* @warning Don't expect data to be nul-terminated.
*
- * @see ssh_buffer_get_rest()
+ * @see ssh_buffer_get()
* @see ssh_buffer_get_len()
*/
void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
@@ -461,9 +461,8 @@ void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
* @return A pointer to the data from current position.
*
* @see ssh_buffer_get_rest_len()
- * @see ssh_buffer_get()
*/
-void *ssh_buffer_get_rest(struct ssh_buffer_struct *buffer){
+void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
return buffer->data + buffer->pos;
}
@@ -489,7 +488,7 @@ uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
*
* @return The length of the buffer.
*
- * @see ssh_buffer_get_rest()
+ * @see ssh_buffer_get()
*/
uint32_t ssh_buffer_get_rest_len(struct ssh_buffer_struct *buffer){
buffer_verify(buffer);
diff --git a/src/channels.c b/src/channels.c
index c04f1fd..5cfc6ed 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -546,7 +546,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
}
rest = channel->callbacks->channel_data_function(channel->session,
channel,
- ssh_buffer_get_rest(buf),
+ ssh_buffer_get(buf),
ssh_buffer_get_rest_len(buf),
is_stderr,
channel->callbacks->userdata);
@@ -1540,7 +1540,7 @@ static int channel_request(ssh_channel channel, const char *request,
}
if (buffer != NULL) {
- if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get_rest(buffer),
+ if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get(buffer),
ssh_buffer_get_rest_len(buffer)) < 0) {
ssh_set_error_oom(session);
goto error;
@@ -2099,7 +2099,7 @@ static int global_request(ssh_session session, const char *request,
if (buffer != NULL) {
rc = ssh_buffer_add_data(session->out_buffer,
- ssh_buffer_get_rest(buffer),
+ ssh_buffer_get(buffer),
ssh_buffer_get_rest_len(buffer));
if (rc < 0) {
ssh_set_error_oom(session);
@@ -2717,7 +2717,7 @@ int ssh_channel_read_timeout(ssh_channel channel,
len = ssh_buffer_get_rest_len(stdbuf);
/* Read count bytes if len is greater, everything otherwise */
len = (len > count ? count : len);
- memcpy(dest, ssh_buffer_get_rest(stdbuf), len);
+ memcpy(dest, ssh_buffer_get(stdbuf), len);
ssh_buffer_pass_bytes(stdbuf,len);
if (channel->counter != NULL) {
channel->counter->in_bytes += len;
diff --git a/src/dh.c b/src/dh.c
index 549f7df..d47c3dc 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -575,10 +575,10 @@ int ssh_make_sessionid(ssh_session session) {
"dPdPS",
ssh_buffer_get_rest_len(client_hash),
ssh_buffer_get_rest_len(client_hash),
- ssh_buffer_get_rest(client_hash),
+ ssh_buffer_get(client_hash),
ssh_buffer_get_rest_len(server_hash),
ssh_buffer_get_rest_len(server_hash),
- ssh_buffer_get_rest(server_hash),
+ ssh_buffer_get(server_hash),
session->next_crypto->server_pubkey);
if(rc != SSH_OK){
@@ -643,7 +643,7 @@ int ssh_make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
- sha1(ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf),
+ sha1(ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf),
session->next_crypto->secret_hash);
break;
case SSH_KEX_ECDH_SHA2_NISTP256:
@@ -655,7 +655,7 @@ int ssh_make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
- sha256(ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf),
+ sha256(ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf),
session->next_crypto->secret_hash);
break;
}
diff --git a/src/gzip.c b/src/gzip.c
index 0a14084..c1b54db 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -58,7 +58,7 @@ static z_stream *initcompress(ssh_session session, int level) {
static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level){
z_stream *zout = session->current_crypto->compress_out_ctx;
- void *in_ptr = ssh_buffer_get_rest(source);
+ void *in_ptr = ssh_buffer_get(source);
unsigned long in_size = ssh_buffer_get_rest_len(source);
ssh_buffer dest = NULL;
unsigned char out_buf[BLOCKSIZE] = {0};
@@ -113,7 +113,7 @@ int compress_buffer(ssh_session session, ssh_buffer buf) {
return -1;
}
- if (ssh_buffer_add_data(buf, ssh_buffer_get_rest(dest), ssh_buffer_get_rest_len(dest)) < 0) {
+ if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_rest_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
@@ -147,7 +147,7 @@ static z_stream *initdecompress(ssh_session session) {
static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t maxlen) {
z_stream *zin = session->current_crypto->compress_in_ctx;
- void *in_ptr = ssh_buffer_get_rest(source);
+ void *in_ptr = ssh_buffer_get(source);
unsigned long in_size = ssh_buffer_get_rest_len(source);
unsigned char out_buf[BLOCKSIZE] = {0};
ssh_buffer dest = NULL;
@@ -209,7 +209,7 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen){
return -1;
}
- if (ssh_buffer_add_data(buf, ssh_buffer_get_rest(dest), ssh_buffer_get_rest_len(dest)) < 0) {
+ if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_rest_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
diff --git a/src/known_hosts.c b/src/known_hosts.c
index 32f795a..b4ad8e4 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -270,7 +270,7 @@ static int check_public_key(ssh_session session, char **tokens) {
}
/* now test that they are identical */
- if (memcmp(ssh_buffer_get_rest(pubkey_buffer), ssh_string_data(pubkey),
+ if (memcmp(ssh_buffer_get(pubkey_buffer), ssh_string_data(pubkey),
ssh_buffer_get_rest_len(pubkey_buffer)) != 0) {
ssh_buffer_free(pubkey_buffer);
return 0;
@@ -340,7 +340,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
return 0;
}
- mac = hmac_init(ssh_buffer_get_rest(salt), ssh_buffer_get_rest_len(salt), SSH_HMAC_SHA1);
+ mac = hmac_init(ssh_buffer_get(salt), ssh_buffer_get_rest_len(salt), SSH_HMAC_SHA1);
if (mac == NULL) {
ssh_buffer_free(salt);
ssh_buffer_free(hash);
@@ -352,7 +352,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
hmac_final(mac, buffer, &size);
if (size == ssh_buffer_get_rest_len(hash) &&
- memcmp(buffer, ssh_buffer_get_rest(hash), size) == 0) {
+ memcmp(buffer, ssh_buffer_get(hash), size) == 0) {
match = 1;
} else {
match = 0;
diff --git a/src/messages.c b/src/messages.c
index 4149e28..eada232 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -786,7 +786,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
rc = ssh_pki_signature_verify_blob(session,
sig_blob,
msg->auth_request.pubkey,
- ssh_buffer_get_rest(digest),
+ ssh_buffer_get(digest),
ssh_buffer_get_rest_len(digest));
ssh_string_free(sig_blob);
ssh_buffer_free(digest);
diff --git a/src/packet.c b/src/packet.c
index f10467b..17f5068 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -257,7 +257,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
/* The following check avoids decrypting zero bytes */
if (buffer_len > blocksize) {
- uint8_t *payload = ((uint8_t*)ssh_buffer_get_rest(session->in_buffer) + blocksize);
+ uint8_t *payload = ((uint8_t*)ssh_buffer_get(session->in_buffer) + blocksize);
uint32_t plen = buffer_len - blocksize;
rc = ssh_packet_decrypt(session, payload, plen);
@@ -507,7 +507,7 @@ static int ssh_packet_write(ssh_session session) {
int rc = SSH_ERROR;
rc=ssh_socket_write(session->socket,
- ssh_buffer_get_rest(session->out_buffer),
+ ssh_buffer_get(session->out_buffer),
ssh_buffer_get_rest_len(session->out_buffer));
return rc;
@@ -563,11 +563,11 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_PCAP
if(session->pcap_ctx){
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,
- ssh_buffer_get_rest(session->out_buffer),ssh_buffer_get_rest_len(session->out_buffer)
+ ssh_buffer_get(session->out_buffer),ssh_buffer_get_rest_len(session->out_buffer)
,ssh_buffer_get_rest_len(session->out_buffer));
}
#endif
- hmac = ssh_packet_encrypt(session, ssh_buffer_get_rest(session->out_buffer),
+ hmac = ssh_packet_encrypt(session, ssh_buffer_get(session->out_buffer),
ssh_buffer_get_rest_len(session->out_buffer));
if (hmac) {
rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
diff --git a/src/packet1.c b/src/packet1.c
index 36e14bb..9465204 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -193,21 +193,21 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
}
memcpy(&crc,
- (unsigned char *)ssh_buffer_get_rest(session->in_buffer) + (len+padding) - sizeof(uint32_t),
+ (unsigned char *)ssh_buffer_get(session->in_buffer) + (len+padding) - sizeof(uint32_t),
sizeof(uint32_t));
ssh_buffer_pass_bytes_end(session->in_buffer, sizeof(uint32_t));
crc = ntohl(crc);
- if (ssh_crc32(ssh_buffer_get_rest(session->in_buffer),
+ if (ssh_crc32(ssh_buffer_get(session->in_buffer),
(len + padding) - sizeof(uint32_t)) != crc) {
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("crc32 on",ssh_buffer_get_rest(session->in_buffer),
+ ssh_print_hexa("crc32 on",ssh_buffer_get(session->in_buffer),
len + padding - sizeof(uint32_t));
#endif
SSH_LOG(SSH_LOG_RARE, "Invalid crc32");
ssh_set_error(session, SSH_FATAL,
"Invalid crc32: expected %.8x, got %.8x",
crc,
- ssh_crc32(ssh_buffer_get_rest(session->in_buffer),
+ ssh_crc32(ssh_buffer_get(session->in_buffer),
len + padding - sizeof(uint32_t)));
goto error;
}
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index fd0db2e..cb04c11 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -175,7 +175,7 @@ int ssh_packet_hmac_verify(ssh_session session, ssh_buffer buffer,
seq = htonl(session->recv_seq);
hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
- hmac_update(ctx, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
+ hmac_update(ctx, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
hmac_final(ctx, hmacbuf, &len);
#ifdef DEBUG_CRYPTO
diff --git a/src/pcap.c b/src/pcap.c
index 4efb052..2055132 100644
--- a/src/pcap.c
+++ b/src/pcap.c
@@ -145,7 +145,7 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
if(pcap == NULL || pcap->output==NULL)
return SSH_ERROR;
len=ssh_buffer_get_rest_len(packet);
- err=fwrite(ssh_buffer_get_rest(packet),len,1,pcap->output);
+ err=fwrite(ssh_buffer_get(packet),len,1,pcap->output);
if(err<0)
return SSH_ERROR;
else
diff --git a/src/pki.c b/src/pki.c
index 12e84e2..334382f 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -1473,7 +1473,7 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
return SSH_ERROR;
}
- ssh_string_fill(str, ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf));
+ ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf));
ssh_buffer_free(buf);
*sig_blob = str;
@@ -1629,7 +1629,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
evp_update(ctx, session_id, ssh_string_len(session_id) + 4);
- evp_update(ctx, ssh_buffer_get_rest(sigbuf), ssh_buffer_get_rest_len(sigbuf));
+ evp_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_rest_len(sigbuf));
evp_final(ctx, ehash, &elen);
#ifdef DEBUG_CRYPTO
@@ -1651,7 +1651,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
rc = ssh_buffer_pack(buf,
"SP",
session_id,
- ssh_buffer_get_rest_len(sigbuf), ssh_buffer_get_rest(sigbuf));
+ ssh_buffer_get_rest_len(sigbuf), ssh_buffer_get(sigbuf));
if (rc != SSH_OK) {
ssh_string_free(session_id);
ssh_buffer_free(buf);
@@ -1673,7 +1673,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
sha1_update(ctx, session_id, ssh_string_len(session_id) + 4);
- sha1_update(ctx, ssh_buffer_get_rest(sigbuf), ssh_buffer_get_rest_len(sigbuf));
+ sha1_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_rest_len(sigbuf));
sha1_final(hash, ctx);
#ifdef DEBUG_CRYPTO
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index dde6230..9df6898 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -1039,7 +1039,7 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
- rc = ssh_string_fill(str, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
+ rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
if (rc < 0) {
goto fail;
}
@@ -1244,7 +1244,7 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
return NULL;
}
- ssh_string_fill(sig_blob, ssh_buffer_get_rest(b), ssh_buffer_get_rest_len(b));
+ ssh_string_fill(sig_blob, ssh_buffer_get(b), ssh_buffer_get_rest_len(b));
ssh_buffer_free(b);
break;
}
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index ed61ef1..5be0388 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -1305,7 +1305,7 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
- rc = ssh_string_fill(str, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
+ rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
if (rc < 0) {
goto fail;
}
diff --git a/src/sftp.c b/src/sftp.c
index c1dbda1..6f7e726 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -288,7 +288,7 @@ int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
return -1;
}
- size = ssh_channel_write(sftp->channel, ssh_buffer_get_rest(payload),
+ size = ssh_channel_write(sftp->channel, ssh_buffer_get(payload),
ssh_buffer_get_rest_len(payload));
if (size < 0) {
return -1;
@@ -460,7 +460,7 @@ static sftp_message sftp_get_message(sftp_packet packet) {
msg->id,
msg->packet_type);
- if (ssh_buffer_add_data(msg->payload, ssh_buffer_get_rest(packet->payload),
+ if (ssh_buffer_add_data(msg->payload, ssh_buffer_get(packet->payload),
ssh_buffer_get_rest_len(packet->payload)) < 0) {
ssh_set_error_oom(sftp->session);
sftp_message_free(msg);
diff --git a/src/sftpserver.c b/src/sftpserver.c
index 5939309..51a4ba7 100644
--- a/src/sftpserver.c
+++ b/src/sftpserver.c
@@ -65,7 +65,7 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
/* take a copy of the whole packet */
msg->complete_message = ssh_buffer_new();
ssh_buffer_add_data(msg->complete_message,
- ssh_buffer_get_rest(payload),
+ ssh_buffer_get(payload),
ssh_buffer_get_rest_len(payload));
ssh_buffer_get_u32(payload, &msg->id);
@@ -377,7 +377,7 @@ int sftp_reply_names(sftp_client_message msg) {
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
ssh_buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
- ssh_buffer_add_data(out, ssh_buffer_get_rest(msg->attrbuf),
+ ssh_buffer_add_data(out, ssh_buffer_get(msg->attrbuf),
ssh_buffer_get_rest_len(msg->attrbuf)) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
ssh_buffer_free(out);
diff --git a/src/socket.c b/src/socket.c
index ba5128a..06ea9e6 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -290,7 +290,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
}
if (s->callbacks && s->callbacks->data) {
do {
- r = s->callbacks->data(ssh_buffer_get_rest(s->in_buffer),
+ r = s->callbacks->data(ssh_buffer_get(s->in_buffer),
ssh_buffer_get_rest_len(s->in_buffer),
s->callbacks->userdata);
ssh_buffer_pass_bytes(s->in_buffer, r);
@@ -658,7 +658,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
return SSH_AGAIN;
}
if (s->write_wontblock && len > 0) {
- w = ssh_socket_unbuffered_write(s, ssh_buffer_get_rest(s->out_buffer), len);
+ w = ssh_socket_unbuffered_write(s, ssh_buffer_get(s->out_buffer), len);
if (w < 0) {
session->alive = 0;
ssh_socket_close(s);
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c
index 03dfcf9..d4cef64 100644
--- a/tests/unittests/torture_buffer.c
+++ b/tests/unittests/torture_buffer.c
@@ -75,25 +75,25 @@ static void torture_buffer_prepend(void **state) {
ssh_buffer_add_data(buffer,"abcdef",6);
ssh_buffer_prepend_data(buffer,"xyz",3);
assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
- assert_memory_equal(ssh_buffer_get_rest(buffer), "xyzabcdef", 9);
+ assert_memory_equal(ssh_buffer_get(buffer), "xyzabcdef", 9);
/* Now remove 4 bytes and see if we can replace them */
ssh_buffer_get_u32(buffer,&v);
assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
- assert_memory_equal(ssh_buffer_get_rest(buffer), "bcdef", 5);
+ assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
ssh_buffer_prepend_data(buffer,"aris",4);
assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
- assert_memory_equal(ssh_buffer_get_rest(buffer), "arisbcdef", 9);
+ assert_memory_equal(ssh_buffer_get(buffer), "arisbcdef", 9);
/* same thing but we add 5 bytes now */
ssh_buffer_get_u32(buffer,&v);
assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
- assert_memory_equal(ssh_buffer_get_rest(buffer), "bcdef", 5);
+ assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
ssh_buffer_prepend_data(buffer,"12345",5);
assert_int_equal(ssh_buffer_get_rest_len(buffer),10);
- assert_memory_equal(ssh_buffer_get_rest(buffer), "12345bcdef", 10);
+ assert_memory_equal(ssh_buffer_get(buffer), "12345bcdef", 10);
}
/*
@@ -157,7 +157,7 @@ static void torture_ssh_buffer_add_format(void **state) {
len = ssh_buffer_get_rest_len(buffer);
assert_int_equal(len, sizeof(verif) - 1);
- assert_memory_equal(ssh_buffer_get_rest(buffer), verif, sizeof(verif) -1);
+ assert_memory_equal(ssh_buffer_get(buffer), verif, sizeof(verif) -1);
ssh_string_free(s);
}
--
2.4.3
From 321c8bc29c8615cc0bf166b9ecadb30923655d17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 00:29:29 +0200
Subject: [PATCH 15/24 v2] buffer: make ssh_buffer_get_len() call
ssh_buffer_get_rest_len()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is a preparatory step for having the behavior of
ssh_buffer_get_rest_len() in the ssh_buffer_get_len() and then remove
the ssh_buffer_rest_len()
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
src/buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/buffer.c b/src/buffer.c
index 8765989..23c8229 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -476,7 +476,7 @@ void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
* @see ssh_buffer_get()
*/
uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
- return buffer->used;
+ return ssh_buffer_get_rest_len(buffer);
}
/**
--
2.4.3
From c583ad5520a556c6a2ba474c2234ea2304c3990c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:18:38 +0200
Subject: [PATCH 16/24 v2] pki_gcrypt: adapt to the new behavior of
ssh_buffer_get_len()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
src/pki_gcrypt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 5be0388..6dadf3f 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -150,8 +150,8 @@ static int asn1_check_sequence(ssh_buffer buffer) {
}
size = asn1_get_len(buffer);
- if ((padding = ssh_buffer_get_len(buffer) - buffer->pos - size) > 0) {
- for (i = ssh_buffer_get_len(buffer) - buffer->pos - size,
+ if ((padding = ssh_buffer_get_len(buffer) - size) > 0) {
+ for (i = ssh_buffer_get_len(buffer) - size,
j = (unsigned char*)ssh_buffer_get_begin(buffer) + size + buffer->pos;
i;
i--, j++)
--
2.4.3
From f507201d805440a670cfdeab7b1a62fd1af93dfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 00:34:42 +0200
Subject: [PATCH 17/24 v2] buffer: do not use ssh_buffer_get_rest_len()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
As ssh_buffer_get_len() actually calls ssh_buffer_get_rest_len(), let's
just use the first one. This is a preparatory step for removing
ssh_buffer_get_rest_len().
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
src/agent.c | 4 ++--
src/buffer.c | 4 ++--
src/channels.c | 42 ++++++++++++++++++++--------------------
src/dh.c | 12 ++++++------
src/gzip.c | 10 +++++-----
src/known_hosts.c | 8 ++++----
src/messages.c | 2 +-
src/packet.c | 26 ++++++++++++-------------
src/packet1.c | 2 +-
src/packet_crypt.c | 2 +-
src/pcap.c | 4 ++--
src/pki.c | 10 +++++-----
src/pki_container_openssh.c | 2 +-
src/pki_crypto.c | 10 +++++-----
src/pki_gcrypt.c | 4 ++--
src/sftp.c | 12 ++++++------
src/sftpserver.c | 4 ++--
src/socket.c | 10 +++++-----
tests/unittests/torture_buffer.c | 22 ++++++++++-----------
19 files changed, 95 insertions(+), 95 deletions(-)
diff --git a/src/agent.c b/src/agent.c
index c3356bc..5cf5fa3 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -273,7 +273,7 @@ static int agent_talk(struct ssh_session_struct *session,
uint32_t len = 0;
uint8_t payload[1024 v2] = {0};
- len = ssh_buffer_get_rest_len(request);
+ len = ssh_buffer_get_len(request);
SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
agent_put_u32(payload, len);
@@ -538,7 +538,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
}
/* Add data */
- dlen = ssh_buffer_get_rest_len(data);
+ dlen = ssh_buffer_get_len(data);
if (ssh_buffer_add_u32(request, htonl(dlen)) < 0) {
ssh_buffer_free(request);
return NULL;
diff --git a/src/buffer.c b/src/buffer.c
index 23c8229..722efb6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -426,7 +426,7 @@ int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
rc = ssh_buffer_add_data(buffer,
ssh_buffer_get(source),
- ssh_buffer_get_rest_len(source));
+ ssh_buffer_get_len(source));
if (rc < 0) {
return -1;
}
@@ -460,7 +460,7 @@ void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
*
* @return A pointer to the data from current position.
*
- * @see ssh_buffer_get_rest_len()
+ * @see ssh_buffer_get_len()
*/
void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
return buffer->data + buffer->pos;
diff --git a/src/channels.c b/src/channels.c
index 5cfc6ed..ffcb1d5 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -547,7 +547,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
rest = channel->callbacks->channel_data_function(channel->session,
channel,
ssh_buffer_get(buf),
- ssh_buffer_get_rest_len(buf),
+ ssh_buffer_get_len(buf),
is_stderr,
channel->callbacks->userdata);
if(rest > 0) {
@@ -556,7 +556,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
}
ssh_buffer_pass_bytes(buf, rest);
}
- if (channel->local_window + ssh_buffer_get_rest_len(buf) < WINDOWLIMIT) {
+ if (channel->local_window + ssh_buffer_get_len(buf) < WINDOWLIMIT) {
if (grow_window(session, channel, 0) < 0) {
return -1;
}
@@ -612,9 +612,9 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
channel->remote_channel);
if ((channel->stdout_buffer &&
- ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
+ ssh_buffer_get_len(channel->stdout_buffer) > 0) ||
(channel->stderr_buffer &&
- ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
+ ssh_buffer_get_len(channel->stderr_buffer) > 0)) {
channel->delayed_close = 1;
} else {
channel->state = SSH_CHANNEL_STATE_CLOSED;
@@ -1414,9 +1414,9 @@ int ssh_channel_is_eof(ssh_channel channel) {
return SSH_ERROR;
}
if ((channel->stdout_buffer &&
- ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
+ ssh_buffer_get_len(channel->stdout_buffer) > 0) ||
(channel->stderr_buffer &&
- ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
+ ssh_buffer_get_len(channel->stderr_buffer) > 0)) {
return 0;
}
@@ -1541,7 +1541,7 @@ static int channel_request(ssh_channel channel, const char *request,
if (buffer != NULL) {
if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get(buffer),
- ssh_buffer_get_rest_len(buffer)) < 0) {
+ ssh_buffer_get_len(buffer)) < 0) {
ssh_set_error_oom(session);
goto error;
}
@@ -2100,7 +2100,7 @@ static int global_request(ssh_session session, const char *request,
if (buffer != NULL) {
rc = ssh_buffer_add_data(session->out_buffer,
ssh_buffer_get(buffer),
- ssh_buffer_get_rest_len(buffer));
+ ssh_buffer_get_len(buffer));
if (rc < 0) {
ssh_set_error_oom(session);
rc = SSH_ERROR;
@@ -2584,7 +2584,7 @@ struct ssh_channel_read_termination_struct {
static int ssh_channel_read_termination(void *s){
struct ssh_channel_read_termination_struct *ctx = s;
- if (ssh_buffer_get_rest_len(ctx->buffer) >= ctx->count ||
+ if (ssh_buffer_get_len(ctx->buffer) >= ctx->count ||
ctx->channel->remote_eof ||
ctx->channel->session->session_state == SSH_SESSION_STATE_ERROR)
return 1;
@@ -2681,11 +2681,11 @@ int ssh_channel_read_timeout(ssh_channel channel,
SSH_LOG(SSH_LOG_PACKET,
"Read (%d) buffered : %d bytes. Window: %d",
count,
- ssh_buffer_get_rest_len(stdbuf),
+ ssh_buffer_get_len(stdbuf),
channel->local_window);
- if (count > ssh_buffer_get_rest_len(stdbuf) + channel->local_window) {
- if (grow_window(session, channel, count - ssh_buffer_get_rest_len(stdbuf)) < 0) {
+ if (count > ssh_buffer_get_len(stdbuf) + channel->local_window) {
+ if (grow_window(session, channel, count - ssh_buffer_get_len(stdbuf)) < 0) {
return -1;
}
}
@@ -2711,10 +2711,10 @@ int ssh_channel_read_timeout(ssh_channel channel,
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
return SSH_ERROR;
}
- if (channel->remote_eof && ssh_buffer_get_rest_len(stdbuf) == 0) {
+ if (channel->remote_eof && ssh_buffer_get_len(stdbuf) == 0) {
return 0;
}
- len = ssh_buffer_get_rest_len(stdbuf);
+ len = ssh_buffer_get_len(stdbuf);
/* Read count bytes if len is greater, everything otherwise */
len = (len > count ? count : len);
memcpy(dest, ssh_buffer_get(stdbuf), len);
@@ -2818,7 +2818,7 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
stdbuf = channel->stderr_buffer;
}
- if (ssh_buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
+ if (ssh_buffer_get_len(stdbuf) == 0 && channel->remote_eof == 0) {
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
return SSH_ERROR;
}
@@ -2827,15 +2827,15 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
}
}
- if (ssh_buffer_get_rest_len(stdbuf) > 0){
- return ssh_buffer_get_rest_len(stdbuf);
+ if (ssh_buffer_get_len(stdbuf) > 0){
+ return ssh_buffer_get_len(stdbuf);
}
if (channel->remote_eof) {
return SSH_EOF;
}
- return ssh_buffer_get_rest_len(stdbuf);
+ return ssh_buffer_get_len(stdbuf);
}
/**
@@ -2882,7 +2882,7 @@ int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr){
rc = SSH_ERROR;
goto end;
}
- rc = ssh_buffer_get_rest_len(stdbuf);
+ rc = ssh_buffer_get_len(stdbuf);
if(rc > 0)
goto end;
if (channel->remote_eof)
@@ -2971,8 +2971,8 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
ssh_handle_packets(chan->session, SSH_TIMEOUT_NONBLOCKING);
}
- if ((chan->stdout_buffer && ssh_buffer_get_rest_len(chan->stdout_buffer) > 0) ||
- (chan->stderr_buffer && ssh_buffer_get_rest_len(chan->stderr_buffer) > 0) ||
+ if ((chan->stdout_buffer && ssh_buffer_get_len(chan->stdout_buffer) > 0) ||
+ (chan->stderr_buffer && ssh_buffer_get_len(chan->stderr_buffer) > 0) ||
chan->remote_eof) {
rout[j] = chan;
j++;
diff --git a/src/dh.c b/src/dh.c
index d47c3dc..67d1f4c 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -573,11 +573,11 @@ int ssh_make_sessionid(ssh_session session) {
rc = ssh_buffer_pack(buf,
"dPdPS",
- ssh_buffer_get_rest_len(client_hash),
- ssh_buffer_get_rest_len(client_hash),
+ ssh_buffer_get_len(client_hash),
+ ssh_buffer_get_len(client_hash),
ssh_buffer_get(client_hash),
- ssh_buffer_get_rest_len(server_hash),
- ssh_buffer_get_rest_len(server_hash),
+ ssh_buffer_get_len(server_hash),
+ ssh_buffer_get_len(server_hash),
ssh_buffer_get(server_hash),
session->next_crypto->server_pubkey);
@@ -643,7 +643,7 @@ int ssh_make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
- sha1(ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf),
+ sha1(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
session->next_crypto->secret_hash);
break;
case SSH_KEX_ECDH_SHA2_NISTP256:
@@ -655,7 +655,7 @@ int ssh_make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
- sha256(ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf),
+ sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
session->next_crypto->secret_hash);
break;
}
diff --git a/src/gzip.c b/src/gzip.c
index c1b54db..73cc331 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -59,7 +59,7 @@ static z_stream *initcompress(ssh_session session, int level) {
static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level){
z_stream *zout = session->current_crypto->compress_out_ctx;
void *in_ptr = ssh_buffer_get(source);
- unsigned long in_size = ssh_buffer_get_rest_len(source);
+ unsigned long in_size = ssh_buffer_get_len(source);
ssh_buffer dest = NULL;
unsigned char out_buf[BLOCKSIZE] = {0};
unsigned long len;
@@ -113,7 +113,7 @@ int compress_buffer(ssh_session session, ssh_buffer buf) {
return -1;
}
- if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_rest_len(dest)) < 0) {
+ if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
@@ -148,7 +148,7 @@ static z_stream *initdecompress(ssh_session session) {
static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t maxlen) {
z_stream *zin = session->current_crypto->compress_in_ctx;
void *in_ptr = ssh_buffer_get(source);
- unsigned long in_size = ssh_buffer_get_rest_len(source);
+ unsigned long in_size = ssh_buffer_get_len(source);
unsigned char out_buf[BLOCKSIZE] = {0};
ssh_buffer dest = NULL;
unsigned long len;
@@ -185,7 +185,7 @@ static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t
ssh_buffer_free(dest);
return NULL;
}
- if (ssh_buffer_get_rest_len(dest) > maxlen){
+ if (ssh_buffer_get_len(dest) > maxlen){
/* Size of packet exceeded, avoid a denial of service attack */
ssh_buffer_free(dest);
return NULL;
@@ -209,7 +209,7 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen){
return -1;
}
- if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_rest_len(dest)) < 0) {
+ if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
diff --git a/src/known_hosts.c b/src/known_hosts.c
index b4ad8e4..ab8a3dc 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -264,14 +264,14 @@ static int check_public_key(ssh_session session, char **tokens) {
return -1;
}
- if (ssh_buffer_get_rest_len(pubkey_buffer) != ssh_string_len(pubkey)) {
+ if (ssh_buffer_get_len(pubkey_buffer) != ssh_string_len(pubkey)) {
ssh_buffer_free(pubkey_buffer);
return 0;
}
/* now test that they are identical */
if (memcmp(ssh_buffer_get(pubkey_buffer), ssh_string_data(pubkey),
- ssh_buffer_get_rest_len(pubkey_buffer)) != 0) {
+ ssh_buffer_get_len(pubkey_buffer)) != 0) {
ssh_buffer_free(pubkey_buffer);
return 0;
}
@@ -340,7 +340,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
return 0;
}
- mac = hmac_init(ssh_buffer_get(salt), ssh_buffer_get_rest_len(salt), SSH_HMAC_SHA1);
+ mac = hmac_init(ssh_buffer_get(salt), ssh_buffer_get_len(salt), SSH_HMAC_SHA1);
if (mac == NULL) {
ssh_buffer_free(salt);
ssh_buffer_free(hash);
@@ -351,7 +351,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
hmac_update(mac, host, strlen(host));
hmac_final(mac, buffer, &size);
- if (size == ssh_buffer_get_rest_len(hash) &&
+ if (size == ssh_buffer_get_len(hash) &&
memcmp(buffer, ssh_buffer_get(hash), size) == 0) {
match = 1;
} else {
diff --git a/src/messages.c b/src/messages.c
index eada232..131eacd 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -787,7 +787,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
sig_blob,
msg->auth_request.pubkey,
ssh_buffer_get(digest),
- ssh_buffer_get_rest_len(digest));
+ ssh_buffer_get_len(digest));
ssh_string_free(sig_blob);
ssh_buffer_free(digest);
if (rc < 0) {
diff --git a/src/packet.c b/src/packet.c
index 17f5068..7d6957c 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -253,7 +253,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
* Decrypt the rest of the packet (blocksize bytes already
* have been decrypted)
*/
- uint32_t buffer_len = ssh_buffer_get_rest_len(session->in_buffer);
+ uint32_t buffer_len = ssh_buffer_get_len(session->in_buffer);
/* The following check avoids decrypting zero bytes */
if (buffer_len > blocksize) {
@@ -290,28 +290,28 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
goto error;
}
- if (padding > ssh_buffer_get_rest_len(session->in_buffer)) {
+ if (padding > ssh_buffer_get_len(session->in_buffer)) {
ssh_set_error(session,
SSH_FATAL,
"Invalid padding: %d (%d left)",
padding,
- ssh_buffer_get_rest_len(session->in_buffer));
+ ssh_buffer_get_len(session->in_buffer));
goto error;
}
ssh_buffer_pass_bytes_end(session->in_buffer, padding);
- compsize = ssh_buffer_get_rest_len(session->in_buffer);
+ compsize = ssh_buffer_get_len(session->in_buffer);
#ifdef WITH_ZLIB
if (session->current_crypto
&& session->current_crypto->do_compress_in
- && ssh_buffer_get_rest_len(session->in_buffer) > 0) {
+ && ssh_buffer_get_len(session->in_buffer) > 0) {
rc = decompress_buffer(session, session->in_buffer,MAX_PACKET_LEN);
if (rc < 0) {
goto error;
}
}
#endif /* WITH_ZLIB */
- payloadsize = ssh_buffer_get_rest_len(session->in_buffer);
+ payloadsize = ssh_buffer_get_len(session->in_buffer);
session->recv_seq++;
if (session->raw_counter != NULL) {
session->raw_counter->in_bytes += payloadsize;
@@ -508,7 +508,7 @@ static int ssh_packet_write(ssh_session session) {
rc=ssh_socket_write(session->socket,
ssh_buffer_get(session->out_buffer),
- ssh_buffer_get_rest_len(session->out_buffer));
+ ssh_buffer_get_len(session->out_buffer));
return rc;
}
@@ -518,7 +518,7 @@ static int packet_send2(ssh_session session) {
session->current_crypto->out_cipher->blocksize : 8);
enum ssh_hmac_e hmac_type = (session->current_crypto ?
session->current_crypto->out_hmac : session->next_crypto->out_hmac);
- uint32_t currentlen = ssh_buffer_get_rest_len(session->out_buffer);
+ uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
unsigned char *hmac = NULL;
char padstring[32] = { 0 };
int rc = SSH_ERROR;
@@ -531,11 +531,11 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_ZLIB
if (session->current_crypto
&& session->current_crypto->do_compress_out
- && ssh_buffer_get_rest_len(session->out_buffer)) {
+ && ssh_buffer_get_len(session->out_buffer)) {
if (compress_buffer(session,session->out_buffer) < 0) {
goto error;
}
- currentlen = ssh_buffer_get_rest_len(session->out_buffer);
+ currentlen = ssh_buffer_get_len(session->out_buffer);
}
#endif /* WITH_ZLIB */
compsize = currentlen;
@@ -563,12 +563,12 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_PCAP
if(session->pcap_ctx){
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,
- ssh_buffer_get(session->out_buffer),ssh_buffer_get_rest_len(session->out_buffer)
- ,ssh_buffer_get_rest_len(session->out_buffer));
+ ssh_buffer_get(session->out_buffer),ssh_buffer_get_len(session->out_buffer)
+ ,ssh_buffer_get_len(session->out_buffer));
}
#endif
hmac = ssh_packet_encrypt(session, ssh_buffer_get(session->out_buffer),
- ssh_buffer_get_rest_len(session->out_buffer));
+ ssh_buffer_get_len(session->out_buffer));
if (hmac) {
rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
if (rc < 0) {
diff --git a/src/packet1.c b/src/packet1.c
index 9465204..25fc44b 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -185,7 +185,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
ssh_buffer_get_len(session->in_buffer));
#endif
SSH_LOG(SSH_LOG_PACKET, "%d bytes padding", padding);
- if(((len + padding) != ssh_buffer_get_rest_len(session->in_buffer)) ||
+ if(((len + padding) != ssh_buffer_get_len(session->in_buffer)) ||
((len + padding) < sizeof(uint32_t))) {
SSH_LOG(SSH_LOG_RARE, "no crc32 in packet");
ssh_set_error(session, SSH_FATAL, "no crc32 in packet");
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index cb04c11..f4104eb 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -175,7 +175,7 @@ int ssh_packet_hmac_verify(ssh_session session, ssh_buffer buffer,
seq = htonl(session->recv_seq);
hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
- hmac_update(ctx, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
+ hmac_update(ctx, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
hmac_final(ctx, hmacbuf, &len);
#ifdef DEBUG_CRYPTO
diff --git a/src/pcap.c b/src/pcap.c
index 2055132..043326b 100644
--- a/src/pcap.c
+++ b/src/pcap.c
@@ -144,7 +144,7 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
uint32_t len;
if(pcap == NULL || pcap->output==NULL)
return SSH_ERROR;
- len=ssh_buffer_get_rest_len(packet);
+ len=ssh_buffer_get_len(packet);
err=fwrite(ssh_buffer_get(packet),len,1,pcap->output);
if(err<0)
return SSH_ERROR;
@@ -171,7 +171,7 @@ int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t o
if (err < 0) {
goto error;
}
- err = ssh_buffer_add_u32(header,htonl(ssh_buffer_get_rest_len(packet)));
+ err = ssh_buffer_add_u32(header,htonl(ssh_buffer_get_len(packet)));
if (err < 0) {
goto error;
}
diff --git a/src/pki.c b/src/pki.c
index 334382f..b7a73d4 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -1467,13 +1467,13 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
return SSH_ERROR;
}
- str = ssh_string_new(ssh_buffer_get_rest_len(buf));
+ str = ssh_string_new(ssh_buffer_get_len(buf));
if (str == NULL) {
ssh_buffer_free(buf);
return SSH_ERROR;
}
- ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf));
+ ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_len(buf));
ssh_buffer_free(buf);
*sig_blob = str;
@@ -1629,7 +1629,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
evp_update(ctx, session_id, ssh_string_len(session_id) + 4);
- evp_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_rest_len(sigbuf));
+ evp_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_len(sigbuf));
evp_final(ctx, ehash, &elen);
#ifdef DEBUG_CRYPTO
@@ -1651,7 +1651,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
rc = ssh_buffer_pack(buf,
"SP",
session_id,
- ssh_buffer_get_rest_len(sigbuf), ssh_buffer_get(sigbuf));
+ ssh_buffer_get_len(sigbuf), ssh_buffer_get(sigbuf));
if (rc != SSH_OK) {
ssh_string_free(session_id);
ssh_buffer_free(buf);
@@ -1673,7 +1673,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
sha1_update(ctx, session_id, ssh_string_len(session_id) + 4);
- sha1_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_rest_len(sigbuf));
+ sha1_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_len(sigbuf));
sha1_final(hash, ctx);
#ifdef DEBUG_CRYPTO
diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c
index 1f2ed97..9653bf0 100644
--- a/src/pki_container_openssh.c
+++ b/src/pki_container_openssh.c
@@ -387,7 +387,7 @@ ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
comment = ssh_buffer_get_ssh_string(privkey_buffer);
SAFE_FREE(comment);
/* verify that the remaining data is correct padding */
- for (i=1; ssh_buffer_get_rest_len(privkey_buffer) > 0; ++i){
+ for (i=1; ssh_buffer_get_len(privkey_buffer) > 0; ++i){
ssh_buffer_get_u8(privkey_buffer, &padding);
if (padding != i){
ssh_key_free(key);
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index 9df6898..e84f3e8 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -1034,12 +1034,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
- str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
+ str = ssh_string_new(ssh_buffer_get_len(buffer));
if (str == NULL) {
goto fail;
}
- rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
+ rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
if (rc < 0) {
goto fail;
}
@@ -1238,13 +1238,13 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
return NULL;
}
- sig_blob = ssh_string_new(ssh_buffer_get_rest_len(b));
+ sig_blob = ssh_string_new(ssh_buffer_get_len(b));
if (sig_blob == NULL) {
ssh_buffer_free(b);
return NULL;
}
- ssh_string_fill(sig_blob, ssh_buffer_get(b), ssh_buffer_get_rest_len(b));
+ ssh_string_fill(sig_blob, ssh_buffer_get(b), ssh_buffer_get_len(b));
ssh_buffer_free(b);
break;
}
@@ -1449,7 +1449,7 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey,
}
s = buffer_get_ssh_string(b);
- rlen = ssh_buffer_get_rest_len(b);
+ rlen = ssh_buffer_get_len(b);
ssh_buffer_free(b);
if (s == NULL) {
ssh_signature_free(sig);
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 6dadf3f..1c44efb 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -1300,12 +1300,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
- str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
+ str = ssh_string_new(ssh_buffer_get_len(buffer));
if (str == NULL) {
goto fail;
}
- rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
+ rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
if (rc < 0) {
goto fail;
}
diff --git a/src/sftp.c b/src/sftp.c
index 6f7e726..69d9584 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -282,20 +282,20 @@ int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
return -1;
}
- size = htonl(ssh_buffer_get_rest_len(payload));
+ size = htonl(ssh_buffer_get_len(payload));
if (ssh_buffer_prepend_data(payload, &size, sizeof(uint32_t)) < 0) {
ssh_set_error_oom(sftp->session);
return -1;
}
size = ssh_channel_write(sftp->channel, ssh_buffer_get(payload),
- ssh_buffer_get_rest_len(payload));
+ ssh_buffer_get_len(payload));
if (size < 0) {
return -1;
- } else if((uint32_t) size != ssh_buffer_get_rest_len(payload)) {
+ } else if((uint32_t) size != ssh_buffer_get_len(payload)) {
SSH_LOG(SSH_LOG_PACKET,
"Had to write %d bytes, wrote only %d",
- ssh_buffer_get_rest_len(payload),
+ ssh_buffer_get_len(payload),
size);
}
@@ -461,7 +461,7 @@ static sftp_message sftp_get_message(sftp_packet packet) {
msg->packet_type);
if (ssh_buffer_add_data(msg->payload, ssh_buffer_get(packet->payload),
- ssh_buffer_get_rest_len(packet->payload)) < 0) {
+ ssh_buffer_get_len(packet->payload)) < 0) {
ssh_set_error_oom(sftp->session);
sftp_message_free(msg);
return NULL;
@@ -1968,7 +1968,7 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
ssh_buffer_free(buffer);
return -1;
}
- packetlen=ssh_buffer_get_rest_len(buffer);
+ packetlen=ssh_buffer_get_len(buffer);
len = sftp_packet_write(file->sftp, SSH_FXP_WRITE, buffer);
ssh_buffer_free(buffer);
if (len < 0) {
diff --git a/src/sftpserver.c b/src/sftpserver.c
index 51a4ba7..5fe831a 100644
--- a/src/sftpserver.c
+++ b/src/sftpserver.c
@@ -66,7 +66,7 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
msg->complete_message = ssh_buffer_new();
ssh_buffer_add_data(msg->complete_message,
ssh_buffer_get(payload),
- ssh_buffer_get_rest_len(payload));
+ ssh_buffer_get_len(payload));
ssh_buffer_get_u32(payload, &msg->id);
@@ -378,7 +378,7 @@ int sftp_reply_names(sftp_client_message msg) {
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
ssh_buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
ssh_buffer_add_data(out, ssh_buffer_get(msg->attrbuf),
- ssh_buffer_get_rest_len(msg->attrbuf)) < 0 ||
+ ssh_buffer_get_len(msg->attrbuf)) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
ssh_buffer_free(out);
ssh_buffer_free(msg->attrbuf);
diff --git a/src/socket.c b/src/socket.c
index 06ea9e6..823be86 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -291,7 +291,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
if (s->callbacks && s->callbacks->data) {
do {
r = s->callbacks->data(ssh_buffer_get(s->in_buffer),
- ssh_buffer_get_rest_len(s->in_buffer),
+ ssh_buffer_get_len(s->in_buffer),
s->callbacks->userdata);
ssh_buffer_pass_bytes(s->in_buffer, r);
} while ((r > 0) && (s->state == SSH_SOCKET_CONNECTED));
@@ -330,7 +330,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
}
/* If buffered data is pending, write it */
- if (ssh_buffer_get_rest_len(s->out_buffer) > 0) {
+ if (ssh_buffer_get_len(s->out_buffer) > 0) {
ssh_socket_nonblocking_flush(s);
} else if (s->callbacks && s->callbacks->controlflow) {
/* Otherwise advertise the upper level that write can be done */
@@ -650,7 +650,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
return SSH_ERROR;
}
- len = ssh_buffer_get_rest_len(s->out_buffer);
+ len = ssh_buffer_get_len(s->out_buffer);
if (!s->write_wontblock && s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
@@ -681,7 +681,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
}
/* Is there some data pending? */
- len = ssh_buffer_get_rest_len(s->out_buffer);
+ len = ssh_buffer_get_len(s->out_buffer);
if (s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
@@ -721,7 +721,7 @@ int ssh_socket_data_writable(ssh_socket s) {
int ssh_socket_buffered_write_bytes(ssh_socket s){
if(s==NULL || s->out_buffer == NULL)
return 0;
- return ssh_buffer_get_rest_len(s->out_buffer);
+ return ssh_buffer_get_len(s->out_buffer);
}
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c
index d4cef64..e29b572 100644
--- a/tests/unittests/torture_buffer.c
+++ b/tests/unittests/torture_buffer.c
@@ -36,8 +36,8 @@ static void torture_growing_buffer(void **state) {
for(i=0;i<LIMIT;++i){
ssh_buffer_add_data(buffer,"A",1);
if(buffer->used >= 128){
- if(ssh_buffer_get_rest_len(buffer) * 2 < buffer->allocated){
- assert_true(ssh_buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
+ if(ssh_buffer_get_len(buffer) * 2 < buffer->allocated){
+ assert_true(ssh_buffer_get_len(buffer) * 2 >= buffer->allocated);
}
}
}
@@ -58,8 +58,8 @@ static void torture_growing_buffer_shifting(void **state) {
ssh_buffer_get_u8(buffer,&c);
ssh_buffer_add_data(buffer,"A",1);
if(buffer->used >= 128){
- if(ssh_buffer_get_rest_len(buffer) * 4 < buffer->allocated){
- assert_true(ssh_buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
+ if(ssh_buffer_get_len(buffer) * 4 < buffer->allocated){
+ assert_true(ssh_buffer_get_len(buffer) * 4 >= buffer->allocated);
return;
}
}
@@ -74,25 +74,25 @@ static void torture_buffer_prepend(void **state) {
uint32_t v;
ssh_buffer_add_data(buffer,"abcdef",6);
ssh_buffer_prepend_data(buffer,"xyz",3);
- assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
+ assert_int_equal(ssh_buffer_get_len(buffer),9);
assert_memory_equal(ssh_buffer_get(buffer), "xyzabcdef", 9);
/* Now remove 4 bytes and see if we can replace them */
ssh_buffer_get_u32(buffer,&v);
- assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
+ assert_int_equal(ssh_buffer_get_len(buffer),5);
assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
ssh_buffer_prepend_data(buffer,"aris",4);
- assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
+ assert_int_equal(ssh_buffer_get_len(buffer),9);
assert_memory_equal(ssh_buffer_get(buffer), "arisbcdef", 9);
/* same thing but we add 5 bytes now */
ssh_buffer_get_u32(buffer,&v);
- assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
+ assert_int_equal(ssh_buffer_get_len(buffer),5);
assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
ssh_buffer_prepend_data(buffer,"12345",5);
- assert_int_equal(ssh_buffer_get_rest_len(buffer),10);
+ assert_int_equal(ssh_buffer_get_len(buffer),10);
assert_memory_equal(ssh_buffer_get(buffer), "12345bcdef", 10);
}
@@ -155,7 +155,7 @@ static void torture_ssh_buffer_add_format(void **state) {
rc=ssh_buffer_pack(buffer, "bwdqSsPt",b,w,d,q,s,"rocks",7,"So much","Fun!");
assert_int_equal(rc, SSH_OK);
- len = ssh_buffer_get_rest_len(buffer);
+ len = ssh_buffer_get_len(buffer);
assert_int_equal(len, sizeof(verif) - 1);
assert_memory_equal(ssh_buffer_get(buffer), verif, sizeof(verif) -1);
@@ -199,7 +199,7 @@ static void torture_ssh_buffer_get_format(void **state) {
assert_true(s2 != NULL);
assert_memory_equal(s2, "So much", 7);
- len = ssh_buffer_get_rest_len(buffer);
+ len = ssh_buffer_get_len(buffer);
assert_int_equal(len, 0);
SAFE_FREE(s);
SAFE_FREE(s1);
--
2.4.3
From 32b0c44f9651182f778ed338ae9ef822d552d165 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:21:42 +0200
Subject: [PATCH 18/24 v2] buffer: remove ssh_buffer_get_rest_len()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 5 ++---
src/buffer.c | 17 +----------------
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 15294b2..656db95 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -43,7 +43,6 @@ struct ssh_buffer_struct {
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
-LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
LIBSSH_API ssh_buffer ssh_buffer_new(void);
void ssh_buffer_set_secure(ssh_buffer buffer);
int ssh_buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
@@ -80,8 +79,8 @@ int ssh_buffer_reinit(ssh_buffer buffer);
/* ssh_buffer_get_rest returns a pointer to the current position into the buffer */
void *ssh_buffer_get(ssh_buffer buffer);
-/* ssh_buffer_get_rest_len returns the number of bytes which can be read */
-uint32_t ssh_buffer_get_rest_len(ssh_buffer buffer);
+/* ssh_buffer_get_len returns the number of bytes which can be read */
+LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
/* buffer_read_*() returns the number of bytes read, except for ssh strings */
int ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
diff --git a/src/buffer.c b/src/buffer.c
index 722efb6..801cbd5 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -467,21 +467,6 @@ void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
}
/**
- * @brief Get the length of the buffer, not counting position.
- *
- * @param[in] buffer The buffer to get the length from.
- *
- * @return The length of the buffer.
- *
- * @see ssh_buffer_get()
- */
-uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
- return ssh_buffer_get_rest_len(buffer);
-}
-
-/**
- * @internal
- *
* @brief Get the length of the buffer from the current position.
*
* @param[in] buffer The buffer to get the length from.
@@ -490,7 +475,7 @@ uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
*
* @see ssh_buffer_get()
*/
-uint32_t ssh_buffer_get_rest_len(struct ssh_buffer_struct *buffer){
+uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
buffer_verify(buffer);
return buffer->used - buffer->pos;
}
--
2.4.3
From 03809be0d4266b9796bb52fb9ef9c45c2d68e077 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:25:56 +0200
Subject: [PATCH 19/24 v2] buffer: use ssh_buffer_get() instead of
ssh_buffer_get_begin()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This commit is a preparatory stage for removing ssh_buffer_get_begin().
Note that removing ssh_buffer_get_begin() doesn't break API
compatibility, as this functions has never been exposed (it only has the
LIBSSH_API prefix).
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
examples/sample.c | 4 ++--
src/dh.c | 2 +-
src/gssapi.c | 6 +++---
src/kex1.c | 2 +-
src/legacy.c | 2 +-
src/packet1.c | 16 ++++++++--------
src/pki.c | 2 +-
src/pki_container_openssh.c | 12 ++++++------
src/pki_gcrypt.c | 8 ++++----
9 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/examples/sample.c b/examples/sample.c
index b716a1b..247004e 100644
--- a/examples/sample.c
+++ b/examples/sample.c
@@ -252,7 +252,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
- if (write(1,ssh_buffer_get_begin(readbuf),lus) < 0) {
+ if (write(1,ssh_buffer_get(readbuf),lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
@@ -268,7 +268,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
- if (write(2,ssh_buffer_get_begin(readbuf),lus) < 0) {
+ if (write(2,ssh_buffer_get(readbuf),lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
diff --git a/src/dh.c b/src/dh.c
index 67d1f4c..1291c5f 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -630,7 +630,7 @@ int ssh_make_sessionid(ssh_session session) {
}
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("hash buffer", ssh_buffer_get_begin(buf), ssh_buffer_get_len(buf));
+ ssh_print_hexa("hash buffer", ssh_buffer_get(buf), ssh_buffer_get_len(buf));
#endif
switch (session->next_crypto->kex_type) {
diff --git a/src/gssapi.c b/src/gssapi.c
index 1c5a2a4..ff0dac0 100644
--- a/src/gssapi.c
+++ b/src/gssapi.c
@@ -427,14 +427,14 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_mic)
}
if (ssh_callbacks_exists(session->server_callbacks, gssapi_verify_mic_function)){
int rc = session->server_callbacks->gssapi_verify_mic_function(session, mic_token,
- ssh_buffer_get_begin(mic_buffer), ssh_buffer_get_len(mic_buffer),
+ ssh_buffer_get(mic_buffer), ssh_buffer_get_len(mic_buffer),
session->server_callbacks->userdata);
if (rc != SSH_OK) {
goto error;
}
} else {
mic_buf.length = ssh_buffer_get_len(mic_buffer);
- mic_buf.value = ssh_buffer_get_begin(mic_buffer);
+ mic_buf.value = ssh_buffer_get(mic_buffer);
mic_token_buf.length = ssh_string_len(mic_token);
mic_token_buf.value = ssh_string_data(mic_token);
@@ -792,7 +792,7 @@ static int ssh_gssapi_send_mic(ssh_session session){
return SSH_ERROR;
}
mic_buf.length = ssh_buffer_get_len(mic_buffer);
- mic_buf.value = ssh_buffer_get_begin(mic_buffer);
+ mic_buf.value = ssh_buffer_get(mic_buffer);
maj_stat = gss_get_mic(&min_stat,session->gssapi->ctx, GSS_C_QOP_DEFAULT, &mic_buf, &mic_token_buf);
if (GSS_ERROR(maj_stat)){
diff --git a/src/kex1.c b/src/kex1.c
index 10e6327..1691984 100644
--- a/src/kex1.c
+++ b/src/kex1.c
@@ -66,7 +66,7 @@ static ssh_string make_rsa1_string(ssh_string e, ssh_string n){
goto error;
}
- ssh_string_fill(ret, ssh_buffer_get_begin(buffer), ssh_buffer_get_len(buffer));
+ ssh_string_fill(ret, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
error:
ssh_buffer_free(buffer);
ssh_string_free(rsa);
diff --git a/src/legacy.c b/src/legacy.c
index 15f287a..3f09992 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -145,7 +145,7 @@ void buffer_free(ssh_buffer buffer){
ssh_buffer_free(buffer);
}
void *buffer_get(ssh_buffer buffer){
- return ssh_buffer_get_begin(buffer);
+ return ssh_buffer_get(buffer);
}
uint32_t buffer_get_len(ssh_buffer buffer){
return ssh_buffer_get_len(buffer);
diff --git a/src/packet1.c b/src/packet1.c
index 25fc44b..ff33ca1 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -160,7 +160,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
}
processed += to_be_read;
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("read packet:", ssh_buffer_get_begin(session->in_buffer),
+ ssh_print_hexa("read packet:", ssh_buffer_get(session->in_buffer),
ssh_buffer_get_len(session->in_buffer));
#endif
if (session->current_crypto) {
@@ -172,7 +172,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
if (buffer_len > 0) {
int rc;
rc = ssh_packet_decrypt(session,
- ssh_buffer_get_begin(session->in_buffer),
+ ssh_buffer_get(session->in_buffer),
buffer_len);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "Packet decrypt error");
@@ -181,7 +181,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
}
}
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("read packet decrypted:", ssh_buffer_get_begin(session->in_buffer),
+ ssh_print_hexa("read packet decrypted:", ssh_buffer_get(session->in_buffer),
ssh_buffer_get_len(session->in_buffer));
#endif
SSH_LOG(SSH_LOG_PACKET, "%d bytes padding", padding);
@@ -293,7 +293,7 @@ int ssh_packet_send1(ssh_session session) {
goto error;
}
- crc = ssh_crc32((char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
+ crc = ssh_crc32((char *)ssh_buffer_get(session->out_buffer) + sizeof(uint32_t),
ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
if (ssh_buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) {
@@ -301,20 +301,20 @@ int ssh_packet_send1(ssh_session session) {
}
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("Clear packet", ssh_buffer_get_begin(session->out_buffer),
+ ssh_print_hexa("Clear packet", ssh_buffer_get(session->out_buffer),
ssh_buffer_get_len(session->out_buffer));
#endif
/* session->out_buffer should have more than sizeof(uint32_t) bytes
in it as required for ssh_packet_encrypt */
- ssh_packet_encrypt(session, (unsigned char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
+ ssh_packet_encrypt(session, (unsigned char *)ssh_buffer_get(session->out_buffer) + sizeof(uint32_t),
ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("encrypted packet",ssh_buffer_get_begin(session->out_buffer),
+ ssh_print_hexa("encrypted packet",ssh_buffer_get(session->out_buffer),
ssh_buffer_get_len(session->out_buffer));
#endif
- rc=ssh_socket_write(session->socket, ssh_buffer_get_begin(session->out_buffer),
+ rc=ssh_socket_write(session->socket, ssh_buffer_get(session->out_buffer),
ssh_buffer_get_len(session->out_buffer));
if(rc== SSH_ERROR) {
goto error;
diff --git a/src/pki.c b/src/pki.c
index b7a73d4..de25643 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -1659,7 +1659,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
sig = pki_do_sign(privkey,
- ssh_buffer_get_begin(buf),
+ ssh_buffer_get(buf),
ssh_buffer_get_len(buf));
ssh_buffer_free(buf);
} else {
diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c
index 9653bf0..a3e6654 100644
--- a/src/pki_container_openssh.c
+++ b/src/pki_container_openssh.c
@@ -543,8 +543,8 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer,
key_material,
key_material + cipher.keysize/8);
cipher.encrypt(&cipher,
- ssh_buffer_get_begin(privkey_buffer),
- ssh_buffer_get_begin(privkey_buffer),
+ ssh_buffer_get(privkey_buffer),
+ ssh_buffer_get(privkey_buffer),
ssh_buffer_get_len(privkey_buffer));
ssh_cipher_clear(&cipher);
BURN_BUFFER(passphrase_buffer, sizeof(passphrase_buffer));
@@ -642,7 +642,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
goto error;
}
memcpy(ssh_string_data(kdf_options),
- ssh_buffer_get_begin(kdf_buf),
+ ssh_buffer_get(kdf_buf),
ssh_buffer_get_len(kdf_buf));
ssh_buffer_free(kdf_buf);
rc = pki_private_key_encrypt(privkey_buffer,
@@ -670,12 +670,12 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
pubkey_s,
(uint32_t)ssh_buffer_get_len(privkey_buffer),
/* rest of buffer is a string */
- (size_t)ssh_buffer_get_len(privkey_buffer), ssh_buffer_get_begin(privkey_buffer));
+ (size_t)ssh_buffer_get_len(privkey_buffer), ssh_buffer_get(privkey_buffer));
if (rc != SSH_OK) {
goto error;
}
- b64 = bin_to_base64(ssh_buffer_get_begin(buffer),
+ b64 = bin_to_base64(ssh_buffer_get(buffer),
ssh_buffer_get_len(buffer));
if (b64 == NULL){
goto error;
@@ -712,7 +712,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
error:
if (privkey_buffer != NULL) {
- void *bufptr = ssh_buffer_get_begin(privkey_buffer);
+ void *bufptr = ssh_buffer_get(privkey_buffer);
BURN_BUFFER(bufptr, ssh_buffer_get_len(privkey_buffer));
ssh_buffer_free(privkey_buffer);
}
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 1c44efb..3b05da9 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -152,7 +152,7 @@ static int asn1_check_sequence(ssh_buffer buffer) {
size = asn1_get_len(buffer);
if ((padding = ssh_buffer_get_len(buffer) - size) > 0) {
for (i = ssh_buffer_get_len(buffer) - size,
- j = (unsigned char*)ssh_buffer_get_begin(buffer) + size + buffer->pos;
+ j = (unsigned char*)ssh_buffer_get(buffer) + size;
i;
i--, j++)
{
@@ -235,12 +235,12 @@ static int privatekey_decrypt(int algo, int mode, unsigned int key_len,
|| gcry_cipher_setiv(cipher, iv, iv_len)
|| (tmp = malloc(ssh_buffer_get_len(data) * sizeof (char))) == NULL
|| gcry_cipher_decrypt(cipher, tmp, ssh_buffer_get_len(data),
- ssh_buffer_get_begin(data), ssh_buffer_get_len(data))) {
+ ssh_buffer_get(data), ssh_buffer_get_len(data))) {
gcry_cipher_close(cipher);
return -1;
}
- memcpy(ssh_buffer_get_begin(data), tmp, ssh_buffer_get_len(data));
+ memcpy(ssh_buffer_get(data), tmp, ssh_buffer_get_len(data));
SAFE_FREE(tmp);
gcry_cipher_close(cipher);
@@ -418,7 +418,7 @@ static ssh_buffer privatekey_string_to_buffer(const char *pkey, int type,
return NULL;
}
- out = base64_to_bin(ssh_buffer_get_begin(buffer));
+ out = base64_to_bin(ssh_buffer_get(buffer));
ssh_buffer_free(buffer);
if (out == NULL) {
SAFE_FREE(iv);
--
2.4.3
From 012b68184c3356a6a0b0241298f85316a7740b16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 00:46:04 +0200
Subject: [PATCH 20/24 v2] buffer: remove ssh_buffer_get_begin()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Note that removing ssh_buffer_get_begin() doesn't break API
compatibility, as this functions has never been exposed (it only
has the LIBSSH_API prefix).
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 1 -
src/buffer.c | 17 -----------------
2 files changed, 18 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 656db95..8134478 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -42,7 +42,6 @@ struct ssh_buffer_struct {
#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
-LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
LIBSSH_API ssh_buffer ssh_buffer_new(void);
void ssh_buffer_set_secure(ssh_buffer buffer);
int ssh_buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
diff --git a/src/buffer.c b/src/buffer.c
index 801cbd5..0b09e77 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -435,23 +435,6 @@ int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
}
/**
- * @brief Get a pointer on the head of a buffer.
- *
- * @param[in] buffer The buffer to get the head pointer.
- *
- * @return A data pointer on the head. It doesn't take the position
- * into account.
- *
- * @warning Don't expect data to be nul-terminated.
- *
- * @see ssh_buffer_get()
- * @see ssh_buffer_get_len()
- */
-void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
- return buffer->data;
-}
-
-/**
* @internal
*
* @brief Get a pointer to the head of a buffer at the current position.
--
2.4.3
From 2c43c73382ac1c55bc736374b2cbeb19bae0b745 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:33:23 +0200
Subject: [PATCH 21/24 v2] libssh.h: move LIBSSH_API buffer' functions to libssh.h
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 4 ----
include/libssh/libssh.h | 4 ++++
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 8134478..a410bc5 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -41,8 +41,6 @@ struct ssh_buffer_struct {
#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
-LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
-LIBSSH_API ssh_buffer ssh_buffer_new(void);
void ssh_buffer_set_secure(ssh_buffer buffer);
int ssh_buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
int ssh_buffer_add_u8(ssh_buffer buffer, uint8_t data);
@@ -78,8 +76,6 @@ int ssh_buffer_reinit(ssh_buffer buffer);
/* ssh_buffer_get_rest returns a pointer to the current position into the buffer */
void *ssh_buffer_get(ssh_buffer buffer);
-/* ssh_buffer_get_len returns the number of bytes which can be read */
-LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
/* buffer_read_*() returns the number of bytes read, except for ssh strings */
int ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index aff0190..f4356bd 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -678,6 +678,10 @@ LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
+LIBSSH_API ssh_buffer ssh_buffer_new(void);
+LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
+LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
+
#ifndef LIBSSH_LEGACY_0_4
#include "libssh/legacy.h"
#endif
--
2.4.3
From ad414ebb66c31633d8362fbd82b102cc397522d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:41:36 +0200
Subject: [PATCH 22/24 v2] buffer: expose ssh_buffer_reinit()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 1 -
include/libssh/libssh.h | 1 +
src/buffer.c | 2 --
3 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index a410bc5..3bdd675 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -72,7 +72,6 @@ int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
int ssh_buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
int ssh_buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
-int ssh_buffer_reinit(ssh_buffer buffer);
/* ssh_buffer_get_rest returns a pointer to the current position into the buffer */
void *ssh_buffer_get(ssh_buffer buffer);
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index f4356bd..654f0ee 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -680,6 +680,7 @@ LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
LIBSSH_API ssh_buffer ssh_buffer_new(void);
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
+LIBSSH_API int ssh_buffer_reinit(ssh_buffer buffer);
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
#ifndef LIBSSH_LEGACY_0_4
diff --git a/src/buffer.c b/src/buffer.c
index 0b09e77..24a428c 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -184,8 +184,6 @@ static void buffer_shift(ssh_buffer buffer){
}
/**
- * @internal
- *
* @brief Reinitialize a SSH buffer.
*
* @param[in] buffer The buffer to reinitialize.
--
2.4.3
From bd53e5752fa5db52b9ca6418ad1cccbe999b0edb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 01:43:47 +0200
Subject: [PATCH 23/24 v2] buffer: expose ssh_buffer_{add,get}_data()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 2 --
include/libssh/libssh.h | 2 ++
src/buffer.c | 4 ----
3 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 3bdd675..abfcc74 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -47,7 +47,6 @@ int ssh_buffer_add_u8(ssh_buffer buffer, uint8_t data);
int ssh_buffer_add_u16(ssh_buffer buffer, uint16_t data);
int ssh_buffer_add_u32(ssh_buffer buffer, uint32_t data);
int ssh_buffer_add_u64(ssh_buffer buffer, uint64_t data);
-int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
const char *format,
@@ -81,7 +80,6 @@ int ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
int ssh_buffer_get_u32(ssh_buffer buffer, uint32_t *data);
int ssh_buffer_get_u64(ssh_buffer buffer, uint64_t *data);
-uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
/* ssh_buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
ssh_string ssh_buffer_get_ssh_string(ssh_buffer buffer);
/* ssh_gets a string out of a SSH-1 mpint */
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 654f0ee..d585d20 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -681,6 +681,8 @@ LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
LIBSSH_API ssh_buffer ssh_buffer_new(void);
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
LIBSSH_API int ssh_buffer_reinit(ssh_buffer buffer);
+LIBSSH_API int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
+LIBSSH_API uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
#ifndef LIBSSH_LEGACY_0_4
diff --git a/src/buffer.c b/src/buffer.c
index 24a428c..16e324f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -206,8 +206,6 @@ int ssh_buffer_reinit(struct ssh_buffer_struct *buffer)
}
/**
- * @internal
- *
* @brief Add data at the tail of a buffer.
*
* @param[in] buffer The buffer to add the data.
@@ -515,8 +513,6 @@ uint32_t ssh_buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t le
}
/**
- * @internal
- *
* @brief Get the remaining data out of the buffer and adjust the read pointer.
*
* @param[in] buffer The buffer to read.
--
2.4.3
From edbbe0055700936f624fd680226620ddca3a58eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@xxxxxxxxxx>
Date: Fri, 25 Sep 2015 02:06:08 +0200
Subject: [PATCH 24/24 v2] buffer: expose ssh_buffer_get()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
include/libssh/buffer.h | 3 ---
include/libssh/libssh.h | 1 +
src/buffer.c | 2 --
3 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index abfcc74..d4cb071 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -72,9 +72,6 @@ int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
int ssh_buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
int ssh_buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
-/* ssh_buffer_get_rest returns a pointer to the current position into the buffer */
-void *ssh_buffer_get(ssh_buffer buffer);
-
/* buffer_read_*() returns the number of bytes read, except for ssh strings */
int ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
int ssh_buffer_get_u32(ssh_buffer buffer, uint32_t *data);
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index d585d20..b1240e6 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -683,6 +683,7 @@ LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
LIBSSH_API int ssh_buffer_reinit(ssh_buffer buffer);
LIBSSH_API int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
LIBSSH_API uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
+LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer);
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
#ifndef LIBSSH_LEGACY_0_4
diff --git a/src/buffer.c b/src/buffer.c
index 16e324f..529db75 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -431,8 +431,6 @@ int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
}
/**
- * @internal
- *
* @brief Get a pointer to the head of a buffer at the current position.
*
* @param[in] buffer The buffer to get the head pointer.
--
2.4.3
| [PATCH 00/24] Adding namespace, fixing some warnings and exposing some buffer functions | Fabiano Fidêncio <fidencio@xxxxxxxxxx> |