diff options
-rw-r--r-- | runtime/dnscache.c | 25 | ||||
-rw-r--r-- | runtime/dnscache.h | 4 | ||||
-rw-r--r-- | runtime/msg.c | 8 | ||||
-rw-r--r-- | runtime/net.c | 7 | ||||
-rw-r--r-- | runtime/net.h | 7 | ||||
-rw-r--r-- | runtime/nsd_ptcp.c | 20 | ||||
-rw-r--r-- | tools/syslogd.c | 7 |
7 files changed, 45 insertions, 33 deletions
diff --git a/runtime/dnscache.c b/runtime/dnscache.c index eeb5cbf4..c6e22833 100644 --- a/runtime/dnscache.c +++ b/runtime/dnscache.c @@ -7,7 +7,7 @@ * In any case, even the initial implementaton is far faster than what we had * before. -- rgerhards, 2011-06-06 * - * Copyright 2011 by Rainer Gerhards and Adiscon GmbH. + * Copyright 2011-2013 by Rainer Gerhards and Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -42,14 +42,13 @@ #include "net.h" #include "hashtable.h" -/* in this initial implementation, we use a simple, non-optimized at all - * linear list. - */ /* module data structures */ struct dnscache_entry_s { struct sockaddr_storage addr; uchar *pszHostFQDN; uchar *ip; + rs_size_t lenHost; + rs_size_t lenIP; struct dnscache_entry_s *next; unsigned nUsed; }; @@ -272,6 +271,8 @@ addEntry(struct sockaddr_storage *addr, dnscache_entry_t **pEtry) CHKiRet(resolveAddr(addr, pszHostFQDN, ip)); CHKmalloc(etry = MALLOC(sizeof(dnscache_entry_t))); + etry->lenHost = ustrlen(pszHostFQDN); + etry->lenIP = ustrlen(ip); CHKmalloc(etry->pszHostFQDN = ustrdup(pszHostFQDN)); CHKmalloc(etry->ip = ustrdup(ip)); memcpy(&etry->addr, addr, SALEN((struct sockaddr*) addr)); @@ -311,7 +312,8 @@ validateEntry(dnscache_entry_t __attribute__((unused)) *etry, struct sockaddr_st * If the entry can not be resolved, an error is reported back. */ rsRetVal -dnscacheLookup(struct sockaddr_storage *addr, uchar *pszHostFQDN, uchar *ip) +dnscacheLookup(struct sockaddr_storage *addr, uchar **pszHostFQDN, rs_size_t *lenHost, + uchar **ip, rs_size_t *lenIP) { dnscache_entry_t *etry; DEFiRet; @@ -324,18 +326,21 @@ dnscacheLookup(struct sockaddr_storage *addr, uchar *pszHostFQDN, uchar *ip) } else { CHKiRet(validateEntry(etry, addr)); } - // TODO/QUESTION: can we get rid of the strcpy? dbgprintf("XXXX: hostn '%s', ip '%s'\n", etry->pszHostFQDN, etry->ip); - strcpy((char*)pszHostFQDN, (char*)etry->pszHostFQDN); - strcpy((char*)ip, (char*)etry->ip); + *pszHostFQDN = etry->pszHostFQDN; + *lenHost = etry->lenHost; + *ip = etry->ip; + *lenIP = etry->lenIP; finalize_it: pthread_rwlock_unlock(&dnsCache.rwlock); dbgprintf("XXXX: dnscacheLookup finished, iRet=%d\n", iRet); if(iRet != RS_RET_OK && iRet != RS_RET_ADDRESS_UNKNOWN) { DBGPRINTF("dnscacheLookup failed with iRet %d\n", iRet); - strcpy((char*) pszHostFQDN, "???"); - strcpy((char*) ip, "???"); + *pszHostFQDN = (uchar*)"???"; + *lenHost = 3; + *ip = (uchar*)"???"; + *lenIP = 3; } RETiRet; } diff --git a/runtime/dnscache.h b/runtime/dnscache.h index 69f038ee..5b7f96d6 100644 --- a/runtime/dnscache.h +++ b/runtime/dnscache.h @@ -1,6 +1,6 @@ /* Definitions for dnscache module. * - * Copyright 2011-2012 Adiscon GmbH. + * Copyright 2011-2013 Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -24,6 +24,6 @@ rsRetVal dnscacheInit(void); rsRetVal dnscacheDeinit(void); -rsRetVal dnscacheLookup(struct sockaddr_storage *addr, uchar *pszHostFQDN, uchar *ip); +rsRetVal dnscacheLookup(struct sockaddr_storage *addr, uchar **pszHostFQDN, rs_size_t *lenHost, uchar **ip, rs_size_t *lenIP); #endif /* #ifndef INCLUDED_DNSCACHE_H */ diff --git a/runtime/msg.c b/runtime/msg.c index 390dd565..0b9e9665 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -362,17 +362,19 @@ resolveDNS(msg_t *pMsg) { prop_t *propFromHost = NULL; prop_t *propFromHostIP = NULL; uchar fromHost[NI_MAXHOST]; - uchar fromHostIP[NI_MAXHOST]; uchar fromHostFQDN[NI_MAXHOST]; + uchar *fromHostIP; + rs_size_t lenIP; DEFiRet; MsgLock(pMsg); CHKiRet(objUse(net, CORE_COMPONENT)); if(pMsg->msgFlags & NEEDS_DNSRESOL) { - localRet = net.cvthname(pMsg->rcvFrom.pfrominet, fromHost, fromHostFQDN, fromHostIP); + localRet = net.cvthname(pMsg->rcvFrom.pfrominet, fromHost, fromHostFQDN, + &fromHostIP, &lenIP); if(localRet == RS_RET_OK) { MsgSetRcvFromStr(pMsg, fromHost, ustrlen(fromHost), &propFromHost); - CHKiRet(MsgSetRcvFromIPStr(pMsg, fromHostIP, ustrlen(fromHostIP), &propFromHostIP)); + CHKiRet(MsgSetRcvFromIPStr(pMsg, fromHostIP, lenIP, &propFromHostIP)); } } finalize_it: diff --git a/runtime/net.c b/runtime/net.c index 1a8f2438..a6670eca 100644 --- a/runtime/net.c +++ b/runtime/net.c @@ -1125,9 +1125,11 @@ void debugListenInfo(int fd, char *type) * pay. * 2005-05-16 rgerhards: added IP representation. Must also be NI_MAXHOST */ -rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN, uchar *pszIP) +rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN, uchar **pszIP, rs_size_t *lenIP) { DEFiRet; + uchar *host; + rs_size_t lenHost; register uchar *p; int count; @@ -1135,7 +1137,8 @@ rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN assert(pszHost != NULL); assert(pszHostFQDN != NULL); - iRet = dnscacheLookup(f, pszHostFQDN, pszIP); + iRet = dnscacheLookup(f, &host, &lenHost, pszIP, lenIP); + strcpy((char*)pszHostFQDN, (char*)host); // TODO: optimize this! requires more changes below (dirty tricks ;)) if(iRet == RS_RET_INVALID_SOURCE) { strcpy((char*) pszHost, (char*) pszHostFQDN); /* we use whatever was provided as replacement */ diff --git a/runtime/net.h b/runtime/net.h index 1b41c81c..a38328a9 100644 --- a/runtime/net.h +++ b/runtime/net.h @@ -1,6 +1,6 @@ /* Definitions for network-related stuff. * - * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH. + * Copyright 2007-2013 Rainer Gerhards and Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -131,7 +131,7 @@ struct permittedPeers_s { /* interfaces */ BEGINinterface(net) /* name must also be changed in ENDinterface macro! */ - rsRetVal (*cvthname)(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN, uchar *pszIP); + rsRetVal (*cvthname)(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN, uchar **pszIP, rs_size_t *lenIP); /* things to go away after proper modularization */ rsRetVal (*addAllowedSenderLine)(char* pName, uchar** ppRestOfConfLine); void (*PrintAllowedSenders)(int iListToPrint); @@ -156,8 +156,9 @@ BEGINinterface(net) /* name must also be changed in ENDinterface macro! */ /* data members - these should go away over time... TODO */ int *pACLAddHostnameOnFail; /* add hostname to acl when DNS resolving has failed */ int *pACLDontResolve; /* add hostname to acl instead of resolving it to IP(s) */ + /* v8 cvthname() signature change -- rgerhards, 2013-01-18 */ ENDinterface(net) -#define netCURR_IF_VERSION 7 /* increment whenever you change the interface structure! */ +#define netCURR_IF_VERSION 8 /* increment whenever you change the interface structure! */ /* prototypes */ PROTOTYPEObj(net); diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c index d355d19c..a212efb0 100644 --- a/runtime/nsd_ptcp.c +++ b/runtime/nsd_ptcp.c @@ -251,32 +251,32 @@ Abort(nsd_t *pNsd) static rsRetVal FillRemHost(nsd_ptcp_t *pThis, struct sockaddr_storage *pAddr) { - uchar szIP[NI_MAXHOST] = ""; - uchar szHname[NI_MAXHOST] = ""; - size_t len; + uchar *szIP; + uchar *szHname; + rs_size_t lenHname, lenIP; DEFiRet; ISOBJ_TYPE_assert(pThis, nsd_ptcp); assert(pAddr != NULL); - CHKiRet(dnscacheLookup(pAddr, szHname, szIP)); + CHKiRet(dnscacheLookup(pAddr, &szHname, &lenHname, &szIP, &lenIP)); /* We now have the names, so now let's allocate memory and store them permanently. * (side note: we may hold on to these values for quite a while, thus we trim their * memory consumption) */ - len = strlen((char*)szIP) + 1; /* +1 for \0 byte */ - if((pThis->pRemHostIP = MALLOC(len)) == NULL) + lenIP++; /* +1 for \0 byte */ + lenHname++; + if((pThis->pRemHostIP = MALLOC(lenIP)) == NULL) ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); - memcpy(pThis->pRemHostIP, szIP, len); + memcpy(pThis->pRemHostIP, szIP, lenIP); - len = strlen((char*)szHname) + 1; /* +1 for \0 byte */ - if((pThis->pRemHostName = MALLOC(len)) == NULL) { + if((pThis->pRemHostName = MALLOC(lenHname)) == NULL) { free(pThis->pRemHostIP); /* prevent leak */ pThis->pRemHostIP = NULL; ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); } - memcpy(pThis->pRemHostName, szHname, len); + memcpy(pThis->pRemHostName, szHname, lenHname); finalize_it: RETiRet; diff --git a/tools/syslogd.c b/tools/syslogd.c index a4b53d1f..4f3bad67 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -501,8 +501,9 @@ finalize_it: static inline rsRetVal preprocessBatch(batch_t *pBatch) { uchar fromHost[NI_MAXHOST]; - uchar fromHostIP[NI_MAXHOST]; uchar fromHostFQDN[NI_MAXHOST]; + uchar *fromHostIP; + rs_size_t lenIP; prop_t *propFromHost = NULL; prop_t *propFromHostIP = NULL; int bSingleRuleset; @@ -520,7 +521,7 @@ preprocessBatch(batch_t *pBatch) { pMsg = pBatch->pElem[i].pMsg; if((pMsg->msgFlags & NEEDS_ACLCHK_U) != 0) { DBGPRINTF("msgConsumer: UDP ACL must be checked for message (hostname-based)\n"); - if(net.cvthname(pMsg->rcvFrom.pfrominet, fromHost, fromHostFQDN, fromHostIP) != RS_RET_OK) + if(net.cvthname(pMsg->rcvFrom.pfrominet, fromHost, fromHostFQDN, &fromHostIP, &lenIP) != RS_RET_OK) continue; bIsPermitted = net.isAllowedSender2((uchar*)"UDP", (struct sockaddr *)pMsg->rcvFrom.pfrominet, (char*)fromHostFQDN, 1); @@ -531,7 +532,7 @@ preprocessBatch(batch_t *pBatch) { } else { /* save some of the info we obtained */ MsgSetRcvFromStr(pMsg, fromHost, ustrlen(fromHost), &propFromHost); - CHKiRet(MsgSetRcvFromIPStr(pMsg, fromHostIP, ustrlen(fromHostIP), &propFromHostIP)); + CHKiRet(MsgSetRcvFromIPStr(pMsg, fromHostIP, lenIP, &propFromHostIP)); pMsg->msgFlags &= ~NEEDS_ACLCHK_U; } } |