version 1.30, 2001/07/31 12:42:50 |
version 1.30.2.2, 2002/06/22 07:23:17 |
|
|
/* |
/* |
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
* Copyright (c) 2000, 2001, 2002 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 |
|
|
{ |
{ |
int i; |
int i; |
|
|
for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) |
for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) |
handles[i].use = HANDLE_UNUSED; |
handles[i].use = HANDLE_UNUSED; |
} |
} |
|
|
|
|
{ |
{ |
int i; |
int i; |
|
|
for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) { |
for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) { |
if (handles[i].use == HANDLE_UNUSED) { |
if (handles[i].use == HANDLE_UNUSED) { |
handles[i].use = use; |
handles[i].use = use; |
handles[i].dirp = dirp; |
handles[i].dirp = dirp; |
|
|
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
version = buffer_get_int(&iqueue); |
version = get_int(); |
TRACE("client version %d", version); |
TRACE("client version %d", version); |
buffer_init(&msg); |
buffer_init(&msg); |
buffer_put_char(&msg, SSH2_FXP_VERSION); |
buffer_put_char(&msg, SSH2_FXP_VERSION); |
|
|
name = get_string(NULL); |
name = get_string(NULL); |
a = get_attrib(); |
a = get_attrib(); |
TRACE("setstat id %d name %s", id, name); |
TRACE("setstat id %d name %s", id, name); |
|
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { |
|
ret = truncate(name, a->size); |
|
if (ret == -1) |
|
status = errno_to_portable(errno); |
|
} |
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
ret = chmod(name, a->perm & 0777); |
ret = chmod(name, a->perm & 0777); |
if (ret == -1) |
if (ret == -1) |
|
|
if (fd < 0) { |
if (fd < 0) { |
status = SSH2_FX_FAILURE; |
status = SSH2_FX_FAILURE; |
} else { |
} else { |
|
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { |
|
ret = ftruncate(fd, a->size); |
|
if (ret == -1) |
|
status = errno_to_portable(errno); |
|
} |
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
ret = fchmod(fd, a->perm & 0777); |
ret = fchmod(fd, a->perm & 0777); |
if (ret == -1) |
if (ret == -1) |
|
|
} |
} |
if (count > 0) { |
if (count > 0) { |
send_names(id, count, stats); |
send_names(id, count, stats); |
for(i = 0; i < count; i++) { |
for (i = 0; i < count; i++) { |
xfree(stats[i].name); |
xfree(stats[i].name); |
xfree(stats[i].long_name); |
xfree(stats[i].long_name); |
} |
} |
|
|
send_status(id, errno_to_portable(errno)); |
send_status(id, errno_to_portable(errno)); |
else { |
else { |
Stat s; |
Stat s; |
|
|
link[len] = '\0'; |
link[len] = '\0'; |
attrib_clear(&s.attrib); |
attrib_clear(&s.attrib); |
s.name = s.long_name = link; |
s.name = s.long_name = link; |
|
|
process(void) |
process(void) |
{ |
{ |
u_int msg_len; |
u_int msg_len; |
|
u_int buf_len; |
|
u_int consumed; |
u_int type; |
u_int type; |
u_char *cp; |
u_char *cp; |
|
|
if (buffer_len(&iqueue) < 5) |
buf_len = buffer_len(&iqueue); |
|
if (buf_len < 5) |
return; /* Incomplete message. */ |
return; /* Incomplete message. */ |
cp = (u_char *) buffer_ptr(&iqueue); |
cp = buffer_ptr(&iqueue); |
msg_len = GET_32BIT(cp); |
msg_len = GET_32BIT(cp); |
if (msg_len > 256 * 1024) { |
if (msg_len > 256 * 1024) { |
error("bad message "); |
error("bad message "); |
exit(11); |
exit(11); |
} |
} |
if (buffer_len(&iqueue) < msg_len + 4) |
if (buf_len < msg_len + 4) |
return; |
return; |
buffer_consume(&iqueue, 4); |
buffer_consume(&iqueue, 4); |
|
buf_len -= 4; |
type = buffer_get_char(&iqueue); |
type = buffer_get_char(&iqueue); |
switch (type) { |
switch (type) { |
case SSH2_FXP_INIT: |
case SSH2_FXP_INIT: |
|
|
error("Unknown message %d", type); |
error("Unknown message %d", type); |
break; |
break; |
} |
} |
|
/* discard the remaining bytes from the current packet */ |
|
if (buf_len < buffer_len(&iqueue)) |
|
fatal("iqueue grows"); |
|
consumed = buf_len - buffer_len(&iqueue); |
|
if (msg_len < consumed) |
|
fatal("msg_len %d < consumed %d", msg_len, consumed); |
|
if (msg_len > consumed) |
|
buffer_consume(&iqueue, msg_len - consumed); |
} |
} |
|
|
int |
int |