| ︙ | | | ︙ | |
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* ----------------------------------------------------------------------
* SFTP packet construction functions.
*/
static void sftp_pkt_ensure(struct sftp_packet *pkt, int length)
{
if (pkt->maxlen < length) {
pkt->maxlen = length + 256;
pkt->data = srealloc(pkt->data, pkt->maxlen);
}
}
static void sftp_pkt_adddata(struct sftp_packet *pkt, void *data, int len)
{
pkt->length += len;
sftp_pkt_ensure(pkt, pkt->length);
memcpy(pkt->data + pkt->length - len, data, len);
}
static void sftp_pkt_addbyte(struct sftp_packet *pkt, unsigned char byte)
{
sftp_pkt_adddata(pkt, &byte, 1);
}
static struct sftp_packet *sftp_pkt_init(int pkt_type)
{
struct sftp_packet *pkt;
pkt = smalloc(sizeof(struct sftp_packet));
pkt->data = NULL;
pkt->savedpos = -1;
pkt->length = 0;
pkt->maxlen = 0;
sftp_pkt_addbyte(pkt, (unsigned char) pkt_type);
return pkt;
}
|
|
|
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* ----------------------------------------------------------------------
* SFTP packet construction functions.
*/
static void sftp_pkt_ensure(struct sftp_packet *pkt, int length)
{
if (pkt->maxlen < length) {
pkt->maxlen = length + 256;
pkt->data = sresize(pkt->data, pkt->maxlen, char);
}
}
static void sftp_pkt_adddata(struct sftp_packet *pkt, void *data, int len)
{
pkt->length += len;
sftp_pkt_ensure(pkt, pkt->length);
memcpy(pkt->data + pkt->length - len, data, len);
}
static void sftp_pkt_addbyte(struct sftp_packet *pkt, unsigned char byte)
{
sftp_pkt_adddata(pkt, &byte, 1);
}
static struct sftp_packet *sftp_pkt_init(int pkt_type)
{
struct sftp_packet *pkt;
pkt = snew(struct sftp_packet);
pkt->data = NULL;
pkt->savedpos = -1;
pkt->length = 0;
pkt->maxlen = 0;
sftp_pkt_addbyte(pkt, (unsigned char) pkt_type);
return pkt;
}
|
| ︙ | | | ︙ | |
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
{
struct sftp_packet *pkt;
char x[4];
if (!sftp_recvdata(x, 4))
return NULL;
pkt = smalloc(sizeof(struct sftp_packet));
pkt->savedpos = 0;
pkt->length = pkt->maxlen = GET_32BIT(x);
pkt->data = smalloc(pkt->length);
if (!sftp_recvdata(pkt->data, pkt->length)) {
sftp_pkt_free(pkt);
return NULL;
}
pkt->type = sftp_pkt_getbyte(pkt);
return pkt;
}
/* ----------------------------------------------------------------------
* String handling routines.
*/
static char *mkstr(char *s, int len)
{
char *p = smalloc(len + 1);
memcpy(p, s, len);
p[len] = '\0';
return p;
}
/* ----------------------------------------------------------------------
* SFTP primitives.
|
|
|
|
|
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
{
struct sftp_packet *pkt;
char x[4];
if (!sftp_recvdata(x, 4))
return NULL;
pkt = snew(struct sftp_packet);
pkt->savedpos = 0;
pkt->length = pkt->maxlen = GET_32BIT(x);
pkt->data = snewn(pkt->length, char);
if (!sftp_recvdata(pkt->data, pkt->length)) {
sftp_pkt_free(pkt);
return NULL;
}
pkt->type = sftp_pkt_getbyte(pkt);
return pkt;
}
/* ----------------------------------------------------------------------
* String handling routines.
*/
static char *mkstr(char *s, int len)
{
char *p = snewn(len + 1, char);
memcpy(p, s, len);
p[len] = '\0';
return p;
}
/* ----------------------------------------------------------------------
* SFTP primitives.
|
| ︙ | | | ︙ | |
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
sftp_pkt_getstring(pktin, &hstring, &len);
if (!hstring) {
fxp_internal_error("OPEN returned malformed FXP_HANDLE\n");
sftp_pkt_free(pktin);
return NULL;
}
handle = smalloc(sizeof(struct fxp_handle));
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
return handle;
} else {
fxp_got_status(pktin);
sftp_pkt_free(pktin);
|
|
|
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
sftp_pkt_getstring(pktin, &hstring, &len);
if (!hstring) {
fxp_internal_error("OPEN returned malformed FXP_HANDLE\n");
sftp_pkt_free(pktin);
return NULL;
}
handle = snew(struct fxp_handle);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
return handle;
} else {
fxp_got_status(pktin);
sftp_pkt_free(pktin);
|
| ︙ | | | ︙ | |
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
sftp_pkt_getstring(pktin, &hstring, &len);
if (!hstring) {
fxp_internal_error("OPENDIR returned malformed FXP_HANDLE\n");
sftp_pkt_free(pktin);
return NULL;
}
handle = smalloc(sizeof(struct fxp_handle));
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
return handle;
} else {
fxp_got_status(pktin);
sftp_pkt_free(pktin);
|
|
|
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
sftp_pkt_getstring(pktin, &hstring, &len);
if (!hstring) {
fxp_internal_error("OPENDIR returned malformed FXP_HANDLE\n");
sftp_pkt_free(pktin);
return NULL;
}
handle = snew(struct fxp_handle);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
return handle;
} else {
fxp_got_status(pktin);
sftp_pkt_free(pktin);
|
| ︙ | | | ︙ | |
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
fxp_internal_error("request ID mismatch\n");
sftp_pkt_free(pktin);
return NULL;
}
if (pktin->type == SSH_FXP_NAME) {
struct fxp_names *ret;
int i;
ret = smalloc(sizeof(struct fxp_names));
ret->nnames = sftp_pkt_getuint32(pktin);
ret->names = smalloc(ret->nnames * sizeof(struct fxp_name));
for (i = 0; i < ret->nnames; i++) {
char *str;
int len;
sftp_pkt_getstring(pktin, &str, &len);
ret->names[i].filename = mkstr(str, len);
sftp_pkt_getstring(pktin, &str, &len);
ret->names[i].longname = mkstr(str, len);
|
|
|
|
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
fxp_internal_error("request ID mismatch\n");
sftp_pkt_free(pktin);
return NULL;
}
if (pktin->type == SSH_FXP_NAME) {
struct fxp_names *ret;
int i;
ret = snew(struct fxp_names);
ret->nnames = sftp_pkt_getuint32(pktin);
ret->names = snewn(ret->nnames, struct fxp_name);
for (i = 0; i < ret->nnames; i++) {
char *str;
int len;
sftp_pkt_getstring(pktin, &str, &len);
ret->names[i].filename = mkstr(str, len);
sftp_pkt_getstring(pktin, &str, &len);
ret->names[i].longname = mkstr(str, len);
|
| ︙ | | | ︙ | |
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
|
/*
* Duplicate an fxp_name structure.
*/
struct fxp_name *fxp_dup_name(struct fxp_name *name)
{
struct fxp_name *ret;
ret = smalloc(sizeof(struct fxp_name));
ret->filename = dupstr(name->filename);
ret->longname = dupstr(name->longname);
ret->attrs = name->attrs; /* structure copy */
return ret;
}
/*
|
|
|
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
|
/*
* Duplicate an fxp_name structure.
*/
struct fxp_name *fxp_dup_name(struct fxp_name *name)
{
struct fxp_name *ret;
ret = snew(struct fxp_name);
ret->filename = dupstr(name->filename);
ret->longname = dupstr(name->longname);
ret->attrs = name->attrs; /* structure copy */
return ret;
}
/*
|
| ︙ | | | ︙ | |