version 1.6.2.4, 2001/05/07 21:09:34 |
version 1.6.2.5, 2001/09/27 00:15:42 |
|
|
/* |
/* |
* Copyright (c) 2000 Markus Friedl. All rights reserved. |
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
Attrib attrib; |
Attrib attrib; |
}; |
}; |
|
|
int |
static int |
errno_to_portable(int unixerrno) |
errno_to_portable(int unixerrno) |
{ |
{ |
int ret = 0; |
int ret = 0; |
|
|
return ret; |
return ret; |
} |
} |
|
|
int |
static int |
flags_from_portable(int pflags) |
flags_from_portable(int pflags) |
{ |
{ |
int flags = 0; |
int flags = 0; |
|
|
return flags; |
return flags; |
} |
} |
|
|
Attrib * |
static Attrib * |
get_attrib(void) |
get_attrib(void) |
{ |
{ |
return decode_attrib(&iqueue); |
return decode_attrib(&iqueue); |
|
|
|
|
Handle handles[100]; |
Handle handles[100]; |
|
|
void |
static void |
handle_init(void) |
handle_init(void) |
{ |
{ |
int i; |
int i; |
|
|
handles[i].use = HANDLE_UNUSED; |
handles[i].use = HANDLE_UNUSED; |
} |
} |
|
|
int |
static int |
handle_new(int use, char *name, int fd, DIR *dirp) |
handle_new(int use, char *name, int fd, DIR *dirp) |
{ |
{ |
int i; |
int i; |
|
|
return -1; |
return -1; |
} |
} |
|
|
int |
static int |
handle_is_ok(int i, int type) |
handle_is_ok(int i, int type) |
{ |
{ |
return i >= 0 && i < sizeof(handles)/sizeof(Handle) && |
return i >= 0 && i < sizeof(handles)/sizeof(Handle) && |
handles[i].use == type; |
handles[i].use == type; |
} |
} |
|
|
int |
static int |
handle_to_string(int handle, char **stringp, int *hlenp) |
handle_to_string(int handle, char **stringp, int *hlenp) |
{ |
{ |
if (stringp == NULL || hlenp == NULL) |
if (stringp == NULL || hlenp == NULL) |
|
|
return 0; |
return 0; |
} |
} |
|
|
int |
static int |
handle_from_string(char *handle, u_int hlen) |
handle_from_string(char *handle, u_int hlen) |
{ |
{ |
int val; |
int val; |
|
|
return -1; |
return -1; |
} |
} |
|
|
char * |
static char * |
handle_to_name(int handle) |
handle_to_name(int handle) |
{ |
{ |
if (handle_is_ok(handle, HANDLE_DIR)|| |
if (handle_is_ok(handle, HANDLE_DIR)|| |
|
|
return NULL; |
return NULL; |
} |
} |
|
|
DIR * |
static DIR * |
handle_to_dir(int handle) |
handle_to_dir(int handle) |
{ |
{ |
if (handle_is_ok(handle, HANDLE_DIR)) |
if (handle_is_ok(handle, HANDLE_DIR)) |
|
|
return NULL; |
return NULL; |
} |
} |
|
|
int |
static int |
handle_to_fd(int handle) |
handle_to_fd(int handle) |
{ |
{ |
if (handle_is_ok(handle, HANDLE_FILE)) |
if (handle_is_ok(handle, HANDLE_FILE)) |
|
|
return -1; |
return -1; |
} |
} |
|
|
int |
static int |
handle_close(int handle) |
handle_close(int handle) |
{ |
{ |
int ret = -1; |
int ret = -1; |
|
|
return ret; |
return ret; |
} |
} |
|
|
int |
static int |
get_handle(void) |
get_handle(void) |
{ |
{ |
char *handle; |
char *handle; |
|
|
|
|
/* send replies */ |
/* send replies */ |
|
|
void |
static void |
send_msg(Buffer *m) |
send_msg(Buffer *m) |
{ |
{ |
int mlen = buffer_len(m); |
int mlen = buffer_len(m); |
|
|
buffer_consume(m, mlen); |
buffer_consume(m, mlen); |
} |
} |
|
|
void |
static void |
send_status(u_int32_t id, u_int32_t error) |
send_status(u_int32_t id, u_int32_t error) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
send_msg(&msg); |
send_msg(&msg); |
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
void |
static void |
send_data_or_handle(char type, u_int32_t id, char *data, int dlen) |
send_data_or_handle(char type, u_int32_t id, char *data, int dlen) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
|
|
void |
static void |
send_data(u_int32_t id, char *data, int dlen) |
send_data(u_int32_t id, char *data, int dlen) |
{ |
{ |
TRACE("sent data id %d len %d", id, dlen); |
TRACE("sent data id %d len %d", id, dlen); |
send_data_or_handle(SSH2_FXP_DATA, id, data, dlen); |
send_data_or_handle(SSH2_FXP_DATA, id, data, dlen); |
} |
} |
|
|
void |
static void |
send_handle(u_int32_t id, int handle) |
send_handle(u_int32_t id, int handle) |
{ |
{ |
char *string; |
char *string; |
|
|
xfree(string); |
xfree(string); |
} |
} |
|
|
void |
static void |
send_names(u_int32_t id, int count, Stat *stats) |
send_names(u_int32_t id, int count, Stat *stats) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
|
|
void |
static void |
send_attrib(u_int32_t id, Attrib *a) |
send_attrib(u_int32_t id, Attrib *a) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
|
|
/* parse incoming */ |
/* parse incoming */ |
|
|
void |
static void |
process_init(void) |
process_init(void) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
|
|
void |
static void |
process_open(void) |
process_open(void) |
{ |
{ |
u_int32_t id, pflags; |
u_int32_t id, pflags; |
|
|
xfree(name); |
xfree(name); |
} |
} |
|
|
void |
static void |
process_close(void) |
process_close(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
|
send_status(id, status); |
send_status(id, status); |
} |
} |
|
|
void |
static void |
process_read(void) |
process_read(void) |
{ |
{ |
char buf[64*1024]; |
char buf[64*1024]; |
|
|
send_status(id, status); |
send_status(id, status); |
} |
} |
|
|
void |
static void |
process_write(void) |
process_write(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
|
xfree(data); |
xfree(data); |
} |
} |
|
|
void |
static void |
process_do_stat(int do_lstat) |
process_do_stat(int do_lstat) |
{ |
{ |
Attrib a; |
Attrib a; |
|
|
xfree(name); |
xfree(name); |
} |
} |
|
|
void |
static void |
process_stat(void) |
process_stat(void) |
{ |
{ |
process_do_stat(0); |
process_do_stat(0); |
} |
} |
|
|
void |
static void |
process_lstat(void) |
process_lstat(void) |
{ |
{ |
process_do_stat(1); |
process_do_stat(1); |
} |
} |
|
|
void |
static void |
process_fstat(void) |
process_fstat(void) |
{ |
{ |
Attrib a; |
Attrib a; |
|
|
send_status(id, status); |
send_status(id, status); |
} |
} |
|
|
struct timeval * |
static struct timeval * |
attrib_to_tv(Attrib *a) |
attrib_to_tv(Attrib *a) |
{ |
{ |
static struct timeval tv[2]; |
static struct timeval tv[2]; |
|
|
return tv; |
return tv; |
} |
} |
|
|
void |
static void |
process_setstat(void) |
process_setstat(void) |
{ |
{ |
Attrib *a; |
Attrib *a; |
|
|
xfree(name); |
xfree(name); |
} |
} |
|
|
void |
static void |
process_fsetstat(void) |
process_fsetstat(void) |
{ |
{ |
Attrib *a; |
Attrib *a; |
|
|
send_status(id, status); |
send_status(id, status); |
} |
} |
|
|
void |
static void |
process_opendir(void) |
process_opendir(void) |
{ |
{ |
DIR *dirp = NULL; |
DIR *dirp = NULL; |
|
|
/* |
/* |
* drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh |
* drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh |
*/ |
*/ |
char * |
static char * |
ls_file(char *name, struct stat *st) |
ls_file(char *name, struct stat *st) |
{ |
{ |
int sz = 0; |
int ulen, glen, sz = 0; |
struct passwd *pw; |
struct passwd *pw; |
struct group *gr; |
struct group *gr; |
struct tm *ltime = localtime(&st->st_mtime); |
struct tm *ltime = localtime(&st->st_mtime); |
|
|
} |
} |
if (sz == 0) |
if (sz == 0) |
tbuf[0] = '\0'; |
tbuf[0] = '\0'; |
snprintf(buf, sizeof buf, "%s %3d %-8.8s %-8.8s %8llu %s %s", mode, |
ulen = MAX(strlen(user), 8); |
st->st_nlink, user, group, (unsigned long long)st->st_size, tbuf, name); |
glen = MAX(strlen(group), 8); |
|
snprintf(buf, sizeof buf, "%s %3d %-*s %-*s %8llu %s %s", mode, |
|
st->st_nlink, ulen, user, glen, group, |
|
(unsigned long long)st->st_size, tbuf, name); |
return xstrdup(buf); |
return xstrdup(buf); |
} |
} |
|
|
void |
static void |
process_readdir(void) |
process_readdir(void) |
{ |
{ |
DIR *dirp; |
DIR *dirp; |
|
|
stats = xrealloc(stats, nstats * sizeof(Stat)); |
stats = xrealloc(stats, nstats * sizeof(Stat)); |
} |
} |
/* XXX OVERFLOW ? */ |
/* XXX OVERFLOW ? */ |
snprintf(pathname, sizeof pathname, |
snprintf(pathname, sizeof pathname, "%s%s%s", path, |
"%s/%s", path, dp->d_name); |
strcmp(path, "/") ? "/" : "", dp->d_name); |
if (lstat(pathname, &st) < 0) |
if (lstat(pathname, &st) < 0) |
continue; |
continue; |
stat_to_attrib(&st, &(stats[count].attrib)); |
stat_to_attrib(&st, &(stats[count].attrib)); |
|
|
} |
} |
} |
} |
|
|
void |
static void |
process_remove(void) |
process_remove(void) |
{ |
{ |
char *name; |
char *name; |
|
|
xfree(name); |
xfree(name); |
} |
} |
|
|
void |
static void |
process_mkdir(void) |
process_mkdir(void) |
{ |
{ |
Attrib *a; |
Attrib *a; |
|
|
xfree(name); |
xfree(name); |
} |
} |
|
|
void |
static void |
process_rmdir(void) |
process_rmdir(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
|
xfree(name); |
xfree(name); |
} |
} |
|
|
void |
static void |
process_realpath(void) |
process_realpath(void) |
{ |
{ |
char resolvedname[MAXPATHLEN]; |
char resolvedname[MAXPATHLEN]; |
|
|
xfree(path); |
xfree(path); |
} |
} |
|
|
void |
static void |
process_rename(void) |
process_rename(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
|
xfree(newpath); |
xfree(newpath); |
} |
} |
|
|
void |
static void |
process_readlink(void) |
process_readlink(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
int len; |
char link[MAXPATHLEN]; |
char link[MAXPATHLEN]; |
char *path; |
char *path; |
|
|
id = get_int(); |
id = get_int(); |
path = get_string(NULL); |
path = get_string(NULL); |
TRACE("readlink id %d path %s", id, path); |
TRACE("readlink id %d path %s", id, path); |
if (readlink(path, link, sizeof(link) - 1) == -1) |
if ((len = readlink(path, link, sizeof(link) - 1)) == -1) |
send_status(id, errno_to_portable(errno)); |
send_status(id, errno_to_portable(errno)); |
else { |
else { |
Stat s; |
Stat s; |
|
|
link[sizeof(link) - 1] = '\0'; |
link[len] = '\0'; |
attrib_clear(&s.attrib); |
attrib_clear(&s.attrib); |
s.name = s.long_name = link; |
s.name = s.long_name = link; |
send_names(id, 1, &s); |
send_names(id, 1, &s); |
|
|
xfree(path); |
xfree(path); |
} |
} |
|
|
void |
static void |
process_symlink(void) |
process_symlink(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
|
xfree(newpath); |
xfree(newpath); |
} |
} |
|
|
void |
static void |
process_extended(void) |
process_extended(void) |
{ |
{ |
u_int32_t id; |
u_int32_t id; |
|
|
|
|
/* stolen from ssh-agent */ |
/* stolen from ssh-agent */ |
|
|
void |
static void |
process(void) |
process(void) |
{ |
{ |
u_int msg_len; |
u_int msg_len; |