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 tx_message_length;
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
unsigned short port;
|
|
||||||
IPAddr ip;
|
|
||||||
|
|
||||||
UTI_SockaddrToIPAndPort(&where_to->sa, &ip, &port);
|
|
||||||
|
|
||||||
switch (where_to->sa.sa_family) {
|
switch (where_to->sa.sa_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
|
@ -738,13 +734,13 @@ transmit_reply(CMD_Reply *msg, union sockaddr_all *where_to, int auth_len)
|
||||||
&where_to->sa, addrlen);
|
&where_to->sa, addrlen);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
DEBUG_LOG(LOGF_CmdMon, "Could not send to %s:%hu fd %d : %s",
|
DEBUG_LOG(LOGF_CmdMon, "Could not send to %s fd %d : %s",
|
||||||
UTI_IPToString(&ip), port, sock_fd, strerror(errno));
|
UTI_SockaddrToString(&where_to->sa), sock_fd, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_CmdMon, "Sent %d bytes to %s:%hu fd %d", status,
|
DEBUG_LOG(LOGF_CmdMon, "Sent %d bytes to %s fd %d", status,
|
||||||
UTI_IPToString(&ip), port, sock_fd);
|
UTI_SockaddrToString(&where_to->sa), sock_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
@ -1595,8 +1591,8 @@ read_from_cmd_socket(void *anything)
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_CmdMon, "Received %d bytes from %s:%hu fd %d",
|
DEBUG_LOG(LOGF_CmdMon, "Received %d bytes from %s fd %d",
|
||||||
status, UTI_IPToString(&remote_ip), remote_port, sock_fd);
|
status, UTI_SockaddrToString(&where_from.sa), sock_fd);
|
||||||
|
|
||||||
if (!(localhost || ADF_IsAllowed(access_auth_table, &remote_ip))) {
|
if (!(localhost || ADF_IsAllowed(access_auth_table, &remote_ip))) {
|
||||||
/* The client is not allowed access, so don't waste any more time
|
/* 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));
|
memset(&tx_message.auth, 0, sizeof(tx_message.auth));
|
||||||
|
|
||||||
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
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);
|
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) {
|
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);
|
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) {
|
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);
|
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,
|
status = sendto(sock_fd, (void *) prev_tx_message, tx_message_length, 0,
|
||||||
&where_from.sa, from_length);
|
&where_from.sa, from_length);
|
||||||
if (status < 0) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1886,9 +1886,8 @@ read_from_cmd_socket(void *anything)
|
||||||
/* If the log-on fails, record the reason why */
|
/* If the log-on fails, record the reason why */
|
||||||
if (!issue_token) {
|
if (!issue_token) {
|
||||||
DEBUG_LOG(LOGF_CmdMon,
|
DEBUG_LOG(LOGF_CmdMon,
|
||||||
"Bad command logon from %s port %d (auth_ok=%d valid_ts=%d)",
|
"Bad command logon from %s (auth_ok=%d valid_ts=%d)",
|
||||||
UTI_IPToString(&remote_ip),
|
UTI_SockaddrToString(&where_from.sa),
|
||||||
remote_port,
|
|
||||||
auth_ok, valid_ts);
|
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 *
|
const char *
|
||||||
UTI_SockaddrFamilyToString(int family)
|
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 void UTI_SockaddrToIPAndPort(struct sockaddr *sa, IPAddr *ip, unsigned short *port);
|
||||||
extern int UTI_IPAndPortToSockaddr(IPAddr *ip, unsigned short port, struct sockaddr *sa);
|
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 const char *UTI_SockaddrFamilyToString(int family);
|
||||||
|
|
||||||
extern char *UTI_TimeToLogForm(time_t t);
|
extern char *UTI_TimeToLogForm(time_t t);
|
||||||
|
|
Loading…
Reference in a new issue