correct codestyle in rsyslog part 2

This commit is contained in:
PascalWithopf 2018-08-01 10:21:23 +02:00
parent 19133327cc
commit c83e3ed216
54 changed files with 1069 additions and 1018 deletions

View File

@ -852,7 +852,7 @@ actionCheckAndCreateWrkrInstance(action_t * const pThis, const wti_t *const pWti
pThis->pModData)); pThis->pModData));
pWti->actWrkrInfo[pThis->iActionNbr].pAction = pThis; pWti->actWrkrInfo[pThis->iActionNbr].pAction = pThis;
setActionState(pWti, pThis, ACT_STATE_RDY); /* action is enabled */ setActionState(pWti, pThis, ACT_STATE_RDY); /* action is enabled */
/* maintain worker data table -- only needed if wrkrHUP is requested! */ /* maintain worker data table -- only needed if wrkrHUP is requested! */
pthread_mutex_lock(&pThis->mutWrkrDataTable); pthread_mutex_lock(&pThis->mutWrkrDataTable);
@ -1401,7 +1401,7 @@ actionCommit(action_t *__restrict__ const pThis, wti_t *__restrict__ const pWti)
} }
DBGPRINTF("actionCommit[%s]: processing...\n", pThis->pszName); DBGPRINTF("actionCommit[%s]: processing...\n", pThis->pszName);
/* we now do one try at commiting the whole batch. Usually, this will /* we now do one try at commiting the whole batch. Usually, this will
* succeed. If so, we are happy and done. If not, we dig into the details * succeed. If so, we are happy and done. If not, we dig into the details
* of finding out if we have a non-temporary error and try to handle this * of finding out if we have a non-temporary error and try to handle this
* as well as retry processing. Due to this logic we do a bit more retries * as well as retry processing. Due to this logic we do a bit more retries

View File

@ -60,11 +60,11 @@
#if defined (_AIX) /* Use ifaddrs_rsys instead of ifaddrs and ifreq instead of lifreq */ #if defined (_AIX) /* Use ifaddrs_rsys instead of ifaddrs and ifreq instead of lifreq */
int getallifaddrs(sa_family_t af, struct ifaddrs_rsys **ifap, int64_t flags); int getallifaddrs(sa_family_t af, struct ifaddrs_rsys **ifap, int64_t flags);
int getallifs(int s, sa_family_t af, struct ifreq **ifr, int *numifs, int getallifs(int s, sa_family_t af, struct ifreq **ifr, int *numifs,
int64_t ifc_flags); int64_t ifc_flags);
#else #else
int getallifaddrs(sa_family_t af, struct ifaddrs **ifap, int64_t flags); int getallifaddrs(sa_family_t af, struct ifaddrs **ifap, int64_t flags);
int getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs, int getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs,
int64_t lifc_flags); int64_t lifc_flags);
#endif #endif
/* /*
@ -310,7 +310,7 @@ fail:
*/ */
int int
getallifs(int s, sa_family_t af, struct ifreq **ifr, int *iflen, getallifs(int s, sa_family_t af, struct ifreq **ifr, int *iflen,
int64_t ifc_flags) int64_t ifc_flags)
{ {
int ifsize; int ifsize;
struct ifconf ifc; struct ifconf ifc;
@ -488,7 +488,7 @@ fail:
*/ */
int int
getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs, getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs,
int64_t lifc_flags) int64_t lifc_flags)
{ {
struct lifnum lifn; struct lifnum lifn;
struct lifconf lifc; struct lifconf lifc;

View File

@ -19,6 +19,9 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
tests/inputfilegen.c \ tests/inputfilegen.c \
tests/msleep.c \ tests/msleep.c \
tests/testconfgen.c \ tests/testconfgen.c \
tests/testbench.h \
tests/uxsockrcvr.c \
tests/tcpflood.c \
plugins/imfile/imfile.c \ plugins/imfile/imfile.c \
plugins/imrelp/imrelp.c \ plugins/imrelp/imrelp.c \
plugins/omrelp/omrelp.c \ plugins/omrelp/omrelp.c \
@ -72,6 +75,11 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
plugins/mmanon/mmanon.c \ plugins/mmanon/mmanon.c \
plugins/mmdblookup/mmdblookup.c \ plugins/mmdblookup/mmdblookup.c \
plugins/omudpspoof/omudpspoof.c \ plugins/omudpspoof/omudpspoof.c \
plugins/omsnmp/omsnmp.c \
plugins/imuxsock/imuxsock.c \
plugins/pmciscoios/pmciscoios.c \
plugins/imgssapi/imgssapi.c \
plugins/ommongodb/ommongodb.c \
grammar/testdriver.c \ grammar/testdriver.c \
runtime/netstrms.h \ runtime/netstrms.h \
runtime/lib_ksi_queue.h \ runtime/lib_ksi_queue.h \
@ -149,6 +157,30 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
runtime/tcpsrv.h \ runtime/tcpsrv.h \
runtime/janitor.c \ runtime/janitor.c \
runtime/linkedlist.c \ runtime/linkedlist.c \
runtime/tcpsrv.c \
runtime/gss-misc.c \
runtime/obj.c \
runtime/hashtable/hashtable_utility.c \
runtime/conf.c \
runtime/hashtable_itr.h \
runtime/debug.c \
runtime/parser.h \
runtime/strmsrv.c \
runtime/queue.c \
runtime/lib_ksi_queue.c \
runtime/typedefs.h \
runtime/tcpclt.c \
runtime/statsobj.c \
runtime/dnscache.c \
runtime/unlimited_select.h \
runtime/srutils.c \
runtime/nsd_ptcp.c \
runtime/net.c \
runtime/msg.c \
runtime/hashtable_itr.c \
runtime/librsksi_read.c \
runtime/hashtable/tester.c \
runtime/hashtable.c \
contrib/mmkubernetes/mmkubernetes.c \ contrib/mmkubernetes/mmkubernetes.c \
contrib/mmrfc5424addhmac/mmrfc5424addhmac.c \ contrib/mmrfc5424addhmac/mmrfc5424addhmac.c \
contrib/mmcount/mmcount.c \ contrib/mmcount/mmcount.c \
@ -166,5 +198,24 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
contrib/omhiredis/omhiredis.c \ contrib/omhiredis/omhiredis.c \
contrib/omczmq/omczmq.c \ contrib/omczmq/omczmq.c \
contrib/omrabbitmq/omrabbitmq.c \ contrib/omrabbitmq/omrabbitmq.c \
compat/getifaddrs.c \
grammar/rainerscript.h \
grammar/rainerscript.c \
tools/omfile.c \
tools/rsyslogd.c \
tools/syncdemo.c \
tools/syslogd.c \
tools/logctl.c \
tools/omfwd.c \
tools/pmrfc3164.c \
tools/rscryutil.c \
tools/pmrfc5424.c \
tools/ompipe.c \
parse.c \
parse.h \ parse.h \
action.h action.h \
template.h \
threads.c \
outchannel.c \
action.c \
template.c

View File

@ -775,12 +775,12 @@ doGetSize(struct nvlst *valnode, struct cnfparamdescr *param,
/* and now the "new" 1000-based definitions */ /* and now the "new" 1000-based definitions */
case 'K': n *= 1000; break; case 'K': n *= 1000; break;
case 'M': n *= 1000000; break; case 'M': n *= 1000000; break;
case 'G': n *= 1000000000; break; case 'G': n *= 1000000000; break;
/* we need to use the multiplication below because otherwise /* we need to use the multiplication below because otherwise
* the compiler gets an error during constant parsing */ * the compiler gets an error during constant parsing */
case 'T': n *= (int64) 1000 * 1000000000; break; /* tera */ case 'T': n *= (int64) 1000 * 1000000000; break; /* tera */
case 'P': n *= (int64) 1000000 * 1000000000; break; /* peta */ case 'P': n *= (int64) 1000000 * 1000000000; break; /* peta */
case 'E': n *= (int64) 1000000000 * 1000000000; break; /* exa */ case 'E': n *= (int64) 1000000000 * 1000000000; break; /* exa */
default: --i; break; /* indicates error */ default: --i; break; /* indicates error */
} }
} }
@ -1478,7 +1478,7 @@ static rsRetVal
doExtractFieldByChar(uchar *str, uchar delim, const int matchnbr, uchar **resstr) doExtractFieldByChar(uchar *str, uchar delim, const int matchnbr, uchar **resstr)
{ {
int iCurrFld; int iCurrFld;
int allocLen; int allocLen;
int iLen; int iLen;
uchar *pBuf; uchar *pBuf;
uchar *pFld; uchar *pFld;
@ -1512,7 +1512,7 @@ doExtractFieldByChar(uchar *str, uchar delim, const int matchnbr, uchar **resstr
allocLen = iLen + 1; allocLen = iLen + 1;
# ifdef VALGRIND # ifdef VALGRIND
allocLen += (3 - (iLen % 4)); allocLen += (3 - (iLen % 4));
/*older versions of valgrind have a problem with strlen inspecting 4-bytes at a time*/ /*older versions of valgrind have a problem with strlen inspecting 4-bytes at a time*/
# endif # endif
CHKmalloc(pBuf = MALLOC(allocLen)); CHKmalloc(pBuf = MALLOC(allocLen));
/* now copy */ /* now copy */
@ -1699,24 +1699,24 @@ doFunc_exec_template(struct cnffunc *__restrict__ const func,
static es_str_t* static es_str_t*
doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restrict__ const findVal, doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restrict__ const findVal,
struct svar *__restrict__ const replaceWithVal) { struct svar *__restrict__ const replaceWithVal) {
int freeOperand, freeFind, freeReplacement; int freeOperand, freeFind, freeReplacement;
es_str_t *str = var2String(operandVal, &freeOperand); es_str_t *str = var2String(operandVal, &freeOperand);
es_str_t *findStr = var2String(findVal, &freeFind); es_str_t *findStr = var2String(findVal, &freeFind);
es_str_t *replaceWithStr = var2String(replaceWithVal, &freeReplacement); es_str_t *replaceWithStr = var2String(replaceWithVal, &freeReplacement);
uchar *find = es_getBufAddr(findStr); uchar *find = es_getBufAddr(findStr);
uchar *replaceWith = es_getBufAddr(replaceWithStr); uchar *replaceWith = es_getBufAddr(replaceWithStr);
uint lfind = es_strlen(findStr); uint lfind = es_strlen(findStr);
uint lReplaceWith = es_strlen(replaceWithStr); uint lReplaceWith = es_strlen(replaceWithStr);
uint lSrc = es_strlen(str); uint lSrc = es_strlen(str);
uint lDst = 0; uint lDst = 0;
uchar* src_buff = es_getBufAddr(str); uchar* src_buff = es_getBufAddr(str);
uint i, j; uint i, j;
for(i = j = 0; i <= lSrc; i++, lDst++) { for(i = j = 0; i <= lSrc; i++, lDst++) {
if (j == lfind) { if (j == lfind) {
lDst = lDst - lfind + lReplaceWith; lDst = lDst - lfind + lReplaceWith;
j = 0; j = 0;
} }
if (i == lSrc) break; if (i == lSrc) break;
if (src_buff[i] == find[j]) { if (src_buff[i] == find[j]) {
j++; j++;
@ -1725,16 +1725,16 @@ doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restric
lDst -= (j - 1); lDst -= (j - 1);
j = 0; j = 0;
} }
} }
es_str_t *res = es_newStr(lDst); es_str_t *res = es_newStr(lDst);
unsigned char* dest = es_getBufAddr(res); unsigned char* dest = es_getBufAddr(res);
uint k, s; uint k, s;
for(i = j = s = 0; i <= lSrc; i++, s++) { for(i = j = s = 0; i <= lSrc; i++, s++) {
if (j == lfind) { if (j == lfind) {
s -= j; s -= j;
for (k = 0; k < lReplaceWith; k++, s++) dest[s] = replaceWith[k]; for (k = 0; k < lReplaceWith; k++, s++) dest[s] = replaceWith[k];
j = 0; j = 0;
} }
if (i == lSrc) break; if (i == lSrc) break;
if (src_buff[i] == find[j]) { if (src_buff[i] == find[j]) {
j++; j++;
@ -1746,15 +1746,15 @@ doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restric
} }
dest[s] = src_buff[i]; dest[s] = src_buff[i];
} }
} }
if (j > 0) { if (j > 0) {
for (k = 1; k <= j; k++) dest[s - k] = src_buff[i - k]; for (k = 1; k <= j; k++) dest[s - k] = src_buff[i - k];
} }
res->lenStr = lDst; res->lenStr = lDst;
if(freeOperand) es_deleteStr(str); if(freeOperand) es_deleteStr(str);
if(freeFind) es_deleteStr(findStr); if(freeFind) es_deleteStr(findStr);
if(freeReplacement) es_deleteStr(replaceWithStr); if(freeReplacement) es_deleteStr(replaceWithStr);
return res; return res;
} }

View File

@ -83,11 +83,11 @@ struct objlst {
}; };
struct nvlst { struct nvlst {
struct nvlst *next; struct nvlst *next;
es_str_t *name; es_str_t *name;
struct svar val; struct svar val;
unsigned char bUsed; unsigned char bUsed;
/**< was this node used during config processing? If not, this /**< was this node used during config processing? If not, this
* indicates an error. After all, the user specified a setting * indicates an error. After all, the user specified a setting
* that the software does not know. * that the software does not know.
*/ */
@ -164,13 +164,13 @@ struct cnfstmt {
struct cnfstmt *t_else; struct cnfstmt *t_else;
} s_propfilt; } s_propfilt;
struct action_s *act; struct action_s *act;
struct { struct {
struct cnfitr *iter; struct cnfitr *iter;
struct cnfstmt *body; struct cnfstmt *body;
} s_foreach; } s_foreach;
struct { struct {
lookup_ref_t *table; lookup_ref_t *table;
uchar *table_name; uchar *table_name;
uchar *stub_value; uchar *stub_value;
} s_reload_lookup_table; } s_reload_lookup_table;
} d; } d;
@ -183,8 +183,8 @@ struct cnfexpr {
} __attribute__((aligned (8))); } __attribute__((aligned (8)));
struct cnfitr { struct cnfitr {
char* var; char* var;
struct cnfexpr* collection; struct cnfexpr* collection;
} __attribute__((aligned (8))); } __attribute__((aligned (8)));
struct cnfnumval { struct cnfnumval {

View File

@ -199,7 +199,7 @@ finalize_it:
struct outchannel *ochAddLine(char* pName, uchar** ppRestOfConfLine) struct outchannel *ochAddLine(char* pName, uchar** ppRestOfConfLine)
{ {
struct outchannel *pOch; struct outchannel *pOch;
uchar *p; uchar *p;
assert(pName != NULL); assert(pName != NULL);
assert(ppRestOfConfLine != NULL); assert(ppRestOfConfLine != NULL);

View File

@ -409,8 +409,8 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits)
/* now we have the string and must check/convert it to /* now we have the string and must check/convert it to
* an NetAddr structure. * an NetAddr structure.
*/ */
CHKiRet(cstrConvSzStrAndDestruct(&pCStr, &pszIP, 0)); CHKiRet(cstrConvSzStrAndDestruct(&pCStr, &pszIP, 0));
if((*pIP = calloc(1, sizeof(struct NetAddr))) == NULL) if((*pIP = calloc(1, sizeof(struct NetAddr))) == NULL)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
@ -442,7 +442,7 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits)
free (*pIP); free (*pIP);
ABORT_FINALIZE(RS_RET_ERR); ABORT_FINALIZE(RS_RET_ERR);
} }
if(*pC == '/') { if(*pC == '/') {
/* mask bits follow, let's parse them! */ /* mask bits follow, let's parse them! */
++pThis->iCurrPos; /* eat slash */ ++pThis->iCurrPos; /* eat slash */
@ -478,7 +478,7 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits)
free (*pIP); free (*pIP);
ABORT_FINALIZE(RS_RET_ERR); ABORT_FINALIZE(RS_RET_ERR);
} }
if(*pC == '/') { if(*pC == '/') {
/* mask bits follow, let's parse them! */ /* mask bits follow, let's parse them! */
++pThis->iCurrPos; /* eat slash */ ++pThis->iCurrPos; /* eat slash */

View File

@ -510,7 +510,7 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t *pSess)
ABORT_FINALIZE(RS_RET_OK); // TODO: define good error codes ABORT_FINALIZE(RS_RET_OK); // TODO: define good error codes
} }
freeFdSet(pFds); freeFdSet(pFds);
} }
context = &pGSess->gss_context; context = &pGSess->gss_context;
@ -565,10 +565,10 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t *pSess)
maj_stat = gss_display_name(&min_stat, client, &recv_tok, NULL); maj_stat = gss_display_name(&min_stat, client, &recv_tok, NULL);
if (maj_stat != GSS_S_COMPLETE) { if (maj_stat != GSS_S_COMPLETE) {
gssutil.display_status((char*)"displaying name", maj_stat, min_stat); gssutil.display_status((char*)"displaying name", maj_stat, min_stat);
} else { } else {
dbgprintf("GSS-API Accepted connection from peer %s: %s\n", (char *)pszPeer, dbgprintf("GSS-API Accepted connection from peer %s: %s\n", (char *)pszPeer,
(char*) recv_tok.value); (char*) recv_tok.value);
} }
gss_release_name(&min_stat, &client); gss_release_name(&min_stat, &client);
gss_release_buffer(&min_stat, &recv_tok); gss_release_buffer(&min_stat, &recv_tok);
@ -736,7 +736,7 @@ CODESTARTmodExit
objRelease(glbl, CORE_COMPONENT); objRelease(glbl, CORE_COMPONENT);
objRelease(netstrm, LM_NETSTRM_FILENAME); objRelease(netstrm, LM_NETSTRM_FILENAME);
objRelease(net, LM_NET_FILENAME); objRelease(net, LM_NET_FILENAME);
objRelease(prop, CORE_COMPONENT); objRelease(prop, CORE_COMPONENT);
ENDmodExit ENDmodExit
@ -770,7 +770,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
} }
bPermitPlainTcp = 0; bPermitPlainTcp = 0;
iTCPSessMax = 200; iTCPSessMax = 200;
bKeepAlive = 0; bKeepAlive = 0;
return RS_RET_OK; return RS_RET_OK;
} }
@ -787,7 +787,7 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(glbl, CORE_COMPONENT)); CHKiRet(objUse(glbl, CORE_COMPONENT));
CHKiRet(objUse(netstrm, LM_NETSTRM_FILENAME)); CHKiRet(objUse(netstrm, LM_NETSTRM_FILENAME));
CHKiRet(objUse(net, LM_NET_FILENAME)); CHKiRet(objUse(net, LM_NET_FILENAME));
CHKiRet(objUse(prop, CORE_COMPONENT)); CHKiRet(objUse(prop, CORE_COMPONENT));
/* register config file handlers */ /* register config file handlers */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverpermitplaintcp", 0, eCmdHdlrBinary, CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverpermitplaintcp", 0, eCmdHdlrBinary,
@ -798,7 +798,7 @@ CODEmodInit_QueryRegCFSLineHdlr
NULL, &gss_listen_service_name, STD_LOADABLE_MODULE_ID)); NULL, &gss_listen_service_name, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssservermaxsessions", 0, eCmdHdlrInt, CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssservermaxsessions", 0, eCmdHdlrInt,
NULL, &iTCPSessMax, STD_LOADABLE_MODULE_ID)); NULL, &iTCPSessMax, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverkeepalive", 0, eCmdHdlrBinary, CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverkeepalive", 0, eCmdHdlrBinary,
NULL, &bKeepAlive, STD_LOADABLE_MODULE_ID)); NULL, &bKeepAlive, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));

View File

