Sanitize libssh namespace + legacy wrappers
Этот коммит содержится в:
родитель
46b249f5ce
Коммит
b23b3f1d99
@ -15,41 +15,41 @@ int main(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
channel = channel_new(session);;
|
||||
channel = ssh_channel_new(session);;
|
||||
if (channel == NULL) {
|
||||
ssh_disconnect(session);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = channel_open_session(channel);
|
||||
rc = ssh_channel_open_session(channel);
|
||||
if (rc < 0) {
|
||||
channel_close(channel);
|
||||
ssh_channel_close(channel);
|
||||
ssh_disconnect(session);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = channel_request_exec(channel, "ps aux");
|
||||
rc = ssh_channel_request_exec(channel, "ps aux");
|
||||
if (rc < 0) {
|
||||
channel_close(channel);
|
||||
ssh_channel_close(channel);
|
||||
ssh_disconnect(session);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
while ((rc = channel_read(channel, buffer, sizeof(buffer), 0)) > 0) {
|
||||
while ((rc = ssh_channel_read(channel, buffer, sizeof(buffer), 0)) > 0) {
|
||||
if (fwrite(buffer, 1, rc, stdout) != (unsigned int) rc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
channel_close(channel);
|
||||
ssh_channel_close(channel);
|
||||
ssh_disconnect(session);
|
||||
return 1;
|
||||
}
|
||||
|
||||
channel_send_eof(channel);
|
||||
channel_close(channel);
|
||||
ssh_channel_send_eof(channel);
|
||||
ssh_channel_close(channel);
|
||||
|
||||
ssh_disconnect(session);
|
||||
|
||||
|
@ -173,7 +173,7 @@ static void setsignal(void){
|
||||
static void sizechanged(void){
|
||||
struct winsize win = { 0, 0, 0, 0 };
|
||||
ioctl(1, TIOCGWINSZ, &win);
|
||||
channel_change_pty_size(chan,win.ws_col, win.ws_row);
|
||||
ssh_channel_change_pty_size(chan,win.ws_col, win.ws_row);
|
||||
// printf("Changed pty size\n");
|
||||
setsignal();
|
||||
}
|
||||
@ -196,7 +196,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
fd_set fds;
|
||||
struct timeval timeout;
|
||||
char buffer[4096];
|
||||
ssh_buffer readbuf=buffer_new();
|
||||
ssh_buffer readbuf=ssh_buffer_new();
|
||||
ssh_channel channels[2];
|
||||
int lus;
|
||||
int eof=0;
|
||||
@ -224,10 +224,10 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
if(FD_ISSET(0,&fds)){
|
||||
lus=read(0,buffer,sizeof(buffer));
|
||||
if(lus)
|
||||
channel_write(channel,buffer,lus);
|
||||
ssh_channel_write(channel,buffer,lus);
|
||||
else {
|
||||
eof=1;
|
||||
channel_send_eof(channel);
|
||||
ssh_channel_send_eof(channel);
|
||||
}
|
||||
}
|
||||
if(FD_ISSET(ssh_get_fd(session),&fds)){
|
||||
@ -235,22 +235,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
}
|
||||
channels[0]=channel; // set the first channel we want to read from
|
||||
channels[1]=NULL;
|
||||
ret=channel_select(channels,NULL,NULL,NULL); // no specific timeout - just poll
|
||||
ret=ssh_channel_select(channels,NULL,NULL,NULL); // no specific timeout - just poll
|
||||
if(signal_delayed)
|
||||
sizechanged();
|
||||
} while (ret==EINTR || ret==SSH_EINTR);
|
||||
|
||||
// we already looked for input from stdin. Now, we are looking for input from the channel
|
||||
|
||||
if(channel && channel_is_closed(channel)){
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
if(channel && ssh_channel_is_closed(channel)){
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
ssh_channel_free(channel);
|
||||
channel=NULL;
|
||||
channels[0]=NULL;
|
||||
}
|
||||
if(channels[0]){
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,0)>0){
|
||||
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)>0){
|
||||
lus=channel_read_buffer(channel,readbuf,0,0);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
@ -259,17 +259,17 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
ssh_channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
if (write(1,buffer_get(readbuf),lus) < 0) {
|
||||
if (write(1,ssh_buffer_get_begin(readbuf),lus) < 0) {
|
||||
fprintf(stderr, "Error writing to buffer\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,1)>0){ /* stderr */
|
||||
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)>0){ /* stderr */
|
||||
lus=channel_read_buffer(channel,readbuf,0,1);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
@ -278,22 +278,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
channel_free(channel);
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
|
||||
ssh_channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
if (write(2,buffer_get(readbuf),lus) < 0) {
|
||||
if (write(2,ssh_buffer_get_begin(readbuf),lus) < 0) {
|
||||
fprintf(stderr, "Error writing to buffer\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(channel && channel_is_closed(channel)){
|
||||
channel_free(channel);
|
||||
if(channel && ssh_channel_is_closed(channel)){
|
||||
ssh_channel_free(channel);
|
||||
channel=NULL;
|
||||
}
|
||||
}
|
||||
buffer_free(readbuf);
|
||||
ssh_buffer_free(readbuf);
|
||||
}
|
||||
#else /* CHANNEL_SELECT */
|
||||
|
||||
@ -328,22 +328,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
if(FD_ISSET(0,&fds)){
|
||||
lus=read(0,buffer,sizeof(buffer));
|
||||
if(lus)
|
||||
channel_write(channel,buffer,lus);
|
||||
ssh_channel_write(channel,buffer,lus);
|
||||
else {
|
||||
eof=1;
|
||||
channel_send_eof(channel);
|
||||
ssh_channel_send_eof(channel);
|
||||
}
|
||||
}
|
||||
if(channel && channel_is_closed(channel)){
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
if(channel && ssh_channel_is_closed(channel)){
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
ssh_channel_free(channel);
|
||||
channel=NULL;
|
||||
channels[0]=NULL;
|
||||
}
|
||||
if(outchannels[0]){
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,0)!=0){
|
||||
lus=channel_read(channel,buffer,sizeof(buffer),0);
|
||||
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)!=0){
|
||||
lus=ssh_channel_read(channel,buffer,sizeof(buffer),0);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
@ -351,9 +351,9 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
|
||||
|
||||
channel_free(channel);
|
||||
ssh_channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
if (write(1,buffer,lus) < 0) {
|
||||
@ -361,8 +361,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
return;
|
||||
}
|
||||
}
|
||||
while(channel && channel_is_open(channel) && channel_poll(channel,1)!=0){ /* stderr */
|
||||
lus=channel_read(channel,buffer,sizeof(buffer),1);
|
||||
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)!=0){ /* stderr */
|
||||
lus=ssh_channel_read(channel,buffer,sizeof(buffer),1);
|
||||
if(lus==-1){
|
||||
fprintf(stderr, "Error reading channel: %s\n",
|
||||
ssh_get_error(session));
|
||||
@ -370,8 +370,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
}
|
||||
if(lus==0){
|
||||
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
|
||||
channel_free(channel);
|
||||
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
|
||||
ssh_channel_free(channel);
|
||||
channel=channels[0]=NULL;
|
||||
} else
|
||||
if (write(2,buffer,lus) < 0) {
|
||||
@ -380,8 +380,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(channel && channel_is_closed(channel)){
|
||||
channel_free(channel);
|
||||
if(channel && ssh_channel_is_closed(channel)){
|
||||
ssh_channel_free(channel);
|
||||
channel=NULL;
|
||||
}
|
||||
} while (ret==EINTR || ret==SSH_EINTR);
|
||||
@ -395,21 +395,21 @@ static void shell(ssh_session session){
|
||||
ssh_channel channel;
|
||||
struct termios terminal_local;
|
||||
int interactive=isatty(0);
|
||||
channel = channel_new(session);
|
||||
channel = ssh_channel_new(session);
|
||||
if(interactive){
|
||||
tcgetattr(0,&terminal_local);
|
||||
memcpy(&terminal,&terminal_local,sizeof(struct termios));
|
||||
}
|
||||
if(channel_open_session(channel)){
|
||||
if(ssh_channel_open_session(channel)){
|
||||
printf("error opening channel : %s\n",ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
chan=channel;
|
||||
if(interactive){
|
||||
channel_request_pty(channel);
|
||||
ssh_channel_request_pty(channel);
|
||||
sizechanged();
|
||||
}
|
||||
if(channel_request_shell(channel)){
|
||||
if(ssh_channel_request_shell(channel)){
|
||||
printf("Requesting shell : %s\n",ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
@ -430,9 +430,9 @@ static void batch_shell(ssh_session session){
|
||||
int i,s=0;
|
||||
for(i=0;i<MAXCMD && cmds[i];++i)
|
||||
s+=snprintf(buffer+s,sizeof(buffer)-s,"%s ",cmds[i]);
|
||||
channel=channel_new(session);
|
||||
channel_open_session(channel);
|
||||
if(channel_request_exec(channel,buffer)){
|
||||
channel=ssh_channel_new(session);
|
||||
ssh_channel_open_session(channel);
|
||||
if(ssh_channel_request_exec(channel,buffer)){
|
||||
printf("error executing \"%s\" : %s\n",buffer,ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
|
@ -56,29 +56,29 @@ static int opts(int argc, char **argv){
|
||||
}
|
||||
|
||||
static void create_files(ssh_session session){
|
||||
ssh_channel channel=channel_new(session);
|
||||
ssh_channel channel=ssh_channel_new(session);
|
||||
char buffer[1];
|
||||
if(channel == NULL){
|
||||
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(channel_open_session(channel) != SSH_OK){
|
||||
if(ssh_channel_open_session(channel) != SSH_OK){
|
||||
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(channel_request_exec(channel,createcommand) != SSH_OK){
|
||||
if(ssh_channel_request_exec(channel,createcommand) != SSH_OK){
|
||||
fprintf(stderr,"Error executing command: %s\n",ssh_get_error(session));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while(!channel_is_eof(channel)){
|
||||
channel_read(channel,buffer,1,1);
|
||||
while(!ssh_channel_is_eof(channel)){
|
||||
ssh_channel_read(channel,buffer,1,1);
|
||||
if (write(1,buffer,1) < 0) {
|
||||
fprintf(stderr, "Error writing to buffer\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
channel_close(channel);
|
||||
channel_free(channel);
|
||||
ssh_channel_close(channel);
|
||||
ssh_channel_free(channel);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#ifndef BUFFER_H_
|
||||
#define BUFFER_H_
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
/* Describes a buffer state */
|
||||
struct ssh_buffer_struct {
|
||||
char *data;
|
||||
@ -30,6 +31,10 @@ struct ssh_buffer_struct {
|
||||
uint32_t pos;
|
||||
};
|
||||
|
||||
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
|
||||
LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
|
||||
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
|
||||
LIBSSH_API ssh_buffer ssh_buffer_new(void);
|
||||
int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
|
||||
int buffer_add_u8(ssh_buffer buffer, uint8_t data);
|
||||
int buffer_add_u16(ssh_buffer buffer, uint16_t data);
|
||||
|
@ -78,7 +78,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_failure);
|
||||
SSH_PACKET_CALLBACK(ssh_request_success);
|
||||
SSH_PACKET_CALLBACK(ssh_request_denied);
|
||||
|
||||
ssh_channel channel_new(ssh_session session);
|
||||
ssh_channel ssh_channel_new(ssh_session session);
|
||||
int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||
int is_stderr);
|
||||
uint32_t ssh_channel_new_id(ssh_session session);
|
||||
|
98
include/libssh/legacy.h
Обычный файл
98
include/libssh/legacy.h
Обычный файл
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2010 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Since libssh.h includes legacy.h, it's important that libssh.h is included
|
||||
* first. we don't define LEGACY_H now because we want it to be defined when
|
||||
* included from libssh.h
|
||||
*/
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifndef LEGACY_H_
|
||||
#define LEGACY_H_
|
||||
LIBSSH_API void buffer_free(ssh_buffer buffer);
|
||||
LIBSSH_API void *buffer_get(ssh_buffer buffer);
|
||||
LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
|
||||
LIBSSH_API ssh_buffer buffer_new(void);
|
||||
|
||||
LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
|
||||
LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
|
||||
LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
|
||||
LIBSSH_API int channel_close(ssh_channel channel);
|
||||
LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
|
||||
LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||
LIBSSH_API void channel_free(ssh_channel channel);
|
||||
LIBSSH_API int channel_get_exit_status(ssh_channel channel);
|
||||
LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_closed(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_eof(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_open(ssh_channel channel);
|
||||
LIBSSH_API ssh_channel channel_new(ssh_session session);
|
||||
LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
int remoteport, const char *sourcehost, int localport);
|
||||
LIBSSH_API int channel_open_session(ssh_channel channel);
|
||||
LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
|
||||
LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||
|
||||
LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||
int is_stderr);
|
||||
|
||||
LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int is_stderr);
|
||||
LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||
LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
|
||||
LIBSSH_API int channel_request_pty(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
|
||||
int cols, int rows);
|
||||
LIBSSH_API int channel_request_shell(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
|
||||
LIBSSH_API int channel_request_sftp(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
|
||||
LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
const char *cookie, int screen_number);
|
||||
LIBSSH_API int channel_send_eof(ssh_channel channel);
|
||||
LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||
timeval * timeout);
|
||||
LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
|
||||
LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
|
||||
|
||||
LIBSSH_API void privatekey_free(ssh_private_key prv);
|
||||
LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
||||
int type, const char *passphrase);
|
||||
LIBSSH_API void publickey_free(ssh_public_key key);
|
||||
LIBSSH_API int ssh_publickey_to_file(ssh_session session, const char *file,
|
||||
ssh_string pubkey, int type);
|
||||
LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filename,
|
||||
int *type);
|
||||
LIBSSH_API ssh_public_key publickey_from_privatekey(ssh_private_key prv);
|
||||
LIBSSH_API ssh_string publickey_to_string(ssh_public_key key);
|
||||
|
||||
LIBSSH_API void string_burn(ssh_string str);
|
||||
LIBSSH_API ssh_string string_copy(ssh_string str);
|
||||
LIBSSH_API void *string_data(ssh_string str);
|
||||
LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
|
||||
LIBSSH_API void string_free(ssh_string str);
|
||||
LIBSSH_API ssh_string string_from_char(const char *what);
|
||||
LIBSSH_API size_t string_len(ssh_string str);
|
||||
LIBSSH_API ssh_string string_new(size_t size);
|
||||
LIBSSH_API char *string_to_char(ssh_string str);
|
||||
|
||||
#endif /* LEGACY_H_ */
|
@ -307,60 +307,43 @@ enum ssh_scp_request_types {
|
||||
SSH_SCP_REQUEST_WARNING
|
||||
};
|
||||
|
||||
LIBSSH_API void buffer_free(ssh_buffer buffer);
|
||||
LIBSSH_API void *buffer_get(ssh_buffer buffer);
|
||||
LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
|
||||
LIBSSH_API ssh_buffer buffer_new(void);
|
||||
|
||||
LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
|
||||
LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
|
||||
LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
|
||||
LIBSSH_API int channel_close(ssh_channel channel);
|
||||
LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
|
||||
LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||
LIBSSH_API void channel_free(ssh_channel channel);
|
||||
LIBSSH_API int channel_get_exit_status(ssh_channel channel);
|
||||
LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_closed(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_eof(ssh_channel channel);
|
||||
LIBSSH_API int channel_is_open(ssh_channel channel);
|
||||
LIBSSH_API ssh_channel channel_new(ssh_session session);
|
||||
LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms);
|
||||
LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel,int cols,int rows);
|
||||
LIBSSH_API ssh_channel ssh_channel_forward_accept(ssh_session session, int timeout_ms);
|
||||
LIBSSH_API int ssh_channel_close(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_forward_cancel(ssh_session session, const char *address, int port);
|
||||
LIBSSH_API int ssh_channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||
LIBSSH_API void ssh_channel_free(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
|
||||
LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_is_closed(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_is_open(ssh_channel channel);
|
||||
LIBSSH_API ssh_channel ssh_channel_new(ssh_session session);
|
||||
LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
int remoteport, const char *sourcehost, int localport);
|
||||
LIBSSH_API int channel_open_session(ssh_channel channel);
|
||||
LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
|
||||
LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||
LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||
LIBSSH_API int ssh_channel_open_session(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
|
||||
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int is_stderr);
|
||||
LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int is_stderr);
|
||||
LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||
LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
|
||||
LIBSSH_API int channel_request_pty(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
|
||||
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd);
|
||||
LIBSSH_API int ssh_channel_request_pty(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term,
|
||||
int cols, int rows);
|
||||
LIBSSH_API int channel_request_shell(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
|
||||
LIBSSH_API int channel_request_sftp(ssh_channel channel);
|
||||
LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
|
||||
LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
LIBSSH_API int ssh_channel_request_shell(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum);
|
||||
LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem);
|
||||
LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
const char *cookie, int screen_number);
|
||||
LIBSSH_API int channel_send_eof(ssh_channel channel);
|
||||
LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel);
|
||||
LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||
timeval * timeout);
|
||||
LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
|
||||
LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
|
||||
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
|
||||
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
|
||||
|
||||
LIBSSH_API void privatekey_free(ssh_private_key prv);
|
||||
LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
||||
int type, const char *passphrase);
|
||||
LIBSSH_API void publickey_free(ssh_public_key key);
|
||||
LIBSSH_API int ssh_publickey_to_file(ssh_session session, const char *file,
|
||||
ssh_string pubkey, int type);
|
||||
LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filename,
|
||||
int *type);
|
||||
LIBSSH_API ssh_public_key publickey_from_privatekey(ssh_private_key prv);
|
||||
LIBSSH_API ssh_string publickey_to_string(ssh_public_key key);
|
||||
LIBSSH_API int ssh_try_publickey_from_file(ssh_session session, const char *keyfile,
|
||||
ssh_string *publickey, int *type);
|
||||
|
||||
@ -457,16 +440,19 @@ LIBSSH_API int ssh_userauth_privatekey_file(ssh_session session, const char *use
|
||||
LIBSSH_API const char *ssh_version(int req_version);
|
||||
LIBSSH_API int ssh_write_knownhost(ssh_session session);
|
||||
|
||||
LIBSSH_API void string_burn(ssh_string str);
|
||||
LIBSSH_API ssh_string string_copy(ssh_string str);
|
||||
LIBSSH_API void *string_data(ssh_string str);
|
||||
LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
|
||||
LIBSSH_API void string_free(ssh_string str);
|
||||
LIBSSH_API ssh_string string_from_char(const char *what);
|
||||
LIBSSH_API size_t string_len(ssh_string str);
|
||||
LIBSSH_API ssh_string string_new(size_t size);
|
||||
LIBSSH_API char *string_to_char(ssh_string str);
|
||||
LIBSSH_API void ssh_string_burn(ssh_string str);
|
||||
LIBSSH_API ssh_string ssh_string_copy(ssh_string str);
|
||||
LIBSSH_API void *ssh_string_data(ssh_string str);
|
||||
LIBSSH_API int ssh_string_fill(ssh_string str, const void *data, size_t len);
|
||||
LIBSSH_API void ssh_string_free(ssh_string str);
|
||||
LIBSSH_API ssh_string ssh_string_from_char(const char *what);
|
||||
LIBSSH_API size_t ssh_string_len(ssh_string str);
|
||||
LIBSSH_API ssh_string ssh_string_new(size_t size);
|
||||
LIBSSH_API char *ssh_string_to_char(ssh_string str);
|
||||
|
||||
#ifndef LIBSSH_LEGACY_0_4
|
||||
#include "libssh/legacy.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -174,11 +174,11 @@ private:
|
||||
class Channel {
|
||||
public:
|
||||
Channel(Session &session){
|
||||
channel=channel_new(session.getCSession());
|
||||
channel=ssh_channel_new(session.getCSession());
|
||||
this->session=&session;
|
||||
}
|
||||
~Channel(){
|
||||
channel_free(channel);
|
||||
ssh_channel_free(channel);
|
||||
channel=NULL;
|
||||
}
|
||||
int acceptX11(int timeout_ms);
|
||||
@ -223,7 +223,7 @@ public:
|
||||
if(is_stderr){
|
||||
ret=channel_write_stderr(channel,data,len);
|
||||
} else {
|
||||
ret=channel_write(channel,data,len);
|
||||
ret=ssh_channel_write(channel,data,len);
|
||||
}
|
||||
if(ret==SSH_ERROR)
|
||||
ssh_throw(ret);
|
||||
|
@ -92,6 +92,7 @@ set(libssh_SRCS
|
||||
kex.c
|
||||
keyfiles.c
|
||||
keys.c
|
||||
legacy.c
|
||||
log.c
|
||||
match.c
|
||||
messages.c
|
||||
|
@ -154,7 +154,7 @@ void agent_close(struct ssh_agent_struct *agent) {
|
||||
void agent_free(ssh_agent agent) {
|
||||
if (agent) {
|
||||
if (agent->ident) {
|
||||
buffer_free(agent->ident);
|
||||
ssh_buffer_free(agent->ident);
|
||||
}
|
||||
if (agent->sock) {
|
||||
agent_close(agent);
|
||||
@ -208,7 +208,7 @@ static int agent_talk(struct ssh_session_struct *session,
|
||||
uint32_t len = 0;
|
||||
uint8_t payload[1024] = {0};
|
||||
|
||||
len = buffer_get_len(request);
|
||||
len = ssh_buffer_get_len(request);
|
||||
ssh_log(session, SSH_LOG_PACKET, "agent_talk - len of request: %u", len);
|
||||
agent_put_u32(payload, len);
|
||||
|
||||
@ -284,23 +284,23 @@ int agent_get_ident_count(struct ssh_session_struct *session) {
|
||||
}
|
||||
|
||||
/* send message to the agent requesting the list of identities */
|
||||
request = buffer_new();
|
||||
request = ssh_buffer_new();
|
||||
if (buffer_add_u8(request, c1) < 0) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
return -1;
|
||||
}
|
||||
|
||||
reply = buffer_new();
|
||||
reply = ssh_buffer_new();
|
||||
if (reply == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (agent_talk(session, request, reply) < 0) {
|
||||
buffer_free(request);
|
||||
ssh_buffer_free(request);
|
||||
return 0;
|
||||
}
|
||||
buffer_free(request);
|
||||
ssh_buffer_free(request);
|
||||
|
||||
/* get message type and verify the answer */
|
||||
buffer_get_u8(reply, (uint8_t *) &type);
|
||||
@ -323,7 +323,7 @@ int agent_get_ident_count(struct ssh_session_struct *session) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Too many identities in authentication reply: %d",
|
||||
session->agent->count);
|
||||
buffer_free(reply);
|
||||
ssh_buffer_free(reply);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -369,24 +369,24 @@ struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *se
|
||||
/* get the comment */
|
||||
tmp = buffer_get_ssh_string(session->agent->ident);
|
||||
if (tmp == NULL) {
|
||||
string_free(blob);
|
||||
ssh_string_free(blob);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (comment) {
|
||||
*comment = string_to_char(tmp);
|
||||
*comment = ssh_string_to_char(tmp);
|
||||
} else {
|
||||
string_free(blob);
|
||||
string_free(tmp);
|
||||
ssh_string_free(blob);
|
||||
ssh_string_free(tmp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
string_free(tmp);
|
||||
ssh_string_free(tmp);
|
||||
|
||||
/* get key from blob */
|
||||
pubkey = publickey_from_string(session, blob);
|
||||
string_free(blob);
|
||||
ssh_string_free(blob);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
@ -409,7 +409,7 @@ ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||
/* create blob from the pubkey */
|
||||
blob = publickey_to_string(pubkey);
|
||||
|
||||
request = buffer_new();
|
||||
request = ssh_buffer_new();
|
||||
if (request == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -425,11 +425,11 @@ ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||
}
|
||||
|
||||
/* Add data */
|
||||
dlen = buffer_get_len(data);
|
||||
dlen = ssh_buffer_get_len(data);
|
||||
if (buffer_add_u32(request, htonl(dlen)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(request, buffer_get(data), dlen) < 0) {
|
||||
if (buffer_add_data(request, ssh_buffer_get_begin(data), dlen) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -437,19 +437,19 @@ ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(blob);
|
||||
ssh_string_free(blob);
|
||||
|
||||
reply = buffer_new();
|
||||
reply = ssh_buffer_new();
|
||||
if (reply == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* send the request */
|
||||
if (agent_talk(session, request, reply) < 0) {
|
||||
buffer_free(request);
|
||||
ssh_buffer_free(request);
|
||||
return NULL;
|
||||
}
|
||||
buffer_free(request);
|
||||
ssh_buffer_free(request);
|
||||
|
||||
/* check if reply is valid */
|
||||
if (buffer_get_u8(reply, (uint8_t *) &type) != sizeof(uint8_t)) {
|
||||
@ -457,24 +457,24 @@ ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||
}
|
||||
if (agent_failed(type)) {
|
||||
ssh_log(session, SSH_LOG_RARE, "Agent reports failure in signing the key");
|
||||
buffer_free(reply);
|
||||
ssh_buffer_free(reply);
|
||||
return NULL;
|
||||
} else if (type != SSH2_AGENT_SIGN_RESPONSE) {
|
||||
ssh_set_error(session, SSH_FATAL, "Bad authentication response: %d", type);
|
||||
buffer_free(reply);
|
||||
ssh_buffer_free(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sig = buffer_get_ssh_string(reply);
|
||||
|
||||
buffer_free(reply);
|
||||
ssh_buffer_free(reply);
|
||||
|
||||
return sig;
|
||||
error:
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough memory");
|
||||
string_free(blob);
|
||||
buffer_free(request);
|
||||
buffer_free(reply);
|
||||
ssh_string_free(blob);
|
||||
ssh_buffer_free(request);
|
||||
ssh_buffer_free(reply);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
232
libssh/auth.c
232
libssh/auth.c
@ -94,7 +94,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_banner){
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"Received SSH_USERAUTH_BANNER packet");
|
||||
if(session->banner != NULL)
|
||||
string_free(session->banner);
|
||||
ssh_string_free(session->banner);
|
||||
session->banner = banner;
|
||||
}
|
||||
leave_function();
|
||||
@ -124,7 +124,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_failure){
|
||||
goto end;
|
||||
}
|
||||
|
||||
auth_methods = string_to_char(auth);
|
||||
auth_methods = ssh_string_to_char(auth);
|
||||
if (auth_methods == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
goto end;
|
||||
@ -160,7 +160,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_failure){
|
||||
}
|
||||
|
||||
end:
|
||||
string_free(auth);
|
||||
ssh_string_free(auth);
|
||||
SAFE_FREE(auth_methods);
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
@ -314,9 +314,9 @@ int ssh_userauth_none(ssh_session session, const char *username) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
user = string_from_char(session->username);
|
||||
user = ssh_string_from_char(session->username);
|
||||
} else {
|
||||
user = string_from_char(username);
|
||||
user = ssh_string_from_char(username);
|
||||
}
|
||||
|
||||
if (user == NULL) {
|
||||
@ -325,16 +325,16 @@ int ssh_userauth_none(ssh_session session, const char *username) {
|
||||
}
|
||||
|
||||
if (ask_userauth(session) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
method = string_from_char("none");
|
||||
method = ssh_string_from_char("none");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
}
|
||||
service = string_from_char("ssh-connection");
|
||||
service = ssh_string_from_char("ssh-connection");
|
||||
if (service == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -346,9 +346,9 @@ int ssh_userauth_none(ssh_session session, const char *username) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(user);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) == SSH_ERROR) {
|
||||
leave_function();
|
||||
@ -360,9 +360,9 @@ int ssh_userauth_none(ssh_session session, const char *username) {
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(user);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -421,9 +421,9 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
user = string_from_char(session->username);
|
||||
user = ssh_string_from_char(session->username);
|
||||
} else {
|
||||
user = string_from_char(username);
|
||||
user = ssh_string_from_char(username);
|
||||
}
|
||||
|
||||
if (user == NULL) {
|
||||
@ -432,20 +432,20 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
||||
}
|
||||
|
||||
if (ask_userauth(session) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
service = string_from_char("ssh-connection");
|
||||
service = ssh_string_from_char("ssh-connection");
|
||||
if (service == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method = string_from_char("publickey");
|
||||
method = ssh_string_from_char("publickey");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
}
|
||||
algo = string_from_char(ssh_type_to_char(type));
|
||||
algo = ssh_string_from_char(ssh_type_to_char(type));
|
||||
if (algo == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -460,10 +460,10 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(user);
|
||||
string_free(method);
|
||||
string_free(service);
|
||||
string_free(algo);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(algo);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
leave_function();
|
||||
@ -475,10 +475,10 @@ int ssh_userauth_offer_pubkey(ssh_session session, const char *username,
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(user);
|
||||
string_free(method);
|
||||
string_free(service);
|
||||
string_free(algo);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(algo);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -536,9 +536,9 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
user = string_from_char(session->username);
|
||||
user = ssh_string_from_char(session->username);
|
||||
} else {
|
||||
user = string_from_char(username);
|
||||
user = ssh_string_from_char(username);
|
||||
}
|
||||
|
||||
if (user == NULL) {
|
||||
@ -547,20 +547,20 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
||||
}
|
||||
|
||||
if (ask_userauth(session) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
service = string_from_char("ssh-connection");
|
||||
service = ssh_string_from_char("ssh-connection");
|
||||
if (service == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method = string_from_char("publickey");
|
||||
method = ssh_string_from_char("publickey");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
}
|
||||
algo = string_from_char(ssh_type_to_char(privatekey->type));
|
||||
algo = ssh_string_from_char(ssh_type_to_char(privatekey->type));
|
||||
if (algo == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -587,18 +587,18 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(user);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(algo);
|
||||
string_free(pkstr);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(algo);
|
||||
ssh_string_free(pkstr);
|
||||
|
||||
sign = ssh_do_sign(session,session->out_buffer, privatekey);
|
||||
if (sign) {
|
||||
if (buffer_add_ssh_string(session->out_buffer,sign) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_free(sign);
|
||||
ssh_string_free(sign);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
leave_function();
|
||||
@ -611,11 +611,11 @@ int ssh_userauth_pubkey(ssh_session session, const char *username,
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(user);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(algo);
|
||||
string_free(pkstr);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(algo);
|
||||
ssh_string_free(pkstr);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -681,7 +681,7 @@ int ssh_userauth_privatekey_file(ssh_session session, const char *username,
|
||||
|
||||
error:
|
||||
SAFE_FREE(pubkeyfile);
|
||||
string_free(pubkey);
|
||||
ssh_string_free(pubkey);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -733,9 +733,9 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
user = string_from_char(session->username);
|
||||
user = ssh_string_from_char(session->username);
|
||||
} else {
|
||||
user = string_from_char(username);
|
||||
user = ssh_string_from_char(username);
|
||||
}
|
||||
|
||||
if (user == NULL) {
|
||||
@ -744,20 +744,20 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
||||
}
|
||||
|
||||
if (ask_userauth(session) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
service = string_from_char("ssh-connection");
|
||||
service = ssh_string_from_char("ssh-connection");
|
||||
if (service == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method = string_from_char("publickey");
|
||||
method = ssh_string_from_char("publickey");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
}
|
||||
algo = string_from_char(ssh_type_to_char(publickey->type));
|
||||
algo = ssh_string_from_char(ssh_type_to_char(publickey->type));
|
||||
if (algo == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -783,7 +783,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
||||
if (buffer_add_ssh_string(session->out_buffer, sign) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_free(sign);
|
||||
ssh_string_free(sign);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
leave_function();
|
||||
@ -792,23 +792,23 @@ int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
||||
rc = wait_auth_status(session);
|
||||
}
|
||||
|
||||
string_free(user);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(algo);
|
||||
string_free(key);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(algo);
|
||||
ssh_string_free(key);
|
||||
|
||||
leave_function();
|
||||
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(sign);
|
||||
string_free(user);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(algo);
|
||||
string_free(key);
|
||||
ssh_string_free(sign);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(algo);
|
||||
ssh_string_free(key);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -861,9 +861,9 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
user = string_from_char(session->username);
|
||||
user = ssh_string_from_char(session->username);
|
||||
} else {
|
||||
user = string_from_char(username);
|
||||
user = ssh_string_from_char(username);
|
||||
}
|
||||
|
||||
if (user == NULL) {
|
||||
@ -872,20 +872,20 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
||||
}
|
||||
|
||||
if (ask_userauth(session) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
service = string_from_char("ssh-connection");
|
||||
service = ssh_string_from_char("ssh-connection");
|
||||
if (service == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method = string_from_char("password");
|
||||
method = ssh_string_from_char("password");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
}
|
||||
pwd = string_from_char(password);
|
||||
pwd = ssh_string_from_char(password);
|
||||
if (pwd == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -899,11 +899,11 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(user);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_burn(pwd);
|
||||
ssh_string_free(pwd);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
leave_function();
|
||||
@ -915,11 +915,11 @@ int ssh_userauth_password(ssh_session session, const char *username,
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(user);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
ssh_string_free(user);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_burn(pwd);
|
||||
ssh_string_free(pwd);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -982,7 +982,7 @@ int ssh_userauth_autopubkey(ssh_session session, const char *passphrase) {
|
||||
pubkey_string = publickey_to_string(pubkey);
|
||||
if (pubkey_string) {
|
||||
rc = ssh_userauth_offer_pubkey(session, NULL, pubkey->type, pubkey_string);
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
if (rc == SSH_AUTH_ERROR) {
|
||||
SAFE_FREE(privkey_file);
|
||||
publickey_free(pubkey);
|
||||
@ -1091,14 +1091,14 @@ int ssh_userauth_autopubkey(ssh_session session, const char *passphrase) {
|
||||
|
||||
rc = ssh_userauth_offer_pubkey(session, NULL, type, pubkey_string);
|
||||
if (rc == SSH_AUTH_ERROR){
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
ssh_log(session, SSH_LOG_RARE, "Publickey authentication error");
|
||||
leave_function();
|
||||
return rc;
|
||||
} else {
|
||||
if (rc != SSH_AUTH_SUCCESS){
|
||||
ssh_log(session, SSH_LOG_PROTOCOL, "Publickey refused by server");
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -1112,14 +1112,14 @@ int ssh_userauth_autopubkey(ssh_session session, const char *passphrase) {
|
||||
ssh_log(session, SSH_LOG_RARE,
|
||||
"Reading private key %s failed (bad passphrase ?)",
|
||||
privkey_file);
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
continue; /* continue the loop with other pubkey */
|
||||
}
|
||||
}
|
||||
|
||||
rc = ssh_userauth_pubkey(session, NULL, pubkey_string, privkey);
|
||||
if (rc == SSH_AUTH_ERROR) {
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
privatekey_free(privkey);
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -1127,7 +1127,7 @@ int ssh_userauth_autopubkey(ssh_session session, const char *passphrase) {
|
||||
if (rc != SSH_AUTH_SUCCESS){
|
||||
ssh_log(session, SSH_LOG_RARE,
|
||||
"The server accepted the public key but refused the signature");
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
privatekey_free(privkey);
|
||||
continue;
|
||||
}
|
||||
@ -1136,7 +1136,7 @@ int ssh_userauth_autopubkey(ssh_session session, const char *passphrase) {
|
||||
/* auth success */
|
||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
||||
"Successfully authenticated using %s", privkey_file);
|
||||
string_free(pubkey_string);
|
||||
ssh_string_free(pubkey_string);
|
||||
privatekey_free(privkey);
|
||||
|
||||
leave_function();
|
||||
@ -1249,19 +1249,19 @@ static int kbdauth_init(ssh_session session, const char *user,
|
||||
|
||||
enter_function();
|
||||
|
||||
usr = string_from_char(user);
|
||||
usr = ssh_string_from_char(user);
|
||||
if (usr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
sub = (submethods ? string_from_char(submethods) : string_from_char(""));
|
||||
sub = (submethods ? ssh_string_from_char(submethods) : ssh_string_from_char(""));
|
||||
if (sub == NULL) {
|
||||
goto error;
|
||||
}
|
||||
service = string_from_char("ssh-connection");
|
||||
service = ssh_string_from_char("ssh-connection");
|
||||
if (service == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method = string_from_char("keyboard-interactive");
|
||||
method = ssh_string_from_char("keyboard-interactive");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1275,10 +1275,10 @@ static int kbdauth_init(ssh_session session, const char *user,
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(usr);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(sub);
|
||||
ssh_string_free(usr);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(sub);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
leave_function();
|
||||
@ -1290,10 +1290,10 @@ static int kbdauth_init(ssh_session session, const char *user,
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(usr);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
string_free(sub);
|
||||
ssh_string_free(usr);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
ssh_string_free(sub);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -1314,21 +1314,21 @@ static int kbdauth_info_get(ssh_session session) {
|
||||
buffer_get_u32(session->in_buffer, &nprompts);
|
||||
|
||||
if (name == NULL || instruction == NULL || tmp == NULL) {
|
||||
string_free(name);
|
||||
string_free(instruction);
|
||||
ssh_string_free(name);
|
||||
ssh_string_free(instruction);
|
||||
/* tmp if empty if we got here */
|
||||
ssh_set_error(session, SSH_FATAL, "Invalid USERAUTH_INFO_REQUEST msg");
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
string_free(tmp);
|
||||
ssh_string_free(tmp);
|
||||
|
||||
if (session->kbdint == NULL) {
|
||||
session->kbdint = kbdint_new();
|
||||
if (session->kbdint == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
string_free(name);
|
||||
string_free(instruction);
|
||||
ssh_string_free(name);
|
||||
ssh_string_free(instruction);
|
||||
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
@ -1337,8 +1337,8 @@ static int kbdauth_info_get(ssh_session session) {
|
||||
kbdint_clean(session->kbdint);
|
||||
}
|
||||
|
||||
session->kbdint->name = string_to_char(name);
|
||||
string_free(name);
|
||||
session->kbdint->name = ssh_string_to_char(name);
|
||||
ssh_string_free(name);
|
||||
if (session->kbdint->name == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
kbdint_free(session->kbdint);
|
||||
@ -1346,8 +1346,8 @@ static int kbdauth_info_get(ssh_session session) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
session->kbdint->instruction = string_to_char(instruction);
|
||||
string_free(instruction);
|
||||
session->kbdint->instruction = ssh_string_to_char(instruction);
|
||||
ssh_string_free(instruction);
|
||||
if (session->kbdint->instruction == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
kbdint_free(session->kbdint);
|
||||
@ -1400,8 +1400,8 @@ static int kbdauth_info_get(ssh_session session) {
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
session->kbdint->prompts[i] = string_to_char(tmp);
|
||||
string_free(tmp);
|
||||
session->kbdint->prompts[i] = ssh_string_to_char(tmp);
|
||||
ssh_string_free(tmp);
|
||||
if (session->kbdint->prompts[i] == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
kbdint_free(session->kbdint);
|
||||
@ -1431,9 +1431,9 @@ static int kbdauth_send(ssh_session session) {
|
||||
|
||||
for (i = 0; i < session->kbdint->nprompts; i++) {
|
||||
if (session->kbdint->answers[i]) {
|
||||
answer = string_from_char(session->kbdint->answers[i]);
|
||||
answer = ssh_string_from_char(session->kbdint->answers[i]);
|
||||
} else {
|
||||
answer = string_from_char("");
|
||||
answer = ssh_string_from_char("");
|
||||
}
|
||||
if (answer == NULL) {
|
||||
goto error;
|
||||
@ -1443,8 +1443,8 @@ static int kbdauth_send(ssh_session session) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_burn(answer);
|
||||
string_free(answer);
|
||||
ssh_string_burn(answer);
|
||||
ssh_string_free(answer);
|
||||
}
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
@ -1457,8 +1457,8 @@ static int kbdauth_send(ssh_session session) {
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_burn(answer);
|
||||
string_free(answer);
|
||||
ssh_string_burn(answer);
|
||||
ssh_string_free(answer);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
|
@ -86,20 +86,20 @@ static int send_username(ssh_session session, const char *username) {
|
||||
}
|
||||
}
|
||||
}
|
||||
user = string_from_char(username);
|
||||
user = ssh_string_from_char(username);
|
||||
if (user == NULL) {
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_USER) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, user) < 0) {
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
string_free(user);
|
||||
ssh_string_free(user);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return SSH_AUTH_ERROR;
|
||||
@ -156,7 +156,7 @@ int ssh_userauth1_password(ssh_session session, const char *username,
|
||||
/* cisco IOS doesn't like when a password is followed by zeroes and random pad. */
|
||||
if(1 || strlen(password) >= 128) {
|
||||
/* not risky to disclose the size of such a big password .. */
|
||||
pwd = string_from_char(password);
|
||||
pwd = ssh_string_from_char(password);
|
||||
if (pwd == NULL) {
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
@ -168,7 +168,7 @@ int ssh_userauth1_password(ssh_session session, const char *username,
|
||||
* why garbage ? because nul bytes will be compressed by
|
||||
* gzip and disclose password len.
|
||||
*/
|
||||
pwd = string_new(128);
|
||||
pwd = ssh_string_new(128);
|
||||
if (pwd == NULL) {
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
@ -178,20 +178,20 @@ int ssh_userauth1_password(ssh_session session, const char *username,
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
ssh_string_burn(pwd);
|
||||
ssh_string_free(pwd);
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
ssh_string_burn(pwd);
|
||||
ssh_string_free(pwd);
|
||||
leave_function();
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
|
||||
string_burn(pwd);
|
||||
string_free(pwd);
|
||||
ssh_string_burn(pwd);
|
||||
ssh_string_free(pwd);
|
||||
session->auth_state=SSH_AUTH_STATE_NONE;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
leave_function();
|
||||
|
@ -77,7 +77,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
SAFE_FREE(base64);
|
||||
return NULL;
|
||||
@ -162,7 +162,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
||||
|
||||
error:
|
||||
SAFE_FREE(base64);
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ static void buffer_verify(struct buffer_struct *buf){
|
||||
*
|
||||
* @return A newly initialized SSH buffer, NULL on error.
|
||||
*/
|
||||
struct ssh_buffer_struct *buffer_new(void) {
|
||||
struct ssh_buffer_struct *ssh_buffer_new(void) {
|
||||
struct ssh_buffer_struct *buf = malloc(sizeof(struct ssh_buffer_struct));
|
||||
|
||||
if (buf == NULL) {
|
||||
@ -94,7 +94,7 @@ struct ssh_buffer_struct *buffer_new(void) {
|
||||
*
|
||||
* \param[in] buffer The buffer to free.
|
||||
*/
|
||||
void buffer_free(struct ssh_buffer_struct *buffer) {
|
||||
void ssh_buffer_free(struct ssh_buffer_struct *buffer) {
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -193,7 +193,7 @@ int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
|
||||
struct ssh_string_struct *string) {
|
||||
uint32_t len = 0;
|
||||
|
||||
len = string_len(string);
|
||||
len = ssh_string_len(string);
|
||||
if (buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -319,7 +319,7 @@ int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
|
||||
*/
|
||||
int buffer_add_buffer(struct ssh_buffer_struct *buffer,
|
||||
struct ssh_buffer_struct *source) {
|
||||
if (buffer_add_data(buffer, buffer_get(source), buffer_get_len(source)) < 0) {
|
||||
if (buffer_add_data(buffer, ssh_buffer_get_begin(source), ssh_buffer_get_len(source)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ int buffer_add_buffer(struct ssh_buffer_struct *buffer,
|
||||
* @see buffer_get_rest()
|
||||
* @see buffer_get_len()
|
||||
*/
|
||||
void *buffer_get(struct ssh_buffer_struct *buffer){
|
||||
void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ void *buffer_get_rest(struct ssh_buffer_struct *buffer){
|
||||
*
|
||||
* @see buffer_get()
|
||||
*/
|
||||
uint32_t buffer_get_len(struct ssh_buffer_struct *buffer){
|
||||
uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
|
||||
return buffer->used;
|
||||
}
|
||||
|
||||
@ -525,11 +525,11 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
|
||||
if ((buffer->pos + hostlen) > buffer->used) {
|
||||
return NULL; /* it is indeed */
|
||||
}
|
||||
str = string_new(hostlen);
|
||||
str = ssh_string_new(hostlen);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_get_data(buffer, string_data(str), hostlen) != hostlen) {
|
||||
if (buffer_get_data(buffer, ssh_string_data(str), hostlen) != hostlen) {
|
||||
/* should never happen */
|
||||
SAFE_FREE(str);
|
||||
return NULL;
|
||||
@ -562,11 +562,11 @@ struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
|
||||
if ((buffer->pos + len) > buffer->used) {
|
||||
return NULL;
|
||||
}
|
||||
str = string_new(len);
|
||||
str = ssh_string_new(len);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_get_data(buffer, string_data(str), len) != len) {
|
||||
if (buffer_get_data(buffer, ssh_string_data(str), len) != len) {
|
||||
SAFE_FREE(str);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ static ssh_channel channel_from_msg(ssh_session session, ssh_buffer packet);
|
||||
*
|
||||
* @return A pointer to a newly allocated channel, NULL on error.
|
||||
*/
|
||||
ssh_channel channel_new(ssh_session session) {
|
||||
ssh_channel ssh_channel_new(ssh_session session) {
|
||||
ssh_channel channel = NULL;
|
||||
|
||||
channel = malloc(sizeof(struct ssh_channel_struct));
|
||||
@ -72,15 +72,15 @@ ssh_channel channel_new(ssh_session session) {
|
||||
}
|
||||
memset(channel,0,sizeof(struct ssh_channel_struct));
|
||||
|
||||
channel->stdout_buffer = buffer_new();
|
||||
channel->stdout_buffer = ssh_buffer_new();
|
||||
if (channel->stdout_buffer == NULL) {
|
||||
SAFE_FREE(channel);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
channel->stderr_buffer = buffer_new();
|
||||
channel->stderr_buffer = ssh_buffer_new();
|
||||
if (channel->stderr_buffer == NULL) {
|
||||
buffer_free(channel->stdout_buffer);
|
||||
ssh_buffer_free(channel->stdout_buffer);
|
||||
SAFE_FREE(channel);
|
||||
return NULL;
|
||||
}
|
||||
@ -188,8 +188,8 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open_fail){
|
||||
|
||||
error_s = buffer_get_ssh_string(packet);
|
||||
if(error_s != NULL)
|
||||
error = string_to_char(error_s);
|
||||
string_free(error_s);
|
||||
error = ssh_string_to_char(error_s);
|
||||
ssh_string_free(error_s);
|
||||
if (error == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
return SSH_PACKET_USED;
|
||||
@ -238,7 +238,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
|
||||
"Creating a channel %d with %d window and %d max packet",
|
||||
channel->local_channel, window, maxpacket);
|
||||
|
||||
type = string_from_char(type_c);
|
||||
type = ssh_string_from_char(type_c);
|
||||
if (type == NULL) {
|
||||
leave_function();
|
||||
return err;
|
||||
@ -249,12 +249,12 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
|
||||
buffer_add_u32(session->out_buffer, htonl(channel->local_channel)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, htonl(channel->local_window)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, htonl(channel->local_maxpacket)) < 0) {
|
||||
string_free(type);
|
||||
ssh_string_free(type);
|
||||
leave_function();
|
||||
return err;
|
||||
}
|
||||
|
||||
string_free(type);
|
||||
ssh_string_free(type);
|
||||
|
||||
if (payload != NULL) {
|
||||
if (buffer_add_buffer(session->out_buffer, payload) < 0) {
|
||||
@ -444,7 +444,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
len = string_len(str);
|
||||
len = ssh_string_len(str);
|
||||
|
||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
||||
"Channel receiving %zu bytes data in %d (local win=%d remote win=%d)",
|
||||
@ -461,9 +461,9 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
|
||||
channel->local_window);
|
||||
}
|
||||
|
||||
if (channel_default_bufferize(channel, string_data(str), len,
|
||||
if (channel_default_bufferize(channel, ssh_string_data(str), len,
|
||||
is_stderr) < 0) {
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
@ -479,7 +479,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
|
||||
channel->local_window,
|
||||
channel->remote_window);
|
||||
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
@ -573,8 +573,8 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
|
||||
request = string_to_char(request_s);
|
||||
string_free(request_s);
|
||||
request = ssh_string_to_char(request_s);
|
||||
ssh_string_free(request_s);
|
||||
if (request == NULL) {
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
@ -607,8 +607,8 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
|
||||
sig = string_to_char(signal_s);
|
||||
string_free(signal_s);
|
||||
sig = ssh_string_to_char(signal_s);
|
||||
ssh_string_free(signal_s);
|
||||
if (sig == NULL) {
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
@ -663,7 +663,7 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||
if (is_stderr == 0) {
|
||||
/* stdout */
|
||||
if (channel->stdout_buffer == NULL) {
|
||||
channel->stdout_buffer = buffer_new();
|
||||
channel->stdout_buffer = ssh_buffer_new();
|
||||
if (channel->stdout_buffer == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
return -1;
|
||||
@ -671,14 +671,14 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||
}
|
||||
|
||||
if (buffer_add_data(channel->stdout_buffer, data, len) < 0) {
|
||||
buffer_free(channel->stdout_buffer);
|
||||
ssh_buffer_free(channel->stdout_buffer);
|
||||
channel->stdout_buffer = NULL;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* stderr */
|
||||
if (channel->stderr_buffer == NULL) {
|
||||
channel->stderr_buffer = buffer_new();
|
||||
channel->stderr_buffer = ssh_buffer_new();
|
||||
if (channel->stderr_buffer == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
return -1;
|
||||
@ -686,7 +686,7 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||
}
|
||||
|
||||
if (buffer_add_data(channel->stderr_buffer, data, len) < 0) {
|
||||
buffer_free(channel->stderr_buffer);
|
||||
ssh_buffer_free(channel->stderr_buffer);
|
||||
channel->stderr_buffer = NULL;
|
||||
return -1;
|
||||
}
|
||||
@ -707,7 +707,7 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||
* @see channel_request_shell()
|
||||
* @see channel_request_exec()
|
||||
*/
|
||||
int channel_open_session(ssh_channel channel) {
|
||||
int ssh_channel_open_session(ssh_channel channel) {
|
||||
#ifdef WITH_SSH1
|
||||
if (channel->session->version == 1) {
|
||||
return channel_open_session1(channel);
|
||||
@ -738,7 +738,7 @@ int channel_open_session(ssh_channel channel) {
|
||||
* forward the content of a socket to the channel. You still have to
|
||||
* use channel_read and channel_write for this.
|
||||
*/
|
||||
int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
int remoteport, const char *sourcehost, int localport) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_buffer payload = NULL;
|
||||
@ -747,11 +747,11 @@ int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
|
||||
enter_function();
|
||||
|
||||
payload = buffer_new();
|
||||
payload = ssh_buffer_new();
|
||||
if (payload == NULL) {
|
||||
goto error;
|
||||
}
|
||||
str = string_from_char(remotehost);
|
||||
str = ssh_string_from_char(remotehost);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -761,8 +761,8 @@ int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(str);
|
||||
str = string_from_char(sourcehost);
|
||||
ssh_string_free(str);
|
||||
str = ssh_string_from_char(sourcehost);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -775,8 +775,8 @@ int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
rc = channel_open(channel, "direct-tcpip", 64000, 32000, payload);
|
||||
|
||||
error:
|
||||
buffer_free(payload);
|
||||
string_free(str);
|
||||
ssh_buffer_free(payload);
|
||||
ssh_string_free(str);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -789,7 +789,7 @@ error:
|
||||
*
|
||||
* @warning Any data unread on this channel will be lost.
|
||||
*/
|
||||
void channel_free(ssh_channel channel) {
|
||||
void ssh_channel_free(ssh_channel channel) {
|
||||
ssh_session session = channel->session;
|
||||
enter_function();
|
||||
|
||||
@ -799,7 +799,7 @@ void channel_free(ssh_channel channel) {
|
||||
}
|
||||
|
||||
if (session->alive && channel->state == SSH_CHANNEL_STATE_OPEN) {
|
||||
channel_close(channel);
|
||||
ssh_channel_close(channel);
|
||||
}
|
||||
|
||||
/* handle the "my channel is first on session list" case */
|
||||
@ -815,8 +815,8 @@ void channel_free(ssh_channel channel) {
|
||||
channel->next->prev = channel->prev;
|
||||
}
|
||||
|
||||
buffer_free(channel->stdout_buffer);
|
||||
buffer_free(channel->stderr_buffer);
|
||||
ssh_buffer_free(channel->stdout_buffer);
|
||||
ssh_buffer_free(channel->stderr_buffer);
|
||||
|
||||
/* debug trick to catch use after frees */
|
||||
memset(channel, 'X', sizeof(struct ssh_channel_struct));
|
||||
@ -837,7 +837,7 @@ void channel_free(ssh_channel channel) {
|
||||
* @see channel_close()
|
||||
* @see channel_free()
|
||||
*/
|
||||
int channel_send_eof(ssh_channel channel){
|
||||
int ssh_channel_send_eof(ssh_channel channel){
|
||||
ssh_session session = channel->session;
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
@ -879,14 +879,14 @@ error:
|
||||
* @see channel_free()
|
||||
* @see channel_eof()
|
||||
*/
|
||||
int channel_close(ssh_channel channel){
|
||||
int ssh_channel_close(ssh_channel channel){
|
||||
ssh_session session = channel->session;
|
||||
int rc = 0;
|
||||
|
||||
enter_function();
|
||||
|
||||
if (channel->local_eof == 0) {
|
||||
rc = channel_send_eof(channel);
|
||||
rc = ssh_channel_send_eof(channel);
|
||||
}
|
||||
|
||||
if (rc != SSH_OK) {
|
||||
@ -1014,7 +1014,7 @@ error:
|
||||
*
|
||||
* @see channel_read()
|
||||
*/
|
||||
int channel_write(ssh_channel channel, const void *data, uint32_t len) {
|
||||
int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len) {
|
||||
return channel_write_common(channel, data, len, 0);
|
||||
}
|
||||
|
||||
@ -1027,7 +1027,7 @@ int channel_write(ssh_channel channel, const void *data, uint32_t len) {
|
||||
*
|
||||
* @see channel_is_closed()
|
||||
*/
|
||||
int channel_is_open(ssh_channel channel) {
|
||||
int ssh_channel_is_open(ssh_channel channel) {
|
||||
return (channel->state == SSH_CHANNEL_STATE_OPEN && channel->session->alive != 0);
|
||||
}
|
||||
|
||||
@ -1040,7 +1040,7 @@ int channel_is_open(ssh_channel channel) {
|
||||
*
|
||||
* @see channel_is_open()
|
||||
*/
|
||||
int channel_is_closed(ssh_channel channel) {
|
||||
int ssh_channel_is_closed(ssh_channel channel) {
|
||||
return (channel->state != SSH_CHANNEL_STATE_OPEN || channel->session->alive == 0);
|
||||
}
|
||||
|
||||
@ -1051,7 +1051,7 @@ int channel_is_closed(ssh_channel channel) {
|
||||
*
|
||||
* @return 0 if there is no EOF, nonzero otherwise.
|
||||
*/
|
||||
int channel_is_eof(ssh_channel channel) {
|
||||
int ssh_channel_is_eof(ssh_channel channel) {
|
||||
if ((channel->stdout_buffer &&
|
||||
buffer_get_rest_len(channel->stdout_buffer) > 0) ||
|
||||
(channel->stderr_buffer &&
|
||||
@ -1072,7 +1072,7 @@ int channel_is_eof(ssh_channel channel) {
|
||||
* @bug This functionality is still under development and
|
||||
* doesn't work correctly.
|
||||
*/
|
||||
void channel_set_blocking(ssh_channel channel, int blocking) {
|
||||
void ssh_channel_set_blocking(ssh_channel channel, int blocking) {
|
||||
channel->blocking = (blocking == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
@ -1156,7 +1156,7 @@ static int channel_request(ssh_channel channel, const char *request,
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
req = string_from_char(request);
|
||||
req = ssh_string_from_char(request);
|
||||
if (req == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1167,11 +1167,11 @@ static int channel_request(ssh_channel channel, const char *request,
|
||||
buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_free(req);
|
||||
ssh_string_free(req);
|
||||
|
||||
if (buffer != NULL) {
|
||||
if (buffer_add_data(session->out_buffer, buffer_get(buffer),
|
||||
buffer_get_len(buffer)) < 0) {
|
||||
if (buffer_add_data(session->out_buffer, ssh_buffer_get_begin(buffer),
|
||||
ssh_buffer_get_len(buffer)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -1218,7 +1218,7 @@ static int channel_request(ssh_channel channel, const char *request,
|
||||
return rc;
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(req);
|
||||
ssh_string_free(req);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -1237,7 +1237,7 @@ error:
|
||||
*
|
||||
* @return SSH_SUCCESS on success, SSH_ERROR if an error occured.
|
||||
*/
|
||||
int channel_request_pty_size(ssh_channel channel, const char *terminal,
|
||||
int ssh_channel_request_pty_size(ssh_channel channel, const char *terminal,
|
||||
int col, int row) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_string term = NULL;
|
||||
@ -1252,12 +1252,12 @@ int channel_request_pty_size(ssh_channel channel, const char *terminal,
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
term = string_from_char(terminal);
|
||||
term = ssh_string_from_char(terminal);
|
||||
if (term == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1274,8 +1274,8 @@ int channel_request_pty_size(ssh_channel channel, const char *terminal,
|
||||
|
||||
rc = channel_request(channel, "pty-req", buffer, 1);
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(term);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(term);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -1290,8 +1290,8 @@ error:
|
||||
*
|
||||
* @see channel_request_pty_size()
|
||||
*/
|
||||
int channel_request_pty(ssh_channel channel) {
|
||||
return channel_request_pty_size(channel, "xterm", 80, 24);
|
||||
int ssh_channel_request_pty(ssh_channel channel) {
|
||||
return ssh_channel_request_pty_size(channel, "xterm", 80, 24);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1309,7 +1309,7 @@ int channel_request_pty(ssh_channel channel) {
|
||||
* libssh function using the same channel/session is running at same
|
||||
* time (not 100% threadsafe).
|
||||
*/
|
||||
int channel_change_pty_size(ssh_channel channel, int cols, int rows) {
|
||||
int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_buffer buffer = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
@ -1324,7 +1324,7 @@ int channel_change_pty_size(ssh_channel channel, int cols, int rows) {
|
||||
}
|
||||
#endif
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1338,7 +1338,7 @@ int channel_change_pty_size(ssh_channel channel, int cols, int rows) {
|
||||
|
||||
rc = channel_request(channel, "window-change", buffer, 0);
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -1351,7 +1351,7 @@ error:
|
||||
*
|
||||
* @return SSH_SUCCESS on success, SSH_ERROR if an error occured.
|
||||
*/
|
||||
int channel_request_shell(ssh_channel channel) {
|
||||
int ssh_channel_request_shell(ssh_channel channel) {
|
||||
#ifdef WITH_SSH1
|
||||
if (channel->version == 1) {
|
||||
return channel_request_shell1(channel);
|
||||
@ -1371,17 +1371,17 @@ int channel_request_shell(ssh_channel channel) {
|
||||
*
|
||||
* @warning You normally don't have to call it for sftp, see sftp_new().
|
||||
*/
|
||||
int channel_request_subsystem(ssh_channel channel, const char *subsys) {
|
||||
int ssh_channel_request_subsystem(ssh_channel channel, const char *subsys) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string subsystem = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
subsystem = string_from_char(subsys);
|
||||
subsystem = ssh_string_from_char(subsys);
|
||||
if (subsystem == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1392,14 +1392,14 @@ int channel_request_subsystem(ssh_channel channel, const char *subsys) {
|
||||
|
||||
rc = channel_request(channel, "subsystem", buffer, 1);
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(subsystem);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(subsystem);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int channel_request_sftp( ssh_channel channel){
|
||||
return channel_request_subsystem(channel, "sftp");
|
||||
int ssh_channel_request_sftp( ssh_channel channel){
|
||||
return ssh_channel_request_subsystem(channel, "sftp");
|
||||
}
|
||||
|
||||
static ssh_string generate_cookie(void) {
|
||||
@ -1412,7 +1412,7 @@ static ssh_string generate_cookie(void) {
|
||||
s[i] = hex[rand() % 16];
|
||||
}
|
||||
s[32] = '\0';
|
||||
return string_from_char(s);
|
||||
return ssh_string_from_char(s);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1437,25 +1437,25 @@ static ssh_string generate_cookie(void) {
|
||||
*
|
||||
* @return SSH_SUCCESS on success, SSH_ERROR if an error occured.
|
||||
*/
|
||||
int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
const char *cookie, int screen_number) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string p = NULL;
|
||||
ssh_string c = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
p = string_from_char(protocol ? protocol : "MIT-MAGIC-COOKIE-1");
|
||||
p = ssh_string_from_char(protocol ? protocol : "MIT-MAGIC-COOKIE-1");
|
||||
if (p == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (cookie) {
|
||||
c = string_from_char(cookie);
|
||||
c = ssh_string_from_char(cookie);
|
||||
} else {
|
||||
c = generate_cookie();
|
||||
}
|
||||
@ -1473,9 +1473,9 @@ int channel_request_x11(ssh_channel channel, int single_connection, const char *
|
||||
rc = channel_request(channel, "x11-req", buffer, 1);
|
||||
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(p);
|
||||
string_free(c);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(p);
|
||||
ssh_string_free(c);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1530,7 +1530,7 @@ static ssh_channel channel_accept(ssh_session session, int channeltype,
|
||||
* @return A newly created channel, or NULL if no X11 request from
|
||||
* the server.
|
||||
*/
|
||||
ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms) {
|
||||
ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms) {
|
||||
return channel_accept(channel->session, SSH_CHANNEL_X11, timeout_ms);
|
||||
}
|
||||
|
||||
@ -1612,7 +1612,7 @@ static int global_request(ssh_session session, const char *request,
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
req = string_from_char(request);
|
||||
req = ssh_string_from_char(request);
|
||||
if (req == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1622,12 +1622,12 @@ static int global_request(ssh_session session, const char *request,
|
||||
buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_free(req);
|
||||
ssh_string_free(req);
|
||||
req=NULL;
|
||||
|
||||
if (buffer != NULL) {
|
||||
if (buffer_add_data(session->out_buffer, buffer_get(buffer),
|
||||
buffer_get_len(buffer)) < 0) {
|
||||
if (buffer_add_data(session->out_buffer, ssh_buffer_get_begin(buffer),
|
||||
ssh_buffer_get_len(buffer)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -1674,7 +1674,7 @@ static int global_request(ssh_session session, const char *request,
|
||||
leave_function();
|
||||
return rc;
|
||||
error:
|
||||
string_free(req);
|
||||
ssh_string_free(req);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
@ -1698,18 +1698,18 @@ error:
|
||||
*
|
||||
* @return SSH_SUCCESS on success, SSH_ERROR if an error occured.
|
||||
*/
|
||||
int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port) {
|
||||
int ssh_channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string addr = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
uint32_t tmp;
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
addr = string_from_char(address ? address : "");
|
||||
addr = ssh_string_from_char(address ? address : "");
|
||||
if (addr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1727,8 +1727,8 @@ int channel_forward_listen(ssh_session session, const char *address, int port, i
|
||||
}
|
||||
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(addr);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(addr);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1742,7 +1742,7 @@ error:
|
||||
* @return Newly created channel, or NULL if no incoming channel request from
|
||||
* the server
|
||||
*/
|
||||
ssh_channel channel_forward_accept(ssh_session session, int timeout_ms) {
|
||||
ssh_channel ssh_channel_forward_accept(ssh_session session, int timeout_ms) {
|
||||
return channel_accept(session, SSH_CHANNEL_FORWARDED_TCPIP, timeout_ms);
|
||||
}
|
||||
|
||||
@ -1758,17 +1758,17 @@ ssh_channel channel_forward_accept(ssh_session session, int timeout_ms) {
|
||||
*
|
||||
* @return SSH_SUCCESS on success, SSH_ERROR if an error occured.
|
||||
*/
|
||||
int channel_forward_cancel(ssh_session session, const char *address, int port) {
|
||||
int ssh_channel_forward_cancel(ssh_session session, const char *address, int port) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string addr = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
addr = string_from_char(address ? address : "");
|
||||
addr = ssh_string_from_char(address ? address : "");
|
||||
if (addr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1781,8 +1781,8 @@ int channel_forward_cancel(ssh_session session, const char *address, int port) {
|
||||
rc = global_request(session, "cancel-tcpip-forward", buffer, 1);
|
||||
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(addr);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(addr);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1799,17 +1799,17 @@ error:
|
||||
*
|
||||
* @warning Some environment variables may be refused by security reasons.
|
||||
*/
|
||||
int channel_request_env(ssh_channel channel, const char *name, const char *value) {
|
||||
int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string str = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
str = string_from_char(name);
|
||||
str = ssh_string_from_char(name);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1818,8 +1818,8 @@ int channel_request_env(ssh_channel channel, const char *name, const char *value
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(str);
|
||||
str = string_from_char(value);
|
||||
ssh_string_free(str);
|
||||
str = ssh_string_from_char(value);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1830,8 +1830,8 @@ int channel_request_env(ssh_channel channel, const char *name, const char *value
|
||||
|
||||
rc = channel_request(channel, "env", buffer,1);
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(str);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(str);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -1863,7 +1863,7 @@ error:
|
||||
*
|
||||
* @see channel_request_shell()
|
||||
*/
|
||||
int channel_request_exec(ssh_channel channel, const char *cmd) {
|
||||
int ssh_channel_request_exec(ssh_channel channel, const char *cmd) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string command = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
@ -1874,12 +1874,12 @@ int channel_request_exec(ssh_channel channel, const char *cmd) {
|
||||
}
|
||||
#endif
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
command = string_from_char(cmd);
|
||||
command = ssh_string_from_char(cmd);
|
||||
if (command == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1890,8 +1890,8 @@ int channel_request_exec(ssh_channel channel, const char *cmd) {
|
||||
|
||||
rc = channel_request(channel, "exec", buffer, 1);
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(command);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(command);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1912,7 +1912,7 @@ error:
|
||||
* @return SSH_SUCCESS on success, SSH_ERROR if an error occured
|
||||
* (including attempts to send signal via SSH-v1 session).
|
||||
*/
|
||||
int channel_request_send_signal(ssh_channel channel, const char *sig) {
|
||||
int ssh_channel_request_send_signal(ssh_channel channel, const char *sig) {
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string encoded_signal = NULL;
|
||||
int rc = SSH_ERROR;
|
||||
@ -1923,12 +1923,12 @@ int channel_request_send_signal(ssh_channel channel, const char *sig) {
|
||||
}
|
||||
#endif
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
encoded_signal = string_from_char(sig);
|
||||
encoded_signal = ssh_string_from_char(sig);
|
||||
if (encoded_signal == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -1939,8 +1939,8 @@ int channel_request_send_signal(ssh_channel channel, const char *sig) {
|
||||
|
||||
rc = channel_request(channel, "signal", buffer, 0);
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(encoded_signal);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(encoded_signal);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -2046,7 +2046,7 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||
}
|
||||
|
||||
leave_function();
|
||||
return buffer_get_len(buffer);
|
||||
return ssh_buffer_get_len(buffer);
|
||||
}
|
||||
|
||||
/* TODO FIXME Fix the delayed close thing */
|
||||
@ -2071,7 +2071,7 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||
* @warning The read function using a buffer has been renamed to
|
||||
* channel_read_buffer().
|
||||
*/
|
||||
int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr) {
|
||||
int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_buffer stdbuf = channel->stdout_buffer;
|
||||
uint32_t len;
|
||||
@ -2165,7 +2165,7 @@ int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
|
||||
*
|
||||
* @see channel_is_eof()
|
||||
*/
|
||||
int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int is_stderr) {
|
||||
ssh_session session = channel->session;
|
||||
uint32_t to_read;
|
||||
@ -2173,7 +2173,7 @@ int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
|
||||
enter_function();
|
||||
|
||||
to_read = channel_poll(channel, is_stderr);
|
||||
to_read = ssh_channel_poll(channel, is_stderr);
|
||||
|
||||
if (to_read <= 0) {
|
||||
leave_function();
|
||||
@ -2183,7 +2183,7 @@ int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
if (to_read > count) {
|
||||
to_read = count;
|
||||
}
|
||||
rc = channel_read(channel, dest, to_read, is_stderr);
|
||||
rc = ssh_channel_read(channel, dest, to_read, is_stderr);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -2203,7 +2203,7 @@ int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
*
|
||||
* @see channel_is_eof()
|
||||
*/
|
||||
int channel_poll(ssh_channel channel, int is_stderr){
|
||||
int ssh_channel_poll(ssh_channel channel, int is_stderr){
|
||||
ssh_session session = channel->session;
|
||||
ssh_buffer stdbuf = channel->stdout_buffer;
|
||||
|
||||
@ -2241,7 +2241,7 @@ int channel_poll(ssh_channel channel, int is_stderr){
|
||||
*
|
||||
* @return The session pointer.
|
||||
*/
|
||||
ssh_session channel_get_session(ssh_channel channel) {
|
||||
ssh_session ssh_channel_get_session(ssh_channel channel) {
|
||||
return channel->session;
|
||||
}
|
||||
|
||||
@ -2254,7 +2254,7 @@ ssh_session channel_get_session(ssh_channel channel) {
|
||||
* @returns The exit status, -1 if no exit status has been returned
|
||||
* or eof not sent.
|
||||
*/
|
||||
int channel_get_exit_status(ssh_channel channel) {
|
||||
int ssh_channel_get_exit_status(ssh_channel channel) {
|
||||
if (channel->local_eof == 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -2295,12 +2295,12 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
|
||||
for (i = 0; rchans[i] != NULL; i++) {
|
||||
chan = rchans[i];
|
||||
|
||||
while (channel_is_open(chan) && ssh_socket_data_available(chan->session->socket)) {
|
||||
while (ssh_channel_is_open(chan) && ssh_socket_data_available(chan->session->socket)) {
|
||||
ssh_handle_packets(chan->session,-1);
|
||||
}
|
||||
|
||||
if ((chan->stdout_buffer && buffer_get_len(chan->stdout_buffer) > 0) ||
|
||||
(chan->stderr_buffer && buffer_get_len(chan->stderr_buffer) > 0) ||
|
||||
if ((chan->stdout_buffer && ssh_buffer_get_len(chan->stdout_buffer) > 0) ||
|
||||
(chan->stderr_buffer && ssh_buffer_get_len(chan->stderr_buffer) > 0) ||
|
||||
chan->remote_eof) {
|
||||
rout[j] = chan;
|
||||
j++;
|
||||
@ -2313,7 +2313,7 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
|
||||
chan = wchans[i];
|
||||
/* It's not our business to seek if the file descriptor is writable */
|
||||
if (ssh_socket_data_writable(chan->session->socket) &&
|
||||
channel_is_open(chan) && (chan->remote_window > 0)) {
|
||||
ssh_channel_is_open(chan) && (chan->remote_window > 0)) {
|
||||
wout[j] = chan;
|
||||
j++;
|
||||
}
|
||||
@ -2324,7 +2324,7 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
|
||||
for (i = 0; echans[i] != NULL; i++) {
|
||||
chan = echans[i];
|
||||
|
||||
if (!ssh_socket_is_open(chan->session->socket) || channel_is_closed(chan)) {
|
||||
if (!ssh_socket_is_open(chan->session->socket) || ssh_channel_is_closed(chan)) {
|
||||
eout[j] = chan;
|
||||
j++;
|
||||
}
|
||||
@ -2365,7 +2365,7 @@ static int count_ptrs(ssh_channel *ptrs) {
|
||||
* select(2) syscall was interrupted, then relaunch the
|
||||
* function.
|
||||
*/
|
||||
int channel_select(ssh_channel *readchans, ssh_channel *writechans,
|
||||
int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans,
|
||||
ssh_channel *exceptchans, struct timeval * timeout) {
|
||||
ssh_channel *rchans, *wchans, *echans;
|
||||
ssh_channel dummy = NULL;
|
||||
|
@ -88,7 +88,7 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
|
||||
ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
|
||||
return SSH_ERROR;
|
||||
}
|
||||
str = string_from_char(terminal);
|
||||
str = ssh_string_from_char(terminal);
|
||||
if (str == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
return -1;
|
||||
@ -96,10 +96,10 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_REQUEST_PTY) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, str) < 0) {
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
return -1;
|
||||
}
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
|
||||
if (buffer_add_u32(session->out_buffer, ntohl(row)) < 0 ||
|
||||
buffer_add_u32(session->out_buffer, ntohl(col)) < 0 ||
|
||||
@ -198,17 +198,17 @@ int channel_request_exec1(ssh_channel channel, const char *cmd) {
|
||||
ssh_session session = channel->session;
|
||||
ssh_string command = NULL;
|
||||
|
||||
command = string_from_char(cmd);
|
||||
command = ssh_string_from_char(cmd);
|
||||
if (command == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH_CMSG_EXEC_CMD) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, command) < 0) {
|
||||
string_free(command);
|
||||
ssh_string_free(command);
|
||||
return -1;
|
||||
}
|
||||
string_free(command);
|
||||
ssh_string_free(command);
|
||||
|
||||
if(packet_send(session) != SSH_OK) {
|
||||
return -1;
|
||||
@ -232,14 +232,14 @@ SSH_PACKET_CALLBACK(ssh_packet_data1){
|
||||
|
||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
||||
"Adding %zu bytes data in %d",
|
||||
string_len(str), is_stderr);
|
||||
ssh_string_len(str), is_stderr);
|
||||
|
||||
if (channel_default_bufferize(channel, string_data(str), string_len(str),
|
||||
if (channel_default_bufferize(channel, ssh_string_data(str), ssh_string_len(str),
|
||||
is_stderr) < 0) {
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
|
@ -278,8 +278,8 @@ SSH_PACKET_CALLBACK(ssh_packet_dh_reply){
|
||||
ssh_set_error(session, SSH_FATAL, "Cannot import f number");
|
||||
goto error;
|
||||
}
|
||||
string_burn(f);
|
||||
string_free(f);
|
||||
ssh_string_burn(f);
|
||||
ssh_string_free(f);
|
||||
f=NULL;
|
||||
signature = buffer_get_ssh_string(packet);
|
||||
if (signature == NULL) {
|
||||
@ -351,8 +351,8 @@ SSH_PACKET_CALLBACK(ssh_packet_newkeys){
|
||||
}
|
||||
|
||||
/* forget it for now ... */
|
||||
string_burn(signature);
|
||||
string_free(signature);
|
||||
ssh_string_burn(signature);
|
||||
ssh_string_free(signature);
|
||||
signature=NULL;
|
||||
/*
|
||||
* Once we got SSH2_MSG_NEWKEYS we can switch next_crypto and
|
||||
@ -416,8 +416,8 @@ static int dh_handshake(ssh_session session) {
|
||||
if (buffer_add_ssh_string(session->out_buffer, e) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
e=NULL;
|
||||
|
||||
rc = packet_send(session);
|
||||
@ -446,16 +446,16 @@ static int dh_handshake(ssh_session session) {
|
||||
return SSH_AGAIN;
|
||||
error:
|
||||
if(e != NULL){
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
}
|
||||
if(f != NULL){
|
||||
string_burn(f);
|
||||
string_free(f);
|
||||
ssh_string_burn(f);
|
||||
ssh_string_free(f);
|
||||
}
|
||||
if(signature != NULL){
|
||||
string_burn(signature);
|
||||
string_free(signature);
|
||||
ssh_string_burn(signature);
|
||||
ssh_string_free(signature);
|
||||
}
|
||||
|
||||
leave_function();
|
||||
@ -503,16 +503,16 @@ int ssh_service_request(ssh_session session, const char *service) {
|
||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_SERVICE_REQUEST) < 0) {
|
||||
break;
|
||||
}
|
||||
service_s = string_from_char(service);
|
||||
service_s = ssh_string_from_char(service);
|
||||
if (service_s == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer_add_ssh_string(session->out_buffer,service_s) < 0) {
|
||||
string_free(service_s);
|
||||
ssh_string_free(service_s);
|
||||
break;
|
||||
}
|
||||
string_free(service_s);
|
||||
ssh_string_free(service_s);
|
||||
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
@ -754,7 +754,7 @@ char *ssh_get_issue_banner(ssh_session session) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return string_to_char(session->banner);
|
||||
return ssh_string_to_char(session->banner);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -799,16 +799,16 @@ void ssh_disconnect(ssh_session session) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
str = string_from_char("Bye Bye");
|
||||
str = ssh_string_from_char("Bye Bye");
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (buffer_add_ssh_string(session->out_buffer,str) < 0) {
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
goto error;
|
||||
}
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
|
||||
packet_send(session);
|
||||
ssh_socket_close(session->socket);
|
||||
|
@ -506,11 +506,11 @@ int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
||||
j = 0;
|
||||
for (i = 0; channels[i]; i++) {
|
||||
if (channels[i]->session->alive) {
|
||||
if(channel_poll(channels[i], 0) > 0) {
|
||||
if(ssh_channel_poll(channels[i], 0) > 0) {
|
||||
outchannels[j] = channels[i];
|
||||
j++;
|
||||
} else {
|
||||
if(channel_poll(channels[i], 1) > 0) {
|
||||
if(ssh_channel_poll(channels[i], 1) > 0) {
|
||||
outchannels[j] = channels[i];
|
||||
j++;
|
||||
}
|
||||
@ -574,8 +574,8 @@ int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
|
||||
for (i = 0; channels[i]; i++) {
|
||||
if (channels[i]->session->alive &&
|
||||
ssh_socket_fd_isset(channels[i]->session->socket,&localset)) {
|
||||
if ((channel_poll(channels[i],0) > 0) ||
|
||||
(channel_poll(channels[i], 1) > 0)) {
|
||||
if ((ssh_channel_poll(channels[i],0) > 0) ||
|
||||
(ssh_channel_poll(channels[i], 1) > 0)) {
|
||||
outchannels[j] = channels[i];
|
||||
j++;
|
||||
}
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "libssh/session.h"
|
||||
#include "libssh/wrapper.h"
|
||||
#include "libssh/crypto.h"
|
||||
#include "libssh/buffer.h"
|
||||
|
||||
uint32_t packet_decrypt_len(ssh_session session, char *crypted){
|
||||
uint32_t decrypted;
|
||||
|
||||
@ -196,7 +198,7 @@ int packet_hmac_verify(ssh_session session, ssh_buffer buffer,
|
||||
seq = htonl(session->recv_seq);
|
||||
|
||||
hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
|
||||
hmac_update(ctx, buffer_get(buffer), buffer_get_len(buffer));
|
||||
hmac_update(ctx, ssh_buffer_get_begin(buffer), ssh_buffer_get_len(buffer));
|
||||
hmac_final(ctx, hmacbuf, &len);
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
|
66
libssh/dh.c
66
libssh/dh.c
@ -368,7 +368,7 @@ ssh_string make_bignum_string(bignum num) {
|
||||
|
||||
bignum make_string_bn(ssh_string string){
|
||||
bignum bn = NULL;
|
||||
unsigned int len = string_len(string);
|
||||
unsigned int len = ssh_string_len(string);
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
fprintf(stderr, "Importing a %d bits, %d bytes object ...\n",
|
||||
@ -498,12 +498,12 @@ int make_sessionid(ssh_session session) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
buf = buffer_new();
|
||||
buf = ssh_buffer_new();
|
||||
if (buf == NULL) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
str = string_from_char(session->clientbanner);
|
||||
str = ssh_string_from_char(session->clientbanner);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -511,9 +511,9 @@ int make_sessionid(ssh_session session) {
|
||||
if (buffer_add_ssh_string(buf, str) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
|
||||
str = string_from_char(session->serverbanner);
|
||||
str = ssh_string_from_char(session->serverbanner);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -543,25 +543,25 @@ int make_sessionid(ssh_session session) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = ntohl(buffer_get_len(client_hash));
|
||||
len = ntohl(ssh_buffer_get_len(client_hash));
|
||||
if (buffer_add_u32(buf,len) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(buf, buffer_get(client_hash),
|
||||
buffer_get_len(client_hash)) < 0) {
|
||||
if (buffer_add_data(buf, ssh_buffer_get_begin(client_hash),
|
||||
ssh_buffer_get_len(client_hash)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = ntohl(buffer_get_len(server_hash));
|
||||
len = ntohl(ssh_buffer_get_len(server_hash));
|
||||
if (buffer_add_u32(buf, len) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(buf, buffer_get(server_hash),
|
||||
buffer_get_len(server_hash)) < 0) {
|
||||
if (buffer_add_data(buf, ssh_buffer_get_begin(server_hash),
|
||||
ssh_buffer_get_len(server_hash)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = string_len(session->next_crypto->server_pubkey) + 4;
|
||||
len = ssh_string_len(session->next_crypto->server_pubkey) + 4;
|
||||
if (buffer_add_data(buf, session->next_crypto->server_pubkey, len) < 0) {
|
||||
goto error;
|
||||
}
|
||||
@ -571,38 +571,38 @@ int make_sessionid(ssh_session session) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = string_len(num) + 4;
|
||||
len = ssh_string_len(num) + 4;
|
||||
if (buffer_add_data(buf, num, len) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(num);
|
||||
ssh_string_free(num);
|
||||
num = make_bignum_string(session->next_crypto->f);
|
||||
if (num == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = string_len(num) + 4;
|
||||
len = ssh_string_len(num) + 4;
|
||||
if (buffer_add_data(buf, num, len) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_free(num);
|
||||
ssh_string_free(num);
|
||||
num = make_bignum_string(session->next_crypto->k);
|
||||
if (num == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = string_len(num) + 4;
|
||||
len = ssh_string_len(num) + 4;
|
||||
if (buffer_add_data(buf, num, len) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("hash buffer", buffer_get(buf), buffer_get_len(buf));
|
||||
ssh_print_hexa("hash buffer", ssh_buffer_get_begin(buf), ssh_buffer_get_len(buf));
|
||||
#endif
|
||||
|
||||
sha1_update(ctx, buffer_get(buf), buffer_get_len(buf));
|
||||
sha1_update(ctx, ssh_buffer_get_begin(buf), ssh_buffer_get_len(buf));
|
||||
sha1_final(session->next_crypto->session_id, ctx);
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
@ -612,15 +612,15 @@ int make_sessionid(ssh_session session) {
|
||||
|
||||
rc = SSH_OK;
|
||||
error:
|
||||
buffer_free(buf);
|
||||
buffer_free(client_hash);
|
||||
buffer_free(server_hash);
|
||||
ssh_buffer_free(buf);
|
||||
ssh_buffer_free(client_hash);
|
||||
ssh_buffer_free(server_hash);
|
||||
|
||||
session->in_hashbuf = NULL;
|
||||
session->out_hashbuf = NULL;
|
||||
|
||||
string_free(str);
|
||||
string_free(num);
|
||||
ssh_string_free(str);
|
||||
ssh_string_free(num);
|
||||
|
||||
leave_function();
|
||||
|
||||
@ -628,7 +628,7 @@ error:
|
||||
}
|
||||
|
||||
int hashbufout_add_cookie(ssh_session session) {
|
||||
session->out_hashbuf = buffer_new();
|
||||
session->out_hashbuf = ssh_buffer_new();
|
||||
if (session->out_hashbuf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -656,7 +656,7 @@ int hashbufout_add_cookie(ssh_session session) {
|
||||
}
|
||||
|
||||
int hashbufin_add_cookie(ssh_session session, unsigned char *cookie) {
|
||||
session->in_hashbuf = buffer_new();
|
||||
session->in_hashbuf = ssh_buffer_new();
|
||||
if (session->in_hashbuf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -684,7 +684,7 @@ static int generate_one_key(ssh_string k,
|
||||
return -1;
|
||||
}
|
||||
|
||||
sha1_update(ctx, k, string_len(k) + 4);
|
||||
sha1_update(ctx, k, ssh_string_len(k) + 4);
|
||||
sha1_update(ctx, session_id, SHA_DIGEST_LEN);
|
||||
sha1_update(ctx, &letter, 1);
|
||||
sha1_update(ctx, session_id, SHA_DIGEST_LEN);
|
||||
@ -752,7 +752,7 @@ int generate_session_keys(ssh_session session) {
|
||||
if (ctx == NULL) {
|
||||
goto error;
|
||||
}
|
||||
sha1_update(ctx, k_string, string_len(k_string) + 4);
|
||||
sha1_update(ctx, k_string, ssh_string_len(k_string) + 4);
|
||||
sha1_update(ctx, session->next_crypto->session_id, SHA_DIGEST_LEN);
|
||||
sha1_update(ctx, session->next_crypto->encryptkey, SHA_DIGEST_LEN);
|
||||
sha1_final(session->next_crypto->encryptkey + SHA_DIGEST_LEN, ctx);
|
||||
@ -760,7 +760,7 @@ int generate_session_keys(ssh_session session) {
|
||||
|
||||
if (session->next_crypto->in_cipher->keysize > SHA_DIGEST_LEN * 8) {
|
||||
ctx = sha1_init();
|
||||
sha1_update(ctx, k_string, string_len(k_string) + 4);
|
||||
sha1_update(ctx, k_string, ssh_string_len(k_string) + 4);
|
||||
sha1_update(ctx, session->next_crypto->session_id, SHA_DIGEST_LEN);
|
||||
sha1_update(ctx, session->next_crypto->decryptkey, SHA_DIGEST_LEN);
|
||||
sha1_final(session->next_crypto->decryptkey + SHA_DIGEST_LEN, ctx);
|
||||
@ -798,7 +798,7 @@ int generate_session_keys(ssh_session session) {
|
||||
|
||||
rc = 0;
|
||||
error:
|
||||
string_free(k_string);
|
||||
ssh_string_free(k_string);
|
||||
leave_function();
|
||||
|
||||
return rc;
|
||||
@ -851,7 +851,7 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) {
|
||||
|
||||
pubkey = session->current_crypto->server_pubkey;
|
||||
|
||||
md5_update(ctx, pubkey->string, string_len(pubkey));
|
||||
md5_update(ctx, pubkey->string, ssh_string_len(pubkey));
|
||||
md5_final(h, ctx);
|
||||
|
||||
*hash = h;
|
||||
@ -875,7 +875,7 @@ void ssh_clean_pubkey_hash(unsigned char **hash) {
|
||||
}
|
||||
|
||||
ssh_string ssh_get_pubkey(ssh_session session){
|
||||
return string_copy(session->current_crypto->server_pubkey);
|
||||
return ssh_string_copy(session->current_crypto->server_pubkey);
|
||||
}
|
||||
|
||||
static int match(const char *group, const char *object){
|
||||
@ -976,7 +976,7 @@ int sig_verify(ssh_session session, ssh_public_key pubkey,
|
||||
}
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
valid = RSA_verify(NID_sha1, hash + 1, SHA_DIGEST_LEN,
|
||||
signature->rsa_sign->string, string_len(signature->rsa_sign),
|
||||
signature->rsa_sign->string, ssh_string_len(signature->rsa_sign),
|
||||
pubkey->rsa_pub);
|
||||
if (valid == 1) {
|
||||
return 0;
|
||||
|
@ -58,8 +58,8 @@ static z_stream *initcompress(ssh_session session, int level) {
|
||||
|
||||
static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level){
|
||||
z_stream *zout = session->current_crypto->compress_out_ctx;
|
||||
void *in_ptr = buffer_get(source);
|
||||
unsigned long in_size = buffer_get_len(source);
|
||||
void *in_ptr = ssh_buffer_get_begin(source);
|
||||
unsigned long in_size = ssh_buffer_get_len(source);
|
||||
ssh_buffer dest = NULL;
|
||||
static unsigned char out_buf[BLOCKSIZE] = {0};
|
||||
unsigned long len;
|
||||
@ -72,7 +72,7 @@ static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level)
|
||||
}
|
||||
}
|
||||
|
||||
dest = buffer_new();
|
||||
dest = ssh_buffer_new();
|
||||
if (dest == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -84,14 +84,14 @@ static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level)
|
||||
zout->avail_out = BLOCKSIZE;
|
||||
status = deflate(zout, Z_PARTIAL_FLUSH);
|
||||
if (status != Z_OK) {
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"status %d deflating zlib packet", status);
|
||||
return NULL;
|
||||
}
|
||||
len = BLOCKSIZE - zout->avail_out;
|
||||
if (buffer_add_data(dest, out_buf, len) < 0) {
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return NULL;
|
||||
}
|
||||
zout->next_out = out_buf;
|
||||
@ -109,16 +109,16 @@ int compress_buffer(ssh_session session, ssh_buffer buf) {
|
||||
}
|
||||
|
||||
if (buffer_reinit(buf) < 0) {
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_data(buf, buffer_get(dest), buffer_get_len(dest)) < 0) {
|
||||
buffer_free(dest);
|
||||
if (buffer_add_data(buf, ssh_buffer_get_begin(dest), ssh_buffer_get_len(dest)) < 0) {
|
||||
ssh_buffer_free(dest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t
|
||||
}
|
||||
}
|
||||
|
||||
dest = buffer_new();
|
||||
dest = ssh_buffer_new();
|
||||
if (dest == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -176,18 +176,18 @@ static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t
|
||||
if (status != Z_OK) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"status %d inflating zlib packet", status);
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = BLOCKSIZE - zin->avail_out;
|
||||
if (buffer_add_data(dest,out_buf,len) < 0) {
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_get_len(dest) > maxlen){
|
||||
if (ssh_buffer_get_len(dest) > maxlen){
|
||||
/* Size of packet exceded, avoid a denial of service attack */
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return NULL;
|
||||
}
|
||||
zin->next_out = out_buf;
|
||||
@ -205,16 +205,16 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen){
|
||||
}
|
||||
|
||||
if (buffer_reinit(buf) < 0) {
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_data(buf, buffer_get(dest), buffer_get_len(dest)) < 0) {
|
||||
buffer_free(dest);
|
||||
if (buffer_add_data(buf, ssh_buffer_get_begin(dest), ssh_buffer_get_len(dest)) < 0) {
|
||||
ssh_buffer_free(dest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_free(dest);
|
||||
ssh_buffer_free(dest);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
68
libssh/kex.c
68
libssh/kex.c
@ -282,11 +282,11 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
|
||||
goto error;
|
||||
}
|
||||
|
||||
strings[i] = string_to_char(str);
|
||||
strings[i] = ssh_string_to_char(str);
|
||||
if (strings[i] == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
str = NULL;
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
|
||||
ssh_connection_callback(session);
|
||||
return SSH_PACKET_USED;
|
||||
error:
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
for (i = 0; i < 10; i++) {
|
||||
SAFE_FREE(strings[i]);
|
||||
}
|
||||
@ -407,7 +407,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
|
||||
ssh_list_kex(session, kex);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
str = string_from_char(kex->methods[i]);
|
||||
str = ssh_string_from_char(kex->methods[i]);
|
||||
if (str == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -418,7 +418,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
|
||||
if (buffer_add_ssh_string(session->out_buffer, str) < 0) {
|
||||
goto error;
|
||||
}
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, 0) < 0) {
|
||||
@ -438,7 +438,7 @@ int ssh_send_kex(ssh_session session, int server_kex) {
|
||||
error:
|
||||
buffer_reinit(session->out_buffer);
|
||||
buffer_reinit(session->out_hashbuf);
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
|
||||
leave_function();
|
||||
return -1;
|
||||
@ -466,8 +466,8 @@ static ssh_string make_rsa1_string(ssh_string e, ssh_string n){
|
||||
ssh_string rsa = NULL;
|
||||
ssh_string ret = NULL;
|
||||
|
||||
buffer = buffer_new();
|
||||
rsa = string_from_char("ssh-rsa1");
|
||||
buffer = ssh_buffer_new();
|
||||
rsa = ssh_string_from_char("ssh-rsa1");
|
||||
|
||||
if (buffer_add_ssh_string(buffer, rsa) < 0) {
|
||||
goto error;
|
||||
@ -479,15 +479,15 @@ static ssh_string make_rsa1_string(ssh_string e, ssh_string n){
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = string_new(buffer_get_len(buffer));
|
||||
ret = ssh_string_new(ssh_buffer_get_len(buffer));
|
||||
if (ret == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_fill(ret, buffer_get(buffer), buffer_get_len(buffer));
|
||||
ssh_string_fill(ret, ssh_buffer_get_begin(buffer), ssh_buffer_get_len(buffer));
|
||||
error:
|
||||
buffer_free(buffer);
|
||||
string_free(rsa);
|
||||
ssh_buffer_free(buffer);
|
||||
ssh_string_free(rsa);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -502,11 +502,11 @@ static int build_session_id1(ssh_session session, ssh_string servern,
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("host modulus",string_data(hostn),string_len(hostn));
|
||||
ssh_print_hexa("server modulus",string_data(servern),string_len(servern));
|
||||
ssh_print_hexa("host modulus",ssh_string_data(hostn),ssh_string_len(hostn));
|
||||
ssh_print_hexa("server modulus",ssh_string_data(servern),ssh_string_len(servern));
|
||||
#endif
|
||||
md5_update(md5,string_data(hostn),string_len(hostn));
|
||||
md5_update(md5,string_data(servern),string_len(servern));
|
||||
md5_update(md5,ssh_string_data(hostn),ssh_string_len(hostn));
|
||||
md5_update(md5,ssh_string_data(servern),ssh_string_len(servern));
|
||||
md5_update(md5,session->server_kex.cookie,8);
|
||||
md5_final(session->next_crypto->session_id,md5);
|
||||
#ifdef DEBUG_CRYPTO
|
||||
@ -566,11 +566,11 @@ static ssh_string encrypt_session_key(ssh_session session, ssh_public_key srvkey
|
||||
for (i = 0; i < 16; i++) {
|
||||
buffer[i] ^= session->next_crypto->session_id[i];
|
||||
}
|
||||
data1 = string_new(32);
|
||||
data1 = ssh_string_new(32);
|
||||
if (data1 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
string_fill(data1, buffer, 32);
|
||||
ssh_string_fill(data1, buffer, 32);
|
||||
if (ABS(hlen - slen) < 128){
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS,
|
||||
"Difference between server modulus and host modulus is only %d. "
|
||||
@ -580,25 +580,25 @@ static ssh_string encrypt_session_key(ssh_session session, ssh_public_key srvkey
|
||||
|
||||
if (modulus_smaller(srvkey, hostkey)) {
|
||||
data2 = ssh_encrypt_rsa1(session, data1, srvkey);
|
||||
string_free(data1);
|
||||
ssh_string_free(data1);
|
||||
data1 = NULL;
|
||||
if (data2 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
data1 = ssh_encrypt_rsa1(session, data2, hostkey);
|
||||
string_free(data2);
|
||||
ssh_string_free(data2);
|
||||
if (data1 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
data2 = ssh_encrypt_rsa1(session, data1, hostkey);
|
||||
string_free(data1);
|
||||
ssh_string_free(data1);
|
||||
data1 = NULL;
|
||||
if (data2 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
data1 = ssh_encrypt_rsa1(session, data2, srvkey);
|
||||
string_free(data2);
|
||||
ssh_string_free(data2);
|
||||
if (data1 == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -718,7 +718,7 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
|
||||
goto error;
|
||||
}
|
||||
|
||||
session->next_crypto->server_pubkey = string_copy(hostkey);
|
||||
session->next_crypto->server_pubkey = ssh_string_copy(hostkey);
|
||||
if (session->next_crypto->server_pubkey == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -747,16 +747,16 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
|
||||
goto error;
|
||||
}
|
||||
|
||||
bits = string_len(enc_session) * 8 - 7;
|
||||
bits = ssh_string_len(enc_session) * 8 - 7;
|
||||
ssh_log(session, SSH_LOG_PROTOCOL, "%d bits, %zu bytes encrypted session",
|
||||
bits, string_len(enc_session));
|
||||
bits, ssh_string_len(enc_session));
|
||||
bits = htons(bits);
|
||||
/* the encrypted mpint */
|
||||
if (buffer_add_data(session->out_buffer, &bits, sizeof(uint16_t)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_data(session->out_buffer, string_data(enc_session),
|
||||
string_len(enc_session)) < 0) {
|
||||
if (buffer_add_data(session->out_buffer, ssh_string_data(enc_session),
|
||||
ssh_string_len(enc_session)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
/* the protocol flags */
|
||||
@ -780,13 +780,13 @@ error:
|
||||
session->session_state=SSH_SESSION_STATE_ERROR;
|
||||
end:
|
||||
|
||||
string_free(host_mod);
|
||||
string_free(host_exp);
|
||||
string_free(server_mod);
|
||||
string_free(server_exp);
|
||||
string_free(serverkey);
|
||||
string_free(hostkey);
|
||||
string_free(enc_session);
|
||||
ssh_string_free(host_mod);
|
||||
ssh_string_free(host_exp);
|
||||
ssh_string_free(server_mod);
|
||||
ssh_string_free(server_exp);
|
||||
ssh_string_free(serverkey);
|
||||
ssh_string_free(hostkey);
|
||||
ssh_string_free(enc_session);
|
||||
|
||||
publickey_free(srv);
|
||||
publickey_free(host);
|
||||
|
@ -155,13 +155,13 @@ static ssh_string asn1_get_int(ssh_buffer buffer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str = string_new(size);
|
||||
str = ssh_string_new(size);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buffer_get_data(buffer, str->string, size) == 0) {
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -180,9 +180,9 @@ static int asn1_check_sequence(ssh_buffer buffer) {
|
||||
}
|
||||
|
||||
size = asn1_get_len(buffer);
|
||||
if ((padding = buffer_get_len(buffer) - buffer->pos - size) > 0) {
|
||||
for (i = buffer_get_len(buffer) - buffer->pos - size,
|
||||
j = (unsigned char*)buffer_get(buffer) + size + buffer->pos;
|
||||
if ((padding = ssh_buffer_get_len(buffer) - buffer->pos - size) > 0) {
|
||||
for (i = ssh_buffer_get_len(buffer) - buffer->pos - size,
|
||||
j = (unsigned char*)ssh_buffer_get_begin(buffer) + size + buffer->pos;
|
||||
i;
|
||||
i--, j++)
|
||||
{
|
||||
@ -280,14 +280,14 @@ static int privatekey_decrypt(int algo, int mode, unsigned int key_len,
|
||||
if (gcry_cipher_open(&cipher, algo, mode, 0)
|
||||
|| gcry_cipher_setkey(cipher, key, key_len)
|
||||
|| gcry_cipher_setiv(cipher, iv, iv_len)
|
||||
|| (tmp = malloc(buffer_get_len(data) * sizeof (char))) == NULL
|
||||
|| gcry_cipher_decrypt(cipher, tmp, buffer_get_len(data),
|
||||
buffer_get(data), buffer_get_len(data))) {
|
||||
|| (tmp = malloc(ssh_buffer_get_len(data) * sizeof (char))) == NULL
|
||||
|| gcry_cipher_decrypt(cipher, tmp, ssh_buffer_get_len(data),
|
||||
ssh_buffer_get_begin(data), ssh_buffer_get_len(data))) {
|
||||
gcry_cipher_close(cipher);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(buffer_get(data), tmp, buffer_get_len(data));
|
||||
memcpy(ssh_buffer_get_begin(data), tmp, ssh_buffer_get_len(data));
|
||||
|
||||
SAFE_FREE(tmp);
|
||||
gcry_cipher_close(cipher);
|
||||
@ -367,7 +367,7 @@ static ssh_buffer privatekey_file_to_buffer(FILE *fp, int type,
|
||||
int mode = 0;
|
||||
int len;
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -382,7 +382,7 @@ static ssh_buffer privatekey_file_to_buffer(FILE *fp, int type,
|
||||
header_end = RSA_HEADER_END;
|
||||
break;
|
||||
default:
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -400,18 +400,18 @@ static ssh_buffer privatekey_file_to_buffer(FILE *fp, int type,
|
||||
if ((privatekey_dek_header(buf + 10, len - 10, &algo, &mode, &key_len,
|
||||
&iv, &iv_len) < 0)
|
||||
|| read_line(buf, MAXLINESIZE, fp)) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (buffer_add_data(buffer, buf, len) < 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
@ -420,31 +420,31 @@ static ssh_buffer privatekey_file_to_buffer(FILE *fp, int type,
|
||||
while ((len = read_line(buf,MAXLINESIZE,fp)) &&
|
||||
strncmp(buf, header_end, header_end_size) != 0) {
|
||||
if (len == -1) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_add_data(buffer, buf, len) < 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp(buf,header_end,header_end_size) != 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buffer_add_data(buffer, "\0", 1) < 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out = base64_to_bin(buffer_get(buffer));
|
||||
buffer_free(buffer);
|
||||
out = base64_to_bin(ssh_buffer_get_begin(buffer));
|
||||
ssh_buffer_free(buffer);
|
||||
if (out == NULL) {
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
@ -453,7 +453,7 @@ static ssh_buffer privatekey_file_to_buffer(FILE *fp, int type,
|
||||
if (algo) {
|
||||
if (privatekey_decrypt(algo, mode, key_len, iv, iv_len, out,
|
||||
cb, userdata, desc) < 0) {
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
SAFE_FREE(iv);
|
||||
return NULL;
|
||||
}
|
||||
@ -483,13 +483,13 @@ static int read_rsa_privatekey(FILE *fp, gcry_sexp_t *r,
|
||||
}
|
||||
|
||||
if (!asn1_check_sequence(buffer)) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
v = asn1_get_int(buffer);
|
||||
if (ntohl(v->size) != 1 || v->string[0] != 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -502,7 +502,7 @@ static int read_rsa_privatekey(FILE *fp, gcry_sexp_t *r,
|
||||
unused2 = asn1_get_int(buffer);
|
||||
u = asn1_get_int(buffer);
|
||||
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
|
||||
if (n == NULL || e == NULL || d == NULL || p == NULL || q == NULL ||
|
||||
unused1 == NULL || unused2 == NULL|| u == NULL) {
|
||||
@ -522,15 +522,15 @@ static int read_rsa_privatekey(FILE *fp, gcry_sexp_t *r,
|
||||
}
|
||||
|
||||
error:
|
||||
string_free(n);
|
||||
string_free(e);
|
||||
string_free(d);
|
||||
string_free(p);
|
||||
string_free(q);
|
||||
string_free(unused1);
|
||||
string_free(unused2);
|
||||
string_free(u);
|
||||
string_free(v);
|
||||
ssh_string_free(n);
|
||||
ssh_string_free(e);
|
||||
ssh_string_free(d);
|
||||
ssh_string_free(p);
|
||||
ssh_string_free(q);
|
||||
ssh_string_free(unused1);
|
||||
ssh_string_free(unused2);
|
||||
ssh_string_free(u);
|
||||
ssh_string_free(v);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -552,13 +552,13 @@ static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb,
|
||||
}
|
||||
|
||||
if (!asn1_check_sequence(buffer)) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
v = asn1_get_int(buffer);
|
||||
if (ntohl(v->size) != 1 || v->string[0] != 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -567,7 +567,7 @@ static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb,
|
||||
g = asn1_get_int(buffer);
|
||||
y = asn1_get_int(buffer);
|
||||
x = asn1_get_int(buffer);
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
|
||||
if (p == NULL || q == NULL || g == NULL || y == NULL || x == NULL) {
|
||||
rc = 0;
|
||||
@ -585,12 +585,12 @@ static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb,
|
||||
}
|
||||
|
||||
error:
|
||||
string_free(p);
|
||||
string_free(q);
|
||||
string_free(g);
|
||||
string_free(y);
|
||||
string_free(x);
|
||||
string_free(v);
|
||||
ssh_string_free(p);
|
||||
ssh_string_free(q);
|
||||
ssh_string_free(g);
|
||||
ssh_string_free(y);
|
||||
ssh_string_free(x);
|
||||
ssh_string_free(v);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -952,7 +952,7 @@ int ssh_publickey_to_file(ssh_session session, const char *file,
|
||||
size_t len;
|
||||
int rc;
|
||||
|
||||
pubkey_64 = bin_to_base64(pubkey->string, string_len(pubkey));
|
||||
pubkey_64 = bin_to_base64(pubkey->string, ssh_string_len(pubkey));
|
||||
if (pubkey_64 == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -1070,15 +1070,15 @@ ssh_string publickey_from_file(ssh_session session, const char *filename,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str = string_new(buffer_get_len(buffer));
|
||||
str = ssh_string_new(ssh_buffer_get_len(buffer));
|
||||
if (str == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string_fill(str, buffer_get(buffer), buffer_get_len(buffer));
|
||||
buffer_free(buffer);
|
||||
ssh_string_fill(str, ssh_buffer_get_begin(buffer), ssh_buffer_get_len(buffer));
|
||||
ssh_buffer_free(buffer);
|
||||
|
||||
if (type) {
|
||||
*type = key_type;
|
||||
@ -1215,7 +1215,7 @@ ssh_string try_publickey_from_file(ssh_session session, struct ssh_keys_struct k
|
||||
|
||||
new = realloc(*privkeyfile, strlen(priv) + 1);
|
||||
if (new == NULL) {
|
||||
string_free(pubkey);
|
||||
ssh_string_free(pubkey);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -1380,29 +1380,29 @@ static int check_public_key(ssh_session session, char **tokens) {
|
||||
unsigned int len;
|
||||
int i;
|
||||
|
||||
pubkey_buffer = buffer_new();
|
||||
pubkey_buffer = ssh_buffer_new();
|
||||
if (pubkey_buffer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmpstring = string_from_char("ssh-rsa1");
|
||||
tmpstring = ssh_string_from_char("ssh-rsa1");
|
||||
if (tmpstring == NULL) {
|
||||
buffer_free(pubkey_buffer);
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
|
||||
buffer_free(pubkey_buffer);
|
||||
string_free(tmpstring);
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
ssh_string_free(tmpstring);
|
||||
return -1;
|
||||
}
|
||||
string_free(tmpstring);
|
||||
ssh_string_free(tmpstring);
|
||||
|
||||
for (i = 2; i < 4; i++) { /* e, then n */
|
||||
tmpbn = NULL;
|
||||
bignum_dec2bn(tokens[i], &tmpbn);
|
||||
if (tmpbn == NULL) {
|
||||
buffer_free(pubkey_buffer);
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
return -1;
|
||||
}
|
||||
/* for some reason, make_bignum_string does not work
|
||||
@ -1412,7 +1412,7 @@ static int check_public_key(ssh_session session, char **tokens) {
|
||||
len = bignum_num_bytes(tmpbn);
|
||||
tmpstring = malloc(4 + len);
|
||||
if (tmpstring == NULL) {
|
||||
buffer_free(pubkey_buffer);
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
bignum_free(tmpbn);
|
||||
return -1;
|
||||
}
|
||||
@ -1425,12 +1425,12 @@ static int check_public_key(ssh_session session, char **tokens) {
|
||||
#endif
|
||||
bignum_free(tmpbn);
|
||||
if (buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
|
||||
buffer_free(pubkey_buffer);
|
||||
string_free(tmpstring);
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
ssh_string_free(tmpstring);
|
||||
bignum_free(tmpbn);
|
||||
return -1;
|
||||
}
|
||||
string_free(tmpstring);
|
||||
ssh_string_free(tmpstring);
|
||||
}
|
||||
} else {
|
||||
/* ssh-dss or ssh-rsa */
|
||||
@ -1444,19 +1444,19 @@ static int check_public_key(ssh_session session, char **tokens) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_get_len(pubkey_buffer) != string_len(pubkey)) {
|
||||
buffer_free(pubkey_buffer);
|
||||
if (ssh_buffer_get_len(pubkey_buffer) != ssh_string_len(pubkey)) {
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* now test that they are identical */
|
||||
if (memcmp(buffer_get(pubkey_buffer), pubkey->string,
|
||||
buffer_get_len(pubkey_buffer)) != 0) {
|
||||
buffer_free(pubkey_buffer);
|
||||
if (memcmp(ssh_buffer_get_begin(pubkey_buffer), pubkey->string,
|
||||
ssh_buffer_get_len(pubkey_buffer)) != 0) {
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer_free(pubkey_buffer);
|
||||
ssh_buffer_free(pubkey_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1519,15 +1519,15 @@ static int match_hashed_host(ssh_session session, const char *host,
|
||||
hash = base64_to_bin(b64hash);
|
||||
SAFE_FREE(source);
|
||||
if (hash == NULL) {
|
||||
buffer_free(salt);
|
||||
ssh_buffer_free(salt);
|
||||
leave_function();
|
||||
return 0;
|
||||
}
|
||||
|
||||
mac = hmac_init(buffer_get(salt), buffer_get_len(salt), HMAC_SHA1);
|
||||
mac = hmac_init(ssh_buffer_get_begin(salt), ssh_buffer_get_len(salt), HMAC_SHA1);
|
||||
if (mac == NULL) {
|
||||
buffer_free(salt);
|
||||
buffer_free(hash);
|
||||
ssh_buffer_free(salt);
|
||||
ssh_buffer_free(hash);
|
||||
leave_function();
|
||||
return 0;
|
||||
}
|
||||
@ -1535,15 +1535,15 @@ static int match_hashed_host(ssh_session session, const char *host,
|
||||
hmac_update(mac, host, strlen(host));
|
||||
hmac_final(mac, buffer, &size);
|
||||
|
||||
if (size == buffer_get_len(hash) &&
|
||||
memcmp(buffer, buffer_get(hash), size) == 0) {
|
||||
if (size == ssh_buffer_get_len(hash) &&
|
||||
memcmp(buffer, ssh_buffer_get_begin(hash), size) == 0) {
|
||||
match = 1;
|
||||
} else {
|
||||
match = 0;
|
||||
}
|
||||
|
||||
buffer_free(salt);
|
||||
buffer_free(hash);
|
||||
ssh_buffer_free(salt);
|
||||
ssh_buffer_free(hash);
|
||||
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"Matching a hashed host: %s match=%d", host, match);
|
||||
@ -1855,7 +1855,7 @@ int ssh_write_knownhost(ssh_session session) {
|
||||
|
||||
publickey_free(key);
|
||||
} else {
|
||||
pubkey_64 = bin_to_base64(pubkey->string, string_len(pubkey));
|
||||
pubkey_64 = bin_to_base64(pubkey->string, ssh_string_len(pubkey));
|
||||
if (pubkey_64 == NULL) {
|
||||
fclose(file);
|
||||
SAFE_FREE(host);
|
||||
|
444
libssh/keys.c
444
libssh/keys.c
@ -85,7 +85,7 @@ ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer) {
|
||||
|
||||
key = malloc(sizeof(struct ssh_public_key_struct));
|
||||
if (key == NULL) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer) {
|
||||
g = buffer_get_ssh_string(buffer);
|
||||
pubkey = buffer_get_ssh_string(buffer);
|
||||
|
||||
buffer_free(buffer); /* we don't need it anymore */
|
||||
ssh_buffer_free(buffer); /* we don't need it anymore */
|
||||
|
||||
if (p == NULL || q == NULL || g == NULL || pubkey == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Invalid DSA public key");
|
||||
@ -107,10 +107,10 @@ ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer) {
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_build(&key->dsa_pub, NULL,
|
||||
"(public-key(dsa(p %b)(q %b)(g %b)(y %b)))",
|
||||
string_len(p), string_data(p),
|
||||
string_len(q), string_data(q),
|
||||
string_len(g), string_data(g),
|
||||
string_len(pubkey), string_data(pubkey));
|
||||
ssh_string_len(p), ssh_string_data(p),
|
||||
ssh_string_len(q), ssh_string_data(q),
|
||||
ssh_string_len(g), ssh_string_data(g),
|
||||
ssh_string_len(pubkey), ssh_string_data(pubkey));
|
||||
if (key->dsa_pub == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -133,30 +133,30 @@ ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer) {
|
||||
#endif /* HAVE_LIBCRYPTO */
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("p", string_data(p), string_len(p));
|
||||
ssh_print_hexa("q", string_data(q), string_len(q));
|
||||
ssh_print_hexa("g", string_data(g), string_len(g));
|
||||
ssh_print_hexa("p", ssh_string_data(p), ssh_string_len(p));
|
||||
ssh_print_hexa("q", ssh_string_data(q), ssh_string_len(q));
|
||||
ssh_print_hexa("g", ssh_string_data(g), ssh_string_len(g));
|
||||
#endif
|
||||
|
||||
string_burn(p);
|
||||
string_free(p);
|
||||
string_burn(q);
|
||||
string_free(q);
|
||||
string_burn(g);
|
||||
string_free(g);
|
||||
string_burn(pubkey);
|
||||
string_free(pubkey);
|
||||
ssh_string_burn(p);
|
||||
ssh_string_free(p);
|
||||
ssh_string_burn(q);
|
||||
ssh_string_free(q);
|
||||
ssh_string_burn(g);
|
||||
ssh_string_free(g);
|
||||
ssh_string_burn(pubkey);
|
||||
ssh_string_free(pubkey);
|
||||
|
||||
return key;
|
||||
error:
|
||||
string_burn(p);
|
||||
string_free(p);
|
||||
string_burn(q);
|
||||
string_free(q);
|
||||
string_burn(g);
|
||||
string_free(g);
|
||||
string_burn(pubkey);
|
||||
string_free(pubkey);
|
||||
ssh_string_burn(p);
|
||||
ssh_string_free(p);
|
||||
ssh_string_burn(q);
|
||||
ssh_string_free(q);
|
||||
ssh_string_burn(g);
|
||||
ssh_string_free(g);
|
||||
ssh_string_burn(pubkey);
|
||||
ssh_string_free(pubkey);
|
||||
publickey_free(key);
|
||||
|
||||
return NULL;
|
||||
@ -170,7 +170,7 @@ ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer,
|
||||
|
||||
key = malloc(sizeof(struct ssh_public_key_struct));
|
||||
if (key == NULL) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer,
|
||||
e = buffer_get_ssh_string(buffer);
|
||||
n = buffer_get_ssh_string(buffer);
|
||||
|
||||
buffer_free(buffer); /* we don't need it anymore */
|
||||
ssh_buffer_free(buffer); /* we don't need it anymore */
|
||||
|
||||
if(e == NULL || n == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Invalid RSA public key");
|
||||
@ -189,8 +189,8 @@ ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer,
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_build(&key->rsa_pub, NULL,
|
||||
"(public-key(rsa(n %b)(e %b)))",
|
||||
string_len(n), string_data(n),
|
||||
string_len(e),string_data(e));
|
||||
ssh_string_len(n), ssh_string_data(n),
|
||||
ssh_string_len(e),ssh_string_data(e));
|
||||
if (key->rsa_pub == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -209,21 +209,21 @@ ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer,
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("e", string_data(e), string_len(e));
|
||||
ssh_print_hexa("n", string_data(n), string_len(n));
|
||||
ssh_print_hexa("e", ssh_string_data(e), ssh_string_len(e));
|
||||
ssh_print_hexa("n", ssh_string_data(n), ssh_string_len(n));
|
||||
#endif
|
||||
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
string_burn(n);
|
||||
string_free(n);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
ssh_string_burn(n);
|
||||
ssh_string_free(n);
|
||||
|
||||
return key;
|
||||
error:
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
string_burn(n);
|
||||
string_free(n);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
ssh_string_burn(n);
|
||||
ssh_string_free(n);
|
||||
publickey_free(key);
|
||||
|
||||
return NULL;
|
||||
@ -262,12 +262,12 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
|
||||
char *type_c = NULL;
|
||||
int type;
|
||||
|
||||
tmpbuf = buffer_new();
|
||||
tmpbuf = ssh_buffer_new();
|
||||
if (tmpbuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buffer_add_data(tmpbuf, string_data(pubkey_s), string_len(pubkey_s)) < 0) {
|
||||
if (buffer_add_data(tmpbuf, ssh_string_data(pubkey_s), ssh_string_len(pubkey_s)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -277,8 +277,8 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
type_c = string_to_char(type_s);
|
||||
string_free(type_s);
|
||||
type_c = ssh_string_to_char(type_s);
|
||||
ssh_string_free(type_s);
|
||||
if (type_c == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -298,7 +298,7 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
|
||||
ssh_type_to_char(type));
|
||||
|
||||
error:
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -339,11 +339,11 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
p = string_new(size);
|
||||
p = ssh_string_new(size);
|
||||
if (p == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(p,(char *) tmp, size);
|
||||
ssh_string_fill(p,(char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(prv->dsa_priv,"q",0);
|
||||
@ -351,11 +351,11 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp,1,&size);
|
||||
q = string_new(size);
|
||||
q = ssh_string_new(size);
|
||||
if (q == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(q,(char *) tmp,size);
|
||||
ssh_string_fill(q,(char *) tmp,size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(prv->dsa_priv, "g", 0);
|
||||
@ -363,11 +363,11 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp,1,&size);
|
||||
g = string_new(size);
|
||||
g = ssh_string_new(size);
|
||||
if (g == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(g,(char *) tmp,size);
|
||||
ssh_string_fill(g,(char *) tmp,size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(prv->dsa_priv,"y",0);
|
||||
@ -375,28 +375,28 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp,1,&size);
|
||||
y = string_new(size);
|
||||
y = ssh_string_new(size);
|
||||
if (y == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(y,(char *) tmp,size);
|
||||
ssh_string_fill(y,(char *) tmp,size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
gcry_sexp_build(&key->dsa_pub, NULL,
|
||||
"(public-key(dsa(p %b)(q %b)(g %b)(y %b)))",
|
||||
string_len(p), string_data(p),
|
||||
string_len(q), string_data(q),
|
||||
string_len(g), string_data(g),
|
||||
string_len(y), string_data(y));
|
||||
ssh_string_len(p), ssh_string_data(p),
|
||||
ssh_string_len(q), ssh_string_data(q),
|
||||
ssh_string_len(g), ssh_string_data(g),
|
||||
ssh_string_len(y), ssh_string_data(y));
|
||||
|
||||
string_burn(p);
|
||||
string_free(p);
|
||||
string_burn(q);
|
||||
string_free(q);
|
||||
string_burn(g);
|
||||
string_free(g);
|
||||
string_burn(y);
|
||||
string_free(y);
|
||||
ssh_string_burn(p);
|
||||
ssh_string_free(p);
|
||||
ssh_string_burn(q);
|
||||
ssh_string_free(q);
|
||||
ssh_string_burn(g);
|
||||
ssh_string_free(g);
|
||||
ssh_string_burn(y);
|
||||
ssh_string_free(y);
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
key->dsa_pub = DSA_new();
|
||||
if (key->dsa_pub == NULL) {
|
||||
@ -422,11 +422,11 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
n = string_new(size);
|
||||
n = ssh_string_new(size);
|
||||
if (n == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(n, (char *) tmp, size);
|
||||
ssh_string_fill(n, (char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(prv->rsa_priv, "e", 0);
|
||||
@ -434,25 +434,25 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
e = string_new(size);
|
||||
e = ssh_string_new(size);
|
||||
if (e == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(e, (char *) tmp, size);
|
||||
ssh_string_fill(e, (char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
gcry_sexp_build(&key->rsa_pub, NULL,
|
||||
"(public-key(rsa(n %b)(e %b)))",
|
||||
string_len(n), string_data(n),
|
||||
string_len(e), string_data(e));
|
||||
ssh_string_len(n), ssh_string_data(n),
|
||||
ssh_string_len(e), ssh_string_data(e));
|
||||
if (key->rsa_pub == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
string_burn(n);
|
||||
string_free(n);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
ssh_string_burn(n);
|
||||
ssh_string_free(n);
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
key->rsa_pub = RSA_new();
|
||||
if (key->rsa_pub == NULL) {
|
||||
@ -473,19 +473,19 @@ ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
|
||||
error:
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
gcry_sexp_release(sexp);
|
||||
string_burn(p);
|
||||
string_free(p);
|
||||
string_burn(q);
|
||||
string_free(q);
|
||||
string_burn(g);
|
||||
string_free(g);
|
||||
string_burn(y);
|
||||
string_free(y);
|
||||
ssh_string_burn(p);
|
||||
ssh_string_free(p);
|
||||
ssh_string_burn(q);
|
||||
ssh_string_free(q);
|
||||
ssh_string_burn(g);
|
||||
ssh_string_free(g);
|
||||
ssh_string_burn(y);
|
||||
ssh_string_free(y);
|
||||
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
string_burn(n);
|
||||
string_free(n);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
ssh_string_burn(n);
|
||||
ssh_string_free(n);
|
||||
#endif
|
||||
publickey_free(key);
|
||||
|
||||
@ -514,11 +514,11 @@ static int dsa_public_to_string(DSA *key, ssh_buffer buffer) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
p = string_new(size);
|
||||
p = ssh_string_new(size);
|
||||
if (p == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(p, (char *) tmp, size);
|
||||
ssh_string_fill(p, (char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(key, "q", 0);
|
||||
@ -526,11 +526,11 @@ static int dsa_public_to_string(DSA *key, ssh_buffer buffer) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
q = string_new(size);
|
||||
q = ssh_string_new(size);
|
||||
if (q == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(q, (char *) tmp, size);
|
||||
ssh_string_fill(q, (char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(key, "g", 0);
|
||||
@ -538,11 +538,11 @@ static int dsa_public_to_string(DSA *key, ssh_buffer buffer) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
g = string_new(size);
|
||||
g = ssh_string_new(size);
|
||||
if (g == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(g, (char *) tmp, size);
|
||||
ssh_string_fill(g, (char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(key, "y", 0);
|
||||
@ -550,11 +550,11 @@ static int dsa_public_to_string(DSA *key, ssh_buffer buffer) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
n = string_new(size);
|
||||
n = ssh_string_new(size);
|
||||
if (n == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(n, (char *) tmp, size);
|
||||
ssh_string_fill(n, (char *) tmp, size);
|
||||
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
p = make_bignum_string(key->p);
|
||||
@ -584,14 +584,14 @@ error:
|
||||
gcry_sexp_release(sexp);
|
||||
#endif
|
||||
|
||||
string_burn(p);
|
||||
string_free(p);
|
||||
string_burn(q);
|
||||
string_free(q);
|
||||
string_burn(g);
|
||||
string_free(g);
|
||||
string_burn(n);
|
||||
string_free(n);
|
||||
ssh_string_burn(p);
|
||||
ssh_string_free(p);
|
||||
ssh_string_burn(q);
|
||||
ssh_string_free(q);
|
||||
ssh_string_burn(g);
|
||||
ssh_string_free(g);
|
||||
ssh_string_burn(n);
|
||||
ssh_string_free(n);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -617,11 +617,11 @@ static int rsa_public_to_string(RSA *key, ssh_buffer buffer) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
n = string_new(size);
|
||||
n = ssh_string_new(size);
|
||||
if (n == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(n, (char *) tmp, size);
|
||||
ssh_string_fill(n, (char *) tmp, size);
|
||||
gcry_sexp_release(sexp);
|
||||
|
||||
sexp = gcry_sexp_find_token(key, "e", 0);
|
||||
@ -629,11 +629,11 @@ static int rsa_public_to_string(RSA *key, ssh_buffer buffer) {
|
||||
goto error;
|
||||
}
|
||||
tmp = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
e = string_new(size);
|
||||
e = ssh_string_new(size);
|
||||
if (e == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_fill(e, (char *) tmp, size);
|
||||
ssh_string_fill(e, (char *) tmp, size);
|
||||
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
e = make_bignum_string(key->e);
|
||||
@ -656,10 +656,10 @@ error:
|
||||
gcry_sexp_release(sexp);
|
||||
#endif
|
||||
|
||||
string_burn(e);
|
||||
string_free(e);
|
||||
string_burn(n);
|
||||
string_free(n);
|
||||
ssh_string_burn(e);
|
||||
ssh_string_free(e);
|
||||
ssh_string_burn(n);
|
||||
ssh_string_free(n);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -679,12 +679,12 @@ ssh_string publickey_to_string(ssh_public_key key) {
|
||||
ssh_string ret = NULL;
|
||||
ssh_buffer buf = NULL;
|
||||
|
||||
buf = buffer_new();
|
||||
buf = ssh_buffer_new();
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type = string_from_char(key->type_c);
|
||||
type = ssh_string_from_char(key->type_c);
|
||||
if (type == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -707,15 +707,15 @@ ssh_string publickey_to_string(ssh_public_key key) {
|
||||
break;
|
||||
}
|
||||
|
||||
ret = string_new(buffer_get_len(buf));
|
||||
ret = ssh_string_new(ssh_buffer_get_len(buf));
|
||||
if (ret == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
string_fill(ret, buffer_get(buf), buffer_get_len(buf));
|
||||
ssh_string_fill(ret, ssh_buffer_get_begin(buf), ssh_buffer_get_len(buf));
|
||||
error:
|
||||
buffer_free(buf);
|
||||
string_free(type);
|
||||
ssh_buffer_free(buf);
|
||||
ssh_string_free(type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -738,29 +738,29 @@ static ssh_string signature_to_string(SIGNATURE *sign) {
|
||||
ssh_string s = NULL;
|
||||
#endif
|
||||
|
||||
tmpbuf = buffer_new();
|
||||
tmpbuf = ssh_buffer_new();
|
||||
if (tmpbuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmp = string_from_char(ssh_type_to_char(sign->type));
|
||||
tmp = ssh_string_from_char(ssh_type_to_char(sign->type));
|
||||
if (tmp == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
if (buffer_add_ssh_string(tmpbuf, tmp) < 0) {
|
||||
buffer_free(tmpbuf);
|
||||
string_free(tmp);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
ssh_string_free(tmp);
|
||||
return NULL;
|
||||
}
|
||||
string_free(tmp);
|
||||
ssh_string_free(tmp);
|
||||
|
||||
switch(sign->type) {
|
||||
case SSH_KEYTYPE_DSS:
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
sexp = gcry_sexp_find_token(sign->dsa_sign, "r", 0);
|
||||
if (sexp == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
r = gcry_sexp_nth_data(sexp, 1, &size);
|
||||
@ -773,7 +773,7 @@ static ssh_string signature_to_string(SIGNATURE *sign) {
|
||||
|
||||
sexp = gcry_sexp_find_token(sign->dsa_sign, "s", 0);
|
||||
if (sexp == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
s = gcry_sexp_nth_data(sexp,1,&size);
|
||||
@ -786,33 +786,33 @@ static ssh_string signature_to_string(SIGNATURE *sign) {
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
r = make_bignum_string(sign->dsa_sign->r);
|
||||
if (r == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
s = make_bignum_string(sign->dsa_sign->s);
|
||||
if (s == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
string_free(r);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
ssh_string_free(r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(buffer, (char *)string_data(r) + string_len(r) - 20, 20);
|
||||
memcpy(buffer + 20, (char *)string_data(s) + string_len(s) - 20, 20);
|
||||
memcpy(buffer, (char *)ssh_string_data(r) + ssh_string_len(r) - 20, 20);
|
||||
memcpy(buffer + 20, (char *)ssh_string_data(s) + ssh_string_len(s) - 20, 20);
|
||||
|
||||
string_free(r);
|
||||
string_free(s);
|
||||
ssh_string_free(r);
|
||||
ssh_string_free(s);
|
||||
#endif /* HAVE_LIBCRYPTO */
|
||||
rs = string_new(40);
|
||||
rs = ssh_string_new(40);
|
||||
if (rs == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string_fill(rs, buffer, 40);
|
||||
ssh_string_fill(rs, buffer, 40);
|
||||
rc = buffer_add_ssh_string(tmpbuf, rs);
|
||||
string_free(rs);
|
||||
ssh_string_free(rs);
|
||||
if (rc < 0) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -822,7 +822,7 @@ static ssh_string signature_to_string(SIGNATURE *sign) {
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
sexp = gcry_sexp_find_token(sign->rsa_sign, "s", 0);
|
||||
if (sexp == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
s = gcry_sexp_nth_data(sexp,1,&size);
|
||||
@ -830,36 +830,36 @@ static ssh_string signature_to_string(SIGNATURE *sign) {
|
||||
size--;
|
||||
s++;
|
||||
}
|
||||
rs = string_new(size);
|
||||
rs = ssh_string_new(size);
|
||||
if (rs == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string_fill(rs, (char *) s, size);
|
||||
ssh_string_fill(rs, (char *) s, size);
|
||||
rc = buffer_add_ssh_string(tmpbuf, rs);
|
||||
gcry_sexp_release(sexp);
|
||||
string_free(rs);
|
||||
ssh_string_free(rs);
|
||||
if (rc < 0) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
if (buffer_add_ssh_string(tmpbuf,sign->rsa_sign) < 0) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
str = string_new(buffer_get_len(tmpbuf));
|
||||
str = ssh_string_new(ssh_buffer_get_len(tmpbuf));
|
||||
if (str == NULL) {
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
string_fill(str, buffer_get(tmpbuf), buffer_get_len(tmpbuf));
|
||||
buffer_free(tmpbuf);
|
||||
ssh_string_fill(str, ssh_buffer_get_begin(tmpbuf), ssh_buffer_get_len(tmpbuf));
|
||||
ssh_buffer_free(tmpbuf);
|
||||
|
||||
return str;
|
||||
}
|
||||
@ -890,16 +890,16 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmpbuf = buffer_new();
|
||||
tmpbuf = ssh_buffer_new();
|
||||
if (tmpbuf == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buffer_add_data(tmpbuf, string_data(signature), string_len(signature)) < 0) {
|
||||
if (buffer_add_data(tmpbuf, ssh_string_data(signature), ssh_string_len(signature)) < 0) {
|
||||
signature_free(sign);
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -907,15 +907,15 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
if (type_s == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Invalid signature packet");
|
||||
signature_free(sign);
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type_c = string_to_char(type_s);
|
||||
string_free(type_s);
|
||||
type_c = ssh_string_to_char(type_s);
|
||||
ssh_string_free(type_s);
|
||||
if (type_c == NULL) {
|
||||
signature_free(sign);
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
type = ssh_type_from_name(type_c);
|
||||
@ -925,18 +925,18 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
ssh_set_error(session, SSH_FATAL, "Invalid signature type: %s",
|
||||
ssh_type_to_char(type));
|
||||
signature_free(sign);
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch(needed_type) {
|
||||
case SSH_KEYTYPE_DSS:
|
||||
rs = buffer_get_ssh_string(tmpbuf);
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
|
||||
/* 40 is the dual signature blob len. */
|
||||
if (rs == NULL || string_len(rs) != 40) {
|
||||
string_free(rs);
|
||||
if (rs == NULL || ssh_string_len(rs) != 40) {
|
||||
ssh_string_free(rs);
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
}
|
||||
@ -945,40 +945,40 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
* them to bignums (ou pas ;) */
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
if (gcry_sexp_build(&sig, NULL, "(sig-val(dsa(r %b)(s %b)))",
|
||||
20 ,string_data(rs), 20,(unsigned char *)string_data(rs) + 20)) {
|
||||
string_free(rs);
|
||||
20 ,ssh_string_data(rs), 20,(unsigned char *)ssh_string_data(rs) + 20)) {
|
||||
ssh_string_free(rs);
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
}
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
r = string_new(20);
|
||||
s = string_new(20);
|
||||
r = ssh_string_new(20);
|
||||
s = ssh_string_new(20);
|
||||
if (r == NULL || s == NULL) {
|
||||
string_free(r);
|
||||
string_free(s);
|
||||
string_free(rs);
|
||||
ssh_string_free(r);
|
||||
ssh_string_free(s);
|
||||
ssh_string_free(rs);
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string_fill(r, string_data(rs), 20);
|
||||
string_fill(s, (char *)string_data(rs) + 20, 20);
|
||||
ssh_string_fill(r, ssh_string_data(rs), 20);
|
||||
ssh_string_fill(s, (char *)ssh_string_data(rs) + 20, 20);
|
||||
|
||||
sig = DSA_SIG_new();
|
||||
if (sig == NULL) {
|
||||
string_free(r);
|
||||
string_free(s);
|
||||
string_free(rs);
|
||||
ssh_string_free(r);
|
||||
ssh_string_free(s);
|
||||
ssh_string_free(rs);
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
}
|
||||
sig->r = make_string_bn(r); /* is that really portable ? Openssh's hack isn't better */
|
||||
sig->s = make_string_bn(s);
|
||||
string_free(r);
|
||||
string_free(s);
|
||||
ssh_string_free(r);
|
||||
ssh_string_free(s);
|
||||
|
||||
if (sig->r == NULL || sig->s == NULL) {
|
||||
string_free(rs);
|
||||
ssh_string_free(rs);
|
||||
DSA_SIG_free(sig);
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
@ -986,10 +986,10 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("r", string_data(rs), 20);
|
||||
ssh_print_hexa("s", (const unsigned char *)string_data(rs) + 20, 20);
|
||||
ssh_print_hexa("r", ssh_string_data(rs), 20);
|
||||
ssh_print_hexa("s", (const unsigned char *)ssh_string_data(rs) + 20, 20);
|
||||
#endif
|
||||
string_free(rs);
|
||||
ssh_string_free(rs);
|
||||
|
||||
sign->type = SSH_KEYTYPE_DSS;
|
||||
sign->dsa_sign = sig;
|
||||
@ -997,19 +997,19 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
return sign;
|
||||
case SSH_KEYTYPE_RSA:
|
||||
e = buffer_get_ssh_string(tmpbuf);
|
||||
buffer_free(tmpbuf);
|
||||
ssh_buffer_free(tmpbuf);
|
||||
if (e == NULL) {
|
||||
signature_free(sign);
|
||||
return NULL;
|
||||
}
|
||||
len = string_len(e);
|
||||
len = ssh_string_len(e);
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
rsalen = (gcry_pk_get_nbits(pubkey->rsa_pub) + 7) / 8;
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
rsalen = RSA_size(pubkey->rsa_pub);
|
||||
#endif
|
||||
if (len > rsalen) {
|
||||
string_free(e);
|
||||
ssh_string_free(e);
|
||||
signature_free(sign);
|
||||
ssh_set_error(session, SSH_FATAL, "Signature too big! %d instead of %d",
|
||||
len, rsalen);
|
||||
@ -1023,9 +1023,9 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
sign->type = SSH_KEYTYPE_RSA;
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
if (gcry_sexp_build(&sig, NULL, "(sig-val(rsa(s %b)))",
|
||||
string_len(e), string_data(e))) {
|
||||
ssh_string_len(e), ssh_string_data(e))) {
|
||||
signature_free(sign);
|
||||
string_free(e);
|
||||
ssh_string_free(e);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1036,11 +1036,11 @@ SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_log(session, SSH_LOG_FUNCTIONS, "len e: %d", len);
|
||||
ssh_print_hexa("RSA signature", string_data(e), len);
|
||||
ssh_print_hexa("RSA signature", ssh_string_data(e), len);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
string_free(e);
|
||||
ssh_string_free(e);
|
||||
#endif
|
||||
|
||||
return sign;
|
||||
@ -1104,13 +1104,13 @@ static ssh_string RSA_do_sign(const unsigned char *payload, int len, RSA *privke
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sign = string_new(size);
|
||||
sign = ssh_string_new(size);
|
||||
if (sign == NULL) {
|
||||
SAFE_FREE(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string_fill(sign, buffer, size);
|
||||
ssh_string_fill(sign, buffer, size);
|
||||
SAFE_FREE(buffer);
|
||||
|
||||
return sign;
|
||||
@ -1132,35 +1132,35 @@ ssh_string ssh_do_sign_with_agent(ssh_session session,
|
||||
}
|
||||
|
||||
/* prepend session identifier */
|
||||
session_id = string_new(SHA_DIGEST_LEN);
|
||||
session_id = ssh_string_new(SHA_DIGEST_LEN);
|
||||
if (session_id == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
string_fill(session_id, crypto->session_id, SHA_DIGEST_LEN);
|
||||
ssh_string_fill(session_id, crypto->session_id, SHA_DIGEST_LEN);
|
||||
|
||||
sigbuf = buffer_new();
|
||||
sigbuf = ssh_buffer_new();
|
||||
if (sigbuf == NULL) {
|
||||
string_free(session_id);
|
||||
ssh_string_free(session_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buffer_add_ssh_string(sigbuf, session_id) < 0) {
|
||||
buffer_free(sigbuf);
|
||||
string_free(session_id);
|
||||
ssh_buffer_free(sigbuf);
|
||||
ssh_string_free(session_id);
|
||||
return NULL;
|
||||
}
|
||||
string_free(session_id);
|
||||
ssh_string_free(session_id);
|
||||
|
||||
/* append out buffer */
|
||||
if (buffer_add_buffer(sigbuf, buf) < 0) {
|
||||
buffer_free(sigbuf);
|
||||
ssh_buffer_free(sigbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create signature */
|
||||
signature = agent_sign_data(session, sigbuf, publickey);
|
||||
|
||||
buffer_free(sigbuf);
|
||||
ssh_buffer_free(sigbuf);
|
||||
|
||||
return signature;
|
||||
}
|
||||
@ -1188,24 +1188,24 @@ ssh_buffer ssh_userauth_build_digest(ssh_session session, ssh_message msg, char
|
||||
ssh_buffer buffer = NULL;
|
||||
ssh_string session_id = NULL;
|
||||
uint8_t type = SSH2_MSG_USERAUTH_REQUEST;
|
||||
ssh_string username = string_from_char(msg->auth_request.username);
|
||||
ssh_string servicename = string_from_char(service);
|
||||
ssh_string method = string_from_char("publickey");
|
||||
ssh_string username = ssh_string_from_char(msg->auth_request.username);
|
||||
ssh_string servicename = ssh_string_from_char(service);
|
||||
ssh_string method = ssh_string_from_char("publickey");
|
||||
uint8_t has_sign = 1;
|
||||
ssh_string algo = string_from_char(msg->auth_request.public_key->type_c);
|
||||
ssh_string algo = ssh_string_from_char(msg->auth_request.public_key->type_c);
|
||||
ssh_string publickey = publickey_to_string(msg->auth_request.public_key);
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
session_id = string_new(SHA_DIGEST_LEN);
|
||||
session_id = ssh_string_new(SHA_DIGEST_LEN);
|
||||
if (session_id == NULL) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
buffer = NULL;
|
||||
goto error;
|
||||
}
|
||||
string_fill(session_id, crypto->session_id, SHA_DIGEST_LEN);
|
||||
ssh_string_fill(session_id, crypto->session_id, SHA_DIGEST_LEN);
|
||||
|
||||
if(buffer_add_ssh_string(buffer, session_id) < 0 ||
|
||||
buffer_add_u8(buffer, type) < 0 ||
|
||||
@ -1215,18 +1215,18 @@ ssh_buffer ssh_userauth_build_digest(ssh_session session, ssh_message msg, char
|
||||
buffer_add_u8(buffer, has_sign) < 0 ||
|
||||
buffer_add_ssh_string(buffer, algo) < 0 ||
|
||||
buffer_add_ssh_string(buffer, publickey) < 0) {
|
||||
buffer_free(buffer);
|
||||
ssh_buffer_free(buffer);
|
||||
buffer = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
error:
|
||||
if(session_id) string_free(session_id);
|
||||
if(username) string_free(username);
|
||||
if(servicename) string_free(servicename);
|
||||
if(method) string_free(method);
|
||||
if(algo) string_free(algo);
|
||||
if(publickey) string_free(publickey);
|
||||
if(session_id) ssh_string_free(session_id);
|
||||
if(username) ssh_string_free(username);
|
||||
if(servicename) ssh_string_free(servicename);
|
||||
if(method) ssh_string_free(method);
|
||||
if(algo) ssh_string_free(algo);
|
||||
if(publickey) ssh_string_free(publickey);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -1246,21 +1246,21 @@ ssh_string ssh_do_sign(ssh_session session, ssh_buffer sigbuf,
|
||||
gcry_sexp_t gcryhash;
|
||||
#endif
|
||||
|
||||
session_str = string_new(SHA_DIGEST_LEN);
|
||||
session_str = ssh_string_new(SHA_DIGEST_LEN);
|
||||
if (session_str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
string_fill(session_str, crypto->session_id, SHA_DIGEST_LEN);
|
||||
ssh_string_fill(session_str, crypto->session_id, SHA_DIGEST_LEN);
|
||||
|
||||
ctx = sha1_init();
|
||||
if (ctx == NULL) {
|
||||
string_free(session_str);
|
||||
ssh_string_free(session_str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sha1_update(ctx, session_str, string_len(session_str) + 4);
|
||||
string_free(session_str);
|
||||
sha1_update(ctx, buffer_get(sigbuf), buffer_get_len(sigbuf));
|
||||
sha1_update(ctx, session_str, ssh_string_len(session_str) + 4);
|
||||
ssh_string_free(session_str);
|
||||
sha1_update(ctx, ssh_buffer_get_begin(sigbuf), ssh_buffer_get_len(sigbuf));
|
||||
sha1_final(hash + 1,ctx);
|
||||
hash[0] = 0;
|
||||
|
||||
@ -1336,7 +1336,7 @@ ssh_string ssh_do_sign(ssh_session session, ssh_buffer sigbuf,
|
||||
|
||||
ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key key) {
|
||||
ssh_string str = NULL;
|
||||
size_t len = string_len(data);
|
||||
size_t len = ssh_string_len(data);
|
||||
size_t size = 0;
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
const char *tmp = NULL;
|
||||
@ -1344,7 +1344,7 @@ ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key
|
||||
gcry_sexp_t data_sexp;
|
||||
|
||||
if (gcry_sexp_build(&data_sexp, NULL, "(data(flags pkcs1)(value %b))",
|
||||
len, string_data(data))) {
|
||||
len, ssh_string_data(data))) {
|
||||
ssh_set_error(session, SSH_FATAL, "RSA1 encrypt: libgcrypt error");
|
||||
return NULL;
|
||||
}
|
||||
@ -1368,29 +1368,29 @@ ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key
|
||||
tmp++;
|
||||
}
|
||||
|
||||
str = string_new(size);
|
||||
str = ssh_string_new(size);
|
||||
if (str == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
gcry_sexp_release(data_sexp);
|
||||
gcry_sexp_release(ret_sexp);
|
||||
return NULL;
|
||||
}
|
||||
string_fill(str, tmp, size);
|
||||
ssh_string_fill(str, tmp, size);
|
||||
|
||||
gcry_sexp_release(data_sexp);
|
||||
gcry_sexp_release(ret_sexp);
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
size = RSA_size(key->rsa_pub);
|
||||
|
||||
str = string_new(size);
|
||||
str = ssh_string_new(size);
|
||||
if (str == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (RSA_public_encrypt(len, string_data(data), string_data(str), key->rsa_pub,
|
||||
if (RSA_public_encrypt(len, ssh_string_data(data), ssh_string_data(str), key->rsa_pub,
|
||||
RSA_PKCS1_PADDING) < 0) {
|
||||
string_free(str);
|
||||
ssh_string_free(str);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
233
libssh/legacy.c
Обычный файл
233
libssh/legacy.c
Обычный файл
@ -0,0 +1,233 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2010 by Aris Adamantiadis
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/** functions in that file are wrappers to the newly named functions. All
|
||||
* of them are depreciated, but these wrapper will avoid breaking backward
|
||||
* compatibility
|
||||
*/
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include <libssh/buffer.h>
|
||||
|
||||
void buffer_free(ssh_buffer buffer){
|
||||
ssh_buffer_free(buffer);
|
||||
}
|
||||
void *buffer_get(ssh_buffer buffer){
|
||||
return ssh_buffer_get_begin(buffer);
|
||||
}
|
||||
uint32_t buffer_get_len(ssh_buffer buffer){
|
||||
return ssh_buffer_get_len(buffer);
|
||||
}
|
||||
ssh_buffer buffer_new(void){
|
||||
return ssh_buffer_new();
|
||||
}
|
||||
|
||||
ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms){
|
||||
return ssh_channel_accept_x11(channel, timeout_ms);
|
||||
}
|
||||
|
||||
int channel_change_pty_size(ssh_channel channel,int cols,int rows){
|
||||
return ssh_channel_change_pty_size(channel,cols,rows);
|
||||
}
|
||||
|
||||
ssh_channel channel_forward_accept(ssh_session session, int timeout_ms){
|
||||
return ssh_channel_forward_accept(session,timeout_ms);
|
||||
}
|
||||
|
||||
int channel_close(ssh_channel channel){
|
||||
return ssh_channel_close(channel);
|
||||
}
|
||||
|
||||
int channel_forward_cancel(ssh_session session, const char *address, int port){
|
||||
return ssh_channel_forward_cancel(session, address, port);
|
||||
}
|
||||
|
||||
int channel_forward_listen(ssh_session session, const char *address,
|
||||
int port, int *bound_port){
|
||||
return ssh_channel_forward_listen(session, address, port, bound_port);
|
||||
}
|
||||
|
||||
void channel_free(ssh_channel channel){
|
||||
ssh_channel_free(channel);
|
||||
}
|
||||
|
||||
int channel_get_exit_status(ssh_channel channel){
|
||||
return ssh_channel_get_exit_status(channel);
|
||||
}
|
||||
|
||||
ssh_session channel_get_session(ssh_channel channel){
|
||||
return ssh_channel_get_session(channel);
|
||||
}
|
||||
|
||||
int channel_is_closed(ssh_channel channel){
|
||||
return ssh_channel_is_closed(channel);
|
||||
}
|
||||
|
||||
int channel_is_eof(ssh_channel channel){
|
||||
return ssh_channel_is_eof(channel);
|
||||
}
|
||||
|
||||
int channel_is_open(ssh_channel channel){
|
||||
return ssh_channel_is_open(channel);
|
||||
}
|
||||
|
||||
ssh_channel channel_new(ssh_session session){
|
||||
return ssh_channel_new(session);
|
||||
}
|
||||
|
||||
int channel_open_forward(ssh_channel channel, const char *remotehost,
|
||||
int remoteport, const char *sourcehost, int localport){
|
||||
return ssh_channel_open_forward(channel, remotehost, remoteport,
|
||||
sourcehost,localport);
|
||||
}
|
||||
|
||||
int channel_open_session(ssh_channel channel){
|
||||
return ssh_channel_open_session(channel);
|
||||
}
|
||||
|
||||
int channel_poll(ssh_channel channel, int is_stderr){
|
||||
return ssh_channel_poll(channel, is_stderr);
|
||||
}
|
||||
|
||||
int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr){
|
||||
return ssh_channel_read(channel, dest, count, is_stderr);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will completely be depreciated. The old implementation was not
|
||||
* renamed.
|
||||
* int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||
* int is_stderr);
|
||||
*/
|
||||
|
||||
int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||
int is_stderr){
|
||||
return ssh_channel_read_nonblocking(channel, dest, count, is_stderr);
|
||||
}
|
||||
|
||||
int channel_request_env(ssh_channel channel, const char *name, const char *value){
|
||||
return ssh_channel_request_env(channel, name, value);
|
||||
}
|
||||
|
||||
int channel_request_exec(ssh_channel channel, const char *cmd){
|
||||
return ssh_channel_request_exec(channel, cmd);
|
||||
}
|
||||
|
||||
int channel_request_pty(ssh_channel channel){
|
||||
return ssh_channel_request_pty(channel);
|
||||
}
|
||||
|
||||
int channel_request_pty_size(ssh_channel channel, const char *term,
|
||||
int cols, int rows){
|
||||
return ssh_channel_request_pty_size(channel, term, cols, rows);
|
||||
}
|
||||
|
||||
int channel_request_shell(ssh_channel channel){
|
||||
return ssh_channel_request_shell(channel);
|
||||
}
|
||||
|
||||
int channel_request_send_signal(ssh_channel channel, const char *signum){
|
||||
return ssh_channel_request_send_signal(channel, signum);
|
||||
}
|
||||
|
||||
int channel_request_sftp(ssh_channel channel){
|
||||
return ssh_channel_request_sftp(channel);
|
||||
}
|
||||
|
||||
int channel_request_subsystem(ssh_channel channel, const char *subsystem){
|
||||
return ssh_channel_request_subsystem(channel, subsystem);
|
||||
}
|
||||
|
||||
int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
|
||||
const char *cookie, int screen_number){
|
||||
return ssh_channel_request_x11(channel, single_connection, protocol, cookie,
|
||||
screen_number);
|
||||
}
|
||||
|
||||
int channel_send_eof(ssh_channel channel){
|
||||
return ssh_channel_send_eof(channel);
|
||||
}
|
||||
|
||||
int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
|
||||
timeval * timeout){
|
||||
return ssh_channel_select(readchans, writechans, exceptchans, timeout);
|
||||
}
|
||||
|
||||
void channel_set_blocking(ssh_channel channel, int blocking){
|
||||
ssh_channel_set_blocking(channel, blocking);
|
||||
}
|
||||
|
||||
int channel_write(ssh_channel channel, const void *data, uint32_t len){
|
||||
return ssh_channel_write(channel, data, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions have to be wrapped around the pki.c functions.
|
||||
|
||||
void privatekey_free(ssh_private_key prv);
|
||||
ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
||||
int type, const char *passphrase);
|
||||
void publickey_free(ssh_public_key key);
|
||||
int ssh_publickey_to_file(ssh_session session, const char *file,
|
||||
ssh_string pubkey, int type);
|
||||
ssh_string publickey_from_file(ssh_session session, const char *filename,
|
||||
int *type);
|
||||
ssh_public_key publickey_from_privatekey(ssh_private_key prv);
|
||||
ssh_string publickey_to_string(ssh_public_key key);
|
||||
*
|
||||
*/
|
||||
|
||||
void string_burn(ssh_string str){
|
||||
ssh_string_burn(str);
|
||||
}
|
||||
|
||||
ssh_string string_copy(ssh_string str){
|
||||
return ssh_string_copy(str);
|
||||
}
|
||||
|
||||
void *string_data(ssh_string str){
|
||||
return ssh_string_data(str);
|
||||
}
|
||||
|
||||
int string_fill(ssh_string str, const void *data, size_t len){
|
||||
return ssh_string_fill(str,data,len);
|
||||
}
|
||||
|
||||
void string_free(ssh_string str){
|
||||
ssh_string_free(str);
|
||||
}
|
||||
|
||||
ssh_string string_from_char(const char *what){
|
||||
return ssh_string_from_char(what);
|
||||
}
|
||||
|
||||
size_t string_len(ssh_string str){
|
||||
return ssh_string_len(str);
|
||||
}
|
||||
|
||||
ssh_string string_new(size_t size){
|
||||
return ssh_string_new(size);
|
||||
}
|
||||
|
||||
char *string_to_char(ssh_string str){
|
||||
return ssh_string_to_char(str);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ SSH_PACKET_CALLBACK(ssh_packet_service_request){
|
||||
goto error;
|
||||
}
|
||||
|
||||
service_c = string_to_char(service);
|
||||
service_c = ssh_string_to_char(service);
|
||||
if (service_c == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -92,7 +92,7 @@ SSH_PACKET_CALLBACK(ssh_packet_service_request){
|
||||
msg->type=SSH_REQUEST_SERVICE;
|
||||
msg->service_request.service=service_c;
|
||||
error:
|
||||
string_free(service);
|
||||
ssh_string_free(service);
|
||||
if(msg != NULL)
|
||||
ssh_message_queue(session,msg);
|
||||
leave_function();
|
||||
@ -138,26 +138,26 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
|
||||
}
|
||||
|
||||
msg->type = SSH_REQUEST_AUTH;
|
||||
msg->auth_request.username = string_to_char(user_s);
|
||||
msg->auth_request.username = ssh_string_to_char(user_s);
|
||||
if (msg->auth_request.username == NULL) {
|
||||
goto error;
|
||||
}
|
||||
string_free(user_s);
|
||||
ssh_string_free(user_s);
|
||||
user_s = NULL;
|
||||
|
||||
service_c = string_to_char(service);
|
||||
service_c = ssh_string_to_char(service);
|
||||
if (service_c == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method_c = string_to_char(method);
|
||||
method_c = ssh_string_to_char(method);
|
||||
if (method_c == NULL) {
|
||||
goto error;
|
||||
}
|
||||
method_size = string_len(method);
|
||||
method_size = ssh_string_len(method);
|
||||
|
||||
string_free(service);
|
||||
ssh_string_free(service);
|
||||
service = NULL;
|
||||
string_free(method);
|
||||
ssh_string_free(method);
|
||||
method = NULL;
|
||||
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
@ -185,9 +185,9 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
|
||||
if (pass == NULL) {
|
||||
goto error;
|
||||
}
|
||||
msg->auth_request.password = string_to_char(pass);
|
||||
string_burn(pass);
|
||||
string_free(pass);
|
||||
msg->auth_request.password = ssh_string_to_char(pass);
|
||||
ssh_string_burn(pass);
|
||||
ssh_string_free(pass);
|
||||
pass = NULL;
|
||||
if (msg->auth_request.password == NULL) {
|
||||
goto error;
|
||||
@ -209,14 +209,14 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
|
||||
}
|
||||
publickey = buffer_get_ssh_string(packet);
|
||||
if (publickey == NULL) {
|
||||
string_free(algo);
|
||||
ssh_string_free(algo);
|
||||
algo = NULL;
|
||||
goto error;
|
||||
}
|
||||
msg->auth_request.public_key = publickey_from_string(session, publickey);
|
||||
string_free(algo);
|
||||
ssh_string_free(algo);
|
||||
algo = NULL;
|
||||
string_free(publickey);
|
||||
ssh_string_free(publickey);
|
||||
publickey = NULL;
|
||||
if (msg->auth_request.public_key == NULL) {
|
||||
goto error;
|
||||
@ -241,12 +241,12 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
|
||||
if ((digest == NULL || signature == NULL) ||
|
||||
(digest != NULL && signature != NULL &&
|
||||
sig_verify(session, public_key, signature,
|
||||
buffer_get(digest), buffer_get_len(digest)) < 0)) {
|
||||
ssh_buffer_get_begin(digest), ssh_buffer_get_len(digest)) < 0)) {
|
||||
ssh_log(session, SSH_LOG_PACKET, "Wrong signature from peer");
|
||||
|
||||
string_free(sign);
|
||||
ssh_string_free(sign);
|
||||
sign = NULL;
|
||||
buffer_free(digest);
|
||||
ssh_buffer_free(digest);
|
||||
digest = NULL;
|
||||
signature_free(signature);
|
||||
signature = NULL;
|
||||
@ -257,9 +257,9 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
|
||||
else
|
||||
ssh_log(session, SSH_LOG_PACKET, "Valid signature received");
|
||||
|
||||
buffer_free(digest);
|
||||
ssh_buffer_free(digest);
|
||||
digest = NULL;
|
||||
string_free(sign);
|
||||
ssh_string_free(sign);
|
||||
sign = NULL;
|
||||
signature_free(signature);
|
||||
signature = NULL;
|
||||
@ -274,9 +274,9 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
|
||||
SAFE_FREE(method_c);
|
||||
goto end;
|
||||
error:
|
||||
string_free(user_s);
|
||||
string_free(service);
|
||||
string_free(method);
|
||||
ssh_string_free(user_s);
|
||||
ssh_string_free(service);
|
||||
ssh_string_free(method);
|
||||
|
||||
SAFE_FREE(method_c);
|
||||
SAFE_FREE(service_c);
|
||||
@ -313,7 +313,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
type_c = string_to_char(type_s);
|
||||
type_c = ssh_string_to_char(type_s);
|
||||
if (type_c == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
@ -321,7 +321,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"Clients wants to open a %s channel", type_c);
|
||||
string_free(type_s);
|
||||
ssh_string_free(type_s);
|
||||
type_s=NULL;
|
||||
|
||||
buffer_get_u32(packet, &sender);
|
||||
@ -344,13 +344,13 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
msg->channel_request_open.destination = string_to_char(type_s);
|
||||
msg->channel_request_open.destination = ssh_string_to_char(type_s);
|
||||
if (msg->channel_request_open.destination == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(destination);
|
||||
ssh_string_free(destination);
|
||||
goto error;
|
||||
}
|
||||
string_free(destination);
|
||||
ssh_string_free(destination);
|
||||
|
||||
buffer_get_u32(packet, &destination_port);
|
||||
msg->channel_request_open.destination_port = ntohl(destination_port);
|
||||
@ -360,13 +360,13 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
msg->channel_request_open.originator = string_to_char(type_s);
|
||||
msg->channel_request_open.originator = ssh_string_to_char(type_s);
|
||||
if (msg->channel_request_open.originator == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(originator);
|
||||
ssh_string_free(originator);
|
||||
goto error;
|
||||
}
|
||||
string_free(originator);
|
||||
ssh_string_free(originator);
|
||||
|
||||
buffer_get_u32(packet, &originator_port);
|
||||
msg->channel_request_open.originator_port = ntohl(originator_port);
|
||||
@ -381,13 +381,13 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
msg->channel_request_open.destination = string_to_char(type_s);
|
||||
msg->channel_request_open.destination = ssh_string_to_char(type_s);
|
||||
if (msg->channel_request_open.destination == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(destination);
|
||||
ssh_string_free(destination);
|
||||
goto error;
|
||||
}
|
||||
string_free(destination);
|
||||
ssh_string_free(destination);
|
||||
|
||||
buffer_get_u32(packet, &destination_port);
|
||||
msg->channel_request_open.destination_port = ntohl(destination_port);
|
||||
@ -397,13 +397,13 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
msg->channel_request_open.originator = string_to_char(type_s);
|
||||
msg->channel_request_open.originator = ssh_string_to_char(type_s);
|
||||
if (msg->channel_request_open.originator == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(originator);
|
||||
ssh_string_free(originator);
|
||||
goto error;
|
||||
}
|
||||
string_free(originator);
|
||||
ssh_string_free(originator);
|
||||
|
||||
buffer_get_u32(packet, &originator_port);
|
||||
msg->channel_request_open.originator_port = ntohl(originator_port);
|
||||
@ -418,13 +418,13 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
msg->channel_request_open.originator = string_to_char(type_s);
|
||||
msg->channel_request_open.originator = ssh_string_to_char(type_s);
|
||||
if (msg->channel_request_open.originator == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(originator);
|
||||
ssh_string_free(originator);
|
||||
goto error;
|
||||
}
|
||||
string_free(originator);
|
||||
ssh_string_free(originator);
|
||||
|
||||
buffer_get_u32(packet, &originator_port);
|
||||
msg->channel_request_open.originator_port = ntohl(originator_port);
|
||||
@ -441,7 +441,7 @@ error:
|
||||
msg=NULL;
|
||||
end:
|
||||
if(type_s != NULL)
|
||||
string_free(type_s);
|
||||
ssh_string_free(type_s);
|
||||
SAFE_FREE(type_c);
|
||||
if(msg != NULL)
|
||||
ssh_message_queue(session,msg);
|
||||
@ -461,7 +461,7 @@ ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
chan = channel_new(session);
|
||||
chan = ssh_channel_new(session);
|
||||
if (chan == NULL) {
|
||||
leave_function();
|
||||
return NULL;
|
||||
@ -501,7 +501,7 @@ ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
|
||||
leave_function();
|
||||
return chan;
|
||||
error:
|
||||
channel_free(chan);
|
||||
ssh_channel_free(chan);
|
||||
|
||||
leave_function();
|
||||
return NULL;
|
||||
@ -552,13 +552,13 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
term_c = string_to_char(term);
|
||||
term_c = ssh_string_to_char(term);
|
||||
if (term_c == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(term);
|
||||
ssh_string_free(term);
|
||||
goto error;
|
||||
}
|
||||
string_free(term);
|
||||
ssh_string_free(term);
|
||||
|
||||
msg->channel_request.type = SSH_CHANNEL_REQUEST_PTY;
|
||||
msg->channel_request.TERM = term_c;
|
||||
@ -604,13 +604,13 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
subsys_c = string_to_char(subsys);
|
||||
subsys_c = ssh_string_to_char(subsys);
|
||||
if (subsys_c == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(subsys);
|
||||
ssh_string_free(subsys);
|
||||
goto error;
|
||||
}
|
||||
string_free(subsys);
|
||||
ssh_string_free(subsys);
|
||||
|
||||
msg->channel_request.type = SSH_CHANNEL_REQUEST_SUBSYSTEM;
|
||||
msg->channel_request.subsystem = subsys_c;
|
||||
@ -631,8 +631,8 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
|
||||
goto error;
|
||||
}
|
||||
msg->channel_request.type = SSH_CHANNEL_REQUEST_EXEC;
|
||||
msg->channel_request.command = string_to_char(cmd);
|
||||
string_free(cmd);
|
||||
msg->channel_request.command = ssh_string_to_char(cmd);
|
||||
ssh_string_free(cmd);
|
||||
if (msg->channel_request.command == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -650,21 +650,21 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
|
||||
value = buffer_get_ssh_string(packet);
|
||||
if (value == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
string_free(name);
|
||||
ssh_string_free(name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
msg->channel_request.type = SSH_CHANNEL_REQUEST_ENV;
|
||||
msg->channel_request.var_name = string_to_char(name);
|
||||
msg->channel_request.var_value = string_to_char(value);
|
||||
msg->channel_request.var_name = ssh_string_to_char(name);
|
||||
msg->channel_request.var_value = ssh_string_to_char(value);
|
||||
if (msg->channel_request.var_name == NULL ||
|
||||
msg->channel_request.var_value == NULL) {
|
||||
string_free(name);
|
||||
string_free(value);
|
||||
ssh_string_free(name);
|
||||
ssh_string_free(value);
|
||||
goto error;
|
||||
}
|
||||
string_free(name);
|
||||
string_free(value);
|
||||
ssh_string_free(name);
|
||||
ssh_string_free(value);
|
||||
|
||||
goto end;
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
session->in_buffer = buffer_new();
|
||||
session->in_buffer = ssh_buffer_new();
|
||||
if (session->in_buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -206,8 +206,8 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
|
||||
* have been decrypted)
|
||||
*/
|
||||
if (packet_decrypt(session,
|
||||
((uint8_t*)buffer_get(session->in_buffer) + blocksize),
|
||||
buffer_get_len(session->in_buffer) - blocksize) < 0) {
|
||||
((uint8_t*)ssh_buffer_get_begin(session->in_buffer) + blocksize),
|
||||
ssh_buffer_get_len(session->in_buffer) - blocksize) < 0) {
|
||||
ssh_set_error(session, SSH_FATAL, "Decrypt error");
|
||||
goto error;
|
||||
}
|
||||
@ -240,8 +240,8 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
|
||||
buffer_get_rest_len(session->in_buffer));
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("incrimined packet",
|
||||
buffer_get(session->in_buffer),
|
||||
buffer_get_len(session->in_buffer));
|
||||
ssh_buffer_get_begin(session->in_buffer),
|
||||
ssh_buffer_get_len(session->in_buffer));
|
||||
#endif
|
||||
goto error;
|
||||
}
|
||||
@ -413,8 +413,8 @@ static int ssh_packet_write(ssh_session session) {
|
||||
enter_function();
|
||||
|
||||
ssh_socket_write(session->socket,
|
||||
buffer_get(session->out_buffer),
|
||||
buffer_get_len(session->out_buffer));
|
||||
ssh_buffer_get_begin(session->out_buffer),
|
||||
ssh_buffer_get_len(session->out_buffer));
|
||||
|
||||
rc = packet_flush(session, 0);
|
||||
|
||||
@ -425,7 +425,7 @@ static int ssh_packet_write(ssh_session session) {
|
||||
static int packet_send2(ssh_session session) {
|
||||
unsigned int blocksize = (session->current_crypto ?
|
||||
session->current_crypto->out_cipher->blocksize : 8);
|
||||
uint32_t currentlen = buffer_get_len(session->out_buffer);
|
||||
uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
|
||||
unsigned char *hmac = NULL;
|
||||
char padstring[32] = {0};
|
||||
int rc = SSH_ERROR;
|
||||
@ -443,7 +443,7 @@ static int packet_send2(ssh_session session) {
|
||||
if (compress_buffer(session,session->out_buffer) < 0) {
|
||||
goto error;
|
||||
}
|
||||
currentlen = buffer_get_len(session->out_buffer);
|
||||
currentlen = ssh_buffer_get_len(session->out_buffer);
|
||||
}
|
||||
#endif
|
||||
padding = (blocksize - ((currentlen +5) % blocksize));
|
||||
@ -474,12 +474,12 @@ static int packet_send2(ssh_session session) {
|
||||
#ifdef WITH_PCAP
|
||||
if(session->pcap_ctx){
|
||||
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,
|
||||
buffer_get(session->out_buffer),buffer_get_len(session->out_buffer)
|
||||
,buffer_get_len(session->out_buffer));
|
||||
ssh_buffer_get_begin(session->out_buffer),ssh_buffer_get_len(session->out_buffer)
|
||||
,ssh_buffer_get_len(session->out_buffer));
|
||||
}
|
||||
#endif
|
||||
hmac = packet_encrypt(session, buffer_get(session->out_buffer),
|
||||
buffer_get_len(session->out_buffer));
|
||||
hmac = packet_encrypt(session, ssh_buffer_get_begin(session->out_buffer),
|
||||
ssh_buffer_get_len(session->out_buffer));
|
||||
if (hmac) {
|
||||
if (buffer_add_data(session->out_buffer, hmac, 20) < 0) {
|
||||
goto error;
|
||||
|
@ -110,7 +110,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
session->in_buffer = buffer_new();
|
||||
session->in_buffer = ssh_buffer_new();
|
||||
if (session->in_buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -156,8 +156,8 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
|
||||
}
|
||||
processed += to_be_read;
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("read packet:", buffer_get(session->in_buffer),
|
||||
buffer_get_len(session->in_buffer));
|
||||
ssh_print_hexa("read packet:", ssh_buffer_get_begin(session->in_buffer),
|
||||
ssh_buffer_get_len(session->in_buffer));
|
||||
#endif
|
||||
if (session->current_crypto) {
|
||||
/*
|
||||
@ -165,15 +165,15 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
|
||||
* previously read, unencrypted, and is not part of the buffer
|
||||
*/
|
||||
if (packet_decrypt(session,
|
||||
buffer_get(session->in_buffer),
|
||||
buffer_get_len(session->in_buffer)) < 0) {
|
||||
ssh_buffer_get_begin(session->in_buffer),
|
||||
ssh_buffer_get_len(session->in_buffer)) < 0) {
|
||||
ssh_set_error(session, SSH_FATAL, "Packet decrypt error");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("read packet decrypted:", buffer_get(session->in_buffer),
|
||||
buffer_get_len(session->in_buffer));
|
||||
ssh_print_hexa("read packet decrypted:", ssh_buffer_get_begin(session->in_buffer),
|
||||
ssh_buffer_get_len(session->in_buffer));
|
||||
#endif
|
||||
ssh_log(session, SSH_LOG_PACKET, "%d bytes padding", padding);
|
||||
if(((len + padding) != buffer_get_rest_len(session->in_buffer)) ||
|
||||
@ -245,7 +245,7 @@ error:
|
||||
int packet_send1(ssh_session session) {
|
||||
unsigned int blocksize = (session->current_crypto ?
|
||||
session->current_crypto->out_cipher->blocksize : 8);
|
||||
uint32_t currentlen = buffer_get_len(session->out_buffer) + sizeof(uint32_t);
|
||||
uint32_t currentlen = ssh_buffer_get_len(session->out_buffer) + sizeof(uint32_t);
|
||||
char padstring[32] = {0};
|
||||
int rc = SSH_ERROR;
|
||||
uint32_t finallen;
|
||||
@ -284,27 +284,27 @@ int packet_send1(ssh_session session) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
crc = ssh_crc32((char *)buffer_get(session->out_buffer) + sizeof(uint32_t),
|
||||
buffer_get_len(session->out_buffer) - sizeof(uint32_t));
|
||||
crc = ssh_crc32((char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
|
||||
ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
|
||||
|
||||
if (buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("Clear packet", buffer_get(session->out_buffer),
|
||||
buffer_get_len(session->out_buffer));
|
||||
ssh_print_hexa("Clear packet", ssh_buffer_get_begin(session->out_buffer),
|
||||
ssh_buffer_get_len(session->out_buffer));
|
||||
#endif
|
||||
|
||||
packet_encrypt(session, (unsigned char *)buffer_get(session->out_buffer) + sizeof(uint32_t),
|
||||
buffer_get_len(session->out_buffer) - sizeof(uint32_t));
|
||||
packet_encrypt(session, (unsigned char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
|
||||
ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
|
||||
|
||||
#ifdef DEBUG_CRYPTO
|
||||
ssh_print_hexa("encrypted packet",buffer_get(session->out_buffer),
|
||||
buffer_get_len(session->out_buffer));
|
||||
ssh_print_hexa("encrypted packet",ssh_buffer_get_begin(session->out_buffer),
|
||||
ssh_buffer_get_len(session->out_buffer));
|
||||
#endif
|
||||
if (ssh_socket_write(session->socket, buffer_get(session->out_buffer),
|
||||
buffer_get_len(session->out_buffer)) == SSH_ERROR) {
|
||||
if (ssh_socket_write(session->socket, ssh_buffer_get_begin(session->out_buffer),
|
||||
ssh_buffer_get_len(session->out_buffer)) == SSH_ERROR) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -133,8 +133,8 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
|
||||
uint32_t len;
|
||||
if(pcap == NULL || pcap->output==NULL)
|
||||
return SSH_ERROR;
|
||||
len=buffer_get_len(packet);
|
||||
err=fwrite(buffer_get(packet),len,1,pcap->output);
|
||||
len=ssh_buffer_get_len(packet);
|
||||
err=fwrite(ssh_buffer_get_begin(packet),len,1,pcap->output);
|
||||
if(err<0)
|
||||
return SSH_ERROR;
|
||||
else
|
||||
@ -146,7 +146,7 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
|
||||
* on file
|
||||
*/
|
||||
int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t original_len){
|
||||
ssh_buffer header=buffer_new();
|
||||
ssh_buffer header=ssh_buffer_new();
|
||||
struct timeval now;
|
||||
int err;
|
||||
if(header == NULL)
|
||||
@ -154,11 +154,11 @@ int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t o
|
||||
gettimeofday(&now,NULL);
|
||||
buffer_add_u32(header,htonl(now.tv_sec));
|
||||
buffer_add_u32(header,htonl(now.tv_usec));
|
||||
buffer_add_u32(header,htonl(buffer_get_len(packet)));
|
||||
buffer_add_u32(header,htonl(ssh_buffer_get_len(packet)));
|
||||
buffer_add_u32(header,htonl(original_len));
|
||||
buffer_add_buffer(header,packet);
|
||||
err=ssh_pcap_file_write(pcap,header);
|
||||
buffer_free(header);
|
||||
ssh_buffer_free(header);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename){
|
||||
pcap->output=fopen(filename,"wb");
|
||||
if(pcap->output==NULL)
|
||||
return SSH_ERROR;
|
||||
header=buffer_new();
|
||||
header=ssh_buffer_new();
|
||||
if(header==NULL)
|
||||
return SSH_ERROR;
|
||||
buffer_add_u32(header,htonl(PCAP_MAGIC));
|
||||
@ -192,7 +192,7 @@ int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename){
|
||||
/* we will write sort-of IP */
|
||||
buffer_add_u32(header,htonl(DLT_RAW));
|
||||
err=ssh_pcap_file_write(pcap,header);
|
||||
buffer_free(header);
|
||||
ssh_buffer_free(header);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
|
||||
if(ctx->connected==0)
|
||||
if(ssh_pcap_context_connect(ctx)==SSH_ERROR)
|
||||
return SSH_ERROR;
|
||||
ip=buffer_new();
|
||||
ip=ssh_buffer_new();
|
||||
if(ip==NULL){
|
||||
ssh_set_error_oom(ctx->session);
|
||||
return SSH_ERROR;
|
||||
@ -364,7 +364,7 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
|
||||
/* actual data */
|
||||
buffer_add_data(ip,data,len);
|
||||
err=ssh_pcap_file_write_packet(ctx->file,ip,origlen + TCPIPHDR_LEN);
|
||||
buffer_free(ip);
|
||||
ssh_buffer_free(ip);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
54
libssh/scp.c
54
libssh/scp.c
@ -90,12 +90,12 @@ int ssh_scp_init(ssh_scp scp){
|
||||
scp->mode==SSH_SCP_WRITE?"write":"read",
|
||||
scp->recursive?"recursive ":"",
|
||||
scp->location);
|
||||
scp->channel=channel_new(scp->session);
|
||||
scp->channel=ssh_channel_new(scp->session);
|
||||
if(scp->channel == NULL){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
r= channel_open_session(scp->channel);
|
||||
r= ssh_channel_open_session(scp->channel);
|
||||
if(r==SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
@ -106,12 +106,12 @@ int ssh_scp_init(ssh_scp scp){
|
||||
else
|
||||
snprintf(execbuffer,sizeof(execbuffer),"scp -f %s %s",
|
||||
scp->recursive ? "-r":"", scp->location);
|
||||
if(channel_request_exec(scp->channel,execbuffer) == SSH_ERROR){
|
||||
if(ssh_channel_request_exec(scp->channel,execbuffer) == SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
if(scp->mode == SSH_SCP_WRITE){
|
||||
r=channel_read(scp->channel,&code,1,0);
|
||||
r=ssh_channel_read(scp->channel,&code,1,0);
|
||||
if(r<=0){
|
||||
ssh_set_error(scp->session,SSH_FATAL, "Error reading status code: %s",ssh_get_error(scp->session));
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
@ -123,7 +123,7 @@ int ssh_scp_init(ssh_scp scp){
|
||||
return SSH_ERROR;
|
||||
}
|
||||
} else {
|
||||
channel_write(scp->channel,"",1);
|
||||
ssh_channel_write(scp->channel,"",1);
|
||||
}
|
||||
if(scp->mode == SSH_SCP_WRITE)
|
||||
scp->state=SSH_SCP_WRITE_INITED;
|
||||
@ -138,7 +138,7 @@ int ssh_scp_close(ssh_scp scp){
|
||||
if(scp==NULL)
|
||||
return SSH_ERROR;
|
||||
if(scp->channel != NULL){
|
||||
if(channel_send_eof(scp->channel) == SSH_ERROR){
|
||||
if(ssh_channel_send_eof(scp->channel) == SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
@ -146,16 +146,16 @@ int ssh_scp_close(ssh_scp scp){
|
||||
* not yet stored on disk. This can happen if the close is sent
|
||||
* before we got the EOF back
|
||||
*/
|
||||
while(!channel_is_eof(scp->channel)){
|
||||
err=channel_read(scp->channel,buffer,sizeof(buffer),0);
|
||||
while(!ssh_channel_is_eof(scp->channel)){
|
||||
err=ssh_channel_read(scp->channel,buffer,sizeof(buffer),0);
|
||||
if(err==SSH_ERROR)
|
||||
break;
|
||||
}
|
||||
if(channel_close(scp->channel) == SSH_ERROR){
|
||||
if(ssh_channel_close(scp->channel) == SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
channel_free(scp->channel);
|
||||
ssh_channel_free(scp->channel);
|
||||
scp->channel=NULL;
|
||||
}
|
||||
scp->state=SSH_SCP_NEW;
|
||||
@ -168,7 +168,7 @@ void ssh_scp_free(ssh_scp scp){
|
||||
if(scp->state != SSH_SCP_NEW)
|
||||
ssh_scp_close(scp);
|
||||
if(scp->channel)
|
||||
channel_free(scp->channel);
|
||||
ssh_channel_free(scp->channel);
|
||||
SAFE_FREE(scp->location);
|
||||
SAFE_FREE(scp->request_name);
|
||||
SAFE_FREE(scp->warning);
|
||||
@ -206,12 +206,12 @@ int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode){
|
||||
snprintf(buffer, sizeof(buffer), "D%s 0 %s\n", perms, dir);
|
||||
SAFE_FREE(dir);
|
||||
SAFE_FREE(perms);
|
||||
r=channel_write(scp->channel,buffer,strlen(buffer));
|
||||
r=ssh_channel_write(scp->channel,buffer,strlen(buffer));
|
||||
if(r==SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
r=channel_read(scp->channel,&code,1,0);
|
||||
r=ssh_channel_read(scp->channel,&code,1,0);
|
||||
if(r<=0){
|
||||
ssh_set_error(scp->session,SSH_FATAL, "Error reading status code: %s",ssh_get_error(scp->session));
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
@ -243,12 +243,12 @@ int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode){
|
||||
ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_leave_directory called under invalid state");
|
||||
return SSH_ERROR;
|
||||
}
|
||||
r=channel_write(scp->channel,buffer,strlen(buffer));
|
||||
r=ssh_channel_write(scp->channel,buffer,strlen(buffer));
|
||||
if(r==SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
r=channel_read(scp->channel,&code,1,0);
|
||||
r=ssh_channel_read(scp->channel,&code,1,0);
|
||||
if(r<=0){
|
||||
ssh_set_error(scp->session,SSH_FATAL, "Error reading status code: %s",ssh_get_error(scp->session));
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
@ -295,12 +295,12 @@ int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int mode){
|
||||
snprintf(buffer, sizeof(buffer), "C%s %" PRIdS " %s\n", perms, size, file);
|
||||
SAFE_FREE(file);
|
||||
SAFE_FREE(perms);
|
||||
r=channel_write(scp->channel,buffer,strlen(buffer));
|
||||
r=ssh_channel_write(scp->channel,buffer,strlen(buffer));
|
||||
if(r==SSH_ERROR){
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
r=channel_read(scp->channel,&code,1,0);
|
||||
r=ssh_channel_read(scp->channel,&code,1,0);
|
||||
if(r<=0){
|
||||
ssh_set_error(scp->session,SSH_FATAL, "Error reading status code: %s",ssh_get_error(scp->session));
|
||||
scp->state=SSH_SCP_ERROR;
|
||||
@ -335,7 +335,7 @@ int ssh_scp_response(ssh_scp scp, char **response){
|
||||
char msg[128];
|
||||
if(scp==NULL)
|
||||
return SSH_ERROR;
|
||||
r=channel_read(scp->channel,&code,1,0);
|
||||
r=ssh_channel_read(scp->channel,&code,1,0);
|
||||
if(r == SSH_ERROR)
|
||||
return SSH_ERROR;
|
||||
if(code == 0)
|
||||
@ -391,8 +391,8 @@ int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){
|
||||
if(scp->processed + len > scp->filelen)
|
||||
len = scp->filelen - scp->processed;
|
||||
/* hack to avoid waiting for window change */
|
||||
channel_poll(scp->channel,0);
|
||||
w=channel_write(scp->channel,buffer,len);
|
||||
ssh_channel_poll(scp->channel,0);
|
||||
w=ssh_channel_write(scp->channel,buffer,len);
|
||||
if(w != SSH_ERROR)
|
||||
scp->processed += w;
|
||||
else {
|
||||
@ -439,7 +439,7 @@ int ssh_scp_read_string(ssh_scp scp, char *buffer, size_t len){
|
||||
if(scp==NULL)
|
||||
return SSH_ERROR;
|
||||
while(r<len-1){
|
||||
err=channel_read(scp->channel,&buffer[r],1,0);
|
||||
err=ssh_channel_read(scp->channel,&buffer[r],1,0);
|
||||
if(err==SSH_ERROR){
|
||||
break;
|
||||
}
|
||||
@ -487,7 +487,7 @@ int ssh_scp_pull_request(ssh_scp scp){
|
||||
}
|
||||
err=ssh_scp_read_string(scp,buffer,sizeof(buffer));
|
||||
if(err==SSH_ERROR){
|
||||
if(channel_is_eof(scp->channel)){
|
||||
if(ssh_channel_is_eof(scp->channel)){
|
||||
scp->state=SSH_SCP_TERMINATED;
|
||||
return SSH_SCP_REQUEST_EOF;
|
||||
}
|
||||
@ -532,7 +532,7 @@ int ssh_scp_pull_request(ssh_scp scp){
|
||||
break;
|
||||
case 'E':
|
||||
scp->request_type=SSH_SCP_REQUEST_ENDDIR;
|
||||
channel_write(scp->channel,"",1);
|
||||
ssh_channel_write(scp->channel,"",1);
|
||||
return scp->request_type;
|
||||
case 0x1:
|
||||
ssh_set_error(scp->session,SSH_REQUEST_DENIED,"SCP: Warning: %s",&buffer[1]);
|
||||
@ -579,7 +579,7 @@ int ssh_scp_deny_request(ssh_scp scp, const char *reason){
|
||||
return SSH_ERROR;
|
||||
}
|
||||
snprintf(buffer,sizeof(buffer),"%c%s\n",2,reason);
|
||||
err=channel_write(scp->channel,buffer,strlen(buffer));
|
||||
err=ssh_channel_write(scp->channel,buffer,strlen(buffer));
|
||||
if(err==SSH_ERROR) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
@ -607,7 +607,7 @@ int ssh_scp_accept_request(ssh_scp scp){
|
||||
ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_deny_request called under invalid state");
|
||||
return SSH_ERROR;
|
||||
}
|
||||
err=channel_write(scp->channel,buffer,1);
|
||||
err=ssh_channel_write(scp->channel,buffer,1);
|
||||
if(err==SSH_ERROR) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
@ -646,7 +646,7 @@ int ssh_scp_read(ssh_scp scp, void *buffer, size_t size){
|
||||
size = scp->filelen - scp->processed;
|
||||
if(size > 65536)
|
||||
size=65536; /* avoid too large reads */
|
||||
r=channel_read(scp->channel,buffer,size,0);
|
||||
r=ssh_channel_read(scp->channel,buffer,size,0);
|
||||
if(r != SSH_ERROR)
|
||||
scp->processed += r;
|
||||
else {
|
||||
@ -656,7 +656,7 @@ int ssh_scp_read(ssh_scp scp, void *buffer, size_t size){
|
||||
/* Check if we arrived at end of file */
|
||||
if(scp->processed == scp->filelen) {
|
||||
scp->processed=scp->filelen=0;
|
||||
channel_write(scp->channel,"",1);
|
||||
ssh_channel_write(scp->channel,"",1);
|
||||
code=ssh_scp_response(scp,NULL);
|
||||
if(code == 0){
|
||||
scp->state=SSH_SCP_READ_INITED;
|
||||
|
@ -375,7 +375,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){
|
||||
} else {
|
||||
session->dh_handshake_state=DH_STATE_INIT_SENT;
|
||||
}
|
||||
string_free(e);
|
||||
ssh_string_free(e);
|
||||
|
||||
error:
|
||||
leave_function();
|
||||
@ -424,34 +424,34 @@ static int dh_handshake_server(ssh_session session) {
|
||||
if (pub == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Could not get the public key from the private key");
|
||||
string_free(f);
|
||||
ssh_string_free(f);
|
||||
return -1;
|
||||
}
|
||||
pubkey = publickey_to_string(pub);
|
||||
publickey_free(pub);
|
||||
if (pubkey == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
string_free(f);
|
||||
ssh_string_free(f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dh_import_pubkey(session, pubkey);
|
||||
if (dh_build_k(session) < 0) {
|
||||
ssh_set_error(session, SSH_FATAL, "Could not import the public key");
|
||||
string_free(f);
|
||||
ssh_string_free(f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (make_sessionid(session) != SSH_OK) {
|
||||
ssh_set_error(session, SSH_FATAL, "Could not create a session id");
|
||||
string_free(f);
|
||||
ssh_string_free(f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sign = ssh_sign_session_id(session, prv);
|
||||
if (sign == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
|
||||
string_free(f);
|
||||
ssh_string_free(f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -471,12 +471,12 @@ static int dh_handshake_server(ssh_session session) {
|
||||
buffer_add_ssh_string(session->out_buffer, sign) < 0) {
|
||||
ssh_set_error(session, SSH_FATAL, "Not enough space");
|
||||
buffer_reinit(session->out_buffer);
|
||||
string_free(f);
|
||||
string_free(sign);
|
||||
ssh_string_free(f);
|
||||
ssh_string_free(sign);
|
||||
return -1;
|
||||
}
|
||||
string_free(f);
|
||||
string_free(sign);
|
||||
ssh_string_free(f);
|
||||
ssh_string_free(sign);
|
||||
session->dh_handshake_state=DH_STATE_NEWKEYS_SENT;
|
||||
if (packet_send(session) != SSH_OK) {
|
||||
return -1;
|
||||
@ -615,7 +615,7 @@ static int ssh_message_auth_reply_default(ssh_message msg,int partial) {
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"Sending a auth failure. methods that can continue: %s", methods_c);
|
||||
|
||||
methods = string_from_char(methods_c);
|
||||
methods = ssh_string_from_char(methods_c);
|
||||
if (methods == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@ -636,7 +636,7 @@ static int ssh_message_auth_reply_default(ssh_message msg,int partial) {
|
||||
|
||||
rc = packet_send(msg->session);
|
||||
error:
|
||||
string_free(methods);
|
||||
ssh_string_free(methods);
|
||||
|
||||
leave_function();
|
||||
return rc;
|
||||
@ -712,12 +712,12 @@ int ssh_message_service_reply_success(ssh_message msg) {
|
||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_SERVICE_ACCEPT) < 0) {
|
||||
return -1;
|
||||
}
|
||||
service=string_from_char(msg->service_request.service);
|
||||
service=ssh_string_from_char(msg->service_request.service);
|
||||
if (buffer_add_ssh_string(session->out_buffer, service) < 0) {
|
||||
string_free(service);
|
||||
ssh_string_free(service);
|
||||
return -1;
|
||||
}
|
||||
string_free(service);
|
||||
ssh_string_free(service);
|
||||
return packet_send(msg->session);
|
||||
}
|
||||
|
||||
@ -829,11 +829,11 @@ int ssh_message_auth_reply_pk_ok_simple(ssh_message msg) {
|
||||
ssh_string algo;
|
||||
ssh_string pubkey;
|
||||
int ret;
|
||||
algo=string_from_char(msg->auth_request.public_key->type_c);
|
||||
algo=ssh_string_from_char(msg->auth_request.public_key->type_c);
|
||||
pubkey=publickey_to_string(msg->auth_request.public_key);
|
||||
ret=ssh_message_auth_reply_pk_ok(msg,algo,pubkey);
|
||||
string_free(algo);
|
||||
string_free(pubkey);
|
||||
ssh_string_free(algo);
|
||||
ssh_string_free(pubkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -73,12 +73,12 @@ ssh_session ssh_new(void) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
session->out_buffer = buffer_new();
|
||||
session->out_buffer = ssh_buffer_new();
|
||||
if (session->out_buffer == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
session->in_buffer=buffer_new();
|
||||
session->in_buffer=ssh_buffer_new();
|
||||
if (session->in_buffer == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@ -171,15 +171,15 @@ void ssh_free(ssh_session session) {
|
||||
session->pcap_ctx=NULL;
|
||||
}
|
||||
#endif
|
||||
buffer_free(session->in_buffer);
|
||||
buffer_free(session->out_buffer);
|
||||
ssh_buffer_free(session->in_buffer);
|
||||
ssh_buffer_free(session->out_buffer);
|
||||
session->in_buffer=session->out_buffer=NULL;
|
||||
crypto_free(session->current_crypto);
|
||||
crypto_free(session->next_crypto);
|
||||
ssh_socket_free(session->socket);
|
||||
/* delete all channels */
|
||||
while (session->channels) {
|
||||
channel_free(session->channels);
|
||||
ssh_channel_free(session->channels);
|
||||
}
|
||||
#ifndef _WIN32
|
||||
agent_free(session->agent);
|
||||
@ -469,8 +469,8 @@ SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback){
|
||||
buffer_get_u32(packet, &code);
|
||||
error_s = buffer_get_ssh_string(packet);
|
||||
if (error_s != NULL) {
|
||||
error = string_to_char(error_s);
|
||||
string_free(error_s);
|
||||
error = ssh_string_to_char(error_s);
|
||||
ssh_string_free(error_s);
|
||||
}
|
||||
ssh_log(session, SSH_LOG_PACKET, "Received SSH_MSG_DISCONNECT %d:%s",code,
|
||||
error != NULL ? error : "no error");
|
||||
|
500
libssh/sftp.c
500
libssh/sftp.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -101,8 +101,8 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
msg->filename = string_to_char(tmp);
|
||||
string_free(tmp);
|
||||
msg->filename = ssh_string_to_char(tmp);
|
||||
ssh_string_free(tmp);
|
||||
if (msg->filename == NULL) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
@ -115,8 +115,8 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
msg->filename = string_to_char(tmp);
|
||||
string_free(tmp);
|
||||
msg->filename = ssh_string_to_char(tmp);
|
||||
ssh_string_free(tmp);
|
||||
if (msg->filename == NULL) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
@ -134,8 +134,8 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
msg->filename=string_to_char(tmp);
|
||||
string_free(tmp);
|
||||
msg->filename=ssh_string_to_char(tmp);
|
||||
ssh_string_free(tmp);
|
||||
if (msg->filename == NULL) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
@ -165,8 +165,8 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
msg->filename = string_to_char(tmp);
|
||||
string_free(tmp);
|
||||
msg->filename = ssh_string_to_char(tmp);
|
||||
ssh_string_free(tmp);
|
||||
if (msg->filename == NULL) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
@ -181,8 +181,8 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
msg->filename = string_to_char(tmp);
|
||||
string_free(tmp);
|
||||
msg->filename = ssh_string_to_char(tmp);
|
||||
ssh_string_free(tmp);
|
||||
if (msg->filename == NULL) {
|
||||
sftp_client_message_free(msg);
|
||||
return NULL;
|
||||
@ -219,8 +219,8 @@ void sftp_client_message_free(sftp_client_message msg) {
|
||||
}
|
||||
|
||||
SAFE_FREE(msg->filename);
|
||||
string_free(msg->data);
|
||||
string_free(msg->handle);
|
||||
ssh_string_free(msg->data);
|
||||
ssh_string_free(msg->handle);
|
||||
sftp_attributes_free(msg->attr);
|
||||
|
||||
ZERO_STRUCTP(msg);
|
||||
@ -232,14 +232,14 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
ssh_buffer out;
|
||||
ssh_string file;
|
||||
|
||||
out = buffer_new();
|
||||
out = ssh_buffer_new();
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
file = string_from_char(name);
|
||||
file = ssh_string_from_char(name);
|
||||
if (file == NULL) {
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -249,12 +249,12 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
|
||||
buffer_add_attributes(out, attr) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
|
||||
buffer_free(out);
|
||||
string_free(file);
|
||||
ssh_buffer_free(out);
|
||||
ssh_string_free(file);
|
||||
return -1;
|
||||
}
|
||||
buffer_free(out);
|
||||
string_free(file);
|
||||
ssh_buffer_free(out);
|
||||
ssh_string_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -262,7 +262,7 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||
int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
|
||||
ssh_buffer out;
|
||||
|
||||
out = buffer_new();
|
||||
out = ssh_buffer_new();
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -270,10 +270,10 @@ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
|
||||
if (buffer_add_u32(out, msg->id) < 0 ||
|
||||
buffer_add_ssh_string(out, handle) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_HANDLE, out) < 0) {
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
return -1;
|
||||
}
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -281,7 +281,7 @@ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
|
||||
int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
|
||||
ssh_buffer out;
|
||||
|
||||
out = buffer_new();
|
||||
out = ssh_buffer_new();
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -289,10 +289,10 @@ int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
|
||||
if (buffer_add_u32(out, msg->id) < 0 ||
|
||||
buffer_add_attributes(out, attr) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_ATTRS, out) < 0) {
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
return -1;
|
||||
}
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -301,35 +301,35 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
const char *longname, sftp_attributes attr) {
|
||||
ssh_string name;
|
||||
|
||||
name = string_from_char(file);
|
||||
name = ssh_string_from_char(file);
|
||||
if (name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (msg->attrbuf == NULL) {
|
||||
msg->attrbuf = buffer_new();
|
||||
msg->attrbuf = ssh_buffer_new();
|
||||
if (msg->attrbuf == NULL) {
|
||||
string_free(name);
|
||||
ssh_string_free(name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer_add_ssh_string(msg->attrbuf, name) < 0) {
|
||||
string_free(name);
|
||||
ssh_string_free(name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
string_free(name);
|
||||
name = string_from_char(longname);
|
||||
ssh_string_free(name);
|
||||
name = ssh_string_from_char(longname);
|
||||
if (name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
|
||||
buffer_add_attributes(msg->attrbuf,attr) < 0) {
|
||||
string_free(name);
|
||||
ssh_string_free(name);
|
||||
return -1;
|
||||
}
|
||||
string_free(name);
|
||||
ssh_string_free(name);
|
||||
msg->attr_num++;
|
||||
|
||||
return 0;
|
||||
@ -338,24 +338,24 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
|
||||
int sftp_reply_names(sftp_client_message msg) {
|
||||
ssh_buffer out;
|
||||
|
||||
out = buffer_new();
|
||||
out = ssh_buffer_new();
|
||||
if (out == NULL) {
|
||||
buffer_free(msg->attrbuf);
|
||||
ssh_buffer_free(msg->attrbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffer_add_u32(out, msg->id) < 0 ||
|
||||
buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
|
||||
buffer_add_data(out, buffer_get(msg->attrbuf),
|
||||
buffer_get_len(msg->attrbuf)) < 0 ||
|
||||
buffer_add_data(out, ssh_buffer_get_begin(msg->attrbuf),
|
||||
ssh_buffer_get_len(msg->attrbuf)) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
|
||||
buffer_free(out);
|
||||
buffer_free(msg->attrbuf);
|
||||
ssh_buffer_free(out);
|
||||
ssh_buffer_free(msg->attrbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_free(out);
|
||||
buffer_free(msg->attrbuf);
|
||||
ssh_buffer_free(out);
|
||||
ssh_buffer_free(msg->attrbuf);
|
||||
|
||||
msg->attr_num = 0;
|
||||
msg->attrbuf = NULL;
|
||||
@ -368,14 +368,14 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
|
||||
ssh_buffer out;
|
||||
ssh_string s;
|
||||
|
||||
out = buffer_new();
|
||||
out = ssh_buffer_new();
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
s = string_from_char(message ? message : "");
|
||||
s = ssh_string_from_char(message ? message : "");
|
||||
if (s == NULL) {
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -384,13 +384,13 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
|
||||
buffer_add_ssh_string(out, s) < 0 ||
|
||||
buffer_add_u32(out, 0) < 0 || /* language string */
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_STATUS, out) < 0) {
|
||||
buffer_free(out);
|
||||
string_free(s);
|
||||
ssh_buffer_free(out);
|
||||
ssh_string_free(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer_free(out);
|
||||
string_free(s);
|
||||
ssh_buffer_free(out);
|
||||
ssh_string_free(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -398,7 +398,7 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
|
||||
int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
|
||||
ssh_buffer out;
|
||||
|
||||
out = buffer_new();
|
||||
out = ssh_buffer_new();
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -407,10 +407,10 @@ int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
|
||||
buffer_add_u32(out, ntohl(len)) < 0 ||
|
||||
buffer_add_data(out, data, len) < 0 ||
|
||||
sftp_packet_write(msg->sftp, SSH_FXP_DATA, out) < 0) {
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
return -1;
|
||||
}
|
||||
buffer_free(out);
|
||||
ssh_buffer_free(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -445,12 +445,12 @@ ssh_string sftp_handle_alloc(sftp_session sftp, void *info) {
|
||||
}
|
||||
|
||||
val = i;
|
||||
ret = string_new(4);
|
||||
ret = ssh_string_new(4);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(string_data(ret), &val, sizeof(uint32_t));
|
||||
memcpy(ssh_string_data(ret), &val, sizeof(uint32_t));
|
||||
sftp->handles[i] = info;
|
||||
|
||||
return ret;
|
||||
@ -463,11 +463,11 @@ void *sftp_handle(sftp_session sftp, ssh_string handle){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (string_len(handle) != sizeof(uint32_t)) {
|
||||
if (ssh_string_len(handle) != sizeof(uint32_t)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(&val, string_data(handle), sizeof(uint32_t));
|
||||
memcpy(&val, ssh_string_data(handle), sizeof(uint32_t));
|
||||
|
||||
if (val > SFTP_HANDLES) {
|
||||
return NULL;
|
||||
|
@ -131,14 +131,14 @@ ssh_socket ssh_socket_new(ssh_session session) {
|
||||
s->last_errno = -1;
|
||||
s->fd_is_socket = 1;
|
||||
s->session = session;
|
||||
s->in_buffer = buffer_new();
|
||||
s->in_buffer = ssh_buffer_new();
|
||||
if (s->in_buffer == NULL) {
|
||||
SAFE_FREE(s);
|
||||
return NULL;
|
||||
}
|
||||
s->out_buffer=buffer_new();
|
||||
s->out_buffer=ssh_buffer_new();
|
||||
if (s->out_buffer == NULL) {
|
||||
buffer_free(s->in_buffer);
|
||||
ssh_buffer_free(s->in_buffer);
|
||||
SAFE_FREE(s);
|
||||
return NULL;
|
||||
}
|
||||
@ -289,8 +289,8 @@ void ssh_socket_free(ssh_socket s){
|
||||
return;
|
||||
}
|
||||
ssh_socket_close(s);
|
||||
buffer_free(s->in_buffer);
|
||||
buffer_free(s->out_buffer);
|
||||
ssh_buffer_free(s->in_buffer);
|
||||
ssh_buffer_free(s->out_buffer);
|
||||
SAFE_FREE(s);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
*
|
||||
* @return The newly allocated string, NULL on error.
|
||||
*/
|
||||
struct ssh_string_struct *string_new(size_t size) {
|
||||
struct ssh_string_struct *ssh_string_new(size_t size) {
|
||||
struct ssh_string_struct *str = NULL;
|
||||
|
||||
str = malloc(size + 4);
|
||||
@ -70,7 +70,7 @@ struct ssh_string_struct *string_new(size_t size) {
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
int string_fill(struct ssh_string_struct *s, const void *data, size_t len) {
|
||||
int ssh_string_fill(struct ssh_string_struct *s, const void *data, size_t len) {
|
||||
if ((s == NULL) || (data == NULL) ||
|
||||
(len == 0) || (len > s->size)) {
|
||||
return -1;
|
||||
@ -90,7 +90,7 @@ int string_fill(struct ssh_string_struct *s, const void *data, size_t len) {
|
||||
*
|
||||
* @note The nul byte is not copied nor counted in the ouput string.
|
||||
*/
|
||||
struct ssh_string_struct *string_from_char(const char *what) {
|
||||
struct ssh_string_struct *ssh_string_from_char(const char *what) {
|
||||
struct ssh_string_struct *ptr = NULL;
|
||||
size_t len = strlen(what);
|
||||
|
||||
@ -111,7 +111,7 @@ struct ssh_string_struct *string_from_char(const char *what) {
|
||||
*
|
||||
* @return The size of the content of the string, 0 on error.
|
||||
*/
|
||||
size_t string_len(struct ssh_string_struct *s) {
|
||||
size_t ssh_string_len(struct ssh_string_struct *s) {
|
||||
if (s == NULL) {
|
||||
return ntohl(0);
|
||||
}
|
||||
@ -130,7 +130,7 @@ size_t string_len(struct ssh_string_struct *s) {
|
||||
* @note If the input SSH string contains zeroes, some parts of the output
|
||||
* string may not be readable with regular libc functions.
|
||||
*/
|
||||
char *string_to_char(struct ssh_string_struct *s) {
|
||||
char *ssh_string_to_char(struct ssh_string_struct *s) {
|
||||
size_t len = ntohl(s->size) + 1;
|
||||
char *new = malloc(len);
|
||||
|
||||
@ -150,7 +150,7 @@ char *string_to_char(struct ssh_string_struct *s) {
|
||||
*
|
||||
* @return Newly allocated copy of the string, NULL on error.
|
||||
*/
|
||||
struct ssh_string_struct *string_copy(struct ssh_string_struct *s) {
|
||||
struct ssh_string_struct *ssh_string_copy(struct ssh_string_struct *s) {
|
||||
struct ssh_string_struct *new = malloc(ntohl(s->size) + 4);
|
||||
|
||||
if (new == NULL) {
|
||||
@ -167,11 +167,11 @@ struct ssh_string_struct *string_copy(struct ssh_string_struct *s) {
|
||||
*
|
||||
* @param[in] s The string to burn.
|
||||
*/
|
||||
void string_burn(struct ssh_string_struct *s) {
|
||||
void ssh_string_burn(struct ssh_string_struct *s) {
|
||||
if (s == NULL) {
|
||||
return;
|
||||
}
|
||||
memset(s->string, 'X', string_len(s));
|
||||
memset(s->string, 'X', ssh_string_len(s));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +181,7 @@ void string_burn(struct ssh_string_struct *s) {
|
||||
*
|
||||
* @return Return the data of the string or NULL on error.
|
||||
*/
|
||||
void *string_data(struct ssh_string_struct *s) {
|
||||
void *ssh_string_data(struct ssh_string_struct *s) {
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -194,7 +194,7 @@ void *string_data(struct ssh_string_struct *s) {
|
||||
*
|
||||
* \param[in] s The SSH string to delete.
|
||||
*/
|
||||
void string_free(struct ssh_string_struct *s) {
|
||||
void ssh_string_free(struct ssh_string_struct *s) {
|
||||
SAFE_FREE(s);
|
||||
}
|
||||
|
||||
|
@ -26,26 +26,26 @@ void do_connect(SSH_SESSION *session) {
|
||||
return;
|
||||
}
|
||||
printf("Authenticated\n");
|
||||
channel = channel_new(session);
|
||||
channel_open_session(channel);
|
||||
channel = ssh_channel_new(session);
|
||||
ssh_channel_open_session(channel);
|
||||
printf("Execute 'ls' on the channel\n");
|
||||
error = channel_request_exec(channel, "ls");
|
||||
error = ssh_channel_request_exec(channel, "ls");
|
||||
if(error != SSH_OK){
|
||||
fprintf(stderr, "Error executing command: %s\n", ssh_get_error(session));
|
||||
return;
|
||||
}
|
||||
printf("--------------------output----------------------\n");
|
||||
while (channel_read(channel, buf, sizeof(buf), 0)) {
|
||||
while (ssh_channel_read(channel, buf, sizeof(buf), 0)) {
|
||||
printf("%s", buf);
|
||||
}
|
||||
printf("\n");
|
||||
printf("---------------------end------------------------\n");
|
||||
channel_send_eof(channel);
|
||||
fprintf(stderr, "Exit status: %d\n", channel_get_exit_status(channel));
|
||||
ssh_channel_send_eof(channel);
|
||||
fprintf(stderr, "Exit status: %d\n", ssh_channel_get_exit_status(channel));
|
||||
|
||||
printf("\nChannel test finished\n");
|
||||
channel_close(channel);
|
||||
channel_free(channel);
|
||||
ssh_channel_close(channel);
|
||||
ssh_channel_free(channel);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
@ -32,7 +32,7 @@
|
||||
int main(int argc, char **argv){
|
||||
ssh_pcap_file pcap;
|
||||
ssh_pcap_context ctx;
|
||||
ssh_buffer buffer=buffer_new();
|
||||
ssh_buffer buffer=ssh_buffer_new();
|
||||
char *str="Hello, this is a test string to test the capabilities of the"
|
||||
"pcap file writer.";
|
||||
printf("Simple pcap tester\n");
|
||||
|
@ -22,8 +22,8 @@ void do_connect(SSH_SESSION *session){
|
||||
return;
|
||||
}
|
||||
printf("Authenticated\n");
|
||||
CHANNEL *channel=channel_new(session);
|
||||
error=channel_open_forward(channel,"localhost",ECHO_PORT,"localhost",42);
|
||||
CHANNEL *channel=ssh_channel_new(session);
|
||||
error=ssh_channel_open_forward(channel,"localhost",ECHO_PORT,"localhost",42);
|
||||
if(error!=SSH_OK){
|
||||
fprintf(stderr,"Error when opening forward:%s\n",ssh_get_error(session));
|
||||
return;
|
||||
@ -34,14 +34,14 @@ void do_connect(SSH_SESSION *session){
|
||||
char buffer[20];
|
||||
for(i=0;i<2000;++i){
|
||||
sprintf(string,"%d\n",i);
|
||||
channel_write(channel,string,strlen(string));
|
||||
ssh_channel_write(channel,string,strlen(string));
|
||||
do {
|
||||
error=channel_poll(channel,0);
|
||||
error=ssh_channel_poll(channel,0);
|
||||
//if(error < strlen(string))
|
||||
//usleep(10);
|
||||
} while(error < strlen(string) && error >= 0);
|
||||
if(error>0){
|
||||
error=channel_read_nonblocking(channel,buffer,strlen(string),0);
|
||||
error=ssh_channel_read_nonblocking(channel,buffer,strlen(string),0);
|
||||
if(error>=0){
|
||||
if(memcmp(buffer,string,strlen(string))!=0){
|
||||
fprintf(stderr,"Problem with answer: wanted %s got %s\n",string,buffer);
|
||||
@ -58,8 +58,8 @@ void do_connect(SSH_SESSION *session){
|
||||
}
|
||||
}
|
||||
printf("\nChannel test finished\n");
|
||||
channel_close(channel);
|
||||
channel_free(channel);
|
||||
ssh_channel_close(channel);
|
||||
ssh_channel_free(channel);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
@ -64,7 +64,7 @@ START_TEST (torture_pubkey_from_file)
|
||||
|
||||
ck_assert_msg(rc == 0,ssh_get_error(session));
|
||||
|
||||
string_free(pubkey);
|
||||
ssh_string_free(pubkey);
|
||||
|
||||
/* test if it returns 1 if pubkey doesn't exist */
|
||||
unlink(LIBSSH_RSA_TESTKEY ".pub");
|
||||
@ -138,9 +138,9 @@ START_TEST (torture_pubkey_generate_from_privkey)
|
||||
|
||||
ck_assert_msg(pubkey_new != NULL,ssh_get_error(session));
|
||||
|
||||
ck_assert(string_len(pubkey_orig) == string_len(pubkey_new));
|
||||
ck_assert(memcmp(string_data(pubkey_orig), string_data(pubkey_new),
|
||||
string_len(pubkey_orig)) == 0);
|
||||
ck_assert(ssh_string_len(pubkey_orig) == ssh_string_len(pubkey_new));
|
||||
ck_assert(memcmp(ssh_string_data(pubkey_orig), ssh_string_data(pubkey_new),
|
||||
ssh_string_len(pubkey_orig)) == 0);
|
||||
|
||||
rc = ssh_publickey_to_file(session, LIBSSH_RSA_TESTKEY ".pub", pubkey_new, type_new);
|
||||
ck_assert_msg(rc == 0,ssh_get_error(session));
|
||||
@ -150,8 +150,8 @@ START_TEST (torture_pubkey_generate_from_privkey)
|
||||
|
||||
ck_assert_str_eq(pubkey_line_orig, pubkey_line_new);
|
||||
|
||||
string_free(pubkey_orig);
|
||||
string_free(pubkey_new);
|
||||
ssh_string_free(pubkey_orig);
|
||||
ssh_string_free(pubkey_new);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user