Skip to content

Commit

Permalink
Report UTF8 support to clients
Browse files Browse the repository at this point in the history
  • Loading branch information
vaguerant authored and Maschell committed Sep 23, 2022
1 parent 092142d commit 13e9c38
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ static int32_t write_reply(client_t *client, uint16_t code, char *msg) {
char *msgbuf = (char *) malloc(msglen + 1);
if (msgbuf == NULL)
return -ENOMEM;
sprintf(msgbuf, "%u %s\r\n", code, msg);
if (code == 211) {
sprintf(msgbuf, "%u-%s\r\n", code, msg);
} else {
sprintf(msgbuf, "%u %s\r\n", code, msg);
}
console_printf("Wrote reply: %s", msgbuf);
int32_t ret = send_exact(client->socket, msgbuf, msglen);
free(msgbuf);
Expand Down Expand Up @@ -223,6 +227,18 @@ static int32_t ftp_MODE(client_t *client, char *rest) {
}
}

static int32_t ftp_FEAT(client_t *client, char *rest) {
return write_reply(client, 211, "Features:\n UTF8\n211 End");
}

static int32_t ftp_OPTS(client_t *client, char *rest) {
if (!strcasecmp("UTF8 ON", rest)) {
return write_reply(client, 200, "OK");
} else {
return write_reply(client, 502, "Command not implemented.");
}
}

static int32_t ftp_PWD(client_t *client, char *rest UNUSED) {
char msg[MAXPATHLEN + 24];
// TODO: escape double-quotes
Expand Down Expand Up @@ -681,21 +697,22 @@ static int32_t ftp_UNKNOWN(client_t *client, char *rest UNUSED) {
return write_reply(client, 502, "Command not implemented.");
}

static const char *unauthenticated_commands[] = {"USER", "PASS", "QUIT", "REIN", "NOOP", NULL};
static const ftp_command_handler unauthenticated_handlers[] = {ftp_USER, ftp_PASS, ftp_QUIT, ftp_REIN, ftp_NOOP, ftp_NEEDAUTH};
static const char *unauthenticated_commands[] = {"USER", "PASS", "QUIT", "REIN", "FEAT", "OPTS", "NOOP", NULL};
static const ftp_command_handler unauthenticated_handlers[] = {ftp_USER, ftp_PASS, ftp_QUIT, ftp_REIN, ftp_FEAT, ftp_OPTS, ftp_NOOP, ftp_NEEDAUTH};

static const char *authenticated_commands[] = {
"USER", "PASS", "LIST", "PWD", "CWD", "CDUP",
"SIZE", "PASV", "PORT", "TYPE", "SYST", "MODE",
"RETR", "STOR", "APPE", "REST", "DELE", "MKD",
"RMD", "RNFR", "RNTO", "NLST", "QUIT", "REIN",
"SITE", "NOOP", "ALLO", NULL};
"SITE", "FEAT", "OPTS", "NOOP", "ALLO", NULL};
static const ftp_command_handler authenticated_handlers[] = {
ftp_USER, ftp_PASS, ftp_LIST, ftp_PWD, ftp_CWD, ftp_CDUP,
ftp_SIZE, ftp_PASV, ftp_PORT, ftp_TYPE, ftp_SYST, ftp_MODE,
ftp_RETR, ftp_STOR, ftp_APPE, ftp_REST, ftp_DELE, ftp_MKD,
ftp_DELE, ftp_RNFR, ftp_RNTO, ftp_NLST, ftp_QUIT, ftp_REIN,
ftp_SITE, ftp_NOOP, ftp_SUPERFLUOUS, ftp_UNKNOWN};
ftp_SITE, ftp_FEAT, ftp_OPTS, ftp_NOOP, ftp_SUPERFLUOUS,
ftp_UNKNOWN};

/*
returns negative to signal an error that requires closing the connection
Expand Down

0 comments on commit 13e9c38

Please sign in to comment.