version 1.12, 2001/01/15 21:46:38 |
version 1.13, 2001/01/16 20:54:27 |
|
|
} |
} |
} |
} |
|
|
Attrib * |
void |
stat_to_attrib(struct stat *st) |
stat_to_attrib(struct stat *st, Attrib *a) |
{ |
{ |
static Attrib a; |
attrib_clear(a); |
attrib_clear(&a); |
a->flags = 0; |
a.flags = 0; |
a->flags |= SSH2_FILEXFER_ATTR_SIZE; |
a.flags |= SSH2_FILEXFER_ATTR_SIZE; |
a->size = st->st_size; |
a.size = st->st_size; |
a->flags |= SSH2_FILEXFER_ATTR_UIDGID; |
a.flags |= SSH2_FILEXFER_ATTR_UIDGID; |
a->uid = st->st_uid; |
a.uid = st->st_uid; |
a->gid = st->st_gid; |
a.gid = st->st_gid; |
a->flags |= SSH2_FILEXFER_ATTR_PERMISSIONS; |
a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS; |
a->perm = st->st_mode; |
a.perm = st->st_mode; |
a->flags |= SSH2_FILEXFER_ATTR_ACMODTIME; |
a.flags |= SSH2_FILEXFER_ATTR_ACMODTIME; |
a->atime = st->st_atime; |
a.atime = st->st_atime; |
a->mtime = st->st_mtime; |
a.mtime = st->st_mtime; |
|
return &a; |
|
} |
} |
|
|
Attrib * |
Attrib * |
|
|
int |
int |
handle_to_string(int handle, char **stringp, int *hlenp) |
handle_to_string(int handle, char **stringp, int *hlenp) |
{ |
{ |
char buf[1024]; |
|
if (stringp == NULL || hlenp == NULL) |
if (stringp == NULL || hlenp == NULL) |
return -1; |
return -1; |
snprintf(buf, sizeof buf, "%d", handle); |
*stringp = xmalloc(sizeof(int32_t)); |
*stringp = xstrdup(buf); |
PUT_32BIT(*stringp, handle); |
*hlenp = strlen(*stringp); |
*hlenp = sizeof(int32_t); |
return 0; |
return 0; |
} |
} |
|
|
int |
int |
handle_from_string(char *handle, u_int hlen) |
handle_from_string(char *handle, u_int hlen) |
{ |
{ |
/* XXX OVERFLOW ? */ |
int val; |
char *ep; |
if (hlen != sizeof(int32_t)) |
long lval = strtol(handle, &ep, 10); |
|
int val = lval; |
|
if (*ep != '\0') |
|
return -1; |
return -1; |
|
val = GET_32BIT(handle); |
if (handle_is_ok(val, HANDLE_FILE) || |
if (handle_is_ok(val, HANDLE_FILE) || |
handle_is_ok(val, HANDLE_DIR)) |
handle_is_ok(val, HANDLE_DIR)) |
return val; |
return val; |
|
|
void |
void |
process_do_stat(int do_lstat) |
process_do_stat(int do_lstat) |
{ |
{ |
Attrib *a; |
Attrib a; |
struct stat st; |
struct stat st; |
u_int32_t id; |
u_int32_t id; |
char *name; |
char *name; |
|
|
if (ret < 0) { |
if (ret < 0) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else { |
} else { |
a = stat_to_attrib(&st); |
stat_to_attrib(&st, &a); |
send_attrib(id, a); |
send_attrib(id, &a); |
status = SSH2_FX_OK; |
status = SSH2_FX_OK; |
} |
} |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
|
|
void |
void |
process_fstat(void) |
process_fstat(void) |
{ |
{ |
Attrib *a; |
Attrib a; |
struct stat st; |
struct stat st; |
u_int32_t id; |
u_int32_t id; |
int fd, ret, handle, status = SSH2_FX_FAILURE; |
int fd, ret, handle, status = SSH2_FX_FAILURE; |
|
|
if (ret < 0) { |
if (ret < 0) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else { |
} else { |
a = stat_to_attrib(&st); |
stat_to_attrib(&st, &a); |
send_attrib(id, a); |
send_attrib(id, &a); |
status = SSH2_FX_OK; |
status = SSH2_FX_OK; |
} |
} |
} |
} |
|
|
if (dirp == NULL || path == NULL) { |
if (dirp == NULL || path == NULL) { |
send_status(id, SSH2_FX_FAILURE); |
send_status(id, SSH2_FX_FAILURE); |
} else { |
} else { |
Attrib *a; |
|
struct stat st; |
struct stat st; |
char pathname[1024]; |
char pathname[1024]; |
Stat *stats; |
Stat *stats; |
|
|
"%s/%s", path, dp->d_name); |
"%s/%s", path, dp->d_name); |
if (lstat(pathname, &st) < 0) |
if (lstat(pathname, &st) < 0) |
continue; |
continue; |
a = stat_to_attrib(&st); |
stat_to_attrib(&st, &(stats[count].attrib)); |
stats[count].attrib = *a; |
|
stats[count].name = xstrdup(dp->d_name); |
stats[count].name = xstrdup(dp->d_name); |
stats[count].long_name = ls_file(dp->d_name, &st); |
stats[count].long_name = ls_file(dp->d_name, &st); |
count++; |
count++; |