summaryrefslogtreecommitdiffstats
path: root/net.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-03-05 14:53:25 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-03-05 14:53:25 +0000
commit24b02dc831889986211600a75572737e733ef9d8 (patch)
tree50e1525e5749c8b6e51969d8ff88060a172b0497 /net.c
parent213e0b596205626214891fb46e1a780af7f26a8b (diff)
downloadrsyslog-24b02dc831889986211600a75572737e733ef9d8.tar.gz
rsyslog-24b02dc831889986211600a75572737e733ef9d8.tar.xz
rsyslog-24b02dc831889986211600a75572737e733ef9d8.zip
- extracted logerror*() family of functions from syslogd, made them their
own class and converted to new object calling conventions (interface-based) - converted gss-misc into a loadable library module
Diffstat (limited to 'net.c')
-rw-r--r--net.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/net.c b/net.c
index a4fdfb33..43c30b53 100644
--- a/net.c
+++ b/net.c
@@ -54,6 +54,12 @@
#include "net.h"
#include "parse.h"
#include "srUtils.h"
+#include "obj.h"
+#include "errmsg.h"
+
+/* static data */
+DEFobjCurrIf(obj)
+DEFobjCurrIf(errmsg)
/* support for defining allowed TCP and UDP senders. We use the same
* structure to implement this (a linked list), but we define two different
@@ -182,14 +188,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
/* we handle this seperatly just to provide a better
* error message.
*/
- logerror("You can not specify 0 bits of the netmask, this would "
+ errmsg.LogError(NO_ERRCODE, "You can not specify 0 bits of the netmask, this would "
"match ALL systems. If you really intend to do that, "
"remove all $AllowedSender directives.");
switch (iAllow->addr.NetAddr->sa_family) {
case AF_INET:
if((iSignificantBits < 1) || (iSignificantBits > 32)) {
- logerrorInt("Invalid bit number in IPv4 address - adjusted to 32",
+ errmsg.LogError(NO_ERRCODE, "Invalid bit number in IPv4 address - adjusted to 32",
(int)iSignificantBits);
iSignificantBits = 32;
}
@@ -198,7 +204,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
break;
case AF_INET6:
if((iSignificantBits < 1) || (iSignificantBits > 128)) {
- logerrorInt("Invalid bit number in IPv6 address - adjusted to 128",
+ errmsg.LogError(NO_ERRCODE, "Invalid bit number in IPv6 address - adjusted to 128",
iSignificantBits);
iSignificantBits = 128;
}
@@ -213,7 +219,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
* worst thing that happens is that one host will not be allowed to
* log.
*/
- logerrorInt("Internal error caused AllowedSender to be ignored, AF = %d",
+ errmsg.LogError(NO_ERRCODE, "Internal error caused AllowedSender to be ignored, AF = %d",
iAllow->addr.NetAddr->sa_family);
ABORT_FINALIZE(RS_RET_ERR);
}
@@ -222,7 +228,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
} else {
/* we need to process a hostname ACL */
if (DisableDNS) {
- logerror ("Ignoring hostname based ACLs because DNS is disabled.");
+ errmsg.LogError(NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled.");
ABORT_FINALIZE(RS_RET_OK);
}
@@ -243,14 +249,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
# endif
if (getaddrinfo (iAllow->addr.HostWildcard, NULL, &hints, &res) != 0) {
- logerrorSz("DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard);
+ errmsg.LogError(NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard);
if (ACLAddHostnameOnFail) {
- logerrorSz("Adding hostname \"%s\" to ACL as a wildcard entry.", iAllow->addr.HostWildcard);
+ errmsg.LogError(NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard entry.", iAllow->addr.HostWildcard);
iRet = AddAllowedSenderEntry(ppRoot, ppLast, iAllow, iSignificantBits);
FINALIZE;
} else {
- logerrorSz("Hostname \"%s\" WON\'T be added to ACL.", iAllow->addr.HostWildcard);
+ errmsg.LogError(NO_ERRCODE, "Hostname \"%s\" WON\'T be added to ACL.", iAllow->addr.HostWildcard);
ABORT_FINALIZE(RS_RET_NOENTRY);
}
}
@@ -410,7 +416,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
ppLast = &pLastAllowedSenders_GSS;
#endif
} else {
- logerrorSz("Invalid protocol '%s' in allowed sender "
+ errmsg.LogError(NO_ERRCODE, "Invalid protocol '%s' in allowed sender "
"list, line ignored", pName);
return RS_RET_ERR;
}
@@ -421,7 +427,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
*/
/* create parser object starting with line string without leading colon */
if((iRet = rsParsConstructFromSz(&pPars, (uchar*) *ppRestOfConfLine) != RS_RET_OK)) {
- logerrorInt("Error %d constructing parser object - ignoring allowed sender list", iRet);
+ errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring allowed sender list", iRet);
return(iRet);
}
@@ -430,7 +436,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
break; /* a comment-sign stops processing of line */
/* now parse a single IP address */
if((iRet = parsAddrWithBits(pPars, &uIP, &iBits)) != RS_RET_OK) {
- logerrorInt("Error %d parsing address in allowed sender"
+ errmsg.LogError(NO_ERRCODE, "Error %d parsing address in allowed sender"
"list - ignoring.", iRet);
rsParsDestruct(pPars);
return(iRet);
@@ -438,10 +444,10 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
if((iRet = AddAllowedSender(ppRoot, ppLast, uIP, iBits))
!= RS_RET_OK) {
if (iRet == RS_RET_NOENTRY) {
- logerrorInt("Error %d adding allowed sender entry "
+ errmsg.LogError(NO_ERRCODE, "Error %d adding allowed sender entry "
"- ignoring.", iRet);
} else {
- logerrorInt("Error %d adding allowed sender entry "
+ errmsg.LogError(NO_ERRCODE, "Error %d adding allowed sender entry "
"- terminating, nothing more will be added.", iRet);
rsParsDestruct(pPars);
return(iRet);
@@ -678,7 +684,7 @@ rsRetVal gethname(struct sockaddr_storage *f, uchar *pszHostFQDN)
"Malicious PTR record, message dropped "
"IP = \"%s\" HOST = \"%s\"",
ip, pszHostFQDN);
- logerror((char*)szErrMsg);
+ errmsg.LogError(NO_ERRCODE, "%s", szErrMsg);
pthread_sigmask(SIG_SETMASK, &omask, NULL);
ABORT_FINALIZE(RS_RET_MALICIOUS_ENTITY);
}
@@ -693,7 +699,7 @@ rsRetVal gethname(struct sockaddr_storage *f, uchar *pszHostFQDN)
"Malicious PTR record (message accepted, but used IP "
"instead of PTR name: IP = \"%s\" HOST = \"%s\"",
ip, pszHostFQDN);
- logerror((char*)szErrMsg);
+ errmsg.LogError(NO_ERRCODE, "%s", szErrMsg);
error = 1; /* that will trigger using IP address below. */
}
@@ -883,8 +889,8 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res);
if(error) {
- logerror((char*) gai_strerror(error));
- logerror("UDP message reception disabled due to error logged in last message.\n");
+ errmsg.LogError(NO_ERRCODE, "%s", gai_strerror(error));
+ errmsg.LogError(NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n");
return NULL;
}
@@ -893,7 +899,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
/* EMPTY */;
socks = malloc((maxs+1) * sizeof(int));
if (socks == NULL) {
- logerror("couldn't allocate memory for UDP sockets, suspending UDP message reception");
+ errmsg.LogError(NO_ERRCODE, "couldn't allocate memory for UDP sockets, suspending UDP message reception");
freeaddrinfo(res);
return NULL;
}
@@ -904,7 +910,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
*s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
if (*s < 0) {
if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT))
- logerror("create_udp_socket(), socket");
+ errmsg.LogError(NO_ERRCODE, "create_udp_socket(), socket");
/* it is debateble if PF_INET with EAFNOSUPPORT should
* also be ignored...
*/
@@ -916,7 +922,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
int ion = 1;
if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY,
(char *)&ion, sizeof (ion)) < 0) {
- logerror("setsockopt");
+ errmsg.LogError(NO_ERRCODE, "setsockopt");
close(*s);
*s = -1;
continue;
@@ -933,7 +939,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
*/
if (setsockopt(*s, SOL_SOCKET, SO_REUSEADDR,
(char *) &on, sizeof(on)) < 0 ) {
- logerror("setsockopt(REUSEADDR)");
+ errmsg.LogError(NO_ERRCODE, "setsockopt(REUSEADDR)");
close(*s);
*s = -1;
continue;
@@ -946,7 +952,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
if (should_use_so_bsdcompat()) {
if (setsockopt(*s, SOL_SOCKET, SO_BSDCOMPAT,
(char *) &on, sizeof(on)) < 0) {
- logerror("setsockopt(BSDCOMPAT)");
+ errmsg.LogError(NO_ERRCODE, "setsockopt(BSDCOMPAT)");
close(*s);
*s = -1;
continue;
@@ -968,7 +974,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
sockflags = fcntl(*s, F_SETFL, sockflags);
}
if (sockflags == -1) {
- logerror("fcntl(O_NONBLOCK)");
+ errmsg.LogError(NO_ERRCODE, "fcntl(O_NONBLOCK)");
close(*s);
*s = -1;
continue;
@@ -987,7 +993,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
&& (errno != EADDRINUSE)
# endif
) {
- logerror("bind");
+ errmsg.LogError(NO_ERRCODE, "bind");
close(*s);
*s = -1;
continue;
@@ -1006,7 +1012,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
"- this may or may not be an error indication.\n", *socks, maxs);
if(*socks == 0) {
- logerror("No UDP listen socket could successfully be initialized, "
+ errmsg.LogError(NO_ERRCODE, "No UDP listen socket could successfully be initialized, "
"message reception via UDP disabled.\n");
/* we do NOT need to free any sockets, because there were none... */
free(socks);
@@ -1016,6 +1022,19 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
return(socks);
}
+
+/* our init function. TODO: remove once converted to a class
+ */
+rsRetVal NetInit()
+{
+ DEFiRet;
+ CHKiRet(objGetObjInterface(&obj));
+ CHKiRet(objUse(errmsg, CORE_COMPONENT));
+
+finalize_it:
+ RETiRet;
+}
+
#endif /* #ifdef SYSLOG_INET */
/*
* vi:set ai: