1
1

Continue removing old flushing code

Этот коммит содержится в:
Aris Adamantiadis 2010-07-23 11:01:06 +02:00
родитель 8cd0d0040e
Коммит e721c122d3
13 изменённых файлов: 53 добавлений и 161 удалений

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

@ -56,7 +56,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
SSH_PACKET_CALLBACK(ssh_packet_unimplemented);
int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum);
int ssh_packet_parse_type(ssh_session session);
int packet_flush(ssh_session session, int enforce_blocking);
//int packet_flush(ssh_session session, int enforce_blocking);
#endif /* PACKET_H_ */

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

@ -47,12 +47,7 @@ int ssh_socket_fd_isset(ssh_socket s, fd_set *set);
void ssh_socket_fd_set(ssh_socket s, fd_set *set, int *fd_max);
void ssh_socket_set_fd_in(ssh_socket s, socket_t fd);
void ssh_socket_set_fd_out(ssh_socket s, socket_t fd);
//int ssh_socket_completeread(ssh_socket s, void *buffer, uint32_t len);
//int ssh_socket_completewrite(ssh_socket s, const void *buffer, uint32_t len);
//int ssh_socket_wait_for_data(ssh_socket s, ssh_session session, uint32_t len);
int ssh_socket_nonblocking_flush(ssh_socket s);
int ssh_socket_blocking_flush(ssh_socket s);
//int ssh_socket_poll(ssh_socket s, int *writeable, int *except);
void ssh_socket_set_towrite(ssh_socket s);
void ssh_socket_set_toread(ssh_socket s);
void ssh_socket_set_except(ssh_socket s);

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

@ -466,7 +466,7 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
ssh_string_free(service);
ssh_string_free(algo);
session->auth_state=SSH_AUTH_STATE_NONE;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}
@ -601,7 +601,7 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
}
ssh_string_free(sign);
session->auth_state=SSH_AUTH_STATE_NONE;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}
@ -786,7 +786,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
}
ssh_string_free(sign);
session->auth_state=SSH_AUTH_STATE_NONE;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}
@ -906,7 +906,7 @@ int ssh_userauth_password(ssh_session session, const char *username,
ssh_string_burn(pwd);
ssh_string_free(pwd);
session->auth_state=SSH_AUTH_STATE_NONE;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}
@ -1280,7 +1280,7 @@ static int kbdauth_init(ssh_session session, const char *user,
ssh_string_free(method);
ssh_string_free(sub);
session->auth_state=SSH_AUTH_STATE_KBDINT_SENT;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}
@ -1465,7 +1465,7 @@ static int kbdauth_send(ssh_session session) {
session->auth_state=SSH_AUTH_STATE_KBDINT_SENT;
kbdint_free(session->kbdint);
session->kbdint = NULL;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}

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

@ -101,7 +101,7 @@ static int send_username(ssh_session session, const char *username) {
}
ssh_string_free(user);
session->auth_state=SSH_AUTH_STATE_NONE;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
@ -193,7 +193,7 @@ int ssh_userauth1_password(ssh_session session, const char *username,
ssh_string_burn(pwd);
ssh_string_free(pwd);
session->auth_state=SSH_AUTH_STATE_NONE;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return SSH_AUTH_ERROR;
}

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

@ -263,7 +263,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
}
}
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return err;
}
@ -314,7 +314,7 @@ static int grow_window(ssh_session session, ssh_channel channel, int minimumsize
goto error;
}
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
/* FIXME should we fail here or not? */
leave_function();
return 1;
@ -979,7 +979,7 @@ int channel_write_common(ssh_channel channel, const void *data,
goto error;
}
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return SSH_ERROR;
}
@ -1176,7 +1176,7 @@ static int channel_request(ssh_channel channel, const char *request,
}
}
channel->request_state = SSH_CHANNEL_REQ_STATE_PENDING;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}
@ -1632,7 +1632,7 @@ static int global_request(ssh_session session, const char *request,
}
}
session->global_req_state = SSH_CHANNEL_REQ_STATE_PENDING;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc;
}

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

