summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-05-16 13:36:41 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-05-16 13:36:41 +0200
commit09afe64f29bae5af8ea1749373e8c8b6586b70d1 (patch)
treeffb0034512375ede89f0d3611db0550ad58e65a9 /runtime
parenta58ad72051a73b8a26e792507544ad4b41283ca7 (diff)
downloadrsyslog-09afe64f29bae5af8ea1749373e8c8b6586b70d1.tar.gz
rsyslog-09afe64f29bae5af8ea1749373e8c8b6586b70d1.tar.xz
rsyslog-09afe64f29bae5af8ea1749373e8c8b6586b70d1.zip
added fromhost-ip properties and some bugfixes
- bugfix: TCP input modules did incorrectly set fromhost property (always blank) - bugfix: imklog did not set fromhost property - added "fromhost-ip" property - added "RSYSLOG_DebugFormat" canned template - bugfix: hostname and fromhost were swapped when a persisted message (in queued mode) was read in
Diffstat (limited to 'runtime')
-rw-r--r--runtime/msg.c41
-rw-r--r--runtime/msg.h3
-rw-r--r--runtime/net.c15
-rw-r--r--runtime/net.h4
-rw-r--r--runtime/nsd_gtls.c2
-rw-r--r--runtime/nsd_gtls.h2
6 files changed, 56 insertions, 11 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index e72ef71b..b421c88f 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -263,6 +263,8 @@ CODESTARTobjDestruct(msg)
free(pThis->pszHOSTNAME);
if(pThis->pszRcvFrom != NULL)
free(pThis->pszRcvFrom);
+ if(pThis->pszRcvFromIP != NULL)
+ free(pThis->pszRcvFromIP);
if(pThis->pszMSG != NULL)
free(pThis->pszMSG);
if(pThis->pszFacility != NULL)
@@ -422,6 +424,7 @@ static rsRetVal MsgSerialize(msg_t *pThis, strm_t *pStrm)
objSerializePTR(pStrm, pszTAG, PSZ);
objSerializePTR(pStrm, pszHOSTNAME, PSZ);
objSerializePTR(pStrm, pszRcvFrom, PSZ);
+ objSerializePTR(pStrm, pszRcvFromIP, PSZ);
objSerializePTR(pStrm, pCSStrucData, CSTR);
objSerializePTR(pStrm, pCSAPPNAME, CSTR);
@@ -1171,6 +1174,18 @@ char *getRcvFrom(msg_t *pM)
return (char*) pM->pszRcvFrom;
}
+
+uchar *getRcvFromIP(msg_t *pM)
+{
+ if(pM == NULL)
+ return (uchar*) "";
+ else
+ if(pM->pszRcvFromIP == NULL)
+ return (uchar*) "";
+ else
+ return pM->pszRcvFromIP;
+}
+
/* rgerhards 2004-11-24: set STRUCTURED DATA in msg object
*/
rsRetVal MsgSetStructuredData(msg_t *pMsg, char* pszStrucData)
@@ -1344,6 +1359,24 @@ void MsgSetRcvFrom(msg_t *pMsg, char* pszRcvFrom)
}
+/* rgerhards 2005-05-16: set pszRcvFromIP in msg object */
+rsRetVal
+MsgSetRcvFromIP(msg_t *pMsg, uchar* pszRcvFromIP)
+{
+ DEFiRet;
+ assert(pMsg != NULL);
+ if(pMsg->pszRcvFromIP != NULL) {
+ free(pMsg->pszRcvFromIP);
+ pMsg->iLenRcvFromIP = 0;
+ }
+
+ CHKmalloc(pMsg->pszRcvFromIP = (uchar*)strdup((char*)pszRcvFromIP));
+ pMsg->iLenRcvFromIP = strlen((char*)pszRcvFromIP);
+finalize_it:
+ RETiRet;
+}
+
+
/* Set the HOSTNAME to a caller-provided string. This is thought
* to be a heap buffer that the caller will no longer use. This
* function is a performance optimization over MsgSetHOSTNAME().
@@ -1597,6 +1630,8 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
pRes = getUxTradMsg(pMsg);
} else if(!strcmp((char*) pName, "fromhost")) {
pRes = getRcvFrom(pMsg);
+ } else if(!strcmp((char*) pName, "fromhost-ip")) {
+ pRes = (char*) getRcvFromIP(pMsg);
} else if(!strcmp((char*) pName, "source") || !strcmp((char*) pName, "hostname")) {
pRes = getHOSTNAME(pMsg);
} else if(!strcmp((char*) pName, "syslogtag")) {
@@ -2204,10 +2239,12 @@ rsRetVal MsgSetProperty(msg_t *pThis, var_t *pProp)
MsgSetUxTradMsg(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pszTAG")) {
MsgSetTAG(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
+ } else if(isProp("pszRcvFromIP")) {
+ MsgSetRcvFromIP(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pszRcvFrom")) {
- MsgSetHOSTNAME(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
- } else if(isProp("pszHOSTNAME")) {
MsgSetRcvFrom(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
+ } else if(isProp("pszHOSTNAME")) {
+ MsgSetHOSTNAME(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pCSStrucData")) {
MsgSetStructuredData(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pCSAPPNAME")) {
diff --git a/runtime/msg.h b/runtime/msg.h
index 9ec038dd..084123b7 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -89,6 +89,8 @@ struct msg {
int iLenHOSTNAME; /* Length of HOSTNAME */
uchar *pszRcvFrom; /* System message was received from */
int iLenRcvFrom; /* Length of pszRcvFrom */
+ uchar *pszRcvFromIP; /* IP of system message was received from */
+ int iLenRcvFromIP; /* Length of pszRcvFromIP */
short iProtocolVersion;/* protocol version of message received 0 - legacy, 1 syslog-protocol) */
cstr_t *pCSProgName; /* the (BSD) program name */
cstr_t *pCSStrucData;/* STRUCTURED-DATA */
@@ -149,6 +151,7 @@ char *getStructuredData(msg_t *pM);
int getProgramNameLen(msg_t *pM);
char *getProgramName(msg_t *pM);
void MsgSetRcvFrom(msg_t *pMsg, char* pszRcvFrom);
+rsRetVal MsgSetRcvFromIP(msg_t *pMsg, uchar* pszRcvFromIP);
void MsgAssignHOSTNAME(msg_t *pMsg, char *pBuf);
void MsgSetHOSTNAME(msg_t *pMsg, char* pszHOSTNAME);
int MsgSetUxTradMsg(msg_t *pMsg, char* pszUxTradMsg);
diff --git a/runtime/net.c b/runtime/net.c
index 1d085290..7663b1b3 100644
--- a/runtime/net.c
+++ b/runtime/net.c
@@ -626,6 +626,8 @@ should_use_so_bsdcompat(void)
* but has been moved out of it because of clarity and fuctional separation.
* It must be provided by the socket we received the message on as well as
* a NI_MAXHOST size large character buffer for the FQDN.
+ * 2008-05-16 rgerhards: added field for IP address representation. Must also
+ * be NI_MAXHOST size large.
*
* Please see http://www.hmug.org/man/3/getnameinfo.php (under Caveats)
* for some explanation of the code found below. We do by default not
@@ -635,23 +637,23 @@ should_use_so_bsdcompat(void)
* message should be processed (1) or discarded (0).
*/
static rsRetVal
-gethname(struct sockaddr_storage *f, uchar *pszHostFQDN)
+gethname(struct sockaddr_storage *f, uchar *pszHostFQDN, uchar *ip)
{
DEFiRet;
int error;
sigset_t omask, nmask;
- char ip[NI_MAXHOST];
struct addrinfo hints, *res;
assert(f != NULL);
assert(pszHostFQDN != NULL);
error = getnameinfo((struct sockaddr *)f, SALEN((struct sockaddr *)f),
- ip, sizeof ip, NULL, 0, NI_NUMERICHOST);
+ (char*) ip, sizeof ip, NULL, 0, NI_NUMERICHOST);
if (error) {
dbgprintf("Malformed from address %s\n", gai_strerror(error));
strcpy((char*) pszHostFQDN, "???");
+ strcpy((char*) ip, "???");
ABORT_FINALIZE(RS_RET_INVALID_SOURCE);
}
@@ -713,7 +715,7 @@ gethname(struct sockaddr_storage *f, uchar *pszHostFQDN)
if(error || glbl.GetDisableDNS()) {
dbgprintf("Host name for your address (%s) unknown\n", ip);
- strcpy((char*) pszHostFQDN, ip);
+ strcpy((char*) pszHostFQDN, (char*)ip);
ABORT_FINALIZE(RS_RET_ADDRESS_UNKNOWN);
}
@@ -773,8 +775,9 @@ void debugListenInfo(int fd, char *type)
* there is no way to check it. We use this way of doing things because it
* frees us from using dynamic memory allocation where it really does not
* pay.
+ * 2005-05-16 rgerhards: added IP representation. Must also be NI_MAXHOST
*/
-rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN)
+rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN, uchar *pszIP)
{
DEFiRet;
register uchar *p;
@@ -784,7 +787,7 @@ rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN
assert(pszHost != NULL);
assert(pszHostFQDN != NULL);
- iRet = gethname(f, pszHostFQDN);
+ iRet = gethname(f, pszHostFQDN, pszIP);
if(iRet == RS_RET_INVALID_SOURCE || iRet == RS_RET_ADDRESS_UNKNOWN) {
strcpy((char*) pszHost, (char*) pszHostFQDN); /* we use whatever was provided as replacement */
diff --git a/runtime/net.h b/runtime/net.h
index 59199451..9e471bf9 100644
--- a/runtime/net.h
+++ b/runtime/net.h
@@ -93,7 +93,7 @@ struct AllowedSenders {
/* interfaces */
BEGINinterface(net) /* name must also be changed in ENDinterface macro! */
- rsRetVal (*cvthname)(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN);
+ rsRetVal (*cvthname)(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN, uchar *pszIP);
/* things to go away after proper modularization */
rsRetVal (*addAllowedSenderLine)(char* pName, uchar** ppRestOfConfLine);
void (*PrintAllowedSenders)(int iListToPrint);
@@ -111,7 +111,7 @@ BEGINinterface(net) /* name must also be changed in ENDinterface macro! */
struct AllowedSenders *pAllowedSenders_TCP;
struct AllowedSenders *pAllowedSenders_GSS;
ENDinterface(net)
-#define netCURR_IF_VERSION 2 /* increment whenever you change the interface structure! */
+#define netCURR_IF_VERSION 3 /* increment whenever you change the interface structure! */
/* prototypes */
PROTOTYPEObj(net);
diff --git a/runtime/nsd_gtls.c b/runtime/nsd_gtls.c
index 5ae92913..5ea7ceb9 100644
--- a/runtime/nsd_gtls.c
+++ b/runtime/nsd_gtls.c
@@ -471,7 +471,7 @@ AcceptConnReq(nsd_t *pNsd, nsd_t **ppNew)
nsd_gtls_t *pThis = (nsd_gtls_t*) pNsd;
ISOBJ_TYPE_assert((pThis), nsd_gtls);
- CHKiRet(nsd_gtlsConstruct(&pNew));
+ CHKiRet(nsd_gtlsConstruct(&pNew)); // TODO: prevent construct/destruct!
CHKiRet(nsd_ptcp.Destruct(&pNew->pTcp));
CHKiRet(nsd_ptcp.AcceptConnReq(pThis->pTcp, &pNew->pTcp));
diff --git a/runtime/nsd_gtls.h b/runtime/nsd_gtls.h
index 83e15f29..bbb0eb9e 100644
--- a/runtime/nsd_gtls.h
+++ b/runtime/nsd_gtls.h
@@ -50,6 +50,8 @@ struct nsd_gtls_s {
/* prototypes */
PROTOTYPEObj(nsd_gtls);
+/* some prototypes for things used by our nsdsel_gtls helper class */
+uchar *gtlsStrerror(int error);
/* the name of our library binary */
#define LM_NSD_GTLS_FILENAME "lmnsd_gtls"