Commit da9d1ae8 authored by Pontus Freyhult's avatar Pontus Freyhult

"The early bird finds the bug"-checkin. Various cocmetic fixes and a

rather important fix (the two callback storages were mixed up). Also a
fix for the callback compact routine.

This fixes batch mode so it doesn't hang without doing anything.

Rev: src/sftp/ChangeLog:1.5
Rev: src/sftp/dc.c:1.3
Rev: src/sftp/lsftp.c:1.3
Rev: src/sftp/sftp_bind.c:1.4
Rev: src/sftp/sftp_bind.h:1.3
parent d45031ec
2002-02-25 Pontus <pont@it.uu.se>
* sftp_bind.c (lsftp_lsftp_cb_init): Fixed a bug using the same
memory both for sftp_cbs and lsftp_cbs, mumble!
2002-02-24 Pontus <pont@it.uu.se>
* sftp_bind.c (lsftp_remove_lsftp_cb): Use lsftp_nullcb to clean
out callback.
(lsftp_handle_packet): Changed variable i (used twice) to r.
* sftp_bind.h: New function lsftp_nullcb.
* sftp_bind.c (lsftp_compact_sftp_cbs): Fixed a bug that would
loose callbacks before a hole if there were any more.
(lsftp_compact_lsftp_cbs): Fixed the same bug for struct
lsftp_callbacks.
(lsftp_handle_packet): Clean out old state after callbacks, should
hopefully make things more robust.
(lsftp_nullcb): New function to clean a struct lsftp_callback.
* dc.c (lsftp_dc_init): Check that malloc succeeded before using
the memory (duh!).
* sftp_bind.c: Removed obsolete default callback array sizes.
* dc.c: Removed obsolete default dircache size.
* lsftp.c (main): Always init the callbacks.
* sftp_bind.c (lsftp_lsftp_cb_init): Also clear option flags.
* lsftp.c (main): Added some comments.
* sftp_bind.c (lsftp_do_put): Added some comments.
2002-02-22 Pontus <pont@it.uu.se>
* configure.ac (lsh_cv_c_attribute): Removed obsolete checks for
......
......@@ -26,7 +26,7 @@
#include "dc.h"
static int dc_entries = 1024;
static int dc_entries = 0;
static struct lsftp_dc_s* lsftp_dircache = 0;
int lsftp_dc_init( int new_dc_entries )
......@@ -42,6 +42,9 @@ int lsftp_dc_init( int new_dc_entries )
lsftp_dircache = malloc( sizeof( struct lsftp_dc_s ) * dc_entries );
if( !lsftp_dircache ) /* malloc failed? */
return -1;
for( i = 0; i < dc_entries; i++ )
{
lsftp_dircache[i].name = 0;
......
......@@ -149,7 +149,7 @@ lsftp_noninteractive_mainloop(int startat, char **argv)
while( !done && !fail )
{
while( !fail && lsftp_active_cbs() )
if( -1 == lsftp_callback() ) /* Checks itself with select */
if( -1 == lsftp_callback() ) /* Checks itself with select */
{
printf( "Failure!\n");
fail++;
......@@ -181,16 +181,17 @@ int main(int argc, char** argv, char** envp)
if( interactive )
lsftp_welcome();
lsftp_sftp_init();
if( 1 < argc - i ) /* Only connect if given arguments */
{
lsftp_open_connection( argv, argc - i );
lsftp_handshake();
lsftp_sftp_init();
lsftp_do_cd( "" ); /* Change to our home directory */
}
lsftp_dc_init( 1024 );
lsftp_dc_init( 1024 ); /* Set up the directory cache */
if( interactive )
lsftp_interactive_mainloop();
......
......@@ -34,8 +34,8 @@ static FILE* from_transport;
static int transport_pid = 0;
static int sftp_callbacks = 256;
static int lsftp_callbacks = 256;
static int sftp_callbacks = 0;
static int lsftp_callbacks = 0;
static int fd_to_transport = -1;
static int fd_from_transport = -1;
......@@ -481,9 +481,6 @@ lsftp_handle_packet(void)
printf( "Bad read!\n" );
/* printf( "Id: %d\n", id ); */
/* printf( "Msg: %d\n", msg ); */
for( i = 0; i < sftp_callbacks; i++ )
if(
id && /* We never send the id zero */
......@@ -499,20 +496,19 @@ lsftp_handle_packet(void)
sftp_cbs[i].nextfun(&state, msg, id, in, out, &sftp_cbs[i]);
sftp_cbs[i] = state; /* Replace old callback with the new one */
/* printf( "Returned from packet nextfun\n "); */
if( ! state.id ) /* No next callback? */
{
int op_id = state.op_id;
sftp_null_state( &sftp_cbs[i] ); /* Clean out old state */
for( j = 0; j < lsftp_callbacks; j++ )
if( lsftp_cbs[j].op_id == op_id )
{
int i;
int r;
/* printf( "Doing lsftp callback\n "); */
/* Do callback */
i = lsftp_cbs[j].nextfun(&state, &lsftp_cbs[j]);
r = lsftp_cbs[j].nextfun(&state, &lsftp_cbs[j]);
/* Free any memory used */
if( lsftp_cbs[j].a )
......@@ -526,23 +522,16 @@ lsftp_handle_packet(void)
if( lsftp_cbs[j].command )
free( (void *) lsftp_cbs[j].command );
lsftp_cbs[j].op_id = 0; /* Remove id so it can be reused */
lsftp_cbs[j].st = 0;
lsftp_cbs[j].a = 0;
lsftp_cbs[j].local = 0;
lsftp_cbs[j].remote = 0;
lsftp_cbs[j].command = 0;
lsftp_cbs[j].memory = 0;
lsftp_cbs[j].opt1 = 0;
lsftp_cbs[j].opt2 = 0;
return i;
lsftp_nullcb( &lsftp_cbs[j] ); /* Clean out struct */
return r;
}
}
}
/* printf( "Returning from packet handler\n "); */
return 0; /* No callback found, ignored */
}
......@@ -926,18 +915,11 @@ lsftp_install_lsftp_cb(lsftp_callback_func nextfun)
struct lsftp_callback lcb;
i = lsftp_free_lsftp_cb();
lcb.a = 0;
lcb.st = 0;
lcb.local = 0;
lcb.command = 0;
lcb.remote = 0;
lcb.op_id = id;
lcb.opt1 = 0;
lcb.opt2 = 0;
lcb.nextfun = nextfun;
lsftp_nullcb( &lcb ); /* Nullify callback */
lcb.nextfun = nextfun;
lcb.op_id = id;
if( i == -1 )
return 0;
......@@ -985,24 +967,26 @@ int lsftp_await_command( int id )
void lsftp_nullcb( struct lsftp_callback* nullcb )
{
nullcb->nextfun = 0;
nullcb->op_id = 0;
nullcb->local = 0;
nullcb->remote = 0;
nullcb->command = 0;
nullcb->st = 0;
nullcb->a = 0;
nullcb->memory = 0;
nullcb->opt1 = 0;
nullcb->opt2 = 0;
nullcb->opt3 = 0;
}
int lsftp_lsftp_cb_init( int new_lsftp_callbacks )
{
int i = 0;
void* newmem;
struct lsftp_callback nullcb;
nullcb.nextfun = 0;
nullcb.op_id = 0;
nullcb.local = 0;
nullcb.remote = 0;
nullcb.command = 0;
nullcb.st = 0;
nullcb.a = 0;
nullcb.memory = 0;
if( lsftp_cbs )
i = lsftp_compact_lsftp_cbs();
......@@ -1010,7 +994,7 @@ int lsftp_lsftp_cb_init( int new_lsftp_callbacks )
if( i > new_lsftp_callbacks ) /* Too few callbacks to fit existing */
return -1;
newmem = realloc( sftp_cbs, sizeof( struct sftp_callback ) * new_lsftp_callbacks );
newmem = realloc( lsftp_cbs, sizeof( struct sftp_callback ) * new_lsftp_callbacks );
if( !newmem ) /* realloc failed? */
{
......@@ -1022,7 +1006,7 @@ int lsftp_lsftp_cb_init( int new_lsftp_callbacks )
lsftp_callbacks = new_lsftp_callbacks;
for( ; i < lsftp_callbacks; i++ )
lsftp_cbs[i] = nullcb;
lsftp_nullcb( &lsftp_cbs[i] );
return 0;
}
......@@ -1058,10 +1042,12 @@ int lsftp_compact_lsftp_cbs()
)
{
if( index > used ) /* That should be moved? */
lsftp_cbs[used++] = lsftp_cbs[index];
{
lsftp_cbs[used++] = lsftp_cbs[index]; /* Copy closer to base */
lsftp_nullcb( &lsftp_cbs[index] ); /* Clean it out */
}
else
/* FIXME: What's intended here? */
used; /* Don't move, just count */
used++; /* Don't move, just count */
}
index++;
}
......@@ -1085,7 +1071,9 @@ int lsftp_sftp_cb_init( int new_sftp_callbacks )
if( i > new_sftp_callbacks ) /* Too few callbacks to fit existing */
return -1;
newmem = realloc( sftp_cbs, sizeof( struct sftp_callback ) * new_sftp_callbacks );
newmem = realloc( sftp_cbs,
sizeof( struct sftp_callback ) * new_sftp_callbacks
);
if( !newmem ) /* realloc failed? */
{
......@@ -1096,7 +1084,7 @@ int lsftp_sftp_cb_init( int new_sftp_callbacks )
sftp_callbacks = new_sftp_callbacks;
sftp_cbs = newmem;
for( ; i < sftp_callbacks; i++ )
for( ; i < sftp_callbacks; i++ ) /* Clear any newly allocated slots */
sftp_null_state(&sftp_cbs[i]);
......@@ -1138,10 +1126,12 @@ int lsftp_compact_sftp_cbs()
)
{
if( index > used ) /* That should be moved? */
sftp_cbs[used++] = sftp_cbs[index];
{
sftp_cbs[used++] = sftp_cbs[index]; /* Copy closer to base */
sftp_null_state( &sftp_cbs[index] ); /* Clean it out */
}
else
/* FIXME: What's intended here? */
used; /* Don't move, just count */
used++; /* Don't move it, just count */
}
index++;
}
......@@ -1160,7 +1150,7 @@ lsftp_install_sftp_cb(struct sftp_callback *s)
i = lsftp_free_sftp_cb();
if( i == -1 )
if( i == -1 ) /* Failed to find any free slot */
return 0;
sftp_cbs[i] = *s;
......@@ -1179,7 +1169,7 @@ lsftp_remove_sftp_cb(UINT32 id)
for( j = 0; j < sftp_callbacks; j++ )
if( sftp_cbs[j].id == id ) /* Callback is free? */
{
sftp_cbs[j].id = 0;
sftp_null_state( sftp_cbs[j].id );
flag++;
}
......@@ -1196,7 +1186,7 @@ lsftp_remove_lsftp_cb(int id)
for( j = 0, flag = 0; j < lsftp_callbacks; j++ )
if( lsftp_cbs[j].op_id == id ) /* Callback is free? */
{
lsftp_cbs[j].op_id = 0;
lsftp_nullcb( &lsftp_cbs[j] );
flag++;
}
......@@ -1232,7 +1222,7 @@ lsftp_do_cd(const char *dir)
{
/* Here we only go if we have a curpath and the new path is relative */
char* tmp;
char* tmp = 0;
if( !dir[0] ) /* Empty path? Special case, reset path */
{
......@@ -1245,11 +1235,7 @@ lsftp_do_cd(const char *dir)
{
/* Two strings with a / to separate them */
char* tmp1;
tmp = 0;
tmp1 = lsftp_concat( curpath, "/" ); /* curpath/ */
char* tmp1 = lsftp_concat( curpath, "/" ); /* curpath/ */
if( tmp1 )
tmp = lsftp_concat( tmp1, dir ); /* Add new path */
......@@ -1261,6 +1247,7 @@ lsftp_do_cd(const char *dir)
}
free( (void *) curpath );
curpath = tmp;
}
......@@ -1386,8 +1373,8 @@ lsftp_do_put(const char *local, const char *remote,
tmp = remote;
}
lsftp_cbs[index].local = strdup( local );
lsftp_cbs[index].remote = strdup( tmp );
lsftp_cbs[index].local = strdup( local ); /* These are not critical, so*/
lsftp_cbs[index].remote = strdup( tmp ); /* we ignore if they succeed*/
lsftp_cbs[index].command = strdup( command );
lsftp_safe_to_write(); /* Wait for any unsent packet to go away */
......@@ -1400,9 +1387,9 @@ lsftp_do_put(const char *local, const char *remote,
if( freeflag )
free( (void *) tmp );
if( s.nextfun )
if( s.nextfun ) /* We should have a callback */
lsftp_install_sftp_cb( &s );
else
else /* Lack of callback means error */
{
lsftp_perror( local, s.localerrno );
lsftp_remove_lsftp_cb( id );
......@@ -2214,11 +2201,8 @@ lsftp_handle_realpath(struct sftp_callback *s,
UINT32 longnamelen;
void* attrib;
UINT32 attriblen;
/* FIXME: Not used? */
struct sftp_attrib *a;
char** destptr;
lenptr = sftp_retrieve( &s->mem, 4, &slen); /* Get string length */
if( slen != 4 )
......@@ -2649,8 +2633,6 @@ lsftp_do_rmdir(const char *dir, const char *command)
const char* tmp;
struct sftp_callback s;
/* FIXME: Unsued? */
struct sftp_attrib* attrib;
id = lsftp_install_lsftp_cb( lsftp_handle_alldir );
index = lsftp_cb_index( id );
......@@ -2700,7 +2682,6 @@ lsftp_do_rm(const char *path, const char *command )
const char* tmp;
struct sftp_callback s;
struct sftp_attrib* attrib;
id = lsftp_install_lsftp_cb( lsftp_handle_alldir );
index = lsftp_cb_index( id );
......
......@@ -55,7 +55,6 @@
#define DEFAULT_AFTER_ARGS TRANSPORT_AFTER_OPTS
#endif /* TRANSPORT_AFTER_OPTS */
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
......@@ -159,6 +158,7 @@ int lsftp_handle_alldir(struct sftp_callback *s,
int lsftp_install_lsftp_cb(lsftp_callback_func nextfun);
int lsftp_install_sftp_cb(struct sftp_callback *s);
void lsftp_nullcb( struct lsftp_callback* nullcb );
int lsftp_sftp_cb_init( int new_sftp_callbacks );
void lsftp_sftp_cb_uninit(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment