summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net.c10
-rw-r--r--plugins/imudp/imudp.c55
-rw-r--r--syslogd.c37
-rw-r--r--syslogd.h1
4 files changed, 59 insertions, 44 deletions
diff --git a/net.c b/net.c
index 4997fdd1..132a154f 100644
--- a/net.c
+++ b/net.c
@@ -855,18 +855,18 @@ dbgprintf("in closeUDPListenSockets()\n");
/* creates the UDP listen sockets
- * hostname and/or LogPort may be NULL, but not both!
+ * hostname and/or pszPort may be NULL, but not both!
* bIsServer indicates if a server socket should be created
* 1 - server, 0 - client
*/
-int *create_udp_socket(uchar *hostname, uchar *LogPort, int bIsServer)
+int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
{
struct addrinfo hints, *res, *r;
int error, maxs, *s, *socks, on = 1;
int sockflags;
-dbgprintf("create_udp_socket('%s', '%s', %d);\n", hostname, LogPort, bIsServer);
- assert(!((LogPort == NULL) && (hostname == NULL)));
+dbgprintf("create_udp_socket('%s', '%s', %d);\n", hostname, pszPort, bIsServer);
+ assert(!((pszPort == NULL) && (hostname == NULL)));
memset(&hints, 0, sizeof(hints));
if(bIsServer)
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
@@ -874,7 +874,7 @@ dbgprintf("create_udp_socket('%s', '%s', %d);\n", hostname, LogPort, bIsServer);
hints.ai_flags = AI_NUMERICSERV;
hints.ai_family = family;
hints.ai_socktype = SOCK_DGRAM;
- error = getaddrinfo((char*) hostname, (char*) LogPort, &hints, &res);
+ error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res);
if(error) {
logerror((char*) gai_strerror(error));
logerror("UDP message reception disabled due to error logged in last message.\n");
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
index f3a2b72a..f8bea91a 100644
--- a/plugins/imudp/imudp.c
+++ b/plugins/imudp/imudp.c
@@ -46,6 +46,7 @@ TERM_SYNC_TYPE(eTermSync_NONE)
DEF_IMOD_STATIC_DATA
static int *udpLstnSocks = NULL; /* Internet datagram sockets, first element is nbr of elements
* read-only after init(), but beware of restart! */
+static uchar *pszLstnPort = NULL;
typedef struct _instanceData {
} instanceData;
@@ -153,8 +154,47 @@ ENDrunInput
BEGINwillRun
CODESTARTwillRun
PrintAllowedSenders(1); /* UDP */
- if((udpLstnSocks = create_udp_socket(NULL, (uchar*)LogPort, 1)) != NULL)
+ if((udpLstnSocks = create_udp_socket(NULL, (pszLstnPort == NULL) ? (uchar*) "514" : pszLstnPort, 1)) != NULL)
dbgprintf("Opened %d syslog UDP port(s).\n", *udpLstnSocks);
+#if 0
+/* TODO: think if we need this code - so far, I simply use "syslog" as port name
+ * if none is specified. That looks OK to me - but I do not remove that code here
+ * so that we can think about it once again. Please note that the code here needs
+ * to be adapted, I haven't done that because I came to the idea I do not need it...
+ * rgerahrds, 2007-12-26
+ */
+ struct servent *sp;
+ if(pszLstnPort == NULL) {
+ /* I was told by an IPv6 expert that calling getservbyname() seems to be
+ * still valid, at least for the use case we have. So I re-enabled that
+ * code. rgerhards, 2007-07-02
+ */
+ /* we shall use the default syslog/udp port, so let's
+ * look it up.
+ * TODO: getservbyname() is not thread-safe, we need to replace it.
+ */
+ sp = getservbyname("syslog", "udp");
+ if (sp == NULL) {
+ errno = 0;
+ logerror("Could not find syslog/udp port in /etc/services. "
+ "Now using IANA-assigned default of 514.");
+ LogPort = "514";
+ } else {
+ /* we can dynamically allocate memory here and do NOT need
+ * to care about freeing it because even though init() is
+ * called on each restart, the LogPort can never again be
+ * "0". So we will only once run into this part of the code
+ * here. rgerhards, 2007-07-02
+ * We save ourselfs the hassle of dynamic memory management
+ * for the very same reason.
+ */
+// we need to do dynamic memory alloc here!
+
+ snprintf(defPort, sizeof(defPort), "%d", ntohs(sp->s_port));
+ LogPort = defPort;
+ }
+ }
+#endif
ENDwillRun
@@ -167,7 +207,10 @@ dbgprintf("call clearAllowedSenders(0x%lx)\n", (unsigned long) pAllowedSenders_U
clearAllowedSenders (pAllowedSenders_UDP);
pAllowedSenders_UDP = NULL;
}
- closeUDPListenSockets(udpLstnSocks);
+ if(udpLstnSocks != NULL)
+ closeUDPListenSockets(udpLstnSocks);
+ if(pszLstnPort != NULL)
+ free(pszLstnPort);
ENDafterRun
@@ -193,6 +236,10 @@ ENDqueryEtryPt
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
{
+ if(pszLstnPort != NULL) {
+ free(pszLstnPort);
+ pszLstnPort = NULL;
+ }
return RS_RET_OK;
}
@@ -202,8 +249,8 @@ CODESTARTmodInit
*ipIFVersProvided = 1; /* so far, we only support the initial definition */
CODEmodInit_QueryRegCFSLineHdlr
/* register config file handlers */
- //CHKiRet(omsdRegCFSLineHdlr((uchar *)"omitlocallogging", 0, eCmdHdlrBinary,
- // NULL, &bOmitLocalLogging, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"udplistenport", 0, eCmdHdlrGetWord,
+ NULL, &pszLstnPort, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit
diff --git a/syslogd.c b/syslogd.c
index 15d88cd4..219bd9c5 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -422,12 +422,11 @@ static int logEveryMsg = 0;/* no repeat message processing - read-only after st
static unsigned int Forwarding = 0;
char LocalHostName[MAXHOSTNAMELEN+1];/* our hostname - read-only after startup */
char *LocalDomain; /* our local domain name - read-only after startup */
-char *LogPort = "514"; /* port number for INET connections */
+//char *LogPort = "514"; /* port number for INET connections */
static int MarkInterval = 20 * 60; /* interval between marks in seconds - read-only after startup */
int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both), set via cmdline */
int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */
static int NoFork = 0; /* don't fork - don't run in daemon mode - read-only after startup */
-int AcceptRemote = 0;/* receive messages that come via UDP - read-only after startup */
int DisableDNS = 0; /* don't look up IP addresses of remote messages */
char **StripDomains = NULL;/* these domains may be stripped before writing logs - r/o after s.u., never touched by init */
char **LocalHosts = NULL;/* these hosts are logged with their hostname - read-only after startup, never touched by init */
@@ -3432,7 +3431,6 @@ init(void)
char cline[BUFSIZ];
#endif
char bufStartUpMsg[512];
- struct servent *sp;
struct sigaction sigAct;
thrdTerminateAll(); /* stop all running threads - TODO: reconsider location! */
@@ -3443,37 +3441,6 @@ init(void)
eDfltHostnameCmpMode = HN_NO_COMP;
Forwarding = 0;
- /* I was told by an IPv6 expert that calling getservbyname() seems to be
- * still valid, at least for the use case we have. So I re-enabled that
- * code. rgerhards, 2007-07-02
- */
- if(!strcmp(LogPort, "0")) {
- /* we shall use the default syslog/udp port, so let's
- * look it up.
- * NOTE: getservbyname() is not thread-safe, but this is OK as
- * it is called only during init, in single-threading mode.
- */
- sp = getservbyname("syslog", "udp");
- if (sp == NULL) {
- errno = 0;
- logerror("Could not find syslog/udp port in /etc/services. "
- "Now using IANA-assigned default of 514.");
- LogPort = "514";
- } else {
- /* we can dynamically allocate memory here and do NOT need
- * to care about freeing it because even though init() is
- * called on each restart, the LogPort can never again be
- * "0". So we will only once run into this part of the code
- * here. rgerhards, 2007-07-02
- * We save ourselfs the hassle of dynamic memory management
- * for the very same reason.
- */
- static char defPort[8];
- snprintf(defPort, sizeof(defPort), "%d", ntohs(sp->s_port));
- LogPort = defPort;
- }
- }
-
dbgprintf("rsyslog %s.\n", VERSION);
dbgprintf("Called init.\n");
@@ -4858,11 +4825,13 @@ int main(int argc, char **argv)
break;
case 'r': /* accept remote messages */
#ifdef SYSLOG_INET
+#if 0
AcceptRemote = 1;
if(optarg == NULL)
LogPort = "0";
else
LogPort = optarg;
+#endif
#else
fprintf(stderr, "rsyslogd: -r not valid - not compiled with network support");
#endif
diff --git a/syslogd.h b/syslogd.h
index 80fd8243..30a1d978 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -77,7 +77,6 @@ extern int glblHadMemShortage; /* indicates if we had memory shortage some time
extern char LocalHostName[];
extern int family;
extern int NoHops;
-extern char *LogPort; /* port number for INET connections */
extern int send_to_all;
extern int option_DisallowWarning;
extern int Debug;