Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance logging #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/ftpcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ static void do_RETR(uev_t *w, void *arg, int events)
num = fread(buf, sizeof(char), sizeof(buf), ctrl->fp);
if (!num) {
if (feof(ctrl->fp))
INFO("User %s from %s downloaded %s", ctrl->name, ctrl->clientaddr, ctrl->file);
INFO("User %s from %s downloaded '%s'", ctrl->name, ctrl->clientaddr, ctrl->file);
else if (ferror(ctrl->fp))
ERR(0, "Error while reading %s", ctrl->file);
do_abort(ctrl);
Expand Down Expand Up @@ -1101,7 +1101,13 @@ static void handle_RETR(ctrl_t *ctrl, char *file)
struct stat st;

path = compose_abspath(ctrl, file);
if (!path || stat(path, &st) || !S_ISREG(st.st_mode)) {
if (!path || stat(path, &st)) {
LOG("%s: Failed opening '%s'. No such file or directory", ctrl->clientaddr, path);
send_msg(ctrl->sd, "550 No such file or directory.\r\n");
return;
}
if (!S_ISREG(st.st_mode)) {
LOG("%s: Failed opening '%s'. Not a regular file", ctrl->clientaddr, path);
send_msg(ctrl->sd, "550 Not a regular file.\r\n");
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/tftpcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static int handle_RRQ(ctrl_t *ctrl)

ctrl->fp = fopen(path, "r");
if (!ctrl->fp) {
ERR(errno, "%s: Failed opening %s", ctrl->clientaddr, path);
ERR(errno, "%s: Failed opening '%s'", ctrl->clientaddr, path);
return send_ERROR(ctrl, ENOTFOUND, NULL);
}

Expand All @@ -240,7 +240,7 @@ static int handle_WRQ(ctrl_t *ctrl)
ctrl->offset = 1; /* First expected block */
ctrl->fp = fopen(path, "w");
if (!ctrl->fp) {
ERR(errno, "%s: Failed opening %s", ctrl->clientaddr, path);
ERR(errno, "%s: Failed opening '%s'", ctrl->clientaddr, path);
return send_ERROR(ctrl, ENOTFOUND, NULL);
}

Expand Down Expand Up @@ -328,7 +328,7 @@ static void read_client_command(uev_t *w, void *arg, int events)
active = 0;
break;
}
DBG("tftp RRQ %s from %s:%d", ctrl->file, ctrl->clientaddr, port);
INFO("tftp RRQ '%s' from %s:%d", ctrl->file, ctrl->clientaddr, port);
active = handle_RRQ(ctrl);
free(ctrl->file);
break;
Expand All @@ -340,13 +340,13 @@ static void read_client_command(uev_t *w, void *arg, int events)
active = 0;
break;
}
DBG("tftp WRQ %s from %s:%d", ctrl->file, ctrl->clientaddr, port);
INFO("tftp WRQ '%s' from %s:%d", ctrl->file, ctrl->clientaddr, port);
handle_WRQ(ctrl);
free(ctrl->file);
break;

case DATA: /* Received data after WRQ */
DBG("tftp DATA %s from %s:%d", ctrl->file, ctrl->clientaddr, port);
INFO("tftp DATA '%s' from %s:%d", ctrl->file, ctrl->clientaddr, port);
len -= ctrl->th->th_data - ctrl->buf;
active = handle_DATA(ctrl, len);
break;
Expand Down