A cleanup effort: libssh2_ prefixes only on external APIs. Use _libssh2_ prefix

for library-wide internal functions. Don't use any of those on static functions.
I also did some comments and whitespace changes.
This commit is contained in:
Daniel Stenberg 2009-03-17 13:48:35 +00:00
parent f2fa02c575
commit cc5e952fa0
16 changed files with 1063 additions and 1093 deletions

File diff suppressed because it is too large Load Diff

View File

@ -44,18 +44,20 @@
* none *
******** */
/* {{{ libssh2_comp_method_none_comp
/*
* comp_method_none_comp
*
* Minimalist compression: Absolutely none
*/
static int
libssh2_comp_method_none_comp(LIBSSH2_SESSION * session,
int compress,
unsigned char **dest,
unsigned long *dest_len,
unsigned long payload_limit,
int *free_dest,
const unsigned char *src,
unsigned long src_len, void **abstract)
comp_method_none_comp(LIBSSH2_SESSION * session,
int compress,
unsigned char **dest,
unsigned long *dest_len,
unsigned long payload_limit,
int *free_dest,
const unsigned char *src,
unsigned long src_len, void **abstract)
{
(void) session;
(void) compress;
@ -71,10 +73,10 @@ libssh2_comp_method_none_comp(LIBSSH2_SESSION * session,
/* }}} */
static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
static const LIBSSH2_COMP_METHOD comp_method_none = {
"none",
NULL,
libssh2_comp_method_none_comp,
comp_method_none_comp,
NULL
};
@ -326,7 +328,7 @@ static const LIBSSH2_COMP_METHOD libssh2_comp_method_zlib = {
*********************** */
static const LIBSSH2_COMP_METHOD *_libssh2_comp_methods[] = {
&libssh2_comp_method_none,
&comp_method_none,
#ifdef LIBSSH2_HAVE_ZLIB
&libssh2_comp_method_zlib,
#endif /* LIBSSH2_HAVE_ZLIB */

View File

@ -38,27 +38,26 @@
#include "libssh2_priv.h"
#ifdef LIBSSH2_CRYPT_NONE
/* {{{ libssh2_crypt_none_crypt
/* crypt_none_crypt
* Minimalist cipher: VERY secure *wink*
*/
static int
libssh2_crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf,
crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf,
void **abstract)
{
/* Do nothing to the data! */
return 0;
}
/* }}} */
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
"none",
8, /* blocksize (SSH2 defines minimum blocksize as 8) */
0, /* iv_len */
0, /* secret_len */
0, /* flags */
8, /* blocksize (SSH2 defines minimum blocksize as 8) */
0, /* iv_len */
0, /* secret_len */
0, /* flags */
NULL,
libssh2_crypt_none_crypt,
crypt_none_crypt,
NULL
};
#endif /* LIBSSH2_CRYPT_NONE */
@ -66,16 +65,16 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
struct crypt_ctx
{
int encrypt;
_libssh2_cipher_type(algo);
_libssh2_cipher_type(algo);
_libssh2_cipher_ctx h;
};
static int
_libssh2_init(LIBSSH2_SESSION * session,
const LIBSSH2_CRYPT_METHOD * method,
unsigned char *iv, int *free_iv,
unsigned char *secret, int *free_secret,
int encrypt, void **abstract)
crypt_init(LIBSSH2_SESSION * session,
const LIBSSH2_CRYPT_METHOD * method,
unsigned char *iv, int *free_iv,
unsigned char *secret, int *free_secret,
int encrypt, void **abstract)
{
struct crypt_ctx *ctx = LIBSSH2_ALLOC(session,
sizeof(struct crypt_ctx));
@ -95,7 +94,7 @@ _libssh2_init(LIBSSH2_SESSION * session,
}
static int
_libssh2_encrypt(LIBSSH2_SESSION * session, unsigned char *block,
crypt_encrypt(LIBSSH2_SESSION * session, unsigned char *block,
void **abstract)
{
struct crypt_ctx *cctx = *(struct crypt_ctx **) abstract;
@ -104,7 +103,7 @@ _libssh2_encrypt(LIBSSH2_SESSION * session, unsigned char *block,
}
static int
_libssh2_dtor(LIBSSH2_SESSION * session, void **abstract)
crypt_dtor(LIBSSH2_SESSION * session, void **abstract)
{
struct crypt_ctx **cctx = (struct crypt_ctx **) abstract;
if (cctx && *cctx) {
@ -122,9 +121,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes128_cbc = {
16, /* initial value length */
16, /* secret length -- 16*8 == 128bit */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_aes128
};
@ -134,9 +133,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes192_cbc = {
16, /* initial value length */
24, /* secret length -- 24*8 == 192bit */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_aes192
};
@ -146,9 +145,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes256_cbc = {
16, /* initial value length */
32, /* secret length -- 32*8 == 256bit */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_aes256
};
@ -160,9 +159,9 @@ static const LIBSSH2_CRYPT_METHOD
16, /* initial value length */
32, /* secret length -- 32*8 == 256bit */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_aes256
};
#endif /* LIBSSH2_AES */
@ -174,9 +173,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_blowfish_cbc = {
8, /* initial value length */
16, /* secret length */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_blowfish
};
#endif /* LIBSSH2_BLOWFISH */
@ -188,9 +187,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_arcfour = {
8, /* initial value length */
16, /* secret length */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_arcfour
};
#endif /* LIBSSH2_RC4 */
@ -202,9 +201,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_cast128_cbc = {
8, /* initial value length */
16, /* secret length */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_cast5
};
#endif /* LIBSSH2_CAST */
@ -216,9 +215,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = {
8, /* initial value length */
24, /* secret length */
0, /* flags */
&_libssh2_init,
&_libssh2_encrypt,
&_libssh2_dtor,
&crypt_init,
&crypt_encrypt,
&crypt_dtor,
_libssh2_cipher_3des
};
#endif

View File

@ -47,17 +47,19 @@
* ssh-rsa *
*********** */
static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session,
void **abstract);
static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session,
void **abstract);
/* {{{ libssh2_hostkey_method_ssh_rsa_init
/*
* hostkey_method_ssh_rsa_init
*
* Initialize the server hostkey working area with e/n pair
*/
static int
libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
const unsigned char *hostkey_data,
unsigned long hostkey_data_len,
void **abstract)
hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
const unsigned char *hostkey_data,
unsigned long hostkey_data_len,
void **abstract)
{
libssh2_rsa_ctx *rsactx;
const unsigned char *s, *e, *n;
@ -66,12 +68,12 @@ libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
(void) hostkey_data_len;
if (*abstract) {
libssh2_hostkey_method_ssh_rsa_dtor(session, abstract);
hostkey_method_ssh_rsa_dtor(session, abstract);
*abstract = NULL;
}
s = hostkey_data;
len = libssh2_ntohu32(s);
len = _libssh2_ntohu32(s);
s += 4;
if (len != 7 || strncmp((char *) s, "ssh-rsa", 7) != 0) {
@ -79,12 +81,12 @@ libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
}
s += 7;
e_len = libssh2_ntohu32(s);
e_len = _libssh2_ntohu32(s);
s += 4;
e = s;
s += e_len;
n_len = libssh2_ntohu32(s);
n_len = _libssh2_ntohu32(s);
s += 4;
n = s;
s += n_len;
@ -98,23 +100,23 @@ libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
return 0;
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_rsa_initPEM
/*
* hostkey_method_ssh_rsa_initPEM
*
* Load a Private Key from a PEM file
*/
static int
libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION * session,
const char *privkeyfile,
unsigned const char *passphrase,
void **abstract)
hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION * session,
const char *privkeyfile,
unsigned const char *passphrase,
void **abstract)
{
libssh2_rsa_ctx *rsactx;
FILE *fp;
int ret;
if (*abstract) {
libssh2_hostkey_method_ssh_rsa_dtor(session, abstract);
hostkey_method_ssh_rsa_dtor(session, abstract);
*abstract = NULL;
}
@ -134,17 +136,17 @@ libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION * session,
return 0;
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_rsa_sign
/*
* hostkey_method_ssh_rsa_sign
*
* Verify signature created by remote
*/
static int
libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session,
const unsigned char *sig,
unsigned long sig_len,
const unsigned char *m,
unsigned long m_len, void **abstract)
hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session,
const unsigned char *sig,
unsigned long sig_len,
const unsigned char *m,
unsigned long m_len, void **abstract)
{
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
(void) session;
@ -155,18 +157,18 @@ libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session,
return _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len);
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_rsa_signv
/*
* hostkey_method_ssh_rsa_signv
*
* Construct a signature from an array of vectors
*/
static int
libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session,
unsigned char **signature,
unsigned long *signature_len,
unsigned long veccount,
const struct iovec datavec[],
void **abstract)
hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session,
unsigned char **signature,
unsigned long *signature_len,
unsigned long veccount,
const struct iovec datavec[],
void **abstract)
{
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
int ret;
@ -189,13 +191,13 @@ libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session,
return 0;
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_rsa_dtor
/*
* hostkey_method_ssh_rsa_dtor
*
* Shutdown the hostkey
*/
static int
libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract)
hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract)
{
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
(void) session;
@ -207,17 +209,15 @@ libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract)
return 0;
}
/* }}} */
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = {
"ssh-rsa",
MD5_DIGEST_LENGTH,
libssh2_hostkey_method_ssh_rsa_init,
libssh2_hostkey_method_ssh_rsa_initPEM,
libssh2_hostkey_method_ssh_rsa_sig_verify,
libssh2_hostkey_method_ssh_rsa_signv,
hostkey_method_ssh_rsa_init,
hostkey_method_ssh_rsa_initPEM,
hostkey_method_ssh_rsa_sig_verify,
hostkey_method_ssh_rsa_signv,
NULL, /* encrypt */
libssh2_hostkey_method_ssh_rsa_dtor,
hostkey_method_ssh_rsa_dtor,
};
#endif /* LIBSSH2_RSA */
@ -226,17 +226,19 @@ static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
* ssh-dss *
*********** */
static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session,
void **abstract);
static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session,
void **abstract);
/* {{{ libssh2_hostkey_method_ssh_dss_init
/*
* hostkey_method_ssh_dss_init
*
* Initialize the server hostkey working area with p/q/g/y set
*/
static int
libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
const unsigned char *hostkey_data,
unsigned long hostkey_data_len,
void **abstract)
hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
const unsigned char *hostkey_data,
unsigned long hostkey_data_len,
void **abstract)
{
libssh2_dsa_ctx *dsactx;
const unsigned char *p, *q, *g, *y, *s;
@ -244,31 +246,31 @@ libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
(void) hostkey_data_len;
if (*abstract) {
libssh2_hostkey_method_ssh_dss_dtor(session, abstract);
hostkey_method_ssh_dss_dtor(session, abstract);
*abstract = NULL;
}
s = hostkey_data;
len = libssh2_ntohu32(s);
len = _libssh2_ntohu32(s);
s += 4;
if (len != 7 || strncmp((char *) s, "ssh-dss", 7) != 0) {
return -1;
}
s += 7;
p_len = libssh2_ntohu32(s);
p_len = _libssh2_ntohu32(s);
s += 4;
p = s;
s += p_len;
q_len = libssh2_ntohu32(s);
q_len = _libssh2_ntohu32(s);
s += 4;
q = s;
s += q_len;
g_len = libssh2_ntohu32(s);
g_len = _libssh2_ntohu32(s);
s += 4;
g = s;
s += g_len;
y_len = libssh2_ntohu32(s);
y_len = _libssh2_ntohu32(s);
s += 4;
y = s;
s += y_len;
@ -280,23 +282,23 @@ libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
return 0;
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_dss_initPEM
/*
* hostkey_method_ssh_dss_initPEM
*
* Load a Private Key from a PEM file
*/
static int
libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION * session,
const char *privkeyfile,
unsigned const char *passphrase,
void **abstract)
hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION * session,
const char *privkeyfile,
unsigned const char *passphrase,
void **abstract)
{
libssh2_dsa_ctx *dsactx;
FILE *fp;
int ret;
if (*abstract) {
libssh2_hostkey_method_ssh_dss_dtor(session, abstract);
hostkey_method_ssh_dss_dtor(session, abstract);
*abstract = NULL;
}
@ -316,17 +318,17 @@ libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION * session,
return 0;
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_dss_sign
/*
* libssh2_hostkey_method_ssh_dss_sign
*
* Verify signature created by remote
*/
static int
libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
const unsigned char *sig,
unsigned long sig_len,
const unsigned char *m,
unsigned long m_len, void **abstract)
hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
const unsigned char *sig,
unsigned long sig_len,
const unsigned char *m,
unsigned long m_len, void **abstract)
{
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
@ -341,18 +343,18 @@ libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_dss_signv
/*
* hostkey_method_ssh_dss_signv
*
* Construct a signature from an array of vectors
*/
static int
libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session,
unsigned char **signature,
unsigned long *signature_len,
unsigned long veccount,
const struct iovec datavec[],
void **abstract)
hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session,
unsigned char **signature,
unsigned long *signature_len,
unsigned long veccount,
const struct iovec datavec[],
void **abstract)
{
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
unsigned char hash[SHA_DIGEST_LENGTH];
@ -381,13 +383,13 @@ libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session,
return 0;
}
/* }}} */
/* {{{ libssh2_hostkey_method_ssh_dss_dtor
/*
* libssh2_hostkey_method_ssh_dss_dtor
*
* Shutdown the hostkey method
*/
static int
libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract)
hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract)
{
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
(void) session;
@ -399,26 +401,24 @@ libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract)
return 0;
}
/* }}} */
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_dss = {
static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_dss = {
"ssh-dss",
MD5_DIGEST_LENGTH,
libssh2_hostkey_method_ssh_dss_init,
libssh2_hostkey_method_ssh_dss_initPEM,
libssh2_hostkey_method_ssh_dss_sig_verify,
libssh2_hostkey_method_ssh_dss_signv,
hostkey_method_ssh_dss_init,
hostkey_method_ssh_dss_initPEM,
hostkey_method_ssh_dss_sig_verify,
hostkey_method_ssh_dss_signv,
NULL, /* encrypt */
libssh2_hostkey_method_ssh_dss_dtor,
hostkey_method_ssh_dss_dtor,
};
#endif /* LIBSSH2_DSA */
static const LIBSSH2_HOSTKEY_METHOD *_libssh2_hostkey_methods[] = {
static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = {
#if LIBSSH2_RSA
&libssh2_hostkey_method_ssh_rsa,
&hostkey_method_ssh_rsa,
#endif /* LIBSSH2_RSA */
#if LIBSSH2_DSA
&libssh2_hostkey_method_ssh_dss,
&hostkey_method_ssh_dss,
#endif /* LIBSSH2_DSA */
NULL
};
@ -426,10 +426,12 @@ static const LIBSSH2_HOSTKEY_METHOD *_libssh2_hostkey_methods[] = {
const LIBSSH2_HOSTKEY_METHOD **
libssh2_hostkey_methods(void)
{
return _libssh2_hostkey_methods;
return hostkey_methods;
}
/* {{{ libssh2_hostkey_hash
/*
* libssh2_hostkey_hash
*
* Returns hash signature
* Returned buffer should NOT be freed
* Length of buffer is determined by hash type
@ -451,5 +453,3 @@ libssh2_hostkey_hash(LIBSSH2_SESSION * session, int hash_type)
return NULL;
}
}
/* }}} */

119
src/kex.c
View File

@ -122,7 +122,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
goto clean_exit;
}
exchange_state->e_packet[0] = packet_type_init;
libssh2_htonu32(exchange_state->e_packet + 1,
_libssh2_htonu32(exchange_state->e_packet + 1,
exchange_state->e_packet_len - 5);
if (_libssh2_bn_bits(exchange_state->e) % 8) {
_libssh2_bn_to_bin(exchange_state->e,
@ -139,8 +139,8 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
}
if (exchange_state->state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, exchange_state->e_packet,
exchange_state->e_packet_len);
rc = _libssh2_packet_write(session, exchange_state->e_packet,
exchange_state->e_packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -162,7 +162,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
_libssh2_debug(session, LIBSSH2_DBG_KEX,
"Waiting for badly guessed KEX packet (to be ignored)");
burn_type =
libssh2_packet_burn(session, &exchange_state->burn_state);
_libssh2_packet_burn(session, &exchange_state->burn_state);
if (burn_type == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (burn_type <= 0) {
@ -182,10 +182,10 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
if (exchange_state->state == libssh2_NB_state_sent1) {
/* Wait for KEX reply */
rc = libssh2_packet_require(session, packet_type_reply,
&exchange_state->s_packet,
&exchange_state->s_packet_len, 0, NULL,
0, &exchange_state->req_state);
rc = _libssh2_packet_require(session, packet_type_reply,
&exchange_state->s_packet,
&exchange_state->s_packet_len, 0, NULL,
0, &exchange_state->req_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
@ -199,7 +199,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
/* Parse KEXDH_REPLY */
exchange_state->s = exchange_state->s_packet + 1;
session->server_hostkey_len = libssh2_ntohu32(exchange_state->s);
session->server_hostkey_len = _libssh2_ntohu32(exchange_state->s);
exchange_state->s += 4;
session->server_hostkey =
LIBSSH2_ALLOC(session, session->server_hostkey_len);
@ -268,14 +268,14 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
goto clean_exit;
}
exchange_state->f_value_len = libssh2_ntohu32(exchange_state->s);
exchange_state->f_value_len = _libssh2_ntohu32(exchange_state->s);
exchange_state->s += 4;
exchange_state->f_value = exchange_state->s;
exchange_state->s += exchange_state->f_value_len;
_libssh2_bn_from_bin(exchange_state->f, exchange_state->f_value_len,
exchange_state->f_value);
exchange_state->h_sig_len = libssh2_ntohu32(exchange_state->s);
exchange_state->h_sig_len = _libssh2_ntohu32(exchange_state->s);
exchange_state->s += 4;
exchange_state->h_sig = exchange_state->s;
@ -295,7 +295,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
ret = -1;
goto clean_exit;
}
libssh2_htonu32(exchange_state->k_value,
_libssh2_htonu32(exchange_state->k_value,
exchange_state->k_value_len - 4);
if (_libssh2_bn_bits(exchange_state->k) % 8) {
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4);
@ -306,7 +306,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
libssh2_sha1_init(&exchange_state->exchange_hash);
if (session->local.banner) {
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
strlen((char *) session->local.banner) - 2);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -314,7 +314,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
(char *) session->local.banner,
strlen((char *) session->local.banner) - 2);
} else {
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -323,7 +323,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1);
}
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
strlen((char *) session->remote.banner));
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -331,7 +331,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
session->remote.banner,
strlen((char *) session->remote.banner));
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
session->local.kexinit_len);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -339,7 +339,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
session->local.kexinit,
session->local.kexinit_len);
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
session->remote.kexinit_len);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -347,7 +347,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
session->remote.kexinit,
session->remote.kexinit_len);
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
session->server_hostkey_len);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -358,16 +358,16 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
if (packet_type_init == SSH_MSG_KEX_DH_GEX_INIT) {
/* diffie-hellman-group-exchange hashes additional fields */
#ifdef LIBSSH2_DH_GEX_NEW
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
LIBSSH2_DH_GEX_MINGROUP);
libssh2_htonu32(exchange_state->h_sig_comp + 4,
_libssh2_htonu32(exchange_state->h_sig_comp + 4,
LIBSSH2_DH_GEX_OPTGROUP);
libssh2_htonu32(exchange_state->h_sig_comp + 8,
_libssh2_htonu32(exchange_state->h_sig_comp + 8,
LIBSSH2_DH_GEX_MAXGROUP);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 12);
#else
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
LIBSSH2_DH_GEX_OPTGROUP);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -383,7 +383,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
exchange_state->e_packet + 1,
exchange_state->e_packet_len - 1);
libssh2_htonu32(exchange_state->h_sig_comp,
_libssh2_htonu32(exchange_state->h_sig_comp,
exchange_state->f_value_len);
libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4);
@ -415,7 +415,7 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
}
if (exchange_state->state == libssh2_NB_state_sent2) {
rc = libssh2_packet_write(session, &exchange_state->c, 1);
rc = _libssh2_packet_write(session, &exchange_state->c, 1);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -429,10 +429,10 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
}
if (exchange_state->state == libssh2_NB_state_sent3) {
rc = libssh2_packet_require(session, SSH_MSG_NEWKEYS,
&exchange_state->tmp,
&exchange_state->tmp_len, 0, NULL, 0,
&exchange_state->req_state);
rc = _libssh2_packet_require(session, SSH_MSG_NEWKEYS,
&exchange_state->tmp,
&exchange_state->tmp_len, 0, NULL, 0,
&exchange_state->req_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -819,15 +819,15 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
/* Ask for a P and G pair */
#ifdef LIBSSH2_DH_GEX_NEW
key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST;
libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_MINGROUP);
libssh2_htonu32(key_state->request + 5, LIBSSH2_DH_GEX_OPTGROUP);
libssh2_htonu32(key_state->request + 9, LIBSSH2_DH_GEX_MAXGROUP);
_libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_MINGROUP);
_libssh2_htonu32(key_state->request + 5, LIBSSH2_DH_GEX_OPTGROUP);
_libssh2_htonu32(key_state->request + 9, LIBSSH2_DH_GEX_MAXGROUP);
key_state->request_len = 13;
_libssh2_debug(session, LIBSSH2_DBG_KEX,
"Initiating Diffie-Hellman Group-Exchange (New Method)");
#else
key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST_OLD;
libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_OPTGROUP);
_libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_OPTGROUP);
key_state->request_len = 5;
_libssh2_debug(session, LIBSSH2_DBG_KEX,
"Initiating Diffie-Hellman Group-Exchange (Old Method)");
@ -837,8 +837,8 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
}
if (key_state->state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, key_state->request,
key_state->request_len);
rc = _libssh2_packet_write(session, key_state->request,
key_state->request_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -852,9 +852,9 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
}
if (key_state->state == libssh2_NB_state_sent) {
rc = libssh2_packet_require(session, SSH_MSG_KEX_DH_GEX_GROUP,
&key_state->data, &key_state->data_len,
0, NULL, 0, &key_state->req_state);
rc = _libssh2_packet_require(session, SSH_MSG_KEX_DH_GEX_GROUP,
&key_state->data, &key_state->data_len,
0, NULL, 0, &key_state->req_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -869,12 +869,12 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (key_state->state == libssh2_NB_state_sent1) {
s = key_state->data + 1;
p_len = libssh2_ntohu32(s);
p_len = _libssh2_ntohu32(s);
s += 4;
_libssh2_bn_from_bin(key_state->p, p_len, s);
s += p_len;
g_len = libssh2_ntohu32(s);
g_len = _libssh2_ntohu32(s);
s += 4;
_libssh2_bn_from_bin(key_state->g, g_len, s);
s += g_len;
@ -969,7 +969,7 @@ static size_t
kex_method_list(unsigned char *buf, size_t list_strlen,
LIBSSH2_COMMON_METHOD ** method)
{
libssh2_htonu32(buf, list_strlen);
_libssh2_htonu32(buf, list_strlen);
buf += 4;
if (!method || !*method) {
@ -995,7 +995,7 @@ kex_method_list(unsigned char *buf, size_t list_strlen,
#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \
if (prefvar) { \
libssh2_htonu32((buf), (prefvarlen)); \
_libssh2_htonu32((buf), (prefvarlen)); \
buf += 4; \
memcpy((buf), (prefvar), (prefvarlen)); \
buf += (prefvarlen); \
@ -1136,11 +1136,13 @@ static int kexinit(LIBSSH2_SESSION * session)
data_len = session->kexinit_data_len;
}
if ((rc = libssh2_packet_write(session, data, data_len)) == PACKET_EAGAIN) {
rc = _libssh2_packet_write(session, data, data_len);
if (rc == PACKET_EAGAIN) {
session->kexinit_data = data;
session->kexinit_data_len = data_len;
return PACKET_EAGAIN;
} else if (rc) {
}
else if (rc) {
LIBSSH2_FREE(session, data);
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send KEXINIT packet to remote host", 0);
@ -1559,34 +1561,34 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
s += 16;
/* Locate each string */
kex_len = libssh2_ntohu32(s);
kex_len = _libssh2_ntohu32(s);
kex = s + 4;
s += 4 + kex_len;
hostkey_len = libssh2_ntohu32(s);
hostkey_len = _libssh2_ntohu32(s);
hostkey = s + 4;
s += 4 + hostkey_len;
crypt_cs_len = libssh2_ntohu32(s);
crypt_cs_len = _libssh2_ntohu32(s);
crypt_cs = s + 4;
s += 4 + crypt_cs_len;
crypt_sc_len = libssh2_ntohu32(s);
crypt_sc_len = _libssh2_ntohu32(s);
crypt_sc = s + 4;
s += 4 + crypt_sc_len;
mac_cs_len = libssh2_ntohu32(s);
mac_cs_len = _libssh2_ntohu32(s);
mac_cs = s + 4;
s += 4 + mac_cs_len;
mac_sc_len = libssh2_ntohu32(s);
mac_sc_len = _libssh2_ntohu32(s);
mac_sc = s + 4;
s += 4 + mac_sc_len;
comp_cs_len = libssh2_ntohu32(s);
comp_cs_len = _libssh2_ntohu32(s);
comp_cs = s + 4;
s += 4 + comp_cs_len;
comp_sc_len = libssh2_ntohu32(s);
comp_sc_len = _libssh2_ntohu32(s);
comp_sc = s + 4;
s += 4 + comp_sc_len;
lang_cs_len = libssh2_ntohu32(s);
lang_cs_len = _libssh2_ntohu32(s);
lang_cs = s + 4;
s += 4 + lang_cs_len;
lang_sc_len = libssh2_ntohu32(s);
lang_sc_len = _libssh2_ntohu32(s);
lang_sc = s + 4;
s += 4 + lang_sc_len;
@ -1720,14 +1722,15 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
if (key_state->state == libssh2_NB_state_sent1) {
retcode =
libssh2_packet_require(session, SSH_MSG_KEXINIT,
&key_state->data,
&key_state->data_len, 0, NULL, 0,
&key_state->req_state);
_libssh2_packet_require(session, SSH_MSG_KEXINIT,
&key_state->data,
&key_state->data_len, 0, NULL, 0,
&key_state->req_state);
if (retcode == PACKET_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return PACKET_EAGAIN;
} else if (retcode) {
}
else if (retcode) {
if (session->local.kexinit) {
LIBSSH2_FREE(session, session->local.kexinit);
}

View File

@ -159,13 +159,20 @@ static inline int usleep(int udelay)
*/
#define MAX_SSH_PACKET_LEN 35000
#define LIBSSH2_ALLOC(session, count) session->alloc((count), &(session)->abstract)
#define LIBSSH2_REALLOC(session, ptr, count) ((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : session->alloc((count), &(session)->abstract))
#define LIBSSH2_FREE(session, ptr) session->free((ptr), &(session)->abstract)
#define LIBSSH2_IGNORE(session, data, datalen) session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract)
#define LIBSSH2_DEBUG(session, always_display, message, message_len, language, language_len) \
session->ssh_msg_disconnect((session), (always_display), (message), (message_len), (language), (language_len), &(session)->abstract)
#define LIBSSH2_ALLOC(session, count) \
session->alloc((count), &(session)->abstract)
#define LIBSSH2_REALLOC(session, ptr, count) \
((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : \
session->alloc((count), &(session)->abstract))
#define LIBSSH2_FREE(session, ptr) \
session->free((ptr), &(session)->abstract)
#define LIBSSH2_IGNORE(session, data, datalen) \
session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract)
#define LIBSSH2_DEBUG(session, always_display, message, message_len, \
language, language_len) \
session->ssh_msg_disconnect((session), (always_display), (message), \
(message_len), (language), (language_len), \
&(session)->abstract)
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, language, language_len) \
session->ssh_msg_disconnect((session), (reason), (message), (message_len), (language), (language_len), &(session)->abstract)
@ -704,7 +711,8 @@ struct _LIBSSH2_SESSION
/* (local as source of data -- packet_write ) */
libssh2_endpoint_data local;
/* Inbound Data buffer -- Sometimes the packet that comes in isn't the packet we're ready for */
/* Inbound Data buffer -- Sometimes the packet that comes in isn't the
packet we're ready for */
LIBSSH2_PACKET_BRIGADE packets;
/* Active connection channels */
@ -866,7 +874,8 @@ struct _LIBSSH2_SESSION
libssh2_nonblocking_states sftpInit_state;
LIBSSH2_SFTP *sftpInit_sftp;
LIBSSH2_CHANNEL *sftpInit_channel;
unsigned char sftpInit_buffer[9]; /* sftp_header(5){excludes request_id} + version_id(4) */
unsigned char sftpInit_buffer[9]; /* sftp_header(5){excludes request_id}
+ version_id(4) */
/* State variables used in libssh2_scp_recv() */
libssh2_nonblocking_states scpRecv_state;
@ -1126,16 +1135,16 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
#define SSH_MSG_CHANNEL_SUCCESS 99
#define SSH_MSG_CHANNEL_FAILURE 100
void libssh2_session_shutdown(LIBSSH2_SESSION * session);
void _libssh2_session_shutdown(LIBSSH2_SESSION * session);
unsigned long libssh2_ntohu32(const unsigned char *buf);
libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf);
void libssh2_htonu32(unsigned char *buf, unsigned long val);
void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t val);
unsigned long _libssh2_ntohu32(const unsigned char *buf);
libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf);
void _libssh2_htonu32(unsigned char *buf, unsigned long val);
void _libssh2_htonu64(unsigned char *buf, libssh2_uint64_t val);
#define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when
waiting for more data to arrive */
int libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds);
int _libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds);
/* CAUTION: some of these error codes are returned in the public API and is
@ -1151,46 +1160,46 @@ int libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds);
#define PACKET_FAIL -1
#define PACKET_NONE 0
libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION * session);
libssh2pack_t _libssh2_packet_read(LIBSSH2_SESSION * session);
int libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int libssh2_packet_askv(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
int _libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int libssh2_packet_require(LIBSSH2_SESSION * session,
unsigned char packet_type, unsigned char **data,
unsigned long *data_len, unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_require_state_t * state);
int libssh2_packet_requirev(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
int _libssh2_packet_askv(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int _libssh2_packet_require(LIBSSH2_SESSION * session,
unsigned char packet_type, unsigned char **data,
unsigned long *data_len, unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state);
int libssh2_packet_burn(LIBSSH2_SESSION * session,
libssh2_nonblocking_states * state);
int libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long data_len);
int libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
size_t datalen, int macstate);
packet_require_state_t * state);
int _libssh2_packet_requirev(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state);
int _libssh2_packet_burn(LIBSSH2_SESSION * session,
libssh2_nonblocking_states * state);
int _libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long data_len);
int _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
size_t datalen, int macstate);
int libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
key_exchange_state_t * state);
unsigned long libssh2_channel_nextid(LIBSSH2_SESSION * session);
LIBSSH2_CHANNEL *libssh2_channel_locate(LIBSSH2_SESSION * session,
unsigned long channel_id);
unsigned long libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel,
int stream_id);
unsigned long _libssh2_channel_nextid(LIBSSH2_SESSION * session);
LIBSSH2_CHANNEL *_libssh2_channel_locate(LIBSSH2_SESSION * session,
unsigned long channel_id);
unsigned long _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel,
int stream_id);
/* this is the lib-internal set blocking function */
int _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking);

View File

@ -110,7 +110,7 @@ libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session,
unsigned char seqno_buf[4];
(void) session;
libssh2_htonu32(seqno_buf, seqno);
_libssh2_htonu32(seqno_buf, seqno);
libssh2_hmac_sha1_init(&ctx, *abstract, 20);
libssh2_hmac_update(ctx, seqno_buf, 4);
@ -181,7 +181,7 @@ libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf,
unsigned char seqno_buf[4];
(void) session;
libssh2_htonu32(seqno_buf, seqno);
_libssh2_htonu32(seqno_buf, seqno);
libssh2_hmac_md5_init(&ctx, *abstract, 16);
libssh2_hmac_update(ctx, seqno_buf, 4);
@ -254,7 +254,7 @@ libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session,
unsigned char seqno_buf[4];
(void) session;
libssh2_htonu32(seqno_buf, seqno);
_libssh2_htonu32(seqno_buf, seqno);
libssh2_hmac_ripemd160_init(&ctx, *abstract, 20);
libssh2_hmac_update(ctx, seqno_buf, 4);

View File

@ -48,7 +48,7 @@
/* libssh2_ntohu32
*/
unsigned long
libssh2_ntohu32(const unsigned char *buf)
_libssh2_ntohu32(const unsigned char *buf)
{
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
}
@ -57,7 +57,7 @@ libssh2_ntohu32(const unsigned char *buf)
/* libssh2_ntohu64
*/
libssh2_uint64_t
libssh2_ntohu64(const unsigned char *buf)
_libssh2_ntohu64(const unsigned char *buf)
{
unsigned long msl, lsl;
@ -70,7 +70,7 @@ libssh2_ntohu64(const unsigned char *buf)
/* libssh2_htonu32
*/
void
libssh2_htonu32(unsigned char *buf, unsigned long value)
_libssh2_htonu32(unsigned char *buf, unsigned long value)
{
buf[0] = (value >> 24) & 0xFF;
buf[1] = (value >> 16) & 0xFF;
@ -81,7 +81,7 @@ libssh2_htonu32(unsigned char *buf, unsigned long value)
/* libssh2_htonu64
*/
void
libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
_libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
{
unsigned long msl = ((libssh2_uint64_t)value >> 32);
@ -98,17 +98,18 @@ libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
/* Base64 Conversion */
static const char libssh2_base64_table[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
static const char base64_table[] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
};
static const char libssh2_base64_pad = '=';
static const char base64_pad = '=';
static const short libssh2_base64_reverse_table[256] = {
static const short base64_reverse_table[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
@ -147,7 +148,7 @@ libssh2_base64_decode(LIBSSH2_SESSION * session, char **data,
}
for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) {
if ((v = libssh2_base64_reverse_table[*s]) < 0)
if ((v = base64_reverse_table[*s]) < 0)
continue;
switch (i % 4) {
case 0:

View File

@ -100,8 +100,7 @@
# define LIBSSH2_3DES 1
#endif
#define libssh2_random(buf, len) \
RAND_bytes ((buf), (len))
#define libssh2_random(buf, len) RAND_bytes ((buf), (len))
#define libssh2_sha1_ctx SHA_CTX
#define libssh2_sha1_init(ctx) SHA1_Init(ctx)

View File

@ -1,4 +1,5 @@
/* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@ -58,13 +59,15 @@
#include <sys/types.h>
/* {{{ libssh2_packet_queue_listener
/*
* libssh2_packet_queue_listener
*
* Queue a connection request for a listener
*/
static inline int
libssh2_packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long datalen,
packet_queue_listener_state_t * listen_state)
packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long datalen,
packet_queue_listener_state_t * listen_state)
{
/*
* Look for a matching listener
@ -80,26 +83,26 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
(void) datalen;
if (listen_state->state == libssh2_NB_state_idle) {
listen_state->sender_channel = libssh2_ntohu32(s);
listen_state->sender_channel = _libssh2_ntohu32(s);
s += 4;
listen_state->initial_window_size = libssh2_ntohu32(s);
listen_state->initial_window_size = _libssh2_ntohu32(s);
s += 4;
listen_state->packet_size = libssh2_ntohu32(s);
listen_state->packet_size = _libssh2_ntohu32(s);
s += 4;
listen_state->host_len = libssh2_ntohu32(s);
listen_state->host_len = _libssh2_ntohu32(s);
s += 4;
listen_state->host = s;
s += listen_state->host_len;
listen_state->port = libssh2_ntohu32(s);
listen_state->port = _libssh2_ntohu32(s);
s += 4;
listen_state->shost_len = libssh2_ntohu32(s);
listen_state->shost_len = _libssh2_ntohu32(s);
s += 4;
listen_state->shost = s;
s += listen_state->shost_len;
listen_state->sport = libssh2_ntohu32(s);
listen_state->sport = _libssh2_ntohu32(s);
s += 4;
_libssh2_debug(session, LIBSSH2_DBG_CONN,
@ -169,7 +172,7 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
channel->remote.packet_size =
LIBSSH2_CHANNEL_PACKET_DEFAULT;
channel->local.id = libssh2_channel_nextid(session);
channel->local.id = _libssh2_channel_nextid(session);
channel->local.window_size_initial =
listen_state->initial_window_size;
channel->local.window_size =
@ -186,20 +189,20 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
p = listen_state->packet;
*(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
libssh2_htonu32(p, channel->remote.id);
_libssh2_htonu32(p, channel->remote.id);
p += 4;
libssh2_htonu32(p, channel->local.id);
_libssh2_htonu32(p, channel->local.id);
p += 4;
libssh2_htonu32(p, channel->remote.window_size_initial);
_libssh2_htonu32(p, channel->remote.window_size_initial);
p += 4;
libssh2_htonu32(p, channel->remote.packet_size);
_libssh2_htonu32(p, channel->remote.packet_size);
p += 4;
listen_state->state = libssh2_NB_state_created;
}
if (listen_state->state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, listen_state->packet,
rc = _libssh2_packet_write(session, listen_state->packet,
17);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
@ -243,17 +246,17 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
{
p = listen_state->packet;
*(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE;
libssh2_htonu32(p, listen_state->sender_channel);
_libssh2_htonu32(p, listen_state->sender_channel);
p += 4;
libssh2_htonu32(p, failure_code);
_libssh2_htonu32(p, failure_code);
p += 4;
libssh2_htonu32(p, sizeof(FwdNotReq) - 1);
_libssh2_htonu32(p, sizeof(FwdNotReq) - 1);
p += 4;
memcpy(s, FwdNotReq, sizeof(FwdNotReq) - 1);
p += sizeof(FwdNotReq) - 1;
libssh2_htonu32(p, 0);
_libssh2_htonu32(p, 0);
rc = libssh2_packet_write(session, listen_state->packet, packet_len);
rc = _libssh2_packet_write(session, listen_state->packet, packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -267,15 +270,15 @@ libssh2_packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
}
}
/* }}} */
/* {{{ libssh2_packet_x11_open
/*
* packet_x11_open
*
* Accept a forwarded X11 connection
*/
static inline int
libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long datalen,
packet_x11_open_state_t * x11open_state)
packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long datalen,
packet_x11_open_state_t * x11open_state)
{
int failure_code = 2; /* SSH_OPEN_CONNECT_FAILED */
unsigned char *s = data + (sizeof("x11") - 1) + 5;
@ -288,17 +291,17 @@ libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
(void) datalen;
if (x11open_state->state == libssh2_NB_state_idle) {
x11open_state->sender_channel = libssh2_ntohu32(s);
x11open_state->sender_channel = _libssh2_ntohu32(s);
s += 4;
x11open_state->initial_window_size = libssh2_ntohu32(s);
x11open_state->initial_window_size = _libssh2_ntohu32(s);
s += 4;
x11open_state->packet_size = libssh2_ntohu32(s);
x11open_state->packet_size = _libssh2_ntohu32(s);
s += 4;
x11open_state->shost_len = libssh2_ntohu32(s);
x11open_state->shost_len = _libssh2_ntohu32(s);
s += 4;
x11open_state->shost = s;
s += x11open_state->shost_len;
x11open_state->sport = libssh2_ntohu32(s);
x11open_state->sport = _libssh2_ntohu32(s);
s += 4;
_libssh2_debug(session, LIBSSH2_DBG_CONN,
@ -343,7 +346,7 @@ libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
channel->remote.window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT;
channel->remote.packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT;
channel->local.id = libssh2_channel_nextid(session);
channel->local.id = _libssh2_channel_nextid(session);
channel->local.window_size_initial =
x11open_state->initial_window_size;
channel->local.window_size = x11open_state->initial_window_size;
@ -358,20 +361,20 @@ libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
channel->remote.packet_size);
p = x11open_state->packet;
*(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
libssh2_htonu32(p, channel->remote.id);
_libssh2_htonu32(p, channel->remote.id);
p += 4;
libssh2_htonu32(p, channel->local.id);
_libssh2_htonu32(p, channel->local.id);
p += 4;
libssh2_htonu32(p, channel->remote.window_size_initial);
_libssh2_htonu32(p, channel->remote.window_size_initial);
p += 4;
libssh2_htonu32(p, channel->remote.packet_size);
_libssh2_htonu32(p, channel->remote.packet_size);
p += 4;
x11open_state->state = libssh2_NB_state_created;
}
if (x11open_state->state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, x11open_state->packet, 17);
rc = _libssh2_packet_write(session, x11open_state->packet, 17);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -409,17 +412,17 @@ libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
x11_exit:
p = x11open_state->packet;
*(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE;
libssh2_htonu32(p, x11open_state->sender_channel);
_libssh2_htonu32(p, x11open_state->sender_channel);
p += 4;
libssh2_htonu32(p, failure_code);
_libssh2_htonu32(p, failure_code);
p += 4;
libssh2_htonu32(p, sizeof(X11FwdUnAvil) - 1);
_libssh2_htonu32(p, sizeof(X11FwdUnAvil) - 1);
p += 4;
memcpy(s, X11FwdUnAvil, sizeof(X11FwdUnAvil) - 1);
p += sizeof(X11FwdUnAvil) - 1;
libssh2_htonu32(p, 0);
_libssh2_htonu32(p, 0);
rc = libssh2_packet_write(session, x11open_state->packet, packet_len);
rc = _libssh2_packet_write(session, x11open_state->packet, packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -433,14 +436,14 @@ libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
}
/*
* libssh2_packet_add
* _libssh2_packet_add
*
* Create a new packet and attach it to the brigade. Called from the transport
* layer when it as received a packet.
*/
int
libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
size_t datalen, int macstate)
_libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
size_t datalen, int macstate)
{
int rc;
@ -519,11 +522,11 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
char *message, *language;
int reason, message_len, language_len;
reason = libssh2_ntohu32(data + 1);
message_len = libssh2_ntohu32(data + 5);
reason = _libssh2_ntohu32(data + 1);
message_len = _libssh2_ntohu32(data + 5);
/* 9 = packet_type(1) + reason(4) + message_len(4) */
message = (char *) data + 9;
language_len = libssh2_ntohu32(data + 9 + message_len);
language_len = _libssh2_ntohu32(data + 9 + message_len);
/*
* This is where we hack on the data a little,
* Use the MSB of language_len to to a terminating NULL
@ -574,10 +577,10 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
char *message, *language;
int message_len, language_len;
message_len = libssh2_ntohu32(data + 2);
message_len = _libssh2_ntohu32(data + 2);
/* 6 = packet_type(1) + display(1) + message_len(4) */
message = (char *) data + 6;
language_len = libssh2_ntohu32(data + 6 + message_len);
language_len = _libssh2_ntohu32(data + 6 + message_len);
/*
* This is where we hack on the data a little,
* Use the MSB of language_len to to a terminating NULL
@ -620,7 +623,7 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
session->packAdd_data_head += 9;
session->packAdd_channel =
libssh2_channel_locate(session, libssh2_ntohu32(data + 1));
_libssh2_channel_locate(session, _libssh2_ntohu32(data + 1));
if (!session->packAdd_channel) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
@ -634,7 +637,7 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
{
unsigned long stream_id = 0;
if (data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA) {
stream_id = libssh2_ntohu32(data + 5);
stream_id = _libssh2_ntohu32(data + 5);
}
_libssh2_debug(session, LIBSSH2_DBG_CONN,
@ -726,9 +729,8 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
case SSH_MSG_CHANNEL_EOF:
{
session->packAdd_channel = libssh2_channel_locate(session,
libssh2_ntohu32
(data + 1));
session->packAdd_channel =
_libssh2_channel_locate(session, _libssh2_ntohu32(data + 1));
if (!session->packAdd_channel) {
/* We may have freed already, just quietly ignore this... */
@ -752,18 +754,18 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
case SSH_MSG_CHANNEL_REQUEST:
{
if (libssh2_ntohu32(data + 5) == sizeof("exit-status") - 1
if (_libssh2_ntohu32(data + 5) == sizeof("exit-status") - 1
&& !memcmp("exit-status", data + 9,
sizeof("exit-status") - 1)) {
/* we've got "exit-status" packet. Set the session value */
session->packAdd_channel =
libssh2_channel_locate(session,
libssh2_ntohu32(data + 1));
_libssh2_channel_locate(session,
_libssh2_ntohu32(data + 1));
if (session->packAdd_channel) {
session->packAdd_channel->exit_status =
libssh2_ntohu32(data + 9 + sizeof("exit-status"));
_libssh2_ntohu32(data + 9 + sizeof("exit-status"));
_libssh2_debug(session, LIBSSH2_DBG_CONN,
"Exit status %lu received for channel %lu/%lu",
session->packAdd_channel->exit_status,
@ -780,9 +782,8 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
case SSH_MSG_CHANNEL_CLOSE:
{
session->packAdd_channel = libssh2_channel_locate(session,
libssh2_ntohu32
(data + 1));
session->packAdd_channel =
_libssh2_channel_locate(session, _libssh2_ntohu32(data + 1));
if (!session->packAdd_channel) {
/* We may have freed already, just quietly ignore this... */
@ -807,7 +808,7 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
case SSH_MSG_CHANNEL_OPEN:
if ((datalen >= (sizeof("forwarded-tcpip") + 4)) &&
((sizeof("forwarded-tcpip") - 1) == libssh2_ntohu32(data + 1))
((sizeof("forwarded-tcpip") - 1) == _libssh2_ntohu32(data + 1))
&&
(memcmp
(data + 5, "forwarded-tcpip",
@ -815,9 +816,8 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
libssh2_packet_add_jump_point2:
session->packAdd_state = libssh2_NB_state_jump2;
rc = libssh2_packet_queue_listener(session, data, datalen,
&session->
packAdd_Qlstn_state);
rc = packet_queue_listener(session, data, datalen,
&session->packAdd_Qlstn_state);
if (rc == PACKET_EAGAIN) {
session->socket_block_directions =
LIBSSH2_SESSION_BLOCK_OUTBOUND;
@ -829,13 +829,13 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
return rc;
}
if ((datalen >= (sizeof("x11") + 4)) &&
((sizeof("x11") - 1) == libssh2_ntohu32(data + 1)) &&
((sizeof("x11") - 1) == _libssh2_ntohu32(data + 1)) &&
(memcmp(data + 5, "x11", sizeof("x11") - 1) == 0)) {
libssh2_packet_add_jump_point3:
session->packAdd_state = libssh2_NB_state_jump3;
rc = libssh2_packet_x11_open(session, data, datalen,
&session->packAdd_x11open_state);
rc = packet_x11_open(session, data, datalen,
&session->packAdd_x11open_state);
if (rc == PACKET_EAGAIN) {
session->socket_block_directions =
LIBSSH2_SESSION_BLOCK_OUTBOUND;
@ -850,10 +850,10 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
case SSH_MSG_CHANNEL_WINDOW_ADJUST:
{
unsigned long bytestoadd = libssh2_ntohu32(data + 5);
session->packAdd_channel = libssh2_channel_locate(session,
libssh2_ntohu32
(data + 1));
unsigned long bytestoadd = _libssh2_ntohu32(data + 5);
session->packAdd_channel =
_libssh2_channel_locate(session,
_libssh2_ntohu32(data + 1));
if (session->packAdd_channel && bytestoadd) {
session->packAdd_channel->local.window_size += bytestoadd;
@ -955,16 +955,16 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
}
/*
* libssh2_packet_ask
* _libssh2_packet_ask
*
* Scan the brigade for a matching packet type, optionally poll the socket for
* a packet first
*/
int
libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs, const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
_libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs, const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
{
LIBSSH2_PACKET *packet = session->packets.head;
@ -975,7 +975,7 @@ libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
* PACKET_EAGAIN. I am not sure what should happen, but internally
* there is only one location that might do so, libssh2_packet_askv_ex()
*/
libssh2pack_t rc = libssh2_packet_read(session);
libssh2pack_t rc = _libssh2_packet_read(session);
if ((rc < 0) && !packet) {
return rc;
}
@ -1025,12 +1025,12 @@ libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
* socket for a packet first
*/
int
libssh2_packet_askv(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
_libssh2_packet_askv(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
{
int i, packet_types_len = strlen((char *) packet_types);
@ -1041,7 +1041,7 @@ libssh2_packet_askv(LIBSSH2_SESSION * session,
* return PACKET_EAGAIN. Not sure the correct action, I
* think it is right as is.
*/
if (0 == libssh2_packet_ask(session, packet_types[i], data,
if (0 == _libssh2_packet_ask(session, packet_types[i], data,
data_len, match_ofs, match_buf,
match_len, i ? 0 : poll_socket)) {
return 0;
@ -1052,7 +1052,7 @@ libssh2_packet_askv(LIBSSH2_SESSION * session,
}
/*
* libssh2_waitsocket
* _libssh2_waitsocket
*
* Returns
* negative on error
@ -1062,7 +1062,7 @@ libssh2_packet_askv(LIBSSH2_SESSION * session,
* FIXME: convert to use poll on systems that have it.
*/
int
libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds)
_libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds)
{
struct timeval timeout;
int rc;
@ -1081,24 +1081,24 @@ libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds)
}
/*
* libssh2_packet_require
* _libssh2_packet_require
*
* Loops libssh2_packet_read() until the packet requested is available
* Loops _libssh2_packet_read() until the packet requested is available
* SSH_DISCONNECT or a SOCKET_DISCONNECTED will cause a bailout
*
* Returns negative on error
* Returns 0 when it has taken care of the requested packet.
*/
int
libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_require_state_t * state)
_libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_require_state_t * state)
{
if (state->start == 0) {
if (libssh2_packet_ask(session, packet_type, data, data_len,
if (_libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf,
match_len, 0) == 0) {
/* A packet was available in the packet brigade */
@ -1113,7 +1113,7 @@ libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
}
while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
libssh2pack_t ret = libssh2_packet_read(session);
libssh2pack_t ret = _libssh2_packet_read(session);
if (ret == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if ((ret == 0) && (!session->socket_block)) {
@ -1125,7 +1125,7 @@ libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
return ret;
} else if (ret == packet_type) {
/* Be lazy, let packet_ask pull it out of the brigade */
ret = libssh2_packet_ask(session, packet_type, data, data_len,
ret = _libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf, match_len, 0);
state->start = 0;
return ret;
@ -1133,7 +1133,7 @@ libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
/* nothing available, wait until data arrives or we time out */
long left = LIBSSH2_READ_TIMEOUT - (time(NULL) - state->start);
if ((left <= 0) || (libssh2_waitsocket(session, left) <= 0)) {
if ((left <= 0) || (_libssh2_waitsocket(session, left) <= 0)) {
state->start = 0;
return PACKET_TIMEOUT;
}
@ -1144,16 +1144,16 @@ libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
return -1;
}
/* }}} */
/* {{{ libssh2_packet_burn
* Loops libssh2_packet_read() until any packet is available and promptly
/*
* libssh2_packet_burn
*
* Loops _libssh2_packet_read() until any packet is available and promptly
* discards it
* Used during KEX exchange to discard badly guessed KEX_INIT packets
*/
int
libssh2_packet_burn(LIBSSH2_SESSION * session,
libssh2_nonblocking_states * state)
_libssh2_packet_burn(LIBSSH2_SESSION * session,
libssh2_nonblocking_states * state)
{
unsigned char *data;
unsigned long data_len;
@ -1166,7 +1166,7 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
all_packets[i - 1] = i;
}
if (libssh2_packet_askv(session, all_packets, &data, &data_len, 0,
if (_libssh2_packet_askv(session, all_packets, &data, &data_len, 0,
NULL, 0, 0) == 0) {
i = data[0];
/* A packet was available in the packet brigade, burn it */
@ -1180,7 +1180,7 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
}
while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
if ((ret = libssh2_packet_read(session)) == PACKET_EAGAIN) {
if ((ret = _libssh2_packet_read(session)) == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (ret < 0) {
*state = libssh2_NB_state_idle;
@ -1192,7 +1192,7 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
/* Be lazy, let packet_ask pull it out of the brigade */
if (0 ==
libssh2_packet_ask(session, ret, &data, &data_len, 0, NULL, 0, 0)) {
_libssh2_packet_ask(session, ret, &data, &data_len, 0, NULL, 0, 0)) {
/* Smoke 'em if you got 'em */
LIBSSH2_FREE(session, data);
*state = libssh2_NB_state_idle;
@ -1205,24 +1205,24 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
}
/*
* libssh2_packet_requirev
* _libssh2_packet_requirev
*
* Loops libssh2_packet_read() until one of a list of packet types requested is
* Loops _libssh2_packet_read() until one of a list of packet types requested is
* available
* SSH_DISCONNECT or a SOCKET_DISCONNECTED will cause a bailout
* packet_types is a null terminated list of packet_type numbers
*/
int
libssh2_packet_requirev(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state)
_libssh2_packet_requirev(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state)
{
if (libssh2_packet_askv(session, packet_types, data, data_len, match_ofs,
if (_libssh2_packet_askv(session, packet_types, data, data_len, match_ofs,
match_buf, match_len, 0) == 0) {
/* One of the packets listed was available in the packet
brigade */
@ -1235,7 +1235,7 @@ libssh2_packet_requirev(LIBSSH2_SESSION * session,
}
while (session->socket_state != LIBSSH2_SOCKET_DISCONNECTED) {
int ret = libssh2_packet_read(session);
int ret = _libssh2_packet_read(session);
if ((ret < 0) && (ret != PACKET_EAGAIN)) {
state->start = 0;
return ret;
@ -1243,7 +1243,7 @@ libssh2_packet_requirev(LIBSSH2_SESSION * session,
if (ret <= 0) {
long left = LIBSSH2_READ_TIMEOUT - (time(NULL) - state->start);
if ((left <= 0) || (libssh2_waitsocket(session, left) <= 0)) {
if ((left <= 0) || (_libssh2_waitsocket(session, left) <= 0)) {
state->start = 0;
return PACKET_TIMEOUT;
} else if (ret == PACKET_EAGAIN) {
@ -1253,7 +1253,7 @@ libssh2_packet_requirev(LIBSSH2_SESSION * session,
if (strchr((char *) packet_types, ret)) {
/* Be lazy, let packet_ask pull it out of the brigade */
return libssh2_packet_askv(session, packet_types, data,
return _libssh2_packet_askv(session, packet_types, data,
data_len, match_ofs, match_buf,
match_len, 0);
}

View File

@ -52,13 +52,12 @@ typedef struct _LIBSSH2_PUBLICKEY_CODE_LIST
int name_len;
} LIBSSH2_PUBLICKEY_CODE_LIST;
static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_response_codes[] = {
{LIBSSH2_PUBLICKEY_RESPONSE_STATUS, "status", sizeof("status") - 1}
,
{LIBSSH2_PUBLICKEY_RESPONSE_VERSION, "version", sizeof("version") - 1}
,
{LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY, "publickey", sizeof("publickey") - 1}
,
static const LIBSSH2_PUBLICKEY_CODE_LIST publickey_response_codes[] =
{
{LIBSSH2_PUBLICKEY_RESPONSE_STATUS, "status", sizeof("status") - 1},
{LIBSSH2_PUBLICKEY_RESPONSE_VERSION, "version", sizeof("version") - 1},
{LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY, "publickey",
sizeof("publickey") - 1} ,
{0, NULL, 0}
};
@ -75,46 +74,39 @@ static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_response_codes[] = {
#define LIBSSH2_PUBLICKEY_STATUS_CODE_MAX 8
static const LIBSSH2_PUBLICKEY_CODE_LIST libssh2_publickey_status_codes[] = {
{LIBSSH2_PUBLICKEY_SUCCESS, "success", sizeof("success") - 1}
,
static const LIBSSH2_PUBLICKEY_CODE_LIST publickey_status_codes[] = {
{LIBSSH2_PUBLICKEY_SUCCESS, "success", sizeof("success") - 1} ,
{LIBSSH2_PUBLICKEY_ACCESS_DENIED, "access denied",
sizeof("access denied") - 1}
,
sizeof("access denied") - 1},
{LIBSSH2_PUBLICKEY_STORAGE_EXCEEDED, "storage exceeded",
sizeof("storage exceeded") - 1}
,
sizeof("storage exceeded") - 1} ,
{LIBSSH2_PUBLICKEY_VERSION_NOT_SUPPORTED, "version not supported",
sizeof("version not supported") - 1}
,
sizeof("version not supported") - 1} ,
{LIBSSH2_PUBLICKEY_KEY_NOT_FOUND, "key not found",
sizeof("key not found") - 1}
,
sizeof("key not found") - 1},
{LIBSSH2_PUBLICKEY_KEY_NOT_SUPPORTED, "key not supported",
sizeof("key not supported") - 1}
,
sizeof("key not supported") - 1},
{LIBSSH2_PUBLICKEY_KEY_ALREADY_PRESENT, "key already present",
sizeof("key already present") - 1}
,
sizeof("key already present") - 1},
{LIBSSH2_PUBLICKEY_GENERAL_FAILURE, "general failure",
sizeof("general failure") - 1}
,
sizeof("general failure") - 1},
{LIBSSH2_PUBLICKEY_REQUEST_NOT_SUPPORTED, "request not supported",
sizeof("request not supported") - 1}
,
sizeof("request not supported") - 1},
{0, NULL, 0}
};
/* {{{ libssh2_publickey_status_error
/*
* publickey_status_error
*
* Format an error message from a status code
*/
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_START "Publickey Subsystem Error: \""
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_MID "\" Server Reports: \""
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_END "\""
static void
libssh2_publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_SESSION * session, int status,
const unsigned char *message, int message_len)
publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_SESSION * session, int status,
const unsigned char *message, int message_len)
{
const char *status_text;
int status_text_len;
@ -130,8 +122,8 @@ libssh2_publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
status_text = "unknown";
status_text_len = sizeof("unknown") - 1;
} else {
status_text = libssh2_publickey_status_codes[status].name;
status_text_len = libssh2_publickey_status_codes[status].name_len;
status_text = publickey_status_codes[status].name;
status_text_len = publickey_status_codes[status].name_len;
}
m_len =
@ -161,14 +153,14 @@ libssh2_publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, m, 1);
}
/* }}} */
/* {{{ libssh2_publickey_packet_receive
/*
* publickey_packet_receive
*
* Read a packet from the subsystem
*/
static int
libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
unsigned char **data, unsigned long *data_len)
publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
unsigned char **data, unsigned long *data_len)
{
LIBSSH2_CHANNEL *channel = pkey->channel;
LIBSSH2_SESSION *session = channel->session;
@ -185,7 +177,7 @@ libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
return -1;
}
pkey->receive_packet_len = libssh2_ntohu32(buffer);
pkey->receive_packet_len = _libssh2_ntohu32(buffer);
pkey->receive_packet =
LIBSSH2_ALLOC(session, pkey->receive_packet_len);
if (!pkey->receive_packet) {
@ -221,25 +213,23 @@ libssh2_publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
return 0;
}
/* }}} */
/* {{{ libssh2_publickey_response_id
/* publickey_response_id
*
* Translate a string response name to a numeric code
* Data will be incremented by 4 + response_len on success only
*/
static int
libssh2_publickey_response_id(unsigned char **pdata, int data_len)
publickey_response_id(unsigned char **pdata, int data_len)
{
unsigned long response_len;
unsigned char *data = *pdata;
const LIBSSH2_PUBLICKEY_CODE_LIST *codes =
libssh2_publickey_response_codes;
const LIBSSH2_PUBLICKEY_CODE_LIST *codes = publickey_response_codes;
if (data_len < 4) {
/* Malformed response */
return -1;
}
response_len = libssh2_ntohu32(data);
response_len = _libssh2_ntohu32(data);
data += 4;
data_len -= 4;
if (data_len < (int)response_len) {
@ -259,13 +249,12 @@ libssh2_publickey_response_id(unsigned char **pdata, int data_len)
return -1;
}
/* }}} */
/* {{{ libssh2_publickey_response_success
/* libssh2_publickey_response_success
*
* Generic helper routine to wait for success response and nothing else
*/
static int
libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
{
LIBSSH2_SESSION *session = pkey->channel->session;
unsigned char *data, *s;
@ -274,7 +263,7 @@ libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
int rc;
while (1) {
rc = libssh2_publickey_packet_receive(pkey, &data, &data_len);
rc = publickey_packet_receive(pkey, &data, &data_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -285,7 +274,7 @@ libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
}
s = data;
if ((response = libssh2_publickey_response_id(&s, data_len)) < 0) {
if ((response = publickey_response_id(&s, data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code", 0);
LIBSSH2_FREE(session, data);
@ -299,13 +288,13 @@ libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
unsigned long status, descr_len, lang_len;
unsigned char *descr, *lang;
status = libssh2_ntohu32(s);
status = _libssh2_ntohu32(s);
s += 4;
descr_len = libssh2_ntohu32(s);
descr_len = _libssh2_ntohu32(s);
s += 4;
descr = s;
s += descr_len;
lang_len = libssh2_ntohu32(s);
lang_len = _libssh2_ntohu32(s);
s += 4;
lang = s;
s += lang_len;
@ -322,8 +311,8 @@ libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
return 0;
}
libssh2_publickey_status_error(pkey, session, status, descr,
descr_len);
publickey_status_error(pkey, session, status, descr,
descr_len);
LIBSSH2_FREE(session, data);
return -1;
}
@ -340,14 +329,13 @@ libssh2_publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
return -1;
}
/* }}} */
/* *****************
* Publickey API *
***************** */
/* {{{ libssh2_publickey_init
/*
* libssh2_publickey_init
*
* Startup the publickey subsystem
*/
LIBSSH2_API LIBSSH2_PUBLICKEY *
@ -436,13 +424,13 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
session->pkeyInit_pkey->version = 0;
s = buffer;
libssh2_htonu32(s, 4 + (sizeof("version") - 1) + 4);
_libssh2_htonu32(s, 4 + (sizeof("version") - 1) + 4);
s += 4;
libssh2_htonu32(s, sizeof("version") - 1);
_libssh2_htonu32(s, sizeof("version") - 1);
s += 4;
memcpy(s, "version", sizeof("version") - 1);
s += sizeof("version") - 1;
libssh2_htonu32(s, LIBSSH2_PUBLICKEY_VERSION);
_libssh2_htonu32(s, LIBSSH2_PUBLICKEY_VERSION);
s += 4;
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
@ -470,9 +458,9 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
if (session->pkeyInit_state == libssh2_NB_state_sent3) {
while (1) {
rc = libssh2_publickey_packet_receive(session->pkeyInit_pkey,
&session->pkeyInit_data,
&session->pkeyInit_data_len);
rc = publickey_packet_receive(session->pkeyInit_pkey,
&session->pkeyInit_data,
&session->pkeyInit_data_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from publickey subsystem",
@ -487,9 +475,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
s = session->pkeyInit_data;
if ((response =
libssh2_publickey_response_id(&s,
session->pkeyInit_data_len)) <
0) {
publickey_response_id(&s, session->pkeyInit_data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code", 0);
goto err_exit;
@ -502,13 +488,13 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
unsigned long status, descr_len, lang_len;
unsigned char *descr, *lang;
status = libssh2_ntohu32(s);
status = _libssh2_ntohu32(s);
s += 4;
descr_len = libssh2_ntohu32(s);
descr_len = _libssh2_ntohu32(s);
s += 4;
descr = s;
s += descr_len;
lang_len = libssh2_ntohu32(s);
lang_len = _libssh2_ntohu32(s);
s += 4;
lang = s;
s += lang_len;
@ -522,14 +508,14 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
goto err_exit;
}
libssh2_publickey_status_error(NULL, session, status,
descr, descr_len);
publickey_status_error(NULL, session, status,
descr, descr_len);
goto err_exit;
}
case LIBSSH2_PUBLICKEY_RESPONSE_VERSION:
/* What we want */
session->pkeyInit_pkey->version = libssh2_ntohu32(s);
session->pkeyInit_pkey->version = _libssh2_ntohu32(s);
if (session->pkeyInit_pkey->version >
LIBSSH2_PUBLICKEY_VERSION) {
_libssh2_debug(session, LIBSSH2_DBG_PUBLICKEY,
@ -580,9 +566,9 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
return NULL;
}
/* }}} */
/* {{{ libssh2_publickey_add_ex
/*
* libssh2_publickey_add_ex
*
* Add a new public key entry
*/
LIBSSH2_API int
@ -635,48 +621,48 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
}
pkey->add_s = pkey->add_packet;
libssh2_htonu32(pkey->add_s, packet_len - 4);
_libssh2_htonu32(pkey->add_s, packet_len - 4);
pkey->add_s += 4;
libssh2_htonu32(pkey->add_s, sizeof("add") - 1);
_libssh2_htonu32(pkey->add_s, sizeof("add") - 1);
pkey->add_s += 4;
memcpy(pkey->add_s, "add", sizeof("add") - 1);
pkey->add_s += sizeof("add") - 1;
if (pkey->version == 1) {
libssh2_htonu32(pkey->add_s, comment_len);
_libssh2_htonu32(pkey->add_s, comment_len);
pkey->add_s += 4;
if (comment) {
memcpy(pkey->add_s, comment, comment_len);
pkey->add_s += comment_len;
}
libssh2_htonu32(pkey->add_s, name_len);
_libssh2_htonu32(pkey->add_s, name_len);
pkey->add_s += 4;
memcpy(pkey->add_s, name, name_len);
pkey->add_s += name_len;
libssh2_htonu32(pkey->add_s, blob_len);
_libssh2_htonu32(pkey->add_s, blob_len);
pkey->add_s += 4;
memcpy(pkey->add_s, blob, blob_len);
pkey->add_s += blob_len;
} else {
/* Version == 2 */
libssh2_htonu32(pkey->add_s, name_len);
_libssh2_htonu32(pkey->add_s, name_len);
pkey->add_s += 4;
memcpy(pkey->add_s, name, name_len);
pkey->add_s += name_len;
libssh2_htonu32(pkey->add_s, blob_len);
_libssh2_htonu32(pkey->add_s, blob_len);
pkey->add_s += 4;
memcpy(pkey->add_s, blob, blob_len);
pkey->add_s += blob_len;
*(pkey->add_s++) = overwrite ? 0x01 : 0;
libssh2_htonu32(pkey->add_s, num_attrs);
_libssh2_htonu32(pkey->add_s, num_attrs);
pkey->add_s += 4;
for(i = 0; i < num_attrs; i++) {
libssh2_htonu32(pkey->add_s, attrs[i].name_len);
_libssh2_htonu32(pkey->add_s, attrs[i].name_len);
pkey->add_s += 4;
memcpy(pkey->add_s, attrs[i].name, attrs[i].name_len);
pkey->add_s += attrs[i].name_len;
libssh2_htonu32(pkey->add_s, attrs[i].value_len);
_libssh2_htonu32(pkey->add_s, attrs[i].value_len);
pkey->add_s += 4;
memcpy(pkey->add_s, attrs[i].value, attrs[i].value_len);
pkey->add_s += attrs[i].value_len;
@ -709,7 +695,7 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
pkey->add_state = libssh2_NB_state_sent;
}
rc = libssh2_publickey_response_success(pkey);
rc = publickey_response_success(pkey);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
@ -719,9 +705,7 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
return rc;
}
/* }}} */
/* {{{ libssh2_publickey_remove_ex
/* libssh2_publickey_remove_ex
* Remove an existing publickey so that authentication can no longer be performed using it
*/
LIBSSH2_API int
@ -747,17 +731,17 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
}
pkey->remove_s = pkey->remove_packet;
libssh2_htonu32(pkey->remove_s, packet_len - 4);
_libssh2_htonu32(pkey->remove_s, packet_len - 4);
pkey->remove_s += 4;
libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1);
_libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1);
pkey->remove_s += 4;
memcpy(pkey->remove_s, "remove", sizeof("remove") - 1);
pkey->remove_s += sizeof("remove") - 1;
libssh2_htonu32(pkey->remove_s, name_len);
_libssh2_htonu32(pkey->remove_s, name_len);
pkey->remove_s += 4;
memcpy(pkey->remove_s, name, name_len);
pkey->remove_s += name_len;
libssh2_htonu32(pkey->remove_s, blob_len);
_libssh2_htonu32(pkey->remove_s, blob_len);
pkey->remove_s += 4;
memcpy(pkey->remove_s, blob, blob_len);
pkey->remove_s += blob_len;
@ -788,7 +772,7 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
pkey->remove_state = libssh2_NB_state_sent;
}
rc = libssh2_publickey_response_success(pkey);
rc = publickey_response_success(pkey);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
@ -798,9 +782,7 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
return rc;
}
/* }}} */
/* {{{ libssh2_publickey_list_fetch
/* libssh2_publickey_list_fetch
* Fetch a list of supported public key from a server
*/
LIBSSH2_API int
@ -819,9 +801,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
pkey->listFetch_data = NULL;
pkey->listFetch_s = pkey->listFetch_buffer;
libssh2_htonu32(pkey->listFetch_s, buffer_len - 4);
_libssh2_htonu32(pkey->listFetch_s, buffer_len - 4);
pkey->listFetch_s += 4;
libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1);
_libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1);
pkey->listFetch_s += 4;
memcpy(pkey->listFetch_s, "list", sizeof("list") - 1);
pkey->listFetch_s += sizeof("list") - 1;
@ -850,8 +832,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
}
while (1) {
rc = libssh2_publickey_packet_receive(pkey, &pkey->listFetch_data,
&pkey->listFetch_data_len);
rc = publickey_packet_receive(pkey, &pkey->listFetch_data,
&pkey->listFetch_data_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -863,8 +845,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
pkey->listFetch_s = pkey->listFetch_data;
if ((response =
libssh2_publickey_response_id(&pkey->listFetch_s,
pkey->listFetch_data_len)) < 0) {
publickey_response_id(&pkey->listFetch_s,
pkey->listFetch_data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code", 0);
goto err_exit;
@ -877,13 +859,13 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
unsigned long status, descr_len, lang_len;
unsigned char *descr, *lang;
status = libssh2_ntohu32(pkey->listFetch_s);
status = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
descr_len = libssh2_ntohu32(pkey->listFetch_s);
descr_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
descr = pkey->listFetch_s;
pkey->listFetch_s += descr_len;
lang_len = libssh2_ntohu32(pkey->listFetch_s);
lang_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
lang = pkey->listFetch_s;
pkey->listFetch_s += lang_len;
@ -904,8 +886,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
return 0;
}
libssh2_publickey_status_error(pkey, session, status, descr,
descr_len);
publickey_status_error(pkey, session, status, descr,
descr_len);
goto err_exit;
}
case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY:
@ -929,7 +911,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if (pkey->version == 1) {
unsigned long comment_len;
comment_len = libssh2_ntohu32(pkey->listFetch_s);
comment_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
if (comment_len) {
list[keys].num_attrs = 1;
@ -953,25 +935,25 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
list[keys].num_attrs = 0;
list[keys].attrs = NULL;
}
list[keys].name_len = libssh2_ntohu32(pkey->listFetch_s);
list[keys].name_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
list[keys].name = pkey->listFetch_s;
pkey->listFetch_s += list[keys].name_len;
list[keys].blob_len = libssh2_ntohu32(pkey->listFetch_s);
list[keys].blob_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
list[keys].blob = pkey->listFetch_s;
pkey->listFetch_s += list[keys].blob_len;
} else {
/* Version == 2 */
list[keys].name_len = libssh2_ntohu32(pkey->listFetch_s);
list[keys].name_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
list[keys].name = pkey->listFetch_s;
pkey->listFetch_s += list[keys].name_len;
list[keys].blob_len = libssh2_ntohu32(pkey->listFetch_s);
list[keys].blob_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
list[keys].blob = pkey->listFetch_s;
pkey->listFetch_s += list[keys].blob_len;
list[keys].num_attrs = libssh2_ntohu32(pkey->listFetch_s);
list[keys].num_attrs = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
if (list[keys].num_attrs) {
list[keys].attrs =
@ -986,12 +968,12 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
}
for(i = 0; i < list[keys].num_attrs; i++) {
list[keys].attrs[i].name_len =
libssh2_ntohu32(pkey->listFetch_s);
_libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
list[keys].attrs[i].name = (char *) pkey->listFetch_s;
pkey->listFetch_s += list[keys].attrs[i].name_len;
list[keys].attrs[i].value_len =
libssh2_ntohu32(pkey->listFetch_s);
_libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4;
list[keys].attrs[i].value = (char *) pkey->listFetch_s;
pkey->listFetch_s += list[keys].attrs[i].value_len;
@ -1030,9 +1012,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
return -1;
}
/* }}} */
/* {{{ libssh2_publickey_list_free
/* libssh2_publickey_list_free
* Free a previously fetched list of public keys
*/
LIBSSH2_API void
@ -1053,9 +1033,7 @@ libssh2_publickey_list_free(LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_FREE(session, pkey_list);
}
/* }}} */
/* {{{ libssh2_publickey_shutdown
/* libssh2_publickey_shutdown
* Shutdown the publickey subsystem
*/
LIBSSH2_API int
@ -1090,5 +1068,3 @@ libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY * pkey)
LIBSSH2_FREE(session, pkey);
return 0;
}
/* }}} */

View File

@ -404,8 +404,8 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
0);
session->scpRecv_err_len =
libssh2_channel_packet_data_len(session->
scpRecv_channel, 0);
_libssh2_channel_packet_data_len(session->
scpRecv_channel, 0);
session->scpRecv_err_msg =
LIBSSH2_ALLOC(session, session->scpRecv_err_len + 1);
if (!session->scpRecv_err_msg) {
@ -981,7 +981,7 @@ libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
"Invalid ACK response from remote", 0);
session->scpSend_err_len =
libssh2_channel_packet_data_len(session->scpSend_channel, 0);
_libssh2_channel_packet_data_len(session->scpSend_channel, 0);
session->scpSend_err_msg =
LIBSSH2_ALLOC(session, session->scpSend_err_len + 1);
if (!session->scpSend_err_msg) {

View File

@ -50,7 +50,7 @@
#include <alloca.h>
#endif
/* {{{ libssh2_default_alloc
/* libssh2_default_alloc
*/
static
LIBSSH2_ALLOC_FUNC(libssh2_default_alloc)
@ -59,9 +59,7 @@ LIBSSH2_ALLOC_FUNC(libssh2_default_alloc)
return malloc(count);
}
/* }}} */
/* {{{ libssh2_default_free
/* libssh2_default_free
*/
static
LIBSSH2_FREE_FUNC(libssh2_default_free)
@ -70,9 +68,7 @@ LIBSSH2_FREE_FUNC(libssh2_default_free)
free(ptr);
}
/* }}} */
/* {{{ libssh2_default_realloc
/* libssh2_default_realloc
*/
static
LIBSSH2_REALLOC_FUNC(libssh2_default_realloc)
@ -81,15 +77,15 @@ LIBSSH2_REALLOC_FUNC(libssh2_default_realloc)
return realloc(ptr, count);
}
/* }}} */
/* {{{ libssh2_banner_receive
/*
* banner_receive
*
* Wait for a hello from the remote host
* Allocate a buffer and store the banner in session->remote.banner
* Returns: 0 on success, PACKET_EAGAIN if read would block, 1 on failure
*/
static int
libssh2_banner_receive(LIBSSH2_SESSION * session)
banner_receive(LIBSSH2_SESSION * session)
{
int ret;
int banner_len;
@ -186,9 +182,9 @@ libssh2_banner_receive(LIBSSH2_SESSION * session)
return 0;
}
/* }}} */
/* {{{ libssh2_banner_send
/*
* banner_send
*
* Send the default banner, or the one set via libssh2_setopt_string
*
* Returns PACKET_EAGAIN if it would block - and if it does so, you should
@ -197,7 +193,7 @@ libssh2_banner_receive(LIBSSH2_SESSION * session)
* (same data pointer and same data_len) until zero or failure is returned.
*/
static int
libssh2_banner_send(LIBSSH2_SESSION * session)
banner_send(LIBSSH2_SESSION * session)
{
char *banner = (char *) LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF;
int banner_len = sizeof(LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF) - 1;
@ -254,16 +250,14 @@ libssh2_banner_send(LIBSSH2_SESSION * session)
return 0;
}
/* }}} */
/*
* _libssh2_nonblock() sets the given socket to either blocking or
* session_nonblock() sets the given socket to either blocking or
* non-blocking mode based on the 'nonblock' boolean argument. This function
* is copied from the libcurl sources with permission.
*/
static int
_libssh2_nonblock(int sockfd, /* operate on this */
int nonblock /* TRUE or FALSE */ )
session_nonblock(int sockfd, /* operate on this */
int nonblock /* TRUE or FALSE */ )
{
#undef SETBLOCK
#define SETBLOCK 0
@ -327,11 +321,12 @@ _libssh2_nonblock(int sockfd, /* operate on this */
}
/*
* _libssh2_get_socket_nonblocking() gets the given blocking or non-blocking
* state of the socket.
* get_socket_nonblocking()
*
* gets the given blocking or non-blocking state of the socket.
*/
static int
_libssh2_get_socket_nonblocking(int sockfd)
get_socket_nonblocking(int sockfd)
{ /* operate on this */
#undef GETBLOCK
#define GETBLOCK 0
@ -386,7 +381,7 @@ _libssh2_get_socket_nonblocking(int sockfd)
#endif
}
/* {{{ libssh2_banner_set
/* libssh2_banner_set
* Set the local banner
*/
LIBSSH2_API int
@ -421,9 +416,9 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner)
return 0;
}
/* }}} */
/* {{{ proto libssh2_session_init
/*
* proto libssh2_session_init
*
* Allocate and initialize a libssh2 session structure
* Allows for malloc callbacks in case the calling program has its own memory manager
* It's allowable (but unadvisable) to define some but not all of the malloc callbacks
@ -463,9 +458,9 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
return session;
}
/* }}} */
/* {{{ libssh2_session_callback_set
/*
* libssh2_session_callback_set
*
* Set (or reset) a callback function
* Returns the prior address
*
@ -510,9 +505,9 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session,
return NULL;
}
/* }}} */
/* {{{ proto libssh2_session_startup
/*
* proto libssh2_session_startup
*
* session: LIBSSH2_SESSION struct allocated and owned by the calling program
* Returns: 0 on success, or non-zero on failure
* Any memory allocated by libssh2 will use alloc/realloc/free
@ -537,14 +532,14 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
session->socket_fd = sock;
session->socket_block =
!_libssh2_get_socket_nonblocking(session->socket_fd);
!get_socket_nonblocking(session->socket_fd);
if (session->socket_block) {
/*
* Since we can't be sure that we are in blocking or there
* was an error detecting the state, so set to blocking to
* be sure
*/
_libssh2_nonblock(session->socket_fd, 0);
session_nonblock(session->socket_fd, 0);
}
session->startup_state = libssh2_NB_state_created;
@ -553,7 +548,7 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
/* TODO: Liveness check */
if (session->startup_state == libssh2_NB_state_created) {
rc = libssh2_banner_send(session);
rc = banner_send(session);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending banner to remote host", 0);
@ -569,7 +564,7 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
}
if (session->startup_state == libssh2_NB_state_sent) {
rc = libssh2_banner_receive(session);
rc = banner_receive(session);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for banner", 0);
@ -605,7 +600,7 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
/* Request the userauth service */
session->startup_service[0] = SSH_MSG_SERVICE_REQUEST;
libssh2_htonu32(session->startup_service + 1,
_libssh2_htonu32(session->startup_service + 1,
sizeof("ssh-userauth") - 1);
memcpy(session->startup_service + 5, "ssh-userauth",
sizeof("ssh-userauth") - 1);
@ -614,13 +609,14 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
}
if (session->startup_state == libssh2_NB_state_sent3) {
rc = libssh2_packet_write(session, session->startup_service,
sizeof("ssh-userauth") + 5 - 1);
rc = _libssh2_packet_write(session, session->startup_service,
sizeof("ssh-userauth") + 5 - 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block asking for ssh-userauth service", 0);
return LIBSSH2_ERROR_EAGAIN;
} else if (rc) {
}
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to ask for ssh-userauth service", 0);
return LIBSSH2_ERROR_SOCKET_SEND;
@ -630,17 +626,17 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
}
if (session->startup_state == libssh2_NB_state_sent4) {
rc = libssh2_packet_require(session, SSH_MSG_SERVICE_ACCEPT,
&session->startup_data,
&session->startup_data_len, 0, NULL, 0,
&session->startup_req_state);
rc = _libssh2_packet_require(session, SSH_MSG_SERVICE_ACCEPT,
&session->startup_data,
&session->startup_data_len, 0, NULL, 0,
&session->startup_req_state);
if (rc == PACKET_EAGAIN) {
return LIBSSH2_ERROR_EAGAIN;
} else if (rc) {
return LIBSSH2_ERROR_SOCKET_DISCONNECT;
}
session->startup_service_length =
libssh2_ntohu32(session->startup_data + 1);
_libssh2_ntohu32(session->startup_data + 1);
if ((session->startup_service_length != (sizeof("ssh-userauth") - 1))
|| strncmp("ssh-userauth", (char *) session->startup_data + 5,
@ -663,9 +659,9 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
return LIBSSH2_ERROR_INVAL;
}
/* }}} */
/* {{{ proto libssh2_session_free
/*
* libssh2_session_free
*
* Frees the memory allocated to the session
* Also closes and frees any channels attached to this session
*/
@ -699,7 +695,8 @@ libssh2_session_free(LIBSSH2_SESSION * session)
/* free */
LIBSSH2_FREE(session, tmp);
/* reverse linking isn't important here, we're killing the structure */
/* reverse linking isn't important here, we're killing the
* structure */
}
}
@ -898,9 +895,7 @@ libssh2_session_free(LIBSSH2_SESSION * session)
return 0;
}
/* }}} */
/* {{{ libssh2_session_disconnect_ex
/* libssh2_session_disconnect_ex
*/
LIBSSH2_API int
libssh2_session_disconnect_ex(LIBSSH2_SESSION * session, int reason,
@ -934,17 +929,17 @@ libssh2_session_disconnect_ex(LIBSSH2_SESSION * session, int reason,
}
*(s++) = SSH_MSG_DISCONNECT;
libssh2_htonu32(s, reason);
_libssh2_htonu32(s, reason);
s += 4;
libssh2_htonu32(s, descr_len);
_libssh2_htonu32(s, descr_len);
s += 4;
if (description) {
memcpy(s, description, descr_len);
s += descr_len;
}
libssh2_htonu32(s, lang_len);
_libssh2_htonu32(s, lang_len);
s += 4;
if (lang) {
memcpy(s, lang, lang_len);
@ -954,8 +949,8 @@ libssh2_session_disconnect_ex(LIBSSH2_SESSION * session, int reason,
session->disconnect_state = libssh2_NB_state_created;
}
rc = libssh2_packet_write(session, session->disconnect_data,
session->disconnect_data_len);
rc = _libssh2_packet_write(session, session->disconnect_data,
session->disconnect_data_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
@ -967,9 +962,7 @@ libssh2_session_disconnect_ex(LIBSSH2_SESSION * session, int reason,
return 0;
}
/* }}} */
/* {{{ libssh2_session_methods
/* libssh2_session_methods
* Return the currently active methods for method_type
* NOTE: Currently lang_cs and lang_sc are ALWAYS set to empty string regardless of actual negotiation
* Strings should NOT be freed
@ -1037,9 +1030,7 @@ libssh2_session_methods(LIBSSH2_SESSION * session, int method_type)
return method->name;
}
/* }}} */
/* {{{ libssh2_session_abstract
/* libssh2_session_abstract
* Retrieve a pointer to the abstract property
*/
LIBSSH2_API void **
@ -1048,9 +1039,7 @@ libssh2_session_abstract(LIBSSH2_SESSION * session)
return &session->abstract;
}
/* }}} */
/* {{{ libssh2_session_last_error
/* libssh2_session_last_error
* Returns error code and populates an error string into errmsg
* If want_buf is non-zero then the string placed into errmsg must be freed by the calling program
* Otherwise it is assumed to be owned by libssh2
@ -1106,9 +1095,7 @@ libssh2_session_last_error(LIBSSH2_SESSION * session, char **errmsg,
return session->err_code;
}
/* }}} */
/* {{{ libssh2_session_last_error
/* libssh2_session_last_error
* Returns error code
*/
LIBSSH2_API int
@ -1117,9 +1104,7 @@ libssh2_session_last_errno(LIBSSH2_SESSION * session)
return session->err_code;
}
/* }}} */
/* {{{ libssh2_session_flag
/* libssh2_session_flag
* Set/Get session flags
* Passing flag==0 will avoid changing session->flags while still returning its current value
*/
@ -1135,9 +1120,8 @@ libssh2_session_flag(LIBSSH2_SESSION * session, int flag, int value)
return session->flags;
}
/* }}} */
/* {{{ _libssh2_session_set_blocking
/* _libssh2_session_set_blocking
*
* Set a session's blocking mode on or off, return the previous status
* when this function is called.
*/
@ -1153,14 +1137,13 @@ _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking)
}
session->socket_block = blocking;
_libssh2_nonblock(session->socket_fd, !blocking);
session_nonblock(session->socket_fd, !blocking);
return bl;
}
/* }}} */
/* {{{ libssh2_session_set_blocking
/* libssh2_session_set_blocking
*
* Set a channel's blocking mode on or off, similar to a socket's
* fcntl(fd, F_SETFL, O_NONBLOCK); type command
*/
@ -1170,20 +1153,19 @@ libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking)
(void) _libssh2_session_set_blocking(session, blocking);
}
/* }}} */
/* {{{ libssh2_session_get_blocking
* Returns a session's blocking mode on or off
*/
/* libssh2_session_get_blocking
*
* Returns a session's blocking mode on or off
*/
LIBSSH2_API int
libssh2_session_get_blocking(LIBSSH2_SESSION * session)
{
return session->socket_block;
}
/* }}} */
/* {{{ libssh2_poll_channel_read
/*
* libssh2_poll_channel_read
*
* Returns 0 if no data is waiting on channel,
* non-0 if data is available
*/
@ -1193,18 +1175,17 @@ libssh2_poll_channel_read(LIBSSH2_CHANNEL * channel, int extended)
LIBSSH2_SESSION *session = channel->session;
LIBSSH2_PACKET *packet = session->packets.head;
while (packet)
{
if ( channel->local.id == libssh2_ntohu32(packet->data + 1)) {
if ( extended == 1 &&
(packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA
|| packet->data[0] == SSH_MSG_CHANNEL_DATA )) {
return 1;
} else if ( extended == 0 &&
packet->data[0] == SSH_MSG_CHANNEL_DATA) {
return 1;
}
/* else - no data of any type is ready to be read */
while (packet) {
if ( channel->local.id == _libssh2_ntohu32(packet->data + 1)) {
if ( extended == 1 &&
(packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA
|| packet->data[0] == SSH_MSG_CHANNEL_DATA )) {
return 1;
} else if ( extended == 0 &&
packet->data[0] == SSH_MSG_CHANNEL_DATA) {
return 1;
}
/* else - no data of any type is ready to be read */
}
packet = packet->next;
}
@ -1212,33 +1193,32 @@ libssh2_poll_channel_read(LIBSSH2_CHANNEL * channel, int extended)
return 0;
}
/* }}} */
/* {{{ libssh2_poll_channel_write
/*
* poll_channel_write
*
* Returns 0 if writing to channel would block,
* non-0 if data can be written without blocking
*/
static inline int
libssh2_poll_channel_write(LIBSSH2_CHANNEL * channel)
poll_channel_write(LIBSSH2_CHANNEL * channel)
{
return channel->local.window_size ? 1 : 0;
}
/* }}} */
/* {{{ libssh2_poll_listener_queued
/* poll_listener_queued
*
* Returns 0 if no connections are waiting to be accepted
* non-0 if one or more connections are available
*/
static inline int
libssh2_poll_listener_queued(LIBSSH2_LISTENER * listener)
poll_listener_queued(LIBSSH2_LISTENER * listener)
{
return listener->queue ? 1 : 0;
}
/* }}} */
/* {{{ libssh2_poll
/*
* libssh2_poll
*
* Poll sockets, channels, and listeners for activity
*/
LIBSSH2_API int
@ -1360,25 +1340,30 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
if (fds[i].events != fds[i].revents) {
switch (fds[i].type) {
case LIBSSH2_POLLFD_CHANNEL:
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want to be ready for read */
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* Not yet known to be ready for read */
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) &&
/* Want to be ready for read */
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) {
/* Not yet known to be ready for read */
fds[i].revents |=
libssh2_poll_channel_read(fds[i].fd.channel,
0) ?
LIBSSH2_POLLFD_POLLIN : 0;
}
if ((fds[i].events & LIBSSH2_POLLFD_POLLEXT) && /* Want to be ready for extended read */
((fds[i].revents & LIBSSH2_POLLFD_POLLEXT) == 0)) { /* Not yet known to be ready for extended read */
if ((fds[i].events & LIBSSH2_POLLFD_POLLEXT) &&
/* Want to be ready for extended read */
((fds[i].revents & LIBSSH2_POLLFD_POLLEXT) == 0)) {
/* Not yet known to be ready for extended read */
fds[i].revents |=
libssh2_poll_channel_read(fds[i].fd.channel,
1) ?
LIBSSH2_POLLFD_POLLEXT : 0;
}
if ((fds[i].events & LIBSSH2_POLLFD_POLLOUT) && /* Want to be ready for write */
((fds[i].revents & LIBSSH2_POLLFD_POLLOUT) == 0)) { /* Not yet known to be ready for write */
if ((fds[i].events & LIBSSH2_POLLFD_POLLOUT) &&
/* Want to be ready for write */
((fds[i].revents & LIBSSH2_POLLFD_POLLOUT) == 0)) {
/* Not yet known to be ready for write */
fds[i].revents |=
libssh2_poll_channel_write(fds[i].fd.
channel) ?
poll_channel_write(fds[i].fd. channel) ?
LIBSSH2_POLLFD_POLLOUT : 0;
}
if (fds[i].fd.channel->remote.close
@ -1394,11 +1379,13 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
break;
case LIBSSH2_POLLFD_LISTENER:
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want a connection */
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* No connections known of yet */
if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) &&
/* Want a connection */
((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) {
/* No connections known of yet */
fds[i].revents |=
libssh2_poll_listener_queued(fds[i].fd.
listener) ?
poll_listener_queued(fds[i].fd.
listener) ?
LIBSSH2_POLLFD_POLLIN : 0;
}
if (fds[i].fd.listener->session->socket_state ==
@ -1444,7 +1431,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
switch (fds[i].type) {
case LIBSSH2_POLLFD_SOCKET:
fds[i].revents = sockets[i].revents;
sockets[i].revents = 0; /* In case we loop again, be nice */
sockets[i].revents = 0; /* In case we loop again, be nice */
if (fds[i].revents) {
active_fds++;
}
@ -1452,7 +1439,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
case LIBSSH2_POLLFD_CHANNEL:
if (sockets[i].events & POLLIN) {
/* Spin session until no data available */
while (libssh2_packet_read(fds[i].fd.channel->session)
while (_libssh2_packet_read(fds[i].fd.channel->session)
> 0);
}
if (sockets[i].revents & POLLHUP) {
@ -1465,7 +1452,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
case LIBSSH2_POLLFD_LISTENER:
if (sockets[i].events & POLLIN) {
/* Spin session until no data available */
while (libssh2_packet_read(fds[i].fd.listener->session)
while (_libssh2_packet_read(fds[i].fd.listener->session)
> 0);
}
if (sockets[i].revents & POLLHUP) {
@ -1534,13 +1521,16 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
}
}
}
#endif /* else no select() or poll() -- timeout (and by extension timeout_remaining) will be equal to 0 */
#endif /* else no select() or poll() -- timeout (and by extension
* timeout_remaining) will be equal to 0 */
} while ((timeout_remaining > 0) && !active_fds);
return active_fds;
}
/* {{{ libssh2_session_block_direction
/*
* libssh2_session_block_direction
*
* Get blocked direction when a function returns LIBSSH2_ERROR_EAGAIN
* Returns LIBSSH2_SOCKET_BLOCK_INBOUND if recv() blocked
* or LIBSSH2_SOCKET_BLOCK_OUTBOUND if send() blocked
@ -1551,4 +1541,3 @@ libssh2_session_block_directions(LIBSSH2_SESSION *session)
return session->socket_block_directions;
}
/* }}} */

View File

@ -164,7 +164,7 @@ sftp_packet_read(LIBSSH2_SFTP * sftp)
return -1;
}
packet_len = libssh2_ntohu32(buffer);
packet_len = _libssh2_ntohu32(buffer);
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
"Data begin - Packet Length: %lu", packet_len);
if (packet_len > LIBSSH2_SFTP_PACKET_MAXLEN) {
@ -243,7 +243,7 @@ sftp_packet_ask(LIBSSH2_SFTP * sftp, unsigned char packet_type,
match_len = 1;
} else {
match_len = 5;
libssh2_htonu32(match_buf + 1, request_id);
_libssh2_htonu32(match_buf + 1, request_id);
}
while (packet) {
@ -364,7 +364,7 @@ sftp_packet_requirev(LIBSSH2_SFTP * sftp, int num_valid_responses,
sftp->requirev_start = 0;
return PACKET_TIMEOUT;
} else if (sftp->channel->session->socket_block
&& (libssh2_waitsocket(sftp->channel->session, left) <=
&& (_libssh2_waitsocket(sftp->channel->session, left) <=
0)) {
sftp->requirev_start = 0;
return PACKET_TIMEOUT;
@ -420,34 +420,34 @@ libssh2_sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs)
/* TODO: When we add SFTP4+ functionality flag_mask can get additional bits */
if (!attrs) {
libssh2_htonu32(s, 0);
_libssh2_htonu32(s, 0);
return 4;
}
libssh2_htonu32(s, attrs->flags & flag_mask);
_libssh2_htonu32(s, attrs->flags & flag_mask);
s += 4;
if (attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
libssh2_htonu64(s, attrs->filesize);
_libssh2_htonu64(s, attrs->filesize);
s += 8;
}
if (attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
libssh2_htonu32(s, attrs->uid);
_libssh2_htonu32(s, attrs->uid);
s += 4;
libssh2_htonu32(s, attrs->gid);
_libssh2_htonu32(s, attrs->gid);
s += 4;
}
if (attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
libssh2_htonu32(s, attrs->permissions);
_libssh2_htonu32(s, attrs->permissions);
s += 4;
}
if (attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
libssh2_htonu32(s, attrs->atime);
_libssh2_htonu32(s, attrs->atime);
s += 4;
libssh2_htonu32(s, attrs->mtime);
_libssh2_htonu32(s, attrs->mtime);
s += 4;
}
@ -464,30 +464,30 @@ libssh2_sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES * attrs, const unsigned char *p)
const unsigned char *s = p;
memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
attrs->flags = libssh2_ntohu32(s);
attrs->flags = _libssh2_ntohu32(s);
s += 4;
if (attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
attrs->filesize = libssh2_ntohu64(s);
attrs->filesize = _libssh2_ntohu64(s);
s += 8;
}
if (attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
attrs->uid = libssh2_ntohu32(s);
attrs->uid = _libssh2_ntohu32(s);
s += 4;
attrs->gid = libssh2_ntohu32(s);
attrs->gid = _libssh2_ntohu32(s);
s += 4;
}
if (attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
attrs->permissions = libssh2_ntohu32(s);
attrs->permissions = _libssh2_ntohu32(s);
s += 4;
}
if (attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
attrs->atime = libssh2_ntohu32(s);
attrs->atime = _libssh2_ntohu32(s);
s += 4;
attrs->mtime = libssh2_ntohu32(s);
attrs->mtime = _libssh2_ntohu32(s);
s += 4;
}
@ -614,9 +614,9 @@ libssh2_sftp_init(LIBSSH2_SESSION * session)
session->sftpInit_sftp->channel = session->sftpInit_channel;
session->sftpInit_sftp->request_id = 0;
libssh2_htonu32(session->sftpInit_buffer, 5);
_libssh2_htonu32(session->sftpInit_buffer, 5);
session->sftpInit_buffer[4] = SSH_FXP_INIT;
libssh2_htonu32(session->sftpInit_buffer + 5, LIBSSH2_SFTP_VERSION);
_libssh2_htonu32(session->sftpInit_buffer + 5, LIBSSH2_SFTP_VERSION);
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
"Sending FXP_INIT packet advertising version %d support",
@ -661,7 +661,7 @@ libssh2_sftp_init(LIBSSH2_SESSION * session)
}
s = data + 1;
session->sftpInit_sftp->version = libssh2_ntohu32(s);
session->sftpInit_sftp->version = _libssh2_ntohu32(s);
s += 4;
if (session->sftpInit_sftp->version > LIBSSH2_SFTP_VERSION) {
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
@ -676,12 +676,12 @@ libssh2_sftp_init(LIBSSH2_SESSION * session)
unsigned char *extension_name, *extension_data;
unsigned long extname_len, extdata_len;
extname_len = libssh2_ntohu32(s);
extname_len = _libssh2_ntohu32(s);
s += 4;
extension_name = s;
s += extname_len;
extdata_len = libssh2_ntohu32(s);
extdata_len = _libssh2_ntohu32(s);
s += 4;
extension_data = s;
s += extdata_len;
@ -814,20 +814,20 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP * sftp, const char *filename,
LIBSSH2_SFTP_OPENFILE) ? LIBSSH2_SFTP_ATTR_PFILETYPE_FILE :
LIBSSH2_SFTP_ATTR_PFILETYPE_DIR);
libssh2_htonu32(s, sftp->open_packet_len - 4);
_libssh2_htonu32(s, sftp->open_packet_len - 4);
s += 4;
*(s++) =
(open_type ==
LIBSSH2_SFTP_OPENFILE) ? SSH_FXP_OPEN : SSH_FXP_OPENDIR;
sftp->open_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->open_request_id);
_libssh2_htonu32(s, sftp->open_request_id);
s += 4;
libssh2_htonu32(s, filename_len);
_libssh2_htonu32(s, filename_len);
s += 4;
memcpy(s, filename, filename_len);
s += filename_len;
if (open_type == LIBSSH2_SFTP_OPENFILE) {
libssh2_htonu32(s, flags);
_libssh2_htonu32(s, flags);
s += 4;
s += libssh2_sftp_attr2bin(s, &attrs);
}
@ -890,7 +890,7 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP * sftp, const char *filename,
we need to properly deal with that. */
if (data[0] == SSH_FXP_STATUS) {
int badness = 1;
sftp->last_errno = libssh2_ntohu32(data + 5);
sftp->last_errno = _libssh2_ntohu32(data + 5);
if(LIBSSH2_FX_OK == sftp->last_errno) {
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "got HANDLE FXOK!");
@ -931,7 +931,7 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP * sftp, const char *filename,
LIBSSH2_SFTP_OPENFILE) ? LIBSSH2_SFTP_HANDLE_FILE :
LIBSSH2_SFTP_HANDLE_DIR;
fp->handle_len = libssh2_ntohu32(data + 5);
fp->handle_len = _libssh2_ntohu32(data + 5);
if (fp->handle_len > SFTP_HANDLE_MAXLEN) {
/* SFTP doesn't allow handles longer than 256 characters */
fp->handle_len = SFTP_HANDLE_MAXLEN;
@ -1022,22 +1022,22 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
#endif
if (sftp->read_state == libssh2_NB_state_allocated) {
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_READ;
request_id = sftp->request_id++;
libssh2_htonu32(s, request_id);
_libssh2_htonu32(s, request_id);
s += 4;
libssh2_htonu32(s, handle->handle_len);
_libssh2_htonu32(s, handle->handle_len);
s += 4;
memcpy(s, handle->handle, handle->handle_len);
s += handle->handle_len;
libssh2_htonu64(s, handle->u.file.offset);
_libssh2_htonu64(s, handle->u.file.offset);
s += 8;
libssh2_htonu32(s, bytes_requested);
_libssh2_htonu32(s, bytes_requested);
s += 4;
sftp->read_state = libssh2_NB_state_created;
@ -1089,7 +1089,7 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
switch (data[0]) {
case SSH_FXP_STATUS:
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
sftp->read_packet = NULL;
sftp->read_state = libssh2_NB_state_idle;
@ -1104,7 +1104,7 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
}
case SSH_FXP_DATA:
bytes_read = libssh2_ntohu32(data + 5);
bytes_read = _libssh2_ntohu32(data + 5);
if (bytes_read > (data_len - 9)) {
sftp->read_packet = NULL;
sftp->read_state = libssh2_NB_state_idle;
@ -1160,7 +1160,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
* feed it back from the buffer
*/
unsigned char *s = (unsigned char *) handle->u.dir.next_name;
unsigned long real_filename_len = libssh2_ntohu32(s);
unsigned long real_filename_len = _libssh2_ntohu32(s);
filename_len = real_filename_len;
s += 4;
@ -1177,9 +1177,9 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
if ((longentry == NULL) || (longentry_maxlen == 0)) {
/* Skip longname */
s += 4 + libssh2_ntohu32(s);
s += 4 + _libssh2_ntohu32(s);
} else {
unsigned long real_longentry_len = libssh2_ntohu32(s);
unsigned long real_longentry_len = _libssh2_ntohu32(s);
longentry_len = real_longentry_len;
s += 4;
@ -1221,13 +1221,13 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_READDIR;
sftp->readdir_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->readdir_request_id);
_libssh2_htonu32(s, sftp->readdir_request_id);
s += 4;
libssh2_htonu32(s, handle->handle_len);
_libssh2_htonu32(s, handle->handle_len);
s += 4;
memcpy(s, handle->handle, handle->handle_len);
s += handle->handle_len;
@ -1275,7 +1275,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
}
if (data[0] == SSH_FXP_STATUS) {
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_EOF) {
sftp->readdir_state = libssh2_NB_state_idle;
@ -1289,7 +1289,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
}
}
num_names = libssh2_ntohu32(data + 5);
num_names = _libssh2_ntohu32(data + 5);
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "%lu entries returned",
num_names);
if (num_names <= 0) {
@ -1299,7 +1299,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
}
if (num_names == 1) {
unsigned long real_filename_len = libssh2_ntohu32(data + 9);
unsigned long real_filename_len = _libssh2_ntohu32(data + 9);
filename_len = real_filename_len;
if (filename_len > buffer_maxlen) {
@ -1316,7 +1316,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
libssh2_sftp_bin2attr(attrs, data + 13 + real_filename_len +
(4 +
libssh2_ntohu32(data + 13 +
_libssh2_ntohu32(data + 13 +
real_filename_len)));
}
LIBSSH2_FREE(session, data);
@ -1365,19 +1365,19 @@ libssh2_sftp_write(LIBSSH2_SFTP_HANDLE * handle, const char *buffer,
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_WRITE;
sftp->write_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->write_request_id);
_libssh2_htonu32(s, sftp->write_request_id);
s += 4;
libssh2_htonu32(s, handle->handle_len);
_libssh2_htonu32(s, handle->handle_len);
s += 4;
memcpy(s, handle->handle, handle->handle_len);
s += handle->handle_len;
libssh2_htonu64(s, handle->u.file.offset);
_libssh2_htonu64(s, handle->u.file.offset);
s += 8;
libssh2_htonu32(s, count);
_libssh2_htonu32(s, count);
s += 4;
memcpy(s, buffer, count);
s += count;
@ -1418,7 +1418,7 @@ libssh2_sftp_write(LIBSSH2_SFTP_HANDLE * handle, const char *buffer,
sftp->write_state = libssh2_NB_state_idle;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
@ -1464,13 +1464,13 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE * handle,
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = setstat ? SSH_FXP_FSETSTAT : SSH_FXP_FSTAT;
sftp->fstat_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->fstat_request_id);
_libssh2_htonu32(s, sftp->fstat_request_id);
s += 4;
libssh2_htonu32(s, handle->handle_len);
_libssh2_htonu32(s, handle->handle_len);
s += 4;
memcpy(s, handle->handle, handle->handle_len);
s += handle->handle_len;
@ -1518,7 +1518,7 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE * handle,
if (data[0] == SSH_FXP_STATUS) {
int retcode;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
return 0;
@ -1605,13 +1605,13 @@ libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE * handle)
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_CLOSE;
handle->close_request_id = sftp->request_id++;
libssh2_htonu32(s, handle->close_request_id);
_libssh2_htonu32(s, handle->close_request_id);
s += 4;
libssh2_htonu32(s, handle->handle_len);
_libssh2_htonu32(s, handle->handle_len);
s += 4;
memcpy(s, handle->handle, handle->handle_len);
s += handle->handle_len;
@ -1655,7 +1655,7 @@ libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE * handle)
handle->close_state = libssh2_NB_state_sent1;
}
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode != LIBSSH2_FX_OK) {
@ -1717,13 +1717,13 @@ libssh2_sftp_unlink_ex(LIBSSH2_SFTP * sftp, const char *filename,
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_REMOVE;
sftp->unlink_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->unlink_request_id);
_libssh2_htonu32(s, sftp->unlink_request_id);
s += 4;
libssh2_htonu32(s, filename_len);
_libssh2_htonu32(s, filename_len);
s += 4;
memcpy(s, filename, filename_len);
s += filename_len;
@ -1765,7 +1765,7 @@ libssh2_sftp_unlink_ex(LIBSSH2_SFTP * sftp, const char *filename,
sftp->unlink_state = libssh2_NB_state_idle;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
@ -1818,23 +1818,23 @@ libssh2_sftp_rename_ex(LIBSSH2_SFTP * sftp, const char *source_filename,
return -1;
}
libssh2_htonu32(sftp->rename_s, packet_len - 4);
_libssh2_htonu32(sftp->rename_s, packet_len - 4);
sftp->rename_s += 4;
*(sftp->rename_s++) = SSH_FXP_RENAME;
sftp->rename_request_id = sftp->request_id++;
libssh2_htonu32(sftp->rename_s, sftp->rename_request_id);
_libssh2_htonu32(sftp->rename_s, sftp->rename_request_id);
sftp->rename_s += 4;
libssh2_htonu32(sftp->rename_s, source_filename_len);
_libssh2_htonu32(sftp->rename_s, source_filename_len);
sftp->rename_s += 4;
memcpy(sftp->rename_s, source_filename, source_filename_len);
sftp->rename_s += source_filename_len;
libssh2_htonu32(sftp->rename_s, dest_filename_len);
_libssh2_htonu32(sftp->rename_s, dest_filename_len);
sftp->rename_s += 4;
memcpy(sftp->rename_s, dest_filename, dest_filename_len);
sftp->rename_s += dest_filename_len;
if (sftp->version >= 5) {
libssh2_htonu32(sftp->rename_s, flags);
_libssh2_htonu32(sftp->rename_s, flags);
sftp->rename_s += 4;
}
@ -1874,7 +1874,7 @@ libssh2_sftp_rename_ex(LIBSSH2_SFTP * sftp, const char *source_filename,
sftp->rename_state = libssh2_NB_state_idle;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
switch (retcode) {
@ -1939,13 +1939,13 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
/* Filetype in SFTP 3 and earlier */
attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR;
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_MKDIR;
sftp->mkdir_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->mkdir_request_id);
_libssh2_htonu32(s, sftp->mkdir_request_id);
s += 4;
libssh2_htonu32(s, path_len);
_libssh2_htonu32(s, path_len);
s += 4;
memcpy(s, path, path_len);
s += path_len;
@ -1987,7 +1987,7 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
sftp->mkdir_state = libssh2_NB_state_idle;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
@ -2029,13 +2029,13 @@ libssh2_sftp_rmdir_ex(LIBSSH2_SFTP * sftp, const char *path,
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_RMDIR;
sftp->rmdir_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->rmdir_request_id);
_libssh2_htonu32(s, sftp->rmdir_request_id);
s += 4;
libssh2_htonu32(s, path_len);
_libssh2_htonu32(s, path_len);
s += 4;
memcpy(s, path, path_len);
s += path_len;
@ -2075,7 +2075,7 @@ libssh2_sftp_rmdir_ex(LIBSSH2_SFTP * sftp, const char *path,
sftp->rmdir_state = libssh2_NB_state_idle;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
@ -2124,7 +2124,7 @@ libssh2_sftp_stat_ex(LIBSSH2_SFTP * sftp, const char *path,
return -1;
}
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
switch (stat_type) {
case LIBSSH2_SFTP_SETSTAT:
@ -2140,9 +2140,9 @@ libssh2_sftp_stat_ex(LIBSSH2_SFTP * sftp, const char *path,
*(s++) = SSH_FXP_STAT;
}
sftp->stat_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->stat_request_id);
_libssh2_htonu32(s, sftp->stat_request_id);
s += 4;
libssh2_htonu32(s, path_len);
_libssh2_htonu32(s, path_len);
s += 4;
memcpy(s, path, path_len);
s += path_len;
@ -2188,7 +2188,7 @@ libssh2_sftp_stat_ex(LIBSSH2_SFTP * sftp, const char *path,
if (data[0] == SSH_FXP_STATUS) {
int retcode;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
return 0;
@ -2250,7 +2250,7 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP * sftp, const char *path,
(link_type ==
LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink", path);
libssh2_htonu32(s, packet_len - 4);
_libssh2_htonu32(s, packet_len - 4);
s += 4;
switch (link_type) {
case LIBSSH2_SFTP_REALPATH:
@ -2266,14 +2266,14 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP * sftp, const char *path,
*(s++) = SSH_FXP_READLINK;
}
sftp->symlink_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->symlink_request_id);
_libssh2_htonu32(s, sftp->symlink_request_id);
s += 4;
libssh2_htonu32(s, path_len);
_libssh2_htonu32(s, path_len);
s += 4;
memcpy(s, path, path_len);
s += path_len;
if (link_type == LIBSSH2_SFTP_SYMLINK) {
libssh2_htonu32(s, target_len);
_libssh2_htonu32(s, target_len);
s += 4;
memcpy(s, target, target_len);
s += target_len;
@ -2320,7 +2320,7 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP * sftp, const char *path,
if (data[0] == SSH_FXP_STATUS) {
int retcode;
retcode = libssh2_ntohu32(data + 5);
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
return 0;
@ -2332,7 +2332,7 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP * sftp, const char *path,
}
}
if (libssh2_ntohu32(data + 5) < 1) {
if (_libssh2_ntohu32(data + 5) < 1) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid READLINK/REALPATH response, no name entries",
0);
@ -2340,7 +2340,7 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP * sftp, const char *path,
return -1;
}
link_len = libssh2_ntohu32(data + 9);
link_len = _libssh2_ntohu32(data + 9);
if (link_len >= target_len) {
link_len = target_len - 1;
}

View File

@ -227,9 +227,9 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
}
if (session->fullpacket_state == libssh2_NB_state_created) {
rc = libssh2_packet_add(session, p->payload,
session->fullpacket_payload_len,
session->fullpacket_macstate);
rc = _libssh2_packet_add(session, p->payload,
session->fullpacket_payload_len,
session->fullpacket_macstate);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc < 0) {
@ -244,7 +244,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
/*
* libssh2_packet_read
* _libssh2_packet_read
*
* Collect a packet into the input brigade block only controls whether or not
* to wait for a packet to start.
@ -259,7 +259,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
* "The Secure Shell (SSH) Transport Layer Protocol"
*/
libssh2pack_t
libssh2_packet_read(LIBSSH2_SESSION * session)
_libssh2_packet_read(LIBSSH2_SESSION * session)
{
libssh2pack_t rc;
struct transportpacket *p = &session->packet;
@ -438,7 +438,7 @@ libssh2_packet_read(LIBSSH2_SESSION * session)
/* we now have the initial blocksize bytes decrypted,
* and we can extract packet and padding length from it
*/
p->packet_length = libssh2_ntohu32(block);
p->packet_length = _libssh2_ntohu32(block);
p->padding_length = block[4];
/* total_num is the number of bytes following the initial
@ -661,8 +661,8 @@ send_existing(LIBSSH2_SESSION * session, unsigned char *data,
* (RFC4253 section 6.1)
*/
int
libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long data_len)
_libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long data_len)
{
int blocksize =
(session->state & LIBSSH2_STATE_NEWKEYS) ? session->local.crypt->
@ -752,7 +752,7 @@ libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
/* store packet_length, which is the size of the whole packet except
the MAC and the packet_length field itself */
libssh2_htonu32(p->outbuf, packet_length - 4);
_libssh2_htonu32(p->outbuf, packet_length - 4);
/* store padding_length */
p->outbuf[4] = padding_length;
/* copy the payload data */

View File

@ -80,19 +80,19 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *username,
}
*(s++) = SSH_MSG_USERAUTH_REQUEST;
libssh2_htonu32(s, username_len);
_libssh2_htonu32(s, username_len);
s += 4;
if (username) {
memcpy(s, username, username_len);
s += username_len;
}
libssh2_htonu32(s, 14);
_libssh2_htonu32(s, 14);
s += 4;
memcpy(s, "ssh-connection", 14);
s += 14;
libssh2_htonu32(s, 4);
_libssh2_htonu32(s, 4);
s += 4;
memcpy(s, "none", 4);
s += 4;
@ -101,7 +101,7 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *username,
}
if (session->userauth_list_state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, session->userauth_list_data,
rc = _libssh2_packet_write(session, session->userauth_list_data,
session->userauth_list_data_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
@ -122,11 +122,11 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *username,
}
if (session->userauth_list_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_list_data,
&session->userauth_list_data_len, 0,
NULL, 0,
&session->userauth_list_packet_requirev_state);
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_list_data,
&session->userauth_list_data_len, 0,
NULL, 0,
&session->userauth_list_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list", 0);
@ -147,11 +147,11 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *username,
return NULL;
}
methods_len = libssh2_ntohu32(session->userauth_list_data + 1);
methods_len = _libssh2_ntohu32(session->userauth_list_data + 1);
/* Do note that the memory areas overlap! */
memmove(session->userauth_list_data, session->userauth_list_data + 5,
methods_len);
methods_len);
session->userauth_list_data[methods_len] = '\0';
_libssh2_debug(session, LIBSSH2_DBG_AUTH, "Permitted auth methods: %s",
session->userauth_list_data);
@ -161,10 +161,10 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *username,
return (char *) session->userauth_list_data;
}
/* }}} */
/* {{{ libssh2_userauth_authenticated
* 0 if not yet authenticated
/*
* libssh2_userauth_authenticated
*
* Returns: 0 if not yet authenticated
* non-zero is already authenticated
*/
LIBSSH2_API int
@ -197,7 +197,7 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
sizeof(session->userauth_pswd_packet_requirev_state));
/*
* 40 = acket_type(1) + username_len(4) + service_len(4) +
* 40 = acket_type(1) + username_len(4) + service_len(4) +
* service(14)"ssh-connection" + method_len(4) + method(8)"password" +
* chgpwdbool(1) + password_len(4) */
session->userauth_pswd_data_len = username_len + password_len + 40;
@ -214,17 +214,17 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
}
*(s++) = SSH_MSG_USERAUTH_REQUEST;
libssh2_htonu32(s, username_len);
_libssh2_htonu32(s, username_len);
s += 4;
memcpy(s, username, username_len);
s += username_len;
libssh2_htonu32(s, sizeof("ssh-connection") - 1);
_libssh2_htonu32(s, sizeof("ssh-connection") - 1);
s += 4;
memcpy(s, "ssh-connection", sizeof("ssh-connection") - 1);
s += sizeof("ssh-connection") - 1;
libssh2_htonu32(s, sizeof("password") - 1);
_libssh2_htonu32(s, sizeof("password") - 1);
s += 4;
memcpy(s, "password", sizeof("password") - 1);
s += sizeof("password") - 1;
@ -232,7 +232,7 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
*s = '\0';
s++;
libssh2_htonu32(s, password_len);
_libssh2_htonu32(s, password_len);
s += 4;
memcpy(s, password, password_len);
s += password_len;
@ -244,7 +244,7 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
}
if (session->userauth_pswd_state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, session->userauth_pswd_data,
rc = _libssh2_packet_write(session, session->userauth_pswd_data,
session->userauth_pswd_data_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
@ -268,12 +268,12 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
|| (session->userauth_pswd_state == libssh2_NB_state_sent1)
|| (session->userauth_pswd_state == libssh2_NB_state_sent2)) {
if (session->userauth_pswd_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_pswd_data,
&session->userauth_pswd_data_len,
0, NULL, 0,
&session->
userauth_pswd_packet_requirev_state);
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_pswd_data,
&session->userauth_pswd_data_len,
0, NULL, 0,
&session->
userauth_pswd_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -344,18 +344,18 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
}
*(s++) = SSH_MSG_USERAUTH_REQUEST;
libssh2_htonu32(s, username_len);
_libssh2_htonu32(s, username_len);
s += 4;
memcpy(s, username, username_len);
s += username_len;
libssh2_htonu32(s, sizeof("ssh-connection") - 1);
_libssh2_htonu32(s, sizeof("ssh-connection") - 1);
s += 4;
memcpy(s, "ssh-connection",
sizeof("ssh-connection") - 1);
s += sizeof("ssh-connection") - 1;
libssh2_htonu32(s, sizeof("password") - 1);
_libssh2_htonu32(s, sizeof("password") - 1);
s += 4;
memcpy(s, "password", sizeof("password") - 1);
s += sizeof("password") - 1;
@ -363,12 +363,12 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
*s = 0x01;
s++;
libssh2_htonu32(s, password_len);
_libssh2_htonu32(s, password_len);
s += 4;
memcpy(s, password, password_len);
s += password_len;
libssh2_htonu32(s, session->userauth_pswd_newpw_len);
_libssh2_htonu32(s, session->userauth_pswd_newpw_len);
s += 4;
memcpy(s, session->userauth_pswd_newpw,
session->userauth_pswd_newpw_len);
@ -378,7 +378,7 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
}
if (session->userauth_pswd_state == libssh2_NB_state_sent2) {
rc = libssh2_packet_write(session,
rc = _libssh2_packet_write(session,
session->userauth_pswd_data,
session->
userauth_pswd_data_len);
@ -427,15 +427,17 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
/* }}} */
/* {{{ libssh2_file_read_publickey
/*
* file_read_publickey
*
* Read a public key from an id_???.pub style file
*/
static int
libssh2_file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
unsigned long *method_len,
unsigned char **pubkeydata,
unsigned long *pubkeydata_len,
const char *pubkeyfile)
file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
unsigned long *method_len,
unsigned char **pubkeydata,
unsigned long *pubkeydata_len,
const char *pubkeyfile)
{
FILE *fd;
char c;
@ -502,7 +504,7 @@ libssh2_file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
return -1;
}
/* Wasting some bytes here (okay, more than some),
* but since it's likely to be freed soon anyway,
* but since it's likely to be freed soon anyway,
* we'll just avoid the extra free/alloc and call it a wash */
*method = pubkey;
*method_len = sp1 - pubkey;
@ -606,17 +608,17 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
memset(&session->userauth_host_packet_requirev_state, 0,
sizeof(session->userauth_host_packet_requirev_state));
if (libssh2_file_read_publickey
(session, &session->userauth_host_method,
&session->userauth_host_method_len, &pubkeydata, &pubkeydata_len,
publickey)) {
if (file_read_publickey(session, &session->userauth_host_method,
&session->userauth_host_method_len,
&pubkeydata, &pubkeydata_len,
publickey)) {
return -1;
}
/*
* 48 = packet_type(1) + username_len(4) + servicename_len(4) +
* 48 = packet_type(1) + username_len(4) + servicename_len(4) +
* service_name(14)"ssh-connection" + authmethod_len(4) +
* authmethod(9)"hostbased" + method_len(4) + pubkeydata_len(4) +
* authmethod(9)"hostbased" + method_len(4) + pubkeydata_len(4) +
* local_username_len(4)
*/
session->userauth_host_packet_len =
@ -625,7 +627,7 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
/*
* Preallocate space for an overall length, method name again,
* and the signature, which won't be any larger than the size of
* and the signature, which won't be any larger than the size of
* the publickeydata itself
*/
session->userauth_host_s = session->userauth_host_packet =
@ -641,39 +643,39 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
}
*(session->userauth_host_s++) = SSH_MSG_USERAUTH_REQUEST;
libssh2_htonu32(session->userauth_host_s, username_len);
_libssh2_htonu32(session->userauth_host_s, username_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, username, username_len);
session->userauth_host_s += username_len;
libssh2_htonu32(session->userauth_host_s, 14);
_libssh2_htonu32(session->userauth_host_s, 14);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, "ssh-connection", 14);
session->userauth_host_s += 14;
libssh2_htonu32(session->userauth_host_s, 9);
_libssh2_htonu32(session->userauth_host_s, 9);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, "hostbased", 9);
session->userauth_host_s += 9;
libssh2_htonu32(session->userauth_host_s,
_libssh2_htonu32(session->userauth_host_s,
session->userauth_host_method_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, session->userauth_host_method,
session->userauth_host_method_len);
session->userauth_host_s += session->userauth_host_method_len;
libssh2_htonu32(session->userauth_host_s, pubkeydata_len);
_libssh2_htonu32(session->userauth_host_s, pubkeydata_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, pubkeydata, pubkeydata_len);
session->userauth_host_s += pubkeydata_len;
libssh2_htonu32(session->userauth_host_s, hostname_len);
_libssh2_htonu32(session->userauth_host_s, hostname_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, hostname, hostname_len);
session->userauth_host_s += hostname_len;
libssh2_htonu32(session->userauth_host_s, local_username_len);
_libssh2_htonu32(session->userauth_host_s, local_username_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, local_username, local_username_len);
session->userauth_host_s += local_username_len;
@ -688,7 +690,7 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
return -1;
}
libssh2_htonu32(buf, session->session_id_len);
_libssh2_htonu32(buf, session->session_id_len);
datavec[0].iov_base = buf;
datavec[0].iov_len = 4;
datavec[1].iov_base = session->session_id;
@ -732,11 +734,11 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
session->userauth_host_s =
session->userauth_host_packet + session->userauth_host_packet_len;
libssh2_htonu32(session->userauth_host_s,
_libssh2_htonu32(session->userauth_host_s,
4 + session->userauth_host_method_len + 4 + sig_len);
session->userauth_host_s += 4;
libssh2_htonu32(session->userauth_host_s,
_libssh2_htonu32(session->userauth_host_s,
session->userauth_host_method_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, session->userauth_host_method,
@ -745,7 +747,7 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL;
libssh2_htonu32(session->userauth_host_s, sig_len);
_libssh2_htonu32(session->userauth_host_s, sig_len);
session->userauth_host_s += 4;
memcpy(session->userauth_host_s, sig, sig_len);
session->userauth_host_s += sig_len;
@ -758,7 +760,7 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
}
if (session->userauth_host_state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, session->userauth_host_packet,
rc = _libssh2_packet_write(session, session->userauth_host_packet,
session->userauth_host_s -
session->userauth_host_packet);
if (rc == PACKET_EAGAIN) {
@ -779,11 +781,11 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
if (session->userauth_host_state == libssh2_NB_state_sent) {
unsigned long data_len;
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_host_data,
&data_len, 0, NULL, 0,
&session->
userauth_host_packet_requirev_state);
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_host_data,
&data_len, 0, NULL, 0,
&session->
userauth_host_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -840,16 +842,15 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
memset(&session->userauth_pblc_packet_requirev_state, 0,
sizeof(session->userauth_pblc_packet_requirev_state));
if (libssh2_file_read_publickey
(session, &session->userauth_pblc_method,
&session->userauth_pblc_method_len, &pubkeydata, &pubkeydata_len,
publickey)) {
if (file_read_publickey(session, &session->userauth_pblc_method,
&session->userauth_pblc_method_len,
&pubkeydata, &pubkeydata_len,publickey)) {
return -1;
}
/*
* 45 = packet_type(1) + username_len(4) + servicename_len(4) +
* service_name(14)"ssh-connection" + authmethod_len(4) +
* 45 = packet_type(1) + username_len(4) + servicename_len(4) +
* service_name(14)"ssh-connection" + authmethod_len(4) +
* authmethod(9)"publickey" + sig_included(1)'\0' + algmethod_len(4) +
* publickey_len(4)
*/
@ -859,7 +860,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
/*
* Preallocate space for an overall length, method name again, and
* the signature, which won't be any larger than the size of the
* the signature, which won't be any larger than the size of the
* publickeydata itself
*/
session->userauth_pblc_s = session->userauth_pblc_packet =
@ -876,17 +877,17 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
}
*(session->userauth_pblc_s++) = SSH_MSG_USERAUTH_REQUEST;
libssh2_htonu32(session->userauth_pblc_s, username_len);
_libssh2_htonu32(session->userauth_pblc_s, username_len);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, username, username_len);
session->userauth_pblc_s += username_len;
libssh2_htonu32(session->userauth_pblc_s, 14);
_libssh2_htonu32(session->userauth_pblc_s, 14);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, "ssh-connection", 14);
session->userauth_pblc_s += 14;
libssh2_htonu32(session->userauth_pblc_s, 9);
_libssh2_htonu32(session->userauth_pblc_s, 9);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, "publickey", 9);
session->userauth_pblc_s += 9;
@ -895,14 +896,14 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
/* Not sending signature with *this* packet */
*(session->userauth_pblc_s++) = 0;
libssh2_htonu32(session->userauth_pblc_s,
_libssh2_htonu32(session->userauth_pblc_s,
session->userauth_pblc_method_len);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, session->userauth_pblc_method,
session->userauth_pblc_method_len);
session->userauth_pblc_s += session->userauth_pblc_method_len;
libssh2_htonu32(session->userauth_pblc_s, pubkeydata_len);
_libssh2_htonu32(session->userauth_pblc_s, pubkeydata_len);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, pubkeydata, pubkeydata_len);
session->userauth_pblc_s += pubkeydata_len;
@ -915,7 +916,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
}
if (session->userauth_pblc_state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, session->userauth_pblc_packet,
rc = _libssh2_packet_write(session, session->userauth_pblc_packet,
session->userauth_pblc_packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
@ -941,12 +942,12 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
unsigned char *sig;
unsigned long sig_len;
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0,
NULL, 0,
&session->
userauth_pblc_packet_requirev_state);
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0,
NULL, 0,
&session->
userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1007,7 +1008,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
*session->userauth_pblc_b = 0x01;
libssh2_htonu32(buf, session->session_id_len);
_libssh2_htonu32(buf, session->session_id_len);
datavec[0].iov_base = buf;
datavec[0].iov_len = 4;
datavec[1].iov_base = session->session_id;
@ -1031,10 +1032,10 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
privkeyobj->dtor(session, &abstract);
}
/*
* If this function was restarted, pubkeydata_len might still be 0
* which will cause an unnecessary but harmless realloc here.
*/
/*
* If this function was restarted, pubkeydata_len might still be 0
* which will cause an unnecessary but harmless realloc here.
*/
if (sig_len > pubkeydata_len) {
unsigned char *newpacket;
/* Should *NEVER* happen, but...well.. better safe than sorry */
@ -1058,11 +1059,11 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
session->userauth_pblc_packet + session->userauth_pblc_packet_len;
session->userauth_pblc_b = NULL;
libssh2_htonu32(session->userauth_pblc_s,
_libssh2_htonu32(session->userauth_pblc_s,
4 + session->userauth_pblc_method_len + 4 + sig_len);
session->userauth_pblc_s += 4;
libssh2_htonu32(session->userauth_pblc_s,
_libssh2_htonu32(session->userauth_pblc_s,
session->userauth_pblc_method_len);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, session->userauth_pblc_method,
@ -1071,7 +1072,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
libssh2_htonu32(session->userauth_pblc_s, sig_len);
_libssh2_htonu32(session->userauth_pblc_s, sig_len);
session->userauth_pblc_s += 4;
memcpy(session->userauth_pblc_s, sig, sig_len);
session->userauth_pblc_s += sig_len;
@ -1084,7 +1085,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
}
if (session->userauth_pblc_state == libssh2_NB_state_sent1) {
rc = libssh2_packet_write(session, session->userauth_pblc_packet,
rc = _libssh2_packet_write(session, session->userauth_pblc_packet,
session->userauth_pblc_s -
session->userauth_pblc_packet);
if (rc == PACKET_EAGAIN) {
@ -1106,10 +1107,10 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
/* PK_OK is no longer valid */
reply_codes[2] = 0;
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0, NULL, 0,
&session->userauth_pblc_packet_requirev_state);
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0, NULL, 0,
&session->userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1190,29 +1191,29 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
*s++ = SSH_MSG_USERAUTH_REQUEST;
/* user name */
libssh2_htonu32(s, username_len);
_libssh2_htonu32(s, username_len);
s += 4;
memcpy(s, username, username_len);
s += username_len;
/* service name */
libssh2_htonu32(s, sizeof("ssh-connection") - 1);
_libssh2_htonu32(s, sizeof("ssh-connection") - 1);
s += 4;
memcpy(s, "ssh-connection", sizeof("ssh-connection") - 1);
s += sizeof("ssh-connection") - 1;
/* "keyboard-interactive" */
libssh2_htonu32(s, sizeof("keyboard-interactive") - 1);
_libssh2_htonu32(s, sizeof("keyboard-interactive") - 1);
s += 4;
memcpy(s, "keyboard-interactive", sizeof("keyboard-interactive") - 1);
s += sizeof("keyboard-interactive") - 1;
/* language tag */
libssh2_htonu32(s, 0);
_libssh2_htonu32(s, 0);
s += 4;
/* submethods */
libssh2_htonu32(s, 0);
_libssh2_htonu32(s, 0);
s += 4;
_libssh2_debug(session, LIBSSH2_DBG_AUTH,
@ -1222,7 +1223,7 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
}
if (session->userauth_kybd_state == libssh2_NB_state_created) {
rc = libssh2_packet_write(session, session->userauth_kybd_data,
rc = _libssh2_packet_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
@ -1242,12 +1243,12 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
for(;;) {
if (session->userauth_kybd_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_kybd_data,
&session->userauth_kybd_data_len,
0, NULL, 0,
&session->
userauth_kybd_packet_requirev_state);
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_kybd_data,
&session->userauth_kybd_data_len,
0, NULL, 0,
&session->
userauth_kybd_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1277,7 +1278,7 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
s = session->userauth_kybd_data + 1;
/* string name (ISO-10646 UTF-8) */
session->userauth_kybd_auth_name_len = libssh2_ntohu32(s);
session->userauth_kybd_auth_name_len = _libssh2_ntohu32(s);
s += 4;
session->userauth_kybd_auth_name =
LIBSSH2_ALLOC(session, session->userauth_kybd_auth_name_len);
@ -1292,7 +1293,7 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
s += session->userauth_kybd_auth_name_len;
/* string instruction (ISO-10646 UTF-8) */
session->userauth_kybd_auth_instruction_len = libssh2_ntohu32(s);
session->userauth_kybd_auth_instruction_len = _libssh2_ntohu32(s);
s += 4;
session->userauth_kybd_auth_instruction =
LIBSSH2_ALLOC(session,
@ -1308,13 +1309,13 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
s += session->userauth_kybd_auth_instruction_len;
/* string language tag (as defined in [RFC-3066]) */
language_tag_len = libssh2_ntohu32(s);
language_tag_len = _libssh2_ntohu32(s);
s += 4;
/* ignoring this field as deprecated */
s += language_tag_len;
/* int num-prompts */
session->userauth_kybd_num_prompts = libssh2_ntohu32(s);
session->userauth_kybd_num_prompts = _libssh2_ntohu32(s);
s += 4;
session->userauth_kybd_prompts =
@ -1347,7 +1348,7 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
for(i = 0; i != session->userauth_kybd_num_prompts; ++i) {
/* string prompt[1] (ISO-10646 UTF-8) */
session->userauth_kybd_prompts[i].length = libssh2_ntohu32(s);
session->userauth_kybd_prompts[i].length = _libssh2_ntohu32(s);
s += 4;
session->userauth_kybd_prompts[i].text =
LIBSSH2_ALLOC(session,
@ -1399,11 +1400,11 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
*s = SSH_MSG_USERAUTH_INFO_RESPONSE;
s++;
libssh2_htonu32(s, session->userauth_kybd_num_prompts);
_libssh2_htonu32(s, session->userauth_kybd_num_prompts);
s += 4;
for(i = 0; i != session->userauth_kybd_num_prompts; ++i) {
libssh2_htonu32(s, session->userauth_kybd_responses[i].length);
_libssh2_htonu32(s, session->userauth_kybd_responses[i].length);
s += 4;
memcpy(s, session->userauth_kybd_responses[i].text,
session->userauth_kybd_responses[i].length);
@ -1414,8 +1415,8 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
}
if (session->userauth_kybd_state == libssh2_NB_state_sent1) {
rc = libssh2_packet_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len);
rc = _libssh2_packet_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}