cmdmon: print path of Unix command socket in debug messages
This commit is contained in:
parent
b7a4b84f0a
commit
0abb470022
3 changed files with 45 additions and 17 deletions
33
cmdmon.c
33
cmdmon.c
|
@ -709,10 +709,6 @@ transmit_reply(CMD_Reply *msg, union sockaddr_all *where_to, int auth_len)
|
|||
int tx_message_length;
|
||||
int sock_fd;
|
||||
socklen_t addrlen;
|
||||
unsigned short port;
|
||||
IPAddr ip;
|
||||
|
||||
UTI_SockaddrToIPAndPort(&where_to->sa, &ip, &port);
|
||||
|
||||
switch (where_to->sa.sa_family) {
|
||||
case AF_INET:
|
||||
|
@ -738,13 +734,13 @@ transmit_reply(CMD_Reply *msg, union sockaddr_all *where_to, int auth_len)
|
|||
&where_to->sa, addrlen);
|
||||
|
||||
if (status < 0) {
|
||||
DEBUG_LOG(LOGF_CmdMon, "Could not send to %s:%hu fd %d : %s",
|
||||
UTI_IPToString(&ip), port, sock_fd, strerror(errno));
|
||||
DEBUG_LOG(LOGF_CmdMon, "Could not send to %s fd %d : %s",
|
||||
UTI_SockaddrToString(&where_to->sa), sock_fd, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(LOGF_CmdMon, "Sent %d bytes to %s:%hu fd %d", status,
|
||||
UTI_IPToString(&ip), port, sock_fd);
|
||||
DEBUG_LOG(LOGF_CmdMon, "Sent %d bytes to %s fd %d", status,
|
||||
UTI_SockaddrToString(&where_to->sa), sock_fd);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
@ -1595,8 +1591,8 @@ read_from_cmd_socket(void *anything)
|
|||
assert(0);
|
||||
}
|
||||
|
||||
DEBUG_LOG(LOGF_CmdMon, "Received %d bytes from %s:%hu fd %d",
|
||||
status, UTI_IPToString(&remote_ip), remote_port, sock_fd);
|
||||
DEBUG_LOG(LOGF_CmdMon, "Received %d bytes from %s fd %d",
|
||||
status, UTI_SockaddrToString(&where_from.sa), sock_fd);
|
||||
|
||||
if (!(localhost || ADF_IsAllowed(access_auth_table, &remote_ip))) {
|
||||
/* The client is not allowed access, so don't waste any more time
|
||||
|
@ -1646,7 +1642,8 @@ read_from_cmd_socket(void *anything)
|
|||
memset(&tx_message.auth, 0, sizeof(tx_message.auth));
|
||||
|
||||
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
||||
DEBUG_LOG(LOGF_CmdMon, "Read command packet with protocol version %d (expected %d) from %s:%hu", rx_message.version, PROTO_VERSION_NUMBER, UTI_IPToString(&remote_ip), remote_port);
|
||||
DEBUG_LOG(LOGF_CmdMon, "Read command packet with protocol version %d (expected %d) from %s",
|
||||
rx_message.version, PROTO_VERSION_NUMBER, UTI_SockaddrToString(&where_from.sa));
|
||||
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
|
||||
|
@ -1658,7 +1655,8 @@ read_from_cmd_socket(void *anything)
|
|||
}
|
||||
|
||||
if (rx_command >= N_REQUEST_TYPES) {
|
||||
DEBUG_LOG(LOGF_CmdMon, "Read command packet with invalid command %d from %s:%hu", rx_command, UTI_IPToString(&remote_ip), remote_port);
|
||||
DEBUG_LOG(LOGF_CmdMon, "Read command packet with invalid command %d from %s",
|
||||
rx_command, UTI_SockaddrToString(&where_from.sa));
|
||||
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
|
||||
|
@ -1668,7 +1666,8 @@ read_from_cmd_socket(void *anything)
|
|||
}
|
||||
|
||||
if (read_length < expected_length) {
|
||||
DEBUG_LOG(LOGF_CmdMon, "Read incorrectly sized command packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
|
||||
DEBUG_LOG(LOGF_CmdMon, "Read incorrectly sized command packet from %s",
|
||||
UTI_SockaddrToString(&where_from.sa));
|
||||
|
||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||
|
||||
|
@ -1752,7 +1751,8 @@ read_from_cmd_socket(void *anything)
|
|||
status = sendto(sock_fd, (void *) prev_tx_message, tx_message_length, 0,
|
||||
&where_from.sa, from_length);
|
||||
if (status < 0) {
|
||||
DEBUG_LOG(LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&remote_ip), remote_port);
|
||||
DEBUG_LOG(LOGF_CmdMon, "Could not send response to %s",
|
||||
UTI_SockaddrToString(&where_from.sa));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1886,9 +1886,8 @@ read_from_cmd_socket(void *anything)
|
|||
/* If the log-on fails, record the reason why */
|
||||
if (!issue_token) {
|
||||
DEBUG_LOG(LOGF_CmdMon,
|
||||
"Bad command logon from %s port %d (auth_ok=%d valid_ts=%d)",
|
||||
UTI_IPToString(&remote_ip),
|
||||
remote_port,
|
||||
"Bad command logon from %s (auth_ok=%d valid_ts=%d)",
|
||||
UTI_SockaddrToString(&where_from.sa),
|
||||
auth_ok, valid_ts);
|
||||
}
|
||||
|
||||
|
|
28
util.c
28
util.c
|
@ -489,6 +489,34 @@ UTI_IPAndPortToSockaddr(IPAddr *ip, unsigned short port, struct sockaddr *sa)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
char *UTI_SockaddrToString(struct sockaddr *sa)
|
||||
{
|
||||
unsigned short port;
|
||||
IPAddr ip;
|
||||
char *result;
|
||||
|
||||
result = NEXT_BUFFER;
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6:
|
||||
#endif
|
||||
UTI_SockaddrToIPAndPort(sa, &ip, &port);
|
||||
snprintf(result, BUFFER_LENGTH, "%s:%hu", UTI_IPToString(&ip), port);
|
||||
break;
|
||||
case AF_UNIX:
|
||||
snprintf(result, BUFFER_LENGTH, "%s", ((struct sockaddr_un *)sa)->sun_path);
|
||||
break;
|
||||
default:
|
||||
snprintf(result, BUFFER_LENGTH, "[UNKNOWN]");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
const char *
|
||||
UTI_SockaddrFamilyToString(int family)
|
||||
{
|
||||
|
|
1
util.h
1
util.h
|
@ -88,6 +88,7 @@ extern int UTI_CompareIPs(IPAddr *a, IPAddr *b, IPAddr *mask);
|
|||
|
||||
extern void UTI_SockaddrToIPAndPort(struct sockaddr *sa, IPAddr *ip, unsigned short *port);
|
||||
extern int UTI_IPAndPortToSockaddr(IPAddr *ip, unsigned short port, struct sockaddr *sa);
|
||||
extern char *UTI_SockaddrToString(struct sockaddr *sa);
|
||||
extern const char *UTI_SockaddrFamilyToString(int family);
|
||||
|
||||
extern char *UTI_TimeToLogForm(time_t t);
|
||||
|
|
Loading…
Reference in a new issue