diff options
Diffstat (limited to 'imap')
| -rw-r--r-- | imap/ChangeLog | 5 | ||||
| -rw-r--r-- | imap/imapd.c | 11 | ||||
| -rw-r--r-- | imap/imaplogin.c | 25 | ||||
| -rw-r--r-- | imap/imaptoken.c | 9 | ||||
| -rw-r--r-- | imap/mainloop.c | 12 | ||||
| -rw-r--r-- | imap/pop3dserver.c | 5 | ||||
| -rw-r--r-- | imap/pop3login.c | 29 |
7 files changed, 63 insertions, 33 deletions
diff --git a/imap/ChangeLog b/imap/ChangeLog index 8d8f31f..f02a57e 100644 --- a/imap/ChangeLog +++ b/imap/ChangeLog @@ -1,3 +1,8 @@ +2019-09-05 Sam Varshavchik <mrsam@courier-mta.com> + + * imap, pop3: include remote port TCP port number together with the + IP address, in log messages. + 5.0.8 2019-08-28 Sam Varshavchik <mrsam@courier-mta.com> diff --git a/imap/imapd.c b/imap/imapd.c index a38e2aa..095defb 100644 --- a/imap/imapd.c +++ b/imap/imapd.c @@ -1480,9 +1480,10 @@ static int doId() curtoken = nexttoken(); - fprintf(stderr, "INFO: ID, user=%s, ip=[%s]", + fprintf(stderr, "INFO: ID, user=%s, ip=[%s], port=[%s]", getenv("AUTHENTICATED"), - getenv("TCPREMOTEIP")); + getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT")); while ((k < 30) && (curtoken->tokentype != IT_RPAREN)) { k++; @@ -1820,9 +1821,10 @@ int log_deletions= cp && *cp != '0'; } if (log_deletions) - fprintf(stderr, "INFO: EXPUNGED, user=%s, ip=[%s], old_name=%s, new_name=%s: only new_name will be left\n", + fprintf(stderr, "INFO: EXPUNGED, user=%s, ip=[%s], port=[%s], old_name=%s, new_name=%s: only new_name will be left\n", getenv("AUTHENTICATED"), getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT"), old_name, new_name); if (rename(old_name, new_name)) @@ -1858,9 +1860,10 @@ int log_deletions= cp && *cp != '0'; } if (log_deletions) - fprintf(stderr, "INFO: EXPUNGED, user=%s, ip=[%s], old_name=%s\n", + fprintf(stderr, "INFO: EXPUNGED, user=%s, ip=[%s], port=[%s], old_name=%s\n", getenv("AUTHENTICATED"), getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT"), old_name); free(old_name); } diff --git a/imap/imaplogin.c b/imap/imaplogin.c index cd223f2..4cc5670 100644 --- a/imap/imaplogin.c +++ b/imap/imaplogin.c @@ -287,8 +287,9 @@ int do_imap_command(const char *tag, int *flushflag) writes("* BYE Courier-IMAP server shutting down\r\n"); cmdsuccess(tag, "LOGOUT completed\r\n"); writeflush(); - fprintf(stderr, "INFO: LOGOUT, ip=[%s], rcvd=%lu, sent=%lu\n", - getenv("TCPREMOTEIP"), bytes_received_count, bytes_sent_count); + fprintf(stderr, "INFO: LOGOUT, ip=[%s], port=[%s], rcvd=%lu, sent=%lu\n", + getenv("TCPREMOTEIP"), getenv("TCPREMOTEPORT"), + bytes_received_count, bytes_sent_count); exit(0); } if (strcmp(curtoken->tokenbuf, "NOOP") == 0) @@ -374,8 +375,9 @@ int do_imap_command(const char *tag, int *flushflag) p="imap"; rc=auth_login(p, userid, passwd, login_callback, (void *)tag); - courier_safe_printf("INFO: LOGIN FAILED, user=%s, ip=[%s]", - userid, getenv("TCPREMOTEIP")); + courier_safe_printf("INFO: LOGIN FAILED, user=%s, ip=[%s], port=[%s]", + userid, getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT")); free(userid); free(passwd); if (rc > 0) @@ -401,8 +403,9 @@ int do_imap_command(const char *tag, int *flushflag) return (0); } rc=authenticate(tag, method, sizeof(method)); - courier_safe_printf("INFO: LOGIN FAILED, method=%s, ip=[%s]", - method, getenv("TCPREMOTEIP")); + courier_safe_printf("INFO: LOGIN FAILED, method=%s, ip=[%s], port=[%s]", + method, getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT")); if (rc > 0) { perror("ERR: authentication error"); @@ -424,6 +427,7 @@ extern void ignorepunct(); int main(int argc, char **argv) { const char *ip; + const char *port; #ifdef HAVE_SETVBUF_IOLBF setvbuf(stderr, NULL, _IOLBF, BUFSIZ); @@ -446,6 +450,11 @@ int main(int argc, char **argv) putenv("TCPREMOTEIP=127.0.0.1"); ip=getenv("TCPREMOTEIP"); + port=getenv("TCPREMOTEPORT"); + if (!port) + putenv("TCPREMOTEPORT=N/A"); + port=getenv("TCPREMOTEPORT"); + if (!getenv("TCPLOCALPORT")) putenv("TCPLOCALPORT=143"); @@ -471,9 +480,9 @@ int main(int argc, char **argv) writes("* OK [CAPABILITY "); imapcapability(); writes("] Courier-IMAP ready. " - "Copyright 1998-2018 Double Precision, Inc. " + "Copyright 1998-2019 Double Precision, Inc. " "See COPYING for distribution information.\r\n"); - fprintf(stderr, "DEBUG: Connection, ip=[%s]\n", ip); + fprintf(stderr, "DEBUG: Connection, ip=[%s], port=[%s]\n", ip, port); writeflush(); main_argc=argc; main_argv=argv; diff --git a/imap/imaptoken.c b/imap/imaptoken.c index a11310a..153450a 100644 --- a/imap/imaptoken.c +++ b/imap/imaptoken.c @@ -60,13 +60,16 @@ void bye_msg(const char *type) if (a && *a) fprintf(stderr, "%s, user=%s, " - "ip=[%s], headers=%lu, body=%lu, rcvd=%lu, sent=%lu, time=%s%s\n", + "ip=[%s], port=[%s], headers=%lu, body=%lu, rcvd=%lu, sent=%lu, time=%s%s\n", type, - a, getenv("TCPREMOTEIP"), header_count, body_count, bytes_received_count, bytes_sent_count, + a, getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT"), + header_count, body_count, bytes_received_count, bytes_sent_count, buf, tls); else - fprintf(stderr, "DEBUG: Disconnected, ip=[%s], time=%s%s\n", + fprintf(stderr, "DEBUG: Disconnected, ip=[%s], port=[%s], time=%s%s\n", getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT"), buf, tls); } diff --git a/imap/mainloop.c b/imap/mainloop.c index f2224a8..dc4b06f 100644 --- a/imap/mainloop.c +++ b/imap/mainloop.c @@ -34,6 +34,7 @@ static RETSIGTYPE sigexit(int n) int l = 0; const char *tls=getenv("IMAP_TLS"); const char *ip=getenv("TCPREMOTEIP"); + const char *port=getenv("TCPREMOTEPORT"); if (write(1, byemsg, sizeof(byemsg)-1) < 0) exit(1); @@ -49,12 +50,13 @@ static RETSIGTYPE sigexit(int n) if (a && *a) l = snprintf(msg, sizeof(msg) - 1, "NOTICE: Disconnected during shutdown by signal, user=%s, " - "ip=[%s], headers=%lu, body=%lu, rcvd=%lu, sent=%lu, time=%s%s\n", - a, ip, header_count, body_count, bytes_received_count, bytes_sent_count, + "ip=[%s], port=[%s], headers=%lu, body=%lu, rcvd=%lu, sent=%lu, time=%s%s\n", + a, ip, port, header_count, body_count, bytes_received_count, bytes_sent_count, buf, tls); else - l = snprintf(msg, sizeof(msg) - 1, "NOTICE: Disconnected during shutdown by signal, ip=[%s], time=%s%s\n", - getenv("TCPREMOTEIP"), + l = snprintf(msg, sizeof(msg) - 1, "NOTICE: Disconnected during shutdown by signal, ip=[%s], port=[%s], time=%s%s\n", + getenv("TCPREMOTEIP"), + getenv("TCPREMOTEPORT"), buf, tls); if (l > 0 && write(2, msg, l)) @@ -123,7 +125,7 @@ void mainloop(void) if (strlen(tag)+strlen(curtoken->tokenbuf) > IT_MAX_ATOM_SIZE) write_error_exit("max atom size too small"); - + strncat(tag, curtoken->tokenbuf, IT_MAX_ATOM_SIZE); rc=do_imap_command(tag, &flushflag); diff --git a/imap/pop3dserver.c b/imap/pop3dserver.c index fc98f2f..ea5ed99 100644 --- a/imap/pop3dserver.c +++ b/imap/pop3dserver.c @@ -558,9 +558,10 @@ static void cleanup() } if (log_deletions) - fprintf(stderr, "INFO: DELETED, user=%s, ip=[%s], filename=%s\n", + fprintf(stderr, "INFO: DELETED, user=%s, ip=[%s], port=[%s], filename=%s\n", getenv("AUTHENTICATED"), - getenv("TCPREMOTEIP"), + remoteip, + remoteport, msglist_a[i]->filename); if (unlink(msglist_a[i]->filename)) diff --git a/imap/pop3login.c b/imap/pop3login.c index be96d0e..1b43df2 100644 --- a/imap/pop3login.c +++ b/imap/pop3login.c @@ -249,7 +249,9 @@ char *p; char buf[BUFSIZ]; int c; const char *ip=getenv("TCPREMOTEIP"); -char authservice[40]; +const char *port=getenv("TCPREMOTEPORT"); + + char authservice[40]; char *q ; #ifdef HAVE_SETVBUF_IOLBF @@ -261,6 +263,9 @@ char *q ; ip="127.0.0.1"; } + if (!port || !*port) + port="N/A"; + if (argc != 3) { printf("-ERR pop3login requires exactly two arguments.\r\n"); @@ -273,7 +278,7 @@ char *q ; courier_authdebug_login_init(); - fprintf(stderr, "DEBUG: Connection, ip=[%s]\n", ip); + fprintf(stderr, "DEBUG: Connection, ip=[%s], port=[%s]\n", ip, port); printf("+OK Hello there.\r\n"); fflush(stdout); @@ -303,8 +308,8 @@ char *q ; if ( strcmp(p, "QUIT") == 0) { - fprintf(stderr, "INFO: LOGOUT, ip=[%s]\n", - ip); + fprintf(stderr, "INFO: LOGOUT, ip=[%s], port=[%s]\n", + ip, port); fflush(stderr); printf("+OK Better luck next time.\r\n"); fflush(stdout); @@ -407,9 +412,10 @@ char *q ; free(authdata); } - courier_safe_printf("INFO: LOGIN " - "FAILED, method=%s, ip=[%s]", - method, ip); + courier_safe_printf + ("INFO: LOGIN " + "FAILED, method=%s, ip=[%s], port=[%s]", + method, ip, port); if (rc == AUTHSASL_ABORTED) printf("-ERR Authentication aborted.\r\n"); else if (rc > 0) @@ -447,9 +453,10 @@ char *q ; q="pop3"; rc=auth_login(q, user, p, login_callback, NULL); - courier_safe_printf("INFO: LOGIN " - "FAILED, user=%s, ip=[%s]", - user, ip); + courier_safe_printf + ("INFO: LOGIN " + "FAILED, user=%s, ip=[%s], port=[%s]", + user, ip, port); if (rc > 0) { perror("ERR: authentication error"); @@ -466,7 +473,7 @@ char *q ; printf("-ERR Invalid command.\r\n"); fflush(stdout); } - fprintf(stderr, "DEBUG: Disconnected, ip=[%s]\n", ip); + fprintf(stderr, "DEBUG: Disconnected, ip=[%s], port=[%s]\n", ip, port); exit(0); return (0); } |
