1
1

cleanup: prefer the internal functions

To get the blocking vs non-blocking to work as smooth as possible
and behave better internally, we avoid using the external
interfaces when calling functions internally.

Renamed a few internal functions to use _libssh2 prefix when not
being private within a file, and removed the libssh2_ for one
that was private within the file.
Этот коммит содержится в:
Daniel Stenberg 2010-04-24 21:14:16 +02:00
родитель 5163e4ecb8
Коммит 71fb9cc93e
15 изменённых файлов: 156 добавлений и 93 удалений

Просмотреть файл

@ -47,6 +47,7 @@
support them. */ support them. */
#undef PF_UNIX #undef PF_UNIX
#endif #endif
#include "userauth.h"
/* Requests from client to agent for protocol 1 key operations */ /* Requests from client to agent for protocol 1 key operations */
#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1 #define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
@ -716,11 +717,12 @@ libssh2_agent_userauth(LIBSSH2_AGENT *agent,
memset(&agent->transctx, 0, sizeof agent->transctx); memset(&agent->transctx, 0, sizeof agent->transctx);
agent->identity = identity->node; agent->identity = identity->node;
} }
return libssh2_userauth_publickey(agent->session, username, return _libssh2_userauth_publickey(agent->session, username,
identity->blob, strlen(username),
identity->blob_len, identity->blob,
agent_sign, identity->blob_len,
&abstract); agent_sign,
&abstract);
} }
/* /*

Просмотреть файл

@ -372,15 +372,12 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host,
} }
channel = channel =
libssh2_channel_open_ex(session, "direct-tcpip", _libssh2_channel_open(session, "direct-tcpip",
sizeof("direct-tcpip") - 1, sizeof("direct-tcpip") - 1,
LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_WINDOW_DEFAULT,
LIBSSH2_CHANNEL_PACKET_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT,
(char *) session->direct_message, (char *) session->direct_message,
session->direct_message_len); session->direct_message_len);
/* by default we set (keep?) idle state... */
session->direct_state = libssh2_NB_state_idle;
if (!channel && if (!channel &&
libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
@ -389,6 +386,8 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host,
session->direct_state = libssh2_NB_state_created; session->direct_state = libssh2_NB_state_created;
return NULL; return NULL;
} }
/* by default we set (keep?) idle state... */
session->direct_state = libssh2_NB_state_idle;
LIBSSH2_FREE(session, session->direct_message); LIBSSH2_FREE(session, session->direct_message);
session->direct_message = NULL; session->direct_message = NULL;
@ -576,14 +575,14 @@ libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
} }
/* /*
* channel_forward_cancel * _libssh2_channel_forward_cancel
* *
* Stop listening on a remote port and free the listener * Stop listening on a remote port and free the listener
* Toss out any pending (un-accept()ed) connections * Toss out any pending (un-accept()ed) connections
* *
* Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error * Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error
*/ */
static int channel_forward_cancel(LIBSSH2_LISTENER *listener) int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener)
{ {
LIBSSH2_SESSION *session = listener->session; LIBSSH2_SESSION *session = listener->session;
LIBSSH2_CHANNEL *queued; LIBSSH2_CHANNEL *queued;
@ -643,7 +642,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
while (queued) { while (queued) {
LIBSSH2_CHANNEL *next = _libssh2_list_next(&queued->node); LIBSSH2_CHANNEL *next = _libssh2_list_next(&queued->node);
rc = libssh2_channel_free(queued); rc = _libssh2_channel_free(queued);
if (rc == LIBSSH2_ERROR_EAGAIN) { if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} }
@ -673,7 +672,8 @@ LIBSSH2_API int
libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener) libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener)
{ {
int rc; int rc;
BLOCK_ADJUST(rc, listener->session, channel_forward_cancel(listener)); BLOCK_ADJUST(rc, listener->session,
_libssh2_channel_forward_cancel(listener));
return rc; return rc;
} }
@ -1104,7 +1104,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
border */ border */
unsigned char buffer[(LIBSSH2_X11_RANDOM_COOKIE_LEN / 2) +1]; unsigned char buffer[(LIBSSH2_X11_RANDOM_COOKIE_LEN / 2) +1];
libssh2_random(buffer, LIBSSH2_X11_RANDOM_COOKIE_LEN / 2); _libssh2_random(buffer, LIBSSH2_X11_RANDOM_COOKIE_LEN / 2);
for(i = 0; i < (LIBSSH2_X11_RANDOM_COOKIE_LEN / 2); i++) { for(i = 0; i < (LIBSSH2_X11_RANDOM_COOKIE_LEN / 2); i++) {
sprintf((char *)&s[i*2], "%02X", buffer[i]); sprintf((char *)&s[i*2], "%02X", buffer[i]);
} }
@ -2123,8 +2123,7 @@ libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel)
return rc; return rc;
} }
static int int _libssh2_channel_close(LIBSSH2_CHANNEL * channel)
channel_close(LIBSSH2_CHANNEL * channel)
{ {
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session = channel->session;
int rc = 0; int rc = 0;
@ -2202,7 +2201,7 @@ LIBSSH2_API int
libssh2_channel_close(LIBSSH2_CHANNEL *channel) libssh2_channel_close(LIBSSH2_CHANNEL *channel)
{ {
int rc; int rc;
BLOCK_ADJUST(rc, channel->session, channel_close(channel) ); BLOCK_ADJUST(rc, channel->session, _libssh2_channel_close(channel) );
return rc; return rc;
} }
@ -2292,7 +2291,7 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel)
/* Allow channel freeing even when the socket has lost its connection */ /* Allow channel freeing even when the socket has lost its connection */
if (!channel->local.close if (!channel->local.close
&& (session->socket_state == LIBSSH2_SOCKET_CONNECTED)) { && (session->socket_state == LIBSSH2_SOCKET_CONNECTED)) {
rc = channel_close(channel); rc = _libssh2_channel_close(channel);
if(rc == LIBSSH2_ERROR_EAGAIN) if(rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;

Просмотреть файл

@ -125,5 +125,17 @@ LIBSSH2_CHANNEL *_libssh2_channel_locate(LIBSSH2_SESSION * session,
size_t _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, size_t _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel,
int stream_id); int stream_id);
int _libssh2_channel_close(LIBSSH2_CHANNEL * channel);
/*
* _libssh2_channel_forward_cancel
*
* Stop listening on a remote port and free the listener
* Toss out any pending (un-accept()ed) connections
*
* Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error
*/
int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
#endif /* __LIBSSH2_CHANNEL_H */ #endif /* __LIBSSH2_CHANNEL_H */

Просмотреть файл

@ -1032,7 +1032,7 @@ static int kexinit(LIBSSH2_SESSION * session)
*(s++) = SSH_MSG_KEXINIT; *(s++) = SSH_MSG_KEXINIT;
libssh2_random(s, 16); _libssh2_random(s, 16);
s += 16; s += 16;
/* Ennumerating through these lists twice is probably (certainly?) /* Ennumerating through these lists twice is probably (certainly?)
@ -1630,14 +1630,14 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
/* libssh2_kex_exchange /* _libssh2_kex_exchange
* Exchange keys * Exchange keys
* Returns 0 on success, non-zero on failure * Returns 0 on success, non-zero on failure
* *
* Returns some errors without _libssh2_error() * Returns some errors without _libssh2_error()
*/ */
int int
libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
key_exchange_state_t * key_state) key_exchange_state_t * key_state)
{ {
int rc = 0; int rc = 0;

Просмотреть файл

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009 by Daniel Stenberg * Copyright (c) 2009, 2010 by Daniel Stenberg
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, * Redistribution and use in source and binary forms,
@ -638,10 +638,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
memcpy(hostbuf, sep, seplen); memcpy(hostbuf, sep, seplen);
hostbuf[seplen]=0; hostbuf[seplen]=0;
rc = libssh2_knownhost_addc(hosts, hostbuf, salt, key, keylen, rc = knownhost_add(hosts, hostbuf, salt, key, keylen,
comment, commentlen, comment, commentlen,
type | LIBSSH2_KNOWNHOST_KEYENC_BASE64, type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
NULL); NULL);
if(rc) if(rc)
return rc; return rc;
} }
@ -651,10 +651,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
memcpy(hostbuf, host, hostlen); memcpy(hostbuf, host, hostlen);
hostbuf[hostlen]=0; hostbuf[hostlen]=0;
rc = libssh2_knownhost_addc(hosts, hostbuf, salt, key, keylen, comment, rc = knownhost_add(hosts, hostbuf, salt, key, keylen, comment,
commentlen, commentlen,
type | LIBSSH2_KNOWNHOST_KEYENC_BASE64, type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
NULL); NULL);
return rc; return rc;
} }

