|
Lines 453-458
do_lsreaddir(struct sftp_conn *conn, cha
Link Here
|
| 453 |
Buffer msg; |
453 |
Buffer msg; |
| 454 |
u_int count, type, id, handle_len, i, expected_id, ents = 0; |
454 |
u_int count, type, id, handle_len, i, expected_id, ents = 0; |
| 455 |
char *handle; |
455 |
char *handle; |
|
|
456 |
int status; |
| 457 |
|
| 458 |
if (dir) |
| 459 |
*dir = NULL; |
| 456 |
|
460 |
|
| 457 |
id = conn->msg_id++; |
461 |
id = conn->msg_id++; |
| 458 |
|
462 |
|
|
Lines 499-518
do_lsreaddir(struct sftp_conn *conn, cha
Link Here
|
| 499 |
fatal("ID mismatch (%u != %u)", id, expected_id); |
503 |
fatal("ID mismatch (%u != %u)", id, expected_id); |
| 500 |
|
504 |
|
| 501 |
if (type == SSH2_FXP_STATUS) { |
505 |
if (type == SSH2_FXP_STATUS) { |
| 502 |
int status = buffer_get_int(&msg); |
506 |
status = buffer_get_int(&msg); |
| 503 |
|
|
|
| 504 |
debug3("Received SSH2_FXP_STATUS %d", status); |
507 |
debug3("Received SSH2_FXP_STATUS %d", status); |
| 505 |
|
508 |
if (status == SSH2_FX_EOF) |
| 506 |
if (status == SSH2_FX_EOF) { |
|
|
| 507 |
break; |
509 |
break; |
| 508 |
} else { |
510 |
error("Couldn't read directory: %s", fx2txt(status)); |
| 509 |
error("Couldn't read directory: %s", |
511 |
goto out; |
| 510 |
fx2txt(status)); |
|
|
| 511 |
do_close(conn, handle, handle_len); |
| 512 |
free(handle); |
| 513 |
buffer_free(&msg); |
| 514 |
return(status); |
| 515 |
} |
| 516 |
} else if (type != SSH2_FXP_NAME) |
512 |
} else if (type != SSH2_FXP_NAME) |
| 517 |
fatal("Expected SSH2_FXP_NAME(%u) packet, got %u", |
513 |
fatal("Expected SSH2_FXP_NAME(%u) packet, got %u", |
| 518 |
SSH2_FXP_NAME, type); |
514 |
SSH2_FXP_NAME, type); |
|
Lines 540-549
do_lsreaddir(struct sftp_conn *conn, cha
Link Here
|
| 540 |
if (strchr(filename, '/') != NULL) { |
536 |
if (strchr(filename, '/') != NULL) { |
| 541 |
error("Server sent suspect path \"%s\" " |
537 |
error("Server sent suspect path \"%s\" " |
| 542 |
"during readdir of \"%s\"", filename, path); |
538 |
"during readdir of \"%s\"", filename, path); |
| 543 |
goto next; |
539 |
} else if (dir) { |
| 544 |
} |
|
|
| 545 |
|
| 546 |
if (dir) { |
| 547 |
*dir = xrealloc(*dir, ents + 2, sizeof(**dir)); |
540 |
*dir = xrealloc(*dir, ents + 2, sizeof(**dir)); |
| 548 |
(*dir)[ents] = xcalloc(1, sizeof(***dir)); |
541 |
(*dir)[ents] = xcalloc(1, sizeof(***dir)); |
| 549 |
(*dir)[ents]->filename = xstrdup(filename); |
542 |
(*dir)[ents]->filename = xstrdup(filename); |
|
Lines 551-574
do_lsreaddir(struct sftp_conn *conn, cha
Link Here
|
| 551 |
memcpy(&(*dir)[ents]->a, a, sizeof(*a)); |
544 |
memcpy(&(*dir)[ents]->a, a, sizeof(*a)); |
| 552 |
(*dir)[++ents] = NULL; |
545 |
(*dir)[++ents] = NULL; |
| 553 |
} |
546 |
} |
| 554 |
next: |
|
|
| 555 |
free(filename); |
547 |
free(filename); |
| 556 |
free(longname); |
548 |
free(longname); |
| 557 |
} |
549 |
} |
| 558 |
} |
550 |
} |
|
|
551 |
status = 0; |
| 559 |
|
552 |
|
|
|
553 |
out: |
| 560 |
buffer_free(&msg); |
554 |
buffer_free(&msg); |
| 561 |
do_close(conn, handle, handle_len); |
555 |
do_close(conn, handle, handle_len); |
| 562 |
free(handle); |
556 |
free(handle); |
| 563 |
|
557 |
|
| 564 |
/* Don't return partial matches on interrupt */ |
558 |
if (status != 0 && dir != NULL) { |
| 565 |
if (interrupted && dir != NULL && *dir != NULL) { |
559 |
/* Don't return results on error */ |
|
|
560 |
free_sftp_dirents(*dir); |
| 561 |
*dir = NULL; |
| 562 |
} else if (interrupted && dir != NULL && *dir != NULL) { |
| 563 |
/* Don't return partial matches on interrupt */ |
| 566 |
free_sftp_dirents(*dir); |
564 |
free_sftp_dirents(*dir); |
| 567 |
*dir = xcalloc(1, sizeof(**dir)); |
565 |
*dir = xcalloc(1, sizeof(**dir)); |
| 568 |
**dir = NULL; |
566 |
**dir = NULL; |
| 569 |
} |
567 |
} |
| 570 |
|
568 |
|
| 571 |
return 0; |
569 |
return status; |
| 572 |
} |
570 |
} |
| 573 |
|
571 |
|
| 574 |
int |
572 |
int |
|
Lines 581-586
void free_sftp_dirents(SFTP_DIRENT **s)
Link Here
|
| 581 |
{ |
579 |
{ |
| 582 |
int i; |
580 |
int i; |
| 583 |
|
581 |
|
|
|
582 |
if (s == NULL) |
| 583 |
return; |
| 584 |
for (i = 0; s[i]; i++) { |
584 |
for (i = 0; s[i]; i++) { |
| 585 |
free(s[i]->filename); |
585 |
free(s[i]->filename); |
| 586 |
free(s[i]->longname); |
586 |
free(s[i]->longname); |