Skip to content

Commit

Permalink
Issue #14: Initial framework for FTP ABOR
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Nilsson <[email protected]>
  • Loading branch information
troglobit committed May 24, 2018
1 parent 58c8d7a commit 218a1e7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ftpcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,29 +208,35 @@ static int open_data_connection(ctrl_t *ctrl)
return 0;
}

static void close_data_connection(ctrl_t *ctrl)
static int close_data_connection(ctrl_t *ctrl)
{
int ret = 0;

DBG("Closing data connection ...");

/* PASV server listening socket */
if (ctrl->data_listen_sd > 0) {
shutdown(ctrl->data_listen_sd, SHUT_RDWR);
close(ctrl->data_listen_sd);
ctrl->data_listen_sd = -1;
ret++;
}

/* PASV client socket */
if (ctrl->data_sd > 0) {
shutdown(ctrl->data_sd, SHUT_RDWR);
close(ctrl->data_sd);
ctrl->data_sd = -1;
ret++;
}

/* PORT */
if (ctrl->data_address[0]) {
ctrl->data_address[0] = 0;
ctrl->data_port = 0;
}

return ret;
}

static int check_user_pass(ctrl_t *ctrl)
Expand All @@ -244,6 +250,21 @@ static int check_user_pass(ctrl_t *ctrl)
return 0;
}

static int do_abort(ctrl_t *ctrl)
{
ctrl->offset = 0;
return close_data_connection(ctrl);
}

static void handle_ABOR(ctrl_t *ctrl, char *arg)
{
DBG("Aborting any current transfer ...");
if (do_abort(ctrl))
send_msg(ctrl->sd, "426 Connection closed; transfer aborted.\r\n");

send_msg(ctrl->sd, "226 Closing data connection.\r\n");
}

static void handle_USER(ctrl_t *ctrl, char *name)
{
if (ctrl->name[0]) {
Expand Down Expand Up @@ -1019,6 +1040,7 @@ static void handle_UNKNOWN(ctrl_t *ctrl, char *command)
#define COMMAND(NAME) { #NAME, handle_ ## NAME }

static ftp_cmd_t supported[] = {
COMMAND(ABOR),
COMMAND(USER),
COMMAND(PASS),
COMMAND(SYST),
Expand Down

0 comments on commit 218a1e7

Please sign in to comment.