@ -1564,12 +1564,12 @@ CODESTARTafterRun
} }
/* Close the UNIX sockets. */ /* Close the UNIX sockets. */
for (i = 0; i < nfd; i++) for (i = 0; i < nfd; i++)
if (listeners[i].fd != -1) if (listeners[i].fd != -1)
close(listeners[i].fd); close(listeners[i].fd);
/* Clean-up files. */ /* Clean-up files. */
for(i = startIndexUxLocalSockets; i < nfd; i++) for(i = startIndexUxLocalSockets; i < nfd; i++)
if (listeners[i].sockName && listeners[i].fd != -1) { if (listeners[i].sockName && listeners[i].fd != -1) {
/* If systemd passed us a socket it is systemd's job to clean it up. /* If systemd passed us a socket it is systemd's job to clean it up.
* Do not unlink it -- we will get same socket (node) from systemd * Do not unlink it -- we will get same socket (node) from systemd

View File

@ -493,9 +493,9 @@ static bson_t *BSONFromJSONObject(struct json_object *json)
return doc; return doc;
error: error:
if(doc != NULL) if(doc != NULL)
bson_destroy(doc); bson_destroy(doc);
return NULL; return NULL;
} }

View File

@ -564,7 +564,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
BEGINmodExit BEGINmodExit
CODESTARTmodExit CODESTARTmodExit
free(cs.pszTarget); free(cs.pszTarget);
free(cs.pszCommunity); free(cs.pszCommunity);
free(cs.pszEnterpriseOID); free(cs.pszEnterpriseOID);
free(cs.pszSnmpTrapOID); free(cs.pszSnmpTrapOID);

View File

@ -219,19 +219,19 @@ CODESTARTparse2
} }
/* Note: date parser strips ": ", so we cannot do the delimiter check here */ /* Note: date parser strips ": ", so we cannot do the delimiter check here */
/* XR RSP (optional) */ /* XR RSP (optional) */
if(pInst->bXrPresent) { if(pInst->bXrPresent) {
while( lenMsg > 1 while( lenMsg > 1
&& !(*p2parse == '%')) { && !(*p2parse == '%')) {
--lenMsg; --lenMsg;
p2parse++; p2parse++;
} }
/* delimiter check */ /* delimiter check */
if(lenMsg < 2) { if(lenMsg < 2) {
DBGPRINTF("pmciscoios: fail after XR tag search: '%s'\n", p2parse); DBGPRINTF("pmciscoios: fail after XR tag search: '%s'\n", p2parse);
ABORT_FINALIZE(RS_RET_COULD_NOT_PARSE); ABORT_FINALIZE(RS_RET_COULD_NOT_PARSE);
} }
} }
/* parse SYSLOG TAG. must always start with '%', else we have a field mismatch */ /* parse SYSLOG TAG. must always start with '%', else we have a field mismatch */
if(lenMsg < 1 || *p2parse != '%') { if(lenMsg < 1 || *p2parse != '%') {

View File

@ -626,7 +626,7 @@ BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANG
CHKiRet(objUse(net, LM_NET_FILENAME)); /* TODO: make this dependcy go away! */ CHKiRet(objUse(net, LM_NET_FILENAME)); /* TODO: make this dependcy go away! */
CHKiRet(objUse(ruleset, CORE_COMPONENT)); CHKiRet(objUse(ruleset, CORE_COMPONENT));
/* These commands will NOT be supported -- the new v6.3 config system provides /* These commands will NOT be supported -- the new v6.3 config system provides
* far better methods. We will remove the related code soon. -- rgerhards, 2012-01-09 * far better methods. We will remove the related code soon. -- rgerhards, 2012-01-09
*/ */
CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables,

View File

@ -575,20 +575,20 @@ int dbgMutexLock(pthread_mutex_t *pmut, dbgFuncDB_t *pFuncDB, int ln, int iStack
/* wrapper for pthread_mutex_trylock() */ /* wrapper for pthread_mutex_trylock() */
int dbgMutexTryLock(pthread_mutex_t *pmut, dbgFuncDB_t *pFuncDB, int ln, int iStackPtr) int dbgMutexTryLock(pthread_mutex_t *pmut, dbgFuncDB_t *pFuncDB, int ln, int iStackPtr)
{ {
int ret; int ret;
dbgRecordExecLocation(iStackPtr, ln); dbgRecordExecLocation(iStackPtr, ln);
dbgMutexPreLockLog(pmut, pFuncDB, ln); // TODO : update this dbgMutexPreLockLog(pmut, pFuncDB, ln); // TODO : update this
ret = pthread_mutex_trylock(pmut); ret = pthread_mutex_trylock(pmut);
if(ret == 0 || ret == EBUSY) { if(ret == 0 || ret == EBUSY) {
// TODO : update this // TODO : update this
dbgMutexLockLog(pmut, pFuncDB, ln); dbgMutexLockLog(pmut, pFuncDB, ln);
} else { } else {
dbgprintf("%s:%d:%s: ERROR: pthread_mutex_trylock() for mutex %p failed with error %d\n", dbgprintf("%s:%d:%s: ERROR: pthread_mutex_trylock() for mutex %p failed with error %d\n",
pFuncDB->file, ln, pFuncDB->func, (void*)pmut, ret); pFuncDB->file, ln, pFuncDB->func, (void*)pmut, ret);
} }
return ret; return ret;
} }
@ -730,9 +730,9 @@ static void dbgCallStackDestruct(void *arg)
free(pThrd->pszThrdName); free(pThrd->pszThrdName);
} }
pthread_mutex_lock(&mutCallStack); pthread_mutex_lock(&mutCallStack);
DLL_Del(CallStack, pThrd); DLL_Del(CallStack, pThrd);
pthread_mutex_unlock(&mutCallStack); pthread_mutex_unlock(&mutCallStack);
} }
@ -965,7 +965,7 @@ checkDbgFile(const char *srcname)
* time being. -- rgerhards, 2008-01-29 * time being. -- rgerhards, 2008-01-29
*/ */
#ifndef DEBUGLESS #ifndef DEBUGLESS
void void
r_dbgoprint( const char *srcname, obj_t *pObj, const char *fmt, ...) r_dbgoprint( const char *srcname, obj_t *pObj, const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -194,8 +194,8 @@ findEntry(struct sockaddr_storage *addr)
*/ */
static int static int
mygetnameinfo(const struct sockaddr *sa, socklen_t salen, mygetnameinfo(const struct sockaddr *sa, socklen_t salen,
char *host, size_t hostlen, char *host, size_t hostlen,
char *serv, size_t servlen, int flags) char *serv, size_t servlen, int flags)
{ {
int iCancelStateSave; int iCancelStateSave;
int i; int i;
@ -296,10 +296,10 @@ resolveAddr(struct sockaddr_storage *addr, dnscache_entry_t *etry)
rs_size_t fqdnLen; rs_size_t fqdnLen;
rs_size_t i; rs_size_t i;
error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *)addr), error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *)addr),
(char*) szIP, sizeof(szIP), NULL, 0, NI_NUMERICHOST); (char*) szIP, sizeof(szIP), NULL, 0, NI_NUMERICHOST);
if(error) { if(error) {
dbgprintf("Malformed from address %s\n", gai_strerror(error)); dbgprintf("Malformed from address %s\n", gai_strerror(error));
ABORT_FINALIZE(RS_RET_INVALID_SOURCE); ABORT_FINALIZE(RS_RET_INVALID_SOURCE);
} }
@ -310,7 +310,7 @@ resolveAddr(struct sockaddr_storage *addr, dnscache_entry_t *etry)
error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *) addr), error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *) addr),
fqdnBuf, NI_MAXHOST, NULL, 0, NI_NAMEREQD); fqdnBuf, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
if(error == 0) { if(error == 0) {
memset (&hints, 0, sizeof (struct addrinfo)); memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_flags = AI_NUMERICHOST; hints.ai_flags = AI_NUMERICHOST;
@ -375,13 +375,13 @@ finalize_it:
/* we need to create the inputName property (only once during our lifetime) */ /* we need to create the inputName property (only once during our lifetime) */
prop.CreateStringProp(&etry->ip, (uchar*)szIP, strlen(szIP)); prop.CreateStringProp(&etry->ip, (uchar*)szIP, strlen(szIP));
if(error || glbl.GetDisableDNS()) { if(error || glbl.GetDisableDNS()) {
dbgprintf("Host name for your address (%s) unknown\n", szIP); dbgprintf("Host name for your address (%s) unknown\n", szIP);
prop.AddRef(etry->ip); prop.AddRef(etry->ip);
etry->fqdn = etry->ip; etry->fqdn = etry->ip;
prop.AddRef(etry->ip); prop.AddRef(etry->ip);
etry->fqdnLowerCase = etry->ip; etry->fqdnLowerCase = etry->ip;
} }
setLocalHostName(etry); setLocalHostName(etry);

View File

@ -149,21 +149,21 @@ static int read_all(int fd, char *buf, unsigned int nbyte)
static int write_all(int fd, char *buf, unsigned int nbyte) static int write_all(int fd, char *buf, unsigned int nbyte)
{ {
int ret; int ret;
char *ptr; char *ptr;
for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) { for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) {
ret = send(fd, ptr, nbyte, 0); ret = send(fd, ptr, nbyte, 0);
if (ret < 0) { if (ret < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
return (ret); return (ret);
} else if (ret == 0) { } else if (ret == 0) {
return (ptr - buf); return (ptr - buf);
}
} }
}
return (ptr - buf); return (ptr - buf);
} }

View File

