Skip to content

Commit

Permalink
mod_webmail: Fix SELECT handling, logging of libetpan errors.
Browse files Browse the repository at this point in the history
* Use page specified by frontend when handling SELECT, rather than
  always fetching page 1.
* Fix logging of mailimap errors. Previously, we were using
  maildriver_strerror, but this is wrong as the maildriver codes
  are not the same as the mailimap ones. The codes are now reported
  correctly; unfortunately, this still does not provide much of any
  useful information as to why the error occured.
* Use MIME_DEBUG in a few more appropriate cases.
* logger.c: Include timestamp in logging failure error messages.
* mod_oauth, config.c: Change some verbose logs to debug messages.
  • Loading branch information
InterLinked1 committed Jan 3, 2025
1 parent 5800b61 commit e63a01e
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 52 deletions.
7 changes: 3 additions & 4 deletions bbs/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static struct bbs_config *config_parse_or_write(const char *name, FILE **restric
* There's nothing incorrect about this, it just looks weird,
* but it's not worth the added overhead to work around that to me... */
fprintf(*write_fp_ptr, "%s = %s%s", write_key, write_value, endl);
bbs_verb(5, "Adding setting '%s' in existing config\n", write_key);
bbs_debug(1, "Adding setting '%s' in existing config\n", write_key);
}

section = calloc(1, sizeof(*section));
Expand Down Expand Up @@ -478,7 +478,7 @@ static struct bbs_config *config_parse_or_write(const char *name, FILE **restric
/* Copy remainder of line from tmp onwards,
* then free dupline since we already handled this line. */
fprintf(*write_fp_ptr, "%s = %s%s", key, write_value, S_IF(tmp)); /* tmp also includes the line ending */
bbs_verb(5, "Updating setting '%s' in existing config\n", write_key);
bbs_debug(1, "Updating setting '%s' in existing config\n", write_key);
FREE(dupline); /* free and set to NULL */
write_section = NULL; /* Do not do any further replacements/additions */
}
Expand Down Expand Up @@ -527,8 +527,7 @@ static struct bbs_config *config_parse_or_write(const char *name, FILE **restric
RWLIST_UNLOCK(&configs);
}

bbs_verb(5, "Parsed config %s\n", fullname);

bbs_debug(1, "Parsed config %s\n", fullname);
return cfg;
}

Expand Down
22 changes: 12 additions & 10 deletions bbs/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
time_t lognow;
struct tm logdate;
struct timeval now;
int timeus;
char datestr[20];
char logminibuf[512];
char logfullbuf[768];
Expand Down Expand Up @@ -467,6 +468,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
#pragma GCC diagnostic pop
lognow = time(NULL);
localtime_r(&lognow, &logdate);
timeus = (int) now.tv_usec / 1000;
strftime(datestr, sizeof(datestr), "%Y-%m-%d %T", &logdate);

thread_id = bbs_gettid();
Expand Down Expand Up @@ -513,7 +515,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
struct remote_log_fd *rfd;
if (loglevel == LOG_VERBOSE && verbose_special_formatting) {
const char *verbprefix = verbose_prefix(level);
bytes = snprintf(logfullbuf, sizeof(logfullbuf), "[%s.%03d] %s%s%s", datestr, (int) now.tv_usec / 1000, verbprefix, buf, need_reset ? COLOR_RESET : "");
bytes = snprintf(logfullbuf, sizeof(logfullbuf), "[%s.%03d] %s%s%s", datestr, timeus, verbprefix, buf, need_reset ? COLOR_RESET : "");
if (bytes >= (int) sizeof(logfullbuf)) {
fulldynamic = 1;
fullbuf = malloc((size_t) bytes + 1);
Expand All @@ -527,7 +529,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
sprintf(fullbuf, "[%s.%03d] %s%s%s", datestr, (int) now.tv_usec / 1000, verbprefix, buf, need_reset ? COLOR_RESET : "");
}
} else {
bytes = snprintf(logfullbuf, sizeof(logfullbuf), "[%s.%03d] %s[%d]: %s%s:%d %s%s: %s%s", datestr, (int) now.tv_usec / 1000, loglevel2str(loglevel, 1), thread_id, COLOR_START TERM_COLOR_WHITE COLOR_BEGIN, file, lineno, func, COLOR_RESET, buf, need_reset ? COLOR_RESET : "");
bytes = snprintf(logfullbuf, sizeof(logfullbuf), "[%s.%03d] %s[%d]: %s%s:%d %s%s: %s%s", datestr, timeus, loglevel2str(loglevel, 1), thread_id, COLOR_START TERM_COLOR_WHITE COLOR_BEGIN, file, lineno, func, COLOR_RESET, buf, need_reset ? COLOR_RESET : "");
if (bytes >= (int) sizeof(logfullbuf)) {
fullbuf = malloc((size_t) bytes + 1);
if (ALLOC_FAILURE(fullbuf)) {
Expand All @@ -537,7 +539,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
}
fulldynamic = 1;
/* Safe */
bytes = sprintf(fullbuf, "[%s.%03d] %s[%d]: %s%s:%d %s%s: %s%s", datestr, (int) now.tv_usec / 1000, loglevel2str(loglevel, 1), thread_id, COLOR_START TERM_COLOR_WHITE COLOR_BEGIN, file, lineno, func, COLOR_RESET, buf, need_reset ? COLOR_RESET : "");
bytes = sprintf(fullbuf, "[%s.%03d] %s[%d]: %s%s:%d %s%s: %s%s", datestr, timeus, loglevel2str(loglevel, 1), thread_id, COLOR_START TERM_COLOR_WHITE COLOR_BEGIN, file, lineno, func, COLOR_RESET, buf, need_reset ? COLOR_RESET : "");
}
}

