summaryrefslogtreecommitdiff
path: root/tests/nettester.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/nettester.c')
-rw-r--r--tests/nettester.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/tests/nettester.c b/tests/nettester.c
index 4e4fe55..82f3013 100644
--- a/tests/nettester.c
+++ b/tests/nettester.c
@@ -12,7 +12,7 @@
*
* Part of the testbench for rsyslog.
*
- * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2009-2014 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -49,6 +49,7 @@
#include <getopt.h>
#include <errno.h>
#include <ctype.h>
+#include <netdb.h>
#define EXIT_FAILURE 1
#define INVALID_SOCKET -1
@@ -65,6 +66,7 @@ static char* pszCustomConf = NULL; /* custom config file, use -c conf to specify
static int verbose = 0; /* verbose output? -v option */
static int IPv4Only = 0; /* use only IPv4 in rsyslogd call? */
static char **ourEnvp;
+static char *ourHostName;
/* these two are quick hacks... */
int iFailed = 0;
@@ -339,6 +341,44 @@ void unescapeTestdata(char *testdata)
}
+/* expand variables in expected string. Here we use tilde (~) as expension
+ * character, because the more natural % is very common in syslog messages
+ * (and most importantly in the samples we currently have.
+ * Currently supported are:
+ * ~H - our hostname
+ * Note: yes, there are vulns in this code. Doesn't matter, as it is a
+ * quick and dirty test program, NOT intended to be used in any production!
+ */
+static void
+doVarsInExpected(char **pe)
+{
+ char *n, *newBase;
+ char *e = *pe;
+ n = newBase = malloc(strlen(e) + 1024); /* we simply say "sufficient" */
+ while(*e) {
+ if(*e == '~') {
+ ++e;
+ if(*e == 'H') {
+ ++e;
+ char *hn = ourHostName;
+ while(*hn)
+ *n++ = *hn++;
+ } else {
+ *n++ = '?';
+ ++e;
+ }
+ } else if(*e == '\\') {
+ ++e; /* skip */
+ *n++ = *e++;
+ } else {
+ *n++ = *e++;
+ }
+ }
+ *n = '\0';
+ free(*pe);
+ *pe = newBase;
+}
+
/* Process a specific test case. File name is provided.
* Needs to return 0 if all is OK, something else otherwise.
*/
@@ -391,9 +431,9 @@ processTestFile(int fd, char *pszFileName)
*/
getline(&expected, &lenLn, fp);
expected[strlen(expected)-1] = '\0'; /* remove \n */
+ doVarsInExpected(&expected);
/* pull response from server and then check if it meets our expectation */
-//printf("try pull pipe...\n");
readLine(fd, buf);
if(strlen(buf) == 0) {
printf("something went wrong - read a zero-length string from rsyslogd\n");
@@ -493,6 +533,23 @@ void doAtExit(void)
unlink(NETTEST_INPUT_CONF_FILE);
}
+
+/* Note: the HOSTNAME file must have been pre-generated */
+static void
+getHostname(void)
+{
+ size_t dummy;
+ FILE *fp;
+ if((fp = fopen("HOSTNAME", "r")) == NULL) {
+ perror("HOSTNAME");
+ printf("error opening HOSTNAME configuration file\n");
+ exit(1);
+ }
+ getline(&ourHostName, &dummy, fp);
+ fclose(fp);
+}
+
+
/* Run the test suite. This must be called with exactly one parameter, the
* name of the test suite. For details, see file header comment at the top
* of this file.
@@ -508,6 +565,8 @@ int main(int argc, char *argv[], char *envp[])
char testcases[4096];
ourEnvp = envp;
+ getHostname();
+
while((opt = getopt(argc, argv, "4c:i:p:t:v")) != EOF) {
switch((char)opt) {
case '4':