@ -18,8 +18,8 @@
/* /*
Credit for primes table: Aaron Krowne Credit for primes table: Aaron Krowne
http://br.endernet.org/~akrowne/ http://br.endernet.org/~akrowne/
http://planetmath.org/encyclopedia/GoodHashTablePrimes.html http://planetmath.org/encyclopedia/GoodHashTablePrimes.html
*/ */
static const unsigned int primes[] = { static const unsigned int primes[] = {
53, 97, 193, 389, 53, 97, 193, 389,
@ -40,36 +40,36 @@ const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
static inline unsigned static inline unsigned
getLoadLimit(unsigned size) getLoadLimit(unsigned size)
{ {
return (unsigned int) ((unsigned long long) size * MAX_LOAD_FACTOR) / 100; return (unsigned int) ((unsigned long long) size * MAX_LOAD_FACTOR) / 100;
} }
/*****************************************************************************/ /*****************************************************************************/
struct hashtable * struct hashtable *
create_hashtable(unsigned int minsize, create_hashtable(unsigned int minsize,
unsigned int (*hashf) (void*), unsigned int (*hashf) (void*),
int (*eqf) (void*,void*), void (*dest)(void*)) int (*eqf) (void*,void*), void (*dest)(void*))
{ {
struct hashtable *h; struct hashtable *h;
unsigned int pindex, size = primes[0]; unsigned int pindex, size = primes[0];
/* Check requested hashtable isn't too large */ /* Check requested hashtable isn't too large */
if (minsize > (1u << 30)) return NULL; if (minsize > (1u << 30)) return NULL;
/* Enforce size as prime */ /* Enforce size as prime */
for (pindex=0; pindex < prime_table_length; pindex++) { for (pindex=0; pindex < prime_table_length; pindex++) {
if (primes[pindex] > minsize) { size = primes[pindex]; break; } if (primes[pindex] > minsize) { size = primes[pindex]; break; }
} }
h = (struct hashtable *)malloc(sizeof(struct hashtable)); h = (struct hashtable *)malloc(sizeof(struct hashtable));
if (NULL == h) return NULL; /*oom*/ if (NULL == h) return NULL; /*oom*/
h->table = (struct entry **)malloc(sizeof(struct entry*) * size); h->table = (struct entry **)malloc(sizeof(struct entry*) * size);
if (NULL == h->table) { free(h); return NULL; } /*oom*/ if (NULL == h->table) { free(h); return NULL; } /*oom*/
memset(h->table, 0, size * sizeof(struct entry *)); memset(h->table, 0, size * sizeof(struct entry *));
h->tablelength = size; h->tablelength = size;
h->primeindex = pindex; h->primeindex = pindex;
h->entrycount = 0; h->entrycount = 0;
h->hashfn = hashf; h->hashfn = hashf;
h->eqfn = eqf; h->eqfn = eqf;
h->dest = dest; h->dest = dest;
h->loadlimit = getLoadLimit(size); h->loadlimit = getLoadLimit(size);
return h; return h;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -82,158 +82,158 @@ __attribute__((no_sanitize("unsigned-integer-overflow")))
#endif #endif
hash(struct hashtable *h, void *k) hash(struct hashtable *h, void *k)
{ {
/* Aim to protect against poor hash functions by adding logic here /* Aim to protect against poor hash functions by adding logic here
* - logic taken from java 1.4 hashtable source */ * - logic taken from java 1.4 hashtable source */
unsigned int i = h->hashfn(k); unsigned int i = h->hashfn(k);
i += ~(i << 9); i += ~(i << 9);
i ^= ((i >> 14) | (i << 18)); /* >>> */ i ^= ((i >> 14) | (i << 18)); /* >>> */
i += (i << 4); i += (i << 4);
i ^= ((i >> 10) | (i << 22)); /* >>> */ i ^= ((i >> 10) | (i << 22)); /* >>> */
return i; return i;
} }
/*****************************************************************************/ /*****************************************************************************/
static int static int
hashtable_expand(struct hashtable *h) hashtable_expand(struct hashtable *h)
{ {
/* Double the size of the table to accomodate more entries */ /* Double the size of the table to accomodate more entries */
struct entry **newtable; struct entry **newtable;
struct entry *e; struct entry *e;
struct entry **pE; struct entry **pE;
unsigned int newsize, i, idx; unsigned int newsize, i, idx;
/* Check we're not hitting max capacity */ /* Check we're not hitting max capacity */
if (h->primeindex == (prime_table_length - 1)) return 0; if (h->primeindex == (prime_table_length - 1)) return 0;
newsize = primes[++(h->primeindex)]; newsize = primes[++(h->primeindex)];
newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize);
if (NULL != newtable) if (NULL != newtable)
{ {
memset(newtable, 0, newsize * sizeof(struct entry *)); memset(newtable, 0, newsize * sizeof(struct entry *));
/* This algorithm is not 'stable'. ie. it reverses the list /* This algorithm is not 'stable'. ie. it reverses the list
* when it transfers entries between the tables */ * when it transfers entries between the tables */
for (i = 0; i < h->tablelength; i++) { for (i = 0; i < h->tablelength; i++) {
while (NULL != (e = h->table[i])) { while (NULL != (e = h->table[i])) {
h->table[i] = e->next; h->table[i] = e->next;
idx = indexFor(newsize,e->h); idx = indexFor(newsize,e->h);
e->next = newtable[idx]; e->next = newtable[idx];
newtable[idx] = e; newtable[idx] = e;
} }
} }
free(h->table); free(h->table);
h->table = newtable; h->table = newtable;
} }
/* Plan B: realloc instead */ /* Plan B: realloc instead */
else else
{ {
newtable = (struct entry **) newtable = (struct entry **)
realloc(h->table, newsize * sizeof(struct entry *)); realloc(h->table, newsize * sizeof(struct entry *));
if (NULL == newtable) { (h->primeindex)--; return 0; } if (NULL == newtable) { (h->primeindex)--; return 0; }
h->table = newtable; h->table = newtable;
memset(newtable[h->tablelength], 0, newsize - h->tablelength); memset(newtable[h->tablelength], 0, newsize - h->tablelength);
for (i = 0; i < h->tablelength; i++) { for (i = 0; i < h->tablelength; i++) {
for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) {
idx = indexFor(newsize,e->h); idx = indexFor(newsize,e->h);
if (idx == i) if (idx == i)
{ {
pE = &(e->next); pE = &(e->next);
} }
else else
{ {
*pE = e->next; *pE = e->next;
e->next = newtable[idx]; e->next = newtable[idx];
newtable[idx] = e; newtable[idx] = e;
} }
} }
} }
} }
h->tablelength = newsize; h->tablelength = newsize;
h->loadlimit = getLoadLimit(newsize); h->loadlimit = getLoadLimit(newsize);
return -1; return -1;
} }
/*****************************************************************************/ /*****************************************************************************/
unsigned int unsigned int
hashtable_count(struct hashtable *h) hashtable_count(struct hashtable *h)
{ {
return h->entrycount; return h->entrycount;
} }
/*****************************************************************************/ /*****************************************************************************/
int int
hashtable_insert(struct hashtable *h, void *k, void *v) hashtable_insert(struct hashtable *h, void *k, void *v)
{ {
/* This method allows duplicate keys - but they shouldn't be used */ /* This method allows duplicate keys - but they shouldn't be used */
unsigned int idx; unsigned int idx;
struct entry *e; struct entry *e;
if (++(h->entrycount) > h->loadlimit) if (++(h->entrycount) > h->loadlimit)
{ {
/* Ignore the return value. If expand fails, we should /* Ignore the return value. If expand fails, we should
* still try cramming just this value into the existing table * still try cramming just this value into the existing table
* -- we may not have memory for a larger table, but one more * -- we may not have memory for a larger table, but one more
* element may be ok. Next time we insert, we'll try expanding again.*/ * element may be ok. Next time we insert, we'll try expanding again.*/
hashtable_expand(h); hashtable_expand(h);
} }
e = (struct entry *)malloc(sizeof(struct entry)); e = (struct entry *)malloc(sizeof(struct entry));
if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
e->h = hash(h,k); e->h = hash(h,k);
idx = indexFor(h->tablelength,e->h); idx = indexFor(h->tablelength,e->h);
e->k = k; e->k = k;
e->v = v; e->v = v;
e->next = h->table[idx]; e->next = h->table[idx];
h->table[idx] = e; h->table[idx] = e;
return -1; return -1;
} }
/*****************************************************************************/ /*****************************************************************************/
void * /* returns value associated with key */ void * /* returns value associated with key */
hashtable_search(struct hashtable *h, void *k) hashtable_search(struct hashtable *h, void *k)
{ {
struct entry *e; struct entry *e;
unsigned int hashvalue, idx; unsigned int hashvalue, idx;
hashvalue = hash(h,k); hashvalue = hash(h,k);
idx = indexFor(h->tablelength,hashvalue); idx = indexFor(h->tablelength,hashvalue);
e = h->table[idx]; e = h->table[idx];
while (NULL != e) while (NULL != e)
{ {
/* Check hash value to short circuit heavier comparison */ /* Check hash value to short circuit heavier comparison */
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v;
e = e->next; e = e->next;
} }
return NULL; return NULL;
} }
/*****************************************************************************/ /*****************************************************************************/
void * /* returns value associated with key */ void * /* returns value associated with key */
hashtable_remove(struct hashtable *h, void *k) hashtable_remove(struct hashtable *h, void *k)
{ {
/* TODO: consider compacting the table when the load factor drops enough, /* TODO: consider compacting the table when the load factor drops enough,
* or provide a 'compact' method. */ * or provide a 'compact' method. */
struct entry *e; struct entry *e;
struct entry **pE; struct entry **pE;
void *v; void *v;
unsigned int hashvalue, idx; unsigned int hashvalue, idx;
hashvalue = hash(h,k); hashvalue = hash(h,k);
idx = indexFor(h->tablelength,hash(h,k)); idx = indexFor(h->tablelength,hash(h,k));
pE = &(h->table[idx]); pE = &(h->table[idx]);
e = *pE; e = *pE;
while (NULL != e) while (NULL != e)
{ {
/* Check hash value to short circuit heavier comparison */ /* Check hash value to short circuit heavier comparison */
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
{ {
*pE = e->next; *pE = e->next;
h->entrycount--; h->entrycount--;
v = e->v; v = e->v;
freekey(e->k); freekey(e->k);
free(e); free(e);
return v; return v;
} }
pE = &(e->next); pE = &(e->next);
e = e->next; e = e->next;
} }
return NULL; return NULL;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -241,38 +241,38 @@ hashtable_remove(struct hashtable *h, void *k)
void void
hashtable_destroy(struct hashtable *h, int free_values) hashtable_destroy(struct hashtable *h, int free_values)
{ {
unsigned int i; unsigned int i;
struct entry *e, *f; struct entry *e, *f;
struct entry **table = h->table; struct entry **table = h->table;
if (free_values) if (free_values)
{ {
for (i = 0; i < h->tablelength; i++) for (i = 0; i < h->tablelength; i++)
{ {
e = table[i]; e = table[i];
while (NULL != e) while (NULL != e)
{ {
f = e; f = e;
e = e->next; e = e->next;
freekey(f->k); freekey(f->k);
if(h->dest == NULL) if(h->dest == NULL)
free(f->v); free(f->v);
else else
h->dest(f->v); h->dest(f->v);
free(f); free(f);
} }
} }
} }
else else
{ {
for (i = 0; i < h->tablelength; i++) for (i = 0; i < h->tablelength; i++)
{ {
e = table[i]; e = table[i];
while (NULL != e) while (NULL != e)
{ f = e; e = e->next; freekey(f->k); free(f); } { f = e; e = e->next; freekey(f->k); free(f); }
} }
} }
free(h->table); free(h->table);
free(h); free(h);
} }
/* some generic hash functions */ /* some generic hash functions */
@ -289,13 +289,13 @@ __attribute__((no_sanitize("unsigned-integer-overflow")))
#endif #endif
hash_from_string(void *k) hash_from_string(void *k)
{ {
char *rkey = (char*) k; char *rkey = (char*) k;
unsigned hashval = 1; unsigned hashval = 1;
while (*rkey) while (*rkey)
hashval = hashval * 33 + *rkey++; hashval = hashval * 33 + *rkey++;
return hashval; return hashval;
} }

View File

@ -18,23 +18,23 @@
int int
hashtable_change(struct hashtable *h, void *k, void *v) hashtable_change(struct hashtable *h, void *k, void *v)
{ {
struct entry *e; struct entry *e;
unsigned int hashvalue, index; unsigned int hashvalue, index;
hashvalue = hash(h,k); hashvalue = hash(h,k);
index = indexFor(h->tablelength,hashvalue); index = indexFor(h->tablelength,hashvalue);
e = h->table[index]; e = h->table[index];
while (NULL != e) while (NULL != e)
{ {
/* Check hash value to short circuit heavier comparison */ /* Check hash value to short circuit heavier comparison */
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
{ {
free(e->v); free(e->v);
e->v = v; e->v = v;
return -1; return -1;
} }
e = e->next; e = e->next;
} }
return 0; return 0;
} }
/* /*

View File

@ -14,12 +14,12 @@ typedef unsigned short uint16_t;
/*****************************************************************************/ /*****************************************************************************/
struct key struct key
{ {
uint32_t one_ip; uint32_t two_ip; uint16_t one_port; uint16_t two_port; uint32_t one_ip; uint32_t two_ip; uint16_t one_port; uint16_t two_port;
}; };
struct value struct value
{ {
char *id; char *id;
}; };
DEFINE_HASHTABLE_INSERT(insert_some, struct key, struct value); DEFINE_HASHTABLE_INSERT(insert_some, struct key, struct value);
@ -32,208 +32,208 @@ DEFINE_HASHTABLE_ITERATOR_SEARCH(search_itr_some, struct key);
static unsigned int static unsigned int
hashfromkey(void *ky) hashfromkey(void *ky)
{ {
struct key *k = (struct key *)ky; struct key *k = (struct key *)ky;
return (((k->one_ip << 17) | (k->one_ip >> 15)) ^ k->two_ip) + return (((k->one_ip << 17) | (k->one_ip >> 15)) ^ k->two_ip) +
(k->one_port * 17) + (k->two_port * 13 * 29); (k->one_port * 17) + (k->two_port * 13 * 29);
} }
static int static int
equalkeys(void *k1, void *k2) equalkeys(void *k1, void *k2)
{ {
return (0 == memcmp(k1,k2,sizeof(struct key))); return (0 == memcmp(k1,k2,sizeof(struct key)));
} }
/*****************************************************************************/ /*****************************************************************************/
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct key *k, *kk; struct key *k, *kk;
struct value *v, *found; struct value *v, *found;
struct hashtable *h; struct hashtable *h;
struct hashtable_itr *itr; struct hashtable_itr *itr;
int i; int i;
h = create_hashtable(16, hashfromkey, equalkeys); h = create_hashtable(16, hashfromkey, equalkeys);
if (NULL == h) exit(-1); /*oom*/ if (NULL == h) exit(-1); /*oom*/
/*****************************************************************************/ /*****************************************************************************/
/* Insertion */ /* Insertion */
for (i = 0; i < ITEM_COUNT; i++) for (i = 0; i < ITEM_COUNT; i++)
{ {
k = (struct key *)malloc(sizeof(struct key)); k = (struct key *)malloc(sizeof(struct key));
if (NULL == k) { if (NULL == k) {
printf("ran out of memory allocating a key\n"); printf("ran out of memory allocating a key\n");
return 1; return 1;
} }
k->one_ip = 0xcfccee40 + i; k->one_ip = 0xcfccee40 + i;
k->two_ip = 0xcf0cee67 - (5 * i); k->two_ip = 0xcf0cee67 - (5 * i);
k->one_port = 22 + (7 * i); k->one_port = 22 + (7 * i);
k->two_port = 5522 - (3 * i); k->two_port = 5522 - (3 * i);
v = (struct value *)malloc(sizeof(struct value)); v = (struct value *)malloc(sizeof(struct value));
v->id = "a value"; v->id = "a value";
if (!insert_some(h,k,v)) exit(-1); /*oom*/ if (!insert_some(h,k,v)) exit(-1); /*oom*/
} }
printf("After insertion, hashtable contains %u items.\n", printf("After insertion, hashtable contains %u items.\n",
hashtable_count(h)); hashtable_count(h));
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable search */ /* Hashtable search */
k = (struct key *)malloc(sizeof(struct key)); k = (struct key *)malloc(sizeof(struct key));
if (NULL == k) { if (NULL == k) {
printf("ran out of memory allocating a key\n"); printf("ran out of memory allocating a key\n");
return 1; return 1;
} }
for (i = 0; i < ITEM_COUNT; i++) for (i = 0; i < ITEM_COUNT; i++)
{ {
k->one_ip = 0xcfccee40 + i; k->one_ip = 0xcfccee40 + i;
k->two_ip = 0xcf0cee67 - (5 * i); k->two_ip = 0xcf0cee67 - (5 * i);
k->one_port = 22 + (7 * i); k->one_port = 22 + (7 * i);
k->two_port = 5522 - (3 * i); k->two_port = 5522 - (3 * i);
if (NULL == (found = search_some(h,k))) { if (NULL == (found = search_some(h,k))) {
printf("BUG: key not found\n"); printf("BUG: key not found\n");
} }
} }
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable iteration */ /* Hashtable iteration */
/* Iterator constructor only returns a valid iterator if /* Iterator constructor only returns a valid iterator if
* the hashtable is not empty */ * the hashtable is not empty */
itr = hashtable_iterator(h); itr = hashtable_iterator(h);
i = 0; i = 0;
if (hashtable_count(h) > 0) if (hashtable_count(h) > 0)
{ {
do { do {
kk = hashtable_iterator_key(itr); kk = hashtable_iterator_key(itr);
v = hashtable_iterator_value(itr); v = hashtable_iterator_value(itr);
/* here (kk,v) are a valid (key, value) pair */ /* here (kk,v) are a valid (key, value) pair */
/* We could call 'hashtable_remove(h,kk)' - and this operation /* We could call 'hashtable_remove(h,kk)' - and this operation
* 'free's kk. However, the iterator is then broken. * 'free's kk. However, the iterator is then broken.
* This is why hashtable_iterator_remove exists - see below. * This is why hashtable_iterator_remove exists - see below.
*/ */
i++; i++;
} while (hashtable_iterator_advance(itr)); } while (hashtable_iterator_advance(itr));
} }
printf("Iterated through %u entries.\n", i); printf("Iterated through %u entries.\n", i);
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable iterator search */ /* Hashtable iterator search */
/* Try the search some method */ /* Try the search some method */
for (i = 0; i < ITEM_COUNT; i++) for (i = 0; i < ITEM_COUNT; i++)
{ {
k->one_ip = 0xcfccee40 + i; k->one_ip = 0xcfccee40 + i;
k->two_ip = 0xcf0cee67 - (5 * i); k->two_ip = 0xcf0cee67 - (5 * i);
k->one_port = 22 + (7 * i); k->one_port = 22 + (7 * i);
k->two_port = 5522 - (3 * i); k->two_port = 5522 - (3 * i);
if (0 == search_itr_some(itr,h,k)) { if (0 == search_itr_some(itr,h,k)) {
printf("BUG: key not found searching with iterator"); printf("BUG: key not found searching with iterator");
} }
} }
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable removal */ /* Hashtable removal */
for (i = 0; i < ITEM_COUNT; i++) for (i = 0; i < ITEM_COUNT; i++)
{ {
k->one_ip = 0xcfccee40 + i; k->one_ip = 0xcfccee40 + i;
k->two_ip = 0xcf0cee67 - (5 * i); k->two_ip = 0xcf0cee67 - (5 * i);
k->one_port = 22 + (7 * i); k->one_port = 22 + (7 * i);
k->two_port = 5522 - (3 * i); k->two_port = 5522 - (3 * i);
if (NULL == (found = remove_some(h,k))) { if (NULL == (found = remove_some(h,k))) {
printf("BUG: key not found for removal\n"); printf("BUG: key not found for removal\n");
} }
} }
printf("After removal, hashtable contains %u items.\n", printf("After removal, hashtable contains %u items.\n",
hashtable_count(h)); hashtable_count(h));
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable destroy and create */ /* Hashtable destroy and create */
hashtable_destroy(h, 1); hashtable_destroy(h, 1);
h = NULL; h = NULL;
free(k); free(k);
h = create_hashtable(160, hashfromkey, equalkeys); h = create_hashtable(160, hashfromkey, equalkeys);
if (NULL == h) { if (NULL == h) {
printf("out of memory allocating second hashtable\n"); printf("out of memory allocating second hashtable\n");
return 1; return 1;
} }
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable insertion */ /* Hashtable insertion */
for (i = 0; i < ITEM_COUNT; i++) for (i = 0; i < ITEM_COUNT; i++)
{ {
k = (struct key *)malloc(sizeof(struct key)); k = (struct key *)malloc(sizeof(struct key));
k->one_ip = 0xcfccee40 + i; k->one_ip = 0xcfccee40 + i;
k->two_ip = 0xcf0cee67 - (5 * i); k->two_ip = 0xcf0cee67 - (5 * i);
k->one_port = 22 + (7 * i); k->one_port = 22 + (7 * i);
k->two_port = 5522 - (3 * i); k->two_port = 5522 - (3 * i);
v = (struct value *)malloc(sizeof(struct value)); v = (struct value *)malloc(sizeof(struct value));
v->id = "a value"; v->id = "a value";
if (!insert_some(h,k,v)) if (!insert_some(h,k,v))
{ {
printf("out of memory inserting into second hashtable\n"); printf("out of memory inserting into second hashtable\n");
return 1; return 1;
} }
} }
printf("After insertion, hashtable contains %u items.\n", printf("After insertion, hashtable contains %u items.\n",
hashtable_count(h)); hashtable_count(h));
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable iterator search and iterator remove */ /* Hashtable iterator search and iterator remove */
k = (struct key *)malloc(sizeof(struct key)); k = (struct key *)malloc(sizeof(struct key));
if (NULL == k) { if (NULL == k) {
printf("ran out of memory allocating a key\n"); printf("ran out of memory allocating a key\n");
return 1; return 1;
} }
for (i = ITEM_COUNT - 1; i >= 0; i = i - 7) for (i = ITEM_COUNT - 1; i >= 0; i = i - 7)
{ {
k->one_ip = 0xcfccee40 + i; k->one_ip = 0xcfccee40 + i;
k->two_ip = 0xcf0cee67 - (5 * i); k->two_ip = 0xcf0cee67 - (5 * i);
k->one_port = 22 + (7 * i); k->one_port = 22 + (7 * i);
k->two_port = 5522 - (3 * i); k->two_port = 5522 - (3 * i);
if (0 == search_itr_some(itr, h, k)) { if (0 == search_itr_some(itr, h, k)) {
printf("BUG: key %u not found for search preremoval using iterator\n", i); printf("BUG: key %u not found for search preremoval using iterator\n", i);
return 1; return 1;
} }
if (0 == hashtable_iterator_remove(itr)) { if (0 == hashtable_iterator_remove(itr)) {
printf("BUG: key not found for removal using iterator\n"); printf("BUG: key not found for removal using iterator\n");
return 1; return 1;
} }
} }
free(itr); free(itr);
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable iterator remove and advance */ /* Hashtable iterator remove and advance */
for (itr = hashtable_iterator(h); for (itr = hashtable_iterator(h);
hashtable_iterator_remove(itr) != 0; ) { hashtable_iterator_remove(itr) != 0; ) {
; ;
} }
free(itr); free(itr);
printf("After removal, hashtable contains %u items.\n", printf("After removal, hashtable contains %u items.\n",
hashtable_count(h)); hashtable_count(h));
/*****************************************************************************/ /*****************************************************************************/
/* Hashtable destroy */ /* Hashtable destroy */
hashtable_destroy(h, 1); hashtable_destroy(h, 1);
free(k); free(k);
return 0; return 0;
} }
/* /*

View File

@ -10,27 +10,27 @@
struct hashtable_itr * struct hashtable_itr *
hashtable_iterator(struct hashtable *h) hashtable_iterator(struct hashtable *h)
{ {
unsigned int i, tablelength; unsigned int i, tablelength;
struct hashtable_itr *itr = (struct hashtable_itr *) struct hashtable_itr *itr = (struct hashtable_itr *)
malloc(sizeof(struct hashtable_itr)); malloc(sizeof(struct hashtable_itr));
if (NULL == itr) return NULL; if (NULL == itr) return NULL;
itr->h = h; itr->h = h;
itr->e = NULL; itr->e = NULL;
itr->parent = NULL; itr->parent = NULL;
tablelength = h->tablelength; tablelength = h->tablelength;
itr->index = tablelength; itr->index = tablelength;
if (0 == h->entrycount) return itr; if (0 == h->entrycount) return itr;
for (i = 0; i < tablelength; i++) for (i = 0; i < tablelength; i++)
{ {
if (NULL != h->table[i]) if (NULL != h->table[i])
{ {
itr->e = h->table[i]; itr->e = h->table[i];
itr->index = i; itr->index = i;
break; break;
} }
} }
return itr; return itr;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -54,38 +54,38 @@ hashtable_iterator_value(struct hashtable_itr *i)
int int
hashtable_iterator_advance(struct hashtable_itr *itr) hashtable_iterator_advance(struct hashtable_itr *itr)
{ {
unsigned int j,tablelength; unsigned int j,tablelength;
struct entry **table; struct entry **table;
struct entry *next; struct entry *next;
if (NULL == itr->e) return 0; /* stupidity check */ if (NULL == itr->e) return 0; /* stupidity check */
next = itr->e->next; next = itr->e->next;
if (NULL != next) if (NULL != next)
{ {
itr->parent = itr->e; itr->parent = itr->e;
itr->e = next; itr->e = next;
return -1; return -1;
} }
tablelength = itr->h->tablelength; tablelength = itr->h->tablelength;
itr->parent = NULL; itr->parent = NULL;
if (tablelength <= (j = ++(itr->index))) if (tablelength <= (j = ++(itr->index)))
{ {
itr->e = NULL; itr->e = NULL;
return 0; return 0;
} }
table = itr->h->table; table = itr->h->table;
while (NULL == (next = table[j])) while (NULL == (next = table[j]))
{ {
if (++j >= tablelength) if (++j >= tablelength)
{ {
itr->index = tablelength; itr->index = tablelength;
itr->e = NULL; itr->e = NULL;
return 0; return 0;
} }
} }
itr->index = j; itr->index = j;
itr->e = next; itr->e = next;
return -1; return -1;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -99,59 +99,59 @@ hashtable_iterator_advance(struct hashtable_itr *itr)
int int
hashtable_iterator_remove(struct hashtable_itr *itr) hashtable_iterator_remove(struct hashtable_itr *itr)
{ {
struct entry *remember_e, *remember_parent; struct entry *remember_e, *remember_parent;
int ret; int ret;
/* Do the removal */ /* Do the removal */
if (NULL == (itr->parent)) if (NULL == (itr->parent))
{ {
/* element is head of a chain */ /* element is head of a chain */
itr->h->table[itr->index] = itr->e->next; itr->h->table[itr->index] = itr->e->next;
} else { } else {
/* element is mid-chain */ /* element is mid-chain */
itr->parent->next = itr->e->next; itr->parent->next = itr->e->next;
} }
/* itr->e is now outside the hashtable */ /* itr->e is now outside the hashtable */
remember_e = itr->e; remember_e = itr->e;
itr->h->entrycount--; itr->h->entrycount--;
freekey(remember_e->k); freekey(remember_e->k);
/* Advance the iterator, correcting the parent */ /* Advance the iterator, correcting the parent */
remember_parent = itr->parent; remember_parent = itr->parent;
ret = hashtable_iterator_advance(itr); ret = hashtable_iterator_advance(itr);
if (itr->parent == remember_e) { itr->parent = remember_parent; } if (itr->parent == remember_e) { itr->parent = remember_parent; }
free(remember_e); free(remember_e);
return ret; return ret;
} }
/*****************************************************************************/ /*****************************************************************************/
int /* returns zero if not found */ int /* returns zero if not found */
hashtable_iterator_search(struct hashtable_itr *itr, hashtable_iterator_search(struct hashtable_itr *itr,
struct hashtable *h, void *k) struct hashtable *h, void *k)
{ {
struct entry *e, *parent; struct entry *e, *parent;
unsigned int hashvalue, index; unsigned int hashvalue, index;
hashvalue = hash(h,k); hashvalue = hash(h,k);
index = indexFor(h->tablelength,hashvalue); index = indexFor(h->tablelength,hashvalue);
e = h->table[index]; e = h->table[index];
parent = NULL; parent = NULL;
while (NULL != e) while (NULL != e)
{ {
/* Check hash value to short circuit heavier comparison */ /* Check hash value to short circuit heavier comparison */
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
{ {
itr->index = index; itr->index = index;
itr->e = e; itr->e = e;
itr->parent = parent; itr->parent = parent;
itr->h = h; itr->h = h;
return -1; return -1;
} }
parent = e; parent = e;
e = e->next; e = e->next;
} }
return 0; return 0;
} }

View File

@ -9,10 +9,10 @@
* accessor functions. */ * accessor functions. */
struct hashtable_itr struct hashtable_itr
{ {
struct hashtable *h; struct hashtable *h;
struct entry *e; struct entry *e;
struct entry *parent; struct entry *parent;
unsigned int index; unsigned int index;
}; };
@ -53,16 +53,16 @@ hashtable_iterator_remove(struct hashtable_itr *itr);
/*****************************************************************************/ /*****************************************************************************/
/* search - overwrite the supplied iterator, to point to the entry /* search - overwrite the supplied iterator, to point to the entry
* matching the supplied key. * matching the supplied key.
h points to the hashtable to be searched. * h points to the hashtable to be searched.
* returns zero if not found. */ * returns zero if not found. */
int int
hashtable_iterator_search(struct hashtable_itr *itr, hashtable_iterator_search(struct hashtable_itr *itr,
struct hashtable *h, void *k); struct hashtable *h, void *k);
#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
{ \ { \
return (hashtable_iterator_search(i,h,k)); \ return (hashtable_iterator_search(i,h,k)); \
} }

View File

@ -161,7 +161,7 @@ bool ProtectedQueue_getItem(ProtectedQueue* this, size_t index, void** item) {
} }
/* Waits for a new work item or timeout (if specified). Returns 0 in case of exit /* Waits for a new work item or timeout (if specified). Returns 0 in case of exit
condition, 1 if item became available and ETIMEDOUT in case of timeout. */ * condition, 1 if item became available and ETIMEDOUT in case of timeout. */
int ProtectedQueue_waitForItem(ProtectedQueue* this, void** item, uint64_t timeout) { int ProtectedQueue_waitForItem(ProtectedQueue* this, void** item, uint64_t timeout) {
struct timespec ts; struct timespec ts;
pthread_mutex_lock(&this->mutex); pthread_mutex_lock(&this->mutex);

View File

@ -410,7 +410,7 @@ rsksi_tlvRecRead(FILE *fp, tlvrecord_t *rec)
} }
r = 0; r = 0;
done: done:
/* Only show debug if no fail */ /* Only show debug if no fail */
if(rsksi_read_debug && r != 0 && r != RSGTE_EOF) if(rsksi_read_debug && r != 0 && r != RSGTE_EOF)
printf("debug: rsksi_tlvRecRead:\t read tlvtype %4.4x, len %u r=%d\n", printf("debug: rsksi_tlvRecRead:\t read tlvtype %4.4x, len %u r=%d\n",
@ -467,7 +467,7 @@ rsksi_tlvDecodeSUBREC(tlvrecord_t *rec, uint16_t *stridx, tlvrecord_t *newrec)
(unsigned) newrec->tlvtype, (unsigned) newrec->tlvtype,
(unsigned) newrec->tlvlen); (unsigned) newrec->tlvlen);
r = 0; r = 0;
done: done:
if(r != 0) /* Only on FAIL! */ if(r != 0) /* Only on FAIL! */
printf("debug: rsksi_tlvDecodeSUBREC:\t\t Failed, tlv record %4.4x with error %d\n", rec->tlvtype, r); printf("debug: rsksi_tlvDecodeSUBREC:\t\t Failed, tlv record %4.4x with error %d\n", rec->tlvtype, r);
return r; return r;
@ -494,7 +494,7 @@ rsksi_tlvDecodeIMPRINT(tlvrecord_t *rec, imprint_t **imprint)
memcpy(imp->data, rec->data+1, imp->len); memcpy(imp->data, rec->data+1, imp->len);
*imprint = imp; *imprint = imp;
r = 0; r = 0;
done: done:
if(r == 0) { if(r == 0) {
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeIMPRINT:\t\t returned %d TLVType=%4.4x, " if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeIMPRINT:\t\t returned %d TLVType=%4.4x, "
"TLVLen=%d, HashID=%d\n", r, rec->tlvtype, rec->tlvlen, imp->hashID); "TLVLen=%d, HashID=%d\n", r, rec->tlvtype, rec->tlvlen, imp->hashID);
@ -547,7 +547,7 @@ rsksi_tlvDecodeREC_HASH(tlvrecord_t *rec, uint16_t *strtidx, imprint_t *imp)
if((imp->data = (uint8_t*)malloc(imp->len)) == NULL) {r=RSGTE_OOM;goto done;} if((imp->data = (uint8_t*)malloc(imp->len)) == NULL) {r=RSGTE_OOM;goto done;}
memcpy(imp->data, subrec.data+1, subrec.tlvlen-1); memcpy(imp->data, subrec.data+1, subrec.tlvlen-1);
r = 0; r = 0;
done: done:
if(r == 0) { if(r == 0) {
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeREC_HASH:\t\t returned %d TLVType=%4.4x, " if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeREC_HASH:\t\t returned %d TLVType=%4.4x, "
"TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen); "TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen);
@ -572,7 +572,7 @@ rsksi_tlvDecodeLEVEL_CORR(tlvrecord_t *rec, uint16_t *strtidx, uint8_t *levelcor
} }
*levelcorr = subrec.data[0]; *levelcorr = subrec.data[0];
r = 0; r = 0;
done: done:
if(r == 0) { if(r == 0) {
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeLEVEL_CORR:\t returned %d TLVType=%4.4x, " if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeLEVEL_CORR:\t returned %d TLVType=%4.4x, "
"TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen); "TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen);
@ -588,7 +588,7 @@ rsksi_tlvDecodeHASH_STEP(tlvrecord_t *rec, uint16_t *pstrtidx, block_hashstep_t
int r = 1; int r = 1;
uint16_t strtidx = 0; uint16_t strtidx = 0;
tlvrecord_t subrec; tlvrecord_t subrec;
*blhashstep = NULL; /* Set to NULL by default first */ *blhashstep = NULL; /* Set to NULL by default first */
/* Init HashStep */ /* Init HashStep */
block_hashstep_t *hashstep = NULL; block_hashstep_t *hashstep = NULL;
@ -611,9 +611,9 @@ rsksi_tlvDecodeHASH_STEP(tlvrecord_t *rec, uint16_t *pstrtidx, block_hashstep_t
goto done; goto done;
} }
*blhashstep = hashstep; *blhashstep = hashstep;
r = 0; r = 0;
done: done:
if (r == 0) { if (r == 0) {
if(rsksi_read_debug) printf("debug: rsksi_tlvDecodeHASH_STEP:\t returned %d, tlvtype " if(rsksi_read_debug) printf("debug: rsksi_tlvDecodeHASH_STEP:\t returned %d, tlvtype "
"%4.4x\n", r, (unsigned) rec->tlvtype); "%4.4x\n", r, (unsigned) rec->tlvtype);
@ -656,7 +656,7 @@ rsksi_tlvDecodeHASH_CHAIN(tlvrecord_t *rec, block_hashchain_t **blhashchain)
*blhashchain = hashchain; *blhashchain = hashchain;
r = 0; r = 0;
done: done:
if(r == 0) { if(r == 0) {
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeHASH_CHAIN:\t returned %d TLVType=%4.4x, " if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeHASH_CHAIN:\t returned %d TLVType=%4.4x, "
"TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen); "TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen);
@ -751,7 +751,7 @@ rsksi_tlvDecodeSIG(tlvrecord_t *rec, uint16_t *strtidx, block_sig_t *bs)
if((bs->sig.der.data = (uint8_t*)malloc(bs->sig.der.len)) == NULL) {r=RSGTE_OOM;goto done;} if((bs->sig.der.data = (uint8_t*)malloc(bs->sig.der.len)) == NULL) {r=RSGTE_OOM;goto done;}
memcpy(bs->sig.der.data, subrec.data, bs->sig.der.len); memcpy(bs->sig.der.data, subrec.data, bs->sig.der.len);
r = 0; r = 0;
done: done:
if(rsksi_read_debug) printf("debug: rsksi_tlvDecodeSIG:\t\t returned %d, tlvtype %4.4x\n", if(rsksi_read_debug) printf("debug: rsksi_tlvDecodeSIG:\t\t returned %d, tlvtype %4.4x\n",
r, (unsigned) rec->tlvtype); r, (unsigned) rec->tlvtype);
return r; return r;
@ -776,7 +776,7 @@ rsksi_tlvDecodeBLOCK_HDR(tlvrecord_t *rec, block_hdr_t **blockhdr)
} }
*blockhdr = bh; *blockhdr = bh;
r = 0; r = 0;
done: done:
if (r == 0) { if (r == 0) {
if(rsksi_read_debug) printf("debug: tlvDecodeBLOCK_HDR:\t\t returned %d, tlvtype %4.4x\n", if(rsksi_read_debug) printf("debug: tlvDecodeBLOCK_HDR:\t\t returned %d, tlvtype %4.4x\n",
r, (unsigned) rec->tlvtype); r, (unsigned) rec->tlvtype);
@ -808,7 +808,7 @@ rsksi_tlvDecodeEXCERPT_SIG(tlvrecord_t *rec, block_sig_t **blocksig)
*blocksig = bs; *blocksig = bs;
r = 0; r = 0;
done: done:
if(r == 0) { if(r == 0) {
if (rsksi_read_debug) printf("debug: tlvDecodeEXCERPT_SIG:\t returned %d, tlvtype %4.4x\n", if (rsksi_read_debug) printf("debug: tlvDecodeEXCERPT_SIG:\t returned %d, tlvtype %4.4x\n",
r, (unsigned) rec->tlvtype); r, (unsigned) rec->tlvtype);
@ -816,7 +816,7 @@ done:
/* Free memory on FAIL!*/ /* Free memory on FAIL!*/
if (bs != NULL) if (bs != NULL)
rsksi_objfree(rec->tlvtype, bs); rsksi_objfree(rec->tlvtype, bs);
} }
return r; return r;
} }
static int static int
@ -838,7 +838,7 @@ rsksi_tlvDecodeBLOCK_SIG(tlvrecord_t *rec, block_sig_t **blocksig)
} }
*blocksig = bs; *blocksig = bs;
r = 0; r = 0;
done: done:
if(r == 0) { if(r == 0) {
if (rsksi_read_debug) printf("debug: tlvDecodeBLOCK_SIG:\t\t returned %d, tlvtype %4.4x, recCount " if (rsksi_read_debug) printf("debug: tlvDecodeBLOCK_SIG:\t\t returned %d, tlvtype %4.4x, recCount "
"%ju\n", r, (unsigned) rec->tlvtype, bs->recCount); "%ju\n", r, (unsigned) rec->tlvtype, bs->recCount);
@ -846,7 +846,7 @@ done:
/* Free memory on FAIL!*/ /* Free memory on FAIL!*/
if (bs != NULL) if (bs != NULL)
rsksi_objfree(rec->tlvtype, bs); rsksi_objfree(rec->tlvtype, bs);
} }
return r; return r;
} }
int int
@ -901,7 +901,7 @@ rsksi_tlvrdRecHash(FILE *fp, FILE *outfp, imprint_t **imp)
if((r = rsksi_tlvwrite(outfp, &rec)) != 0) goto done; if((r = rsksi_tlvwrite(outfp, &rec)) != 0) goto done;
} }
r = 0; r = 0;
done: done:
if(r == 0 && rsksi_read_debug) if(r == 0 && rsksi_read_debug)
printf("debug: tlvrdRecHash:\t\t\t returned %d, rec->tlvtype %4.4x\n", r, (unsigned) rec.tlvtype); printf("debug: tlvrdRecHash:\t\t\t returned %d, rec->tlvtype %4.4x\n", r, (unsigned) rec.tlvtype);
return r; return r;
@ -926,7 +926,7 @@ rsksi_tlvrdTreeHash(FILE *fp, FILE *outfp, imprint_t **imp)
if((r = rsksi_tlvwrite(outfp, &rec)) != 0) goto done; if((r = rsksi_tlvwrite(outfp, &rec)) != 0) goto done;
} }
r = 0; r = 0;
done: done:
if(r == 0 && rsksi_read_debug) printf("debug: rsksi_tlvrdTreeHash:\t\t returned %d, rec->tlvtype %4.4x\n", if(r == 0 && rsksi_read_debug) printf("debug: rsksi_tlvrdTreeHash:\t\t returned %d, rec->tlvtype %4.4x\n",
r, (unsigned) rec.tlvtype); r, (unsigned) rec.tlvtype);
return r; return r;
@ -974,7 +974,7 @@ rsksi_tlvrd(FILE *fp, tlvrecord_t *rec, void *obj)
int r; int r;
if((r = rsksi_tlvRecRead(fp, rec)) != 0) goto done; if((r = rsksi_tlvRecRead(fp, rec)) != 0) goto done;
r = rsksi_tlvRecDecode(rec, obj); r = rsksi_tlvRecDecode(rec, obj);
done: done:
if(rsksi_read_debug && r != RSGTE_SUCCESS && r != RSGTE_EOF) printf("debug: rsksi_tlvrd:\t failed with " if(rsksi_read_debug && r != RSGTE_SUCCESS && r != RSGTE_EOF) printf("debug: rsksi_tlvrd:\t failed with "
"error %d\n", r); "error %d\n", r);
return r; return r;
@ -1025,19 +1025,19 @@ rsksi_printINT_HASH(FILE *fp, imprint_t *imp, uint8_t verbose)
*/ */
void void
rsksi_printBLOCK_HDR(FILE *fp, block_hdr_t *bh, uint8_t verbose) rsksi_printBLOCK_HDR(FILE *fp, block_hdr_t *bh, uint8_t verbose)
{ {
fprintf(fp, "[0x0901]Block Header Record:\n"); fprintf(fp, "[0x0901]Block Header Record:\n");
fprintf(fp, "\tPrevious Block Hash:\n"); fprintf(fp, "\tPrevious Block Hash:\n");
fprintf(fp, "\t Algorithm..: %s\n", hashAlgNameKSI(bh->lastHash.hashID)); fprintf(fp, "\t Algorithm..: %s\n", hashAlgNameKSI(bh->lastHash.hashID));
fprintf(fp, "\t Hash.......: "); fprintf(fp, "\t Hash.......: ");
outputHexBlob(fp, bh->lastHash.data, bh->lastHash.len, verbose); outputHexBlob(fp, bh->lastHash.data, bh->lastHash.len, verbose);
fputc('\n', fp); fputc('\n', fp);
if(blobIsZero(bh->lastHash.data, bh->lastHash.len)) if(blobIsZero(bh->lastHash.data, bh->lastHash.len))
fprintf(fp, "\t NOTE: New Hash Chain Start!\n"); fprintf(fp, "\t NOTE: New Hash Chain Start!\n");
fprintf(fp, "\tHash Algorithm: %s\n", hashAlgNameKSI(bh->hashID)); fprintf(fp, "\tHash Algorithm: %s\n", hashAlgNameKSI(bh->hashID));
fprintf(fp, "\tIV............: "); fprintf(fp, "\tIV............: ");
outputHexBlob(fp, bh->iv, getIVLenKSI(bh), verbose); outputHexBlob(fp, bh->iv, getIVLenKSI(bh), verbose);
fputc('\n', fp); fputc('\n', fp);
} }
@ -1223,7 +1223,7 @@ rsksiHashstepFromKSI_DataHash(ksifile ksi, KSI_DataHash *hash)
goto done; goto done;
} }
memcpy(hashstep->sib_hash.data, digest, digest_len); memcpy(hashstep->sib_hash.data, digest, digest_len);
done: done:
return hashstep; return hashstep;
} }
@ -1377,7 +1377,7 @@ rsksi_getExcerptBlockParams(FILE *fp, uint8_t bRewind, block_sig_t **bs, block_h
default:fprintf(fp, "unknown tlv record %4.4x\n", rec.tlvtype); default:fprintf(fp, "unknown tlv record %4.4x\n", rec.tlvtype);
break; break;
} }
/* Free second Signatur object if set! */ /* Free second Signatur object if set! */
if(bSig == 1 && obj != NULL) rsksi_objfree(rec.tlvtype, obj); if(bSig == 1 && obj != NULL) rsksi_objfree(rec.tlvtype, obj);
} }
@ -1566,7 +1566,7 @@ done:
static int static int
rsksi_vrfy_chkTreeHash(ksifile ksi, FILE *sigfp, FILE *nsigfp, rsksi_vrfy_chkTreeHash(ksifile ksi, FILE *sigfp, FILE *nsigfp,
KSI_DataHash *hash, ksierrctx_t *ectx) KSI_DataHash *hash, ksierrctx_t *ectx)
{ {
int r = 0; int r = 0;
imprint_t *imp = NULL; imprint_t *imp = NULL;
@ -1726,11 +1726,11 @@ block_hashchain_t *hashchain, int storehashchain)
hashstep->level_corr = 0; /* Level Correction 0 */ hashstep->level_corr = 0; /* Level Correction 0 */
if(rsksi_read_debug) outputHash(stdout, "debug: rsksi_vrfy_nextRecExtract:\t RIGHT Hash:" if(rsksi_read_debug) outputHash(stdout, "debug: rsksi_vrfy_nextRecExtract:\t RIGHT Hash:"
" \t\t", hashstep->sib_hash.data, hashstep->sib_hash.len, ectx->verbose); " \t\t", hashstep->sib_hash.data, hashstep->sib_hash.len, ectx->verbose);
/* Attach to HashChain */ /* Attach to HashChain */
hashchain->hashsteps[hashchain->stepCount] = hashstep; hashchain->hashsteps[hashchain->stepCount] = hashstep;
hashchain->stepCount++; hashchain->stepCount++;
hashchain->direction = 0x03; /* RIGHT */ hashchain->direction = 0x03; /* RIGHT */
hashchain->level = 1; hashchain->level = 1;
} }
@ -1773,7 +1773,7 @@ block_hashchain_t *hashchain, int storehashchain)
hashstep->sib_hash.len, ectx->verbose); hashstep->sib_hash.len, ectx->verbose);
} }
hashstep->direction = hashchain->direction; hashstep->direction = hashchain->direction;
hashstep->level_corr = 0; hashstep->level_corr = 0;
/* Attach to HashChain */ /* Attach to HashChain */
hashchain->hashsteps[hashchain->stepCount] = hashstep; hashchain->hashsteps[hashchain->stepCount] = hashstep;
hashchain->stepCount++; hashchain->stepCount++;
@ -1942,7 +1942,7 @@ rsksi_vrfy_nextHashChain(ksifile ksi, block_sig_t *bs, FILE *sigfp, unsigned cha
} }
bCheckLineHash = 1; bCheckLineHash = 1;
} }
/* Store into TMP for next LOOP */ /* Store into TMP for next LOOP */
root_tmp = root_hash; root_tmp = root_hash;
@ -2051,7 +2051,7 @@ if(rsksi_read_debug)
ectx->verbose); ectx->verbose);
} }
hashstep->direction = hashchain->direction; hashstep->direction = hashchain->direction;
hashstep->level_corr = j+1 - hashchain->level; hashstep->level_corr = j+1 - hashchain->level;
if(rsksi_read_debug) printf("debug: verifySigblkFinishChain:\t\t level_corr=%d\n", hashstep->level_corr); if(rsksi_read_debug) printf("debug: verifySigblkFinishChain:\t\t level_corr=%d\n", hashstep->level_corr);
/* Attach to HashChain */ /* Attach to HashChain */
@ -2224,7 +2224,7 @@ verifyBLOCK_HDRKSI(FILE *sigfp, FILE *nsigfp, tlvrecord_t* tlvrec)
} }
if (nsigfp != NULL) if (nsigfp != NULL)
if ((r = rsksi_tlvwrite(nsigfp, tlvrec)) != 0) goto done; if ((r = rsksi_tlvwrite(nsigfp, tlvrec)) != 0) goto done;
done: done:
if (bh != NULL) if (bh != NULL)
rsksi_objfree(tlvrec->tlvtype, bh); rsksi_objfree(tlvrec->tlvtype, bh);
if(rsksi_read_debug) printf("debug: verifyBLOCK_HDRKSI:\t\t returned %d\n", r); if(rsksi_read_debug) printf("debug: verifyBLOCK_HDRKSI:\t\t returned %d\n", r);
@ -2236,7 +2236,7 @@ done:
*/ */
int int
verifyBLOCK_SIGKSI(block_sig_t *bs, ksifile ksi, FILE *sigfp, FILE *nsigfp, verifyBLOCK_SIGKSI(block_sig_t *bs, ksifile ksi, FILE *sigfp, FILE *nsigfp,
uint8_t bExtend, KSI_DataHash *ksiHash, ksierrctx_t *ectx) uint8_t bExtend, KSI_DataHash *ksiHash, ksierrctx_t *ectx)
{ {
int r; int r;
int ksistate; int ksistate;
@ -2591,7 +2591,7 @@ int rsksi_WriteHashChain(FILE *newsigfp, block_hashchain_t *hashchain, int verbo
tlvlenLevelCorr = rsksi_tlvGetInt64OctetSize(uiLevelCorr); tlvlenLevelCorr = rsksi_tlvGetInt64OctetSize(uiLevelCorr);
/* Total Length of Hash Chain */ /* Total Length of Hash Chain */
tlvlen = /*4 + ???? */ tlvlen = /*4 + ???? */
2 + 1 + hashchain->rec_hash.len /* rec-hash */ + 2 + 1 + hashchain->rec_hash.len /* rec-hash */ +
((2 + 2 + tlvlenLevelCorr + 2 + 1 + hashchain->hashsteps[0]->sib_hash.len) * hashchain->stepCount); ((2 + 2 + tlvlenLevelCorr + 2 + 1 + hashchain->hashsteps[0]->sib_hash.len) * hashchain->stepCount);
/* Count of all left/right chains*/ /* Count of all left/right chains*/

View File

@ -43,10 +43,10 @@
#include <libestr.h> #include <libestr.h>
#include <json.h> #include <json.h>
#ifdef HAVE_MALLOC_H #ifdef HAVE_MALLOC_H
# include <malloc.h> #include <malloc.h>
#endif #endif
#ifdef USE_LIBUUID #ifdef USE_LIBUUID
#include <uuid/uuid.h> #include <uuid/uuid.h>
#endif #endif
#include <errno.h> #include <errno.h>
#include "rsyslog.h" #include "rsyslog.h"
@ -374,19 +374,19 @@ static char hexdigit[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', {'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F' }; '9', 'A', 'B', 'C', 'D', 'E', 'F' };
#if defined(_AIX) #if defined(_AIX)
/* AIXPORT : replace facility names with aso and caa only for AIX */ /* AIXPORT : replace facility names with aso and caa only for AIX */
static char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr", static char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
"news", "uucp", "cron", "authpriv", "ftp", "aso", "audit", "news", "uucp", "cron", "authpriv", "ftp", "aso", "audit",
"alert", "caa", "local0", "local1", "local2", "local3", "alert", "caa", "local0", "local1", "local2", "local3",
"local4", "local5", "local6", "local7", "invld" }; "local4", "local5", "local6", "local7", "invld" };
/* length of the facility names string (for optimizatiions) */ /* length of the facility names string (for optimizatiions) */
static short len_syslog_fac_names[LOG_NFACILITIES] = { 4, 4, 4, 6, 4, 6, 3, static short len_syslog_fac_names[LOG_NFACILITIES] = { 4, 4, 4, 6, 4, 6, 3,
4, 4, 4, 8, 3, 3, 5, 4, 4, 4, 8, 3, 3, 5,
5, 3, 6, 6, 6, 6, 5, 3, 6, 6, 6, 6,
6, 6, 6, 6, 5 }; 6, 6, 6, 6, 5 };
#else #else
/*syslog facility names (as of RFC5424) */ /*syslog facility names (as of RFC5424) */
static const char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr", static const char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
"news", "uucp", "cron", "authpriv", "ftp", "ntp", "audit", "news", "uucp", "cron", "authpriv", "ftp", "ntp", "audit",
@ -960,7 +960,7 @@ static inline void freeHOSTNAME(smsg_t *pThis)
rsRetVal msgDestruct(smsg_t **ppThis) rsRetVal msgDestruct(smsg_t **ppThis)
{ {
DEFiRet; DEFiRet;
smsg_t *pThis; smsg_t *pThis;
int currRefCount; int currRefCount;
# ifdef HAVE_MALLOC_TRIM # ifdef HAVE_MALLOC_TRIM
int currCnt; int currCnt;
@ -2130,10 +2130,10 @@ static const char *getFacility(smsg_t * const pM)
static const char *getFacilityStr(smsg_t * const pM) static const char *getFacilityStr(smsg_t * const pM)
{ {
const char *name = NULL; const char *name = NULL;
if(pM == NULL) if(pM == NULL)
return ""; return "";
if(pM->iFacility > 23) { if(pM->iFacility > 23) {
name = "invld"; name = "invld";
@ -3470,8 +3470,8 @@ finalize_it:
*pPropLen = sizeof("**OUT OF MEMORY**") - 1; \ *pPropLen = sizeof("**OUT OF MEMORY**") - 1; \
return(UCHAR_CONSTANT("**OUT OF MEMORY**"));} return(UCHAR_CONSTANT("**OUT OF MEMORY**"));}
uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restrict__ const pTpe, uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restrict__ const pTpe,
msgPropDescr_t *pProp, rs_size_t *__restrict__ const pPropLen, msgPropDescr_t *pProp, rs_size_t *__restrict__ const pPropLen,
unsigned short *__restrict__ const pbMustBeFreed, struct syslogTime * const ttNow) unsigned short *__restrict__ const pbMustBeFreed, struct syslogTime * const ttNow)
{ {
uchar *pRes; /* result pointer */ uchar *pRes; /* result pointer */
rs_size_t bufLen = -1; /* length of string or -1, if not known */ rs_size_t bufLen = -1; /* length of string or -1, if not known */
@ -3790,14 +3790,14 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
if(clock_gettime(CLOCK_UPTIME, &tp) == -1) { if(clock_gettime(CLOCK_UPTIME, &tp) == -1) {
free(pRes); free(pRes);
*pPropLen = sizeof("**SYSCALL FAILED**") - 1; *pPropLen = sizeof("**SYSCALL FAILED**") - 1;
return(UCHAR_CONSTANT("**SYSCALL FAILED**")); return(UCHAR_CONSTANT("**SYSCALL FAILED**"));
} }
*pbMustBeFreed = 1; *pbMustBeFreed = 1;
snprintf((char*) pRes, 32, "%ld", tp.tv_sec); snprintf((char*) pRes, 32, "%ld", tp.tv_sec);
} }
# else # else
@ -3871,7 +3871,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
} }
} }
dbgprintf("field requested %d, field found %d\n", pTpe->data.field.iFieldNr, (int) iCurrFld); dbgprintf("field requested %d, field found %d\n", pTpe->data.field.iFieldNr, (int) iCurrFld);
if(iCurrFld == pTpe->data.field.iFieldNr) { if(iCurrFld == pTpe->data.field.iFieldNr) {
/* field found, now extract it */ /* field found, now extract it */
/* first of all, we need to find the end */ /* first of all, we need to find the end */
@ -4172,7 +4172,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
uchar *pDstStart; uchar *pDstStart;
uchar *pDst; uchar *pDst;
uchar bDropped = 0; uchar bDropped = 0;
while(*pSrc) { while(*pSrc) {
if(!iscntrl((int) *pSrc++)) if(!iscntrl((int) *pSrc++))
iLenBuf++; iLenBuf++;
@ -4202,7 +4202,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
uchar *pSrc; uchar *pSrc;
uchar *pDstStart; uchar *pDstStart;
uchar *pDst; uchar *pDst;
if(*pbMustBeFreed == 1) { if(*pbMustBeFreed == 1) {
/* in this case, we already work on dynamic /* in this case, we already work on dynamic
* memory, so there is no need to copy it - we can * memory, so there is no need to copy it - we can
@ -4291,14 +4291,14 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
uchar *pDstStart; uchar *pDstStart;
uchar *pDst; uchar *pDst;
uchar bDropped = 0; uchar bDropped = 0;
while(*pSrc) { while(*pSrc) {
if(*pSrc++ != '/') if(*pSrc++ != '/')
iLenBuf++; iLenBuf++;
else else
bDropped = 1; bDropped = 1;
} }
if(bDropped) { if(bDropped) {
pDst = pDstStart = MALLOC(iLenBuf + 1); pDst = pDstStart = MALLOC(iLenBuf + 1);
if(pDst == NULL) { if(pDst == NULL) {
@ -4321,7 +4321,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
uchar *pSrc; uchar *pSrc;
uchar *pDstStart; uchar *pDstStart;
uchar *pDst; uchar *pDst;
if(*pbMustBeFreed == 1) { if(*pbMustBeFreed == 1) {
/* here, again, we can modify the string as we already obtained /* here, again, we can modify the string as we already obtained
* a private buffer. As we do not change the size of that buffer, * a private buffer. As we do not change the size of that buffer,
@ -4356,7 +4356,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
*pbMustBeFreed = 1; *pbMustBeFreed = 1;
} }
} }
/* check for "." and ".." (note the parenthesis in the if condition!) */ /* check for "." and ".." (note the parenthesis in the if condition!) */
if(*pRes == '\0') { if(*pRes == '\0') {
if(*pbMustBeFreed == 1) if(*pbMustBeFreed == 1)
@ -4692,33 +4692,33 @@ jsonPathGetLeaf(uchar *name, int lenName)
} }
static json_bool jsonVarExtract(struct json_object* root, const char *key, struct json_object **value) { static json_bool jsonVarExtract(struct json_object* root, const char *key, struct json_object **value) {
char namebuf[MAX_VARIABLE_NAME_LEN]; char namebuf[MAX_VARIABLE_NAME_LEN];
int key_len = strlen(key); int key_len = strlen(key);
char *array_idx_start = strstr(key, "["); char *array_idx_start = strstr(key, "[");
char *array_idx_end = NULL; char *array_idx_end = NULL;
char *array_idx_num_end_discovered = NULL; char *array_idx_num_end_discovered = NULL;
struct json_object *arr = NULL; struct json_object *arr = NULL;
if (array_idx_start != NULL) { if (array_idx_start != NULL) {
array_idx_end = strstr(array_idx_start, "]"); array_idx_end = strstr(array_idx_start, "]");
} }
if (array_idx_end != NULL && (array_idx_end - key + 1) == key_len) { if (array_idx_end != NULL && (array_idx_end - key + 1) == key_len) {
errno = 0; errno = 0;
int idx = (int) strtol(array_idx_start + 1, &array_idx_num_end_discovered, 10); int idx = (int) strtol(array_idx_start + 1, &array_idx_num_end_discovered, 10);
if (errno == 0 && array_idx_num_end_discovered == array_idx_end) { if (errno == 0 && array_idx_num_end_discovered == array_idx_end) {
memcpy(namebuf, key, array_idx_start - key); memcpy(namebuf, key, array_idx_start - key);
namebuf[array_idx_start - key] = '\0'; namebuf[array_idx_start - key] = '\0';
json_bool found_obj = json_object_object_get_ex(root, namebuf, &arr); json_bool found_obj = json_object_object_get_ex(root, namebuf, &arr);
if (found_obj && json_object_is_type(arr, json_type_array)) { if (found_obj && json_object_is_type(arr, json_type_array)) {
int len = json_object_array_length(arr); int len = json_object_array_length(arr);
if (len > idx) { if (len > idx) {
*value = json_object_array_get_idx(arr, idx); *value = json_object_array_get_idx(arr, idx);
if (*value != NULL) return TRUE; if (*value != NULL) return TRUE;
} }
return FALSE; return FALSE;
} }
} }
} }
return json_object_object_get_ex(root, key, value); return json_object_object_get_ex(root, key, value);
} }
@ -4988,7 +4988,7 @@ msgAddMultiMetadata(smsg_t *const __restrict__ pMsg,
if(jval == NULL) { if(jval == NULL) {
json_object_put(json); json_object_put(json);
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
} }
json_object_object_add(json, (const char *const)metaname[i], jval); json_object_object_add(json, (const char *const)metaname[i], jval);
} }
iRet = msgAddJSON(pMsg, (uchar*)"!metadata", json, 0, 0); iRet = msgAddJSON(pMsg, (uchar*)"!metadata", json, 0, 0);

View File

@ -282,7 +282,7 @@ AddPermittedPeer(permittedPeers_t **ppRootPeer, uchar* pszID)
pNew->pNext = *ppRootPeer; pNew->pNext = *ppRootPeer;
} }
*ppRootPeer = pNew; *ppRootPeer = pNew;
finalize_it: finalize_it:
if(iRet != RS_RET_OK) { if(iRet != RS_RET_OK) {
if(pNew != NULL) if(pNew != NULL)
@ -524,8 +524,8 @@ static void MaskIP4 (struct in_addr *addr, uint8_t bits) {
*/ */
static int static int
mygetnameinfo(const struct sockaddr *sa, socklen_t salen, mygetnameinfo(const struct sockaddr *sa, socklen_t salen,
char *host, size_t hostlen, char *host, size_t hostlen,
char *serv, size_t servlen, int flags) char *serv, size_t servlen, int flags)
{ {
int iCancelStateSave; int iCancelStateSave;
int i; int i;
@ -632,7 +632,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
LogError(0, NO_ERRCODE, "You can not specify 0 bits of the netmask, this would " LogError(0, NO_ERRCODE, "You can not specify 0 bits of the netmask, this would "
"match ALL systems. If you really intend to do that, " "match ALL systems. If you really intend to do that, "
"remove all $AllowedSender directives."); "remove all $AllowedSender directives.");
switch (iAllow->addr.NetAddr->sa_family) { switch (iAllow->addr.NetAddr->sa_family) {
case AF_INET: case AF_INET:
if((iSignificantBits < 1) || (iSignificantBits > 32)) { if((iSignificantBits < 1) || (iSignificantBits > 32)) {
@ -640,7 +640,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
(int)iSignificantBits); (int)iSignificantBits);
iSignificantBits = 32; iSignificantBits = 32;
} }
MaskIP4 (&(SIN(iAllow->addr.NetAddr)->sin_addr), iSignificantBits); MaskIP4 (&(SIN(iAllow->addr.NetAddr)->sin_addr), iSignificantBits);
break; break;
case AF_INET6: case AF_INET6:
@ -672,7 +672,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
LogError(0, NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled."); LogError(0, NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled.");
ABORT_FINALIZE(RS_RET_OK); ABORT_FINALIZE(RS_RET_OK);
} }
if (!strchr (iAllow->addr.HostWildcard, '*') && if (!strchr (iAllow->addr.HostWildcard, '*') &&
!strchr (iAllow->addr.HostWildcard, '?') && !strchr (iAllow->addr.HostWildcard, '?') &&
ACLDontResolve == 0) { ACLDontResolve == 0) {
@ -681,7 +681,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
*/ */
struct addrinfo hints, *res; struct addrinfo hints, *res;
struct NetAddr allowIP; struct NetAddr allowIP;
memset (&hints, 0, sizeof (struct addrinfo)); memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
@ -691,7 +691,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
if (getaddrinfo (iAllow->addr.HostWildcard, NULL, &hints, &res) != 0) { if (getaddrinfo (iAllow->addr.HostWildcard, NULL, &hints, &res) != 0) {
LogError(0, NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard); LogError(0, NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard);
if (ACLAddHostnameOnFail) { if (ACLAddHostnameOnFail) {
LogError(0, NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard " LogError(0, NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard "
"entry.", iAllow->addr.HostWildcard); "entry.", iAllow->addr.HostWildcard);
@ -703,7 +703,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
ABORT_FINALIZE(RS_RET_NOENTRY); ABORT_FINALIZE(RS_RET_NOENTRY);
} }
} }
restmp = res; restmp = res;
for ( ; res != NULL ; res = res->ai_next) { for ( ; res != NULL ; res = res->ai_next) {
switch (res->ai_family) { switch (res->ai_family) {
@ -714,7 +714,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
} }
memcpy(allowIP.addr.NetAddr, res->ai_addr, res->ai_addrlen); memcpy(allowIP.addr.NetAddr, res->ai_addr, res->ai_addrlen);
if((iRet = AddAllowedSenderEntry(ppRoot, ppLast, &allowIP, iSignificantBits)) if((iRet = AddAllowedSenderEntry(ppRoot, ppLast, &allowIP, iSignificantBits))
!= RS_RET_OK) { != RS_RET_OK) {
free(allowIP.addr.NetAddr); free(allowIP.addr.NetAddr);
@ -724,7 +724,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
case AF_INET6: /* IPv6 - but need to check if it is a v6-mapped IPv4 */ case AF_INET6: /* IPv6 - but need to check if it is a v6-mapped IPv4 */
if(IN6_IS_ADDR_V4MAPPED (&SIN6(res->ai_addr)->sin6_addr)) { if(IN6_IS_ADDR_V4MAPPED (&SIN6(res->ai_addr)->sin6_addr)) {
/* extract & add IPv4 */ /* extract & add IPv4 */
iSignificantBits = 32; iSignificantBits = 32;
allowIP.flags = 0; allowIP.flags = 0;
if((allowIP.addr.NetAddr = (struct sockaddr *) if((allowIP.addr.NetAddr = (struct sockaddr *)
@ -733,7 +733,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
} }
SIN(allowIP.addr.NetAddr)->sin_family = AF_INET; SIN(allowIP.addr.NetAddr)->sin_family = AF_INET;
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
SIN(allowIP.addr.NetAddr)->sin_len = sizeof (struct sockaddr_in); SIN(allowIP.addr.NetAddr)->sin_len = sizeof (struct sockaddr_in);
#endif #endif
SIN(allowIP.addr.NetAddr)->sin_port = 0; SIN(allowIP.addr.NetAddr)->sin_port = 0;
memcpy(&(SIN(allowIP.addr.NetAddr)->sin_addr.s_addr), memcpy(&(SIN(allowIP.addr.NetAddr)->sin_addr.s_addr),
@ -748,14 +748,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
} }
} else { } else {
/* finally add IPv6 */ /* finally add IPv6 */
iSignificantBits = 128; iSignificantBits = 128;
allowIP.flags = 0; allowIP.flags = 0;
if((allowIP.addr.NetAddr = MALLOC(res->ai_addrlen)) == NULL) { if((allowIP.addr.NetAddr = MALLOC(res->ai_addrlen)) == NULL) {
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
} }
memcpy(allowIP.addr.NetAddr, res->ai_addr, res->ai_addrlen); memcpy(allowIP.addr.NetAddr, res->ai_addr, res->ai_addrlen);
if((iRet = AddAllowedSenderEntry(ppRoot, ppLast, &allowIP, if((iRet = AddAllowedSenderEntry(ppRoot, ppLast, &allowIP,
iSignificantBits)) iSignificantBits))
!= RS_RET_OK) { != RS_RET_OK) {
@ -945,7 +945,7 @@ MaskCmp(struct NetAddr *pAllow, uint8_t bits, struct sockaddr *pFrom, const char
if(bChkDNS == 0) if(bChkDNS == 0)
return 2; return 2;
dbgprintf("MaskCmp: host=\"%s\"; pattern=\"%s\"\n", pszFromHost, pAllow->addr.HostWildcard); dbgprintf("MaskCmp: host=\"%s\"; pattern=\"%s\"\n", pszFromHost, pAllow->addr.HostWildcard);
# if !defined(FNM_CASEFOLD) # if !defined(FNM_CASEFOLD)
/* TODO: I don't know if that then works, seen on HP UX, what I have not in lab... ;) */ /* TODO: I don't know if that then works, seen on HP UX, what I have not in lab... ;) */
return(fnmatch(pAllow->addr.HostWildcard, pszFromHost, FNM_NOESCAPE) == 0); return(fnmatch(pAllow->addr.HostWildcard, pszFromHost, FNM_NOESCAPE) == 0);
@ -966,16 +966,16 @@ MaskCmp(struct NetAddr *pAllow, uint8_t bits, struct sockaddr *pFrom, const char
case AF_INET6: { case AF_INET6: {
struct in6_addr ip, net; struct in6_addr ip, net;
register uint8_t i; register uint8_t i;
memcpy (&ip, &(SIN6(pFrom))->sin6_addr, sizeof (struct in6_addr)); memcpy (&ip, &(SIN6(pFrom))->sin6_addr, sizeof (struct in6_addr));
memcpy (&net, &(SIN6(pAllow->addr.NetAddr))->sin6_addr, sizeof (struct in6_addr)); memcpy (&net, &(SIN6(pAllow->addr.NetAddr))->sin6_addr, sizeof (struct in6_addr));
i = bits/32; i = bits/32;
if (bits % 32) if (bits % 32)
ip.s6_addr32[i++] &= htonl(0xffffffff << (32 - (bits % 32))); ip.s6_addr32[i++] &= htonl(0xffffffff << (32 - (bits % 32)));
for (; i < (sizeof ip.s6_addr32)/4; i++) for (; i < (sizeof ip.s6_addr32)/4; i++)
ip.s6_addr32[i] = 0; ip.s6_addr32[i] = 0;
return (memcmp (ip.s6_addr, net.s6_addr, sizeof ip.s6_addr) == 0 && return (memcmp (ip.s6_addr, net.s6_addr, sizeof ip.s6_addr) == 0 &&
(SIN6(pAllow->addr.NetAddr)->sin6_scope_id != 0 ? (SIN6(pAllow->addr.NetAddr)->sin6_scope_id != 0 ?
SIN6(pFrom)->sin6_scope_id == SIN6(pAllow->addr.NetAddr)->sin6_scope_id : 1)); SIN6(pFrom)->sin6_scope_id == SIN6(pAllow->addr.NetAddr)->sin6_scope_id : 1));
@ -983,7 +983,7 @@ MaskCmp(struct NetAddr *pAllow, uint8_t bits, struct sockaddr *pFrom, const char
case AF_INET: { case AF_INET: {
struct in6_addr *ip6 = &(SIN6(pFrom))->sin6_addr; struct in6_addr *ip6 = &(SIN6(pFrom))->sin6_addr;
struct in_addr *net = &(SIN(pAllow->addr.NetAddr))->sin_addr; struct in_addr *net = &(SIN(pAllow->addr.NetAddr))->sin_addr;
if ((ip6->s6_addr32[3] & (u_int32_t) if ((ip6->s6_addr32[3] & (u_int32_t)
htonl((0xffffffff << (32 - bits)))) == net->s_addr && htonl((0xffffffff << (32 - bits)))) == net->s_addr &&
#if BYTE_ORDER == LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
@ -1068,35 +1068,35 @@ static int
should_use_so_bsdcompat(void) should_use_so_bsdcompat(void)
{ {
#ifndef OS_BSD #ifndef OS_BSD
static int init_done = 0; static int init_done = 0;
static int so_bsdcompat_is_obsolete = 0; static int so_bsdcompat_is_obsolete = 0;
if (!init_done) { if (!init_done) {
struct utsname myutsname; struct utsname myutsname;
unsigned int version, patchlevel; unsigned int version, patchlevel;
init_done = 1; init_done = 1;
if (uname(&myutsname) < 0) { if (uname(&myutsname) < 0) {
char errStr[1024]; char errStr[1024];
dbgprintf("uname: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr))); dbgprintf("uname: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr)));
return 1; return 1;
}
/* Format is <version>.<patchlevel>.<sublevel><extraversion>
* where the first three are unsigned integers and the last
* is an arbitrary string. We only care about the first two. */
if (sscanf(myutsname.release, "%u.%u", &version, &patchlevel) != 2) {
dbgprintf("uname: unexpected release '%s'\r\n",
myutsname.release);
return 1;
}
/* SO_BSCOMPAT is deprecated and triggers warnings in 2.5
kernels. It is a no-op in 2.4 but not in 2.2 kernels. */
if (version > 2 || (version == 2 && patchlevel >= 5))
so_bsdcompat_is_obsolete = 1;
} }
/* Format is <version>.<patchlevel>.<sublevel><extraversion> return !so_bsdcompat_is_obsolete;
where the first three are unsigned integers and the last
is an arbitrary string. We only care about the first two. */
if (sscanf(myutsname.release, "%u.%u", &version, &patchlevel) != 2) {
dbgprintf("uname: unexpected release '%s'\r\n",
myutsname.release);
return 1;
}
/* SO_BSCOMPAT is deprecated and triggers warnings in 2.5
kernels. It is a no-op in 2.4 but not in 2.2 kernels. */
if (version > 2 || (version == 2 && patchlevel >= 5))
so_bsdcompat_is_obsolete = 1;
}
return !so_bsdcompat_is_obsolete;
#else /* #ifndef OS_BSD */ #else /* #ifndef OS_BSD */
return 1; return 1;
#endif /* #ifndef OS_BSD */ #endif /* #ifndef OS_BSD */
} }
#ifndef SO_BSDCOMPAT #ifndef SO_BSDCOMPAT
@ -1244,7 +1244,7 @@ closeUDPListenSockets(int *pSockArr)
register int i; register int i;
assert(pSockArr != NULL); assert(pSockArr != NULL);
if(pSockArr != NULL) { if(pSockArr != NULL) {
for (i = 0; i < *pSockArr; i++) for (i = 0; i < *pSockArr; i++)
close(pSockArr[i+1]); close(pSockArr[i+1]);
free(pSockArr); free(pSockArr);
@ -1268,7 +1268,7 @@ create_single_udp_socket(int *const s, /* socket */
const char *const device const char *const device
) )
{ {
const int on = 1; const int on = 1;
int sockflags; int sockflags;
int actrcvbuf; int actrcvbuf;
int actsndbuf; int actsndbuf;
@ -1471,44 +1471,44 @@ create_udp_socket(uchar *hostname,
const int ipfreebind, const int ipfreebind,
char *device) char *device)
{ {
struct addrinfo hints, *res, *r; struct addrinfo hints, *res, *r;
int error, maxs, *s, *socks; int error, maxs, *s, *socks;
rsRetVal localRet; rsRetVal localRet;
assert(!((pszPort == NULL) && (hostname == NULL))); /* one of them must be non-NULL */ assert(!((pszPort == NULL) && (hostname == NULL))); /* one of them must be non-NULL */
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
if(bIsServer) if(bIsServer)
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV; hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
else else
hints.ai_flags = AI_NUMERICSERV; hints.ai_flags = AI_NUMERICSERV;
hints.ai_family = glbl.GetDefPFFamily(); hints.ai_family = glbl.GetDefPFFamily();
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
# if defined (_AIX) # if defined (_AIX)
/* AIXPORT : SOCK_DGRAM has the protocol IPPROTO_UDP /* AIXPORT : SOCK_DGRAM has the protocol IPPROTO_UDP
* getaddrinfo needs this hint on AIX * getaddrinfo needs this hint on AIX
*/ */
hints.ai_protocol = IPPROTO_UDP; hints.ai_protocol = IPPROTO_UDP;
# endif # endif
error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res); error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res);
if(error) { if(error) {
LogError(0, NO_ERRCODE, "%s", gai_strerror(error)); LogError(0, NO_ERRCODE, "%s", gai_strerror(error));
LogError(0, NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n"); LogError(0, NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n");
return NULL; return NULL;
} }
/* Count max number of sockets we may open */ /* Count max number of sockets we may open */
for (maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++) for (maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++)
/* EMPTY */; /* EMPTY */;
socks = MALLOC((maxs+1) * sizeof(int)); socks = MALLOC((maxs+1) * sizeof(int));
if (socks == NULL) { if (socks == NULL) {
LogError(0, RS_RET_OUT_OF_MEMORY, "couldn't allocate memory for UDP " LogError(0, RS_RET_OUT_OF_MEMORY, "couldn't allocate memory for UDP "
"sockets, suspending UDP message reception"); "sockets, suspending UDP message reception");
freeaddrinfo(res); freeaddrinfo(res);
return NULL; return NULL;
} }
*socks = 0; /* num of sockets counter at start of array */ *socks = 0; /* num of sockets counter at start of array */
s = socks + 1; s = socks + 1;
for (r = res; r != NULL ; r = r->ai_next) { for (r = res; r != NULL ; r = r->ai_next) {
localRet = create_single_udp_socket(s, r, hostname, bIsServer, rcvbuf, localRet = create_single_udp_socket(s, r, hostname, bIsServer, rcvbuf,
sndbuf, ipfreebind, device); sndbuf, ipfreebind, device);
@ -1518,18 +1518,18 @@ create_udp_socket(uchar *hostname,
} }
} }
if(res != NULL) if(res != NULL)
freeaddrinfo(res); freeaddrinfo(res);
if(Debug && *socks != maxs) if(Debug && *socks != maxs)
dbgprintf("We could initialize %d UDP listen sockets out of %d we received " dbgprintf("We could initialize %d UDP listen sockets out of %d we received "
"- this may or may not be an error indication.\n", *socks, maxs); "- this may or may not be an error indication.\n", *socks, maxs);
if(*socks == 0) { if(*socks == 0) {
LogError(0, NO_ERRCODE, "No UDP socket could successfully be initialized, " LogError(0, NO_ERRCODE, "No UDP socket could successfully be initialized, "
"some functionality may be disabled.\n"); "some functionality may be disabled.\n");
/* we do NOT need to close any sockets, because there were none... */ /* we do NOT need to close any sockets, because there were none... */
free(socks); free(socks);
return(NULL); return(NULL);
} }
@ -1631,7 +1631,7 @@ getIFIPAddr(uchar *szif, int family, uchar *pszbuf, int lenBuf)
void * pAddr; void * pAddr;
DEFiRet; DEFiRet;
if(getifaddrs(&ifaddrs) != 0) { if(getifaddrs(&ifaddrs) != 0) {
ABORT_FINALIZE(RS_RET_ERR); ABORT_FINALIZE(RS_RET_ERR);
} }

View File

@ -311,38 +311,38 @@ long BIO_debug_callback(BIO *bio, int cmd, const char __attribute__((unused)) *a
dbgprintf("write %s\n", RSYSLOG_BIO_method_name(bio)); dbgprintf("write %s\n", RSYSLOG_BIO_method_name(bio));
break; break;
#endif #endif
case BIO_CB_PUTS: case BIO_CB_PUTS:
dbgprintf("puts() - %s\n", RSYSLOG_BIO_method_name(bio)); dbgprintf("puts() - %s\n", RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_GETS: case BIO_CB_GETS:
dbgprintf("gets(%lu) - %s\n", (unsigned long)argi, dbgprintf("gets(%lu) - %s\n", (unsigned long)argi,
RSYSLOG_BIO_method_name(bio)); RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_CTRL: case BIO_CB_CTRL:
dbgprintf("ctrl(%lu) - %s\n", (unsigned long)argi, dbgprintf("ctrl(%lu) - %s\n", (unsigned long)argi,
RSYSLOG_BIO_method_name(bio)); RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_RETURN | BIO_CB_READ: case BIO_CB_RETURN | BIO_CB_READ:
dbgprintf("read return %ld\n", ret); dbgprintf("read return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_WRITE: case BIO_CB_RETURN | BIO_CB_WRITE:
dbgprintf("write return %ld\n", ret); dbgprintf("write return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_GETS: case BIO_CB_RETURN | BIO_CB_GETS:
dbgprintf("gets return %ld\n", ret); dbgprintf("gets return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_PUTS: case BIO_CB_RETURN | BIO_CB_PUTS:
dbgprintf("puts return %ld\n", ret); dbgprintf("puts return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_CTRL: case BIO_CB_RETURN | BIO_CB_CTRL:
dbgprintf("ctrl return %ld\n", ret); dbgprintf("ctrl return %ld\n", ret);
break; break;
default: default:
dbgprintf("bio callback - unknown type (%d)\n", cmd); dbgprintf("bio callback - unknown type (%d)\n", cmd);
break; break;
} }
return (r); return (r);
} }

View File

@ -292,7 +292,7 @@ Abort(nsd_t *pNsd)
if((pThis)->sock != -1) { if((pThis)->sock != -1) {
ling.l_onoff = 1; ling.l_onoff = 1;
ling.l_linger = 0; ling.l_linger = 0;
if(setsockopt((pThis)->sock, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) < 0 ) { if(setsockopt((pThis)->sock, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) < 0 ) {
dbgprintf("could not set SO_LINGER, errno %d\n", errno); dbgprintf("could not set SO_LINGER, errno %d\n", errno);
} }
} }
@ -416,11 +416,11 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
DEFiRet; DEFiRet;
netstrm_t *pNewStrm = NULL; netstrm_t *pNewStrm = NULL;
nsd_t *pNewNsd = NULL; nsd_t *pNewNsd = NULL;
int error, maxs, on = 1; int error, maxs, on = 1;
int sock = -1; int sock = -1;
int numSocks; int numSocks;
int sockflags; int sockflags;
struct addrinfo hints, *res = NULL, *r; struct addrinfo hints, *res = NULL, *r;
ISOBJ_TYPE_assert(pNS, netstrms); ISOBJ_TYPE_assert(pNS, netstrms);
assert(fAddLstn != NULL); assert(fAddLstn != NULL);
@ -429,49 +429,49 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
dbgprintf("creating tcp listen socket on port %s\n", pLstnPort); dbgprintf("creating tcp listen socket on port %s\n", pLstnPort);
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE; hints.ai_flags = AI_PASSIVE;
hints.ai_family = glbl.GetDefPFFamily(); hints.ai_family = glbl.GetDefPFFamily();
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo((char*)pLstnIP, (char*) pLstnPort, &hints, &res); error = getaddrinfo((char*)pLstnIP, (char*) pLstnPort, &hints, &res);
if(error) { if(error) {
LogError(0, RS_RET_INVALID_PORT, "error querying port '%s': %s", LogError(0, RS_RET_INVALID_PORT, "error querying port '%s': %s",
pLstnPort, gai_strerror(error)); pLstnPort, gai_strerror(error));
ABORT_FINALIZE(RS_RET_INVALID_PORT); ABORT_FINALIZE(RS_RET_INVALID_PORT);
} }
/* Count max number of sockets we may open */ /* Count max number of sockets we may open */
for(maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++) for(maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++)
/* EMPTY */; /* EMPTY */;
numSocks = 0; /* num of sockets counter at start of array */ numSocks = 0; /* num of sockets counter at start of array */
for(r = res; r != NULL ; r = r->ai_next) { for(r = res; r != NULL ; r = r->ai_next) {
sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol); sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
if(sock < 0) { if(sock < 0) {
if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT)) { if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT)) {
dbgprintf("error %d creating tcp listen socket", errno); dbgprintf("error %d creating tcp listen socket", errno);
/* it is debatable if PF_INET with EAFNOSUPPORT should /* it is debatable if PF_INET with EAFNOSUPPORT should
* also be ignored... * also be ignored...
*/ */
} }
continue; continue;
} }
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
if(r->ai_family == AF_INET6) { if(r->ai_family == AF_INET6) {
int iOn = 1; int iOn = 1;
if(setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, if(setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
(char *)&iOn, sizeof (iOn)) < 0) { (char *)&iOn, sizeof (iOn)) < 0) {
close(sock); close(sock);
sock = -1; sock = -1;
continue; continue;
} }
} }
#endif #endif
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) { if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) {
dbgprintf("error %d setting tcp socket option\n", errno); dbgprintf("error %d setting tcp socket option\n", errno);
close(sock); close(sock);
sock = -1; sock = -1;
continue; continue;
} }
@ -486,7 +486,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
} }
if(sockflags == -1) { if(sockflags == -1) {
dbgprintf("error %d setting fcntl(O_NONBLOCK) on tcp socket", errno); dbgprintf("error %d setting fcntl(O_NONBLOCK) on tcp socket", errno);
close(sock); close(sock);
sock = -1; sock = -1;
continue; continue;
} }
@ -496,15 +496,15 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
* could flood our log files by sending us tons of ICMP errors. * could flood our log files by sending us tons of ICMP errors.
*/ */
/* AIXPORT : SO_BSDCOMPAT socket option is depricated , and its usage has been discontinued /* AIXPORT : SO_BSDCOMPAT socket option is depricated , and its usage has been discontinued
on most unixes, AIX does not support this option , hence remove the call. * on most unixes, AIX does not support this option , hence remove the call.
*/ */
#if !defined(_AIX) #if !defined(_AIX)
#ifndef BSD #ifndef BSD
if(net.should_use_so_bsdcompat()) { if(net.should_use_so_bsdcompat()) {
if (setsockopt(sock, SOL_SOCKET, SO_BSDCOMPAT, if (setsockopt(sock, SOL_SOCKET, SO_BSDCOMPAT,
(char *) &on, sizeof(on)) < 0) { (char *) &on, sizeof(on)) < 0) {
LogError(errno, NO_ERRCODE, "TCP setsockopt(BSDCOMPAT)"); LogError(errno, NO_ERRCODE, "TCP setsockopt(BSDCOMPAT)");
close(sock); close(sock);
sock = -1; sock = -1;
continue; continue;
} }
@ -520,11 +520,11 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
/* TODO: check if *we* bound the socket - else we *have* an error! */ /* TODO: check if *we* bound the socket - else we *have* an error! */
char errStr[1024]; char errStr[1024];
rs_strerror_r(errno, errStr, sizeof(errStr)); rs_strerror_r(errno, errStr, sizeof(errStr));
dbgprintf("error %d while binding tcp socket: %s\n", errno, errStr); dbgprintf("error %d while binding tcp socket: %s\n", errno, errStr);
close(sock); close(sock);
sock = -1; sock = -1;
continue; continue;
} }
if(listen(sock, iSessMax / 10 + 5) < 0) { if(listen(sock, iSessMax / 10 + 5) < 0) {
/* If the listen fails, it most probably fails because we ask /* If the listen fails, it most probably fails because we ask
@ -538,7 +538,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
dbgprintf("tcp listen error %d, suspending\n", errno); dbgprintf("tcp listen error %d, suspending\n", errno);
close(sock); close(sock);
sock = -1; sock = -1;
continue; continue;
} }
} }
@ -569,7 +569,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
dbgprintf("We could initialize %d TCP listen sockets out of %d we received " dbgprintf("We could initialize %d TCP listen sockets out of %d we received "
"- this may or may not be an error indication.\n", numSocks, maxs); "- this may or may not be an error indication.\n", numSocks, maxs);
if(numSocks == 0) { if(numSocks == 0) {
dbgprintf("No TCP listen sockets could successfully be initialized\n"); dbgprintf("No TCP listen sockets could successfully be initialized\n");
ABORT_FINALIZE(RS_RET_COULD_NOT_BIND); ABORT_FINALIZE(RS_RET_COULD_NOT_BIND);
} }
@ -774,8 +774,8 @@ Connect(nsd_t *pNsd, int family, uchar *port, uchar *host, char *device)
# if defined(SO_BINDTODEVICE) # if defined(SO_BINDTODEVICE)
if(setsockopt(pThis->sock, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) < 0) if(setsockopt(pThis->sock, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) < 0)
# endif # endif
{ {
dbgprintf("setsockopt(SO_BINDTODEVICE) failed\n"); dbgprintf("setsockopt(SO_BINDTODEVICE) failed\n");
ABORT_FINALIZE(RS_RET_IO_ERROR); ABORT_FINALIZE(RS_RET_IO_ERROR);
} }
} }
@ -788,7 +788,7 @@ Connect(nsd_t *pNsd, int family, uchar *port, uchar *host, char *device)
finalize_it: finalize_it:
if(res != NULL) if(res != NULL)
freeaddrinfo(res); freeaddrinfo(res);
if(iRet != RS_RET_OK) { if(iRet != RS_RET_OK) {
sockClose(&pThis->sock); sockClose(&pThis->sock);

View File

@ -133,8 +133,8 @@ static rsRetVal objInfoNotImplementedDummy(void __attribute__((unused)) *pThis)
*/ */
static rsRetVal static rsRetVal
InfoConstruct(objInfo_t **ppThis, uchar *pszID, int iObjVers, InfoConstruct(objInfo_t **ppThis, uchar *pszID, int iObjVers,
rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *), rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *),
rsRetVal (*pQueryIF)(interface_t*), modInfo_t *pModInfo) rsRetVal (*pQueryIF)(interface_t*), modInfo_t *pModInfo)
{ {
DEFiRet; DEFiRet;
int i; int i;

View File

@ -61,7 +61,7 @@ BEGINinterface(parser) /* name must also be changed in ENDinterface macro! */
ENDinterface(parser) ENDinterface(parser)
#define parserCURR_IF_VERSION 2 /* increment whenever you change the interface above! */ #define parserCURR_IF_VERSION 2 /* increment whenever you change the interface above! */
/* version changes /* version changes
2 SetDoSanitization removed, no longer needed 2 SetDoSanitization removed, no longer needed
*/ */
void printParserList(parserList_t *pList); void printParserList(parserList_t *pList);

View File

@ -2123,7 +2123,7 @@ finalize_it:
* Unless the error code is RS_RET_ERR_QUEUE_EMERGENCY, we reset the return state to RS_RET_OK. * Unless the error code is RS_RET_ERR_QUEUE_EMERGENCY, we reset the return state to RS_RET_OK.
* Otherwise the Caller functions would run into an infinite Loop trying to enqueue the * Otherwise the Caller functions would run into an infinite Loop trying to enqueue the
* same messages over and over again. * same messages over and over again.
* *
* However we do NOT overwrite positive return states like * However we do NOT overwrite positive return states like
* RS_RET_TERMINATE_NOW, * RS_RET_TERMINATE_NOW,
* RS_RET_NO_RUN, * RS_RET_NO_RUN,
@ -2525,7 +2525,7 @@ qqueuePersist(qqueue_t *pThis, int bIsCheckpoint)
if(pThis->qType != QUEUETYPE_DISK) { if(pThis->qType != QUEUETYPE_DISK) {
if(getPhysicalQueueSize(pThis) > 0) { if(getPhysicalQueueSize(pThis) > 0) {
/* This error code is OK, but we will probably not implement this any time /* This error code is OK, but we will probably not implement this any time
* The reason is that persistence happens via DA queues. But I would like to * The reason is that persistence happens via DA queues. But I would like to
* leave the code as is, as we so have a hook in case we need one. * leave the code as is, as we so have a hook in case we need one.
* -- rgerhards, 2008-01-28 * -- rgerhards, 2008-01-28
*/ */
@ -2552,7 +2552,7 @@ qqueuePersist(qqueue_t *pThis, int bIsCheckpoint)
lentmpQIFName = strlen( pThis->pszQIFNam) + strlen(".tmp") + 1; lentmpQIFName = strlen( pThis->pszQIFNam) + strlen(".tmp") + 1;
tmpQIFName = malloc(sizeof(char)*lentmpQIFName); tmpQIFName = malloc(sizeof(char)*lentmpQIFName);
if(tmpQIFName == NULL) if(tmpQIFName == NULL)
tmpQIFName = (char*)pThis->pszQIFNam; tmpQIFName = (char*)pThis->pszQIFNam;
snprintf(tmpQIFName, lentmpQIFName, "%s.tmp", pThis->pszQIFNam); snprintf(tmpQIFName, lentmpQIFName, "%s.tmp", pThis->pszQIFNam);
#else #else
lentmpQIFName = asprintf((char **)&tmpQIFName, "%s.tmp", pThis->pszQIFNam); lentmpQIFName = asprintf((char **)&tmpQIFName, "%s.tmp", pThis->pszQIFNam);
@ -2898,7 +2898,7 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, smsg_t *pMsg)
DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()" DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()"
"/fulldelay returned %d\n", err); "/fulldelay returned %d\n", err);
break; break;
} }
DBGPRINTF("wti worker in full delay timed out, checking termination...\n"); DBGPRINTF("wti worker in full delay timed out, checking termination...\n");
} }
@ -2912,7 +2912,7 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, smsg_t *pMsg)
/* Something is really wrong now. Report to debug log */ /* Something is really wrong now. Report to debug log */
DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()" DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()"
"/lightdelay returned %d\n", err); "/lightdelay returned %d\n", err);
} }
} }
} }
@ -3302,14 +3302,14 @@ static rsRetVal qqueueSetProperty(qqueue_t *pThis, var_t *pProp)
ISOBJ_TYPE_assert(pThis, qqueue); ISOBJ_TYPE_assert(pThis, qqueue);
ASSERT(pProp != NULL); ASSERT(pProp != NULL);
if(isProp("iQueueSize")) { if(isProp("iQueueSize")) {
pThis->iQueueSize = pProp->val.num; pThis->iQueueSize = pProp->val.num;
# ifdef ENABLE_IMDIAG # ifdef ENABLE_IMDIAG
iOverallQueueSize += pThis->iQueueSize; iOverallQueueSize += pThis->iQueueSize;
# endif # endif
} else if(isProp("tVars.disk.sizeOnDisk")) { } else if(isProp("tVars.disk.sizeOnDisk")) {
pThis->tVars.disk.sizeOnDisk = pProp->val.num; pThis->tVars.disk.sizeOnDisk = pProp->val.num;
} else if(isProp("qType")) { } else if(isProp("qType")) {
if(pThis->qType != pProp->val.num) if(pThis->qType != pProp->val.num)
ABORT_FINALIZE(RS_RET_QTYPE_MISMATCH); ABORT_FINALIZE(RS_RET_QTYPE_MISMATCH);
} }

View File

@ -203,21 +203,21 @@ uchar *srUtilStrDup(uchar *pOld, size_t len)
static int real_makeFileParentDirs(const uchar *const szFile, const size_t lenFile, const mode_t mode, static int real_makeFileParentDirs(const uchar *const szFile, const size_t lenFile, const mode_t mode,
const uid_t uid, const gid_t gid, const int bFailOnChownFail) const uid_t uid, const gid_t gid, const int bFailOnChownFail)
{ {
uchar *p; uchar *p;
uchar *pszWork; uchar *pszWork;
size_t len; size_t len;
assert(szFile != NULL); assert(szFile != NULL);
assert(lenFile > 0); assert(lenFile > 0);
len = lenFile + 1; /* add one for '\0'-byte */ len = lenFile + 1; /* add one for '\0'-byte */
if((pszWork = MALLOC(len)) == NULL) if((pszWork = MALLOC(len)) == NULL)
return -1; return -1;
memcpy(pszWork, szFile, len); memcpy(pszWork, szFile, len);
for(p = pszWork+1 ; *p ; p++) for(p = pszWork+1 ; *p ; p++)
if(*p == '/') { if(*p == '/') {
/* temporarily terminate string, create dir and go on */ /* temporarily terminate string, create dir and go on */
*p = '\0'; *p = '\0';
int bErr = 0; int bErr = 0;
if(mkdir((char*)pszWork, mode) == 0) { if(mkdir((char*)pszWork, mode) == 0) {
if(uid != (uid_t) -1 || gid != (gid_t) -1) { if(uid != (uid_t) -1 || gid != (gid_t) -1) {
@ -242,8 +242,8 @@ static int real_makeFileParentDirs(const uchar *const szFile, const size_t lenFi
errno = eSave; errno = eSave;
return -1; return -1;
} }
*p = '/'; *p = '/';
} }
free(pszWork); free(pszWork);
return 0; return 0;
} }
@ -274,17 +274,17 @@ int makeFileParentDirs(const uchar *const szFile, const size_t lenFile, const mo
*/ */
int execProg(uchar *program, int bWait, uchar *arg) int execProg(uchar *program, int bWait, uchar *arg)
{ {
int pid; int pid;
int sig; int sig;
struct sigaction sigAct; struct sigaction sigAct;
dbgprintf("exec program '%s' with param '%s'\n", program, arg); dbgprintf("exec program '%s' with param '%s'\n", program, arg);
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
return 0; return 0;
} }
if(pid) { /* Parent */ if(pid) { /* Parent */
if(bWait) if(bWait)
if(waitpid(pid, NULL, 0) == -1) if(waitpid(pid, NULL, 0) == -1)
if(errno != ECHILD) { if(errno != ECHILD) {
@ -296,9 +296,9 @@ int execProg(uchar *program, int bWait, uchar *arg)
dbgprintf("could not wait on child after executing '%s'", dbgprintf("could not wait on child after executing '%s'",
(char*)program); (char*)program);
} }
return pid; return pid;
} }
/* Child */ /* Child */
alarm(0); /* create a clean environment before we exec the real child */ alarm(0); /* create a clean environment before we exec the real child */
memset(&sigAct, 0, sizeof(sigAct)); memset(&sigAct, 0, sizeof(sigAct));
@ -637,7 +637,7 @@ int getSubString(uchar **ppSrc, char *pDst, size_t DstSize, char cSep)
if ((cSep == ' ' ? !isspace(*pSrc) : *pSrc != cSep) && *pSrc != '\n' && *pSrc != '\0') { if ((cSep == ' ' ? !isspace(*pSrc) : *pSrc != cSep) && *pSrc != '\n' && *pSrc != '\0') {
dbgprintf("in getSubString, error Src buffer > Dst buffer\n"); dbgprintf("in getSubString, error Src buffer > Dst buffer\n");
iErr = 1; iErr = 1;
} }
if (*pSrc == '\0' || *pSrc == '\n') if (*pSrc == '\0' || *pSrc == '\n')
/* this line was missing, causing ppSrc to be invalid when it /* this line was missing, causing ppSrc to be invalid when it
* was returned in case of end-of-string. rgerhards 2005-07-29 * was returned in case of end-of-string. rgerhards 2005-07-29

View File

@ -232,12 +232,12 @@ ctr_t **entryRef, int8_t linked)
*entryRef = ctr; *entryRef = ctr;
finalize_it: finalize_it:
if (iRet != RS_RET_OK) { if (iRet != RS_RET_OK) {
if (ctr != NULL) { if (ctr != NULL) {
free(ctr->name); free(ctr->name);
free(ctr); free(ctr);
} }
} }
RETiRet; RETiRet;
} }
@ -267,7 +267,7 @@ destructUnlinkedCounter(ctr_t *ctr) {
static void static void
destructCounter(statsobj_t *pThis, ctr_t *pCtr) destructCounter(statsobj_t *pThis, ctr_t *pCtr)
{ {
pthread_mutex_lock(&pThis->mutCtr); pthread_mutex_lock(&pThis->mutCtr);
if (pCtr->prev != NULL) { if (pCtr->prev != NULL) {
pCtr->prev->next = pCtr->next; pCtr->prev->next = pCtr->next;
} }

View File

@ -862,7 +862,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF,
if(pThis->bPrevWasNL) { if(pThis->bPrevWasNL) {
if ((c == ' ') || (c == '\t')){ if ((c == ' ') || (c == '\t')){
CHKiRet(cstrAppendChar(*ppCStr, c)); CHKiRet(cstrAppendChar(*ppCStr, c));
CHKiRet(strmReadChar(pThis, &c)); CHKiRet(strmReadChar(pThis, &c));
pThis->bPrevWasNL = 0; pThis->bPrevWasNL = 0;
} else { } else {
/* clean things up by putting the character we just read back into /* clean things up by putting the character we just read back into
@ -885,7 +885,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF,
} else { } else {
CHKiRet(cstrAppendChar(*ppCStr, c)); CHKiRet(cstrAppendChar(*ppCStr, c));
} }
CHKiRet(strmReadChar(pThis, &c)); CHKiRet(strmReadChar(pThis, &c));
} }
} }
} }
@ -900,7 +900,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF,
} }
finalize_it: finalize_it:
if(iRet == RS_RET_OK) { if(iRet == RS_RET_OK) {
if(strtOffs != NULL) { if(strtOffs != NULL) {
*strtOffs = pThis->strtOffs; *strtOffs = pThis->strtOffs;
} }
@ -920,7 +920,7 @@ finalize_it:
} }
} }
RETiRet; RETiRet;
} }
/* check if the current multi line read is timed out /* check if the current multi line read is timed out
@ -950,13 +950,13 @@ rsRetVal
strmReadMultiLine(strm_t *pThis, cstr_t **ppCStr, regex_t *preg, const sbool bEscapeLF, strmReadMultiLine(strm_t *pThis, cstr_t **ppCStr, regex_t *preg, const sbool bEscapeLF,
const sbool discardTruncatedMsg, const sbool msgDiscardingError, int64 *const strtOffs) const sbool discardTruncatedMsg, const sbool msgDiscardingError, int64 *const strtOffs)
{ {
uchar c; uchar c;
uchar finished = 0; uchar finished = 0;
cstr_t *thisLine = NULL; cstr_t *thisLine = NULL;
rsRetVal readCharRet; rsRetVal readCharRet;
const time_t tCurr = pThis->readTimeout ? getTime(NULL) : 0; const time_t tCurr = pThis->readTimeout ? getTime(NULL) : 0;
int maxMsgSize = glblGetMaxLine(); int maxMsgSize = glblGetMaxLine();
DEFiRet; DEFiRet;
do { do {
CHKiRet(strmReadChar(pThis, &c)); /* immediately exit on EOF */ CHKiRet(strmReadChar(pThis, &c)); /* immediately exit on EOF */
@ -1073,7 +1073,7 @@ finalize_it:
} }
} }
} }
RETiRet; RETiRet;
} }
/* Standard-Constructor for the strm object /* Standard-Constructor for the strm object
@ -1544,7 +1544,7 @@ asyncWriterThread(void *pPtr)
pthread_cond_broadcast(&pThis->isEmpty); pthread_cond_broadcast(&pThis->isEmpty);
} }
} }
/* Not reached */ /* Not reached */
finalize_it: finalize_it:
ENDfunc ENDfunc
@ -2318,37 +2318,37 @@ static rsRetVal strmSetProperty(strm_t *pThis, var_t *pProp)
ISOBJ_TYPE_assert(pThis, strm); ISOBJ_TYPE_assert(pThis, strm);
ASSERT(pProp != NULL); ASSERT(pProp != NULL);
if(isProp("sType")) { if(isProp("sType")) {
CHKiRet(strmSetsType(pThis, (strmType_t) pProp->val.num)); CHKiRet(strmSetsType(pThis, (strmType_t) pProp->val.num));
} else if(isProp("iCurrFNum")) { } else if(isProp("iCurrFNum")) {
pThis->iCurrFNum = (unsigned) pProp->val.num; pThis->iCurrFNum = (unsigned) pProp->val.num;
} else if(isProp("pszFName")) { } else if(isProp("pszFName")) {
CHKiRet(strmSetFName(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr), rsCStrLen(pProp->val.pStr))); CHKiRet(strmSetFName(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr), rsCStrLen(pProp->val.pStr)));
} else if(isProp("tOperationsMode")) { } else if(isProp("tOperationsMode")) {
CHKiRet(strmSettOperationsMode(pThis, pProp->val.num)); CHKiRet(strmSettOperationsMode(pThis, pProp->val.num));
} else if(isProp("tOpenMode")) { } else if(isProp("tOpenMode")) {
CHKiRet(strmSettOpenMode(pThis, pProp->val.num)); CHKiRet(strmSettOpenMode(pThis, pProp->val.num));
} else if(isProp("iCurrOffs")) { } else if(isProp("iCurrOffs")) {
pThis->iCurrOffs = pProp->val.num; pThis->iCurrOffs = pProp->val.num;
} else if(isProp("inode")) { } else if(isProp("inode")) {
pThis->inode = (ino_t) pProp->val.num; pThis->inode = (ino_t) pProp->val.num;
} else if(isProp("strtOffs")) { } else if(isProp("strtOffs")) {
pThis->strtOffs = pProp->val.num; pThis->strtOffs = pProp->val.num;
} else if(isProp("iMaxFileSize")) { } else if(isProp("iMaxFileSize")) {
CHKiRet(strmSetiMaxFileSize(pThis, pProp->val.num)); CHKiRet(strmSetiMaxFileSize(pThis, pProp->val.num));
} else if(isProp("fileNotFoundError")) { } else if(isProp("fileNotFoundError")) {
CHKiRet(strmSetFileNotFoundError(pThis, pProp->val.num)); CHKiRet(strmSetFileNotFoundError(pThis, pProp->val.num));
} else if(isProp("iMaxFiles")) { } else if(isProp("iMaxFiles")) {
CHKiRet(strmSetiMaxFiles(pThis, pProp->val.num)); CHKiRet(strmSetiMaxFiles(pThis, pProp->val.num));
} else if(isProp("iFileNumDigits")) { } else if(isProp("iFileNumDigits")) {
CHKiRet(strmSetiFileNumDigits(pThis, pProp->val.num)); CHKiRet(strmSetiFileNumDigits(pThis, pProp->val.num));
} else if(isProp("bDeleteOnClose")) { } else if(isProp("bDeleteOnClose")) {
CHKiRet(strmSetbDeleteOnClose(pThis, pProp->val.num)); CHKiRet(strmSetbDeleteOnClose(pThis, pProp->val.num));
} else if(isProp("prevLineSegment")) { } else if(isProp("prevLineSegment")) {
CHKiRet(rsCStrConstructFromCStr(&pThis->prevLineSegment, pProp->val.pStr)); CHKiRet(rsCStrConstructFromCStr(&pThis->prevLineSegment, pProp->val.pStr));
} else if(isProp("prevMsgSegment")) { } else if(isProp("prevMsgSegment")) {
CHKiRet(rsCStrConstructFromCStr(&pThis->prevMsgSegment, pProp->val.pStr)); CHKiRet(rsCStrConstructFromCStr(&pThis->prevMsgSegment, pProp->val.pStr));
} else if(isProp("bPrevWasNL")) { } else if(isProp("bPrevWasNL")) {
pThis->bPrevWasNL = (sbool) pProp->val.num; pThis->bPrevWasNL = (sbool) pProp->val.num;
} }

View File

@ -307,7 +307,7 @@ static void deinit_strm_listener(strmsrv_t *pThis)
/* now get next... */ /* now get next... */
i = STRMSessGetNxtSess(pThis, i); i = STRMSessGetNxtSess(pThis, i);
} }
/* we are done with the session table - so get rid of it... */ /* we are done with the session table - so get rid of it... */
free(pThis->pSessions); free(pThis->pSessions);
pThis->pSessions = NULL; /* just to make sure... */ pThis->pSessions = NULL; /* just to make sure... */

View File

@ -95,7 +95,7 @@ CreateSocket(struct addrinfo *addrDest)
char errStr[1024]; char errStr[1024];
dbgprintf("couldn't create send socket, reason %s", rs_strerror_r(errno, errStr, dbgprintf("couldn't create send socket, reason %s", rs_strerror_r(errno, errStr,
sizeof(errStr))); sizeof(errStr)));
} }
r = r->ai_next; r = r->ai_next;
} }