Expand Down Expand Up @@ -591,9 +593,9 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
bufstart += wres;
bytesleft -= (size_t) wres;
#ifdef DEBUG_LOGGING_FAILURES
fprintf(stderr, "%5u [%d <%d>] Retrying partial write\n", logid, thread_id, rfd->fd);
fprintf(stderr, "[%s.%03d] %5u [%d <%d>] Retrying partial write\n", datestr, timeus, logid, thread_id, rfd->fd);
} else {
fprintf(stderr, "%5u [%d <%d>] Retrying failed write\n", logid, thread_id, rfd->fd);
fprintf(stderr, "[%s.%03d] %5u [%d <%d>] Retrying failed write\n", datestr, timeus, logid, thread_id, rfd->fd);
#endif
}
/* If we can make progress now, try again. Otherwise, give up immediately.
Expand All @@ -605,12 +607,12 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
/* Release console lock ASAP */
bbs_block_fd(rfd->fd);
bbs_mutex_unlock(&rfd->lock);
fprintf(stderr, "%5u [%d <%d>] Failed to log %lu bytes: Resource temporarily unavailable\n", logid, thread_id, rfd->fd, bytesleft);
fprintf(stderr, "[%s.%03d] %5u [%d <%d>] Failed to log %lu bytes: Resource temporarily unavailable\n", datestr, timeus, logid, thread_id, rfd->fd, bytesleft);
goto nextiteration; /* Can't continue since we're in a double loop. We want to continue the outer loop. */
}
#ifdef DEBUG_LOGGING_FAILURES
if (wres == (ssize_t) bytesleft) {
fprintf(stderr, "%5u [%d <%d>] Succeeded after retry\n", logid, thread_id, rfd->fd);
fprintf(stderr, "[%s.%03d] %5u [%d <%d>] Succeeded after retry\n", datestr, timeus, logid, thread_id, rfd->fd);
}
#endif
}
Expand All @@ -621,7 +623,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
bbs_mutex_unlock(&rfd->lock);
/* Well, we can't log a message if we failed to log a message.
* That would probably not work out well. */
fprintf(stderr, "%5u [%d <%d>] Failed to log %lu bytes (wrote %ld): %s\n", logid, thread_id, rfd->fd, bytesleft, wres, strerror(saved_errno));
fprintf(stderr, "[%s.%03d] %5u [%d <%d>] Failed to log %lu bytes (wrote %ld): %s\n", datestr, timeus, logid, thread_id, rfd->fd, bytesleft, wres, strerror(saved_errno));
} else {
bbs_block_fd(rfd->fd);
bbs_mutex_unlock(&rfd->lock);
Expand All @@ -641,7 +643,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo

if (!skip_logfile) {
/* Log message to file should not include color formatting */
bytes = snprintf(logfullbuf, sizeof(logfullbuf), "[%s.%03d] %s[%d]: %s:%d %s: %s%s", datestr, (int) now.tv_usec / 1000, loglevel2str(loglevel, 0), thread_id, file, lineno, func, buf, need_reset ? COLOR_RESET : "");
bytes = snprintf(logfullbuf, sizeof(logfullbuf), "[%s.%03d] %s[%d]: %s:%d %s: %s%s", datestr, timeus, loglevel2str(loglevel, 0), thread_id, file, lineno, func, buf, need_reset ? COLOR_RESET : "");
if (bytes >= (int) sizeof(logfullbuf)) {
fullbuf = malloc((size_t) bytes + 1);
if (ALLOC_FAILURE(fullbuf)) {
Expand All @@ -651,7 +653,7 @@ void __attribute__ ((format (gnu_printf, 6, 7))) __bbs_log(enum bbs_log_level lo
}
fulldynamic = 1;
/* Safe */
sprintf(fullbuf, "[%s.%03d] %s[%d]: %s:%d %s: %s%s", datestr, (int) now.tv_usec / 1000, loglevel2str(loglevel, 0), thread_id, file, lineno, func, buf, need_reset ? COLOR_RESET : "");
sprintf(fullbuf, "[%s.%03d] %s[%d]: %s:%d %s: %s%s", datestr, timeus, loglevel2str(loglevel, 0), thread_id, file, lineno, func, buf, need_reset ? COLOR_RESET : "");
}

fwrite(fullbuf, 1, (size_t) bytes, logfp);
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_oauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int refresh_token(struct oauth_client *client)
/* The authorization server MAY issue a new refresh token, in which case the client
* MUST discard the old refresh token and replace it with the new refresh token.
* The authorization server MAY revoke the old refresh token after issuing a new refresh token to the client. */
bbs_verb(5, "OAuth refresh token has changed\n");
bbs_debug(2, "OAuth refresh token has changed\n");
REPLACE(client->refreshtoken, newrefreshtoken);
/* This is good as long as the BBS is running continously, but we also need to update the static configuration file,
* or we'll lose the new refresh token the next time the BBS starts (or mod_oauth is reloaded). */
Expand Down
Loading

0 comments on commit e63a01e

Please sign in to comment.