summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/cfsysline.c2
-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.c8
-rw-r--r--runtime/nsd_gtls.h2
-rw-r--r--runtime/nsdsel_gtls.c6
8 files changed, 70 insertions, 11 deletions
diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c
index 0043ce5c..ef21fb4b 100644
--- a/runtime/cfsysline.c
+++ b/runtime/cfsysline.c
@@ -464,6 +464,8 @@ getWord(uchar **pp, cstr_t **ppStrB)
CHKiRet(rsCStrConstruct(ppStrB));
+ skipWhiteSpace(pp); /* skip over any whitespace */
+
/* parse out the word */
p = *pp;
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 3edaf68f..60685de7 100644
--- a/runtime/nsd_gtls.c
+++ b/runtime/nsd_gtls.c
@@ -496,7 +496,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));
@@ -559,6 +559,12 @@ Rcv(nsd_t *pNsd, uchar *pBuf, ssize_t *pLenBuf)
/* in TLS mode now */
lenRcvd = gnutls_record_recv(pThis->sess, pBuf, *pLenBuf);
+ if(lenRcvd < 0) {
+ int gnuRet; /* TODO: build a specific function for GnuTLS error reporting */
+ *pLenBuf = -1;
+ CHKgnutls(lenRcvd); /* this will abort the function */
+ }
+
*pLenBuf = lenRcvd;
finalize_it:
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"
diff --git a/runtime/nsdsel_gtls.c b/runtime/nsdsel_gtls.c
index f8889a48..e54693dc 100644
--- a/runtime/nsdsel_gtls.c
+++ b/runtime/nsdsel_gtls.c
@@ -138,12 +138,18 @@ doRetry(nsd_gtls_t *pNsd)
break;
default:
assert(0); /* this shall not happen! */
+ dbgprintf("ERROR: pNsd->rtryCall invalid in nsdsel_gtls.c:%d\n", __LINE__);
+ gnuRet = 0; /* if it happens, we have at least a defined behaviour... ;) */
break;
}
if(gnuRet == 0) {
pNsd->rtryCall = gtlsRtry_None; /* we are done */
} else if(gnuRet != GNUTLS_E_AGAIN && gnuRet != GNUTLS_E_INTERRUPTED) {
+ uchar *pErr = gtlsStrerror(gnuRet);
+ dbgprintf("unexpected GnuTLS error %d in %s:%d: %s\n", gnuRet, __FILE__, __LINE__, pErr);
+ free(pErr);
+ pNsd->rtryCall = gtlsRtry_None; /* we are also done... ;) */
ABORT_FINALIZE(RS_RET_GNUTLS_ERR);
}
/* if we are interrupted once again (else case), we do not need to