Просмотреть файл

@ -56,7 +56,7 @@
#define MD5_DIGEST_LENGTH 16 #define MD5_DIGEST_LENGTH 16
#define SHA_DIGEST_LENGTH 20 #define SHA_DIGEST_LENGTH 20
#define libssh2_random(buf, len) \ #define _libssh2_random(buf, len) \
(gcry_randomize ((buf), (len), GCRY_STRONG_RANDOM), 1) (gcry_randomize ((buf), (len), GCRY_STRONG_RANDOM), 1)
#define libssh2_sha1_ctx gcry_md_hd_t #define libssh2_sha1_ctx gcry_md_hd_t

Просмотреть файл

@ -1122,8 +1122,8 @@ ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length
waiting for more data to arrive */ waiting for more data to arrive */
int libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, int _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
key_exchange_state_t * state); key_exchange_state_t * state);
/* Let crypt.c/hostkey.c expose their method structs */ /* Let crypt.c/hostkey.c expose their method structs */
const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void); const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void);

Просмотреть файл

@ -104,7 +104,7 @@
# define LIBSSH2_3DES 1 # define LIBSSH2_3DES 1
#endif #endif
#define libssh2_random(buf, len) RAND_bytes ((buf), (len)) #define _libssh2_random(buf, len) RAND_bytes ((buf), (len))
#define libssh2_sha1_ctx EVP_MD_CTX #define libssh2_sha1_ctx EVP_MD_CTX
#define libssh2_sha1_init(ctx) EVP_DigestInit(ctx, EVP_get_digestbyname("sha1")) #define libssh2_sha1_init(ctx) EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))