View File

@ -1187,10 +1187,10 @@ SetKeepAliveProbes(tcpsrv_t *pThis, int iVal)
static rsRetVal static rsRetVal
SetKeepAliveTime(tcpsrv_t *pThis, int iVal) SetKeepAliveTime(tcpsrv_t *pThis, int iVal)
{ {
DEFiRet; DEFiRet;
DBGPRINTF("tcpsrv: keep-alive timeout set to %d\n", iVal); DBGPRINTF("tcpsrv: keep-alive timeout set to %d\n", iVal);
pThis->iKeepAliveTime = iVal; pThis->iKeepAliveTime = iVal;
RETiRet; RETiRet;
} }
static rsRetVal static rsRetVal

View File

@ -27,7 +27,7 @@
#define INCLUDED_TYPEDEFS_H #define INCLUDED_TYPEDEFS_H
#ifndef _AIX #ifndef _AIX
#include <stdint.h> #include <stdint.h>
#endif #endif
#ifdef _AIX #ifdef _AIX
#include "config.h" #include "config.h"

View File

@ -36,7 +36,7 @@
#ifdef USE_UNLIMITED_SELECT #ifdef USE_UNLIMITED_SELECT
static inline void freeFdSet(fd_set *p) { static inline void freeFdSet(fd_set *p) {
free(p); free(p);
} }
#else #else
# define freeFdSet(x) # define freeFdSet(x)

