Commit e7873f42 authored by Pontus Freyhult's avatar Pontus Freyhult

* commands.c (com_lpwd): Don't assume getcwd with extended

functionality, use 8192 as a fallback if PATH_MAX is undefined.

* configure.ac: Check for canonicalize_file_name.

* commands.c (get_file_or_folder): Use canonicalize_file_name
instead of realpath.
(put_file_or_folder): Dito.

* gnu_stuff.c: Added compability function for systems without
canonicalize_file_name.

* gnu_stuff.h: Declaration of compability function.

* str_utils.h: Changed declaration of lsftp_s_strtok, take a char** to
fill in with a new allocated string instead of a buffer and it's
length.

* str_utils.c (lsftp_s_strtok): See above.

* commands.c: Changed to use the new lsftp_s_strtok.

* rl.c (lsftp_rl_completion): Dito.

* sftp_bind.c (lsftp_open_connection): Dito.

Rev: src/sftp/ChangeLog:1.31
Rev: src/sftp/commands.c:1.11
Rev: src/sftp/configure.ac:1.12
Rev: src/sftp/gnu_stuff.c:1.5
Rev: src/sftp/gnu_stuff.h:1.3
Rev: src/sftp/rl.c:1.6
Rev: src/sftp/sftp_bind.c:1.11
Rev: src/sftp/str_utils.c:1.3
Rev: src/sftp/str_utils.h:1.3
parent afd66d04
2002-06-06 Pontus Skld <pont@soua.net>
* commands.c (com_lpwd): Don't assume getcwd with extended
functionality, use 8192 as a fallback if PATH_MAX is undefined.
* configure.ac: Check for canonicalize_file_name.
* commands.c (get_file_or_folder): Use canonicalize_file_name
instead of realpath.
(put_file_or_folder): Dito.
* gnu_stuff.c: Added compability function for systems without
canonicalize_file_name.
* gnu_stuff.h: Declaration of compability function.
2002-06-05 Pontus Skld <pont@soua.net>
* str_utils.h: Changed declaration of lsftp_s_strtok, take a
char** to fill in with a new allocated string instead of a buffer
and it's length.
* str_utils.c (lsftp_s_strtok): See above.
* commands.c: Changed to use the new lsftp_s_strtok.
* rl.c (lsftp_rl_completion): Dito.
* sftp_bind.c (lsftp_open_connection): Dito.
2002-05-26 Pontus Skld <pont@soua.net>
* rl.c (lsftp_rl_remotefile_generator):
......
This diff is collapsed.
......@@ -316,7 +316,7 @@ AC_HEADER_TIME
AC_CHECK_FUNCS([getcwd getwd strcoll strdup getenv fnmatch dup2])
AC_CHECK_FUNCS([getcwd getwd strcoll strdup getenv fnmatch dup2 canonicalize_file_name])
......
......@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void lsftp_welcome()
{
......@@ -113,3 +114,39 @@ void do_gnu_stuff( const char** argv )
}
#ifndef HAVE_CANONICALIZE_FILE_NAME
/* Compability function, taken from a parted patch */
char*
canonicalize_file_name (const char* name)
{
char* buf;
int size;
char* result;
#ifdef PATH_MAX
size = PATH_MAX;
#else
/* Bigger is better; realpath has no way todo bounds checking. */
size = 4096;
#endif
/* Just in case realpath does not NULL terminate the string
* or it just fits in SIZE without a NULL terminator. */
buf = calloc( size + 1, 1 );
if( !buf )
{
errno = ENOMEM;
return NULL;
}
result = realpath(name, buf);
if (! result)
free (buf);
return result;
}
#endif /* !HAVE_CANONICALIZE_FILE_NAME */
......@@ -37,4 +37,10 @@ void version_option(void);
void lsftp_welcome(void);
void do_gnu_stuff( const char** argv );
#ifndef HAVE_CANONICALIZE_FILE_NAME
char* canonicalize_file_name (const char* name);
#endif
#endif /* LSFTP_GNU_STUFF_H */
......@@ -208,48 +208,52 @@ n */
else
{
/* We're not completing the command */
char tmp[256];
char* tmp;
int i=0;
char* cmdname;
/* Get the first word from the line (the command) */
lsftp_s_strtok( rl_line_buffer+s," \n\t\r", tmp, 256 );
lsftp_s_strtok( rl_line_buffer+s," \n\t\r", &tmp );
while( (cmdname = commands[i].name) )
if ( ! strncmp( cmdname, tmp, commands[i++].uniquelen ) ) /* We've got the command? */
switch ( commands[i-1].arg_type )
{
case COMMAND: /* Command takes a command as argument? */
matches = RL_COMPLETION_MATCHES(
text,
lsftp_rl_command_generator
);
break;
case REMOTEFILE: /* Remote file or dir as argument? */
matches = RL_COMPLETION_MATCHES(
text,
lsftp_rl_remotefile_generator
);
break;
case LOCALFILE:
matches = RL_COMPLETION_MATCHES(
{
if ( ! strncmp( cmdname, tmp, commands[i++].uniquelen ) ) /* We've got the command? */
switch ( commands[i-1].arg_type )
{
case COMMAND: /* Command takes a command as argument? */
matches = RL_COMPLETION_MATCHES(
text,
lsftp_rl_command_generator
);
break;
case REMOTEFILE: /* Remote file or dir as argument? */
matches = RL_COMPLETION_MATCHES(
text,
lsftp_rl_remotefile_generator
);
break;
case LOCALFILE:
matches = RL_COMPLETION_MATCHES(
text,
RL_FILENAME_COMPLETION_FUNCTION
);
break;
default:
case NOARG: /* Doesn't take any argument? */
matches = RL_COMPLETION_MATCHES(
text,
lsftp_rl_no_generator
);
break;
}
default:
case NOARG: /* Doesn't take any argument? */
matches = RL_COMPLETION_MATCHES(
text,
lsftp_rl_no_generator
);
break;
}
free( tmp );
}
if( !matches ) /* No matching command? */
{
......
......@@ -158,7 +158,7 @@ int lsftp_open_connection(char** argv, int argc)
int j = 0;
int i;
char tmp[PATH_MAX];
char* tmp;
char* lsh_name=NULL;
char** new_argv=NULL;
const char* before_string;
......@@ -182,12 +182,14 @@ int lsftp_open_connection(char** argv, int argc)
lsftp_s_strtok(
cur_string, /* Old startat */
" \r\n\t", /* Separators */
tmp, /* Store in */
PATH_MAX /* Storage length */
&tmp /* Storage adress */
)
)
)
k++;
{
k++;
free( tmp );
}
/* And also after */
......@@ -199,18 +201,18 @@ int lsftp_open_connection(char** argv, int argc)
cur_string = after_string;
while( (
cur_string =
lsftp_s_strtok(
cur_string, /* Old startat */
" \r\n\t", /* Separators */
tmp, /* Store in */
PATH_MAX /* Storage length */
)
)
)
k++;
while(
cur_string =
lsftp_s_strtok(
cur_string, /* Old startat */
" \r\n\t", /* Separators */
&tmp /* Storage */
)
)
{
k++;
free( tmp );
}
new_argv = malloc( ( argc + k + 1 ) * sizeof( char* ) ); /* k new
arguments,
......@@ -223,18 +225,16 @@ int lsftp_open_connection(char** argv, int argc)
cur_string = before_string;
while( (
cur_string =
lsftp_s_strtok(
cur_string, /* Old startat */
" \r\n\t", /* Separators */
tmp, /* Store in */
PATH_MAX /* Storage length */
)
)
)
/* Make a copy of the string and pass it as an argument */
new_argv[ ++j ] = strdup(tmp);
while(
cur_string =
lsftp_s_strtok(
cur_string, /* Old startat */
" \r\n\t", /* Separators */
&tmp /* Storage */
)
)
/* Pass it as an argument */
new_argv[ ++j ] = tmp;
i = 1; /* argv[0] doesn't interest us */
......@@ -252,13 +252,12 @@ int lsftp_open_connection(char** argv, int argc)
lsftp_s_strtok(
cur_string, /* Old startat */
" \r\n\t", /* Separators */
tmp, /* Store in */
PATH_MAX /* Storage length */
&tmp /* Storage */
)
)
)
/* Make a copy of the string and pass it as an argument */
new_argv[ j++ ] = strdup(tmp);
new_argv[ j++ ] = tmp;
new_argv[ j++ ] = 0;
......
......@@ -139,18 +139,19 @@ lsftp_unqoute( char* s )
const char *
lsftp_s_strtok(const char* s, const char* sep,
char *store, int storelen )
char **store )
{
/* TODO: should we do this different to support char-types with more than eight bits? */
int copychars;
char* tend;
char* scopy;
*store = NULL;
if( !s ) /* NULL-address given? */
return NULL;
/* Skip any starting separators */
s = lsftp_s_skip( s, sep );
......@@ -159,15 +160,16 @@ lsftp_s_strtok(const char* s, const char* sep,
if( !s || !(*s) ) /* No string or ended without a token (only contained separators) */
return NULL;
tend = lsftp_s_skipn( s, sep ); /* Find the first separator in our new s */
copychars = ( tend-s > storelen-1 ? storelen-1 : tend-s );
/* The number of bytes to copy is min(tend-tstart,storelen-1) */
tend = lsftp_s_skipn( s, sep ); /* Find the first separator in our new s (or it's end) */
scopy = strndup(s, tend-s); /* Put the token in store */
strncpy(store, s, copychars); /* Put the token in store */
if( !scopy )
return NULL;
store[copychars]=0; /* Make sure it is null-terminated */
scopy[tend-s] = 0; /* Make sure it is null-terminated */
*store = scopy;
return tend; /* Return a pointer to where we haven't yet looked */
}
......
......@@ -41,7 +41,7 @@ char* lsftp_unquote( const char* s );
/* Given a string and a set of tokens, place in store (is of size storelen) */
const char *lsftp_s_strtok(const char *s, const char* tok,
char *store, int storelen);
char **store);
const char *lsftp_s_skip(const char *s, const char *sep);
const char* lsftp_s_skipn(const char *s, const char *sep );
......
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