@ -111,7 +111,7 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
ssh_log(session, SSH_LOG_FUNCTIONS, "Opening a ssh1 pty");
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
return -1;
}
switch(channel->request_state){
@ -149,7 +149,7 @@ int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
return SSH_ERROR;
}
channel->request_state=SSH_CHANNEL_REQ_STATE_PENDING;
if (packet_send(session)) {
if (packet_send(session) == SSH_ERROR) {
return SSH_ERROR;
}
@ -185,7 +185,7 @@ int channel_request_shell1(ssh_channel channel) {
return -1;
}
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
return -1;
}
@ -210,7 +210,7 @@ int channel_request_exec1(ssh_channel channel, const char *cmd) {
}
ssh_string_free(command);
if(packet_send(session) != SSH_OK) {
if(packet_send(session) == SSH_ERROR) {
return -1;
}
@ -286,7 +286,7 @@ int channel_write1(ssh_channel channel, const void *data, int len) {
ptr += effectivelen;
len -= effectivelen;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
return -1;
}
}

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

@ -204,6 +204,7 @@ static int ssh_analyze_banner(ssh_session session, int *ssh1, int *ssh2) {
int ssh_send_banner(ssh_session session, int server) {
const char *banner = NULL;
char buffer[128] = {0};
int err=SSH_ERROR;
enter_function();
@ -216,30 +217,31 @@ int ssh_send_banner(ssh_session session, int server) {
if (server) {
session->serverbanner = strdup(banner);
if (session->serverbanner == NULL) {
leave_function();
return -1;
goto end;
}
} else {
session->clientbanner = strdup(banner);
if (session->clientbanner == NULL) {
leave_function();
return -1;
goto end;
}
}
snprintf(buffer, 128, "%s\n", banner);
if (ssh_socket_write(session->socket, buffer, strlen(buffer)) == SSH_ERROR) {
leave_function();
return -1;
goto end;
}
if (ssh_socket_nonblocking_flush(session->socket) == SSH_ERROR){
goto end;
}
#ifdef WITH_PCAP
if(session->pcap_ctx)
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,buffer,strlen(buffer),strlen(buffer));
#endif
err=SSH_OK;
end:
leave_function();
return 0;
return err;
}
@ -510,7 +512,7 @@ int ssh_service_request(ssh_session session, const char *service) {
}
ssh_string_free(service_s);
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
ssh_set_error(session, SSH_FATAL,
"Sending SSH2_MSG_SERVICE_REQUEST failed.");
break;

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

@ -428,7 +428,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
goto error;
}
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
leave_function();
return -1;
}
@ -764,7 +764,7 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
goto error;
}
session->session_state=SSH_SESSION_STATE_KEXINIT_RECEIVED;
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
goto error;
}

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

