version 1.26, 2014/01/09 03:26:00 |
version 1.27, 2015/01/14 13:54:13 |
|
|
#include <util.h> |
#include <util.h> |
|
|
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "buffer.h" |
#include "ssherr.h" |
|
#include "sshbuf.h" |
#include "log.h" |
#include "log.h" |
|
|
#include "sftp.h" |
#include "sftp.h" |
|
|
} |
} |
|
|
/* Decode attributes in buffer */ |
/* Decode attributes in buffer */ |
Attrib * |
int |
decode_attrib(Buffer *b) |
decode_attrib(struct sshbuf *b, Attrib *a) |
{ |
{ |
static Attrib a; |
int r; |
|
|
attrib_clear(&a); |
attrib_clear(a); |
a.flags = buffer_get_int(b); |
if ((r = sshbuf_get_u32(b, &a->flags)) != 0) |
if (a.flags & SSH2_FILEXFER_ATTR_SIZE) |
return r; |
a.size = buffer_get_int64(b); |
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { |
if (a.flags & SSH2_FILEXFER_ATTR_UIDGID) { |
if ((r = sshbuf_get_u64(b, &a->size)) != 0) |
a.uid = buffer_get_int(b); |
return r; |
a.gid = buffer_get_int(b); |
|
} |
} |
if (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) |
if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { |
a.perm = buffer_get_int(b); |
if ((r = sshbuf_get_u32(b, &a->uid)) != 0 || |
if (a.flags & SSH2_FILEXFER_ATTR_ACMODTIME) { |
(r = sshbuf_get_u32(b, &a->gid)) != 0) |
a.atime = buffer_get_int(b); |
return r; |
a.mtime = buffer_get_int(b); |
|
} |
} |
|
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
|
if ((r = sshbuf_get_u32(b, &a->perm)) != 0) |
|
return r; |
|
} |
|
if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { |
|
if ((r = sshbuf_get_u32(b, &a->atime)) != 0 || |
|
(r = sshbuf_get_u32(b, &a->mtime)) != 0) |
|
return r; |
|
} |
/* vendor-specific extensions */ |
/* vendor-specific extensions */ |
if (a.flags & SSH2_FILEXFER_ATTR_EXTENDED) { |
if (a->flags & SSH2_FILEXFER_ATTR_EXTENDED) { |
char *type, *data; |
char *type; |
int i, count; |
u_char *data; |
|
size_t dlen; |
|
u_int i, count; |
|
|
count = buffer_get_int(b); |
if ((r = sshbuf_get_u32(b, &count)) != 0) |
|
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
for (i = 0; i < count; i++) { |
for (i = 0; i < count; i++) { |
type = buffer_get_string(b, NULL); |
if ((r = sshbuf_get_cstring(b, &type, NULL)) != 0 || |
data = buffer_get_string(b, NULL); |
(r = sshbuf_get_string(b, &data, &dlen)) != 0) |
debug3("Got file attribute \"%s\"", type); |
return r; |
|
debug3("Got file attribute \"%.100s\" len %zu", |
|
type, dlen); |
free(type); |
free(type); |
free(data); |
free(data); |
} |
} |
} |
} |
return &a; |
return 0; |
} |
} |
|
|
/* Encode attributes to buffer */ |
/* Encode attributes to buffer */ |
void |
int |
encode_attrib(Buffer *b, const Attrib *a) |
encode_attrib(struct sshbuf *b, const Attrib *a) |
{ |
{ |
buffer_put_int(b, a->flags); |
int r; |
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) |
|
buffer_put_int64(b, a->size); |
if ((r = sshbuf_put_u32(b, a->flags)) != 0) |
|
return r; |
|
if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { |
|
if ((r = sshbuf_put_u64(b, a->size)) != 0) |
|
return r; |
|
} |
if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { |
if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { |
buffer_put_int(b, a->uid); |
if ((r = sshbuf_put_u32(b, a->uid)) != 0 || |
buffer_put_int(b, a->gid); |
(r = sshbuf_put_u32(b, a->gid)) != 0) |
|
return r; |
} |
} |
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) |
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
buffer_put_int(b, a->perm); |
if ((r = sshbuf_put_u32(b, a->perm)) != 0) |
|
return r; |
|
} |
if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { |
if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { |
buffer_put_int(b, a->atime); |
if ((r = sshbuf_put_u32(b, a->atime)) != 0 || |
buffer_put_int(b, a->mtime); |
(r = sshbuf_put_u32(b, a->mtime)) != 0) |
|
return r; |
} |
} |
|
return 0; |
} |
} |
|
|
/* Convert from SSH2_FX_ status to text error message */ |
/* Convert from SSH2_FX_ status to text error message */ |