summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-09-26 12:41:50 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-09-26 12:41:50 +0200
commita8b1e96d7bf91d97646789c1805587ca1ebba3e9 (patch)
treefea136da0c5c290c953d8b80a4b233a96de5d247 /runtime
parent039e23df84ed435ebd674ff5bcad6098b5038664 (diff)
parentb810f0dd3ade85efeb7dc9b99fade798764d0ac2 (diff)
downloadrsyslog-a8b1e96d7bf91d97646789c1805587ca1ebba3e9.tar.gz
rsyslog-a8b1e96d7bf91d97646789c1805587ca1ebba3e9.tar.bz2
rsyslog-a8b1e96d7bf91d97646789c1805587ca1ebba3e9.zip
Merge branch 'v7-stable-mmrfc5424addhmac'
Conflicts: Makefile.am configure.ac runtime/msg.c runtime/rsyslog.h
Diffstat (limited to 'runtime')
-rw-r--r--runtime/msg.c92
-rw-r--r--runtime/msg.h21
-rw-r--r--runtime/rsyslog.h2
3 files changed, 68 insertions, 47 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index f3181898..2bd470a1 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -384,13 +384,6 @@ MsgSetRulesetByName(msg_t *pMsg, cstr_t *rulesetName)
rulesetGetRuleset(runConf, &(pMsg->pRuleset), rsCStrGetSzStrNoNULL(rulesetName));
}
-
-static inline int getProtocolVersion(msg_t *pM)
-{
- return(pM->iProtocolVersion);
-}
-
-
/* do a DNS reverse resolution, if not already done, reflect status
* rgerhards, 2009-11-16
*/
@@ -715,7 +708,7 @@ static inline rsRetVal msgBaseConstruct(msg_t **ppThis)
pM->pszTIMESTAMP3339 = NULL;
pM->pszTIMESTAMP_MySQL = NULL;
pM->pszTIMESTAMP_PgSQL = NULL;
- pM->pCSStrucData = NULL;
+ pM->pszStrucData = NULL;
pM->pCSAPPNAME = NULL;
pM->pCSPROCID = NULL;
pM->pCSMSGID = NULL;
@@ -859,10 +852,9 @@ CODESTARTobjDestruct(msg)
free(pThis->pszRcvdAt_PgSQL);
free(pThis->pszTIMESTAMP_MySQL);
free(pThis->pszTIMESTAMP_PgSQL);
+ free(pThis->pszStrucData);
if(pThis->iLenPROGNAME >= CONF_PROGNAME_BUFSIZE)
free(pThis->PROGNAME.ptr);
- if(pThis->pCSStrucData != NULL)
- rsCStrDestruct(&pThis->pCSStrucData);
if(pThis->pCSAPPNAME != NULL)
rsCStrDestruct(&pThis->pCSAPPNAME);
if(pThis->pCSPROCID != NULL)
@@ -1014,8 +1006,13 @@ msg_t* MsgDup(msg_t* pOld)
tmpCOPYSZ(HOSTNAME);
}
}
+ if(pOld->pszStrucData == NULL) {
+ pNew->pszStrucData = NULL;
+ } else {
+ pNew->pszStrucData = (uchar*)strdup((char*)pOld->pszStrucData);
+ pNew->lenStrucData = pOld->lenStrucData;
+ }
- tmpCOPYCSTR(StrucData);
tmpCOPYCSTR(APPNAME);
tmpCOPYCSTR(PROCID);
tmpCOPYCSTR(MSGID);
@@ -1078,6 +1075,8 @@ static rsRetVal MsgSerialize(msg_t *pThis, strm_t *pStrm)
CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("pszRcvFrom"), PROPTYPE_PSZ, (void*) psz));
psz = getRcvFromIP(pThis);
CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("pszRcvFromIP"), PROPTYPE_PSZ, (void*) psz));
+ psz = pThis->pszStrucData;
+ CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("pszRcvStrucData"), PROPTYPE_PSZ, (void*) psz));
if(pThis->json != NULL) {
psz = (uchar*) json_object_get_string(pThis->json);
CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("json"), PROPTYPE_PSZ, (void*) psz));
@@ -1087,7 +1086,6 @@ static rsRetVal MsgSerialize(msg_t *pThis, strm_t *pStrm)
CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("localvars"), PROPTYPE_PSZ, (void*) psz));
}
- objSerializePTR(pStrm, pCSStrucData, CSTR);
objSerializePTR(pStrm, pCSAPPNAME, CSTR);
objSerializePTR(pStrm, pCSPROCID, CSTR);
objSerializePTR(pStrm, pCSMSGID, CSTR);
@@ -1236,7 +1234,7 @@ MsgDeserialize(msg_t *pMsg, strm_t *pStrm)
reinitVar(pVar);
CHKiRet(objDeserializeProperty(pVar, pStrm));
}
- if(isProp("pCSStrucData")) {
+ if(isProp("pszStrucData")) {
MsgSetStructuredData(pMsg, (char*) rsCStrGetSzStrNoNULL(pVar->val.pStr));
reinitVar(pVar);
CHKiRet(objDeserializeProperty(pVar, pStrm));
@@ -1326,7 +1324,7 @@ static rsRetVal aquirePROCIDFromTAG(msg_t *pM)
if(pM->pCSPROCID != NULL)
return RS_RET_OK; /* we are already done ;) */
- if(getProtocolVersion(pM) != 0)
+ if(msgGetProtocolVersion(pM) != 0)
return RS_RET_OK; /* we can only emulate if we have legacy format */
pszTag = (uchar*) ((pM->iLenTAG < CONF_TAG_BUFSIZE) ? pM->TAG.szBuf : pM->TAG.pszTAG);
@@ -2009,7 +2007,7 @@ static inline void tryEmulateTAG(msg_t *pM, sbool bLockMutex)
return; /* done, no need to emulate */
}
- if(getProtocolVersion(pM) == 1) {
+ if(msgGetProtocolVersion(pM) == 1) {
if(!strcmp(getPROCID(pM, MUTEX_ALREADY_LOCKED), "-")) {
/* no process ID, use APP-NAME only */
MsgSetTAG(pM, (uchar*) getAPPNAME(pM, MUTEX_ALREADY_LOCKED), getAPPNAMELen(pM, MUTEX_ALREADY_LOCKED));
@@ -2109,42 +2107,27 @@ rsRetVal MsgSetStructuredData(msg_t *pMsg, char* pszStrucData)
{
DEFiRet;
ISOBJ_TYPE_assert(pMsg, msg);
- if(pMsg->pCSStrucData == NULL) {
- /* we need to obtain the object first */
- CHKiRet(rsCStrConstruct(&pMsg->pCSStrucData));
- }
- /* if we reach this point, we have the object */
- iRet = rsCStrSetSzStr(pMsg->pCSStrucData, (uchar*) pszStrucData);
-
+ free(pMsg->pszStrucData);
+ CHKmalloc(pMsg->pszStrucData = (uchar*)strdup(pszStrucData));
+ pMsg->lenStrucData = strlen(pszStrucData);
finalize_it:
RETiRet;
}
-/* get the length of the "STRUCTURED-DATA" sz string
- * rgerhards, 2005-11-24
- */
-#if 0 /* This method is currently not called, be we like to preserve it */
-static int getStructuredDataLen(msg_t *pM)
-{
- return (pM->pCSStrucData == NULL) ? 1 : rsCStrLen(pM->pCSStrucData);
-}
-#endif
-
-/* get the "STRUCTURED-DATA" as sz string
- * rgerhards, 2005-11-24
- */
-static inline char *getStructuredData(msg_t *pM)
+/* get the "STRUCTURED-DATA" as sz string, including length */
+void
+MsgGetStructuredData(msg_t *pM, uchar **pBuf, rs_size_t *len)
{
- uchar *pszRet;
-
MsgLock(pM);
- if(pM->pCSStrucData == NULL)
- pszRet = UCHAR_CONSTANT("-");
- else
- pszRet = rsCStrGetSzStrNoNULL(pM->pCSStrucData);
+ if(pM->pszStrucData == NULL) {
+ *pBuf = UCHAR_CONSTANT("-"),
+ *len = 1;
+ } else {
+ *pBuf = pM->pszStrucData,
+ *len = pM->lenStrucData;
+ }
MsgUnlock(pM);
- return (char*) pszRet;
}
/* get the "programname" as sz string
@@ -2179,7 +2162,7 @@ static void tryEmulateAPPNAME(msg_t *pM)
if(pM->pCSAPPNAME != NULL)
return; /* we are already done */
- if(getProtocolVersion(pM) == 0) {
+ if(msgGetProtocolVersion(pM) == 0) {
/* only then it makes sense to emulate */
MsgSetAPPNAME(pM, (char*)getProgramName(pM, MUTEX_ALREADY_LOCKED));
}
@@ -2965,7 +2948,7 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
pRes = (uchar*)getProtocolVersionString(pMsg);
break;
case PROP_STRUCTURED_DATA:
- pRes = (uchar*)getStructuredData(pMsg);
+ MsgGetStructuredData(pMsg, &pRes, &bufLen);
break;
case PROP_APP_NAME:
pRes = (uchar*)getAPPNAME(pMsg, LOCK_MUTEX);
@@ -3863,7 +3846,7 @@ rsRetVal MsgSetProperty(msg_t *pThis, var_t *pProp)
prop.Destruct(&propRcvFrom);
} else if(isProp("pszHOSTNAME")) {
MsgSetHOSTNAME(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr), rsCStrLen(pProp->val.pStr));
- } else if(isProp("pCSStrucData")) {
+ } else if(isProp("pszStrucData")) {
MsgSetStructuredData(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pCSAPPNAME")) {
MsgSetAPPNAME(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
@@ -4217,6 +4200,23 @@ finalize_it:
RETiRet;
}
+rsRetVal
+MsgAddToStructuredData(msg_t *pMsg, uchar *toadd, rs_size_t len)
+{
+ uchar *newptr;
+ rs_size_t newlen;
+ DEFiRet;
+ newlen = pMsg->lenStrucData + len;
+ CHKmalloc(newptr = (uchar*) realloc(pMsg->pszStrucData, newlen+1));
+ pMsg->pszStrucData = newptr;
+ memcpy(pMsg->pszStrucData+pMsg->lenStrucData, toadd, len);
+ pMsg->pszStrucData[newlen] = '\0';
+ pMsg->lenStrucData = newlen;
+finalize_it:
+ RETiRet;
+}
+
+
/* dummy */
rsRetVal msgQueryInterface(void) { return RS_RET_NOT_IMPLEMENTED; }
diff --git a/runtime/msg.h b/runtime/msg.h
index 1d9e2c70..ed15622a 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -30,6 +30,7 @@
#include <pthread.h>
#include <libestr.h>
+#include <stdint.h>
#include <json.h>
#include "obj.h"
#include "syslogd-types.h"
@@ -85,7 +86,8 @@ struct msg {
char *pszTIMESTAMP3339; /* TIMESTAMP as RFC3339 formatted string (32 charcters at most) */
char *pszTIMESTAMP_MySQL;/* TIMESTAMP as MySQL formatted string (always 14 charcters) */
char *pszTIMESTAMP_PgSQL;/* TIMESTAMP as PgSQL formatted string (always 21 characters) */
- cstr_t *pCSStrucData; /* STRUCTURED-DATA */
+ uchar *pszStrucData; /* STRUCTURED-DATA */
+ uint16_t lenStrucData; /* (cached) length of STRUCTURED-DATA */
cstr_t *pCSAPPNAME; /* APP-NAME */
cstr_t *pCSPROCID; /* PROCID */
cstr_t *pCSMSGID; /* MSGID */
@@ -143,6 +145,9 @@ struct msg {
#define NEEDS_ACLCHK_U 0x080 /* check UDP ACLs after DNS resolution has been done in main queue consumer */
#define NO_PRI_IN_RAW 0x100 /* rawmsg does not include a PRI (Solaris!), but PRI is already set correctly in the msg object */
+/* (syslog) protocol types */
+#define MSG_LEGACY_PROTOCOL 0
+#define MSG_RFC5424_PROTOCOL 1
/* function prototypes
*/
@@ -165,6 +170,8 @@ void MsgSetTAG(msg_t *pMsg, uchar* pszBuf, size_t lenBuf);
void MsgSetRuleset(msg_t *pMsg, ruleset_t*);
rsRetVal MsgSetFlowControlType(msg_t *pMsg, flowControl_t eFlowCtl);
rsRetVal MsgSetStructuredData(msg_t *pMsg, char* pszStrucData);
+rsRetVal MsgAddToStructuredData(msg_t *pMsg, uchar *toadd, rs_size_t len);
+void MsgGetStructuredData(msg_t *pM, uchar **pBuf, rs_size_t *len);
rsRetVal msgSetFromSockinfo(msg_t *pThis, struct sockaddr_storage *sa);
void MsgSetRcvFrom(msg_t *pMsg, prop_t*);
void MsgSetRcvFromStr(msg_t *pMsg, uchar* pszRcvFrom, int, prop_t **);
@@ -221,6 +228,18 @@ msgUnsetJSON(msg_t *pMsg, uchar *varname) {
return msgDelJSON(pMsg, varname+1);
}
+static inline int
+msgGetProtocolVersion(msg_t *pM)
+{
+ return(pM->iProtocolVersion);
+}
+
+/* returns non-zero if the message has structured data, 0 otherwise */
+static inline sbool
+MsgHasStructuredData(msg_t *pM)
+{
+ return (pM->pszStrucData == NULL) ? 0 : 1;
+}
/* ------------------------------ some inline functions ------------------------------ */
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 7cad3eae..743296b5 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -418,6 +418,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_CA_CERT_MISSING = -2329,/**< a CA cert is missing where one is required (e.g. TLS) */
RS_RET_CERT_MISSING = -2330,/**< a cert is missing where one is required (e.g. TLS) */
RS_RET_CERTKEY_MISSING = -2331,/**< a cert (private) key is missing where one is required (e.g. TLS) */
+ RS_RET_STRUC_DATA_INVLD = -2349,/**< structured data is malformed */
+
/* up to 2350 reserved for 7.4 */
RS_RET_QUEUE_CRY_DISK_ONLY = -2351,/**< crypto provider only supported for disk-associated queues */
RS_RET_NO_DATA = -2352,/**< file has no data; more a state than a real error */