Просмотреть файл

@ -903,7 +903,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
/* /*
* The KEXINIT message has been added to the queue. The packAdd and * The KEXINIT message has been added to the queue. The packAdd and
* readPack states need to be reset because libssh2_kex_exchange * readPack states need to be reset because _libssh2_kex_exchange
* (eventually) calls upon _libssh2_transport_read to read the rest of * (eventually) calls upon _libssh2_transport_read to read the rest of
* the key exchange conversation. * the key exchange conversation.
*/ */
@ -923,10 +923,9 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* If there was a key reexchange failure, let's just hope we didn't * If there was a key reexchange failure, let's just hope we didn't
* send NEWKEYS yet, otherwise remote will drop us like a rock * send NEWKEYS yet, otherwise remote will drop us like a rock
*/ */
rc = libssh2_kex_exchange(session, 1, &session->startup_key_state); rc = _libssh2_kex_exchange(session, 1, &session->startup_key_state);
if (rc == LIBSSH2_ERROR_EAGAIN) { if (rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;
}
} }
session->packAdd_state = libssh2_NB_state_idle; session->packAdd_state = libssh2_NB_state_idle;

Просмотреть файл

@ -487,7 +487,7 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
err_exit: err_exit:
session->pkeyInit_state = libssh2_NB_state_sent4; session->pkeyInit_state = libssh2_NB_state_sent4;
if (session->pkeyInit_channel) { if (session->pkeyInit_channel) {
rc = libssh2_channel_close(session->pkeyInit_channel); rc = _libssh2_channel_close(session->pkeyInit_channel);
if (rc == LIBSSH2_ERROR_EAGAIN) { if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block closing channel"); "Would block closing channel");
@ -1011,7 +1011,7 @@ libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY * pkey)
pkey->listFetch_data = NULL; pkey->listFetch_data = NULL;
} }
rc = libssh2_channel_free(pkey->channel); rc = _libssh2_channel_free(pkey->channel);
if (rc == LIBSSH2_ERROR_EAGAIN) if (rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;

Просмотреть файл

@ -45,7 +45,7 @@
/* Max. length of a quoted string after libssh2_shell_quotearg() processing */ /* Max. length of a quoted string after libssh2_shell_quotearg() processing */
#define libssh2_shell_quotedsize(s) (3 * strlen(s) + 2) #define _libssh2_shell_quotedsize(s) (3 * strlen(s) + 2)
/* /*
This function quotes a string in a way suitable to be used with a This function quotes a string in a way suitable to be used with a
@ -123,8 +123,8 @@
*/ */
static unsigned static unsigned
libssh2_shell_quotearg(const char *path, unsigned char *buf, shell_quotearg(const char *path, unsigned char *buf,
unsigned bufsize) unsigned bufsize)
{ {
const char *src; const char *src;
unsigned char *dst, *endp; unsigned char *dst, *endp;
@ -280,7 +280,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_atime = 0; session->scpRecv_atime = 0;
session->scpRecv_command_len = session->scpRecv_command_len =
libssh2_shell_quotedsize(path) + sizeof("scp -f ") + (sb?1:0); _libssh2_shell_quotedsize(path) + sizeof("scp -f ") + (sb?1:0);
session->scpRecv_command = session->scpRecv_command =
LIBSSH2_ALLOC(session, session->scpRecv_command_len); LIBSSH2_ALLOC(session, session->scpRecv_command_len);
@ -297,9 +297,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
cmd_len = strlen((char *)session->scpRecv_command); cmd_len = strlen((char *)session->scpRecv_command);
(void) libssh2_shell_quotearg(path, (void) shell_quotearg(path,
&session->scpRecv_command[cmd_len], &session->scpRecv_command[cmd_len],
session->scpRecv_command_len - cmd_len); session->scpRecv_command_len - cmd_len);
_libssh2_debug(session, LIBSSH2_TRACE_SCP, _libssh2_debug(session, LIBSSH2_TRACE_SCP,
@ -311,11 +311,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_state == libssh2_NB_state_created) { if (session->scpRecv_state == libssh2_NB_state_created) {
/* Allocate a channel */ /* Allocate a channel */
session->scpRecv_channel = session->scpRecv_channel =
libssh2_channel_open_ex(session, "session", _libssh2_channel_open(session, "session",
sizeof("session") - 1, sizeof("session") - 1,
LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_WINDOW_DEFAULT,
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL,
0); 0);
if (!session->scpRecv_channel) { if (!session->scpRecv_channel) {
if (libssh2_session_last_errno(session) != if (libssh2_session_last_errno(session) !=
LIBSSH2_ERROR_EAGAIN) { LIBSSH2_ERROR_EAGAIN) {
@ -335,10 +335,10 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_state == libssh2_NB_state_sent) { if (session->scpRecv_state == libssh2_NB_state_sent) {
/* Request SCP for the desired file */ /* Request SCP for the desired file */
rc = libssh2_channel_process_startup(session->scpRecv_channel, "exec", rc = _libssh2_channel_process_startup(session->scpRecv_channel, "exec",
sizeof("exec") - 1, sizeof("exec") - 1,
(char *) session->scpRecv_command, (char *) session->scpRecv_command,
session->scpRecv_command_len); session->scpRecv_command_len);
if (rc == LIBSSH2_ERROR_EAGAIN) { if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup"); "Would block requesting SCP startup");
@ -783,7 +783,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
if (session->scpSend_state == libssh2_NB_state_idle) { if (session->scpSend_state == libssh2_NB_state_idle) {
session->scpSend_command_len = session->scpSend_command_len =
libssh2_shell_quotedsize(path) + sizeof("scp -t ") + _libssh2_shell_quotedsize(path) + sizeof("scp -t ") +
((mtime || atime)?1:0); ((mtime || atime)?1:0);
session->scpSend_command = session->scpSend_command =
@ -799,9 +799,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
cmd_len = strlen((char *)session->scpSend_command); cmd_len = strlen((char *)session->scpSend_command);
(void)libssh2_shell_quotearg(path, (void)shell_quotearg(path,
&session->scpSend_command[cmd_len], &session->scpSend_command[cmd_len],
session->scpSend_command_len - cmd_len); session->scpSend_command_len - cmd_len);
session->scpSend_command[session->scpSend_command_len - 1] = '\0'; session->scpSend_command[session->scpSend_command_len - 1] = '\0';
@ -814,9 +814,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
if (session->scpSend_state == libssh2_NB_state_created) { if (session->scpSend_state == libssh2_NB_state_created) {
session->scpSend_channel = session->scpSend_channel =
libssh2_channel_open_ex(session, "session", sizeof("session") - 1, _libssh2_channel_open(session, "session", sizeof("session") - 1,
LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_WINDOW_DEFAULT,
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0); LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
if (!session->scpSend_channel) { if (!session->scpSend_channel) {
if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
/* previous call set libssh2_session_last_error(), pass it /* previous call set libssh2_session_last_error(), pass it
@ -837,10 +837,10 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
if (session->scpSend_state == libssh2_NB_state_sent) { if (session->scpSend_state == libssh2_NB_state_sent) {
/* Request SCP for the desired file */ /* Request SCP for the desired file */
rc = libssh2_channel_process_startup(session->scpSend_channel, "exec", rc = _libssh2_channel_process_startup(session->scpSend_channel, "exec",
sizeof("exec") - 1, sizeof("exec") - 1,
(char *) session->scpSend_command, (char *) session->scpSend_command,
session->scpSend_command_len); session->scpSend_command_len);
if (rc == LIBSSH2_ERROR_EAGAIN) { if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup"); "Would block requesting SCP startup");

Просмотреть файл

@ -54,6 +54,7 @@
#include "transport.h" #include "transport.h"
#include "session.h" #include "session.h"
#include "channel.h"
/* libssh2_default_alloc /* libssh2_default_alloc
*/ */
@ -631,11 +632,10 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
} }
if (session->startup_state == libssh2_NB_state_sent1) { if (session->startup_state == libssh2_NB_state_sent1) {
rc = libssh2_kex_exchange(session, 0, &session->startup_key_state); rc = _libssh2_kex_exchange(session, 0, &session->startup_key_state);
if (rc) { if (rc)
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to exchange encryption keys"); "Unable to exchange encryption keys");
}
session->startup_state = libssh2_NB_state_sent2; session->startup_state = libssh2_NB_state_sent2;
} }
@ -740,7 +740,7 @@ session_free(LIBSSH2_SESSION *session)
if (session->free_state == libssh2_NB_state_created) { if (session->free_state == libssh2_NB_state_created) {
while ((ch = _libssh2_list_first(&session->channels))) { while ((ch = _libssh2_list_first(&session->channels))) {
rc = libssh2_channel_free(ch); rc = _libssh2_channel_free(ch);
if (rc == LIBSSH2_ERROR_EAGAIN) if (rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;
} }
@ -750,7 +750,7 @@ session_free(LIBSSH2_SESSION *session)
if (session->state == libssh2_NB_state_sent) { if (session->state == libssh2_NB_state_sent) {
while ((l = _libssh2_list_first(&session->listeners))) { while ((l = _libssh2_list_first(&session->listeners))) {
rc = libssh2_channel_forward_cancel(l); rc = _libssh2_channel_forward_cancel(l);
if (rc == LIBSSH2_ERROR_EAGAIN) if (rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;
} }

Просмотреть файл

@ -313,7 +313,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
*/ */
_libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Redirecting into the" _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Redirecting into the"
" key re-exchange"); " key re-exchange");
rc = libssh2_kex_exchange(session, 1, &session->startup_key_state); rc = _libssh2_kex_exchange(session, 1, &session->startup_key_state);
if (rc) if (rc)
return rc; return rc;
} }
@ -797,7 +797,7 @@ _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data,
/* copy the payload data */ /* copy the payload data */
memcpy(p->outbuf + 5, data, data_len); memcpy(p->outbuf + 5, data, data_len);
/* fill the padding area with random junk */ /* fill the padding area with random junk */
libssh2_random(p->outbuf + 5 + data_len, padding_length); _libssh2_random(p->outbuf + 5 + data_len, padding_length);
if (free_data) { if (free_data) {
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
} }

Просмотреть файл

@ -50,6 +50,7 @@
#include "transport.h" #include "transport.h"
#include "session.h" #include "session.h"
#include "userauth.h"
/* libssh2_userauth_list /* libssh2_userauth_list
* *
@ -857,14 +858,14 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
static int int
userauth_publickey(LIBSSH2_SESSION *session, _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
const char *username, const char *username,
unsigned int username_len, unsigned int username_len,
const unsigned char *pubkeydata, const unsigned char *pubkeydata,
unsigned long pubkeydata_len, unsigned long pubkeydata_len,
LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)), LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
void *abstract) void *abstract)
{ {
unsigned char reply_codes[4] = unsigned char reply_codes[4] =
{ SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE, { SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE,
@ -1186,9 +1187,9 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session,
return rc; return rc;
} }
rc = userauth_publickey(session, username, username_len, rc = _libssh2_userauth_publickey(session, username, username_len,
pubkeydata, pubkeydata_len, pubkeydata, pubkeydata_len,
sign_fromfile, &abstract); sign_fromfile, &abstract);
if(pubkeydata) if(pubkeydata)
LIBSSH2_FREE(session, pubkeydata); LIBSSH2_FREE(session, pubkeydata);
@ -1233,9 +1234,9 @@ libssh2_userauth_publickey(LIBSSH2_SESSION *session,
{ {
int rc; int rc;
BLOCK_ADJUST(rc, session, BLOCK_ADJUST(rc, session,
userauth_publickey(session, user, strlen(user), _libssh2_userauth_publickey(session, user, strlen(user),
pubkeydata, pubkeydata_len, pubkeydata, pubkeydata_len,
sign_callback, abstract)); sign_callback, abstract));
return rc; return rc;
} }

50
src/userauth.h Обычный файл
Просмотреть файл

@ -0,0 +1,50 @@
#ifndef LIBSSH2_USERAUTH_H
#define LIBSSH2_USERAUTH_H
/* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009-2010 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the copyright holder nor the names
* of any other contributors may be used to endorse or
* promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
int
_libssh2_userauth_publickey(LIBSSH2_SESSION *session,
const char *username,
unsigned int username_len,
const unsigned char *pubkeydata,
unsigned long pubkeydata_len,
LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
void *abstract);
#endif /* LIBSSH2_USERAUTH_H */