View File

@ -647,7 +647,7 @@ do_Constant(unsigned char **pp, struct template *pTpl, int bDoEscapes)
while(*p && *p != '%' && !(bDoEscapes && *p == '\"')) { while(*p && *p != '%' && !(bDoEscapes && *p == '\"')) {
if(bDoEscapes && *p == '\\') { if(bDoEscapes && *p == '\\') {
switch(*++p) { switch(*++p) {
case '\0': case '\0':
/* the best we can do - it's invalid anyhow... */ /* the best we can do - it's invalid anyhow... */
cstrAppendChar(pStrB, *p); cstrAppendChar(pStrB, *p);
break; break;
@ -760,8 +760,8 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe)
*/ */
if(!strcmp((char*)Buf, "date-mysql")) { if(!strcmp((char*)Buf, "date-mysql")) {
pTpe->data.field.eDateFormat = tplFmtMySQLDate; pTpe->data.field.eDateFormat = tplFmtMySQLDate;
} else if(!strcmp((char*)Buf, "date-pgsql")) { } else if(!strcmp((char*)Buf, "date-pgsql")) {
pTpe->data.field.eDateFormat = tplFmtPgSQLDate; pTpe->data.field.eDateFormat = tplFmtPgSQLDate;
} else if(!strcmp((char*)Buf, "date-rfc3164")) { } else if(!strcmp((char*)Buf, "date-rfc3164")) {
pTpe->data.field.eDateFormat = tplFmtRFC3164Date; pTpe->data.field.eDateFormat = tplFmtRFC3164Date;
} else if(!strcmp((char*)Buf, "date-rfc3164-buggyday")) { } else if(!strcmp((char*)Buf, "date-rfc3164-buggyday")) {
@ -1264,7 +1264,7 @@ tplAddTplMod(struct template *pTpl, uchar** ppRestOfConfLine)
while(*pSrc && !isspace(*pSrc) && lenMod < sizeof(szMod) - 1) { while(*pSrc && !isspace(*pSrc) && lenMod < sizeof(szMod) - 1) {
szMod[lenMod] = *pSrc++; szMod[lenMod] = *pSrc++;
lenMod++; lenMod++;
} }
szMod[lenMod] = '\0'; szMod[lenMod] = '\0';
*ppRestOfConfLine = pSrc; *ppRestOfConfLine = pSrc;
@ -1300,7 +1300,7 @@ finalize_it:
struct template *tplAddLine(rsconf_t *conf, const char* pName, uchar** ppRestOfConfLine) struct template *tplAddLine(rsconf_t *conf, const char* pName, uchar** ppRestOfConfLine)
{ {
struct template *pTpl; struct template *pTpl;
unsigned char *p; unsigned char *p;
int bDone; int bDone;
size_t i; size_t i;
rsRetVal localRet; rsRetVal localRet;
@ -1392,14 +1392,14 @@ struct template *tplAddLine(rsconf_t *conf, const char* pName, uchar** ppRestOfC
while(*p) { while(*p) {
while(isspace((int)*p))/* skip whitespace */ while(isspace((int)*p))/* skip whitespace */
++p; ++p;
if(*p != ',') if(*p != ',')
break; break;
++p; /* eat ',' */ ++p; /* eat ',' */
while(isspace((int)*p))/* skip whitespace */ while(isspace((int)*p))/* skip whitespace */
++p; ++p;
/* read option word */ /* read option word */
char optBuf[128] = { '\0' }; /* buffer for options - should be more than enough... */ char optBuf[128] = { '\0' }; /* buffer for options - should be more than enough... */
i = 0; i = 0;
@ -2345,9 +2345,9 @@ void tplPrintList(rsconf_t *conf)
case tplFmtMySQLDate: case tplFmtMySQLDate:
dbgprintf("[Format as MySQL-Date] "); dbgprintf("[Format as MySQL-Date] ");
break; break;
case tplFmtPgSQLDate: case tplFmtPgSQLDate:
dbgprintf("[Format as PgSQL-Date] "); dbgprintf("[Format as PgSQL-Date] ");
break; break;
case tplFmtRFC3164Date: case tplFmtRFC3164Date:
dbgprintf("[Format as RFC3164-Date] "); dbgprintf("[Format as RFC3164-Date] ");
break; break;

View File

@ -60,12 +60,12 @@ struct template {
enum EntryTypes { UNDEFINED = 0, CONSTANT = 1, FIELD = 2 }; enum EntryTypes { UNDEFINED = 0, CONSTANT = 1, FIELD = 2 };
enum tplFormatTypes { tplFmtDefault = 0, tplFmtMySQLDate = 1, enum tplFormatTypes { tplFmtDefault = 0, tplFmtMySQLDate = 1,
tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3, tplFmtPgSQLDate = 4, tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3, tplFmtPgSQLDate = 4,
tplFmtSecFrac = 5, tplFmtRFC3164BuggyDate = 6, tplFmtUnixDate = 7, tplFmtSecFrac = 5, tplFmtRFC3164BuggyDate = 6, tplFmtUnixDate = 7,
tplFmtWDayName = 8, tplFmtYear = 9, tplFmtMonth = 10, tplFmtDay = 11, tplFmtWDayName = 8, tplFmtYear = 9, tplFmtMonth = 10, tplFmtDay = 11,
tplFmtHour = 12, tplFmtMinute = 13, tplFmtSecond = 14, tplFmtHour = 12, tplFmtMinute = 13, tplFmtSecond = 14,
tplFmtTZOffsHour = 15, tplFmtTZOffsMin = 16, tplFmtTZOffsDirection = 17, tplFmtTZOffsHour = 15, tplFmtTZOffsMin = 16, tplFmtTZOffsDirection = 17,
tplFmtWDay = 18, tplFmtOrdinal = 19, tplFmtWeek = 20}; tplFmtWDay = 18, tplFmtOrdinal = 19, tplFmtWeek = 20};
enum tplFormatCaseConvTypes { tplCaseConvNo = 0, tplCaseConvUpper = 1, tplCaseConvLower = 2 }; enum tplFormatCaseConvTypes { tplCaseConvNo = 0, tplCaseConvUpper = 1, tplCaseConvLower = 2 };
enum tplRegexType { TPL_REGEX_BRE = 0, /* posix BRE */ enum tplRegexType { TPL_REGEX_BRE = 0, /* posix BRE */
TPL_REGEX_ERE = 1 /* posix ERE */ TPL_REGEX_ERE = 1 /* posix ERE */
@ -104,7 +104,7 @@ struct templateEntry {
that we were searching in*/ that we were searching in*/
TPL_REGEX_NOMATCH_USE_ZERO = 3 /* use 0 (useful for numerical values) */ TPL_REGEX_NOMATCH_USE_ZERO = 3 /* use 0 (useful for numerical values) */
} nomatchAction; /**< what to do if we do not have a match? */ } nomatchAction; /**< what to do if we do not have a match? */
#endif #endif
unsigned has_fields; /* support for field-counting: field to extract */ unsigned has_fields; /* support for field-counting: field to extract */
unsigned char field_delim; /* support for field-counting: field delemiter char */ unsigned char field_delim; /* support for field-counting: field delemiter char */

View File

@ -254,7 +254,7 @@ static void closeTLSSess(int __attribute__((unused)) i);
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-security" #pragma GCC diagnostic ignored "-Wformat-security"
static void relp_dbgprintf(char __attribute__((unused)) *fmt, ...) { static void relp_dbgprintf(char __attribute__((unused)) *fmt, ...) {
printf(fmt); printf(fmt);
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@ -938,79 +938,79 @@ runTests(void)
*/ */
long BIO_debug_callback(BIO *bio, int cmd, const char __attribute__((unused)) *argp, long BIO_debug_callback(BIO *bio, int cmd, const char __attribute__((unused)) *argp,
int argi, long __attribute__((unused)) argl, long ret) int argi, long __attribute__((unused)) argl, long ret)
{ {
long r = 1; long r = 1;
if (BIO_CB_RETURN & cmd) if (BIO_CB_RETURN & cmd)
r = ret; r = ret;
printf("tcpdump: openssl debugmsg: BIO[%p]: ", (void *)bio); printf("tcpdump: openssl debugmsg: BIO[%p]: ", (void *)bio);
switch (cmd) { switch (cmd) {
case BIO_CB_FREE: case BIO_CB_FREE:
printf("Free - %s\n", RSYSLOG_BIO_method_name(bio)); printf("Free - %s\n", RSYSLOG_BIO_method_name(bio));
break; break;
/* Disabled due API changes for OpenSSL 1.1.0+ */ /* Disabled due API changes for OpenSSL 1.1.0+ */
#if OPENSSL_VERSION_NUMBER < 0x10100000L #if OPENSSL_VERSION_NUMBER < 0x10100000L
case BIO_CB_READ: case BIO_CB_READ:
if (bio->method->type & BIO_TYPE_DESCRIPTOR) if (bio->method->type & BIO_TYPE_DESCRIPTOR)
printf("read(%d,%lu) - %s fd=%d\n", printf("read(%d,%lu) - %s fd=%d\n",
RSYSLOG_BIO_number_read(bio), (unsigned long)argi, RSYSLOG_BIO_number_read(bio), (unsigned long)argi,
RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_read(bio)); RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_read(bio));
else else
printf("read(%d,%lu) - %s\n", printf("read(%d,%lu) - %s\n",
RSYSLOG_BIO_number_read(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio)); RSYSLOG_BIO_number_read(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_WRITE: case BIO_CB_WRITE:
if (bio->method->type & BIO_TYPE_DESCRIPTOR) if (bio->method->type & BIO_TYPE_DESCRIPTOR)
printf("write(%d,%lu) - %s fd=%d\n", printf("write(%d,%lu) - %s fd=%d\n",
RSYSLOG_BIO_number_written(bio), (unsigned long)argi, RSYSLOG_BIO_number_written(bio), (unsigned long)argi,
RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_written(bio)); RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_written(bio));
else else
printf("write(%d,%lu) - %s\n", printf("write(%d,%lu) - %s\n",
RSYSLOG_BIO_number_written(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio)); RSYSLOG_BIO_number_written(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio));
break; break;
#else #else
case BIO_CB_READ: case BIO_CB_READ:
printf("read %s\n", RSYSLOG_BIO_method_name(bio)); printf("read %s\n", RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_WRITE: case BIO_CB_WRITE:
printf("write %s\n", RSYSLOG_BIO_method_name(bio)); printf("write %s\n", RSYSLOG_BIO_method_name(bio));
break; break;
#endif #endif
case BIO_CB_PUTS: case BIO_CB_PUTS:
printf("puts() - %s\n", RSYSLOG_BIO_method_name(bio)); printf("puts() - %s\n", RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_GETS: case BIO_CB_GETS:
printf("gets(%lu) - %s\n", (unsigned long)argi, printf("gets(%lu) - %s\n", (unsigned long)argi,
RSYSLOG_BIO_method_name(bio)); RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_CTRL: case BIO_CB_CTRL:
printf("ctrl(%lu) - %s\n", (unsigned long)argi, printf("ctrl(%lu) - %s\n", (unsigned long)argi,
RSYSLOG_BIO_method_name(bio)); RSYSLOG_BIO_method_name(bio));
break; break;
case BIO_CB_RETURN | BIO_CB_READ: case BIO_CB_RETURN | BIO_CB_READ:
printf("read return %ld\n", ret); printf("read return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_WRITE: case BIO_CB_RETURN | BIO_CB_WRITE:
printf("write return %ld\n", ret); printf("write return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_GETS: case BIO_CB_RETURN | BIO_CB_GETS:
printf("gets return %ld\n", ret); printf("gets return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_PUTS: case BIO_CB_RETURN | BIO_CB_PUTS:
printf("puts return %ld\n", ret); printf("puts return %ld\n", ret);
break; break;
case BIO_CB_RETURN | BIO_CB_CTRL: case BIO_CB_RETURN | BIO_CB_CTRL:
printf("ctrl return %ld\n", ret); printf("ctrl return %ld\n", ret);
break; break;
default: default:
printf("bio callback - unknown type (%d)\n", cmd); printf("bio callback - unknown type (%d)\n", cmd);
break; break;
} }
return (r); return (r);
} }
void osslLastSSLErrorMsg(int ret, SSL *ssl, const char* pszCallSource) void osslLastSSLErrorMsg(int ret, SSL *ssl, const char* pszCallSource)

View File

@ -55,7 +55,7 @@ static rsRetVal doInit(void) \
DEFiRet; \ DEFiRet; \
char *pErrObj; /* tells us which object failed if that happens */ \ char *pErrObj; /* tells us which object failed if that happens */ \
putenv("RSYSLOG_MODDIR=../runtime/.libs/"); /* this is a bit hackish... */ \ putenv("RSYSLOG_MODDIR=../runtime/.libs/"); /* this is a bit hackish... */ \
\ \
dbgClassInit(); \ dbgClassInit(); \
/* Intialize the runtime system */ \ /* Intialize the runtime system */ \
pErrObj = "rsyslog runtime"; /* set in case the runtime errors before setting an object */ \ pErrObj = "rsyslog runtime"; /* set in case the runtime errors before setting an object */ \
@ -68,7 +68,7 @@ finalize_it: \
if(iRet != RS_RET_OK) { \ if(iRet != RS_RET_OK) { \
printf("failure occured during init of object '%s'\n", pErrObj); \ printf("failure occured during init of object '%s'\n", pErrObj); \
} \ } \
\ \
RETiRet; \ RETiRet; \
} }

View File

@ -50,7 +50,7 @@ int addNL = 0;
void void
cleanup(void) cleanup(void)
{ {
unlink(sockName); unlink(sockName);
close(sock); close(sock);
} }
@ -77,12 +77,12 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int opt; int opt;
int rlen; int rlen;
FILE *fp = stdout; FILE *fp = stdout;
unsigned char data[128*1024]; unsigned char data[128*1024];
struct sockaddr_un addr; /* address of server */ struct sockaddr_un addr; /* address of server */
struct sockaddr from; struct sockaddr from;
socklen_t fromlen; socklen_t fromlen;
if(argc < 2) { if(argc < 2) {
fprintf(stderr, "error: too few arguments!\n"); fprintf(stderr, "error: too few arguments!\n");
@ -91,13 +91,13 @@ main(int argc, char *argv[])
while((opt = getopt(argc, argv, "s:o:l")) != EOF) { while((opt = getopt(argc, argv, "s:o:l")) != EOF) {
switch((char)opt) { switch((char)opt) {
case 'l': case 'l':
addNL = 1; addNL = 1;
break; break;
case 's': case 's':
sockName = optarg; sockName = optarg;
break; break;
case 'o': case 'o':
if((fp = fopen(optarg, "w")) == NULL) { if((fp = fopen(optarg, "w")) == NULL) {
perror(optarg); perror(optarg);
exit(1); exit(1);
@ -112,33 +112,33 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
if(signal(SIGTERM, doTerm) == SIG_ERR) { if(signal(SIGTERM, doTerm) == SIG_ERR) {
perror("signal(SIGTERM, ...)"); perror("signal(SIGTERM, ...)");
exit(1); exit(1);
} }
if(signal(SIGINT, doTerm) == SIG_ERR) { if(signal(SIGINT, doTerm) == SIG_ERR) {
perror("signal(SIGINT, ...)"); perror("signal(SIGINT, ...)");
exit(1); exit(1);
} }
/* Create a UNIX datagram socket for server */ /* Create a UNIX datagram socket for server */
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
perror("server: socket"); perror("server: socket");
exit(1); exit(1);
} }
atexit(cleanup); atexit(cleanup);
/* Set up address structure for server socket */ /* Set up address structure for server socket */
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, sockName); strcpy(addr.sun_path, sockName);
if (bind(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0) { if (bind(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
close(sock); close(sock);
perror("server: bind"); perror("server: bind");
exit(1); exit(1);
} }
/* we now run in an endless loop. We do not check who sends us /* we now run in an endless loop. We do not check who sends us
* data. This should be no problem for our testbench use. * data. This should be no problem for our testbench use.
@ -154,7 +154,7 @@ main(int argc, char *argv[])
if(addNL) if(addNL)
fputc('\n', fp); fputc('\n', fp);
} }
} }
return 0; return 0;
} }

View File

@ -279,9 +279,9 @@ rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), rsRetVal(*afterRun)(thrdI
pThis->bNeedsCancel = bNeedsCancel; pThis->bNeedsCancel = bNeedsCancel;
pThis->name = ustrdup(name); pThis->name = ustrdup(name);
#if defined (_AIX) #if defined (_AIX)
pthread_attr_init(&aix_attr); pthread_attr_init(&aix_attr);
pthread_attr_setstacksize(&aix_attr, 4096*512); pthread_attr_setstacksize(&aix_attr, 4096*512);
pthread_create(&pThis->thrdID, &aix_attr, thrdStarter, pThis); pthread_create(&pThis->thrdID, &aix_attr, thrdStarter, pThis);
#else #else
pthread_create(&pThis->thrdID, &default_thread_attr, thrdStarter, pThis); pthread_create(&pThis->thrdID, &default_thread_attr, thrdStarter, pThis);
#endif #endif

View File

@ -6,7 +6,7 @@
* *
* Copyright 2017 Hugo Soszynski and aDvens * Copyright 2017 Hugo Soszynski and aDvens
* *
* long short * long short
* level l read records with level x * level l read records with level x
* severity s read records with severity x * severity s read records with severity x

View File

@ -1409,7 +1409,7 @@ CODESTARTparseSelectorAct
pData->iSizeLimit = 0; /* default value, use outchannels to configure! */ pData->iSizeLimit = 0; /* default value, use outchannels to configure! */
switch(*p) { switch(*p) {
case '$': case '$':
CODE_STD_STRING_REQUESTparseSelectorAct(1) CODE_STD_STRING_REQUESTparseSelectorAct(1)
pData->iNumTpls = 1; pData->iNumTpls = 1;
/* rgerhards 2005-06-21: this is a special setting for output-channel /* rgerhards 2005-06-21: this is a special setting for output-channel

View File

@ -1330,7 +1330,7 @@ BEGINparseSelectorAct
uchar *q; uchar *q;
int i; int i;
rsRetVal localRet; rsRetVal localRet;
struct addrinfo; struct addrinfo;
TCPFRAMINGMODE tcp_framing = TCP_FRAMING_OCTET_STUFFING; TCPFRAMINGMODE tcp_framing = TCP_FRAMING_OCTET_STUFFING;
CODESTARTparseSelectorAct CODESTARTparseSelectorAct
CODE_STD_STRING_REQUESTparseSelectorAct(1) CODE_STD_STRING_REQUESTparseSelectorAct(1)

View File

@ -397,7 +397,7 @@ CODESTARTparseSelectorAct
++p; ++p;
CHKiRet(cflineParseFileName(p, (uchar*) pData->pipe, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, CHKiRet(cflineParseFileName(p, (uchar*) pData->pipe, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS,
getDfltTpl())); getDfltTpl()));
CODE_STD_FINALIZERparseSelectorAct CODE_STD_FINALIZERparseSelectorAct
ENDparseSelectorAct ENDparseSelectorAct

View File

@ -408,7 +408,7 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(datetime, CORE_COMPONENT)); CHKiRet(objUse(datetime, CORE_COMPONENT));
DBGPRINTF("rfc3164 parser init called\n"); DBGPRINTF("rfc3164 parser init called\n");
bParseHOSTNAMEandTAG = glbl.GetParseHOSTNAMEandTAG(); bParseHOSTNAMEandTAG = glbl.GetParseHOSTNAMEandTAG();
/* cache value, is set only during rsyslogd option processing */ /* cache value, is set only during rsyslogd option processing */

View File

@ -237,7 +237,7 @@ CODESTARTparse
* wiser than to use individual buffers. * wiser than to use individual buffers.
*/ */
CHKmalloc(pBuf = MALLOC(lenMsg + 1)); CHKmalloc(pBuf = MALLOC(lenMsg + 1));
/* IMPORTANT NOTE: /* IMPORTANT NOTE:
* Validation is not actually done below nor are any errors handled. I have * Validation is not actually done below nor are any errors handled. I have
* NOT included this for the current proof of concept. However, it is strongly * NOT included this for the current proof of concept. However, it is strongly

View File

@ -182,7 +182,7 @@ done: return r;
static int static int
initCrypt(FILE *eifp) initCrypt(FILE *eifp)
{ {
int r = 0; int r = 0;
gcry_error_t gcryError; gcry_error_t gcryError;
char iv[4096]; char iv[4096];
@ -296,21 +296,21 @@ doDecrypt(FILE *logfp, FILE *eifp, FILE *outfp)
off64_t currOffs = 0; off64_t currOffs = 0;
int r = 1; int r = 1;
int fd; int fd;
struct stat buf; struct stat buf;
while(1) { while(1) {
/* process block */ /* process block */
if(initCrypt(eifp) != 0) if(initCrypt(eifp) != 0)
goto done; goto done;
/* set blkEnd to size of logfp and proceed. */ /* set blkEnd to size of logfp and proceed. */
if((fd = fileno(logfp)) == -1) { if((fd = fileno(logfp)) == -1) {
r = -1; r = -1;
goto done; goto done;
} }
if((r = fstat(fd, &buf)) != 0) goto done; if((r = fstat(fd, &buf)) != 0) goto done;
blkEnd = buf.st_size; blkEnd = buf.st_size;
r = eiGetEND(eifp, &blkEnd); r = eiGetEND(eifp, &blkEnd);
if(r != 0 && r != 1) goto done; if(r != 0 && r != 1) goto done;
decryptBlock(logfp, outfp, blkEnd, &currOffs); decryptBlock(logfp, outfp, blkEnd, &currOffs);
gcry_cipher_close(gcry_chd); gcry_cipher_close(gcry_chd);
} }

View File

@ -153,7 +153,7 @@ static int bHadHUP;
static int doFork = 1; /* fork - run in daemon mode - read-only after startup */ static int doFork = 1; /* fork - run in daemon mode - read-only after startup */
int bFinished = 0; /* used by termination signal handler, read-only except there int bFinished = 0; /* used by termination signal handler, read-only except there
* is either 0 or the number of the signal that requested the * is either 0 or the number of the signal that requested the
* termination. * termination.
*/ */
const char *PidFile; const char *PidFile;
#define NO_PIDFILE "NONE" #define NO_PIDFILE "NONE"
@ -1309,9 +1309,9 @@ initAll(int argc, char **argv)
while((ch = getopt(argc, argv, "46ACDdf:i:l:M:nN:qQs:S:T:u:vwx")) != EOF) { while((ch = getopt(argc, argv, "46ACDdf:i:l:M:nN:qQs:S:T:u:vwx")) != EOF) {
#endif #endif
switch((char)ch) { switch((char)ch) {
case '4': case '4':
case '6': case '6':
case 'A': case 'A':
case 'f': /* configuration file */ case 'f': /* configuration file */
case 'i': /* pid file name */ case 'i': /* pid file name */
case 'l': case 'l':
@ -1392,24 +1392,24 @@ initAll(int argc, char **argv)
while((iRet = bufOptRemove(&ch, &arg)) == RS_RET_OK) { while((iRet = bufOptRemove(&ch, &arg)) == RS_RET_OK) {
DBGPRINTF("deque option %c, optarg '%s'\n", ch, (arg == NULL) ? "" : arg); DBGPRINTF("deque option %c, optarg '%s'\n", ch, (arg == NULL) ? "" : arg);
switch((char)ch) { switch((char)ch) {
case '4': case '4':
fprintf (stderr, "rsyslogd: the -4 command line option will go away " fprintf (stderr, "rsyslogd: the -4 command line option will go away "
"soon.\nPlease use the global(net.ipprotocol=\"ipv4-only\") " "soon.\nPlease use the global(net.ipprotocol=\"ipv4-only\") "
"configuration parameter instead.\n"); "configuration parameter instead.\n");
glbl.SetDefPFFamily(PF_INET); glbl.SetDefPFFamily(PF_INET);
break; break;
case '6': case '6':
fprintf (stderr, "rsyslogd: the -6 command line option will go away " fprintf (stderr, "rsyslogd: the -6 command line option will go away "
"soon.\nPlease use the global(net.ipprotocol=\"ipv6-only\") " "soon.\nPlease use the global(net.ipprotocol=\"ipv6-only\") "
"configuration parameter instead.\n"); "configuration parameter instead.\n");
glbl.SetDefPFFamily(PF_INET6); glbl.SetDefPFFamily(PF_INET6);
break; break;
case 'A': case 'A':
fprintf (stderr, "rsyslogd: the -A command line option will go away " fprintf (stderr, "rsyslogd: the -A command line option will go away "
"soon.\n" "soon.\n"
"Please use the omfwd parameter \"upd.sendToAll\" instead.\n"); "Please use the omfwd parameter \"upd.sendToAll\" instead.\n");
send_to_all++; send_to_all++;
break; break;
case 'S': /* Source IP for local client to be used on multihomed host */ case 'S': /* Source IP for local client to be used on multihomed host */
fprintf (stderr, "rsyslogd: the -S command line option will go away " fprintf (stderr, "rsyslogd: the -S command line option will go away "
"soon.\n" "soon.\n"
@ -1477,8 +1477,8 @@ initAll(int argc, char **argv)
perror("chroot"); perror("chroot");
exit(1); exit(1);
} }
if(chdir("/") != 0) { if(chdir("/") != 0) {
perror("chdir"); perror("chdir");
exit(1); exit(1);
} }
break; break;
@ -1514,7 +1514,7 @@ initAll(int argc, char **argv)
"configuration parameter instead.\n"); "configuration parameter instead.\n");
glbl.SetDisableDNS(1); glbl.SetDisableDNS(1);
break; break;
case '?': case '?':
default: default:
rsyslogd_usage(); rsyslogd_usage();
} }

View File

@ -350,8 +350,8 @@ doTest(syncType_t st)
} }
/* we have a memory leak due to calling dispRuntime(), but we don't /* we have a memory leak due to calling dispRuntime(), but we don't
* care as we terminate immediately. * care as we terminate immediately.
*/ */
printf("%-10s: total runtime %6ld.%3.3u, avg %s, min %s, max %s\n", printf("%-10s: total runtime %6ld.%3.3u, avg %s, min %s, max %s\n",
getSyncMethName(st), getSyncMethName(st),
(long)totalRuntime/1000, (unsigned)(totalRuntime % 1000), (long)totalRuntime/1000, (unsigned)(totalRuntime % 1000),

View File

@ -147,7 +147,7 @@ char **syslogd_crunch_list(char *list)
} }
/* cut off leading delimiters */ /* cut off leading delimiters */
while (p[0] == LIST_DELIMITER) { while (p[0] == LIST_DELIMITER) {
p++; p++;
} }
/* count delimiters to calculate elements */ /* count delimiters to calculate elements */