@ -1700,7 +1700,7 @@ int ssh_is_server_known(ssh_session session) {
* @return SSH_OK on success, SSH_ERROR on error.
*/
int ssh_write_knownhost(ssh_session session) {
ssh_string pubkey = session->current_crypto->server_pubkey;
ssh_string pubkey;
unsigned char *pubkey_64;
char buffer[4096] = {0};
FILE *file;
@ -1727,10 +1727,21 @@ int ssh_write_knownhost(ssh_session session) {
if (session->knownhosts == NULL) {
if (ssh_options_apply(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Can't find a known_hosts file");
return -1;
return SSH_ERROR;
}
}
if(session->current_crypto==NULL) {
ssh_set_error(session, SSH_FATAL, "No current crypto context");
return SSH_ERROR;
}
pubkey = session->current_crypto->server_pubkey;
if(pubkey == NULL){
ssh_set_error(session, SSH_FATAL, "No public key present");
return SSH_ERROR;
}
/* Check if ~/.ssh exists and create it if not */
dir = ssh_dirname(session->knownhosts);
if (dir == NULL) {

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

@ -494,7 +494,7 @@ ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
ssh_log(session, SSH_LOG_PACKET,
"Accepting a channel request_open for chan %d", chan->remote_channel);
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
goto error;
}

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

@ -421,20 +421,6 @@ int ssh_packet_parse_type(ssh_session session) {
return SSH_OK;
}
/*
* Write the the bufferized output. If the session is blocking, or
* enforce_blocking is set, the call may block. Otherwise, it won't block.
* Return SSH_OK if everything has been sent, SSH_AGAIN if there are still
* things to send on buffer, SSH_ERROR if there is an error.
*/
int packet_flush(ssh_session session, int enforce_blocking) {
if (enforce_blocking || session->blocking) {
return ssh_socket_blocking_flush(session->socket);
}
return ssh_socket_nonblocking_flush(session->socket);
}
/*
* This function places the outgoing packet buffer into an outgoing
* socket buffer
@ -447,7 +433,9 @@ static int ssh_packet_write(ssh_session session) {
rc=ssh_socket_write(session->socket,
ssh_buffer_get_begin(session->out_buffer),
ssh_buffer_get_len(session->out_buffer));
if(rc == SSH_OK){
rc=ssh_socket_nonblocking_flush(session->socket);
}
leave_function();
return rc;
}

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

@ -477,7 +477,7 @@ static int dh_handshake_server(ssh_session session) {
}
ssh_string_free(f);
ssh_string_free(sign);
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
return -1;
}
@ -486,7 +486,7 @@ static int dh_handshake_server(ssh_session session) {
return -1;
}
if (packet_send(session) != SSH_OK) {
if (packet_send(session) == SSH_ERROR) {
return -1;
}
ssh_log(session, SSH_LOG_PACKET, "SSH_MSG_NEWKEYS sent");

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

@ -463,6 +463,7 @@ static int ssh_socket_unbuffered_write(ssh_socket s, const void *buffer,
s->data_to_write = 0;
/* Reactive the POLLOUT detector in the poll multiplexer system */
if(s->poll_out){
ssh_log(s->session, SSH_LOG_PACKET, "Enabling POLLOUT for socket");
ssh_poll_set_events(s->poll_out,ssh_poll_get_events(s->poll_out) | POLLOUT);
}
if (w < 0) {
@ -502,63 +503,6 @@ void ssh_socket_fd_set(ssh_socket s, fd_set *set, socket_t *max_fd) {
}
}
/** \internal
* \brief reads blocking until len bytes have been read
*/
//int ssh_socket_completeread(ssh_socket s, void *buffer, uint32_t len) {
// int r = -1;
// uint32_t total = 0;
// uint32_t toread = len;
// if(! ssh_socket_is_open(s)) {
// return SSH_ERROR;
// }
//
// while((r = ssh_socket_unbuffered_read(s, ((uint8_t*)buffer + total), toread))) {
// if (r < 0) {
// return SSH_ERROR;
// }
// total += r;
// toread -= r;
// if (total == len) {
// return len;
// }
// if (r == 0) {
// return 0;
// }
// }
//
// /* connection closed */
// return total;
//}
//
///** \internal
// * \brief Blocking write of len bytes
// */
//int ssh_socket_completewrite(ssh_socket s, const void *buffer, uint32_t len) {
// ssh_session session = s->session;
// int written = -1;
//
// enter_function();
//
// if(! ssh_socket_is_open(s)) {
// leave_function();
// return SSH_ERROR;
// }
//
// while (len >0) {
// written = ssh_socket_unbuffered_write(s, buffer, len);
// if (written == 0 || written == -1) {
// leave_function();
// return SSH_ERROR;
// }
// len -= written;
// buffer = ((uint8_t*)buffer + written);
// }
//
// leave_function();
// return SSH_OK;
//}
/** \internal
* \brief buffered write of data
* \returns SSH_OK, or SSH_ERROR
@ -571,7 +515,7 @@ int ssh_socket_write(ssh_socket s, const void *buffer, int len) {
return SSH_ERROR;
}
leave_function();
return len;
return SSH_OK;
}
@ -626,54 +570,6 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
return SSH_OK;
}
/** \internal
* \brief locking flush of the output packet buffer
*/
int ssh_socket_blocking_flush(ssh_socket s) {
ssh_session session = s->session;
enter_function();
if (!ssh_socket_is_open(s)) {
session->alive = 0;
leave_function();
return SSH_ERROR;
}
if (s->data_except) {
leave_function();
return SSH_ERROR;
}
if (buffer_get_rest_len(s->out_buffer) == 0) {
leave_function();
return SSH_OK;
}
if (ssh_socket_completewrite(s, buffer_get_rest(s->out_buffer),
buffer_get_rest_len(s->out_buffer)) != SSH_OK) {
session->alive = 0;
ssh_socket_close(s);
/* FIXME use the proper errno */
ssh_set_error(session, SSH_FATAL,
"Writing packet: error on socket (or connection closed): %s",
strerror(errno));
leave_function();
return SSH_ERROR;
}
if (buffer_reinit(s->out_buffer) < 0) {
leave_function();
return SSH_ERROR;
}
leave_function();
return SSH_OK; // no data pending
}
void ssh_socket_set_towrite(ssh_socket s) {
s->data_to_write = 1;
}